From: Alex Markuze Date: Mon, 7 Apr 2025 19:46:20 +0000 (+0000) Subject: resolving const and macro expansion issues -- need to handle arrays and variable... X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9e52473136fef961a6db411444dec6311d8c84f1;p=ceph-client.git resolving const and macro expansion issues -- need to handle arrays and variable strings! --- diff --git a/include/linux/ceph/ceph_debug.h b/include/linux/ceph/ceph_debug.h index e7ae9c7a4fc5..19d27fb4eaf2 100644 --- a/include/linux/ceph/ceph_debug.h +++ b/include/linux/ceph/ceph_debug.h @@ -51,9 +51,10 @@ * or, just wrap pr_debug */ # define dout(fmt, ...) CEPH_SAN_LOG(fmt, ##__VA_ARGS__) -# define doutc(client, fmt, ...) \ - CEPH_SAN_LOG("[%pU:%llu] " fmt, &client->fsid, \ - client->monc.auth->global_id, ##__VA_ARGS__) +# define doutc(__c, fmt, ...) if (__c) { CEPH_SAN_LOG(fmt, ##__VA_ARGS__); } +//# define doutc(client, fmt, ...) \ +// CEPH_SAN_LOG("[%pU:%llu] " fmt, &client->fsid, \ +// client->monc.auth->global_id, ##__VA_ARGS__) #endif diff --git a/include/linux/ceph/ceph_san_logger.h b/include/linux/ceph/ceph_san_logger.h index 0a4dde8e917f..cc200c639026 100644 --- a/include/linux/ceph/ceph_san_logger.h +++ b/include/linux/ceph/ceph_san_logger.h @@ -89,12 +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; \ + 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__); \ } \ - __buffer = ceph_san_log(__source_id, __size); \ + ___buffer = ceph_san_log(__source_id, __size); \ + if (likely(___buffer)) { \ + ceph_san_ser(___buffer, ##__VA_ARGS__);\ + } \ } while (0) /* Global logger instance */ diff --git a/include/linux/ceph/ceph_san_ser.h b/include/linux/ceph/ceph_san_ser.h index 69db63e4f14a..aa6f688bc204 100644 --- a/include/linux/ceph/ceph_san_ser.h +++ b/include/linux/ceph/ceph_san_ser.h @@ -46,16 +46,50 @@ #define ___ceph_san_cnt32(__t, __args...) (___ceph_san_cnt31(__args) + sizeof(__t)) #define ceph_san_cnt(...) ___ceph_san_apply(___ceph_san_cnt, ceph_san_narg(__VA_ARGS__))(__VA_ARGS__) -#define __ceph_san_ser_type(__buffer, __t) \ +#define __ceph_san_ser_const_type(__buffer, __t) \ (__builtin_choose_expr( \ __builtin_types_compatible_p(typeof(__t), const char *), \ - (*(char **)(__buffer) = (char *)(__t), printf("const")), \ - (*(typeof(__t) *)(__buffer) = (__t), printf("other")) \ + (*(char **)(__buffer) = (char *)(__t)), \ + (*(typeof(__t) *)(__buffer) = (__t)) \ )) +#define __ceph_san_ser_type_size(__buffer, __t) \ + (__builtin_choose_expr(sizeof(__t) == 1, \ + (*(uint8_t *)(__buffer) = (uint8_t)(__t)), \ + __builtin_choose_expr(sizeof(__t) == 2, \ + (*(uint16_t *)(__buffer) = (uint16_t)(__t)), \ + __builtin_choose_expr(sizeof(__t) == 4, \ + (*(uint32_t *)(__buffer) = (uint32_t)(__t)), \ + __builtin_choose_expr(sizeof(__t) == 8, \ + (*(uint64_t *)(__buffer) = (uint64_t)(__t)), \ + (*(typeof(__t) *)(__buffer) = (__t)) \ + ))))) + +#define __ceph_san_ser_type_memcpy(__buffer, __t) \ + (__builtin_memcpy(__buffer, &(__t), sizeof(__t)), \ + __buffer = (void *)((char *)__buffer + sizeof(__t))) + +#define __suppress_cast_warning(type, value) \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wint-to-pointer-cast\"") \ + _Pragma("GCC diagnostic ignored \"-Wpointer-to-int-cast\"") \ + ((type)(value)) \ + _Pragma("GCC diagnostic pop") + +#define __ceph_san_ser_type(__buffer, __t) \ + (__builtin_choose_expr(sizeof(__t) == 1, \ + (*(uint8_t *)(__buffer) = __suppress_cast_warning(uint8_t, __t)), \ + __builtin_choose_expr(sizeof(__t) == 2, \ + (*(uint16_t *)(__buffer) = __suppress_cast_warning(uint16_t, __t)), \ + __builtin_choose_expr(sizeof(__t) == 4, \ + (*(uint32_t *)(__buffer) = __suppress_cast_warning(uint32_t, __t)), \ + __builtin_choose_expr(sizeof(__t) == 8, \ + (*(uint64_t *)(__buffer) = __suppress_cast_warning(uint64_t, __t)), \ + (*(typeof(__t) *)(__buffer) = __suppress_cast_warning(typeof(__t), __t)) \ + ))))) #define __ceph_san_ser(__buffer, __t) (__ceph_san_ser_type(__buffer, __t), __buffer = (void*)((typeof(__t)*)__buffer + 1)) -#define ___ceph_san_ser0(__buffer) (__buffer) +#define ___ceph_san_ser0(__buffer) #define ___ceph_san_ser1(__buffer, __t) (__ceph_san_ser(__buffer, __t)) #define ___ceph_san_ser2(__buffer, __t, __args...) (__ceph_san_ser(__buffer, __t), ___ceph_san_ser1(__buffer, __args)) #define ___ceph_san_ser3(__buffer, __t, __args...) (__ceph_san_ser(__buffer, __t), ___ceph_san_ser2(__buffer, __args))