From c1a51d74ff46422cec55de41c8f2f84d368efa9e Mon Sep 17 00:00:00 2001 From: Jiri Tyr Date: Thu, 29 Sep 2016 06:35:44 +0100 Subject: [PATCH] Fixing bind mount pattern in the mount module (#5084) --- system/mount.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/system/mount.py b/system/mount.py index 90bf6303fc0..ea76a0a9568 100644 --- a/system/mount.py +++ b/system/mount.py @@ -441,12 +441,12 @@ def get_linux_mounts(module): src = mnt['src'] if mnt['fs'] == 'tmpfs' and mnt['root'] != '/': - ### Example: + # == Example: # 65 19 0:35 / /tmp rw shared:25 - tmpfs tmpfs rw # 210 65 0:35 /aaa /tmp/bbb rw shared:25 - tmpfs tmpfs rw - ### Expected result: + # == Expected result: # src=/tmp/aaa - ### + # == shared = None @@ -456,7 +456,7 @@ def get_linux_mounts(module): shared = fld if shared is None: - break + continue dest = None @@ -471,15 +471,15 @@ def get_linux_mounts(module): if dest is not None: src = "%s%s" % (dest, mnt['root']) else: - break + continue elif mnt['root'] != '/' and len(mnt['fields']) > 0: - ### Example: + # == Example: # 67 19 8:18 / /mnt/disk2 rw shared:26 - ext4 /dev/sdb2 rw # 217 65 8:18 /test /tmp/ccc rw shared:26 - ext4 /dev/sdb2 rw - ### Expected result: + # == Expected result: # src=/mnt/disk2/test - ### + # == # Search for parent for j, m in enumerate(mntinfo): @@ -490,13 +490,27 @@ def get_linux_mounts(module): break elif mnt['root'] != '/' and len(mnt['fields']) == 0: - ### Example: + # == Example 1: # 27 20 8:1 /tmp/aaa /tmp/bbb rw - ext4 /dev/sdb2 rw - ### Expected result: + # == Example 2: + # 204 136 253:2 /rootfs / rw - ext4 /dev/sdb2 rw + # 141 140 253:2 /rootfs/tmp/aaa /tmp/bbb rw - ext4 /dev/sdb2 rw + # == Expected result: # src=/tmp/aaa - ### + # == + src = mnt['root'] + # Search for parent + for j, m in enumerate(mntinfo): + if j < i: + if ( + m['src'] == mnt['src'] and + mnt['root'].startswith(m['root'])): + src = src.replace("%s/" % m['root'], '/', 1) + else: + break + mounts[mnt['dst']] = { 'src': src, 'opts': mnt['opts'],