mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
machine-image: introduce image_hash_ops and use it
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user