]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
resolving const and macro expansion issues -- need to handle arrays and variable...
authorAlex Markuze <amarkuze@redhat.com>
Mon, 7 Apr 2025 19:46:20 +0000 (19:46 +0000)
committerAlex Markuze <amarkuze@redhat.com>
Mon, 7 Apr 2025 19:46:20 +0000 (19:46 +0000)
include/linux/ceph/ceph_debug.h
include/linux/ceph/ceph_san_logger.h
include/linux/ceph/ceph_san_ser.h

index e7ae9c7a4fc5baa8dee9dcb8d91801196c3183d8..19d27fb4eaf2b05ddf93296d33356f705413f982 100644 (file)
  * 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
 
index 0a4dde8e917f285f7b6ffb0bbbdbf856fa63a3d2..cc200c639026078b41ee13808f35bd33accef80e 100644 (file)
@@ -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 */
index 69db63e4f14af60763bee12c81ac7e6231f0518e..aa6f688bc2045325a418082ab8aace0fa85afbb0 100644 (file)
 #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))