[PATCH 16/17] Add support for read-only btrfs snapshots.
David Lehman
dlehman at redhat.com
Thu Jun 5 16:47:36 UTC 2014
---
blivet/devicelibs/btrfs.py | 13 +++++++++++--
blivet/devices.py | 5 ++++-
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/blivet/devicelibs/btrfs.py b/blivet/devicelibs/btrfs.py
index e1d08d0..0e22942 100644
--- a/blivet/devicelibs/btrfs.py
+++ b/blivet/devicelibs/btrfs.py
@@ -141,11 +141,20 @@ def get_default_subvolume(mountpoint):
return default
-def create_snapshot(source, dest):
+def create_snapshot(source, dest, ro=False):
+ """
+ :param str source: path to source subvolume
+ :param str dest: path to new snapshot subvolume
+ :keyword bool ro: whether to create a read-only snapshot
+ """
if not os.path.ismount(source):
raise ValueError("source is not a mounted subvolume")
- args = ["subvol", "snapshot", source, dest]
+ args = ["subvol", "snapshot"]
+ if ro:
+ args.append("-r")
+
+ args.extend([source, dest])
return btrfs(args)
_DEVICE_REGEX_STR = r'devid[ \t]+(\d+)[ \t]+size[ \t]+(\S+)[ \t]+used[ \t]+(\S+)[ \t]+path[ \t]+(\S+)\n'
diff --git a/blivet/devices.py b/blivet/devices.py
index 8eec9a6..dea4473 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -5253,6 +5253,7 @@ class BTRFSSnapShotDevice(BTRFSSubVolumeDevice):
:type fmt: :class:`~.formats.DeviceFormat` or a subclass of it
:keyword str sysfsPath: sysfs device path
:keyword :class:`~.BTRFSDevice` source: the snapshot source
+ :keyword bool readOnly: create a read-only snapshot
Snapshot source can be either a subvolume or a top-level volume.
@@ -5271,6 +5272,8 @@ class BTRFSSnapShotDevice(BTRFSSubVolumeDevice):
self.source = source
""" the snapshot's source subvolume """
+ self.readOnly = kwargs.pop("readOnly", False)
+
super(BTRFSSnapShotDevice, self).__init__(*args, **kwargs)
if source and getattr(source, "volume", source) != self.volume:
@@ -5292,7 +5295,7 @@ class BTRFSSnapShotDevice(BTRFSSubVolumeDevice):
dest_path = "%s/%s" % (mountpoint, self.name)
try:
- btrfs.create_snapshot(source_path, dest_path)
+ btrfs.create_snapshot(source_path, dest_path, ro=self.readOnly)
finally:
self.volume._undo_temp_mount()
--
1.9.0
More information about the anaconda-patches
mailing list