]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
FSID serialization
authorAlex Markuze <amarkuze@redhat.com>
Tue, 15 Apr 2025 14:17:24 +0000 (14:17 +0000)
committerAlex Markuze <amarkuze@redhat.com>
Tue, 15 Apr 2025 14:17:24 +0000 (14:17 +0000)
include/linux/ceph/ceph_san_logger.h
net/ceph/ceph_san_logger.c

index e7e4fecf71b53fbbd62b7ec2bf81ae587515e850..bde916d2c8f9d16bd22cd90548d76aa59604d996 100644 (file)
@@ -20,7 +20,6 @@
 struct ceph_san_client_id {
     char fsid[16];         /* Client FSID */
     u64 global_id;         /* Client global ID */
-    u32 idx;              /* Index in the cache */
 };
 
 /* Source information mapping structure */
@@ -97,13 +96,13 @@ u32 ceph_san_check_client_id(u32 id, const char *fsid, u64 global_id);
 const struct ceph_san_client_id *ceph_san_get_client_info(u32 id);
 
 /* Log a message */
-void* ceph_san_log(u32 source_id, size_t needed_size);
+void* ceph_san_log(u32 source_id, u32 client_id, size_t needed_size);
 
 /* Get current TLS context, creating if necessary */
 struct ceph_san_tls_ctx *ceph_san_get_tls_ctx(void);
 
 /* Helper macro for logging */
-#define CEPH_SAN_LOG(fmt, ...) \
+#define __CEPH_SAN_LOG(id, fmt, ...) \
     do { \
         static u32 __source_id = 0; \
         static size_t __size = 0; \
@@ -112,30 +111,22 @@ struct ceph_san_tls_ctx *ceph_san_get_tls_ctx(void);
             __source_id = ceph_san_get_source_id(kbasename(__FILE__), __func__, __LINE__, fmt); \
             __size = ceph_san_cnt(__VA_ARGS__); \
         } \
-        ___buffer = ceph_san_log(__source_id, __size); \
+        ___buffer = ceph_san_log(__source_id, 0, __size); \
        if (likely(___buffer)) {        \
                ceph_san_ser(___buffer, ##__VA_ARGS__);\
        } \
     } while (0)
 
+#define CEPH_SAN_LOG(fmt, ...) \
+    __CEPH_SAN_LOG(0, fmt, ##__VA_ARGS__)
+
 /* Helper macro for logging with client ID */
 #define CEPH_SAN_LOG_CLIENT(client, fmt, ...) \
     do { \
-        static u32 __source_id = 0; \
         static u32 __client_id = 0; \
-        static size_t __size = 0; \
-        void *___buffer = NULL; \
-        if (unlikely(__source_id == 0)) { \
-            __source_id = ceph_san_get_source_id(kbasename(__FILE__), __func__, __LINE__, fmt); \
-            __size = ceph_san_cnt(__VA_ARGS__); \
-        } \
         __client_id = ceph_san_check_client_id(__client_id, client->fsid.fsid, client->monc.auth->global_id); \
-        ___buffer = ceph_san_log(__source_id, __size); \
-       if (likely(___buffer)) {        \
-               ceph_san_ser(___buffer, ##__VA_ARGS__);\
-       } \
+        __CEPH_SAN_LOG(__client_id, fmt, ##__VA_ARGS__); \
     } while (0)
-
 /* Global logger instance */
 extern struct ceph_san_logger g_logger;
 
index f2ba6f7c384b5d4718d85d4c5111528a6d8711aa..35481971618c94155776d31889e261297d007060 100644 (file)
@@ -201,7 +201,6 @@ u32 ceph_san_check_client_id(u32 id, const char *fsid, u64 global_id)
     entry = &g_logger.client_map[found_id];
     memcpy(entry->fsid, fsid, sizeof(entry->fsid));
     entry->global_id = global_id;
-    entry->idx = found_id;
 
 out:
     spin_unlock(&g_logger.client_lock);
@@ -210,52 +209,6 @@ out_fast:
 }
 EXPORT_SYMBOL(ceph_san_check_client_id);
 
-/**
- * ceph_san_get_client_id - Helper function to get or create a client ID
- * @fsid: Client FSID
- * @global_id: Client global ID
- *
- * Returns a unique ID for this client pair
- */
-static u32 ceph_san_get_client_id(const char *fsid, u64 global_id)
-{
-    u32 id;
-    struct ceph_san_client_id *entry;
-    bool found = false;
-    u32 max_id;
-
-    spin_lock(&g_logger.client_lock);
-    max_id = g_logger.next_client_id;
-
-    /* First try to find existing entry */
-    for (id = 1; id < max_id && id < CEPH_SAN_MAX_CLIENT_IDS; id++) {
-        entry = &g_logger.client_map[id];
-        if (memcmp(entry->fsid, fsid, sizeof(entry->fsid)) == 0 &&
-            entry->global_id == global_id) {
-            found = true;
-            break;
-        }
-    }
-
-    /* If not found, allocate new ID */
-    if (!found) {
-        id = ++g_logger.next_client_id;
-        if (id >= CEPH_SAN_MAX_CLIENT_IDS) {
-            /* If we run out of IDs, just use the first one */
-            pr_warn("ceph_san_logger: client ID overflow, reusing ID 1\n");
-            id = 1;
-        }
-
-        entry = &g_logger.client_map[id];
-        memcpy(entry->fsid, fsid, sizeof(entry->fsid));
-        entry->global_id = global_id;
-        entry->idx = id;
-    }
-
-    spin_unlock(&g_logger.client_lock);
-    return id;
-}
-
 /**
  * ceph_san_get_client_info - Get client info for a given ID
  * @id: Client ID
@@ -273,13 +226,13 @@ EXPORT_SYMBOL(ceph_san_get_client_info);
 /**
  * ceph_san_log - Log a message
  * @source_id: Source ID for this location
+ * @client_id: Client ID for this message
+ * @needed_size: Size needed for the message
  *
- * Logs a message to the current TLS context's log buffer
- * Format string is retrieved from the source_map
+ * Returns a buffer to write the message into
  */
-void* ceph_san_log(u32 source_id, size_t needed_size)
+void* ceph_san_log(u32 source_id, u32 client_id, size_t needed_size)
 {
-    /* Format the message into local buffer first */
     struct ceph_san_tls_ctx *ctx;
     struct ceph_san_log_entry *entry;
     u64 alloc;
@@ -290,7 +243,7 @@ void* ceph_san_log(u32 source_id, size_t needed_size)
         return NULL;
     }
 
-    /* Allocate entry from pagefrag - We need a spinlock here to protect access iterators */
+    /* Allocate entry from pagefrag */
     spin_lock_bh(&ctx->pf.lock);
     alloc = cephsan_pagefrag_alloc(&ctx->pf, needed_size);
     int loop_count = 0;
@@ -327,6 +280,7 @@ void* ceph_san_log(u32 source_id, size_t needed_size)
     entry->debug_poison = CEPH_SAN_LOG_ENTRY_POISON;
     entry->ts = jiffies;
     entry->source_id = source_id;
+    entry->client_id = client_id;
     if (unlikely(cephsan_pagefrag_is_wraparound(alloc))) {
         entry->buffer = cephsan_pagefrag_get_ptr(&ctx->pf, 0);
     } else {