diff options
author | Iago López Galeiras <iago@kinvolk.io> | 2019-07-24 16:41:29 +0200 |
---|---|---|
committer | Iago López Galeiras <iago@kinvolk.io> | 2019-07-24 17:17:42 +0200 |
commit | a11fd4067bb8a805b9d7af0af0740b40abd24ae9 (patch) | |
tree | 4a7e6674f04795dacfcf53da8d2c4832a6f5146d /src/nspawn/nspawn-mount.c | |
parent | 372901d071400510875a3db3001cf92fa2693342 (diff) | |
download | systemd-a11fd4067bb8a805b9d7af0af0740b40abd24ae9.tar.gz |
Revert "nspawn: remove unnecessary mount option parsing logic"
This reverts commit 72d967df3e27186dd014bed2c6e7400cc32d84c5.
Revert this because it broke the `norbind` option of the bind flags
because it does bind-mounts unconditionally recursive.
Let's bring the old logic back.
Fixes: #13170
Diffstat (limited to 'src/nspawn/nspawn-mount.c')
-rw-r--r-- | src/nspawn/nspawn-mount.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/nspawn/nspawn-mount.c b/src/nspawn/nspawn-mount.c index 82b7068fcd..31f7f3e445 100644 --- a/src/nspawn/nspawn-mount.c +++ b/src/nspawn/nspawn-mount.c @@ -681,14 +681,55 @@ int mount_all(const char *dest, return 0; } +static int parse_mount_bind_options(const char *options, unsigned long *mount_flags, char **mount_opts) { + const char *p = options; + unsigned long flags = *mount_flags; + char *opts = NULL; + int r; + + assert(options); + + for (;;) { + _cleanup_free_ char *word = NULL; + + r = extract_first_word(&p, &word, ",", 0); + if (r < 0) + return log_error_errno(r, "Failed to extract mount option: %m"); + if (r == 0) + break; + + if (streq(word, "rbind")) + flags |= MS_REC; + else if (streq(word, "norbind")) + flags &= ~MS_REC; + else { + log_error("Invalid bind mount option: %s", word); + return -EINVAL; + } + } + + *mount_flags = flags; + /* in the future mount_opts will hold string options for mount(2) */ + *mount_opts = opts; + + return 0; +} + static int mount_bind(const char *dest, CustomMount *m) { - _cleanup_free_ char *where = NULL; + _cleanup_free_ char *mount_opts = NULL, *where = NULL; + unsigned long mount_flags = MS_BIND | MS_REC; struct stat source_st, dest_st; int r; assert(dest); assert(m); + if (m->options) { + r = parse_mount_bind_options(m->options, &mount_flags, &mount_opts); + if (r < 0) + return r; + } + if (stat(m->source, &source_st) < 0) return log_error_errno(errno, "Failed to stat %s: %m", m->source); @@ -727,7 +768,7 @@ static int mount_bind(const char *dest, CustomMount *m) { return log_error_errno(r, "Failed to create mount point %s: %m", where); } - r = mount_verbose(LOG_ERR, m->source, where, NULL, MS_BIND | MS_REC, m->options); + r = mount_verbose(LOG_ERR, m->source, where, NULL, mount_flags, mount_opts); if (r < 0) return r; |