Commit 0ab45a16 by Stéphane Graber

Merge pull request #617 from alkino/master

A little bit of refactor and doc
parents d4b36def db4aba38
...@@ -770,6 +770,11 @@ proc proc proc nodev,noexec,nosuid 0 0 ...@@ -770,6 +770,11 @@ proc proc proc nodev,noexec,nosuid 0 0
<para> <para>
specify a mount point corresponding to a line in the specify a mount point corresponding to a line in the
fstab format. fstab format.
Moreover lxc add two options to mount.
<option>optional</option> don't fail if mount does not work.
<option>create=dir</option> or <option>create=file</option>
to create dir (or file) when the point will be mounted.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -1804,36 +1804,47 @@ static void cull_mntent_opt(struct mntent *mntent) ...@@ -1804,36 +1804,47 @@ static void cull_mntent_opt(struct mntent *mntent)
} }
} }
static inline int mount_entry_on_systemfs(struct mntent *mntent) static int mount_entry_create_dir_file(const struct mntent *mntent,
const char* path)
{ {
unsigned long mntflags; char *pathdirname = NULL;
char *mntdata;
int ret; int ret;
FILE *pathfile = NULL; FILE *pathfile = NULL;
char* pathdirname = NULL;
bool optional = hasmntopt(mntent, "optional") != NULL;
if (hasmntopt(mntent, "create=dir")) { if (hasmntopt(mntent, "create=dir")) {
if (mkdir_p(mntent->mnt_dir, 0755) < 0) { if (mkdir_p(path, 0755) < 0) {
WARN("Failed to create mount target '%s'", mntent->mnt_dir); WARN("Failed to create mount target '%s'", path);
ret = -1; ret = -1;
} }
} }
if (hasmntopt(mntent, "create=file") && access(mntent->mnt_dir, F_OK)) { if (hasmntopt(mntent, "create=file") && access(path, F_OK)) {
pathdirname = strdup(mntent->mnt_dir); pathdirname = strdup(path);
pathdirname = dirname(pathdirname); pathdirname = dirname(pathdirname);
if (mkdir_p(pathdirname, 0755) < 0) { if (mkdir_p(pathdirname, 0755) < 0) {
WARN("Failed to create target directory"); WARN("Failed to create target directory");
} }
pathfile = fopen(mntent->mnt_dir, "wb"); pathfile = fopen(path, "wb");
if (!pathfile) { if (!pathfile) {
WARN("Failed to create mount target '%s'", mntent->mnt_dir); WARN("Failed to create mount target '%s'", path);
ret = -1; ret = -1;
} }
else else
fclose(pathfile); fclose(pathfile);
} }
free(pathdirname);
return ret;
}
static inline int mount_entry_on_generic(struct mntent *mntent,
const char* path)
{
unsigned long mntflags;
char *mntdata;
int ret;
bool optional = hasmntopt(mntent, "optional") != NULL;
ret = mount_entry_create_dir_file(mntent, path);
cull_mntent_opt(mntent); cull_mntent_opt(mntent);
...@@ -1842,28 +1853,27 @@ static inline int mount_entry_on_systemfs(struct mntent *mntent) ...@@ -1842,28 +1853,27 @@ static inline int mount_entry_on_systemfs(struct mntent *mntent)
return -1; return -1;
} }
ret = mount_entry(mntent->mnt_fsname, mntent->mnt_dir, ret = mount_entry(mntent->mnt_fsname, path, mntent->mnt_type,
mntent->mnt_type, mntflags, mntdata, optional); mntflags, mntdata, optional);
free(pathdirname);
free(mntdata); free(mntdata);
return ret; return ret;
} }
static inline int mount_entry_on_systemfs(struct mntent *mntent)
{
return mount_entry_on_generic(mntent, mntent->mnt_dir);
}
static int mount_entry_on_absolute_rootfs(struct mntent *mntent, static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
const struct lxc_rootfs *rootfs, const struct lxc_rootfs *rootfs,
const char *lxc_name) const char *lxc_name)
{ {
char *aux; char *aux;
char path[MAXPATHLEN]; char path[MAXPATHLEN];
unsigned long mntflags;
char *mntdata;
int r, ret = 0, offset; int r, ret = 0, offset;
const char *lxcpath; const char *lxcpath;
FILE *pathfile = NULL;
char *pathdirname = NULL;
bool optional = hasmntopt(mntent, "optional") != NULL;
lxcpath = lxc_global_config_value("lxc.lxcpath"); lxcpath = lxc_global_config_value("lxc.lxcpath");
if (!lxcpath) { if (!lxcpath) {
...@@ -1887,7 +1897,7 @@ skipvarlib: ...@@ -1887,7 +1897,7 @@ skipvarlib:
aux = strstr(mntent->mnt_dir, rootfs->path); aux = strstr(mntent->mnt_dir, rootfs->path);
if (!aux) { if (!aux) {
WARN("ignoring mount point '%s'", mntent->mnt_dir); WARN("ignoring mount point '%s'", mntent->mnt_dir);
goto out; return ret;
} }
offset = strlen(rootfs->path); offset = strlen(rootfs->path);
...@@ -1897,58 +1907,17 @@ skipabs: ...@@ -1897,58 +1907,17 @@ skipabs:
aux + offset); aux + offset);
if (r < 0 || r >= MAXPATHLEN) { if (r < 0 || r >= MAXPATHLEN) {
WARN("pathnme too long for '%s'", mntent->mnt_dir); WARN("pathnme too long for '%s'", mntent->mnt_dir);
ret = -1;
goto out;
}
if (hasmntopt(mntent, "create=dir")) {
if (mkdir_p(path, 0755) < 0) {
WARN("Failed to create mount target '%s'", path);
ret = -1;
}
}
if (hasmntopt(mntent, "create=file") && access(path, F_OK)) {
pathdirname = strdup(path);
pathdirname = dirname(pathdirname);
if (mkdir_p(pathdirname, 0755) < 0) {
WARN("Failed to create target directory");
}
pathfile = fopen(path, "wb");
if (!pathfile) {
WARN("Failed to create mount target '%s'", path);
ret = -1;
}
else
fclose(pathfile);
}
cull_mntent_opt(mntent);
if (parse_mntopts(mntent->mnt_opts, &mntflags, &mntdata) < 0) {
free(mntdata);
return -1; return -1;
} }
ret = mount_entry(mntent->mnt_fsname, path, mntent->mnt_type, return mount_entry_on_generic(mntent, path);
mntflags, mntdata, optional);
free(mntdata);
out:
free(pathdirname);
return ret;
} }
static int mount_entry_on_relative_rootfs(struct mntent *mntent, static int mount_entry_on_relative_rootfs(struct mntent *mntent,
const char *rootfs) const char *rootfs)
{ {
char path[MAXPATHLEN]; char path[MAXPATHLEN];
unsigned long mntflags;
char *mntdata;
int ret; int ret;
FILE *pathfile = NULL;
char *pathdirname = NULL;
bool optional = hasmntopt(mntent, "optional") != NULL;
/* relative to root mount point */ /* relative to root mount point */
ret = snprintf(path, sizeof(path), "%s/%s", rootfs, mntent->mnt_dir); ret = snprintf(path, sizeof(path), "%s/%s", rootfs, mntent->mnt_dir);
...@@ -1957,41 +1926,7 @@ static int mount_entry_on_relative_rootfs(struct mntent *mntent, ...@@ -1957,41 +1926,7 @@ static int mount_entry_on_relative_rootfs(struct mntent *mntent,
return -1; return -1;
} }
if (hasmntopt(mntent, "create=dir")) { return mount_entry_on_generic(mntent, path);
if (mkdir_p(path, 0755) < 0) {
WARN("Failed to create mount target '%s'", path);
ret = -1;
}
}
if (hasmntopt(mntent, "create=file") && access(path, F_OK)) {
pathdirname = strdup(path);
pathdirname = dirname(pathdirname);
if (mkdir_p(pathdirname, 0755) < 0) {
WARN("Failed to create target directory");
}
pathfile = fopen(path, "wb");
if (!pathfile) {
WARN("Failed to create mount target '%s'", path);
ret = -1;
}
else
fclose(pathfile);
}
cull_mntent_opt(mntent);
if (parse_mntopts(mntent->mnt_opts, &mntflags, &mntdata) < 0) {
free(mntdata);
return -1;
}
ret = mount_entry(mntent->mnt_fsname, path, mntent->mnt_type,
mntflags, mntdata, optional);
free(pathdirname);
free(mntdata);
return ret;
} }
static int mount_file_entries(const struct lxc_rootfs *rootfs, FILE *file, static int mount_file_entries(const struct lxc_rootfs *rootfs, FILE *file,
...@@ -4574,7 +4509,7 @@ struct lxc_list *sort_cgroup_settings(struct lxc_list* cgroup_settings) ...@@ -4574,7 +4509,7 @@ struct lxc_list *sort_cgroup_settings(struct lxc_list* cgroup_settings)
/* Store the memsw_limit location */ /* Store the memsw_limit location */
memsw_limit = item; memsw_limit = item;
} else if (strcmp(cg->subsystem, "memory.limit_in_bytes") == 0 && memsw_limit != NULL) { } else if (strcmp(cg->subsystem, "memory.limit_in_bytes") == 0 && memsw_limit != NULL) {
/* lxc.cgroup.memory.memsw.limit_in_bytes is found before /* lxc.cgroup.memory.memsw.limit_in_bytes is found before
* lxc.cgroup.memory.limit_in_bytes, swap these two items */ * lxc.cgroup.memory.limit_in_bytes, swap these two items */
item->elem = memsw_limit->elem; item->elem = memsw_limit->elem;
memsw_limit->elem = it->elem; memsw_limit->elem = it->elem;
......
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