Whamcloud - gitweb
LU-14291 ptlrpc: format UPDATE messages in server-only code
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
index 087c491..e4bacc2 100644 (file)
@@ -40,6 +40,8 @@
 
 #define DEBUG_SUBSYSTEM S_RPC
 
+#include <linux/crc32.h>
+
 #include <libcfs/libcfs.h>
 
 #include <llog_swab.h>
@@ -48,8 +50,6 @@
 #include <obd_cksum.h>
 #include <obd_class.h>
 #include <obd_support.h>
-#include <obj_update.h>
-
 #include "ptlrpc_internal.h"
 
 static inline __u32 lustre_msg_hdr_size_v2(__u32 count)
@@ -1374,20 +1374,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);
+               struct ptlrpc_body *pb = lustre_msg_buf_v2(msg, buf, 0);
+               __u32 len = lustre_msg_buflen(msg, buf);
+               __u32 crc;
 
+#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;
-               __u32 crc;
 
-               LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
                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 +1993,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);
 }
@@ -2073,14 +2079,19 @@ static void lustre_swab_obd_dqblk(struct obd_dqblk *b)
        BUILD_BUG_ON(offsetof(typeof(*b), dqb_padding) == 0);
 }
 
-void lustre_swab_obd_quotactl(struct obd_quotactl *q)
+int lustre_swab_obd_quotactl(struct obd_quotactl *q, __u32 len)
 {
+       if (unlikely(len <= sizeof(struct obd_quotactl)))
+               return -EOVERFLOW;
+
        __swab32s(&q->qc_cmd);
        __swab32s(&q->qc_type);
        __swab32s(&q->qc_id);
        __swab32s(&q->qc_stat);
        lustre_swab_obd_dqinfo(&q->qc_dqinfo);
        lustre_swab_obd_dqblk(&q->qc_dqblk);
+
+       return len;
 }
 
 void lustre_swab_fid2path(struct getinfo_fid2path *gf)
@@ -2881,110 +2892,6 @@ void lustre_swab_hsm_request(struct hsm_request *hr)
        __swab32s(&hr->hr_data_len);
 }
 
-void lustre_swab_object_update(struct object_update *ou)
-{
-       struct object_update_param *param;
-       size_t  i;
-
-       __swab16s(&ou->ou_type);
-       __swab16s(&ou->ou_params_count);
-       __swab32s(&ou->ou_result_size);
-       __swab32s(&ou->ou_flags);
-       __swab32s(&ou->ou_padding1);
-       __swab64s(&ou->ou_batchid);
-       lustre_swab_lu_fid(&ou->ou_fid);
-       param = &ou->ou_params[0];
-       for (i = 0; i < ou->ou_params_count; i++) {
-               __swab16s(&param->oup_len);
-               __swab16s(&param->oup_padding);
-               __swab32s(&param->oup_padding2);
-               param = (struct object_update_param *)((char *)param +
-                        object_update_param_size(param));
-       }
-}
-
-int lustre_swab_object_update_request(struct object_update_request *our,
-                                     __u32 len)
-{
-       __u32 i, size = 0;
-       struct object_update *ou;
-
-       __swab32s(&our->ourq_magic);
-       __swab16s(&our->ourq_count);
-       __swab16s(&our->ourq_padding);
-
-       /* Don't need to calculate request size if len is 0. */
-       if (len > 0) {
-               size = sizeof(struct object_update_request);
-               for (i = 0; i < our->ourq_count; i++) {
-                       ou = object_update_request_get(our, i, NULL);
-                       if (ou == NULL)
-                               return -EPROTO;
-                       size += sizeof(struct object_update) +
-                               ou->ou_params_count *
-                               sizeof(struct object_update_param);
-               }
-               if (unlikely(size > len))
-                       return -EOVERFLOW;
-       }
-
-       for (i = 0; i < our->ourq_count; i++) {
-               ou = object_update_request_get(our, i, NULL);
-               lustre_swab_object_update(ou);
-       }
-
-       return size;
-}
-
-void lustre_swab_object_update_result(struct object_update_result *our)
-{
-       __swab32s(&our->our_rc);
-       __swab16s(&our->our_datalen);
-       __swab16s(&our->our_padding);
-}
-
-int lustre_swab_object_update_reply(struct object_update_reply *our, __u32 len)
-{
-       __u32 i, size;
-
-       __swab32s(&our->ourp_magic);
-       __swab16s(&our->ourp_count);
-       __swab16s(&our->ourp_padding);
-
-       size = sizeof(struct object_update_reply) + our->ourp_count *
-              (sizeof(__u16) + sizeof(struct object_update_result));
-       if (unlikely(size > len))
-               return -EOVERFLOW;
-
-       for (i = 0; i < our->ourp_count; i++) {
-               struct object_update_result *ourp;
-
-               __swab16s(&our->ourp_lens[i]);
-               ourp = object_update_result_get(our, i, NULL);
-               if (ourp == NULL)
-                       return -EPROTO;
-               lustre_swab_object_update_result(ourp);
-       }
-
-       return size;
-}
-
-void lustre_swab_out_update_header(struct out_update_header *ouh)
-{
-       __swab32s(&ouh->ouh_magic);
-       __swab32s(&ouh->ouh_count);
-       __swab32s(&ouh->ouh_inline_length);
-       __swab32s(&ouh->ouh_reply_size);
-}
-EXPORT_SYMBOL(lustre_swab_out_update_header);
-
-void lustre_swab_out_update_buffer(struct out_update_buffer *oub)
-{
-       __swab32s(&oub->oub_size);
-       __swab32s(&oub->oub_padding);
-}
-EXPORT_SYMBOL(lustre_swab_out_update_buffer);
-
 void lustre_swab_swap_layouts(struct mdc_swap_layouts *msl)
 {
        __swab64s(&msl->msl_flags);