← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~harlowja/cloud-init/mtab-fix into lp:cloud-init

 

Joshua Harlow has proposed merging lp:~harlowja/cloud-init/mtab-fix into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1248625 in cloud-init: "resizefs fails on linux kernel versions < 2.6.26 with error : IOError: [Errno 2] No such file or directory: '/proc/2857/mountinfo'"
  https://bugs.launchpad.net/cloud-init/+bug/1248625

For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/mtab-fix/+merge/195453

Attempt reading /etc/mtab when mountinfo is not present.
-- 
https://code.launchpad.net/~harlowja/cloud-init/mtab-fix/+merge/195453
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/mtab-fix into lp:cloud-init.
=== modified file 'cloudinit/util.py'
--- cloudinit/util.py	2013-10-04 21:29:25 +0000
+++ cloudinit/util.py	2013-11-15 22:42:10 +0000
@@ -1737,6 +1737,17 @@
         return None
 
 
+def parse_mtab(path):
+    for line in load_file("/etc/mtab").splitlines():
+        try:
+            devpth, mount_point, fs_type = line.split()[:3]
+            if mount_point == path:
+                return devpth, fs_type, mount_point
+        except ValueError:
+            pass
+    return None
+
+
 def get_mount_info(path, log=LOG):
     # Use /proc/$$/mountinfo to find the device where path is mounted.
     # This is done because with a btrfs filesystem using os.stat(path)
@@ -1767,8 +1778,12 @@
     # So use /proc/$$/mountinfo to find the device underlying the
     # input path.
     mountinfo_path = '/proc/%s/mountinfo' % os.getpid()
-    lines = load_file(mountinfo_path).splitlines()
-    return parse_mount_info(path, lines, log)
+    if os.path.exists(mountinfo_path):
+        lines = load_file(mountinfo_path).splitlines()
+        return parse_mount_info(path, lines, log)
+    else:
+        # On older kernels there's no /proc/$$/mountinfo, so use mtab.
+        return parse_mtab(path)
 
 
 def which(program):


Follow ups