Pino Toscano
2015-Jan-13 09:38 UTC
[Libguestfs] [PATCH] mkfs: add 'label' optional argument
Add the 'label' optional argument to the mkfs action, so it is possible to set a filesystem label direct when creating it. There may be filesystems not supporting changing the label of existing filesystems but only setting it at creation time, so this new optarg will help. Implement it for the most common filesystems (ext*, fat, ntfs, btrfs, xfs), giving an error for all the others, just like set_label does. --- daemon/mkfs.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- generator/actions.ml | 42 +++++++++++++++++++++++------------------- 2 files changed, 66 insertions(+), 21 deletions(-) diff --git a/daemon/mkfs.c b/daemon/mkfs.c index 95ab874..2994307 100644 --- a/daemon/mkfs.c +++ b/daemon/mkfs.c @@ -36,7 +36,7 @@ GUESTFSD_EXT_CMD(str_mkfs, mkfs); /* Takes optional arguments, consult optargs_bitmask. */ int do_mkfs (const char *fstype, const char *device, int blocksize, - const char *features, int inode, int sectorsize) + const char *features, int inode, int sectorsize, const char *label) { const char *argv[MAX_ARGS]; size_t i = 0; @@ -194,6 +194,47 @@ do_mkfs (const char *fstype, const char *device, int blocksize, ADD_ARG (argv, i, sectorsize_str); } + if (optargs_bitmask & GUESTFS_MKFS_LABEL_BITMASK) { + if (extfs) { + if (strlen (label) > EXT2_LABEL_MAX) { + reply_with_error ("%s: ext2 labels are limited to %d bytes", + label, EXT2_LABEL_MAX); + return -1; + } + + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, label); + } + else if (STREQ (fstype, "fat") || STREQ (fstype, "vfat") || + STREQ (fstype, "msdos")) { + ADD_ARG (argv, i, "-n"); + ADD_ARG (argv, i, label); + } + else if (STREQ (fstype, "ntfs")) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, label); + } + else if (STREQ (fstype, "xfs")) { + if (strlen (label) > XFS_LABEL_MAX) { + reply_with_error ("%s: xfs labels are limited to %d bytes", + label, XFS_LABEL_MAX); + return -1; + } + + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, label); + } + else if (STREQ (fstype, "btrfs")) { + ADD_ARG (argv, i, "-L"); + ADD_ARG (argv, i, label); + } + else { + reply_with_error ("don't know how to set the label for '%s' filesystems", + fstype); + return -1; + } + } + ADD_ARG (argv, i, device); ADD_ARG (argv, i, NULL); @@ -212,5 +253,5 @@ int do_mkfs_b (const char *fstype, int blocksize, const char *device) { optargs_bitmask = GUESTFS_MKFS_BLOCKSIZE_BITMASK; - return do_mkfs (fstype, device, blocksize, 0, 0, 0); + return do_mkfs (fstype, device, blocksize, 0, 0, 0, NULL); } diff --git a/generator/actions.ml b/generator/actions.ml index a6a6dad..96a9dd6 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -3324,7 +3324,7 @@ let daemon_functions = [ tests = [ InitEmpty, Always, TestResultString ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["mount"; "/dev/sda1"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents"), [] @@ -4138,12 +4138,12 @@ characters does I<not> work, even if the length is specified." }; tests = [ InitEmpty, Always, TestResult ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["mount"; "/dev/sda1"; "/"]; ["mounts"]], "is_device_list (ret, 1, \"/dev/sda1\")"), []; InitEmpty, Always, TestResult ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["mount"; "/dev/sda1"; "/"]; ["umount"; "/"; "false"; "false"]; ["mounts"]], "is_string_list (ret, 0)"), [] @@ -4186,9 +4186,9 @@ See also: C<guestfs_mountpoints>" }; ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; ["part_add"; "/dev/sda"; "p"; "204800"; "409599"]; ["part_add"; "/dev/sda"; "p"; "409600"; "-64"]; - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; - ["mkfs"; "ext2"; "/dev/sda2"; ""; "NOARG"; ""; ""]; - ["mkfs"; "ext2"; "/dev/sda3"; ""; "NOARG"; ""; ""]; + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; + ["mkfs"; "ext2"; "/dev/sda2"; ""; "NOARG"; ""; ""; "NOARG"]; + ["mkfs"; "ext2"; "/dev/sda3"; ""; "NOARG"; ""; ""; "NOARG"]; ["mount"; "/dev/sda1"; "/"]; ["mkdir"; "/mp1"]; ["mount"; "/dev/sda2"; "/mp1"]; @@ -5478,7 +5478,7 @@ the human-readable, canonical hex dump of the file." }; tests = [ InitNone, Always, TestResultString ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "ext3"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "ext3"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["mount"; "/dev/sda1"; "/"]; ["write"; "/new"; "test file"]; ["umount"; "/dev/sda1"; "false"; "false"]; @@ -5602,7 +5602,7 @@ are activated or deactivated." }; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV"; "VG"; "10"]; - ["mkfs"; "ext2"; "/dev/VG/LV"; ""; "NOARG"; ""; ""]; + ["mkfs"; "ext2"; "/dev/VG/LV"; ""; "NOARG"; ""; ""; "NOARG"]; ["mount"; "/dev/VG/LV"; "/"]; ["write"; "/new"; "test content"]; ["umount"; "/"; "false"; "false"]; @@ -5669,11 +5669,11 @@ Sleep for C<secs> seconds." }; tests = [ InitNone, Always, TestResult ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["ntfs_3g_probe"; "true"; "/dev/sda1"]], "ret == 0"), []; InitNone, Always, TestResult ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["ntfs_3g_probe"; "true"; "/dev/sda1"]], "ret == 12"), [] ]; shortdesc = "probe NTFS volume"; @@ -8543,7 +8543,11 @@ a file in the host and attach it as a device." }; tests = [ InitBasicFS, Always, TestResultString ( [["set_label"; "/dev/sda1"; "LTEST"]; - ["vfs_label"; "/dev/sda1"]], "LTEST"), [] + ["vfs_label"; "/dev/sda1"]], "LTEST"), []; + InitEmpty, Always, TestResultString ( + [["part_disk"; "/dev/sda"; "mbr"]; + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "test-label"]; + ["vfs_label"; "/dev/sda1"]], "test-label"), []; ]; shortdesc = "get the filesystem label"; longdesc = "\ @@ -9015,13 +9019,13 @@ See also C<guestfs_is_lv>, C<guestfs_canonical_device_name>." }; { defaults with name = "mkfs"; - style = RErr, [String "fstype"; Device "device"], [OInt "blocksize"; OString "features"; OInt "inode"; OInt "sectorsize"]; + style = RErr, [String "fstype"; Device "device"], [OInt "blocksize"; OString "features"; OInt "inode"; OInt "sectorsize"; OString "label"]; proc_nr = Some 278; once_had_no_optargs = true; tests = [ InitEmpty, Always, TestResultString ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["mount"; "/dev/sda1"; "/"]; ["write"; "/new"; "new file contents"]; ["cat"; "/new"]], "new file contents"), [] @@ -9761,7 +9765,7 @@ device." }; optional = Some "ntfs3g"; tests = [ InitPartition, Always, TestRun ( - [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["ntfsfix"; "/dev/sda1"; "false"]]), [] ]; shortdesc = "fix common errors and force Windows to check NTFS"; @@ -9820,7 +9824,7 @@ any existing contents of this device." }; [["set_label"; "/dev/sda1"; "testlabel"]; ["vfs_label"; "/dev/sda1"]], "testlabel"), []; InitPartition, IfAvailable "ntfs3g", TestResultString ( - [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["set_label"; "/dev/sda1"; "testlabel2"]; ["vfs_label"; "/dev/sda1"]], "testlabel2"), []; InitPartition, Always, TestLastFail ( @@ -10485,7 +10489,7 @@ call C<guestfs_max_disks>." }; tests = [ InitEmpty, Always, TestResult ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["mount"; "/dev/sda1"; "/"]; ["xfs_info"; "/"]], "ret->xfs_blocksize == 4096"), [] ]; @@ -10585,7 +10589,7 @@ in the returned structure is defined by the API." }; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV"; "VG"; "40"]; - ["mkfs"; "xfs"; "/dev/VG/LV"; ""; "NOARG"; ""; ""]; + ["mkfs"; "xfs"; "/dev/VG/LV"; ""; "NOARG"; ""; ""; "NOARG"]; ["lvresize"; "/dev/VG/LV"; "80"]; ["mount"; "/dev/VG/LV"; "/"]; ["xfs_growfs"; "/"; "true"; "false"; "false"; ""; ""; ""; ""; ""]; @@ -10722,7 +10726,7 @@ with zeroes)." }; tests = [ InitEmpty, Always, TestResult ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["xfs_admin"; "/dev/sda1"; ""; ""; ""; ""; "false"; "NOARG"; "NOARG"]; ["mount"; "/dev/sda1"; "/"]; ["xfs_info"; "/"]], "ret->xfs_lazycount == 0"), []; @@ -10956,7 +10960,7 @@ This is a wrapper around the L<hivex(3)> call of the same name." }; tests = [ InitEmpty, Always, TestRun ( [["part_disk"; "/dev/sda"; "mbr"]; - ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; + ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; ["xfs_repair"; "/dev/sda1"; ""; "true"; ""; ""; ""; ""; ""; ""; "NOARG"; "NOARG"] ]), [] ]; -- 1.9.3
Pino Toscano
2015-Jan-13 09:38 UTC
[Libguestfs] [PATCH] format, make-fs: specify the label on mkfs
If specified, pass the label for the new filesystem directly to the mkfs (or mkfs_btrfs) call. This saves one set_label call, mostly. --- format/format.c | 10 ++++++---- make-fs/make-fs.c | 28 +++++++++++++++++----------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/format/format.c b/format/format.c index 4e6069f..cc371ab 100644 --- a/format/format.c +++ b/format/format.c @@ -434,13 +434,15 @@ do_format (void) } if (filesystem) { - if (guestfs_mkfs_opts (g, filesystem, dev, -1) == -1) - exit (EXIT_FAILURE); + struct guestfs_mkfs_opts_argv optargs = { .bitmask = 0 }; if (label) { - if (guestfs_set_label (g, dev, label) == -1) - exit (EXIT_FAILURE); + optargs.label = label; + optargs.bitmask |= GUESTFS_MKFS_OPTS_LABEL_BITMASK; } + + if (guestfs_mkfs_opts_argv (g, filesystem, dev, &optargs) == -1) + exit (EXIT_FAILURE); } if (free_dev) diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c index 841c202..14729ad 100644 --- a/make-fs/make-fs.c +++ b/make-fs/make-fs.c @@ -755,9 +755,15 @@ do_make_fs (const char *input, const char *output_str) /* Create the filesystem. */ if (STRNEQ (type, "btrfs")) { int r; + struct guestfs_mkfs_opts_argv optargs = { .bitmask = 0 }; + + if (label) { + optargs.label = label; + optargs.bitmask |= GUESTFS_MKFS_OPTS_LABEL_BITMASK; + } guestfs_push_error_handler (g, NULL, NULL); - r = guestfs_mkfs (g, type, dev); + r = guestfs_mkfs_opts_argv (g, type, dev, &optargs); guestfs_pop_error_handler (g); if (r == -1) { @@ -774,17 +780,17 @@ do_make_fs (const char *input, const char *output_str) } else { const char *devs[] = { dev, NULL }; + struct guestfs_mkfs_btrfs_argv optargs = { .bitmask = 0 }; + + optargs.datatype = "single"; + optargs.metadata = "single"; + optargs.bitmask |= GUESTFS_MKFS_BTRFS_DATATYPE_BITMASK | GUESTFS_MKFS_BTRFS_METADATA_BITMASK; + if (label) { + optargs.label = label; + optargs.bitmask |= GUESTFS_MKFS_BTRFS_LABEL_BITMASK; + } - if (guestfs_mkfs_btrfs (g, (char **) devs, - GUESTFS_MKFS_BTRFS_DATATYPE, "single", - GUESTFS_MKFS_BTRFS_METADATA, "single", - -1) == -1) - return -1; - } - - /* Set label. */ - if (label) { - if (guestfs_set_label (g, dev, label) == -1) + if (guestfs_mkfs_btrfs_argv (g, (char **) devs, &optargs) == -1) return -1; } -- 1.9.3
Richard W.M. Jones
2015-Jan-19 14:41 UTC
Re: [Libguestfs] [PATCH] mkfs: add 'label' optional argument
On Tue, Jan 13, 2015 at 10:38:09AM +0100, Pino Toscano wrote:> Add the 'label' optional argument to the mkfs action, so it is possible > to set a filesystem label direct when creating it. There may be > filesystems not supporting changing the label of existing filesystems > but only setting it at creation time, so this new optarg will help. > > Implement it for the most common filesystems (ext*, fat, ntfs, btrfs, > xfs), giving an error for all the others, just like set_label does. > --- > daemon/mkfs.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- > generator/actions.ml | 42 +++++++++++++++++++++++------------------- > 2 files changed, 66 insertions(+), 21 deletions(-) > > diff --git a/daemon/mkfs.c b/daemon/mkfs.c > index 95ab874..2994307 100644 > --- a/daemon/mkfs.c > +++ b/daemon/mkfs.c > @@ -36,7 +36,7 @@ GUESTFSD_EXT_CMD(str_mkfs, mkfs); > /* Takes optional arguments, consult optargs_bitmask. */ > int > do_mkfs (const char *fstype, const char *device, int blocksize, > - const char *features, int inode, int sectorsize) > + const char *features, int inode, int sectorsize, const char *label) > { > const char *argv[MAX_ARGS]; > size_t i = 0; > @@ -194,6 +194,47 @@ do_mkfs (const char *fstype, const char *device, int blocksize, > ADD_ARG (argv, i, sectorsize_str); > } > > + if (optargs_bitmask & GUESTFS_MKFS_LABEL_BITMASK) { > + if (extfs) { > + if (strlen (label) > EXT2_LABEL_MAX) { > + reply_with_error ("%s: ext2 labels are limited to %d bytes", > + label, EXT2_LABEL_MAX); > + return -1; > + } > + > + ADD_ARG (argv, i, "-L"); > + ADD_ARG (argv, i, label); > + } > + else if (STREQ (fstype, "fat") || STREQ (fstype, "vfat") || > + STREQ (fstype, "msdos")) { > + ADD_ARG (argv, i, "-n"); > + ADD_ARG (argv, i, label); > + } > + else if (STREQ (fstype, "ntfs")) { > + ADD_ARG (argv, i, "-L"); > + ADD_ARG (argv, i, label); > + } > + else if (STREQ (fstype, "xfs")) { > + if (strlen (label) > XFS_LABEL_MAX) { > + reply_with_error ("%s: xfs labels are limited to %d bytes", > + label, XFS_LABEL_MAX); > + return -1; > + } > + > + ADD_ARG (argv, i, "-L"); > + ADD_ARG (argv, i, label); > + } > + else if (STREQ (fstype, "btrfs")) { > + ADD_ARG (argv, i, "-L"); > + ADD_ARG (argv, i, label); > + } > + else { > + reply_with_error ("don't know how to set the label for '%s' filesystems", > + fstype); > + return -1; > + } > + } > + > ADD_ARG (argv, i, device); > ADD_ARG (argv, i, NULL); > > @@ -212,5 +253,5 @@ int > do_mkfs_b (const char *fstype, int blocksize, const char *device) > { > optargs_bitmask = GUESTFS_MKFS_BLOCKSIZE_BITMASK; > - return do_mkfs (fstype, device, blocksize, 0, 0, 0); > + return do_mkfs (fstype, device, blocksize, 0, 0, 0, NULL); > } > diff --git a/generator/actions.ml b/generator/actions.ml > index a6a6dad..96a9dd6 100644 > --- a/generator/actions.ml > +++ b/generator/actions.ml > @@ -3324,7 +3324,7 @@ let daemon_functions = [ > tests = [ > InitEmpty, Always, TestResultString ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["mount"; "/dev/sda1"; "/"]; > ["write"; "/new"; "new file contents"]; > ["cat"; "/new"]], "new file contents"), [] > @@ -4138,12 +4138,12 @@ characters does I<not> work, even if the length is specified." }; > tests = [ > InitEmpty, Always, TestResult ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["mount"; "/dev/sda1"; "/"]; > ["mounts"]], "is_device_list (ret, 1, \"/dev/sda1\")"), []; > InitEmpty, Always, TestResult ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["mount"; "/dev/sda1"; "/"]; > ["umount"; "/"; "false"; "false"]; > ["mounts"]], "is_string_list (ret, 0)"), [] > @@ -4186,9 +4186,9 @@ See also: C<guestfs_mountpoints>" }; > ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; > ["part_add"; "/dev/sda"; "p"; "204800"; "409599"]; > ["part_add"; "/dev/sda"; "p"; "409600"; "-64"]; > - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > - ["mkfs"; "ext2"; "/dev/sda2"; ""; "NOARG"; ""; ""]; > - ["mkfs"; "ext2"; "/dev/sda3"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > + ["mkfs"; "ext2"; "/dev/sda2"; ""; "NOARG"; ""; ""; "NOARG"]; > + ["mkfs"; "ext2"; "/dev/sda3"; ""; "NOARG"; ""; ""; "NOARG"]; > ["mount"; "/dev/sda1"; "/"]; > ["mkdir"; "/mp1"]; > ["mount"; "/dev/sda2"; "/mp1"]; > @@ -5478,7 +5478,7 @@ the human-readable, canonical hex dump of the file." }; > tests = [ > InitNone, Always, TestResultString ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "ext3"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "ext3"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["mount"; "/dev/sda1"; "/"]; > ["write"; "/new"; "test file"]; > ["umount"; "/dev/sda1"; "false"; "false"]; > @@ -5602,7 +5602,7 @@ are activated or deactivated." }; > ["pvcreate"; "/dev/sda1"]; > ["vgcreate"; "VG"; "/dev/sda1"]; > ["lvcreate"; "LV"; "VG"; "10"]; > - ["mkfs"; "ext2"; "/dev/VG/LV"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "ext2"; "/dev/VG/LV"; ""; "NOARG"; ""; ""; "NOARG"]; > ["mount"; "/dev/VG/LV"; "/"]; > ["write"; "/new"; "test content"]; > ["umount"; "/"; "false"; "false"]; > @@ -5669,11 +5669,11 @@ Sleep for C<secs> seconds." }; > tests = [ > InitNone, Always, TestResult ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["ntfs_3g_probe"; "true"; "/dev/sda1"]], "ret == 0"), []; > InitNone, Always, TestResult ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["ntfs_3g_probe"; "true"; "/dev/sda1"]], "ret == 12"), [] > ]; > shortdesc = "probe NTFS volume"; > @@ -8543,7 +8543,11 @@ a file in the host and attach it as a device." }; > tests = [ > InitBasicFS, Always, TestResultString ( > [["set_label"; "/dev/sda1"; "LTEST"]; > - ["vfs_label"; "/dev/sda1"]], "LTEST"), [] > + ["vfs_label"; "/dev/sda1"]], "LTEST"), []; > + InitEmpty, Always, TestResultString ( > + [["part_disk"; "/dev/sda"; "mbr"]; > + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "test-label"]; > + ["vfs_label"; "/dev/sda1"]], "test-label"), []; > ]; > shortdesc = "get the filesystem label"; > longdesc = "\ > @@ -9015,13 +9019,13 @@ See also C<guestfs_is_lv>, C<guestfs_canonical_device_name>." }; > > { defaults with > name = "mkfs"; > - style = RErr, [String "fstype"; Device "device"], [OInt "blocksize"; OString "features"; OInt "inode"; OInt "sectorsize"]; > + style = RErr, [String "fstype"; Device "device"], [OInt "blocksize"; OString "features"; OInt "inode"; OInt "sectorsize"; OString "label"]; > proc_nr = Some 278; > once_had_no_optargs = true; > tests = [ > InitEmpty, Always, TestResultString ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "ext2"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["mount"; "/dev/sda1"; "/"]; > ["write"; "/new"; "new file contents"]; > ["cat"; "/new"]], "new file contents"), [] > @@ -9761,7 +9765,7 @@ device." }; > optional = Some "ntfs3g"; > tests = [ > InitPartition, Always, TestRun ( > - [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["ntfsfix"; "/dev/sda1"; "false"]]), [] > ]; > shortdesc = "fix common errors and force Windows to check NTFS"; > @@ -9820,7 +9824,7 @@ any existing contents of this device." }; > [["set_label"; "/dev/sda1"; "testlabel"]; > ["vfs_label"; "/dev/sda1"]], "testlabel"), []; > InitPartition, IfAvailable "ntfs3g", TestResultString ( > - [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + [["mkfs"; "ntfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["set_label"; "/dev/sda1"; "testlabel2"]; > ["vfs_label"; "/dev/sda1"]], "testlabel2"), []; > InitPartition, Always, TestLastFail ( > @@ -10485,7 +10489,7 @@ call C<guestfs_max_disks>." }; > tests = [ > InitEmpty, Always, TestResult ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["mount"; "/dev/sda1"; "/"]; > ["xfs_info"; "/"]], "ret->xfs_blocksize == 4096"), [] > ]; > @@ -10585,7 +10589,7 @@ in the returned structure is defined by the API." }; > ["pvcreate"; "/dev/sda1"]; > ["vgcreate"; "VG"; "/dev/sda1"]; > ["lvcreate"; "LV"; "VG"; "40"]; > - ["mkfs"; "xfs"; "/dev/VG/LV"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "xfs"; "/dev/VG/LV"; ""; "NOARG"; ""; ""; "NOARG"]; > ["lvresize"; "/dev/VG/LV"; "80"]; > ["mount"; "/dev/VG/LV"; "/"]; > ["xfs_growfs"; "/"; "true"; "false"; "false"; ""; ""; ""; ""; ""]; > @@ -10722,7 +10726,7 @@ with zeroes)." }; > tests = [ > InitEmpty, Always, TestResult ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["xfs_admin"; "/dev/sda1"; ""; ""; ""; ""; "false"; "NOARG"; "NOARG"]; > ["mount"; "/dev/sda1"; "/"]; > ["xfs_info"; "/"]], "ret->xfs_lazycount == 0"), []; > @@ -10956,7 +10960,7 @@ This is a wrapper around the L<hivex(3)> call of the same name." }; > tests = [ > InitEmpty, Always, TestRun ( > [["part_disk"; "/dev/sda"; "mbr"]; > - ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""]; > + ["mkfs"; "xfs"; "/dev/sda1"; ""; "NOARG"; ""; ""; "NOARG"]; > ["xfs_repair"; "/dev/sda1"; ""; "true"; ""; ""; ""; ""; ""; ""; "NOARG"; "NOARG"] > ]), [] > ];Looks good, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Richard W.M. Jones
2015-Jan-19 14:43 UTC
Re: [Libguestfs] [PATCH] format, make-fs: specify the label on mkfs
On Tue, Jan 13, 2015 at 10:38:10AM +0100, Pino Toscano wrote:> If specified, pass the label for the new filesystem directly to the > mkfs (or mkfs_btrfs) call. > > This saves one set_label call, mostly. > --- > format/format.c | 10 ++++++---- > make-fs/make-fs.c | 28 +++++++++++++++++----------- > 2 files changed, 23 insertions(+), 15 deletions(-) > > diff --git a/format/format.c b/format/format.c > index 4e6069f..cc371ab 100644 > --- a/format/format.c > +++ b/format/format.c > @@ -434,13 +434,15 @@ do_format (void) > } > > if (filesystem) { > - if (guestfs_mkfs_opts (g, filesystem, dev, -1) == -1) > - exit (EXIT_FAILURE); > + struct guestfs_mkfs_opts_argv optargs = { .bitmask = 0 }; > > if (label) { > - if (guestfs_set_label (g, dev, label) == -1) > - exit (EXIT_FAILURE); > + optargs.label = label; > + optargs.bitmask |= GUESTFS_MKFS_OPTS_LABEL_BITMASK; > } > + > + if (guestfs_mkfs_opts_argv (g, filesystem, dev, &optargs) == -1) > + exit (EXIT_FAILURE); > > if (free_dev) > diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c > index 841c202..14729ad 100644 > --- a/make-fs/make-fs.c > +++ b/make-fs/make-fs.c > @@ -755,9 +755,15 @@ do_make_fs (const char *input, const char *output_str) > /* Create the filesystem. */ > if (STRNEQ (type, "btrfs")) { > int r; > + struct guestfs_mkfs_opts_argv optargs = { .bitmask = 0 }; > + > + if (label) { > + optargs.label = label; > + optargs.bitmask |= GUESTFS_MKFS_OPTS_LABEL_BITMASK; > + } > > guestfs_push_error_handler (g, NULL, NULL); > - r = guestfs_mkfs (g, type, dev); > + r = guestfs_mkfs_opts_argv (g, type, dev, &optargs); > guestfs_pop_error_handler (g); > > if (r == -1) { > @@ -774,17 +780,17 @@ do_make_fs (const char *input, const char *output_str) > } > else { > const char *devs[] = { dev, NULL }; > + struct guestfs_mkfs_btrfs_argv optargs = { .bitmask = 0 }; > + > + optargs.datatype = "single"; > + optargs.metadata = "single"; > + optargs.bitmask |= GUESTFS_MKFS_BTRFS_DATATYPE_BITMASK | GUESTFS_MKFS_BTRFS_METADATA_BITMASK; > + if (label) { > + optargs.label = label; > + optargs.bitmask |= GUESTFS_MKFS_BTRFS_LABEL_BITMASK; > + } > > - if (guestfs_mkfs_btrfs (g, (char **) devs, > - GUESTFS_MKFS_BTRFS_DATATYPE, "single", > - GUESTFS_MKFS_BTRFS_METADATA, "single", > - -1) == -1) > - return -1; > - } > - > - /* Set label. */ > - if (label) { > - if (guestfs_set_label (g, dev, label) == -1) > + if (guestfs_mkfs_btrfs_argv (g, (char **) devs, &optargs) == -1) > return -1; > } > > -- > 1.9.3ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Possibly Parallel Threads
- [PATCH] mkfs: add 'label' optional argument
- [PATCH 1/1] virt-make-fs: add '--blocksize' option support
- [PATCH v2] virt-make-fs: add '--blocksize' option support
- [PATCH 0/6] Update the way that API versions are generated for the man page.
- [PATCH] make-fs: print error message on mkfs failure