[Libguestfs] [PATCH] uuid: add support to change uuid of btrfs partition
Chen, Hanxiao
chenhanxiao at cn.fujitsu.com
Tue Jun 23 10:07:42 UTC 2015
> -----Original Message-----
> From: libguestfs-bounces at redhat.com [mailto:libguestfs-bounces at redhat.com] On
> Behalf Of Pino Toscano
> Sent: Tuesday, June 23, 2015 5:50 PM
> To: libguestfs at redhat.com
> Subject: Re: [Libguestfs] [PATCH] uuid: add support to change uuid of btrfs partition
>
> Hi,
>
> In data martedì 23 giugno 2015 15:59:19, Chen Hanxiao ha scritto:
> > btrfs-progs v4.1 add support to change uuid of btrfs fs.
>
> This needs to support older btrfs-progs versions though, so run
> btrfstune to check whether it has the -U parameter, and if not return
> the old error message. Something like test_btrfs_device_add_needs_force
> for example.
Sure.
>
> Also:
>
> $ btrfs --version
> btrfs-progs v4.0
> $ btrfstune --help
> btrfstune: invalid option -- '-'
> usage: btrfstune [options] device
> -S value positive value will enable seeding, zero to disable, negative
> is not allowed
> -r enable extended inode refs
> -x enable skinny metadata extent refs
> -f force to set or clear flags, make sure that you are aware of
> the dangers
>
> Would be cool if btrfs tools would support -h/--help, so it is not
> considered an error (i.e. exiting with 1).
Unfortunately they don't have.
I've talked to my colleagues, he said that this may be added if he had time.
If I had time, I'll send a btrfs-progs patch for it.
Also, for back compact, we may still use the old method as we did in daemon/btrfs.c.
>
> >
> > Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
> > ---
> > daemon/uuids.c | 19 +++++++++++++++++--
> > generator/actions.ml | 4 ++++
> > 2 files changed, 21 insertions(+), 2 deletions(-)
> >
> > diff --git a/daemon/uuids.c b/daemon/uuids.c
> > index 06b33e9..c18cb55 100644
> > --- a/daemon/uuids.c
> > +++ b/daemon/uuids.c
> > @@ -30,6 +30,7 @@
> > GUESTFSD_EXT_CMD(str_tune2fs, tune2fs);
> > GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin);
> > GUESTFSD_EXT_CMD(str_swaplabel, swaplabel);
> > +GUESTFSD_EXT_CMD(str_btrfstune, btrfstune);
> >
> > static int
> > e2uuid (const char *device, const char *uuid)
> > @@ -91,6 +92,21 @@ swapuuid (const char *device, const char *uuid)
> > return 0;
> > }
> >
> > +static int
> > +btrfsuuid (const char *device, const char *uuid)
> > +{
> > + int r;
> > + CLEANUP_FREE char *err = NULL;
> > +
> > + r = command (NULL, &err, str_btrfstune, "-f", "-U", uuid, device, NULL);
> > + if (r == -1) {
> > + reply_with_error ("%s", err);
> > + return -1;
> > + }
> > +
> > + return 0;
> > +}
>
> While other uuid methods are currently here in uuids.c, IMHO they would
> better fit together with their filesystem implementations. Similar to
> what I did with 6db3c100 and 8ad667f1 for labels.
That sounds good.
Like other XXuuid in uuids.c, it's a simple function.
Or maybe we could do the same thing to other XXuuid.
>
> > int
> > do_set_uuid (const char *device, const char *uuid)
> > {
> > @@ -111,8 +127,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/generator/actions.ml b/generator/actions.ml
> > index d5e5ccf..ca77c87 100644
> > --- a/generator/actions.ml
> > +++ b/generator/actions.ml
> > @@ -11774,6 +11774,10 @@ parameter. In future we may allow other flags to be
> adjusted." };
> > InitBasicFS, Always, TestResultString (
> > [["set_uuid"; "/dev/sda1"; uuid];
> > ["vfs_uuid"; "/dev/sda1"]], uuid), [];
> > + InitPartition, Always, TestResultString (
> > + [["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG";
> ""; ""];
> > + ["set_uuid"; "/dev/sda1"; uuid];
> > + ["vfs_uuid"; "/dev/sda1"]], uuid), [];
>
> Unfortunately this cannot be added, as it will fail with
> btrfs-progs < 4.1. My suggestion is to add a simple shell test in
> tests/btrfs, which would create a simple btrfs fs, try to change the
> UUID and check that it either returned the old error message, or that
> it succeeded.
Thanks for your comments. Will do in v2.
Regards,
- Chen
>
> Thanks,
> --
> Pino Toscano
>
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs
More information about the Libguestfs
mailing list