[Libguestfs] [PATCH] uuid: add support to change uuid of btrfs partition

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Tue Jun 23 07:59:19 UTC 2015


btrfs-progs v4.1 add support to change uuid of btrfs fs.

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;
+}
+
 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), [];
       ]);
     shortdesc = "set the filesystem UUID";
     longdesc = "\
-- 
2.1.0




More information about the Libguestfs mailing list