]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: move all mount options into struct lxc_mount_options
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 25 Apr 2021 08:24:17 +0000 (10:24 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 25 Apr 2021 11:55:49 +0000 (13:55 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c
src/lxc/storage/dir.c

index 71ea7cf95c722d69a77414f747d9fb7c76ae425c..44aa8ba4aa2b6f6a2ea505cfa377c7413c113dab 100644 (file)
@@ -4065,7 +4065,6 @@ void lxc_conf_free(struct lxc_conf *conf)
        free(conf->rootfs.bdev_type);
        free(conf->rootfs.options);
        free(conf->rootfs.path);
-       free(conf->rootfs.data);
        put_lxc_rootfs(&conf->rootfs, true);
        free(conf->logfile);
        if (conf->logfd != -1)
index ef118794ca2234b5db6a1129776091a856326f29..3a787948578fce654b28b8880013626381a81c2d 100644 (file)
@@ -200,6 +200,9 @@ struct lxc_mount_options {
        int relative : 1;
        char userns_path[PATH_MAX];
        int userns_fd;
+       unsigned long mnt_flags;
+       unsigned long prop_flags;
+       char *data;
 };
 
 /* Defines a structure to store the rootfs location, the
@@ -209,8 +212,6 @@ struct lxc_mount_options {
  * @buf                 : static buffer to construct paths
  * @bev_type     : optional backing store type
  * @options      : mount options
- * @mountflags   : the portion of @options that are flags
- * @data         : the portion of @options that are not flags
  * @managed      : whether it is managed by LXC
  * @dfd_mnt     : fd for @mount
  * @dfd_dev : fd for /dev of the container
@@ -230,7 +231,6 @@ struct lxc_rootfs {
        char *bdev_type;
        char *options;
        unsigned long mountflags;
-       char *data;
        bool managed;
        struct lxc_mount_options mnt_opts;
        struct lxc_storage *storage;
@@ -585,6 +585,20 @@ static inline bool idmapped_rootfs_mnt(const struct lxc_rootfs *rootfs)
        return rootfs->mnt_opts.userns_fd >= 0;
 }
 
+static inline void put_lxc_mount_options(struct lxc_mount_options *mnt_opts)
+{
+       mnt_opts->create_dir = 0;
+       mnt_opts->create_file = 0;
+       mnt_opts->optional = 0;
+       mnt_opts->relative = 0;
+       mnt_opts->userns_path[0] = '\0';
+       mnt_opts->mnt_flags = 0;
+       mnt_opts->prop_flags = 0;
+
+       close_prot_errno_disarm(mnt_opts->userns_fd);
+       free_disarm(mnt_opts->data);
+}
+
 static inline void put_lxc_rootfs(struct lxc_rootfs *rootfs, bool unpin)
 {
        if (rootfs) {
@@ -594,6 +608,7 @@ static inline void put_lxc_rootfs(struct lxc_rootfs *rootfs, bool unpin)
                close_prot_errno_disarm(rootfs->mnt_opts.userns_fd);
                if (unpin)
                        close_prot_errno_disarm(rootfs->fd_path_pin);
+               put_lxc_mount_options(&rootfs->mnt_opts);
                storage_put(rootfs->storage);
                rootfs->storage = NULL;
        }
index e987812e4b46a9c35472c6383c227b1fad0cb22d..e04cd714e1f9a0af8e1bd12c0cc405642ac06142 100644 (file)
@@ -2791,8 +2791,8 @@ static int set_config_rootfs_options(const char *key, const char *value,
                                     struct lxc_conf *lxc_conf, void *data)
 {
        __do_free char *dup = NULL, *mdata = NULL, *opts = NULL;
-       unsigned long mflags = 0, pflags = 0;
        struct lxc_rootfs *rootfs = &lxc_conf->rootfs;
+       struct lxc_mount_options *mnt_opts = &rootfs->mnt_opts;
        int ret;
 
        clr_config_rootfs_options(key, lxc_conf, data);
@@ -2803,15 +2803,15 @@ static int set_config_rootfs_options(const char *key, const char *value,
        if (!dup)
                return -ENOMEM;
 
-       ret = parse_lxc_mntopts(&rootfs->mnt_opts, dup);
+       ret = parse_lxc_mntopts(mnt_opts, dup);
        if (ret < 0)
                return ret;
 
-       ret = parse_mntopts(dup, &mflags, &mdata);
+       ret = parse_mntopts(dup, &mnt_opts->mnt_flags, &mdata);
        if (ret < 0)
                return ret_errno(EINVAL);
 
-       ret = parse_propagationopts(dup, &pflags);
+       ret = parse_propagationopts(dup, &mnt_opts->prop_flags);
        if (ret < 0)
                return ret_errno(EINVAL);
 
@@ -2819,13 +2819,12 @@ static int set_config_rootfs_options(const char *key, const char *value,
        if (ret < 0)
                return ret_errno(ENOMEM);
 
-       if (rootfs->mnt_opts.create_dir || rootfs->mnt_opts.create_file ||
-           rootfs->mnt_opts.optional || rootfs->mnt_opts.relative)
+       if (mnt_opts->create_dir || mnt_opts->create_file ||
+           mnt_opts->optional || mnt_opts->relative)
                return syserror_set(-EINVAL, "Invalid LXC specifc mount option for rootfs mount");
 
-       rootfs->mountflags      = mflags | pflags;
+       mnt_opts->data          = move_ptr(mdata);
        rootfs->options         = move_ptr(opts);
-       rootfs->data            = move_ptr(mdata);
 
        return 0;
 }
@@ -5017,7 +5016,7 @@ static inline int clr_config_rootfs_options(const char *key, struct lxc_conf *c,
                                            void *data)
 {
        free_disarm(c->rootfs.options);
-       free_disarm(c->rootfs.data);
+       put_lxc_mount_options(&c->rootfs.mnt_opts);
 
        return 0;
 }
index edbe781adfc80b52eb94088b6ed124480556ae9d..eacf928e027992971410d86b0207a4c7a8cbddba 100644 (file)
@@ -127,8 +127,9 @@ bool dir_detect(const char *path)
 
 int dir_mount(struct lxc_storage *bdev)
 {
+       struct lxc_mount_options *mnt_opts = &bdev->rootfs->mnt_opts;
        __do_free char *mntdata = NULL;
-       unsigned long mflags = 0, mntflags = 0, pflags = 0;
+       unsigned long mflags = 0;
        int ret;
        const char *src;
 
@@ -138,14 +139,6 @@ int dir_mount(struct lxc_storage *bdev)
        if (!bdev->src || !bdev->dest)
                return -22;
 
-       ret = parse_mntopts(bdev->mntopts, &mntflags, &mntdata);
-       if (ret < 0)
-               return log_error_errno(ret, errno, "Failed to parse mount options \"%s\"", bdev->mntopts);
-
-       ret = parse_propagationopts(bdev->mntopts, &pflags);
-       if (ret < 0)
-               return log_error_errno(-EINVAL, EINVAL, "Failed to parse mount propagation options \"%s\"", bdev->mntopts);
-
        src = lxc_storage_get_path(bdev->src, bdev->type);
 
        if (can_use_bind_mounts()) {
@@ -163,28 +156,28 @@ int dir_mount(struct lxc_storage *bdev)
                                        PROTECT_LOOKUP_BENEATH, fd_target, "",
                                        PROTECT_OPATH_DIRECTORY,
                                        PROTECT_LOOKUP_BENEATH, 0,
-                                       bdev->rootfs->mnt_opts.userns_fd, true);
+                                       mnt_opts->userns_fd, true);
                if (ret < 0)
                        return syserror("Failed to mount \"%s\" onto \"%s\"", src, bdev->dest);
        } else {
-               ret = mount(src, bdev->dest, "bind", MS_BIND | MS_REC | mntflags | pflags, mntdata);
+               ret = mount(src, bdev->dest, "bind", MS_BIND | MS_REC | mnt_opts->mnt_flags | mnt_opts->prop_flags, mntdata);
                if (ret < 0)
                        return log_error_errno(-errno, errno, "Failed to mount \"%s\" on \"%s\"", src, bdev->dest);
 
-               if (ret == 0 && (mntflags & MS_RDONLY)) {
-                       mflags = add_required_remount_flags(src, bdev->dest, MS_BIND | MS_REC | mntflags | pflags | MS_REMOUNT);
+               if (ret == 0 && (mnt_opts->mnt_flags & MS_RDONLY)) {
+                       mflags = add_required_remount_flags(src, bdev->dest, MS_BIND | MS_REC | mnt_opts->mnt_flags | mnt_opts->mnt_flags | MS_REMOUNT);
 
                        ret = mount(src, bdev->dest, "bind", mflags, mntdata);
                        if (ret < 0)
                                return log_error_errno(-errno, errno, "Failed to remount \"%s\" on \"%s\" read-only with options \"%s\", mount flags \"%lu\", and propagation flags \"%lu\"",
-                                                      src ? src : "(none)", bdev->dest ? bdev->dest : "(none)", mntdata, mflags, pflags);
+                                                      src ? src : "(none)", bdev->dest ? bdev->dest : "(none)", mntdata, mflags, mnt_opts->mnt_flags);
                        else
                                DEBUG("Remounted \"%s\" on \"%s\" read-only with options \"%s\", mount flags \"%lu\", and propagation flags \"%lu\"",
-                                     src ? src : "(none)", bdev->dest ? bdev->dest : "(none)", mntdata, mflags, pflags);
+                                     src ? src : "(none)", bdev->dest ? bdev->dest : "(none)", mntdata, mflags, mnt_opts->mnt_flags);
                }
 
                TRACE("Mounted \"%s\" on \"%s\" with options \"%s\", mount flags \"%lu\", and propagation flags \"%lu\"",
-                     src ? src : "(none)", bdev->dest ? bdev->dest : "(none)", mntdata, mflags, pflags);
+                     src ? src : "(none)", bdev->dest ? bdev->dest : "(none)", mntdata, mflags, mnt_opts->mnt_flags);
        }
 
        TRACE("Mounted \"%s\" onto \"%s\"", src, bdev->dest);