]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph_new: improve mount cache-entry ref-count
authorShachar Sharon <ssharon@redhat.com>
Thu, 5 Sep 2024 14:14:59 +0000 (17:14 +0300)
committerJule Anger <janger@samba.org>
Mon, 17 Feb 2025 16:09:09 +0000 (16:09 +0000)
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 <ssharon@redhat.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 29a9d18d2d21842bb38bcdc6b9e366abac458ed9)

source3/modules/vfs_ceph_new.c

index 235cc352d2e72fc88c3af2a0ee876e64a6c2e996..073a51ce94cf19cfbf8a1b1754ad1c330660fd09 100644 (file)
@@ -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;
        }