]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machine-image: introduce image_hash_ops and use it
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Nov 2018 13:54:44 +0000 (22:54 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 2 Dec 2018 11:18:54 +0000 (12:18 +0100)
src/machine/image-dbus.c
src/machine/machined-dbus.c
src/machine/machined.c
src/portable/portabled-bus.c
src/portable/portabled-image-bus.c
src/portable/portabled-image.c
src/portable/portabled.c
src/shared/machine-image.c
src/shared/machine-image.h

index 89df274544cbe939def4e7c427442d975cd02741..a311ed9077d537ca4ddb590569bda165d34d6a07 100644 (file)
@@ -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;
 
index 453ca30b64a7261998d1ab068634bae5ef8df89e..ef1958d8b0bc7fa257b30de26e66157524af56b8 100644 (file)
@@ -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;
index 22eb030dee6afb40fd69a9392fb5413fd7d29038..6742722d0ddec78daa13842319c16a7aedff1e97 100644 (file)
@@ -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);
 
index 70fc750fe3e6b2ad8048dd00c2d994a1f9f368a7..ec93838538139657618df2faa0c8963f0f21c4ab 100644 (file)
@@ -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;
 
index 0e1f7c5e87d0a73227e6fb51b324ff3c986a0ae8..ec39205dc429124351e290e895caa82e35775fae 100644 (file)
@@ -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;
 
index a6b3f52e99a269266b48e33b6fac153c65590aac..d95845b32a0f6354547525cc0e200020ea810ac4 100644 (file)
@@ -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;
 
index cfaf2a59e3ece38f56a012d775f15a65f0a45d51..63fc34046913c5b9d7a12189c0e75cc4d15eb715 100644 (file)
@@ -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);
 
index d5f6ab8529a917e6d6680774d6222286fffd22f5..28a05976be8680831b616e857916aeed8fdcd3de 100644 (file)
@@ -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;
index de06147e7bf3e2b56499995dc29db3bee6af5666..9fd45899c80d3a5e160ca4a2a4ee04481ba3900b 100644 (file)
@@ -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;