Whamcloud - gitweb
LU-13127 ptlrpc: prefer crc32_le() over CryptoAPI
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
index 8cc0ff6..33b491c 100644 (file)
@@ -40,6 +40,8 @@
 
 #define DEBUG_SUBSYSTEM S_RPC
 
+#include <linux/crc32.h>
+
 #include <libcfs/libcfs.h>
 
 #include <llog_swab.h>
@@ -1374,20 +1376,26 @@ __u64 lustre_msg_get_mbits(struct lustre_msg *msg)
        }
 }
 
-__u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
+__u32 lustre_msg_calc_cksum(struct lustre_msg *msg, __u32 buf)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
-               struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-               __u32 len = lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF);
-
-               unsigned int hsize = 4;
+               struct ptlrpc_body *pb = lustre_msg_buf_v2(msg, buf, 0);
+               __u32 len = lustre_msg_buflen(msg, buf);
                __u32 crc;
 
                LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
+#if IS_ENABLED(CONFIG_CRC32)
+               /* about 10x faster than crypto_hash for small buffers */
+               crc = crc32_le(~(__u32)0, (unsigned char *)pb, len);
+#elif IS_ENABLED(CONFIG_CRYPTO_CRC32)
+               unsigned int hsize = 4;
                cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb,
                                       len, NULL, 0, (unsigned char *)&crc,
                                       &hsize);
+#else
+#error "need either CONFIG_CRC32 or CONFIG_CRYPTO_CRC32 enabled in the kernel"
+#endif
                return crc;
        }
        default:
@@ -1987,7 +1995,7 @@ void lustre_swab_mdt_body(struct mdt_body *b)
        __swab32s(&b->mbo_projid);
        __swab64s(&b->mbo_dom_size);
        __swab64s(&b->mbo_dom_blocks);
-       BUILD_BUG_ON(offsetof(typeof(*b), mbo_padding_8) == 0);
+       __swab64s(&b->mbo_btime);
        BUILD_BUG_ON(offsetof(typeof(*b), mbo_padding_9) == 0);
        BUILD_BUG_ON(offsetof(typeof(*b), mbo_padding_10) == 0);
 }