]> git.apps.os.sepia.ceph.com Git - ceph-client.git/commitdiff
pf spin lock
authorAlex Markuze <amarkuze@redhat.com>
Mon, 17 Mar 2025 15:30:31 +0000 (15:30 +0000)
committerAlex Markuze <amarkuze@redhat.com>
Mon, 17 Mar 2025 15:30:31 +0000 (15:30 +0000)
include/linux/ceph/ceph_san_pagefrag.h
net/ceph/ceph_san_logger.c
net/ceph/ceph_san_pagefrag.c

index faeba5dcce0ce1d3e53e166bafe34925118515ed..85248b851b64396d25e38b522332dad365032dab 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <linux/types.h>
 #include <linux/mm.h>
+#include <linux/spinlock.h>
 
 #define CEPHSAN_PAGEFRAG_SIZE  (1<<21)  /* 2MB */
 #define CEPHSAN_PAGEFRAG_MASK (CEPHSAN_PAGEFRAG_SIZE - 1)
@@ -11,6 +12,7 @@
 struct cephsan_pagefrag {
     struct page *pages;
     void *buffer;
+    spinlock_t lock;        /* protects head and tail */
     unsigned int head;
     unsigned int tail;
 };
index 16fee904102ab67a16965e405d5907214b9108ef..88e056058da6f199c2521dec011b31e8fde2e181 100644 (file)
@@ -131,7 +131,8 @@ void ceph_san_log(const char *file, unsigned int line, const char *fmt, ...)
     va_end(args);
 
     needed_size = sizeof(*entry) + len + 1;
-    /* Allocate entry from pagefrag */ //We need a spinlock here to protect printing
+    /* Allocate entry from pagefrag - We need a spinlock here to protect access iterators */
+    spin_lock(&ctx->pf.lock);
     alloc = cephsan_pagefrag_alloc(&ctx->pf, needed_size);
     while (!alloc) {
         entry = cephsan_pagefrag_get_ptr_from_tail(&ctx->pf);
@@ -149,16 +150,17 @@ void ceph_san_log(const char *file, unsigned int line, const char *fmt, ...)
     }
     entry = cephsan_pagefrag_get_ptr(&ctx->pf, alloc);
 
-    /* Copy to entry buffer */
-    memcpy(entry->buffer, buf, len + 1);
-    entry->buffer[len] = '\0';
-
     /* Fill in entry details */
     entry->debug_poison = CEPH_SAN_LOG_ENTRY_POISON;
     entry->ts = jiffies;
     entry->line = line;
     entry->file = file;
     entry->len = cephsan_pagefrag_get_alloc_size(alloc);
+    spin_unlock(&ctx->pf.lock);
+
+    /* Copy to entry buffer */
+    memcpy(entry->buffer, buf, len + 1);
+    entry->buffer[len] = '\0';
 }
 EXPORT_SYMBOL(ceph_san_log);
 
index 282b236376f613cb87cfff0f3c3c39db4c8019a3..80d34d04585468a22397f52ca3ccdaacc4b96ead 100644 (file)
@@ -12,6 +12,7 @@
  */
 int cephsan_pagefrag_init(struct cephsan_pagefrag *pf)
 {
+    spin_lock_init(&pf->lock);
     pf->pages = alloc_pages(GFP_KERNEL, get_order(CEPHSAN_PAGEFRAG_SIZE));
     if (!pf->pages)
         return -ENOMEM;
@@ -33,6 +34,7 @@ EXPORT_SYMBOL(cephsan_pagefrag_init);
  */
 int cephsan_pagefrag_init_with_buffer(struct cephsan_pagefrag *pf, void *buffer, size_t size)
 {
+    spin_lock_init(&pf->lock);
     pf->pages = NULL; /* No pages allocated, using provided buffer */
     pf->buffer = buffer;
     pf->head = 0;
@@ -151,7 +153,9 @@ EXPORT_SYMBOL(cephsan_pagefrag_deinit);
  */
 void cephsan_pagefrag_reset(struct cephsan_pagefrag *pf)
 {
+    spin_lock(&pf->lock);
     pf->head = 0;
     pf->tail = 0;
+    spin_unlock(&pf->lock);
 }
 EXPORT_SYMBOL(cephsan_pagefrag_reset);