[Libguestfs] [PATCH 4/5] New API: add btrfs_filesystem_defragment

Hu Tao hutao at cn.fujitsu.com
Wed Jan 14 08:58:24 UTC 2015


On Tue, Jan 13, 2015 at 02:00:13PM +0100, Pino Toscano wrote:
> On Friday 26 December 2014 16:17:48 Hu Tao wrote:
> > Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
> > ---
> >  daemon/btrfs.c       | 32 ++++++++++++++++++++++++++++++++
> >  generator/actions.ml | 20 ++++++++++++++++++++
> >  src/MAX_PROC_NR      |  2 +-
> >  3 files changed, 53 insertions(+), 1 deletion(-)
> > 
> > diff --git a/daemon/btrfs.c b/daemon/btrfs.c
> > index 6c74892..32b1b05 100644
> > --- a/daemon/btrfs.c
> > +++ b/daemon/btrfs.c
> > @@ -1431,3 +1431,35 @@ do_btrfs_filesystem_get_label (const char *path)
> >  
> >    return out;
> >  }
> > +
> > +int
> > +do_btrfs_filesystem_defragment (const char *path)
> > +{
> > +  const size_t MAX_ARGS = 64;
> > +  const char *argv[MAX_ARGS];
> > +  size_t i = 0;
> > +  CLEANUP_FREE char *path_buf = NULL;
> > +  CLEANUP_FREE char *err = NULL;
> > +  CLEANUP_FREE char *out = NULL;
> > +  int r;
> > +
> > +  path_buf = sysroot_path (path);
> > +  if (path_buf == NULL) {
> > +    reply_with_perror ("malloc");
> > +    return -1;
> > +  }
> > +
> > +  ADD_ARG (argv, i, str_btrfs);
> > +  ADD_ARG (argv, i, "filesystem");
> > +  ADD_ARG (argv, i, "defragment");
> > +  ADD_ARG (argv, i, path_buf);
> > +  ADD_ARG (argv, i, NULL);
> > +
> > +  r = commandv (&out, &err, argv);
> > +  if (r == -1) {
> > +    reply_with_error ("%s: %s", path, err);
> > +    return -1;
> > +  }
> > +
> > +  return 0;
> > +}
> 
> Generally this sounds fine for me.
> 
> It seems that directories are not recursively handled by default
> (-r is needed); should btrfs_filesystem_defragment do that
> automatically?

Agreed.

> 
> What about the options like -f (to flush) and -c (to compress), are
> they options which get used often/usually, and thus worthy to be
> passed as optargs?

Agreed too, as optargs.

> 
> > diff --git a/generator/actions.ml b/generator/actions.ml
> > index 5223eb8..4b24f8a 100644
> > --- a/generator/actions.ml
> > +++ b/generator/actions.ml
> > @@ -12296,6 +12296,26 @@ Check or repair a btrfs filesystem offline." };
> >      longdesc = "\
> >  Get a btrfs filesystem's label." };
> >  
> > +  { defaults with
> > +    name = "btrfs_filesystem_defragment";
> > +    style = RErr, [Pathname "path"], [];
> > +    proc_nr = Some 438;
> > +    optional = Some "btrfs"; camel_name = "BTRFSFilesystemDefragment";
> > +    tests = [
> > +      InitPartition, Always, TestRun (
> > +        [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
> > +         ["mount"; "/dev/sda1"; "/"];
> > +         ["btrfs_filesystem_defragment"; "/"]]), [];
> > +      InitPartition, Always, TestRun (
> > +        [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
> > +         ["mount"; "/dev/sda1"; "/"];
> > +         ["touch"; "/hello"];
> > +         ["btrfs_filesystem_defragment"; "/hello"]]), [];
> > +    ];
> > +    shortdesc = "defragment a file or directory";
> > +    longdesc = "\
> > +Defragment a file or directory." };
> 
> Maybe it would be worth mentioning btrfs in the descriptions.

Okay.

Regards,
Hu




More information about the Libguestfs mailing list