summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorTim Daly Jr. <timjr@yahoo-inc.com>2013-11-13 19:28:52 -0800
committerTim Daly Jr. <timjr@yahoo-inc.com>2013-11-13 19:28:52 -0800
commit9af91df4446ec7e62bc780612e05f869c269ccf0 (patch)
treeedd4f2b83ccbc2f416223ceba00436b48ed1bcec /cloudinit
parent29e34159eea27e6136ea62fc8bd16252a132b295 (diff)
downloadvyos-cloud-init-9af91df4446ec7e62bc780612e05f869c269ccf0.tar.gz
vyos-cloud-init-9af91df4446ec7e62bc780612e05f869c269ccf0.zip
Fix bug lp:1248625 by reading /etc/mtab when mountinfo is not present.
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/util.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 9e6e0a73..a8ddb390 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1737,6 +1737,15 @@ def parse_mount_info(path, mountinfo_lines, log=LOG):
return None
+def parse_mtab(path):
+ """On older kernels there's no /proc/$$/mountinfo, so use mtab."""
+ for line in load_file("/etc/mtab").splitlines():
+ devpth, mount_point, fs_type = line.split()[:3]
+ if mount_point == path:
+ return devpth, fs_type, mount_point
+ 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 +1776,11 @@ def get_mount_info(path, log=LOG):
# 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:
+ return parse_mtab(path)
def which(program):