Skip to content

Commit

Permalink
mock: Work around bug setting propagation for recursive bind-mounts
Browse files Browse the repository at this point in the history
In util-linux versions before 2.33, the mount program does not make
new bind-mounts recursive when the propagation is specified in the
same command (rhbz#1584443). This affects RHEL 7 and 8.

Instead, make the bind-mount first, then remount it to change mount
options and/or propagation. This is the "classic" method described
in the mount(8) man page, which explains that userspace must issue
separate system calls, even if the options are provided in a single
command. Use this method for all bind-mounts.

Also, adjust the return value from this method when the bind-mount
is already mounted, for consistency.

Closes: #712
  • Loading branch information
dpward authored and praiskup committed Apr 13, 2021
1 parent 9f33b5a commit 163b24e
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions mock/py/mockbuild/mounts.py
Expand Up @@ -96,23 +96,24 @@ def __init__(self, srcpath, bindpath, recursive=False, options=None):

@traceLog()
def mount(self):
if not self.mounted:
if os.path.isdir(self.srcpath):
file_util.mkdirIfAbsent(self.bindpath)
elif not os.path.exists(self.bindpath):
normbindpath = os.path.normpath(self.bindpath)
file_util.mkdirIfAbsent(os.path.dirname(normbindpath))
file_util.touch(self.bindpath)
cmd = ['/bin/mount', '-n']
if self.recursive:
cmd.append('--rbind')
else:
cmd.append('--bind')
if self.options:
cmd += ['-o', self.options]
cmd += [self.srcpath, self.bindpath]
util.do(cmd)
if self.mounted:
return None
if os.path.isdir(self.srcpath):
file_util.mkdirIfAbsent(self.bindpath)
elif not os.path.exists(self.bindpath):
normbindpath = os.path.normpath(self.bindpath)
file_util.mkdirIfAbsent(os.path.dirname(normbindpath))
file_util.touch(self.bindpath)
bind_option = 'rbind' if self.recursive else 'bind'
util.do(['/bin/mount', '-n', '-o', bind_option, self.srcpath,
self.bindpath])
self.mounted = True
# Remount the new bind-mount to set specified options (rhbz#1584443).
# Userspace must implement this as separate system calls anyway.
if self.options:
options = ','.join(['remount', self.options, bind_option])
util.do(['/bin/mount', '-n', '-o', options, self.srcpath,
self.bindpath])
return True

@traceLog()
Expand Down

0 comments on commit 163b24e

Please sign in to comment.