[node-patches] Change in ovirt-node[master]: utils_fs: add ismount isbindmount python implementation

asegurap at redhat.com asegurap at redhat.com
Wed Jul 2 15:42:32 UTC 2014


Antoni Segura Puimedon has uploaded a new change for review.

Change subject: utils_fs: add ismount isbindmount python implementation
......................................................................

utils_fs: add ismount isbindmount python implementation

python's os.path.ismount does not properly work with bind mounts that
are withing the same device nor does it support file bind mounts.
This patch adds convenience methods that support these cases.

Change-Id: I92e3b9368f795bda587d5de1d61a3a0266038d8f
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M src/ovirt/node/utils/fs/mount.py
1 file changed, 40 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/19/29519/1

diff --git a/src/ovirt/node/utils/fs/mount.py b/src/ovirt/node/utils/fs/mount.py
index 068dd41..a42a685 100644
--- a/src/ovirt/node/utils/fs/mount.py
+++ b/src/ovirt/node/utils/fs/mount.py
@@ -23,6 +23,7 @@
 File system mounting bindings
 """
 
+import collections
 import ctypes
 import os
 
@@ -52,6 +53,45 @@
 MS_I_VERSION = 1 << 23  # Update inode I_version field.
 MS_STRICTATIME = 1 << 24  # Always perform atime updates.
 
+_MountEntry = collections.namedtuple(
+    '_MountEntry',
+    ('mount_id',  # Unique ID of the mount (may be reused after umount
+     'parent_id',  # ID of the parent (self for the top of the mount tree)
+     'major_minor',  # st_dev value for files on fs, e.g. 0:26
+     'root',  # Root of the mount withing the filesystem
+     'mount_point',  # mount point relative to the process root
+     'mount_opts',  # per mount options
+     'opts',  # optional tag:value fields
+     'type',  # name of the filesystem, e.g. ext3
+     'mount_src',  # fs specific info (or 'none'), e.g. /dev/mapper/foo
+     'super_opts',  # super block options, e.g. rw,seclabel,data=ordered
+     ))
+
+
+def _entries():
+    """Generates _MountEntries with the information in /proc/self/mountinfo"""
+    with open('/proc/self/mountinfo') as mount_file:
+        for line in mount_file:
+            tokens = line.split()
+            yield _MountEntry(*(tokens[:6] + [' '.join(tokens[6:-4])] +
+                              tokens[-3:]))
+
+
+def ismount(path):
+    if os.path.islink(path):  # Must be tested first
+        return False
+    elif os.path.isdir(path):
+        return os.path.ismount(path)
+    else:  # os.path.ismount does not operate with file mount points
+        path = os.path.abspath(path)
+        return any(entry for entry in _entries() if entry.mount_point == path)
+
+
+def isbindmount(path):
+    path = os.path.abspath(path)
+    return any(entry for entry in _entries() if
+               entry.mount_point == path and entry.root != '/')
+
 
 def mount(source, target, fstype='', flags=0L, data=None):
     """Mount a filesystem source to the target of type fstype"""


-- 
To view, visit http://gerrit.ovirt.org/29519
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I92e3b9368f795bda587d5de1d61a3a0266038d8f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>



More information about the node-patches mailing list