From 900a19876e34d98b50bd17aa99eb65cbb36d513a Mon Sep 17 00:00:00 2001 From: haozi007 Date: Tue, 14 Jul 2020 15:34:26 +0800 Subject: [PATCH] fix deadlock ensure all lock call in api method Signed-off-by: haozi007 --- .../oci/storage/layer_store/layer_store.c | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c index 5c0ac0f..18cdf2d 100644 --- a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c +++ b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c @@ -1039,8 +1039,7 @@ static int do_delete_layer(const char *id) l = lookup(id); if (l == NULL) { - ERROR("layer not known"); - ret = -1; + WARN("layer %s not exists already, return success", id); goto free_out; } @@ -1086,11 +1085,6 @@ int layer_store_delete(const char *id) return -1; } - if (!layer_store_exists(id)) { - WARN("layer %s not exists already, return success", id); - return 0; - } - if (!layer_store_lock(true)) { return -1; } @@ -1182,10 +1176,6 @@ static int layers_by_digest_map(map_t *m, const char *digest, struct layer_list digest_layer_t *id_list = NULL; size_t i = 0; - if (!layer_store_lock(false)) { - return -1; - } - id_list = (digest_layer_t *)map_search(m, (void *)digest); if (id_list == NULL) { ERROR("Not found digest: %s", digest); @@ -1223,24 +1213,40 @@ static int layers_by_digest_map(map_t *m, const char *digest, struct layer_list ret = 0; free_out: - layer_store_unlock(); return ret; } int layer_store_by_compress_digest(const char *digest, struct layer_list *resp) { + int ret = 0; + if (resp == NULL) { return -1; } - return layers_by_digest_map(g_metadata.by_compress_digest, digest, resp); + + if (!layer_store_lock(false)) { + return -1; + } + + ret = layers_by_digest_map(g_metadata.by_compress_digest, digest, resp); + layer_store_unlock(); + return ret; } int layer_store_by_uncompress_digest(const char *digest, struct layer_list *resp) { + int ret = 0; + if (resp == NULL) { return -1; } - return layers_by_digest_map(g_metadata.by_uncompress_digest, digest, resp); + if (!layer_store_lock(false)) { + return -1; + } + + ret = layers_by_digest_map(g_metadata.by_uncompress_digest, digest, resp); + layer_store_unlock(); + return ret; } struct layer *layer_store_lookup(const char *name) @@ -1649,4 +1655,4 @@ free_out: void layer_store_exit() { graphdriver_cleanup(); -} \ No newline at end of file +} -- GitLab