[Libguestfs] [PATCH 1/8] New API: btrfs_subvolume_get_default

Hu Tao hutao at cn.fujitsu.com
Mon Dec 8 05:23:35 UTC 2014


On Fri, Dec 05, 2014 at 12:27:06PM +0000, Richard W.M. Jones wrote:
> On Tue, Dec 02, 2014 at 05:33:31PM +0800, Hu Tao wrote:
> > +  ADD_ARG (argv, i, str_btrfs);
> > +  ADD_ARG (argv, i, "subvolume");
> > +  ADD_ARG (argv, i, "get-default");
> > +  ADD_ARG (argv, i, fs_buf);
> > +  ADD_ARG (argv, i, NULL);
> > +
> > +  r = commandv (&out, &err, argv);
> > +  if (r == -1) {
> > +    reply_with_error ("%s: %s", mountpoint, err);
> > +    return -1;
> > +  }
> > +  r = xstrtol (out + 2, NULL, 10, &ret, NULL);
> 
> Unfortunately even gnulib's "xstrtol" function is a minefield, and the
> code above won't work [specifically -- it's insecure] on 32 bit
> machines.
> 
> Anyway, I think it's better to use sscanf here, so:
> 
>   if (sscanf (out, "ID %" SCNi64, &ret) != 2) {
>      // error ...
>   }

Okay.

> 
> > +  if (r != LONGINT_OK) {
> > +    reply_with_error ("%s: could not parse subvolume id: %s.", argv[0], out);
> > +    return -1;
> > +  }
> > +
> > +  return ret;
> > +}
> > +
> >  int
> >  do_btrfs_filesystem_sync (const char *fs)
> >  {
> > diff --git a/generator/actions.ml b/generator/actions.ml
> > index 385b620..80c7ea7 100644
> > --- a/generator/actions.ml
> > +++ b/generator/actions.ml
> > @@ -12027,6 +12027,15 @@ Set readahead (in 512-byte sectors) for the device.
> >  
> >  This uses the L<blockdev(8)> command." };
> >  
> > +  { defaults with
> > +    name = "btrfs_subvolume_get_default";
> > +    style = RInt64 "id", [Pathname "mountpoint"], [];
> > +    proc_nr = Some 425;
> > +    optional = Some "btrfs"; camel_name = "BTRFSSubvolumeGetDefault";
> > +    shortdesc = "get the default subvolume or snapshot of a filesystem";
> > +    longdesc = "\
> > +Get the default subvolume or snapshot of a filesystem mounted at C<mountpoint>." };
> > +
> 
> All of these APIs need tests.

Please hold the series until I add some tests.

Regards,
Hu

> 
> 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