[Libguestfs] [PATCH] NEW API: add new api xfs_info

Richard W.M. Jones rjones at redhat.com
Mon Jul 9 09:08:17 UTC 2012


On Mon, Jul 09, 2012 at 04:37:52PM +0800, Wanlong Gao wrote:
> Add xfs_info to show the geometry of the xfs filesystem.
> 
> Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
> ---
> 
> Hi Rich,
> 
> This patch add xfs_info, and start the
> xfs support work.
> I'd like to add the xfs support, like
> xfs_growfs, xfs_io, xfs_db, xfs_repair etc.
> Any thoughts?

Yes, it's a very good idea.

> Thanks,
> Wanlong Gao
> 
> 
>  daemon/Makefile.am             |  1 +
>  daemon/xfs.c                   | 69 ++++++++++++++++++++++++++++++++++++++++++
>  generator/generator_actions.ml |  6 ++++
>  src/MAX_PROC_NR                |  2 +-
>  5 files changed, 78 insertions(+), 2 deletions(-)
>  create mode 100644 daemon/xfs.c
> 
> diff --git a/daemon/Makefile.am b/daemon/Makefile.am
> index 9e2a633..afe8874 100644
> --- a/daemon/Makefile.am
> +++ b/daemon/Makefile.am
> @@ -165,6 +165,7 @@ guestfsd_SOURCES = \
>  	utimens.c \
>  	wc.c \
>  	xattr.c \
> +	xfs.c \
>  	zero.c \
>  	zerofree.c
>  guestfsd_LDADD = \
> diff --git a/daemon/xfs.c b/daemon/xfs.c
> new file mode 100644
> index 0000000..8b60b19
> --- /dev/null
> +++ b/daemon/xfs.c
> @@ -0,0 +1,69 @@
> +/* libguestfs - the guestfsd daemon
> + * Copyright (C) 2012 Fujitsu Limited.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program 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 General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#include <config.h>
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <inttypes.h>
> +#include <string.h>
> +#include <unistd.h>
> +
> +#include "guestfs_protocol.h"
> +#include "daemon.h"
> +#include "c-ctype.h"
> +#include "actions.h"
> +
> +int
> +optgroup_xfs_available (void)
> +{
> +  return prog_exists ("mkfs.xfs");
> +}
> +
> +char *
> +do_xfs_info (const char *path)
> +{
> +  int r;
> +  char *buf;
> +  char *out, *err;
> +
> +  if (do_is_dir (path)) {
> +    buf = sysroot_path (path);
> +    if (!buf) {
> +      reply_with_perror ("malloc");
> +      return NULL;
> +    }
> +  } else {
> +    buf = strdup(path);
> +    if (!buf) {
> +      reply_with_perror ("strdup");
> +      return NULL;
> +    }
> +  }
> +
> +  r = command (&out, &err, "xfs_info", buf, NULL);
> +  free (buf);
> +  if (r == -1) {
> +    reply_with_error ("%s", err);
> +    free (err);
> +    free (out);
> +    return NULL;
> +  }
> +
> +  return out;

xfs_info has structured output:

  $ virt-rescue --scratch
  ><rescue> parted /dev/vda mklabel msdos
  ><rescue> parted -- /dev/vda mkpart primary 32s -32s
  ><rescue> mkfs.xfs /dev/vda1 
  ><rescue> file -bsL /dev/vda1 
  SGI XFS filesystem data (blksz 4096, inosz 256, v2 dirs)
  ><rescue> mount /dev/vda1 /sysroot 
  [  136.526415] SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled
  [  136.539163] XFS (vda1): Mounting Filesystem
  [  136.615296] XFS (vda1): Ending clean mount
  ><rescue> xfs_info /dev/vda1 
  meta-data=/dev/vda1              isize=256    agcount=4, agsize=655358 blks
           =                       sectsz=512   attr=2
  data     =                       bsize=4096   blocks=2621432, imaxpct=25
           =                       sunit=0      swidth=0 blks
  naming   =version 2              bsize=4096   ascii-ci=0
  log      =internal               bsize=4096   blocks=2560, version=2
           =                       sectsz=512   sunit=0 blks, lazy-count=1
  realtime =none                   extsz=4096   blocks=0, rtextents=0

It's weird output, but let's parse and return that instead of dumping
the problem onto every caller.

> +}
> diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
> index 5baa9b2..ba0b0de 100644
> --- a/generator/generator_actions.ml
> +++ b/generator/generator_actions.ml
> @@ -7374,6 +7374,12 @@ be returned if you called C<guestfs_list_devices>.
>  To find out the maximum number of devices that could be added,
>  call C<guestfs_max_disks>.");
>  
> +  ("xfs_info", (RString "information", [String "path"], []), 337, [Optional "xfs"],

"path" isn't a string, it's a filename.  And the return type has to
be changed to reflect the structure being returned.

> +   [],

I think it'd be good to add test(s) here.

> +   "print out the geometry of the filesystem",

Only for XFS filesystems, so perhaps a better description is:

  "get geometry of XFS filesystem"

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v




More information about the Libguestfs mailing list