conf: rework lxc specific mount option parsing

parent 12cf9f5a
......@@ -2090,33 +2090,48 @@ skipremount:
return 0;
}
const char *lxc_mount_options_info[LXC_MOUNT_MAX] = {
"create=dir",
"create=file",
"optional",
"relative",
};
/* Remove "optional", "create=dir", and "create=file" from mntopt */
static void cull_mntent_opt(struct mntent *mntent)
void parse_lxc_mntopts(struct lxc_mount_options *opts, char *mnt_opts)
{
int i;
char *list[] = {
"create=dir",
"create=file",
"optional",
"relative",
NULL
};
for (i = 0; list[i]; i++) {
for (size_t i = LXC_MOUNT_CREATE_DIR; i < LXC_MOUNT_MAX; i++) {
const char *opt_name = lxc_mount_options_info[i];
char *p, *p2;
p = strstr(mntent->mnt_opts, list[i]);
p = strstr(mnt_opts, opt_name);
if (!p)
continue;
p2 = strchr(p, ',');
if (!p2) {
/* no more mntopts, so just chop it here */
*p = '\0';
switch (i) {
case LXC_MOUNT_CREATE_DIR:
opts->create_dir = 1;
break;
case LXC_MOUNT_CREATE_FILE:
opts->create_file = 1;
break;
case LXC_MOUNT_OPTIONAL:
opts->optional = 1;
break;
case LXC_MOUNT_RELATIVE:
opts->relative = 1;
break;
default:
WARN("Unknown LXC specific mount option");
continue;
}
memmove(p, p2 + 1, strlen(p2 + 1) + 1);
p2 = strchr(p, ',');
if (!p2)
*p = '\0'; /* no more mntopts, so just chop it here */
else
memmove(p, p2 + 1, strlen(p2 + 1) + 1);
}
}
......@@ -2178,6 +2193,7 @@ static inline int mount_entry_on_generic(struct mntent *mntent,
char *rootfs_path = NULL;
int ret;
bool dev, optional, relative;
struct lxc_mount_options opts = {};
optional = hasmntopt(mntent, "optional") != NULL;
dev = hasmntopt(mntent, "dev") != NULL;
......@@ -2194,7 +2210,7 @@ static inline int mount_entry_on_generic(struct mntent *mntent,
return -1;
}
cull_mntent_opt(mntent);
parse_lxc_mntopts(&opts, mntent->mnt_opts);
ret = parse_propagationopts(mntent->mnt_opts, &pflags);
if (ret < 0)
......
......@@ -181,6 +181,23 @@ struct lxc_tty_info {
struct lxc_terminal_info *tty;
};
typedef enum lxc_mount_options_t {
LXC_MOUNT_CREATE_DIR = 0,
LXC_MOUNT_CREATE_FILE = 1,
LXC_MOUNT_OPTIONAL = 2,
LXC_MOUNT_RELATIVE = 3,
LXC_MOUNT_MAX = 4,
} lxc_mount_options_t;
__hidden extern const char *lxc_mount_options_info[LXC_MOUNT_MAX];
struct lxc_mount_options {
int create_dir : 1;
int create_file : 1;
int optional : 1;
int relative : 1;
};
/* Defines a structure to store the rootfs location, the
* optionals pivot_root, rootfs mount paths
* @path : the rootfs source (directory or device)
......@@ -211,6 +228,7 @@ struct lxc_rootfs {
unsigned long mountflags;
char *data;
bool managed;
struct lxc_mount_options mnt_opts;
};
/*
......@@ -509,6 +527,7 @@ __hidden extern int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), v
const char *fn_name);
__hidden extern int parse_mntopts(const char *mntopts, unsigned long *mntflags, char **mntdata);
__hidden extern int parse_propagationopts(const char *mntopts, unsigned long *pflags);
__hidden extern void parse_lxc_mntopts(struct lxc_mount_options *opts, char *mnt_opts);
__hidden extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
__hidden extern void suggest_default_idmap(void);
__hidden extern FILE *make_anonymous_mount_file(struct lxc_list *mount, bool include_nesting_helpers);
......
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