[PATCH] NEW API: add new api xfs_info
Add xfs_info to show the geometry of the xfs filesystem. Signed-off-by: Wanlong Gao <gaowanlong@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? 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; +} 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"], + [], + "print out the geometry of the filesystem", + "\ +Thie function can print out the geometry of an mounted XFS filesystem."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index e64f24d..f59a90f 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -336 +337 -- 1.7.11.rc0
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@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;
<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
xfs_info has structured output: $ virt-rescue --scratch 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
On 07/09/2012 05:08 PM, Richard W.M. Jones wrote:
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@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:
<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
$ virt-rescue --scratch 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.
Sorry, I can't understand what do you mean here, it's the original output of xfs_info.
+} 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.
You mean not a simple string?
+ [],
I think it'd be good to add test(s) here.
Ok, will do.
+ "print out the geometry of the filesystem",
Only for XFS filesystems, so perhaps a better description is:
"get geometry of XFS filesystem"
OK, will update. Thanks, Wanlong Gao
Rich.
On Mon, Jul 09, 2012 at 05:15:47PM +0800, Wanlong Gao wrote:
<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.
Sorry, I can't understand what do you mean here, it's the original output of xfs_info.
Sure, but what's the caller going to do with this output (assuming the caller is a program)? If it wants to find, eg, the 'bsize' field then it has to parse this, so we're pushing the problem of parsing the output up to every program. BTW we can use augeas to handle parsing, since these useful APIs were added to augeas recently: https://www.redhat.com/archives/augeas-devel/2012-May/msg00035.html 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
On 07/09/2012 05:28 PM, Richard W.M. Jones wrote:
On Mon, Jul 09, 2012 at 05:15:47PM +0800, Wanlong Gao wrote:
<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.
Sorry, I can't understand what do you mean here, it's the original output of xfs_info.
Sure, but what's the caller going to do with this output (assuming the caller is a program)?
If it wants to find, eg, the 'bsize' field then it has to parse this, so we're pushing the problem of parsing the output up to every program.
BTW we can use augeas to handle parsing, since these useful APIs were added to augeas recently:
https://www.redhat.com/archives/augeas-devel/2012-May/msg00035.html
Got it, thank you for explanation. I'll try. Wanlong Gao
Rich.
Add xfs_info to show the geometry of the xfs filesystem. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- Hi Rich, This is the v2 version, please help reviewing. Formated the output, but seems that there's also something wrong. And I'll add self test in next version. Thanks, Wanlong Gao daemon/Makefile.am | 1 + daemon/xfs.c | 228 +++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 6 ++ po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 5 files changed, 237 insertions(+), 1 deletion(-) 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..ea3782b --- /dev/null +++ b/daemon/xfs.c @@ -0,0 +1,228 @@ +/* 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; + int i, j; + char *buf; + char *out = NULL, *err = NULL; + char **lines = NULL; + char *line = NULL, *p = NULL, *s = NULL; + char strbuf[BUFSIZ]; + + DECLARE_STRINGSBUF (ret); + + 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); + goto error; + } + + lines = split_lines (out); + if (lines == NULL) + goto error; + + const char *md[] = {"meta-data", "isize", "agcount", "agsize", + "sectsz", "attr", NULL}; + const char *data[] = {"data", "bsize", "blocks", "imaxpct", + "sunit", "swidth", NULL}; + const char *name[] = {"naming", "bsize", "ascii-ci", NULL}; + const char *log[] = {"log", "bsize", "blocks", "version", + "sectsz", "sunit", "lazy-count", NULL}; + const char *rt[] = {"realtime", "extsz", "blocks", "rtextents", NULL}; + + for (j = 0; j < 2; j++) { + line = lines[j]; + if (!line) + goto error; + s = line; + for (i = 0; md[i] != NULL; i++) { + p = strstr(s, md[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + if (add_string (&ret, md[i]) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf (strbuf, "%s.%s", md[0], md[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + } + + for (j = 2; j < 4; j++) { + line = lines[j]; + if (!line) + goto error; + s = line; + for (i = 1; data[i] != NULL; i++) { + p = strstr(s, data[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + sprintf(strbuf, "%s.%s", data[0], data[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + + line = lines[4]; + if (!line) + goto error; + s = line; + for (i = 0; name[i] != NULL; i++) { + p = strstr(s, name[i]); + if (p) { + while (*p != '=') p++; + p++; + if (i == 0) { + while (*p != ' ') p++; p++; + } + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + sprintf(strbuf, "%s.%s", name[i], "version"); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf(strbuf, "%s.%s", name[0], name[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + + + for (j = 5; j < 7; j++) { + line = lines[j]; + if (!line) + goto error; + s = line; + for (i = 0; log[i] != NULL; i++) { + p = strstr(s, log[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + if (add_string (&ret, log[i]) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf(strbuf, "%s.%s", log[0], log[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + } + + + line = lines[7]; + if (!line) + goto error; + s = line; + for (i = 0; rt[i] != NULL; i++) { + p = strstr(s, rt[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + if (add_string (&ret, rt[i]) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf(strbuf, "%s.%s", rt[0], rt[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + + free (out); + free (err); + free_strings (lines); + + if (end_stringsbuf (&ret) == -1) + return NULL; + + return ret.argv; + +error: + free (out); + free (err); + free_strings (lines); + if (ret.argv != NULL) + free_stringslen (ret.argv, ret.size); + return NULL; +} diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 5baa9b2..e4cbee0 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", (RHashtable "info", [String "path"], []), 337, [Optional "xfs"], + [], + "print out the geometry of the filesystem", + "\ +Thie function can print out the geometry of an mounted XFS filesystem."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/po/POTFILES b/po/POTFILES index 747b341..8217314 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -84,6 +84,7 @@ daemon/upload.c daemon/utimens.c daemon/wc.c daemon/xattr.c +daemon/xfs.c daemon/zero.c daemon/zerofree.c df/df.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index e64f24d..f59a90f 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -336 +337 -- 1.7.11.1.165.g299666c
On Thu, Jul 12, 2012 at 11:15:57AM +0800, Wanlong Gao wrote:
Add xfs_info to show the geometry of the xfs filesystem.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> ---
Hi Rich,
This is the v2 version, please help reviewing. Formated the output, but seems that there's also something wrong. And I'll add self test in next version.
Also you'll need to change it for the new way that functions are defined in the generator (see previous email). Sorry, I can only do a quick review now as I'm having all the electricity turned off this morning.
Thanks, Wanlong Gao
daemon/Makefile.am | 1 + daemon/xfs.c | 228 +++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 6 ++ po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 5 files changed, 237 insertions(+), 1 deletion(-) 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..ea3782b --- /dev/null +++ b/daemon/xfs.c @@ -0,0 +1,228 @@ +/* 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; + int i, j; + char *buf; + char *out = NULL, *err = NULL; + char **lines = NULL; + char *line = NULL, *p = NULL, *s = NULL; + char strbuf[BUFSIZ]; + + DECLARE_STRINGSBUF (ret); + + 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); + goto error; + } + + lines = split_lines (out); + if (lines == NULL) + goto error; + + const char *md[] = {"meta-data", "isize", "agcount", "agsize", + "sectsz", "attr", NULL}; + const char *data[] = {"data", "bsize", "blocks", "imaxpct", + "sunit", "swidth", NULL}; + const char *name[] = {"naming", "bsize", "ascii-ci", NULL}; + const char *log[] = {"log", "bsize", "blocks", "version", + "sectsz", "sunit", "lazy-count", NULL}; + const char *rt[] = {"realtime", "extsz", "blocks", "rtextents", NULL}; + + for (j = 0; j < 2; j++) { + line = lines[j]; + if (!line) + goto error; + s = line; + for (i = 0; md[i] != NULL; i++) { + p = strstr(s, md[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + if (add_string (&ret, md[i]) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf (strbuf, "%s.%s", md[0], md[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + } + + for (j = 2; j < 4; j++) { + line = lines[j]; + if (!line) + goto error; + s = line; + for (i = 1; data[i] != NULL; i++) { + p = strstr(s, data[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + sprintf(strbuf, "%s.%s", data[0], data[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + + line = lines[4]; + if (!line) + goto error; + s = line; + for (i = 0; name[i] != NULL; i++) { + p = strstr(s, name[i]); + if (p) { + while (*p != '=') p++; + p++; + if (i == 0) { + while (*p != ' ') p++; p++; + } + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + sprintf(strbuf, "%s.%s", name[i], "version"); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf(strbuf, "%s.%s", name[0], name[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + + + for (j = 5; j < 7; j++) { + line = lines[j]; + if (!line) + goto error; + s = line; + for (i = 0; log[i] != NULL; i++) { + p = strstr(s, log[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + if (add_string (&ret, log[i]) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf(strbuf, "%s.%s", log[0], log[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + } + + + line = lines[7]; + if (!line) + goto error; + s = line; + for (i = 0; rt[i] != NULL; i++) { + p = strstr(s, rt[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + if (add_string (&ret, rt[i]) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf(strbuf, "%s.%s", rt[0], rt[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + + free (out); + free (err); + free_strings (lines); + + if (end_stringsbuf (&ret) == -1) + return NULL; + + return ret.argv; + +error: + free (out); + free (err); + free_strings (lines); + if (ret.argv != NULL) + free_stringslen (ret.argv, ret.size); + return NULL; +}
It seems like a reasonable approach given the complex and frankly obscure output of the xfs_info command. Did you have a look at the sources of XFS to see if the format is fixed or can change? It might also be worth considering using an 'RStruct' instead of 'RHashtable', although it mainly depends on whether the output can change in future or not.
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 5baa9b2..e4cbee0 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", (RHashtable "info", [String "path"], []), 337, [Optional "xfs"], + [], + "print out the geometry of the filesystem", + "\ +Thie function can print out the geometry of an mounted XFS filesystem."); + ]
let all_functions = non_daemon_functions @ daemon_functions diff --git a/po/POTFILES b/po/POTFILES index 747b341..8217314 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -84,6 +84,7 @@ daemon/upload.c daemon/utimens.c daemon/wc.c daemon/xattr.c +daemon/xfs.c daemon/zero.c daemon/zerofree.c df/df.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index e64f24d..f59a90f 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -336 +337 -- 1.7.11.1.165.g299666c
Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
On 07/12/2012 04:06 PM, Richard W.M. Jones wrote:
On Thu, Jul 12, 2012 at 11:15:57AM +0800, Wanlong Gao wrote:
Add xfs_info to show the geometry of the xfs filesystem.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> ---
Hi Rich,
This is the v2 version, please help reviewing. Formated the output, but seems that there's also something wrong. And I'll add self test in next version.
Also you'll need to change it for the new way that functions are defined in the generator (see previous email).
Sorry, I can only do a quick review now as I'm having all the electricity turned off this morning.
Thanks, Wanlong Gao
daemon/Makefile.am | 1 + daemon/xfs.c | 228 +++++++++++++++++++++++++++++++++++++++++ generator/generator_actions.ml | 6 ++ po/POTFILES | 1 + src/MAX_PROC_NR | 2 +- 5 files changed, 237 insertions(+), 1 deletion(-) 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..ea3782b --- /dev/null +++ b/daemon/xfs.c @@ -0,0 +1,228 @@ +/* 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; + int i, j; + char *buf; + char *out = NULL, *err = NULL; + char **lines = NULL; + char *line = NULL, *p = NULL, *s = NULL; + char strbuf[BUFSIZ]; + + DECLARE_STRINGSBUF (ret); + + 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); + goto error; + } + + lines = split_lines (out); + if (lines == NULL) + goto error; + + const char *md[] = {"meta-data", "isize", "agcount", "agsize", + "sectsz", "attr", NULL}; + const char *data[] = {"data", "bsize", "blocks", "imaxpct", + "sunit", "swidth", NULL}; + const char *name[] = {"naming", "bsize", "ascii-ci", NULL}; + const char *log[] = {"log", "bsize", "blocks", "version", + "sectsz", "sunit", "lazy-count", NULL}; + const char *rt[] = {"realtime", "extsz", "blocks", "rtextents", NULL}; + + for (j = 0; j < 2; j++) { + line = lines[j]; + if (!line) + goto error; + s = line; + for (i = 0; md[i] != NULL; i++) { + p = strstr(s, md[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + if (add_string (&ret, md[i]) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf (strbuf, "%s.%s", md[0], md[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + } + + for (j = 2; j < 4; j++) { + line = lines[j]; + if (!line) + goto error; + s = line; + for (i = 1; data[i] != NULL; i++) { + p = strstr(s, data[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + sprintf(strbuf, "%s.%s", data[0], data[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + + line = lines[4]; + if (!line) + goto error; + s = line; + for (i = 0; name[i] != NULL; i++) { + p = strstr(s, name[i]); + if (p) { + while (*p != '=') p++; + p++; + if (i == 0) { + while (*p != ' ') p++; p++; + } + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + sprintf(strbuf, "%s.%s", name[i], "version"); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf(strbuf, "%s.%s", name[0], name[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + + + for (j = 5; j < 7; j++) { + line = lines[j]; + if (!line) + goto error; + s = line; + for (i = 0; log[i] != NULL; i++) { + p = strstr(s, log[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + if (add_string (&ret, log[i]) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf(strbuf, "%s.%s", log[0], log[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + } + + + line = lines[7]; + if (!line) + goto error; + s = line; + for (i = 0; rt[i] != NULL; i++) { + p = strstr(s, rt[i]); + if (p) { + while (*p != '=') p++; + p++; + s = p; + while (*s != ' ' && *s != ',') s++; + *s = '\0'; + s++; + if (i == 0) { + if (add_string (&ret, rt[i]) == -1 || + add_string (&ret, p) == -1) goto error; + } else { + sprintf(strbuf, "%s.%s", rt[0], rt[i]); + if (add_string (&ret, strbuf) == -1 || + add_string (&ret, p) == -1) goto error; + } + } + } + + free (out); + free (err); + free_strings (lines); + + if (end_stringsbuf (&ret) == -1) + return NULL; + + return ret.argv; + +error: + free (out); + free (err); + free_strings (lines); + if (ret.argv != NULL) + free_stringslen (ret.argv, ret.size); + return NULL; +}
It seems like a reasonable approach given the complex and frankly obscure output of the xfs_info command.
Did you have a look at the sources of XFS to see if the format is fixed or can change? It might also be worth considering using an 'RStruct' instead of 'RHashtable', although it mainly depends on whether the output can change in future or not.
Yes, it's defined like this. printf(_( "meta-data=%-22s isize=%-6u agcount=%u, agsize=%u blks\n" " =%-22s sectsz=%-5u attr=%u\n" "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n" " =%-22s sunit=%-6u swidth=%u blks\n" "naming =version %-14u bsize=%-6u ascii-ci=%d\n" "log =%-22s bsize=%-6u blocks=%u, version=%u\n" " =%-22s sectsz=%-5u sunit=%u blks, lazy-count=%u\n" "realtime =%-22s extsz=%-6u blocks=%llu, rtextents=%llu\n"), Thanks, Wanlong Gao
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index 5baa9b2..e4cbee0 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", (RHashtable "info", [String "path"], []), 337, [Optional "xfs"], + [], + "print out the geometry of the filesystem", + "\ +Thie function can print out the geometry of an mounted XFS filesystem."); + ]
let all_functions = non_daemon_functions @ daemon_functions diff --git a/po/POTFILES b/po/POTFILES index 747b341..8217314 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -84,6 +84,7 @@ daemon/upload.c daemon/utimens.c daemon/wc.c daemon/xattr.c +daemon/xfs.c daemon/zero.c daemon/zerofree.c df/df.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index e64f24d..f59a90f 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -336 +337 -- 1.7.11.1.165.g299666c
Rich.
On Thu, Jul 12, 2012 at 04:37:59PM +0800, Wanlong Gao wrote:
Yes, it's defined like this.
printf(_( "meta-data=%-22s isize=%-6u agcount=%u, agsize=%u blks\n" " =%-22s sectsz=%-5u attr=%u\n" "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n" " =%-22s sunit=%-6u swidth=%u blks\n" "naming =version %-14u bsize=%-6u ascii-ci=%d\n" "log =%-22s bsize=%-6u blocks=%u, version=%u\n" " =%-22s sectsz=%-5u sunit=%u blks, lazy-count=%u\n" "realtime =%-22s extsz=%-6u blocks=%llu, rtextents=%llu\n"),
It really is the most bizarre output format imaginable! What do you think about using a struct then? It's probably easier than returning a hash table, but there is no room for changing the API later if, eg., extra fields are added. An example of an API that added a new struct type: https://github.com/libguestfs/libguestfs/commit/a43f35f5bb7c40b000083cd8be5c... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Add xfs_info to show the geometry of the xfs filesystem. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- Hi Rich, This version use the RStruct as you said, but I also got some thing wrong, please help reviewing and give some advises about fixing or debugging. Thanks, Wanlong Gao daemon/Makefile.am | 1 + daemon/xfs.c | 306 +++++++++++++++++++++++++++++++ generator/generator_actions.ml | 6 + generator/generator_structs.ml | 30 +++ gobject/Makefile.inc | 2 + java/Makefile.inc | 1 + java/com/redhat/et/libguestfs/.gitignore | 1 + po/POTFILES | 2 + src/MAX_PROC_NR | 2 +- 9 files changed, 350 insertions(+), 1 deletion(-) 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..47d027d --- /dev/null +++ b/daemon/xfs.c @@ -0,0 +1,306 @@ +/* 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"); +} + +static char * +split_strdup (char *string) +{ + char *end = string; + while (*end != ' ' && *end != ',') end++; + size_t len = end - string; + char *ret = malloc (len + 1); + if (!ret) { + reply_with_perror ("malloc"); + return NULL; + } + strncpy (ret, string, len); + ret[len] = '\0'; + fprintf(stderr, "%s\n", ret); + return ret; +} + +static int +parse_uint32 (uint32_t *ret, const char *str) +{ + uint32_t r; + + if (sscanf (str, "%" SCNu32, &r) != 1) { + reply_with_error ("cannot parse numeric field from isoinfo: %s", str); + return -1; + } + + *ret = r; + return 0; +} + +static int +parse_uint64 (uint64_t *ret, const char *str) +{ + uint64_t r; + + if (sscanf (str, "%" SCNu64, &r) != 1) { + reply_with_error ("cannot parse numeric field from isoinfo: %s", str); + return -1; + } + + *ret = r; + return 0; +} + +static guestfs_int_xfsinfo * +parse_xfs_info (char **lines) +{ + guestfs_int_xfsinfo *ret; + char *buf, *p; + size_t i; + + ret = calloc (1, sizeof *ret); + if (ret == NULL) { + reply_with_error ("calloc"); + return NULL; + } +#if 0 + ret->inodesize = (uint32_t) -1; + ret->agcount = (uint32_t) -1; + ret->agsize = (uint32_t) -1; + ret->sectsize = (uint32_t) -1; + ret->attr = (uint32_t) -1; + ret->blocksize = (uint32_t) -1; + ret->datablocks = (uint64_t) -1; + ret->imaxpct = (uint32_t) -1; + ret->sunit = (uint32_t) -1; + ret->swidth = (uint32_t) -1; + ret->dirversion = (uint32_t) -1; + ret->dirblocksize = (uint32_t) -1; + ret->cimode = (uint32_t) -1; + ret->logblocksize = (uint32_t) -1; + ret->logblocks = (uint32_t) -1; + ret->logversion = (uint32_t) -1; + ret->logsectsize = (uint32_t) -1; + ret->logsunit = (uint32_t) -1; + ret->lazycount = (uint32_t) -1; + ret->rtextsize = (uint32_t) -1; + ret->rtblocks = (uint64_t) -1; + ret->rtextents = (uint64_t) -1; +#endif + + for (i = 0; lines[i] != NULL; ++i) { + if (p = strstr (lines[i], "meta-data=")) { + ret->mntpoint = split_strdup (p + 10); + if (ret->mntpoint == NULL) goto error; + } else if (p = strstr (lines[i], "isize=")) { + buf = split_strdup (p + 6); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->inodesize, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "agcount=")) { + buf = split_strdup (p + 8); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->agcount, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "agsize=")) { + buf = split_strdup (p + 7); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->agsize, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "sectsz=")) { + buf = split_strdup (p + 7); + if (buf == NULL) goto error; + if (i == 1) + if (parse_uint32 (&ret->sectsize, buf) == -1) + goto error; + else if (i == 6) + if (parse_uint32 (&ret->logsectsize, buf) == -1) + goto error; + else goto error; + } else if (p = strstr (lines[i], "attr=")) { + buf = split_strdup (p + 5); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->attr, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "bsize=")) { + buf = split_strdup (p + 6); + if (buf == NULL) goto error; + if (i == 2) + if (parse_uint32 (&ret->blocksize, buf) == -1) + goto error; + else if (i == 4) + if (parse_uint32 (&ret->dirblocksize, buf) == -1) + goto error; + else if (i == 5) + if (parse_uint32 (&ret->logblocksize, buf) == -1) + goto error; + else goto error; + } else if (p = strstr (lines[i], "blocks=")) { + buf = split_strdup (p + 7); + if (buf == NULL) goto error; + if (i == 2) + if (parse_uint64 (&ret->datablocks, buf) == -1) + goto error; + else if (i == 5) + if (parse_uint32 (&ret->logblocks, buf) == -1) + goto error; + else if (i == 7) + if (parse_uint64 (&ret->rtblocks, buf) == -1) + goto error; + else goto error; + } else if (p = strstr (lines[i], "imaxpct=")) { + buf = split_strdup (p + 8); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->imaxpct, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "sunit=")) { + buf = split_strdup (p + 6); + if (buf == NULL) goto error; + if (i == 3) + if (parse_uint32 (&ret->sunit, buf) == -1) + goto error; + else if (i == 6) + if (parse_uint32 (&ret->logsunit, buf) == -1) + goto error; + else goto error; + } else if (p = strstr (lines[i], "swidth=")) { + buf = split_strdup (p + 7); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->swidth, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "naming =version ")) { + buf = split_strdup (p + 18); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->dirversion, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "ascii-ci=")) { + buf = split_strdup (p + 9); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->cimode, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "log =")) { + ret->logname = split_strdup (p + 10); + if (ret->logname == NULL) goto error; + } else if (p = strstr (lines[i], "version=")) { + buf = split_strdup (p + 8); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->logversion, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "lazy-count=")) { + buf = split_strdup (p + 11); + if (buf == NULL) goto error; + if (parse_uint32 (&ret->lazycount, buf) == -1) + goto error; + } else if (p = strstr (lines[i], "realtime =")) { + ret->rtname = split_strdup (p + 10); + if (ret->rtname == NULL) goto error; + } else if (p = strstr (lines[i], "rtextents=")) { + buf = split_strdup (p + 10); + if (buf == NULL) goto error; + if (parse_uint64 (&ret->rtextents, buf) == -1) + goto error; + } + } + + if (ret->mntpoint == NULL) { + ret->mntpoint = strdup (""); + if (ret->mntpoint == NULL) goto error; + } + if (ret->logname == NULL) { + ret->logname = strdup (""); + if (ret->logname == NULL) goto error; + } + if (ret->rtname == NULL) { + ret->rtname = strdup (""); + if (ret->rtname == NULL) goto error; + } + + return ret; + +error: + free (buf); + free (ret->mntpoint); + free (ret->logname); + free (ret->rtname); + free (ret); +} + +guestfs_int_xfsinfo * +do_xfs_info (const char *path) +{ + int r; + char *buf; + char *out = NULL, *err = NULL; + char **lines = NULL; + guestfs_int_xfsinfo *ret; + + 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); + goto error; + } + + lines = split_lines (out); + if (lines == NULL) + goto error; + + ret = parse_xfs_info (lines); + if (ret == NULL) + goto error; + + free (err); + free (out); + free_strings (lines); + return ret; + +error: + free (out); + free (err); + if (lines) + free_strings (lines); + return NULL; +} diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index beb2b3c..6d21351 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -8995,6 +8995,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", (RStruct ("info", "xfsinfo"), [Pathname "path"], []), 337, [Optional "xfs"], + [], + "get geometry of XFS filesystem", + "\ +Thie function can print out the geometry of an mounted XFS filesystem."); + ] (* Non-API meta-commands available only in guestfish. diff --git a/generator/generator_structs.ml b/generator/generator_structs.ml index 024bb3c..3dded35 100644 --- a/generator/generator_structs.ml +++ b/generator/generator_structs.ml @@ -213,6 +213,35 @@ let structs = [ "iso_volume_effective_t", FInt64; ]; + (* XFS info descriptor. *) + "xfsinfo", [ + "mntpoint", FString; + "inodesize", FUInt32; + "agcount", FUInt32; + "agsize", FUInt32; + "sectsize", FUInt32; + "attr", FUInt32; + "blocksize", FUInt32; + "datablocks", FUInt64; + "imaxpct", FUInt32; + "sunit", FUInt32; + "swidth", FUInt32; + "dirversion", FUInt32; + "dirblocksize", FUInt32; + "cimode", FInt32; + "logname", FString; + "logblocksize", FUInt32; + "logblocks", FUInt32; + "logversion", FUInt32; + "logsectsize", FUInt32; + "logsunit", FUInt32; + "lazycount", FUInt32; + "rtname", FString; + "rtextsize", FUInt32; + "rtblocks", FUInt64; + "rtextents", FUInt64; + ]; + (* /proc/mdstat information. See linux.git/drivers/md/md.c *) "mdstat", [ "mdstat_device", FString; @@ -243,6 +272,7 @@ let camel_structs = [ "partition", "Partition"; "application", "Application"; "isoinfo", "ISOInfo"; + "xfsinfo", "XFSInfo"; "mdstat", "MDStat"; "btrfssubvolume", "BTRFSSubvolume"; ] diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index e84236d..d70e106 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -36,6 +36,7 @@ guestfs_gobject_headers= \ include/guestfs-gobject/struct-partition.h \ include/guestfs-gobject/struct-application.h \ include/guestfs-gobject/struct-isoinfo.h \ + include/guestfs-gobject/struct-xfsinfo.h \ include/guestfs-gobject/struct-mdstat.h \ include/guestfs-gobject/struct-btrfssubvolume.h \ include/guestfs-gobject/optargs-internal_test.h \ @@ -80,6 +81,7 @@ guestfs_gobject_sources= \ src/struct-partition.c \ src/struct-application.c \ src/struct-isoinfo.c \ + src/struct-xfsinfo.c \ src/struct-mdstat.c \ src/struct-btrfssubvolume.c \ src/optargs-internal_test.c \ diff --git a/java/Makefile.inc b/java/Makefile.inc index efad2a0..da8de49 100644 --- a/java/Makefile.inc +++ b/java/Makefile.inc @@ -35,4 +35,5 @@ java_built_sources = \ com/redhat/et/libguestfs/VG.java \ com/redhat/et/libguestfs/Version.java \ com/redhat/et/libguestfs/XAttr.java \ + com/redhat/et/libguestfs/XFSInfo.java \ com/redhat/et/libguestfs/GuestFS.java diff --git a/java/com/redhat/et/libguestfs/.gitignore b/java/com/redhat/et/libguestfs/.gitignore index 9556d81..1034665 100644 --- a/java/com/redhat/et/libguestfs/.gitignore +++ b/java/com/redhat/et/libguestfs/.gitignore @@ -13,3 +13,4 @@ StatVFS.java VG.java Version.java XAttr.java +XFSInfo.java diff --git a/po/POTFILES b/po/POTFILES index 6c819d3..c8ec38d 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -84,6 +84,7 @@ daemon/upload.c daemon/utimens.c daemon/wc.c daemon/xattr.c +daemon/xfs.c daemon/zero.c daemon/zerofree.c df/df.c @@ -173,6 +174,7 @@ gobject/src/struct-stat.c gobject/src/struct-statvfs.c gobject/src/struct-version.c gobject/src/struct-xattr.c +gobject/src/struct-xfsinfo.c gobject/src/tristate.c inspector/virt-inspector.c java/com_redhat_et_libguestfs_GuestFS.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index e64f24d..f59a90f 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -336 +337 -- 1.7.11.1.165.g299666c
participants (2)
-
Richard W.M. Jones -
Wanlong Gao