conf: move all mount options into struct lxc_mount_options

parent 3b59ddb6
...@@ -4065,7 +4065,6 @@ void lxc_conf_free(struct lxc_conf *conf) ...@@ -4065,7 +4065,6 @@ void lxc_conf_free(struct lxc_conf *conf)
free(conf->rootfs.bdev_type); free(conf->rootfs.bdev_type);
free(conf->rootfs.options); free(conf->rootfs.options);
free(conf->rootfs.path); free(conf->rootfs.path);
free(conf->rootfs.data);
put_lxc_rootfs(&conf->rootfs, true); put_lxc_rootfs(&conf->rootfs, true);
free(conf->logfile); free(conf->logfile);
if (conf->logfd != -1) if (conf->logfd != -1)
......
...@@ -200,6 +200,9 @@ struct lxc_mount_options { ...@@ -200,6 +200,9 @@ struct lxc_mount_options {
int relative : 1; int relative : 1;
char userns_path[PATH_MAX]; char userns_path[PATH_MAX];
int userns_fd; int userns_fd;
unsigned long mnt_flags;
unsigned long prop_flags;
char *data;
}; };
/* Defines a structure to store the rootfs location, the /* Defines a structure to store the rootfs location, the
...@@ -209,8 +212,6 @@ struct lxc_mount_options { ...@@ -209,8 +212,6 @@ struct lxc_mount_options {
* @buf : static buffer to construct paths * @buf : static buffer to construct paths
* @bev_type : optional backing store type * @bev_type : optional backing store type
* @options : mount options * @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 * @managed : whether it is managed by LXC
* @dfd_mnt : fd for @mount * @dfd_mnt : fd for @mount
* @dfd_dev : fd for /dev of the container * @dfd_dev : fd for /dev of the container
...@@ -230,7 +231,6 @@ struct lxc_rootfs { ...@@ -230,7 +231,6 @@ struct lxc_rootfs {
char *bdev_type; char *bdev_type;
char *options; char *options;
unsigned long mountflags; unsigned long mountflags;
char *data;
bool managed; bool managed;
struct lxc_mount_options mnt_opts; struct lxc_mount_options mnt_opts;
struct lxc_storage *storage; struct lxc_storage *storage;
...@@ -585,6 +585,20 @@ static inline bool idmapped_rootfs_mnt(const struct lxc_rootfs *rootfs) ...@@ -585,6 +585,20 @@ static inline bool idmapped_rootfs_mnt(const struct lxc_rootfs *rootfs)
return rootfs->mnt_opts.userns_fd >= 0; 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) static inline void put_lxc_rootfs(struct lxc_rootfs *rootfs, bool unpin)
{ {
if (rootfs) { if (rootfs) {
...@@ -594,6 +608,7 @@ static inline void put_lxc_rootfs(struct lxc_rootfs *rootfs, bool unpin) ...@@ -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); close_prot_errno_disarm(rootfs->mnt_opts.userns_fd);
if (unpin) if (unpin)
close_prot_errno_disarm(rootfs->fd_path_pin); close_prot_errno_disarm(rootfs->fd_path_pin);
put_lxc_mount_options(&rootfs->mnt_opts);
storage_put(rootfs->storage); storage_put(rootfs->storage);
rootfs->storage = NULL; rootfs->storage = NULL;
} }
......
...@@ -2581,8 +2581,8 @@ static int set_config_rootfs_options(const char *key, const char *value, ...@@ -2581,8 +2581,8 @@ static int set_config_rootfs_options(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
__do_free char *dup = NULL, *mdata = NULL, *opts = NULL; __do_free char *dup = NULL, *mdata = NULL, *opts = NULL;
unsigned long mflags = 0, pflags = 0;
struct lxc_rootfs *rootfs = &lxc_conf->rootfs; struct lxc_rootfs *rootfs = &lxc_conf->rootfs;
struct lxc_mount_options *mnt_opts = &rootfs->mnt_opts;
int ret; int ret;
clr_config_rootfs_options(key, lxc_conf, data); clr_config_rootfs_options(key, lxc_conf, data);
...@@ -2593,15 +2593,15 @@ static int set_config_rootfs_options(const char *key, const char *value, ...@@ -2593,15 +2593,15 @@ static int set_config_rootfs_options(const char *key, const char *value,
if (!dup) if (!dup)
return -ENOMEM; return -ENOMEM;
ret = parse_lxc_mntopts(&rootfs->mnt_opts, dup); ret = parse_lxc_mntopts(mnt_opts, dup);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = parse_mntopts(dup, &mflags, &mdata); ret = parse_mntopts(dup, &mnt_opts->mnt_flags, &mdata);
if (ret < 0) if (ret < 0)
return ret_errno(EINVAL); return ret_errno(EINVAL);
ret = parse_propagationopts(dup, &pflags); ret = parse_propagationopts(dup, &mnt_opts->prop_flags);
if (ret < 0) if (ret < 0)
return ret_errno(EINVAL); return ret_errno(EINVAL);
...@@ -2609,13 +2609,12 @@ static int set_config_rootfs_options(const char *key, const char *value, ...@@ -2609,13 +2609,12 @@ static int set_config_rootfs_options(const char *key, const char *value,
if (ret < 0) if (ret < 0)
return ret_errno(ENOMEM); return ret_errno(ENOMEM);
if (rootfs->mnt_opts.create_dir || rootfs->mnt_opts.create_file || if (mnt_opts->create_dir || mnt_opts->create_file ||
rootfs->mnt_opts.optional || rootfs->mnt_opts.relative) mnt_opts->optional || mnt_opts->relative)
return syserror_set(-EINVAL, "Invalid LXC specifc mount option for rootfs mount"); 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->options = move_ptr(opts);
rootfs->data = move_ptr(mdata);
return 0; return 0;
} }
...@@ -4569,7 +4568,7 @@ static inline int clr_config_rootfs_options(const char *key, struct lxc_conf *c, ...@@ -4569,7 +4568,7 @@ static inline int clr_config_rootfs_options(const char *key, struct lxc_conf *c,
void *data) void *data)
{ {
free_disarm(c->rootfs.options); free_disarm(c->rootfs.options);
free_disarm(c->rootfs.data); put_lxc_mount_options(&c->rootfs.mnt_opts);
return 0; return 0;
} }
......
...@@ -127,8 +127,9 @@ bool dir_detect(const char *path) ...@@ -127,8 +127,9 @@ bool dir_detect(const char *path)
int dir_mount(struct lxc_storage *bdev) int dir_mount(struct lxc_storage *bdev)
{ {
struct lxc_mount_options *mnt_opts = &bdev->rootfs->mnt_opts;
__do_free char *mntdata = NULL; __do_free char *mntdata = NULL;
unsigned long mflags = 0, mntflags = 0, pflags = 0; unsigned long mflags = 0;
int ret; int ret;
const char *src; const char *src;
...@@ -138,14 +139,6 @@ int dir_mount(struct lxc_storage *bdev) ...@@ -138,14 +139,6 @@ int dir_mount(struct lxc_storage *bdev)
if (!bdev->src || !bdev->dest) if (!bdev->src || !bdev->dest)
return -22; 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); src = lxc_storage_get_path(bdev->src, bdev->type);
if (can_use_bind_mounts()) { if (can_use_bind_mounts()) {
...@@ -163,28 +156,28 @@ int dir_mount(struct lxc_storage *bdev) ...@@ -163,28 +156,28 @@ int dir_mount(struct lxc_storage *bdev)
PROTECT_LOOKUP_BENEATH, fd_target, "", PROTECT_LOOKUP_BENEATH, fd_target, "",
PROTECT_OPATH_DIRECTORY, PROTECT_OPATH_DIRECTORY,
PROTECT_LOOKUP_BENEATH, 0, PROTECT_LOOKUP_BENEATH, 0,
bdev->rootfs->mnt_opts.userns_fd, true); mnt_opts->userns_fd, true);
if (ret < 0) if (ret < 0)
return syserror("Failed to mount \"%s\" onto \"%s\"", src, bdev->dest); return syserror("Failed to mount \"%s\" onto \"%s\"", src, bdev->dest);
} else { } 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) if (ret < 0)
return log_error_errno(-errno, errno, "Failed to mount \"%s\" on \"%s\"", src, bdev->dest); return log_error_errno(-errno, errno, "Failed to mount \"%s\" on \"%s\"", src, bdev->dest);
if (ret == 0 && (mntflags & MS_RDONLY)) { if (ret == 0 && (mnt_opts->mnt_flags & MS_RDONLY)) {
mflags = add_required_remount_flags(src, bdev->dest, MS_BIND | MS_REC | mntflags | pflags | MS_REMOUNT); 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); ret = mount(src, bdev->dest, "bind", mflags, mntdata);
if (ret < 0) 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\"", 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 else
DEBUG("Remounted \"%s\" on \"%s\" read-only with options \"%s\", mount flags \"%lu\", and propagation flags \"%lu\"", 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\"", 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); TRACE("Mounted \"%s\" onto \"%s\"", src, bdev->dest);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment