diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-12-26 19:21:09 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-12-26 19:33:15 +0100 |
commit | 087682d103e08670963686d9b1bc1d35c412a63f (patch) | |
tree | 70a16dd061e6619530ba943253fc4ef386e826a6 /src/import | |
parent | 5fc7f358420883c73dd662769b1670c0694111a0 (diff) |
import: make image root directory configurable, instead of hardcoding /var/lib/container
Diffstat (limited to 'src/import')
-rw-r--r-- | src/import/import-dkr.c | 25 | ||||
-rw-r--r-- | src/import/import-dkr.h | 2 | ||||
-rw-r--r-- | src/import/import-gpt.c | 17 | ||||
-rw-r--r-- | src/import/import-gpt.h | 2 | ||||
-rw-r--r-- | src/import/import.c | 16 |
5 files changed, 45 insertions, 17 deletions
diff --git a/src/import/import-dkr.c b/src/import/import-dkr.c index fbd64122f9..a3f390ca82 100644 --- a/src/import/import-dkr.c +++ b/src/import/import-dkr.c @@ -94,6 +94,7 @@ struct DkrImport { CurlGlue *glue; char *index_url; + char *image_root; Hashmap *names; Hashmap *jobs; @@ -406,8 +407,8 @@ static void dkr_import_name_maybe_finish(DkrImportName *name) { assert(name->id); - p = strappenda("/var/lib/container/", name->local); - q = strappenda("/var/lib/container/.dkr-", name->id); + p = strappenda(name->import->image_root, "/", name->local); + q = strappenda(name->import->image_root, "/.dkr-", name->id); if (name->force_local) { (void) btrfs_subvol_remove(p); @@ -534,7 +535,7 @@ static int dkr_import_name_pull_layer(DkrImportName *name) { return 0; } - path = strjoin("/var/lib/container/.dkr-", layer, NULL); + path = strjoin(name->import->image_root, "/.dkr-", layer, NULL); if (!path) return log_oom(); @@ -575,7 +576,7 @@ static int dkr_import_name_pull_layer(DkrImportName *name) { if (base) { const char *base_path; - base_path = strappend("/var/lib/container/.dkr-", base); + base_path = strappenda(name->import->image_root, "/.dkr-", base); r = btrfs_subvol_snapshot(base_path, temp, false, true); } else r = btrfs_subvol_make(temp); @@ -1021,13 +1022,21 @@ static int dkr_import_name_begin(DkrImportName *name) { return dkr_import_name_add_job(name, DKR_IMPORT_JOB_IMAGES, url, &name->job_images); } -int dkr_import_new(DkrImport **import, sd_event *event, const char *index_url, dkr_import_on_finished on_finished, void *userdata) { +int dkr_import_new( + DkrImport **import, + sd_event *event, + const char *index_url, + const char *image_root, + dkr_import_on_finished on_finished, + void *userdata) { + _cleanup_(dkr_import_unrefp) DkrImport *i = NULL; char *e; int r; assert(import); assert(dkr_url_is_valid(index_url)); + assert(image_root); i = new0(DkrImport, 1); if (!i) @@ -1040,6 +1049,10 @@ int dkr_import_new(DkrImport **import, sd_event *event, const char *index_url, d if (!i->index_url) return -ENOMEM; + i->image_root = strdup(image_root); + if (!i->image_root) + return -ENOMEM; + e = endswith(i->index_url, "/"); if (e) *e = 0; @@ -1084,7 +1097,7 @@ DkrImport* dkr_import_unref(DkrImport *import) { sd_event_unref(import->event); free(import->index_url); - + free(import->image_root); free(import); return NULL; diff --git a/src/import/import-dkr.h b/src/import/import-dkr.h index 8e6a462cc7..5f888765a8 100644 --- a/src/import/import-dkr.h +++ b/src/import/import-dkr.h @@ -26,7 +26,7 @@ typedef struct DkrImport DkrImport; typedef void (*dkr_import_on_finished)(DkrImport *import, int error, void *userdata); -int dkr_import_new(DkrImport **import, sd_event *event, const char *index_url, dkr_import_on_finished on_finished, void *userdata); +int dkr_import_new(DkrImport **import, sd_event *event, const char *index_url, const char *image_root, dkr_import_on_finished on_finished, void *userdata); DkrImport* dkr_import_unref(DkrImport *import); DEFINE_TRIVIAL_CLEANUP_FUNC(DkrImport*, dkr_import_unref); diff --git a/src/import/import-gpt.c b/src/import/import-gpt.c index e1c493bbe3..a85ceee337 100644 --- a/src/import/import-gpt.c +++ b/src/import/import-gpt.c @@ -60,6 +60,7 @@ struct GptImport { sd_event *event; CurlGlue *glue; + char *image_root; Hashmap *files; gpt_import_on_finished on_finished; @@ -129,9 +130,9 @@ static int gpt_import_file_make_final_path(GptImportFile *f) { if (!escaped_etag) return -ENOMEM; - f->final_path = strjoin("/var/lib/container/.gpt-", escaped_url, ".", escaped_etag, ".gpt", NULL); + f->final_path = strjoin(f->import->image_root, "/.gpt-", escaped_url, ".", escaped_etag, ".gpt", NULL); } else - f->final_path = strjoin("/var/lib/container/.gpt-", escaped_url, ".gpt", NULL); + f->final_path = strjoin(f->import->image_root, "/.gpt-", escaped_url, ".gpt", NULL); if (!f->final_path) return -ENOMEM; @@ -169,7 +170,7 @@ static void gpt_import_file_success(GptImportFile *f) { } } - p = strappenda("/var/lib/container/", f->local, ".gpt"); + p = strappenda(f->import->image_root, "/", f->local, ".gpt"); if (f->force_local) (void) rm_rf_dangerous(p, false, true, false); @@ -469,7 +470,7 @@ static int gpt_import_file_find_old_etags(GptImportFile *f) { if (!escaped_url) return -ENOMEM; - d = opendir("/var/lib/container/"); + d = opendir(f->import->image_root); if (!d) { if (errno == ENOENT) return 0; @@ -575,11 +576,12 @@ static int gpt_import_file_begin(GptImportFile *f) { return 0; } -int gpt_import_new(GptImport **import, sd_event *event, gpt_import_on_finished on_finished, void *userdata) { +int gpt_import_new(GptImport **import, sd_event *event, const char *image_root, gpt_import_on_finished on_finished, void *userdata) { _cleanup_(gpt_import_unrefp) GptImport *i = NULL; int r; assert(import); + assert(image_root); i = new0(GptImport, 1); if (!i) @@ -588,6 +590,10 @@ int gpt_import_new(GptImport **import, sd_event *event, gpt_import_on_finished o i->on_finished = on_finished; i->userdata = userdata; + i->image_root = strdup(image_root); + if (!i->image_root) + return -ENOMEM; + if (event) i->event = sd_event_ref(event); else { @@ -622,6 +628,7 @@ GptImport* gpt_import_unref(GptImport *import) { curl_glue_unref(import->glue); sd_event_unref(import->event); + free(import->image_root); free(import); return NULL; diff --git a/src/import/import-gpt.h b/src/import/import-gpt.h index e4c534c41f..e9003db21a 100644 --- a/src/import/import-gpt.h +++ b/src/import/import-gpt.h @@ -26,7 +26,7 @@ typedef struct GptImport GptImport; typedef void (*gpt_import_on_finished)(GptImport *import, int error, void *userdata); -int gpt_import_new(GptImport **import, sd_event *event, gpt_import_on_finished on_finished, void *userdata); +int gpt_import_new(GptImport **import, sd_event *event, const char *image_root, gpt_import_on_finished on_finished, void *userdata); GptImport* gpt_import_unref(GptImport *import); DEFINE_TRIVIAL_CLEANUP_FUNC(GptImport*, gpt_import_unref); diff --git a/src/import/import.c b/src/import/import.c index 79dd203142..c28ff8f8bf 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -29,6 +29,7 @@ #include "import-dkr.h" static bool arg_force = false; +static const char *arg_image_root = "/var/lib/container"; static const char* arg_dkr_index_url = DEFAULT_DKR_INDEX_URL; @@ -87,7 +88,7 @@ static int pull_gpt(int argc, char *argv[], void *userdata) { return -EINVAL; } - p = strappenda("/var/lib/container/", local, ".gpt"); + p = strappenda(arg_image_root, "/", local, ".gpt"); if (laccess(p, F_OK) >= 0) { if (!arg_force) { log_info("Image '%s' already exists.", local); @@ -108,7 +109,7 @@ static int pull_gpt(int argc, char *argv[], void *userdata) { sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); - r = gpt_import_new(&import, event, on_gpt_finished, event); + r = gpt_import_new(&import, event, arg_image_root, on_gpt_finished, event); if (r < 0) return log_error_errno(r, "Failed to allocate importer: %m"); @@ -188,7 +189,7 @@ static int pull_dkr(int argc, char *argv[], void *userdata) { return -EINVAL; } - p = strappenda("/var/lib/container/", local); + p = strappenda(arg_image_root, "/", local); if (laccess(p, F_OK) >= 0) { if (!arg_force) { log_info("Image '%s' already exists.", local); @@ -209,7 +210,7 @@ static int pull_dkr(int argc, char *argv[], void *userdata) { sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); - r = dkr_import_new(&import, event, arg_dkr_index_url, on_dkr_finished, event); + r = dkr_import_new(&import, event, arg_dkr_index_url, arg_image_root, on_dkr_finished, event); if (r < 0) return log_error_errno(r, "Failed to allocate importer: %m"); @@ -233,6 +234,7 @@ static int help(int argc, char *argv[], void *userdata) { " -h --help Show this help\n" " --version Show package version\n" " --force Force creation of image\n" + " --image-root= Image root directory\n" " --dkr-index-url=URL Specify index URL to use for downloads\n\n" "Commands:\n" " pull-dkr REMOTE [NAME] Download a DKR image\n" @@ -248,6 +250,7 @@ static int parse_argv(int argc, char *argv[]) { ARG_VERSION = 0x100, ARG_FORCE, ARG_DKR_INDEX_URL, + ARG_IMAGE_ROOT, }; static const struct option options[] = { @@ -255,6 +258,7 @@ static int parse_argv(int argc, char *argv[]) { { "version", no_argument, NULL, ARG_VERSION }, { "force", no_argument, NULL, ARG_FORCE }, { "dkr-index-url", required_argument, NULL, ARG_DKR_INDEX_URL }, + { "image-root", required_argument, NULL, ARG_IMAGE_ROOT }, {} }; @@ -288,6 +292,10 @@ static int parse_argv(int argc, char *argv[]) { arg_dkr_index_url = optarg; break; + case ARG_IMAGE_ROOT: + arg_image_root = optarg; + break; + case '?': return -EINVAL; |