mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-14 23:23:11 +00:00
lxc: add a new lxc.mount.entry keyword
The purpose of this new keyword is to save in main config file all the lines of a provided fstab file. This will ultimately replace the the lxc.mount keyword when lxc scripts will use the new keyword. Warning: I did not validated this patch in all conditions of provided malformed input string. Signed-off-by: Michel Normand <michel_mno@laposte.net> Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
parent
88329c69cd
commit
e7938e9ee3
@ -536,23 +536,13 @@ static int parse_mntopts(struct mntent *mntent, unsigned long *mntflags,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setup_mount(const char *fstab)
|
static int mount_file_entries(FILE *file)
|
||||||
{
|
{
|
||||||
struct mntent *mntent;
|
struct mntent *mntent;
|
||||||
FILE *file;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
unsigned long mntflags;
|
unsigned long mntflags;
|
||||||
char *mntdata;
|
char *mntdata;
|
||||||
|
|
||||||
if (!fstab)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
file = setmntent(fstab, "r");
|
|
||||||
if (!file) {
|
|
||||||
SYSERROR("failed to use '%s'", fstab);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ((mntent = getmntent(file))) {
|
while ((mntent = getmntent(file))) {
|
||||||
|
|
||||||
mntflags = 0;
|
mntflags = 0;
|
||||||
@ -580,10 +570,55 @@ static int setup_mount(const char *fstab)
|
|||||||
|
|
||||||
INFO("mount points have been setup");
|
INFO("mount points have been setup");
|
||||||
out:
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int setup_mount(const char *fstab)
|
||||||
|
{
|
||||||
|
FILE *file;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!fstab)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
file = setmntent(fstab, "r");
|
||||||
|
if (!file) {
|
||||||
|
SYSERROR("failed to use '%s'", fstab);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = mount_file_entries(file);
|
||||||
|
|
||||||
endmntent(file);
|
endmntent(file);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int setup_mount_entries(struct lxc_list *mount)
|
||||||
|
{
|
||||||
|
FILE *file;
|
||||||
|
struct lxc_list *iterator;
|
||||||
|
char *mount_entry;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
file = tmpfile();
|
||||||
|
if (!file) {
|
||||||
|
ERROR("tmpfile error: %m");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
lxc_list_for_each(iterator, mount) {
|
||||||
|
mount_entry = iterator->elem;
|
||||||
|
fprintf(file, "%s", mount_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
rewind(file);
|
||||||
|
|
||||||
|
ret = mount_file_entries(file);
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int setup_hw_addr(char *hwaddr, const char *ifname)
|
static int setup_hw_addr(char *hwaddr, const char *ifname)
|
||||||
{
|
{
|
||||||
struct sockaddr sockaddr;
|
struct sockaddr sockaddr;
|
||||||
@ -787,6 +822,7 @@ int lxc_conf_init(struct lxc_conf *conf)
|
|||||||
conf->console[0] = '\0';
|
conf->console[0] = '\0';
|
||||||
lxc_list_init(&conf->cgroup);
|
lxc_list_init(&conf->cgroup);
|
||||||
lxc_list_init(&conf->network);
|
lxc_list_init(&conf->network);
|
||||||
|
lxc_list_init(&conf->mount_list);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1040,6 +1076,11 @@ int lxc_setup(const char *name, struct lxc_conf *lxc_conf)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (setup_mount_entries(&lxc_conf->mount_list)) {
|
||||||
|
ERROR("failed to setup the mount entries for '%s'", name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (setup_console(lxc_conf->rootfs, lxc_conf->console)) {
|
if (setup_console(lxc_conf->rootfs, lxc_conf->console)) {
|
||||||
ERROR("failed to setup the console for '%s'", name);
|
ERROR("failed to setup the console for '%s'", name);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -136,6 +136,7 @@ struct lxc_conf {
|
|||||||
struct utsname *utsname;
|
struct utsname *utsname;
|
||||||
struct lxc_list cgroup;
|
struct lxc_list cgroup;
|
||||||
struct lxc_list network;
|
struct lxc_list network;
|
||||||
|
struct lxc_list mount_list;
|
||||||
struct lxc_tty_info tty_info;
|
struct lxc_tty_info tty_info;
|
||||||
char console[MAXPATHLEN];
|
char console[MAXPATHLEN];
|
||||||
};
|
};
|
||||||
|
@ -441,7 +441,7 @@ static int config_cgroup(const char *key, char *value, struct lxc_conf *lxc_conf
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf)
|
static int config_fstab(const char *key, char *value, struct lxc_conf *lxc_conf)
|
||||||
{
|
{
|
||||||
if (strlen(value) >= MAXPATHLEN) {
|
if (strlen(value) >= MAXPATHLEN) {
|
||||||
ERROR("%s path is too long", value);
|
ERROR("%s path is too long", value);
|
||||||
@ -457,6 +457,40 @@ static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf)
|
||||||
|
{
|
||||||
|
char *fstab_token = "lxc.mount";
|
||||||
|
char *token = "lxc.mount.entry";
|
||||||
|
char *subkey;
|
||||||
|
char *mntelem;
|
||||||
|
struct lxc_list *mntlist;
|
||||||
|
|
||||||
|
subkey = strstr(key, token);
|
||||||
|
|
||||||
|
if (!subkey) {
|
||||||
|
subkey = strstr(key, fstab_token);
|
||||||
|
|
||||||
|
if (!subkey)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return config_fstab(key, value, lxc_conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strlen(subkey))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
mntlist = malloc(sizeof(*mntlist));
|
||||||
|
if (!mntlist)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
mntelem = strdup(value);
|
||||||
|
mntlist->elem = mntelem;
|
||||||
|
|
||||||
|
lxc_list_add_tail(&lxc_conf->mount_list, mntlist);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int config_rootfs(const char *key, char *value, struct lxc_conf *lxc_conf)
|
static int config_rootfs(const char *key, char *value, struct lxc_conf *lxc_conf)
|
||||||
{
|
{
|
||||||
if (strlen(value) >= MAXPATHLEN) {
|
if (strlen(value) >= MAXPATHLEN) {
|
||||||
|
Loading…
Reference in New Issue
Block a user