From: Shachar Sharon Date: Thu, 5 Sep 2024 14:14:59 +0000 (+0300) Subject: vfs_ceph_new: improve mount cache-entry ref-count X-Git-Tag: samba-4.20.8~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00d505ae38e935d4594041533363050523139bbd;p=thirdparty%2Fsamba.git vfs_ceph_new: improve mount cache-entry ref-count Use singed int32_t for cached mount-entries reference counting. Define helper function for inc/dec ref-count which also provides proper logging. Prefer boolean return-value for 'cephmount_cache_remove' as 'int' is often used as error indicator within the context of libcephfs and this VFS module. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15703 Signed-off-by: Shachar Sharon Reviewed-by: Anoop C S Reviewed-by: John Mulligan (cherry picked from commit 29a9d18d2d21842bb38bcdc6b9e366abac458ed9) --- diff --git a/source3/modules/vfs_ceph_new.c b/source3/modules/vfs_ceph_new.c index 235cc352d2e..073a51ce94c 100644 --- a/source3/modules/vfs_ceph_new.c +++ b/source3/modules/vfs_ceph_new.c @@ -172,7 +172,7 @@ struct vfs_ceph_config { static struct cephmount_cached { char *cookie; - uint32_t count; + int32_t count; struct ceph_mount_info *mount; struct cephmount_cached *next, *prev; uint64_t fd_index; @@ -207,15 +207,28 @@ static int cephmount_cache_add(const char *cookie, return 0; } +static bool cephmount_cache_change_ref(struct cephmount_cached *entry, int n) +{ + entry->count += n; + + DBG_DEBUG("[CEPH] updated mount cache entry: count=%" PRId32 + "change=%+d cookie='%s'\n", entry->count, n, entry->cookie); + + if (entry->count && (n < 0)) { + DBG_DEBUG("[CEPH] mount cache entry still in use: " + "count=%" PRId32 " cookie='%s'\n", + entry->count, entry->cookie); + } + return (entry->count == 0); +} + static struct cephmount_cached *cephmount_cache_update(const char *cookie) { struct cephmount_cached *entry = NULL; for (entry = cephmount_cached; entry; entry = entry->next) { if (strcmp(entry->cookie, cookie) == 0) { - entry->count++; - DBG_DEBUG("[CEPH] updated mount cache: count is [%" - PRIu32 "]\n", entry->count); + cephmount_cache_change_ref(entry, 1); return entry; } } @@ -223,18 +236,16 @@ static struct cephmount_cached *cephmount_cache_update(const char *cookie) return NULL; } -static int cephmount_cache_remove(struct cephmount_cached *entry) +static bool cephmount_cache_remove(struct cephmount_cached *entry) { - if (--entry->count) { - DBG_DEBUG("[CEPH] updated mount cache: count is [%" - PRIu32 "]\n", entry->count); - return entry->count; + if (!cephmount_cache_change_ref(entry, -1)) { + return false; } DBG_DEBUG("[CEPH] removing mount cache entry for %s\n", entry->cookie); DLIST_REMOVE(cephmount_cached, entry); talloc_free(entry); - return 0; + return true; } static char *cephmount_get_cookie(TALLOC_CTX * mem_ctx, @@ -543,9 +554,7 @@ static void vfs_ceph_disconnect(struct vfs_handle_struct *handle) mount = config->mount; - ret = cephmount_cache_remove(config->mount_entry); - if (ret > 0) { - DBG_DEBUG("[CEPH] mount cache entry still in use\n"); + if (!cephmount_cache_remove(config->mount_entry)) { return; }