summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-28 22:54:44 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-12-02 12:18:54 +0100
commitb07ec5a173f285c35661150764562fb78bb6fadd (patch)
tree28fe94c8ff17b893ea5ddd7b0addb4e9b82ae471
parent87938c3bea13fe1a237303fd15c69a0249a96c18 (diff)
downloadsystemd-b07ec5a173f285c35661150764562fb78bb6fadd.tar.gz
systemd-b07ec5a173f285c35661150764562fb78bb6fadd.tar.bz2
systemd-b07ec5a173f285c35661150764562fb78bb6fadd.zip
machine-image: introduce image_hash_ops and use it
-rw-r--r--src/machine/image-dbus.c8
-rw-r--r--src/machine/machined-dbus.c8
-rw-r--r--src/machine/machined.c3
-rw-r--r--src/portable/portabled-bus.c4
-rw-r--r--src/portable/portabled-image-bus.c4
-rw-r--r--src/portable/portabled-image.c4
-rw-r--r--src/portable/portabled.c2
-rw-r--r--src/shared/machine-image.c2
-rw-r--r--src/shared/machine-image.h7
9 files changed, 20 insertions, 22 deletions
diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c
index 89df274544..a311ed9077 100644
--- a/src/machine/image-dbus.c
+++ b/src/machine/image-dbus.c
@@ -382,7 +382,7 @@ static int image_flush_cache(sd_event_source *s, void *userdata) {
assert(s);
assert(m);
- hashmap_clear_with_destructor(m->image_cache, image_unref);
+ hashmap_clear(m->image_cache);
return 0;
}
@@ -412,7 +412,7 @@ int image_object_find(sd_bus *bus, const char *path, const char *interface, void
return 1;
}
- r = hashmap_ensure_allocated(&m->image_cache, &string_hash_ops);
+ r = hashmap_ensure_allocated(&m->image_cache, &image_hash_ops);
if (r < 0)
return r;
@@ -461,7 +461,7 @@ char *image_bus_path(const char *name) {
}
int image_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
- _cleanup_(image_hashmap_freep) Hashmap *images = NULL;
+ _cleanup_hashmap_free_ Hashmap *images = NULL;
_cleanup_strv_free_ char **l = NULL;
Image *image;
Iterator i;
@@ -471,7 +471,7 @@ int image_node_enumerator(sd_bus *bus, const char *path, void *userdata, char **
assert(path);
assert(nodes);
- images = hashmap_new(&string_hash_ops);
+ images = hashmap_new(&image_hash_ops);
if (!images)
return -ENOMEM;
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 453ca30b64..ef1958d8b0 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -463,7 +463,7 @@ static int method_get_machine_os_release(sd_bus_message *message, void *userdata
static int method_list_images(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- _cleanup_(image_hashmap_freep) Hashmap *images = NULL;
+ _cleanup_hashmap_free_ Hashmap *images = NULL;
Manager *m = userdata;
Image *image;
Iterator i;
@@ -472,7 +472,7 @@ static int method_list_images(sd_bus_message *message, void *userdata, sd_bus_er
assert(message);
assert(m);
- images = hashmap_new(&string_hash_ops);
+ images = hashmap_new(&image_hash_ops);
if (!images)
return -ENOMEM;
@@ -740,7 +740,7 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to fork(): %m");
if (r == 0) {
- _cleanup_(image_hashmap_freep) Hashmap *images = NULL;
+ _cleanup_hashmap_free_ Hashmap *images = NULL;
bool success = true;
Image *image;
Iterator i;
@@ -748,7 +748,7 @@ static int method_clean_pool(sd_bus_message *message, void *userdata, sd_bus_err
errno_pipe_fd[0] = safe_close(errno_pipe_fd[0]);
- images = hashmap_new(&string_hash_ops);
+ images = hashmap_new(&image_hash_ops);
if (!images) {
r = -ENOMEM;
goto child_fail;
diff --git a/src/machine/machined.c b/src/machine/machined.c
index 22eb030dee..6742722d0d 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -77,8 +77,7 @@ static Manager* manager_unref(Manager *m) {
hashmap_free(m->machines);
hashmap_free(m->machine_units);
hashmap_free(m->machine_leaders);
-
- hashmap_free_with_destructor(m->image_cache, image_unref);
+ hashmap_free(m->image_cache);
sd_event_source_unref(m->image_cache_defer_event);
diff --git a/src/portable/portabled-bus.c b/src/portable/portabled-bus.c
index 70fc750fe3..ec93838538 100644
--- a/src/portable/portabled-bus.c
+++ b/src/portable/portabled-bus.c
@@ -131,7 +131,7 @@ static int method_get_image(sd_bus_message *message, void *userdata, sd_bus_erro
static int method_list_images(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- _cleanup_(image_hashmap_freep) Hashmap *images = NULL;
+ _cleanup_hashmap_free_ Hashmap *images = NULL;
Manager *m = userdata;
Image *image;
Iterator i;
@@ -140,7 +140,7 @@ static int method_list_images(sd_bus_message *message, void *userdata, sd_bus_er
assert(message);
assert(m);
- images = hashmap_new(&string_hash_ops);
+ images = hashmap_new(&image_hash_ops);
if (!images)
return -ENOMEM;
diff --git a/src/portable/portabled-image-bus.c b/src/portable/portabled-image-bus.c
index 0e1f7c5e87..ec39205dc4 100644
--- a/src/portable/portabled-image-bus.c
+++ b/src/portable/portabled-image-bus.c
@@ -693,7 +693,7 @@ not_found:
}
int bus_image_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
- _cleanup_(image_hashmap_freep) Hashmap *images = NULL;
+ _cleanup_hashmap_free_ Hashmap *images = NULL;
_cleanup_strv_free_ char **l = NULL;
size_t n_allocated = 0, n = 0;
Manager *m = userdata;
@@ -705,7 +705,7 @@ int bus_image_node_enumerator(sd_bus *bus, const char *path, void *userdata, cha
assert(path);
assert(nodes);
- images = hashmap_new(&string_hash_ops);
+ images = hashmap_new(&image_hash_ops);
if (!images)
return -ENOMEM;
diff --git a/src/portable/portabled-image.c b/src/portable/portabled-image.c
index a6b3f52e99..d95845b32a 100644
--- a/src/portable/portabled-image.c
+++ b/src/portable/portabled-image.c
@@ -16,7 +16,7 @@ static int image_cache_flush(sd_event_source *s, void *userdata) {
assert(s);
assert(m);
- hashmap_clear_with_destructor(m->image_cache, image_unref);
+ hashmap_clear(m->image_cache);
return 0;
}
@@ -25,7 +25,7 @@ static int manager_image_cache_initialize(Manager *m) {
assert(m);
- r = hashmap_ensure_allocated(&m->image_cache, &string_hash_ops);
+ r = hashmap_ensure_allocated(&m->image_cache, &image_hash_ops);
if (r < 0)
return r;
diff --git a/src/portable/portabled.c b/src/portable/portabled.c
index cfaf2a59e3..63fc340469 100644
--- a/src/portable/portabled.c
+++ b/src/portable/portabled.c
@@ -47,7 +47,7 @@ static int manager_new(Manager **ret) {
static Manager* manager_unref(Manager *m) {
assert(m);
- hashmap_free_with_destructor(m->image_cache, image_unref);
+ hashmap_free(m->image_cache);
sd_event_source_unref(m->image_cache_defer_event);
diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c
index d5f6ab8529..28a05976be 100644
--- a/src/shared/machine-image.c
+++ b/src/shared/machine-image.c
@@ -70,6 +70,8 @@ static Image *image_free(Image *i) {
}
DEFINE_TRIVIAL_REF_UNREF_FUNC(Image, image, image_free);
+DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(image_hash_ops, char, string_hash_func, string_compare_func,
+ Image, image_unref);
static char **image_settings_path(Image *image) {
_cleanup_strv_free_ char **l = NULL;
diff --git a/src/shared/machine-image.h b/src/shared/machine-image.h
index de06147e7b..9fd45899c8 100644
--- a/src/shared/machine-image.h
+++ b/src/shared/machine-image.h
@@ -59,12 +59,7 @@ typedef struct Image {
Image *image_unref(Image *i);
Image *image_ref(Image *i);
-static inline Hashmap* image_hashmap_free(Hashmap *map) {
- return hashmap_free_with_destructor(map, image_unref);
-}
-
DEFINE_TRIVIAL_CLEANUP_FUNC(Image*, image_unref);
-DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, image_hashmap_free);
int image_find(ImageClass class, const char *name, Image **ret);
int image_from_path(const char *path, Image **ret);
@@ -113,3 +108,5 @@ static inline bool IMAGE_IS_HOST(const struct Image *i) {
return false;
}
+
+extern const struct hash_ops image_hash_ops;