[Libguestfs] [PATCH nbdinfo v2] info: Add a --map option for displaying allocation metadata.

Richard W.M. Jones rjones at redhat.com
Thu Oct 1 14:32:40 UTC 2020


On Thu, Oct 01, 2020 at 08:02:56AM -0500, Eric Blake wrote:
> On 9/26/20 11:36 AM, Richard W.M. Jones wrote:
> > ---
> >  info/Makefile.am                      |   4 +
> >  info/info-map-base-allocation-json.sh |  52 ++++++++++
> >  info/info-map-base-allocation.sh      |  49 ++++++++++
> >  info/nbdinfo.c                        | 134 ++++++++++++++++++++++++--
> >  info/nbdinfo.pod                      |  39 +++++++-
> >  5 files changed, 271 insertions(+), 7 deletions(-)
> 
> An interesting followup might be adding options for --start and --length
> to map out only a subset of the file.  That was recently added to
> qemu-img map, because there are cases where a file is fragmented enough
> that getting the entire map can be time-consuming, in relation to
> mapping out just a subset of the image.
> 
> > +++ b/info/info-map-base-allocation-json.sh
> > @@ -0,0 +1,52 @@
> > +#!/usr/bin/env bash
> > +# nbd client library in userspace
> > +# Copyright (C) 2020 Red Hat Inc.
> > +#
> > +# This library is free software; you can redistribute it and/or
> > +# modify it under the terms of the GNU Lesser General Public
> > +# License as published by the Free Software Foundation; either
> > +# version 2 of the License, or (at your option) any later version.
> > +#
> > +# This library is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> > +# Lesser General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU Lesser General Public
> > +# License along with this library; if not, write to the Free Software
> > +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> > +
> > +. ../tests/functions.sh
> > +
> > +set -e
> > +set -x
> > +
> > +requires nbdkit --version
> > +requires nbdsh --version
> 
> Why are we requiring nbdsh in the libnbd testsuite? :)  Is there a
> configure option where you can have nbdinfo but not nbdsh?

Yes: --disable-python.

> On the other hand, we _do_ require URI support (libxml2); maybe it's
> worth porting 'requires_nbdsh_uri' from nbdkit back to libnbd's
> functions.sh, and using that...

Yes.

> > +requires jq --version
> > +
> > +out=info-base-allocation-json.out
> > +cleanup_fn rm -f $out
> > +rm -f $out
> > +
> > +# Note the memory plugin uses a 32K page size, and extents
> > +# are always aligned with this.
> > +nbdkit -U - memory 1M --run '
> > +    nbdsh -u "$uri" \
> 
> ...since you are depending on it.
> 
> 
> > +/* Callback handling --map. */
> > +static const char *
> > +extent_description (const char *metacontext, uint32_t type)
> > +{
> > +  if (strcmp (metacontext, "base:allocation") == 0) {
> 
> Should we favor the use of LIBNBD_CONTEXT_BASE_ALLOCATION instead of
> open-coding this?

TBH I'm not really sure why we added LIBNBD_CONTEXT_BASE_ALLOCATION,
since this string is part of the ABI so could never be changed, and
the macro isn't even shorter.  Obviously we have it now so we can't
remove it.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html




More information about the Libguestfs mailing list