nspawn: permit prefixing of source paths in --bind= and --overlay= with "+"

If a source path is prefixed with "+" it is taken relative to the container's
root directory instead of the host. This permits easily establishing bind and
overlay mounts based on data from the container rather than the host.

This also reworks custom_mounts_prepare(), and turns it into two functions: one
custom_mount_check_all() that remains in nspawn.c but purely verifies the
validity of the custom mounts configured. And one called
custom_mount_prepare_all() that actually does the preparation step, sorts the
custom mounts, resolves relative paths, and allocates temporary directories as
necessary.
This commit is contained in:
Lennart Poettering
2016-12-01 12:41:18 +01:00
parent e28c7cd066
commit 86c0dd4a71
5 changed files with 148 additions and 82 deletions
+6 -20
View File
@@ -280,14 +280,9 @@ static void help(void) {
, program_invocation_short_name);
}
static int custom_mounts_prepare(void) {
static int custom_mount_check_all(void) {
unsigned i;
int r;
/* Ensure the mounts are applied prefix first. */
qsort_safe(arg_custom_mounts, arg_n_custom_mounts, sizeof(CustomMount), custom_mount_compare);
/* Allocate working directories for the overlay file systems that need it */
for (i = 0; i < arg_n_custom_mounts; i++) {
CustomMount *m = &arg_custom_mounts[i];
@@ -301,19 +296,6 @@ static int custom_mounts_prepare(void) {
return -EINVAL;
}
}
if (m->type != CUSTOM_MOUNT_OVERLAY)
continue;
if (m->work_dir)
continue;
if (m->read_only)
continue;
r = tempfn_random(m->source, NULL, &m->work_dir);
if (r < 0)
return log_error_errno(r, "Failed to generate work directory from %s: %m", m->source);
}
return 0;
@@ -1147,6 +1129,10 @@ static int parse_argv(int argc, char *argv[]) {
else
arg_use_cgns = r;
r = custom_mount_check_all();
if (r < 0)
return r;
return 1;
}
@@ -4284,7 +4270,7 @@ int main(int argc, char *argv[]) {
remove_image = false;
}
r = custom_mounts_prepare();
r = custom_mount_prepare_all(arg_directory, arg_custom_mounts, arg_n_custom_mounts);
if (r < 0)
goto finish;