diff options
author | Wanlong Gao <gaowanlong@cn.fujitsu.com> | 2012-08-01 17:02:07 +0800 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-08-02 10:20:57 +0100 |
commit | d40b5028762eeaf9235165301bd76d468b7e251c (patch) | |
tree | f91247e3e4390ac99cf91c2fdc44e08228905fa0 | |
parent | 9b9c3721146b734fb71721875d80e5f2db1b7b7b (diff) | |
download | libguestfs-d40b5028762eeaf9235165301bd76d468b7e251c.tar.gz libguestfs-d40b5028762eeaf9235165301bd76d468b7e251c.tar.xz libguestfs-d40b5028762eeaf9235165301bd76d468b7e251c.zip |
xfs: add new api xfs-growfs
New api xfs_growfs for expanding a XFS filesystem.
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
-rw-r--r-- | daemon/xfs.c | 111 | ||||
-rw-r--r-- | generator/generator_actions.ml | 27 | ||||
-rw-r--r-- | gobject/Makefile.inc | 6 | ||||
-rw-r--r-- | po/POTFILES | 1 | ||||
-rw-r--r-- | src/MAX_PROC_NR | 2 |
5 files changed, 144 insertions, 3 deletions
diff --git a/daemon/xfs.c b/daemon/xfs.c index e0f0062a..73ba791e 100644 --- a/daemon/xfs.c +++ b/daemon/xfs.c @@ -28,6 +28,8 @@ #include "actions.h" #include "optgroups.h" +#define MAX_ARGS 64 + int optgroup_xfs_available (void) { @@ -348,3 +350,112 @@ error: free_strings (lines); return ret; } + +char * +do_xfs_growfs (const char *path, + int datasec, int logsec, int rtsec, + int64_t datasize, int64_t logsize, int64_t rtsize, + int64_t rtextsize, int32_t maxpct) +{ + int r; + char *buf; + char *out = NULL, *err = NULL; + const char *argv[MAX_ARGS]; + char datasize_s[64]; + char logsize_s[64]; + char rtsize_s[64]; + char rtextsize_s[64]; + char maxpct_s[32]; + size_t i = 0; + + buf = sysroot_path (path); + if (buf == NULL) { + reply_with_perror ("malloc"); + return NULL; + } + + ADD_ARG (argv, i, "xfs_growfs"); + + /* Optional arguments */ + if (!(optargs_bitmask & GUESTFS_XFS_GROWFS_DATASEC_BITMASK)) + datasec = 0; + if (!(optargs_bitmask & GUESTFS_XFS_GROWFS_LOGSEC_BITMASK)) + logsec = 0; + if (!(optargs_bitmask & GUESTFS_XFS_GROWFS_RTSEC_BITMASK)) + rtsec = 0; + + if (datasec) + ADD_ARG (argv, i, "-d"); + if (logsec) + ADD_ARG (argv, i, "-l"); + if (rtsec) + ADD_ARG (argv, i, "-r"); + + if (optargs_bitmask & GUESTFS_XFS_GROWFS_DATASIZE_BITMASK) { + if (datasize < 0) { + reply_with_error ("datasize must be >= 0"); + goto error; + } + snprintf (datasize_s, sizeof datasize_s, "%" PRIi64, datasize); + ADD_ARG (argv, i, "-D"); + ADD_ARG (argv, i, datasize_s); + } + + if (optargs_bitmask & GUESTFS_XFS_GROWFS_LOGSIZE_BITMASK) { + if (logsize < 0) { + reply_with_error ("logsize must be >= 0"); + goto error; + } + snprintf(logsize_s, sizeof logsize_s, "%" PRIi64, logsize); + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, logsize_s); + } + + if (optargs_bitmask & GUESTFS_XFS_GROWFS_RTSIZE_BITMASK) { + if (rtsize < 0) { + reply_with_error ("rtsize must be >= 0"); + goto error; + } + snprintf(rtsize_s, sizeof rtsize_s, "%" PRIi64, rtsize); + ADD_ARG (argv, i, "-R"); + ADD_ARG (argv, i, rtsize_s); + } + + if (optargs_bitmask & GUESTFS_XFS_GROWFS_RTEXTSIZE_BITMASK) { + if (rtextsize < 0) { + reply_with_error ("rtextsize must be >= 0"); + goto error; + } + snprintf(rtextsize_s, sizeof rtextsize_s, "%" PRIi64, rtextsize); + ADD_ARG (argv, i, "-e"); + ADD_ARG (argv, i, rtextsize_s); + } + + if (optargs_bitmask & GUESTFS_XFS_GROWFS_MAXPCT_BITMASK) { + if (maxpct < 0) { + reply_with_error ("maxpct must be >= 0"); + goto error; + } + snprintf(maxpct_s, sizeof maxpct_s, "%" PRIi32, maxpct); + ADD_ARG (argv, i, "-m"); + ADD_ARG (argv, i, maxpct_s); + } + + ADD_ARG (argv, i, buf); + ADD_ARG (argv, i, NULL); + + r = commandv (&out, &err, argv); + free (buf); + if (r == -1) { + reply_with_error ("%s: %s", path, err); + goto error; + } + + free (err); + return out; + +error: + if (buf) free (buf); + if (err) free (err); + return NULL; +} diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index e4956f7a..555157cb 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -9051,6 +9051,33 @@ This returns the kernel version of the appliance, where this is available. This information is only useful for debugging. Nothing in the returned structure is defined by the API." }; + { defaults with + name = "xfs_growfs"; + style = RString "info", [Pathname "path"], [OBool "datasec"; OBool "logsec"; OBool "rtsec"; OInt64 "datasize"; OInt64 "logsize"; OInt64 "rtsize"; OInt64 "rtextsize"; OInt "maxpct"]; + proc_nr = Some 343; + optional = Some "xfs"; + tests = [ + InitEmpty, IfAvailable "xfs", TestOutputStruct ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["pvcreate"; "/dev/sda1"]; + ["vgcreate"; "VG"; "/dev/sda1"]; + ["lvcreate"; "LV"; "VG"; "40"]; + ["mkfs"; "xfs"; "/dev/VG/LV"; ""; "NOARG"; ""; ""]; + ["lvresize"; "/dev/VG/LV"; "80"]; + ["mount_options"; ""; "/dev/VG/LV"; "/"]; + ["xfs_growfs"; "/"; "true"; "false"; "false"; ""; ""; ""; ""; ""]; + ["xfs_info"; "/"]], + [CompareWithInt ("xfs_blocksize", 4096); + ]) + ]; + shortdesc = "expand an existing XFS filesystem"; + longdesc = "\ +Grow the XFS filesystem mounted at C<path>. + +The returned struct contains geometry information. Missing +fields are returned as C<-1> (for numeric fields) or empty +string." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index 7a60933b..3129275d 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -65,7 +65,8 @@ guestfs_gobject_headers= \ include/guestfs-gobject/optargs-mkfs_btrfs.h \ include/guestfs-gobject/optargs-set_e2attrs.h \ include/guestfs-gobject/optargs-btrfs_fsck.h \ - include/guestfs-gobject/optargs-fstrim.h + include/guestfs-gobject/optargs-fstrim.h \ + include/guestfs-gobject/optargs-xfs_growfs.h guestfs_gobject_sources= \ src/session.c \ @@ -112,4 +113,5 @@ guestfs_gobject_sources= \ src/optargs-mkfs_btrfs.c \ src/optargs-set_e2attrs.c \ src/optargs-btrfs_fsck.c \ - src/optargs-fstrim.c + src/optargs-fstrim.c \ + src/optargs-xfs_growfs.c diff --git a/po/POTFILES b/po/POTFILES index cdb873e3..ada0da87 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -160,6 +160,7 @@ gobject/src/optargs-set_e2attrs.c gobject/src/optargs-tune2fs.c gobject/src/optargs-umount.c gobject/src/optargs-umount_local.c +gobject/src/optargs-xfs_growfs.c gobject/src/session.c gobject/src/struct-application.c gobject/src/struct-btrfssubvolume.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index c9693eb7..fe2cd8b0 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -342 +343 |