[Yum-devel] [PATCH 2/3] plugins/fs-snapshot: use a dictionary to represent each "volume"

Mike Snitzer snitzer at redhat.com
Wed Feb 3 07:12:03 UTC 2010


From: Mike Snitzer <msnitzer at fedoraproject.org>

Using a dictionary to represent a volume's attributes allows additional
capabilities to be added to the fs-snapshot plugin (e.g. LVM snapshot
support).

Signed-off-by: Mike Snitzer <msnitzer at fedoraproject.org>
---
 plugins/fs-snapshot/fs-snapshot.py |   46 ++++++++++++++++++++++++-----------
 1 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/plugins/fs-snapshot/fs-snapshot.py b/plugins/fs-snapshot/fs-snapshot.py
index 215f7bb..c9f3586 100644
--- a/plugins/fs-snapshot/fs-snapshot.py
+++ b/plugins/fs-snapshot/fs-snapshot.py
@@ -36,20 +36,18 @@ from subprocess import Popen,PIPE
 requires_api_version = '2.4'
 plugin_type = (TYPE_CORE,)
 
-def pretrans_hook(conduit):
-    """
-    This runs before the transaction starts.  Try to snapshot anything and
-    everything that is snapshottable, since we do not know what an RPM will
-    modify (thank you scriptlets).
-    """
-    # common snapshot tag format: yum_${year}${month}${day}${hour}${minute}${sec}
-    snapshot_tag = "yum_" + time.strftime("%Y%m%d%H%M%S")
+def get_volumes(conduit):
+    # return list of volume dictionaries
+    volumes = []
 
     excluded_mntpnts = conduit.confString('main', 'exclude', default="").split()
     try:
         mtabfile = open('/etc/mtab', 'r')
         for line in mtabfile.readlines():
             device, mntpnt, fstype, rest = line.split(' ', 3)
+            volume = { "device" : device,
+                       "mntpnt" : mntpnt,
+                       "fstype" : fstype }
 
             if mntpnt in excluded_mntpnts:
                 continue
@@ -63,16 +61,18 @@ def pretrans_hook(conduit):
             if not device.find("/") == 0:
                 continue
 
-            rc = _create_snapshot(conduit, snapshot_tag, device, mntpnt, fstype)
-            if rc == 1:
-                conduit.info(1, "fs-snapshot: error snapshotting " + mntpnt)
+            volumes.append(volume)
+
         mtabfile.close()
 
     except Exception as (errno, strerror):
         msg = "fs-snapshot: error reading /etc/mtab: %s" % (strerror)
         conduit.error(1, msg)
 
-def _create_snapshot(conduit, snapshot_tag, device, mntpnt, fstype):
+    return volumes
+
+
+def _create_snapshot(conduit, snapshot_tag, volume):
     """
     Determines if the device is capable of being snapshotted and then calls the
     appropriate snapshotting function.  The idea is you could add something for
@@ -83,12 +83,12 @@ def _create_snapshot(conduit, snapshot_tag, device, mntpnt, fstype):
     # which filesystems they don't want snapshotted and we'd automatically match
     # them here and just return.
 
-    if fstype == "btrfs":
-        return _create_btrfs_snapshot(conduit, snapshot_tag, mntpnt)
+    if volume["fstype"] == "btrfs":
+        return _create_btrfs_snapshot(conduit, snapshot_tag, volume)
 
     return 0
 
-def _create_btrfs_snapshot(conduit, snapshot_tag, mntpnt):
+def _create_btrfs_snapshot(conduit, snapshot_tag, volume):
     """
     Runs the commands necessary for a snapshot.  Basically its just
 
@@ -98,6 +98,7 @@ def _create_btrfs_snapshot(conduit, snapshot_tag, mntpnt):
 
     and then we're done.
     """
+    mntpnt = volume["mntpnt"]
     #/etc/mtab doesn't have /'s at the end of the mount point, unless of course
     #the mountpoint is /
     if not mntpnt.endswith("/"):
@@ -119,3 +120,18 @@ def init_hook(conduit):
     if hasattr(conduit, 'registerPackageName'):
         conduit.registerPackageName("yum-plugin-fs-snapshot")
     conduit.info(3, "Loading File System Snapshot support.")
+
+def pretrans_hook(conduit):
+    """
+    This runs before the transaction starts.  Try to snapshot anything and
+    everything that is snapshottable, since we do not know what an RPM will
+    modify (thank you scriptlets).
+    """
+    # common snapshot tag format: yum_${year}${month}${day}${hour}${minute}${sec}
+    snapshot_tag = "yum_" + time.strftime("%Y%m%d%H%M%S")
+
+    volumes = get_volumes(conduit)
+    for volume in volumes:
+        rc = _create_snapshot(conduit, snapshot_tag, volume)
+        if rc == 1:
+            conduit.error(1, "fs-snapshot: error snapshotting " + volume["mntpnt"])
-- 
1.6.5.2



More information about the Yum-devel mailing list