summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-04-05 15:39:43 +0200
committerLennart Poettering <lennart@poettering.net>2018-05-24 17:01:57 +0200
commit5ef46e5f6598d74acbfe963d4feb8dca4e9486b4 (patch)
tree683837dcfba3b8109cb01b9d3c120e1060ba1389 /src
parentconf-files: beef up conf-files.[ch] a bit (diff)
downloadsystemd-5ef46e5f6598d74acbfe963d4feb8dca4e9486b4.tar.xz
systemd-5ef46e5f6598d74acbfe963d4feb8dca4e9486b4.zip
machine-image: introduce two different classes of images
This distuingishes two different classes of images, one for the purpose of npsawn-like containers, i.e. "machines", and one for portable services. This distinction is mostly about search paths. We look for machine images in /var/lib/machines and for portable images in /var/lib/portables.
Diffstat (limited to 'src')
-rw-r--r--src/import/export.c4
-rw-r--r--src/import/import.c4
-rw-r--r--src/import/pull.c4
-rw-r--r--src/machine/image-dbus.c4
-rw-r--r--src/machine/machined-dbus.c24
-rw-r--r--src/nspawn/nspawn.c2
-rw-r--r--src/shared/machine-image.c35
-rw-r--r--src/shared/machine-image.h11
8 files changed, 52 insertions, 36 deletions
diff --git a/src/import/export.c b/src/import/export.c
index 5464b85840..b8bae74d1a 100644
--- a/src/import/export.c
+++ b/src/import/export.c
@@ -69,7 +69,7 @@ static int export_tar(int argc, char *argv[], void *userdata) {
int r, fd;
if (machine_name_is_valid(argv[1])) {
- r = image_find(argv[1], &image);
+ r = image_find(IMAGE_MACHINE, argv[1], &image);
if (r < 0)
return log_error_errno(r, "Failed to look for machine %s: %m", argv[1]);
if (r == 0) {
@@ -148,7 +148,7 @@ static int export_raw(int argc, char *argv[], void *userdata) {
int r, fd;
if (machine_name_is_valid(argv[1])) {
- r = image_find(argv[1], &image);
+ r = image_find(IMAGE_MACHINE, argv[1], &image);
if (r < 0)
return log_error_errno(r, "Failed to look for machine %s: %m", argv[1]);
if (r == 0) {
diff --git a/src/import/import.c b/src/import/import.c
index 5f459b0b3d..04f404f832 100644
--- a/src/import/import.c
+++ b/src/import/import.c
@@ -75,7 +75,7 @@ static int import_tar(int argc, char *argv[], void *userdata) {
}
if (!arg_force) {
- r = image_find(local, NULL);
+ r = image_find(IMAGE_MACHINE, local, NULL);
if (r < 0)
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
else if (r > 0) {
@@ -170,7 +170,7 @@ static int import_raw(int argc, char *argv[], void *userdata) {
}
if (!arg_force) {
- r = image_find(local, NULL);
+ r = image_find(IMAGE_MACHINE, local, NULL);
if (r < 0)
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
else if (r > 0) {
diff --git a/src/import/pull.c b/src/import/pull.c
index d2a4d94f2b..8a7eccdeda 100644
--- a/src/import/pull.c
+++ b/src/import/pull.c
@@ -83,7 +83,7 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
}
if (!arg_force) {
- r = image_find(local, NULL);
+ r = image_find(IMAGE_MACHINE, local, NULL);
if (r < 0)
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
else if (r > 0) {
@@ -169,7 +169,7 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
}
if (!arg_force) {
- r = image_find(local, NULL);
+ r = image_find(IMAGE_MACHINE, local, NULL);
if (r < 0)
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
else if (r > 0) {
diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c
index 0ee2247167..ae5aa30a90 100644
--- a/src/machine/image-dbus.c
+++ b/src/machine/image-dbus.c
@@ -435,7 +435,7 @@ int image_object_find(sd_bus *bus, const char *path, const char *interface, void
if (r < 0)
return r;
- r = image_find(e, &image);
+ r = image_find(IMAGE_MACHINE, e, &image);
if (r <= 0)
return r;
@@ -478,7 +478,7 @@ int image_node_enumerator(sd_bus *bus, const char *path, void *userdata, char **
if (!images)
return -ENOMEM;
- r = image_discover(images);
+ r = image_discover(IMAGE_MACHINE, images);
if (r < 0)
return r;
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 2ac4689ba1..5cf0aa8838 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -145,7 +145,7 @@ static int method_get_image(sd_bus_message *message, void *userdata, sd_bus_erro
if (r < 0)
return r;
- r = image_find(name, NULL);
+ r = image_find(IMAGE_MACHINE, name, NULL);
if (r == 0)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
if (r < 0)
@@ -545,7 +545,7 @@ static int method_list_images(sd_bus_message *message, void *userdata, sd_bus_er
if (!images)
return -ENOMEM;
- r = image_discover(images);
+ r = image_discover(IMAGE_MACHINE, images);
if (r < 0)
return r;
@@ -738,7 +738,7 @@ static int method_remove_image(sd_bus_message *message, void *userdata, sd_bus_e
if (!image_name_is_valid(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
- r = image_find(name, &i);
+ r = image_find(IMAGE_MACHINE, name, &i);
if (r < 0)
return r;
if (r == 0)
@@ -762,7 +762,7 @@ static int method_rename_image(sd_bus_message *message, void *userdata, sd_bus_e
if (!image_name_is_valid(old_name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", old_name);
- r = image_find(old_name, &i);
+ r = image_find(IMAGE_MACHINE, old_name, &i);
if (r < 0)
return r;
if (r == 0)
@@ -786,7 +786,7 @@ static int method_clone_image(sd_bus_message *message, void *userdata, sd_bus_er
if (!image_name_is_valid(old_name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", old_name);
- r = image_find(old_name, &i);
+ r = image_find(IMAGE_MACHINE, old_name, &i);
if (r < 0)
return r;
if (r == 0)
@@ -810,7 +810,7 @@ static int method_mark_image_read_only(sd_bus_message *message, void *userdata,
if (!image_name_is_valid(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
- r = image_find(name, &i);
+ r = image_find(IMAGE_MACHINE, name, &i);
if (r < 0)
return r;
if (r == 0)
@@ -834,7 +834,7 @@ static int method_get_image_hostname(sd_bus_message *message, void *userdata, sd
if (!image_name_is_valid(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
- r = image_find(name, &i);
+ r = image_find(IMAGE_MACHINE, name, &i);
if (r < 0)
return r;
if (r == 0)
@@ -858,7 +858,7 @@ static int method_get_image_machine_id(sd_bus_message *message, void *userdata,
if (!image_name_is_valid(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
- r = image_find(name, &i);
+ r = image_find(IMAGE_MACHINE, name, &i);
if (r < 0)
return r;
if (r == 0)
@@ -882,7 +882,7 @@ static int method_get_image_machine_info(sd_bus_message *message, void *userdata
if (!image_name_is_valid(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
- r = image_find(name, &i);
+ r = image_find(IMAGE_MACHINE, name, &i);
if (r < 0)
return r;
if (r == 0)
@@ -906,7 +906,7 @@ static int method_get_image_os_release(sd_bus_message *message, void *userdata,
if (!image_name_is_valid(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
- r = image_find(name, &i);
+ r = image_find(IMAGE_MACHINE, name, &i);
if (r < 0)
return r;
if (r == 0)
@@ -1070,7 +1070,7 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err
goto child_fail;
}
- r = image_discover(images);
+ r = image_discover(IMAGE_MACHINE, images);
if (r < 0)
goto child_fail;
@@ -1211,7 +1211,7 @@ static int method_set_image_limit(sd_bus_message *message, void *userdata, sd_bu
if (!image_name_is_valid(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
- r = image_find(name, &i);
+ r = image_find(IMAGE_MACHINE, name, &i);
if (r < 0)
return r;
if (r == 0)
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 4c157cf654..9d89af2d24 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -2399,7 +2399,7 @@ static int determine_names(void) {
if (arg_machine) {
_cleanup_(image_unrefp) Image *i = NULL;
- r = image_find(arg_machine, &i);
+ r = image_find(IMAGE_MACHINE, arg_machine, &i);
if (r < 0)
return log_error_errno(r, "Failed to find image for machine '%s': %m", arg_machine);
if (r == 0) {
diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c
index 44cb371da6..40fbccd596 100644
--- a/src/shared/machine-image.c
+++ b/src/shared/machine-image.c
@@ -46,11 +46,16 @@
#include "util.h"
#include "xattr-util.h"
-static const char image_search_path[] =
- "/var/lib/machines\0"
- "/var/lib/container\0" /* legacy */
- "/usr/local/lib/machines\0"
- "/usr/lib/machines\0";
+static const char* const image_search_path[_IMAGE_CLASS_MAX] = {
+ [IMAGE_MACHINE] = "/var/lib/machines\0"
+ "/var/lib/container\0" /* legacy */
+ "/usr/local/lib/machines\0"
+ "/usr/lib/machines\0",
+
+ [IMAGE_PORTABLE] = "/var/lib/portables\0"
+ "/usr/local/lib/portables\0"
+ "/usr/lib/portables\0",
+};
Image *image_unref(Image *i) {
if (!i)
@@ -336,17 +341,19 @@ static int image_make(
return 0;
}
-int image_find(const char *name, Image **ret) {
+int image_find(ImageClass class, const char *name, Image **ret) {
const char *path;
int r;
+ assert(class >= 0);
+ assert(class < _IMAGE_CLASS_MAX);
assert(name);
/* There are no images with invalid names */
if (!image_name_is_valid(name))
return 0;
- NULSTR_FOREACH(path, image_search_path) {
+ NULSTR_FOREACH(path, image_search_path[class]) {
_cleanup_closedir_ DIR *d = NULL;
d = opendir(path);
@@ -375,19 +382,21 @@ int image_find(const char *name, Image **ret) {
return 1;
}
- if (streq(name, ".host"))
+ if (class == IMAGE_MACHINE && streq(name, ".host"))
return image_make(".host", AT_FDCWD, NULL, "/", ret);
return 0;
};
-int image_discover(Hashmap *h) {
+int image_discover(ImageClass class, Hashmap *h) {
const char *path;
int r;
+ assert(class >= 0);
+ assert(class < _IMAGE_CLASS_MAX);
assert(h);
- NULSTR_FOREACH(path, image_search_path) {
+ NULSTR_FOREACH(path, image_search_path[class]) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
@@ -422,7 +431,7 @@ int image_discover(Hashmap *h) {
}
}
- if (!hashmap_contains(h, ".host")) {
+ if (class == IMAGE_MACHINE && !hashmap_contains(h, ".host")) {
_cleanup_(image_unrefp) Image *image = NULL;
r = image_make(".host", AT_FDCWD, NULL, "/", &image);
@@ -567,7 +576,7 @@ int image_rename(Image *i, const char *new_name) {
if (r < 0)
return r;
- r = image_find(new_name, NULL);
+ r = image_find(IMAGE_MACHINE, new_name, NULL);
if (r < 0)
return r;
if (r > 0)
@@ -680,7 +689,7 @@ int image_clone(Image *i, const char *new_name, bool read_only) {
if (r < 0)
return r;
- r = image_find(new_name, NULL);
+ r = image_find(IMAGE_MACHINE, new_name, NULL);
if (r < 0)
return r;
if (r > 0)
diff --git a/src/shared/machine-image.h b/src/shared/machine-image.h
index 51cfb412c1..dafea0c903 100644
--- a/src/shared/machine-image.h
+++ b/src/shared/machine-image.h
@@ -17,6 +17,13 @@
#include "string-util.h"
#include "time-util.h"
+typedef enum ImageClass {
+ IMAGE_MACHINE,
+ IMAGE_PORTABLE,
+ _IMAGE_CLASS_MAX,
+ _IMAGE_CLASS_INVALID = -1
+} ImageClass;
+
typedef enum ImageType {
IMAGE_DIRECTORY,
IMAGE_SUBVOLUME,
@@ -58,8 +65,8 @@ static inline Hashmap* image_hashmap_free(Hashmap *map) {
DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free);
-int image_find(const char *name, Image **ret);
-int image_discover(Hashmap *map);
+int image_find(ImageClass class, const char *name, Image **ret);
+int image_discover(ImageClass class, Hashmap *map);
int image_remove(Image *i);
int image_rename(Image *i, const char *new_name);