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

David Lehman dlehman at redhat.com
Fri Nov 15 14:32:02 UTC 2013


---
 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 a53fdb5..497934e 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -476,7 +476,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 6c8acd3..2f85d64 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -4348,6 +4348,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"
@@ -4537,6 +4544,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:
@@ -4588,6 +4603,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 4ef67d3..3b9e7a0 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -1608,6 +1608,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.1.4



More information about the anaconda-patches mailing list