Chen Hanxiao
2015-Jun-24 07:54 UTC
[Libguestfs] [PATCH 0/5] uuid: add btrfs uuid change support and some rework
- Btrfs-progs v4.1 introduced new feature of changing uuid of btrfs partition. This patch add support of this. - uuids.c did a lot of deplicated work for changing uuid of fs. Use existed functions. -- Introduce new API: btrfstune_set_uuid_random Chen Hanxiao (5): uuid: add support to change uuid of btrfs partition uuid: use existed function of ext2 uuid: use newly introduced do_xfs_admin_uuid of xfs uuid: use existed do_mkswap_U New API: btrfstune_set_uuid_random daemon/btrfs.c | 81 ++++++++++++++++++++++++++++++++++++++++++ daemon/daemon.h | 6 ++++ daemon/uuids.c | 44 +++++------------------ daemon/xfs.c | 7 ++++ generator/actions.ml | 18 ++++++++++ src/MAX_PROC_NR | 2 +- tests/btrfs/test-btrfs-misc.pl | 6 ++++ 7 files changed, 128 insertions(+), 36 deletions(-) -- 2.1.0
Chen Hanxiao
2015-Jun-24 07:54 UTC
[Libguestfs] [PATCH v2 1/5] uuid: add support to change uuid of btrfs partition
btrfs-progs v4.1 add support to change uuid of btrfs fs. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- v2: put btrfs operation back to daemon/btrfs.c move tests to tests/btrfs daemon/btrfs.c | 60 ++++++++++++++++++++++++++++++++++++++++++ daemon/daemon.h | 1 + daemon/uuids.c | 9 +++++-- tests/btrfs/test-btrfs-misc.pl | 6 +++++ 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/daemon/btrfs.c b/daemon/btrfs.c index 20e5e6b..b82c1b9 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -790,6 +790,44 @@ do_btrfs_device_delete (char *const *devices, const char *fs) return 0; } + +/* btrfstune command add two new options + * -U UUID change fsid to UUID + * -u change fsid, use a random one + * since v4.1 + * We could check wheter 'btrfstune' support + * '-u' and '-U UUID' option by checking the output of + * 'btrfstune' command. + */ +static int +test_btrftune_uuid_opt (void) +{ + static int result = -1; + if (result != -1) + return result; + + CLEANUP_FREE char *err = NULL; + + int r = commandr (NULL, &err, str_btrfstune, NULL); + + if (r == -1) { + reply_with_error ("btrfstune: %s", err); + return -1; + } + + /* FIXME currently btrfstune do not support '--help'. + * If got an invalid options, it will print its usage + * in stderr. + * We had to check it there. + */ + if (strstr (err, "-U") == NULL || strstr (err, "-u") == NULL) + result = 0; + else + result = 1; + + return result; +} + int do_btrfs_set_seeding (const char *device, int svalue) { @@ -807,6 +845,28 @@ do_btrfs_set_seeding (const char *device, int svalue) return 0; } +int +btrfstune_set_uuid (const char *device, const char *uuid) +{ + CLEANUP_FREE char *err = NULL; + int r; + int has_uuid_opts = test_btrftune_uuid_opt (); + + if (has_uuid_opts == 0) { + reply_with_error ("btrfstune do not support '-u'"); + return -1; + } + + r = commandr (NULL, &err, str_btrfstune, "-f", "-U", uuid, device, NULL); + + if (r == -1) { + reply_with_error ("%s: %s", device, err); + return -1; + } + + return 0; +} + /* Takes optional arguments, consult optargs_bitmask. */ int do_btrfs_fsck (const char *device, int64_t superblock, int repair) diff --git a/daemon/daemon.h b/daemon/daemon.h index 136e9a9..ee0c96f 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -268,6 +268,7 @@ extern char *debug_bmap_device (const char *subcmd, size_t argc, char *const *co /*-- in btrfs.c --*/ extern char *btrfs_get_label (const char *device); +extern int btrfstune_set_uuid (const char *device, const char *uuid); /*-- in ntfs.c --*/ extern char *ntfs_get_label (const char *device); diff --git a/daemon/uuids.c b/daemon/uuids.c index 06b33e9..f7791ab 100644 --- a/daemon/uuids.c +++ b/daemon/uuids.c @@ -91,6 +91,12 @@ swapuuid (const char *device, const char *uuid) return 0; } +static int +btrfsuuid (const char *device, const char *uuid) +{ + return btrfstune_set_uuid (device, uuid); +} + int do_set_uuid (const char *device, const char *uuid) { @@ -111,8 +117,7 @@ do_set_uuid (const char *device, const char *uuid) r = swapuuid (device, uuid); else if (STREQ (vfs_type, "btrfs")) { - reply_with_error ("btrfs filesystems' UUID cannot be changed"); - r = -1; + r = btrfsuuid (device, uuid); } else { diff --git a/tests/btrfs/test-btrfs-misc.pl b/tests/btrfs/test-btrfs-misc.pl index 2fe7c59..cd60990 100755 --- a/tests/btrfs/test-btrfs-misc.pl +++ b/tests/btrfs/test-btrfs-misc.pl @@ -47,5 +47,11 @@ my $label = $g->vfs_label ("/dev/sda1"); die "unexpected label: expecting 'newlabel' but got '$label'" unless $label eq "newlabel"; +# Setting btrfs UUID +$g->set_uuid ("/dev/sda1", "12345678-1234-1234-1234-123456789012"); +my $uuid = $g->vfs_uuid ("/dev/sda1"); +die "unexpected label: expecting 'newlabel' but got '$uuid'" + unless $uuid eq "12345678-1234-1234-1234-123456789012"; + $g->shutdown (); $g->close (); -- 2.1.0
Chen Hanxiao
2015-Jun-24 07:54 UTC
[Libguestfs] [PATCH 2/5] uuid: use existed function of ext2
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/daemon.h | 1 + daemon/uuids.c | 12 +----------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index ee0c96f..eeb4ff7 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -219,6 +219,7 @@ extern int sync_disks (void); /* Confirmed this is true up to ext4 from the Linux sources. */ #define EXT2_LABEL_MAX 16 extern int fstype_is_extfs (const char *fstype); +extern int do_set_e2uuid (const char *device, const char *uuid); /*-- in blkid.c --*/ extern char *get_blkid_tag (const char *device, const char *tag); diff --git a/daemon/uuids.c b/daemon/uuids.c index f7791ab..8626884 100644 --- a/daemon/uuids.c +++ b/daemon/uuids.c @@ -27,16 +27,12 @@ #include "actions.h" #include "optgroups.h" -GUESTFSD_EXT_CMD(str_tune2fs, tune2fs); GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin); GUESTFSD_EXT_CMD(str_swaplabel, swaplabel); static int e2uuid (const char *device, const char *uuid) { - int r; - CLEANUP_FREE char *err = NULL; - /* Don't allow the magic values here. If callers want to do this * we'll add alternate set_uuid_* calls. */ @@ -46,13 +42,7 @@ e2uuid (const char *device, const char *uuid) return -1; } - r = command (NULL, &err, str_tune2fs, "-U", uuid, device, NULL); - if (r == -1) { - reply_with_error ("%s", err); - return -1; - } - - return 0; + return do_set_e2uuid (device, uuid); } static int -- 2.1.0
Chen Hanxiao
2015-Jun-24 07:54 UTC
[Libguestfs] [PATCH 3/5] uuid: use newly introduced do_xfs_admin_uuid of xfs
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/daemon.h | 1 + daemon/uuids.c | 12 +----------- daemon/xfs.c | 7 +++++++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index eeb4ff7..aba6ef2 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -261,6 +261,7 @@ extern int copy_xattrs (const char *src, const char *dest); /*-- in xfs.c --*/ /* Documented in xfs_admin(8). */ #define XFS_LABEL_MAX 12 +extern int do_xfs_admin_uuid (const char *device, const char *uuid); /*-- debug-bmap.c --*/ extern char *debug_bmap (const char *subcmd, size_t argc, char *const *const argv); diff --git a/daemon/uuids.c b/daemon/uuids.c index 8626884..0520113 100644 --- a/daemon/uuids.c +++ b/daemon/uuids.c @@ -27,7 +27,6 @@ #include "actions.h" #include "optgroups.h" -GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin); GUESTFSD_EXT_CMD(str_swaplabel, swaplabel); static int @@ -48,22 +47,13 @@ e2uuid (const char *device, const char *uuid) static int xfsuuid (const char *device, const char *uuid) { - int r; - CLEANUP_FREE char *err = NULL; - /* Don't allow special values. */ if (STREQ (uuid, "nil") || STREQ (uuid, "generate")) { reply_with_error ("xfs: invalid new UUID"); return -1; } - r = command (NULL, &err, str_xfs_admin, "-U", uuid, device, NULL); - if (r == -1) { - reply_with_error ("%s", err); - return -1; - } - - return 0; + return do_xfs_admin_uuid (device, uuid); } static int diff --git a/daemon/xfs.c b/daemon/xfs.c index 687013b..aaeff3e 100644 --- a/daemon/xfs.c +++ b/daemon/xfs.c @@ -456,6 +456,13 @@ do_xfs_growfs (const char *path, } int +do_xfs_admin_uuid (const char *device, const char *uuid) +{ + optargs_bitmask = GUESTFS_XFS_ADMIN_UUID_BITMASK; + return do_xfs_admin (device, 0, 0, 0, 0, 0, NULL, uuid); +} + +int do_xfs_admin (const char *device, int extunwritten, int imgfile, int v2log, int projid32bit, -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/daemon.h | 3 +++ daemon/uuids.c | 13 +------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index aba6ef2..c887cfd 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -275,6 +275,9 @@ extern int btrfstune_set_uuid (const char *device, const char *uuid); /*-- in ntfs.c --*/ extern char *ntfs_get_label (const char *device); +/*-- in swap.c --*/ +extern int do_mkswap_U (const char *device, const char *uuid); + /* ordinary daemon functions use these to indicate errors * NB: you don't need to prefix the string with the current command, * it is added automatically by the client-side RPC stubs. diff --git a/daemon/uuids.c b/daemon/uuids.c index 0520113..704906d 100644 --- a/daemon/uuids.c +++ b/daemon/uuids.c @@ -27,8 +27,6 @@ #include "actions.h" #include "optgroups.h" -GUESTFSD_EXT_CMD(str_swaplabel, swaplabel); - static int e2uuid (const char *device, const char *uuid) { @@ -59,16 +57,7 @@ xfsuuid (const char *device, const char *uuid) static int swapuuid (const char *device, const char *uuid) { - int r; - CLEANUP_FREE char *err = NULL; - - r = command (NULL, &err, str_swaplabel, "-U", uuid, device, NULL); - if (r == -1) { - reply_with_error ("%s", err); - return -1; - } - - return 0; + return do_mkswap_U (device, uuid); } static int -- 2.1.0
Chen Hanxiao
2015-Jun-24 07:54 UTC
[Libguestfs] [PATCH 5/5] New API: btrfstune_set_uuid_random
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/btrfs.c | 21 +++++++++++++++++++++ generator/actions.ml | 18 ++++++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/daemon/btrfs.c b/daemon/btrfs.c index b82c1b9..e4d8b64 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -867,6 +867,27 @@ btrfstune_set_uuid (const char *device, const char *uuid) return 0; } +int +do_btrfstune_set_uuid_random (const char *device) +{ + CLEANUP_FREE char *err = NULL; + int r; + int has_uuid_opts = test_btrftune_uuid_opt(); + + if (has_uuid_opts == 0) { + reply_with_error ("btrfstune do not support '-u'"); + return -1; + } + + r = commandr (NULL, &err, str_btrfstune, "-u", device, NULL); + if (r == -1) { + reply_with_error("%s: %s", device, err); + return -1; + } + + return 0; +} + /* Takes optional arguments, consult optargs_bitmask. */ int do_btrfs_fsck (const char *device, int64_t superblock, int repair) diff --git a/generator/actions.ml b/generator/actions.ml index d5e5ccf..329b388 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -12593,6 +12593,24 @@ numbered C<partnum> on device C<device>. It returns C<primary>, C<logical>, or C<extended>." }; + { defaults with + name = "btrfstune_set_uuid_random"; added = (1, 29, 47); + style = RErr, [Device "device"], []; + proc_nr = Some 455; + optional = Some "btrfs"; camel_name = "BTRFSTuneSetUuidRandom"; + tests = [ + InitPartition, Always, TestRun ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; + ["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""]; + ["btrfstune_set_uuid_random"; "/dev/sda1"]]), [] + ]; + + shortdesc = "change fsid to a random generated UUID"; + longdesc = "\ + Change fsid to a randomly generated UUID or continue previous fsid change + operation in case it was interrupted." }; + ] (* Non-API meta-commands available only in guestfish. diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 515f19a..4930863 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -454 +455 -- 2.1.0
Pino Toscano
2015-Jun-24 10:15 UTC
Re: [Libguestfs] [PATCH v2 1/5] uuid: add support to change uuid of btrfs partition
In data mercoledì 24 giugno 2015 15:54:03, Chen Hanxiao ha scritto:> btrfs-progs v4.1 add support to change uuid of btrfs fs. > > Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> > --- > v2: put btrfs operation back to daemon/btrfs.c > move tests to tests/btrfs > > daemon/btrfs.c | 60 ++++++++++++++++++++++++++++++++++++++++++ > daemon/daemon.h | 1 + > daemon/uuids.c | 9 +++++-- > tests/btrfs/test-btrfs-misc.pl | 6 +++++ > 4 files changed, 74 insertions(+), 2 deletions(-) > > diff --git a/daemon/btrfs.c b/daemon/btrfs.c > index 20e5e6b..b82c1b9 100644 > --- a/daemon/btrfs.c > +++ b/daemon/btrfs.c > @@ -790,6 +790,44 @@ do_btrfs_device_delete (char *const *devices, const char *fs) > return 0; > } > > + > +/* btrfstune command add two new options > + * -U UUID change fsid to UUID > + * -u change fsid, use a random one > + * since v4.1 > + * We could check wheter 'btrfstune' support > + * '-u' and '-U UUID' option by checking the output of > + * 'btrfstune' command. > + */ > +static int > +test_btrftune_uuid_opt (void) > +{ > + static int result = -1; > + if (result != -1) > + return result; > + > + CLEANUP_FREE char *err = NULL; > + > + int r = commandr (NULL, &err, str_btrfstune, NULL); > + > + if (r == -1) { > + reply_with_error ("btrfstune: %s", err); > + return -1; > + } > + > + /* FIXME currently btrfstune do not support '--help'. > + * If got an invalid options, it will print its usage > + * in stderr. > + * We had to check it there. > + */ > + if (strstr (err, "-U") == NULL || strstr (err, "-u") == NULL) > + result = 0; > + else > + result = 1; > + > + return result; > +} > + > int > do_btrfs_set_seeding (const char *device, int svalue) > { > @@ -807,6 +845,28 @@ do_btrfs_set_seeding (const char *device, int svalue) > return 0; > } > > +int > +btrfstune_set_uuid (const char *device, const char *uuid)Call it btrfs_set_uuid please, as the fact that it uses btrfstune is an implementation detail of it.> +{ > + CLEANUP_FREE char *err = NULL; > + int r; > + int has_uuid_opts = test_btrftune_uuid_opt (); > + > + if (has_uuid_opts == 0) {Check for <= 0 here, to consider errors in test_btrftune_uuid_opt on the safe side.> + reply_with_error ("btrfstune do not support '-u'");reply_with_error ("btrfs filesystems' UUID cannot be changed");> + return -1; > + } > + > + r = commandr (NULL, &err, str_btrfstune, "-f", "-U", uuid, device, NULL); > + > + if (r == -1) { > + reply_with_error ("%s: %s", device, err); > + return -1; > + } > + > + return 0; > +} > + > /* Takes optional arguments, consult optargs_bitmask. */ > int > do_btrfs_fsck (const char *device, int64_t superblock, int repair) > diff --git a/daemon/daemon.h b/daemon/daemon.h > index 136e9a9..ee0c96f 100644 > --- a/daemon/daemon.h > +++ b/daemon/daemon.h > @@ -268,6 +268,7 @@ extern char *debug_bmap_device (const char *subcmd, size_t argc, char *const *co > > /*-- in btrfs.c --*/ > extern char *btrfs_get_label (const char *device); > +extern int btrfstune_set_uuid (const char *device, const char *uuid); > > /*-- in ntfs.c --*/ > extern char *ntfs_get_label (const char *device); > diff --git a/daemon/uuids.c b/daemon/uuids.c > index 06b33e9..f7791ab 100644 > --- a/daemon/uuids.c > +++ b/daemon/uuids.c > @@ -91,6 +91,12 @@ swapuuid (const char *device, const char *uuid) > return 0; > } > > +static int > +btrfsuuid (const char *device, const char *uuid) > +{ > + return btrfstune_set_uuid (device, uuid); > +}What is this wrapper for? Just call btrfs_set_uuid below.> int > do_set_uuid (const char *device, const char *uuid) > { > @@ -111,8 +117,7 @@ do_set_uuid (const char *device, const char *uuid) > r = swapuuid (device, uuid); > > else if (STREQ (vfs_type, "btrfs")) { > - reply_with_error ("btrfs filesystems' UUID cannot be changed"); > - r = -1; > + r = btrfsuuid (device, uuid); > }Minor style note: curly brackets can be removed now.> else { > diff --git a/tests/btrfs/test-btrfs-misc.pl b/tests/btrfs/test-btrfs-misc.pl > index 2fe7c59..cd60990 100755 > --- a/tests/btrfs/test-btrfs-misc.pl > +++ b/tests/btrfs/test-btrfs-misc.pl > @@ -47,5 +47,11 @@ my $label = $g->vfs_label ("/dev/sda1"); > die "unexpected label: expecting 'newlabel' but got '$label'" > unless $label eq "newlabel"; > > +# Setting btrfs UUID > +$g->set_uuid ("/dev/sda1", "12345678-1234-1234-1234-123456789012"); > +my $uuid = $g->vfs_uuid ("/dev/sda1"); > +die "unexpected label: expecting 'newlabel' but got '$uuid'" > + unless $uuid eq "12345678-1234-1234-1234-123456789012"; > +Ignoring the "newlabel" copy&paste error: this code has the same issue as the old test added to the action tests in generator/actions.ml. That is, if btrfs-tools < 4.1 is used, then the test will fail (instead of being skipped). Thinking further about it: it might be better to make set_uuid return ENOTSUP for all the unsupported filesystems (including older btrfs-tools case). This way, the perl snippet above could check, when set_uuid fails, for the last_errno() and consider that a hard failure if it was different than ENOTSUP. Something like (untested): eval { $g->set_uuid (...); }; my $err = $g->last_errno (); if ($err == 0) { my $uuid = $g->vfs_uuid (...); die ... } elsif ($err != Errno::ENOTSUP()) { die $@ } -- Pino Toscano
Pino Toscano
2015-Jun-24 10:33 UTC
Re: [Libguestfs] [PATCH 2/5] uuid: use existed function of ext2
Hi, in commit message, s/existed/existing/. In data mercoledì 24 giugno 2015 15:54:04, Chen Hanxiao ha scritto:> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> > --- > daemon/daemon.h | 1 + > daemon/uuids.c | 12 +----------- > 2 files changed, 2 insertions(+), 11 deletions(-) > > diff --git a/daemon/daemon.h b/daemon/daemon.h > index ee0c96f..eeb4ff7 100644 > --- a/daemon/daemon.h > +++ b/daemon/daemon.h > @@ -219,6 +219,7 @@ extern int sync_disks (void); > /* Confirmed this is true up to ext4 from the Linux sources. */ > #define EXT2_LABEL_MAX 16 > extern int fstype_is_extfs (const char *fstype); > +extern int do_set_e2uuid (const char *device, const char *uuid);You don't need to declare prototypes of do_* functions of the daemon, they are generated automatically in daemon/actions.h.> /*-- in blkid.c --*/ > extern char *get_blkid_tag (const char *device, const char *tag); > diff --git a/daemon/uuids.c b/daemon/uuids.c > index f7791ab..8626884 100644 > --- a/daemon/uuids.c > +++ b/daemon/uuids.c > @@ -27,16 +27,12 @@ > #include "actions.h" > #include "optgroups.h" > > -GUESTFSD_EXT_CMD(str_tune2fs, tune2fs); > GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin); > GUESTFSD_EXT_CMD(str_swaplabel, swaplabel); > > static int > e2uuid (const char *device, const char *uuid) > { > - int r; > - CLEANUP_FREE char *err = NULL; > - > /* Don't allow the magic values here. If callers want to do this > * we'll add alternate set_uuid_* calls. > */ > @@ -46,13 +42,7 @@ e2uuid (const char *device, const char *uuid) > return -1; > } > > - r = command (NULL, &err, str_tune2fs, "-U", uuid, device, NULL); > - if (r == -1) { > - reply_with_error ("%s", err); > - return -1; > - } > - > - return 0; > + return do_set_e2uuid (device, uuid); > } > > static int >The rest would seem okay. Thanks, -- Pino Toscano
Pino Toscano
2015-Jun-24 10:40 UTC
Re: [Libguestfs] [PATCH 3/5] uuid: use newly introduced do_xfs_admin_uuid of xfs
In data mercoledì 24 giugno 2015 15:54:05, Chen Hanxiao ha scritto:> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> > --- > daemon/daemon.h | 1 + > daemon/uuids.c | 12 +----------- > daemon/xfs.c | 7 +++++++ > 3 files changed, 9 insertions(+), 11 deletions(-) > > diff --git a/daemon/daemon.h b/daemon/daemon.h > index eeb4ff7..aba6ef2 100644 > --- a/daemon/daemon.h > +++ b/daemon/daemon.h > @@ -261,6 +261,7 @@ extern int copy_xattrs (const char *src, const char *dest); > /*-- in xfs.c --*/ > /* Documented in xfs_admin(8). */ > #define XFS_LABEL_MAX 12 > +extern int do_xfs_admin_uuid (const char *device, const char *uuid);The do_* naming in the daemon is reserved for actions. Just name it like xfs_set_uuid.> > /*-- debug-bmap.c --*/ > extern char *debug_bmap (const char *subcmd, size_t argc, char *const *const argv); > diff --git a/daemon/uuids.c b/daemon/uuids.c > index 8626884..0520113 100644 > --- a/daemon/uuids.c > +++ b/daemon/uuids.c > @@ -27,7 +27,6 @@ > #include "actions.h" > #include "optgroups.h" > > -GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin); > GUESTFSD_EXT_CMD(str_swaplabel, swaplabel); > > static int > @@ -48,22 +47,13 @@ e2uuid (const char *device, const char *uuid) > static int > xfsuuid (const char *device, const char *uuid) > { > - int r; > - CLEANUP_FREE char *err = NULL; > - > /* Don't allow special values. */ > if (STREQ (uuid, "nil") || STREQ (uuid, "generate")) { > reply_with_error ("xfs: invalid new UUID"); > return -1; > } > > - r = command (NULL, &err, str_xfs_admin, "-U", uuid, device, NULL); > - if (r == -1) { > - reply_with_error ("%s", err); > - return -1; > - } > - > - return 0; > + return do_xfs_admin_uuid (device, uuid); > } > > static int > diff --git a/daemon/xfs.c b/daemon/xfs.c > index 687013b..aaeff3e 100644 > --- a/daemon/xfs.c > +++ b/daemon/xfs.c > @@ -456,6 +456,13 @@ do_xfs_growfs (const char *path, > } > > int > +do_xfs_admin_uuid (const char *device, const char *uuid) > +{ > + optargs_bitmask = GUESTFS_XFS_ADMIN_UUID_BITMASK; > + return do_xfs_admin (device, 0, 0, 0, 0, 0, NULL, uuid); > +} > + > +int > do_xfs_admin (const char *device, > int extunwritten, int imgfile, int v2log, > int projid32bit, >The rest seems okay. Thanks, -- Pino Toscano
Pino Toscano
2015-Jun-24 10:49 UTC
Re: [Libguestfs] [PATCH 4/5] uuid: use existed do_mkswap_U
In data mercoledì 24 giugno 2015 15:54:06, Chen Hanxiao ha scritto:> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> > --- > daemon/daemon.h | 3 +++ > daemon/uuids.c | 13 +------------ > 2 files changed, 4 insertions(+), 12 deletions(-) > > diff --git a/daemon/daemon.h b/daemon/daemon.h > index aba6ef2..c887cfd 100644 > --- a/daemon/daemon.h > +++ b/daemon/daemon.h > @@ -275,6 +275,9 @@ extern int btrfstune_set_uuid (const char *device, const char *uuid); > /*-- in ntfs.c --*/ > extern char *ntfs_get_label (const char *device); > > +/*-- in swap.c --*/ > +extern int do_mkswap_U (const char *device, const char *uuid); > + > /* ordinary daemon functions use these to indicate errors > * NB: you don't need to prefix the string with the current command, > * it is added automatically by the client-side RPC stubs. > diff --git a/daemon/uuids.c b/daemon/uuids.c > index 0520113..704906d 100644 > --- a/daemon/uuids.c > +++ b/daemon/uuids.c > @@ -27,8 +27,6 @@ > #include "actions.h" > #include "optgroups.h" > > -GUESTFSD_EXT_CMD(str_swaplabel, swaplabel); > - > static int > e2uuid (const char *device, const char *uuid) > { > @@ -59,16 +57,7 @@ xfsuuid (const char *device, const char *uuid) > static int > swapuuid (const char *device, const char *uuid) > { > - int r; > - CLEANUP_FREE char *err = NULL; > - > - r = command (NULL, &err, str_swaplabel, "-U", uuid, device, NULL); > - if (r == -1) { > - reply_with_error ("%s", err); > - return -1; > - } > - > - return 0; > + return do_mkswap_U (device, uuid); > }This is actually wrong: swaplabel prints or changes the label/UUID of an existing swap area, while mkswap creates a new swap area trashing the previous content of the device/file. Just move swapuuid to daemon/swap.c, renaming it to swap_set_uuid. Thanks, -- Pino Toscano
Pino Toscano
2015-Jun-24 10:57 UTC
Re: [Libguestfs] [PATCH 5/5] New API: btrfstune_set_uuid_random
In data mercoledì 24 giugno 2015 15:54:07, Chen Hanxiao ha scritto:> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> > --- > daemon/btrfs.c | 21 +++++++++++++++++++++ > generator/actions.ml | 18 ++++++++++++++++++ > src/MAX_PROC_NR | 2 +- > 3 files changed, 40 insertions(+), 1 deletion(-) > > diff --git a/daemon/btrfs.c b/daemon/btrfs.c > index b82c1b9..e4d8b64 100644 > --- a/daemon/btrfs.c > +++ b/daemon/btrfs.c > @@ -867,6 +867,27 @@ btrfstune_set_uuid (const char *device, const char *uuid) > return 0; > } > > +int > +do_btrfstune_set_uuid_random (const char *device) > +{ > + CLEANUP_FREE char *err = NULL; > + int r; > + int has_uuid_opts = test_btrftune_uuid_opt(); > + > + if (has_uuid_opts == 0) { > + reply_with_error ("btrfstune do not support '-u'"); > + return -1; > + } > + > + r = commandr (NULL, &err, str_btrfstune, "-u", device, NULL); > + if (r == -1) { > + reply_with_error("%s: %s", device, err); > + return -1; > + } > + > + return 0; > +} > + > /* Takes optional arguments, consult optargs_bitmask. */ > int > do_btrfs_fsck (const char *device, int64_t superblock, int repair) > diff --git a/generator/actions.ml b/generator/actions.ml > index d5e5ccf..329b388 100644 > --- a/generator/actions.ml > +++ b/generator/actions.ml > @@ -12593,6 +12593,24 @@ numbered C<partnum> on device C<device>. > > It returns C<primary>, C<logical>, or C<extended>." }; > > + { defaults with > + name = "btrfstune_set_uuid_random"; added = (1, 29, 47); > + style = RErr, [Device "device"], []; > + proc_nr = Some 455; > + optional = Some "btrfs"; camel_name = "BTRFSTuneSetUuidRandom"; > + tests = [ > + InitPartition, Always, TestRun ( > + [["part_init"; "/dev/sda"; "mbr"]; > + ["part_add"; "/dev/sda"; "p"; "64"; "204799"]; > + ["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""]; > + ["btrfstune_set_uuid_random"; "/dev/sda1"]]), [] > + ]; > + > + shortdesc = "change fsid to a random generated UUID";"set a random UUID for the filesystem"> + longdesc = "\ > + Change fsid to a randomly generated UUID or continue previous fsid change > + operation in case it was interrupted." }; > + > ] > > (* Non-API meta-commands available only in guestfish. > diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR > index 515f19a..4930863 100644 > --- a/src/MAX_PROC_NR > +++ b/src/MAX_PROC_NR > @@ -1 +1 @@ > -454 > +455See current comment in daemon/uuids.c:e2uuid about particular UUID operations. In case we want to allow these operations, they should be doable whichever filesystem it is, just like set_uuid: i.e. a new set_uuid_random, implemented for ext, xfs, and btrfs. -- Pino Toscano
Possibly Parallel Threads
- [PATCH 0/5] uuid: add btrfs uuid change support and some rework
- [PATCH v4 4/7] uuid: use newly introduced swap_set_uuid
- [PATCH 3/5] uuid: use newly introduced do_xfs_admin_uuid of xfs
- [PATCH 1/3] uuid: add support to change uuid of swap partition
- [PATCH v4 3/7] uuid: use newly introduced xfs_set_uuid of xfs