summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorRobert Schweikert <rjschwei@suse.com>2017-11-27 19:05:52 -0500
committerScott Moser <smoser@ubuntu.com>2018-01-24 09:52:58 -0500
commitb28ab78089d362c5c6cab985feee0f5f84c9db44 (patch)
tree85b0d7ecd54d7227d4526629ff9ca421bd9a29fc /cloudinit/util.py
parent8a9421421497b3e7c05589c62389745d565c6633 (diff)
downloadvyos-cloud-init-b28ab78089d362c5c6cab985feee0f5f84c9db44.tar.gz
vyos-cloud-init-b28ab78089d362c5c6cab985feee0f5f84c9db44.zip
btrfs: support resizing if root is mounted ro.
Resize of btrfs fails if the mount point for the file system we are trying to resize, i.e. the root of the filesystem is read only. With this change we use a known (currently snapper specific) rw location to work around a flaw that blocks resizing of the ro filesystem. LP: #1734787
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index df0aa5db..9976400f 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -2059,7 +2059,7 @@ def expand_package_list(version_fmt, pkgs):
return pkglist
-def parse_mount_info(path, mountinfo_lines, log=LOG):
+def parse_mount_info(path, mountinfo_lines, log=LOG, get_mnt_opts=False):
"""Return the mount information for PATH given the lines from
/proc/$$/mountinfo."""
@@ -2121,11 +2121,16 @@ def parse_mount_info(path, mountinfo_lines, log=LOG):
match_mount_point = mount_point
match_mount_point_elements = mount_point_elements
+ mount_options = parts[5]
- if devpth and fs_type and match_mount_point:
- return (devpth, fs_type, match_mount_point)
+ if get_mnt_opts:
+ if devpth and fs_type and match_mount_point and mount_options:
+ return (devpth, fs_type, match_mount_point, mount_options)
else:
- return None
+ if devpth and fs_type and match_mount_point:
+ return (devpth, fs_type, match_mount_point)
+
+ return None
def parse_mtab(path):
@@ -2195,7 +2200,7 @@ def parse_mount(path):
return None
-def get_mount_info(path, log=LOG):
+def get_mount_info(path, log=LOG, get_mnt_opts=False):
# Use /proc/$$/mountinfo to find the device where path is mounted.
# This is done because with a btrfs filesystem using os.stat(path)
# does not return the ID of the device.
@@ -2227,7 +2232,7 @@ def get_mount_info(path, log=LOG):
mountinfo_path = '/proc/%s/mountinfo' % os.getpid()
if os.path.exists(mountinfo_path):
lines = load_file(mountinfo_path).splitlines()
- return parse_mount_info(path, lines, log)
+ return parse_mount_info(path, lines, log, get_mnt_opts)
elif os.path.exists("/etc/mtab"):
return parse_mtab(path)
else:
@@ -2613,4 +2618,10 @@ def wait_for_files(flist, maxwait, naplen=.5, log_pre=""):
return need
+def mount_is_read_write(mount_point):
+ """Check whether the given mount point is mounted rw"""
+ result = get_mount_info(mount_point, get_mnt_opts=True)
+ mount_opts = result[-1].split(',')
+ return mount_opts[0] == 'rw'
+
# vi: ts=4 expandtab