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
* @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
char *bdev_type;
char *options;
unsigned long mountflags;
- char *data;
bool managed;
struct lxc_mount_options mnt_opts;
struct lxc_storage *storage;
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) {
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;
}
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);
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);
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;
}
void *data)
{
free_disarm(c->rootfs.options);
- free_disarm(c->rootfs.data);
+ put_lxc_mount_options(&c->rootfs.mnt_opts);
return 0;
}
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;
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()) {
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);