Unverified Commit 7a41e857 by Liza Tretyakova Committed by Christian Brauner

conf, confile, lxccontainer, start: nonfunctional changes

parent 1f5a90f9
......@@ -656,12 +656,12 @@ static int add_shmount_to_list(struct lxc_conf *conf) {
int ret = -1, offset = 1;
/* +1 for the separating whitespace */
len_mount = strlen(conf->lxc_shmount.path_host) + 1
+ strlen(conf->lxc_shmount.path_cont) - offset
len_mount = strlen(conf->shmount.path_host) + 1
+ strlen(conf->shmount.path_cont) - offset
+ sizeof(" none bind,create=dir 0 0") - 1;
ret = snprintf(new_mount, len_mount + 1, "%s %s none bind,create=dir 0 0",
conf->lxc_shmount.path_host, conf->lxc_shmount.path_cont + offset);
conf->shmount.path_host, conf->shmount.path_cont + offset);
if (ret < 0 || (size_t)ret >= len_mount + 1)
return -1;
......@@ -2747,8 +2747,9 @@ struct lxc_conf *lxc_conf_init(void)
new->lsm_aa_profile = NULL;
new->lsm_se_context = NULL;
new->tmp_umount_proc = false;
new->lxc_shmount.path_host = NULL;
new->lxc_shmount.path_cont = NULL;
new->tmp_umount_proc = 0;
new->shmount.path_host = NULL;
new->shmount.path_cont = NULL;
/* if running in a new user namespace, init and COMMAND
* default to running as UID/GID 0 when using lxc-execute */
......@@ -4076,8 +4077,8 @@ void lxc_conf_free(struct lxc_conf *conf)
lxc_clear_procs(conf, "lxc.proc");
free(conf->cgroup_meta.dir);
free(conf->cgroup_meta.controllers);
free(conf->lxc_shmount.path_host);
free(conf->lxc_shmount.path_cont);
free(conf->shmount.path_host);
free(conf->shmount.path_cont);
free(conf);
}
......
......@@ -371,12 +371,12 @@ struct lxc_conf {
/* procs */
struct lxc_list procs;
struct lxc_shmount {
struct shmount {
/* Absolute path to the shared mount point on the host */
char *path_host;
/* Absolute path (in the container) to the shared mount point */
char *path_cont;
} lxc_shmount;
} shmount;
};
extern int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
......
......@@ -1704,12 +1704,12 @@ static int set_config_mount_auto(const char *key, const char *value,
lxc_conf->auto_mounts &= ~allowed_auto_mounts[i].mask;
lxc_conf->auto_mounts |= allowed_auto_mounts[i].flag;
if (is_shmounts) {
lxc_conf->lxc_shmount.path_host = strdup(token + (sizeof("shmounts:") - 1));
if (strcmp(lxc_conf->lxc_shmount.path_host, "") == 0) {
lxc_conf->shmount.path_host = strdup(token + (sizeof("shmounts:") - 1));
if (strcmp(lxc_conf->shmount.path_host, "") == 0) {
ERROR("Invalid shmounts path: empty");
break;
}
lxc_conf->lxc_shmount.path_cont = strdup("/dev/.lxc-mounts");
lxc_conf->shmount.path_cont = strdup("/dev/.lxc-mounts");
}
}
......
......@@ -4966,13 +4966,13 @@ static int do_lxcapi_mount(struct lxc_container *c, const char *source,
return -EINVAL;
}
if (!c->lxc_conf->lxc_shmount.path_host) {
if (!c->lxc_conf->shmount.path_host) {
ERROR("Host path to shared mountpoint must be specified in the config\n");
return -EINVAL;
}
len = strlen(c->lxc_conf->lxc_shmount.path_host) + sizeof("/.lxcmount_XXXXXX") - 1;
len = strlen(c->lxc_conf->shmount.path_host) + sizeof("/.lxcmount_XXXXXX") - 1;
ret = snprintf(template, len + 1, "%s/.lxcmount_XXXXXX", c->lxc_conf->lxc_shmount.path_host);
ret = snprintf(template, len + 1, "%s/.lxcmount_XXXXXX", c->lxc_conf->shmount.path_host);
if (ret < 0 || (size_t)ret >= len + 1) {
SYSERROR("Error writing shmounts tempdir name");
goto out;
......@@ -5048,8 +5048,8 @@ static int do_lxcapi_mount(struct lxc_container *c, const char *source,
if (!suff)
_exit(EXIT_FAILURE);
len = strlen(c->lxc_conf->lxc_shmount.path_cont) + sizeof("/.lxcmount_XXXXXX") - 1;
ret = snprintf(path, len + 1, "%s%s", c->lxc_conf->lxc_shmount.path_cont, suff);
len = strlen(c->lxc_conf->shmount.path_cont) + sizeof("/.lxcmount_XXXXXX") - 1;
ret = snprintf(path, len + 1, "%s%s", c->lxc_conf->shmount.path_cont, suff);
if (ret < 0 || (size_t)ret >= len + 1) {
SYSERROR("Error writing container mountpoint name");
_exit(EXIT_FAILURE);
......@@ -5087,7 +5087,7 @@ WRAP_API_6(int, lxcapi_mount, const char *, const char *, const char *,
unsigned long, const void *, struct lxc_mount *)
static int do_lxcapi_umount(struct lxc_container *c, const char *target,
unsigned long mountflags, struct lxc_mount *mnt)
unsigned long flags, struct lxc_mount *mnt)
{
pid_t pid, init_pid;
int ret = -1;
......@@ -5125,7 +5125,7 @@ static int do_lxcapi_umount(struct lxc_container *c, const char *target,
}
/* Do the unmount */
ret = umount2(target, mountflags);
ret = umount2(target, flags);
if (ret < 0) {
SYSERROR("Failed to umount \"%s\"", target);
_exit(EXIT_FAILURE);
......
......@@ -1536,14 +1536,14 @@ static int lxc_setup_shmount(struct lxc_conf *conf) {
/* Construct the shmount path under the container root */
/* +1 for slash */
len_cont = strlen(conf->rootfs.mount) + 1 + strlen(conf->lxc_shmount.path_cont);
len_cont = strlen(conf->rootfs.mount) + 1 + strlen(conf->shmount.path_cont);
/* +1 for the terminating '\0' */
full_cont_path = malloc(len_cont + 1);
if(!full_cont_path) {
SYSERROR("Not enough memory");
return -ENOMEM;
}
ret = snprintf(full_cont_path, len_cont + 1, "%s/%s", conf->rootfs.mount, conf->lxc_shmount.path_cont);
ret = snprintf(full_cont_path, len_cont + 1, "%s/%s", conf->rootfs.mount, conf->shmount.path_cont);
if (ret < 0 || ret >= len_cont + 1) {
SYSERROR("Failed to create filename");
free(full_cont_path);
......@@ -1551,16 +1551,16 @@ static int lxc_setup_shmount(struct lxc_conf *conf) {
}
/* Check if shmount point is already set up */
if (is_shared_mountpoint(conf->lxc_shmount.path_host)) {
INFO("Path \"%s\" is already MS_SHARED. Reusing", conf->lxc_shmount.path_host);
if (is_shared_mountpoint(conf->shmount.path_host)) {
INFO("Path \"%s\" is already MS_SHARED. Reusing", conf->shmount.path_host);
free(full_cont_path);
return 0;
}
/* Create host and cont mount paths */
ret = mkdir_p(conf->lxc_shmount.path_host, 0711);
ret = mkdir_p(conf->shmount.path_host, 0711);
if (ret < 0 && errno != EEXIST) {
SYSERROR("Failed to create directory \"%s\"", conf->lxc_shmount.path_host);
SYSERROR("Failed to create directory \"%s\"", conf->shmount.path_host);
free(full_cont_path);
return ret;
}
......@@ -1573,22 +1573,22 @@ static int lxc_setup_shmount(struct lxc_conf *conf) {
}
/* Prepare host mountpoint */
ret = mount("tmpfs", conf->lxc_shmount.path_host, "tmpfs",
ret = mount("tmpfs", conf->shmount.path_host, "tmpfs",
0, "size=100k,mode=0711");
if (ret < 0) {
SYSERROR("Failed to mount \"%s\"", conf->lxc_shmount.path_host);
SYSERROR("Failed to mount \"%s\"", conf->shmount.path_host);
free(full_cont_path);
return ret;
}
ret = mount(conf->lxc_shmount.path_host, conf->lxc_shmount.path_host, "none",
ret = mount(conf->shmount.path_host, conf->shmount.path_host, "none",
MS_REC | MS_SHARED, "");
if (ret < 0) {
SYSERROR("Failed to make shared \"%s\"", conf->lxc_shmount.path_host);
SYSERROR("Failed to make shared \"%s\"", conf->shmount.path_host);
free(full_cont_path);
return ret;
}
INFO("Made shared mount point \"%s\"", conf->lxc_shmount.path_host);
INFO("Made shared mount point \"%s\"", conf->shmount.path_host);
free(full_cont_path);
return 0;
}
......@@ -1670,12 +1670,12 @@ static int lxc_spawn(struct lxc_handler *handler)
}
}
if (conf->lxc_shmount.path_host && !conf->lxc_shmount.path_cont) {
if (conf->shmount.path_host && !conf->shmount.path_cont) {
ERROR("Missing the container side path to the shared mount point");
lxc_sync_fini(handler);
return -1;
}
if (conf->lxc_shmount.path_host) {
if (conf->shmount.path_host) {
ret = lxc_setup_shmount(conf);
if (ret < 0) {
ERROR("Failed to setup shared mount point");
......
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