[PATCH] Specify btrfs volumes by UUID in /etc/fstab

Gene Czarcinski gene at czarc.net
Fri Dec 27 16:48:37 UTC 2013


This patch corrects support for the part or partition kickstart
command which refers to an existing BTRFS volume (not subvolume)
so that it will use the UUID for /etc/fstab rather than the pathname.
---
 blivet/deviceaction.py |  4 +++-
 blivet/devices.py      | 19 +++++++++++++++++++
 blivet/devicetree.py   |  1 +
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index 275a6fe..b8a66f7 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -478,7 +478,9 @@ class ActionCreateFormat(DeviceAction):
             # only do this if the format has a device known to udev
             # (the format might not have a normal device at all)
             if info:
-                self.device.format.uuid = udev_device_get_uuid(info)
+                if self.device.format.type != "btrfs":
+                    self.device.format.uuid = udev_device_get_uuid(info)
+
                 self.device.deviceLinks = udev_device_get_symlinks(info)
             elif self.device.format.type != "tmpfs":
                 # udev lookup failing is a serious issue for anything other than tmpfs
diff --git a/blivet/devices.py b/blivet/devices.py
index 1af4e00..4cfd0b8 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -4340,6 +4340,13 @@ class BTRFSDevice(StorageDevice):
     def path(self):
         return self.parents[0].path
 
+    @property
+    def fstabSpec(self):
+        if self.format.volUUID:
+            spec = "UUID=%s" % self.format.volUUID
+        else:
+            spec = super(BTRFSDevice, self).fstabSpec
+        return spec
 
 class BTRFSVolumeDevice(BTRFSDevice):
     _type = "btrfs volume"
@@ -4502,6 +4509,14 @@ class BTRFSVolumeDevice(BTRFSDevice):
                             data=self.dataLevel,
                             metadata=self.metaDataLevel)
 
+    def _postCreate(self):
+        super(BTRFSVolumeDevice, self)._postCreate()
+        info = udev_get_block_device(self.sysfsPath)
+        if not info:
+            log.error("failed to get updated udev info for new btrfs volume")
+        else:
+            self.format.volUUID = udev_device_get_uuid(info)
+
     def _destroy(self):
         log_method_call(self, self.name, status=self.status)
         for device in self.parents:
@@ -4553,6 +4568,10 @@ class BTRFSSubVolumeDevice(BTRFSDevice):
         btrfs.create_subvolume(mountpoint, self.name)
         self.volume._undo_temp_mount()
 
+    def _postCreate(self):
+        super(BTRFSSubVolumeDevice, self)._postCreate()
+        self.format.volUUID = self.volume.format.volUUID
+
     def _destroy(self):
         log_method_call(self, self.name, status=self.status)
         self.volume._do_temp_mount(orig=True)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index afb48e9..520bb7d 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -1610,6 +1610,7 @@ class DeviceTree(object):
                     raise DeviceTreeError("could not find parent for subvol")
 
                 fmt = getFormat("btrfs", device=btrfs_dev.path, exists=True,
+                                volUUID=btrfs_dev.format.volUUID,
                                 mountopts="subvol=%s" % vol_path)
                 subvol = BTRFSSubVolumeDevice(vol_path,
                                               vol_id=vol_id,
-- 
1.8.4.2



More information about the anaconda-patches mailing list