From d70110aa951eaabc6a9a22d0a7e89c1d8ec51f9d Mon Sep 17 00:00:00 2001 From: Alex Markuze Date: Mon, 7 Apr 2025 12:00:57 +0000 Subject: [PATCH] serializing input parameters --- include/linux/ceph/ceph_san_logger.h | 8 ++++++-- net/ceph/ceph_san_logger.c | 24 +++--------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/include/linux/ceph/ceph_san_logger.h b/include/linux/ceph/ceph_san_logger.h index 0b377119abb9f..b007c0cff4f2d 100644 --- a/include/linux/ceph/ceph_san_logger.h +++ b/include/linux/ceph/ceph_san_logger.h @@ -79,7 +79,7 @@ u32 ceph_san_get_source_id(const char *file, const char *func, unsigned int line const struct ceph_san_source_info *ceph_san_get_source_info(u32 id); /* Log a message */ -void ceph_san_log(u32 source_id, ...); +void* ceph_san_log(u32 source_id, size_t size); /* Get current TLS context, creating if necessary */ struct ceph_san_tls_ctx *ceph_san_get_tls_ctx(void); @@ -89,11 +89,15 @@ struct ceph_san_tls_ctx *ceph_san_get_tls_ctx(void); do { \ static u32 __source_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__); \ } \ - ceph_san_log(__source_id, ##__VA_ARGS__); \ + __buffer = ceph_san_log(__source_id, __size); \ + if (__buffer) { \ + ceph_san_ser(__buffer, ##__VA_ARGS__); \ + } \ } while (0) /* Global logger instance */ diff --git a/net/ceph/ceph_san_logger.c b/net/ceph/ceph_san_logger.c index ac243a70c08ee..46127229cc324 100644 --- a/net/ceph/ceph_san_logger.c +++ b/net/ceph/ceph_san_logger.c @@ -159,35 +159,19 @@ EXPORT_SYMBOL(ceph_san_get_source_info); * Logs a message to the current TLS context's log buffer * Format string is retrieved from the source_map */ -void ceph_san_log(u32 source_id, ...) +void* ceph_san_log(u32 source_id, size_t needed_size) { /* Format the message into local buffer first */ - char buf[256]; struct ceph_san_tls_ctx *ctx; struct ceph_san_log_entry *entry; - va_list args; u64 alloc; - int len, needed_size; - const struct ceph_san_source_info *source_info; ctx = ceph_san_get_tls_ctx(); if (!ctx) { pr_err("Failed to get TLS context\n"); - return; - } - - /* Get format string from source info */ - source_info = ceph_san_get_source_info(source_id); - if (!source_info || !source_info->fmt) { - pr_err("Invalid source ID or missing format string\n"); - return; + return NULL; } - va_start(args, source_id); - len = vsnprintf(buf, sizeof(buf), source_info->fmt, args); - va_end(args); - - needed_size = sizeof(*entry) + len + 1; /* Allocate entry from pagefrag - We need a spinlock here to protect access iterators */ spin_lock_bh(&ctx->pf.lock); alloc = cephsan_pagefrag_alloc(&ctx->pf, needed_size); @@ -233,9 +217,7 @@ void ceph_san_log(u32 source_id, ...) entry->len = cephsan_pagefrag_get_alloc_size(alloc); spin_unlock_bh(&ctx->pf.lock); - /* Copy to entry buffer */ - memcpy(entry->buffer, buf, len + 1); - entry->buffer[len] = '\0'; + return entry->buffer; } EXPORT_SYMBOL(ceph_san_log); -- 2.39.5