Whamcloud - gitweb
LU-13127 ptlrpc: prefer crc32_le() over CryptoAPI
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
index 634f7d6..33b491c 100644 (file)
@@ -40,6 +40,8 @@
 
 #define DEBUG_SUBSYSTEM S_RPC
 
+#include <linux/crc32.h>
+
 #include <libcfs/libcfs.h>
 
 #include <llog_swab.h>
@@ -54,8 +56,8 @@
 
 static inline __u32 lustre_msg_hdr_size_v2(__u32 count)
 {
-        return cfs_size_round(offsetof(struct lustre_msg_v2,
-                                       lm_buflens[count]));
+       return cfs_size_round(offsetof(struct lustre_msg_v2,
+                                      lm_buflens[count]));
 }
 
 __u32 lustre_msg_hdr_size(__u32 magic, __u32 count)
@@ -74,10 +76,10 @@ __u32 lustre_msg_hdr_size(__u32 magic, __u32 count)
 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
                            __u32 index)
 {
-        if (inout)
-                lustre_set_req_swabbed(req, index);
-        else
-                lustre_set_rep_swabbed(req, index);
+       if (inout)
+               lustre_set_req_swabbed(req, index);
+       else
+               lustre_set_rep_swabbed(req, index);
 }
 
 bool ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
@@ -138,44 +140,48 @@ __u32 lustre_msg_size_v2(int count, __u32 *lengths)
 }
 EXPORT_SYMBOL(lustre_msg_size_v2);
 
-/* This returns the size of the buffer that is required to hold a lustre_msg
+/*
+ * This returns the size of the buffer that is required to hold a lustre_msg
  * with the given sub-buffer lengths.
  * NOTE: this should only be used for NEW requests, and should always be
  *       in the form of a v2 request.  If this is a connection to a v1
  *       target then the first buffer will be stripped because the ptlrpc
- *       data is part of the lustre_msg_v1 header. b=14043 */
+ *       data is part of the lustre_msg_v1 header. b=14043
+ */
 __u32 lustre_msg_size(__u32 magic, int count, __u32 *lens)
 {
-        __u32 size[] = { sizeof(struct ptlrpc_body) };
+       __u32 size[] = { sizeof(struct ptlrpc_body) };
 
-        if (!lens) {
-                LASSERT(count == 1);
-                lens = size;
-        }
+       if (!lens) {
+               LASSERT(count == 1);
+               lens = size;
+       }
 
-        LASSERT(count > 0);
+       LASSERT(count > 0);
        LASSERT(lens[MSG_PTLRPC_BODY_OFF] >= sizeof(struct ptlrpc_body_v2));
 
-        switch (magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return lustre_msg_size_v2(count, lens);
-        default:
-                LASSERTF(0, "incorrect message magic: %08x\n", magic);
+       switch (magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_msg_size_v2(count, lens);
+       default:
+               LASSERTF(0, "incorrect message magic: %08x\n", magic);
                return 0;
-        }
+       }
 }
 
-/* This is used to determine the size of a buffer that was already packed
- * and will correctly handle the different message formats. */
+/*
+ * This is used to determine the size of a buffer that was already packed
+ * and will correctly handle the different message formats.
+ */
 __u32 lustre_packed_msg_size(struct lustre_msg *msg)
 {
-        switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
-        default:
-                CERROR("incorrect message magic: %08x\n", msg->lm_magic);
-                return 0;
-        }
+       switch (msg->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
+       default:
+               CERROR("incorrect message magic: %08x\n", msg->lm_magic);
+               return 0;
+       }
 }
 EXPORT_SYMBOL(lustre_packed_msg_size);
 
@@ -209,46 +215,46 @@ void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
 EXPORT_SYMBOL(lustre_init_msg_v2);
 
 static int lustre_pack_request_v2(struct ptlrpc_request *req,
-                                  int count, __u32 *lens, char **bufs)
+                                 int count, __u32 *lens, char **bufs)
 {
-        int reqlen, rc;
+       int reqlen, rc;
 
-        reqlen = lustre_msg_size_v2(count, lens);
+       reqlen = lustre_msg_size_v2(count, lens);
 
-        rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
-        if (rc)
-                return rc;
+       rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
+       if (rc)
+               return rc;
 
-        req->rq_reqlen = reqlen;
+       req->rq_reqlen = reqlen;
 
-        lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
-        lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
-        return 0;
+       lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
+       lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
+       return 0;
 }
 
 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
-                        __u32 *lens, char **bufs)
+                       __u32 *lens, char **bufs)
 {
-        __u32 size[] = { sizeof(struct ptlrpc_body) };
+       __u32 size[] = { sizeof(struct ptlrpc_body) };
 
-        if (!lens) {
-                LASSERT(count == 1);
-                lens = size;
-        }
+       if (!lens) {
+               LASSERT(count == 1);
+               lens = size;
+       }
 
-        LASSERT(count > 0);
-        LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
+       LASSERT(count > 0);
+       LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
 
-        /* only use new format, we don't need to be compatible with 1.4 */
-        magic = LUSTRE_MSG_MAGIC_V2;
+       /* only use new format, we don't need to be compatible with 1.4 */
+       magic = LUSTRE_MSG_MAGIC_V2;
 
-        switch (magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return lustre_pack_request_v2(req, count, lens, bufs);
-        default:
-                LASSERTF(0, "incorrect message magic: %08x\n", magic);
-                return -EINVAL;
-        }
+       switch (magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_pack_request_v2(req, count, lens, bufs);
+       default:
+               LASSERTF(0, "incorrect message magic: %08x\n", magic);
+               return -EINVAL;
+       }
 }
 
 #if RS_DEBUG
@@ -283,16 +289,15 @@ lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt)
 
        /* See if we have anything in a pool, and wait if nothing */
        while (list_empty(&svcpt->scp_rep_idle)) {
-               struct l_wait_info      lwi;
                int                     rc;
 
                spin_unlock(&svcpt->scp_rep_lock);
                /* If we cannot get anything for some long time, we better
                 * bail out instead of waiting infinitely */
-               lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
-               rc = l_wait_event(svcpt->scp_rep_waitq,
-                                 !list_empty(&svcpt->scp_rep_idle), &lwi);
-               if (rc != 0)
+               rc = wait_event_idle_timeout(svcpt->scp_rep_waitq,
+                                            !list_empty(&svcpt->scp_rep_idle),
+                                            cfs_time_seconds(10));
+               if (rc <= 0)
                        goto out;
                spin_lock(&svcpt->scp_rep_lock);
        }
@@ -325,7 +330,7 @@ int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
                         __u32 *lens, char **bufs, int flags)
 {
        struct ptlrpc_reply_state *rs;
-       int                        msg_len, rc;
+       int msg_len, rc;
        ENTRY;
 
        LASSERT(req->rq_reply_state == NULL);
@@ -343,7 +348,7 @@ int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
                RETURN(rc);
 
        rs = req->rq_reply_state;
-       atomic_set(&rs->rs_refcount, 1);        /* 1 ref for rq_reply_state */
+       atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
        rs->rs_cb_id.cbid_fn = reply_out_callback;
        rs->rs_cb_id.cbid_arg = rs;
        rs->rs_svcpt = req->rq_rqbd->rqbd_svcpt;
@@ -366,38 +371,38 @@ int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
 EXPORT_SYMBOL(lustre_pack_reply_v2);
 
 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
-                            char **bufs, int flags)
-{
-        int rc = 0;
-        __u32 size[] = { sizeof(struct ptlrpc_body) };
-
-        if (!lens) {
-                LASSERT(count == 1);
-                lens = size;
-        }
-
-        LASSERT(count > 0);
-        LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
-
-        switch (req->rq_reqmsg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
-                break;
-        default:
-                LASSERTF(0, "incorrect message magic: %08x\n",
-                         req->rq_reqmsg->lm_magic);
-                rc = -EINVAL;
-        }
-        if (rc != 0)
-                CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
-                       lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
-        return rc;
+                           char **bufs, int flags)
+{
+       int rc = 0;
+       __u32 size[] = { sizeof(struct ptlrpc_body) };
+
+       if (!lens) {
+               LASSERT(count == 1);
+               lens = size;
+       }
+
+       LASSERT(count > 0);
+       LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
+
+       switch (req->rq_reqmsg->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
+               break;
+       default:
+               LASSERTF(0, "incorrect message magic: %08x\n",
+                        req->rq_reqmsg->lm_magic);
+               rc = -EINVAL;
+       }
+       if (rc != 0)
+               CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
+                      lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
+       return rc;
 }
 
 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
-                      char **bufs)
+                     char **bufs)
 {
-        return lustre_pack_reply_flags(req, count, lens, bufs, 0);
+       return lustre_pack_reply_flags(req, count, lens, bufs, 0);
 }
 EXPORT_SYMBOL(lustre_pack_reply);
 
@@ -446,32 +451,32 @@ EXPORT_SYMBOL(lustre_msg_buf);
 static int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, __u32 segment,
                                unsigned int newlen, int move_data)
 {
-        char   *tail = NULL, *newpos;
-        int     tail_len = 0, n;
+       char *tail = NULL, *newpos;
+       int tail_len = 0, n;
 
-        LASSERT(msg);
-        LASSERT(msg->lm_bufcount > segment);
-        LASSERT(msg->lm_buflens[segment] >= newlen);
+       LASSERT(msg);
+       LASSERT(msg->lm_bufcount > segment);
+       LASSERT(msg->lm_buflens[segment] >= newlen);
 
-        if (msg->lm_buflens[segment] == newlen)
-                goto out;
+       if (msg->lm_buflens[segment] == newlen)
+               goto out;
 
-        if (move_data && msg->lm_bufcount > segment + 1) {
-                tail = lustre_msg_buf_v2(msg, segment + 1, 0);
-                for (n = segment + 1; n < msg->lm_bufcount; n++)
-                        tail_len += cfs_size_round(msg->lm_buflens[n]);
-        }
+       if (move_data && msg->lm_bufcount > segment + 1) {
+               tail = lustre_msg_buf_v2(msg, segment + 1, 0);
+               for (n = segment + 1; n < msg->lm_bufcount; n++)
+                       tail_len += cfs_size_round(msg->lm_buflens[n]);
+       }
 
-        msg->lm_buflens[segment] = newlen;
+       msg->lm_buflens[segment] = newlen;
 
-        if (tail && tail_len) {
-                newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
-                LASSERT(newpos <= tail);
-                if (newpos != tail)
-                        memmove(newpos, tail, tail_len);
-        }
+       if (tail && tail_len) {
+               newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
+               LASSERT(newpos <= tail);
+               if (newpos != tail)
+                       memmove(newpos, tail, tail_len);
+       }
 out:
-        return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
+       return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
 }
 
 /*
@@ -491,14 +496,14 @@ out:
  *   after call shrink.
  */
 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
-                      unsigned int newlen, int move_data)
+                     unsigned int newlen, int move_data)
 {
-        switch (msg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
-        default:
-                LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
-        }
+       switch (msg->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
+       default:
+               LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
+       }
 }
 EXPORT_SYMBOL(lustre_shrink_msg);
 
@@ -590,8 +595,8 @@ static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
                __swab32s(&m->lm_repsize);
                __swab32s(&m->lm_cksum);
                __swab32s(&m->lm_flags);
-               CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
-               CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
+               BUILD_BUG_ON(offsetof(typeof(*m), lm_padding_2) == 0);
+               BUILD_BUG_ON(offsetof(typeof(*m), lm_padding_3) == 0);
        }
 
        if (m->lm_bufcount == 0 || m->lm_bufcount > PTLRPC_MAX_BUFCOUNT) {
@@ -629,109 +634,111 @@ static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
 
 int __lustre_unpack_msg(struct lustre_msg *m, int len)
 {
-        int required_len, rc;
-        ENTRY;
+       int required_len, rc;
 
-        /* We can provide a slightly better error log, if we check the
-         * message magic and version first.  In the future, struct
-         * lustre_msg may grow, and we'd like to log a version mismatch,
-         * rather than a short message.
-         *
-         */
-        required_len = offsetof(struct lustre_msg, lm_magic) +
-                       sizeof(m->lm_magic);
-        if (len < required_len) {
-                /* can't even look inside the message */
-                CERROR("message length %d too small for magic/version check\n",
-                       len);
-                RETURN(-EINVAL);
-        }
+       ENTRY;
+       /*
+        * We can provide a slightly better error log, if we check the
+        * message magic and version first.  In the future, struct
+        * lustre_msg may grow, and we'd like to log a version mismatch,
+        * rather than a short message.
+        */
+       required_len = offsetof(struct lustre_msg, lm_magic) +
+                               sizeof(m->lm_magic);
+       if (len < required_len) {
+               /* can't even look inside the message */
+               CERROR("message length %d too small for magic/version check\n",
+                      len);
+               RETURN(-EINVAL);
+       }
 
-        rc = lustre_unpack_msg_v2(m, len);
+       rc = lustre_unpack_msg_v2(m, len);
 
-        RETURN(rc);
+       RETURN(rc);
 }
 EXPORT_SYMBOL(__lustre_unpack_msg);
 
 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len)
 {
-        int rc;
-        rc = __lustre_unpack_msg(req->rq_reqmsg, len);
-        if (rc == 1) {
-                lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
-                rc = 0;
-        }
-        return rc;
+       int rc;
+
+       rc = __lustre_unpack_msg(req->rq_reqmsg, len);
+       if (rc == 1) {
+               lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+               rc = 0;
+       }
+       return rc;
 }
 
 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len)
 {
-        int rc;
-        rc = __lustre_unpack_msg(req->rq_repmsg, len);
-        if (rc == 1) {
-                lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
-                rc = 0;
-        }
-        return rc;
+       int rc;
+
+       rc = __lustre_unpack_msg(req->rq_repmsg, len);
+       if (rc == 1) {
+               lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
+               rc = 0;
+       }
+       return rc;
 }
 
 static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
-                                               const int inout, int offset)
+                                              const int inout, int offset)
 {
-        struct ptlrpc_body *pb;
-        struct lustre_msg_v2 *m = inout ? req->rq_reqmsg : req->rq_repmsg;
+       struct ptlrpc_body *pb;
+       struct lustre_msg_v2 *m = inout ? req->rq_reqmsg : req->rq_repmsg;
 
        pb = lustre_msg_buf_v2(m, offset, sizeof(struct ptlrpc_body_v2));
-        if (!pb) {
-                CERROR("error unpacking ptlrpc body\n");
-                return -EFAULT;
-        }
-        if (ptlrpc_buf_need_swab(req, inout, offset)) {
-                lustre_swab_ptlrpc_body(pb);
-                ptlrpc_buf_set_swabbed(req, inout, offset);
-        }
-
-        if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
-                 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
-                 return -EINVAL;
-        }
+       if (!pb) {
+               CERROR("error unpacking ptlrpc body\n");
+               return -EFAULT;
+       }
+       if (ptlrpc_buf_need_swab(req, inout, offset)) {
+               lustre_swab_ptlrpc_body(pb);
+               ptlrpc_buf_set_swabbed(req, inout, offset);
+       }
+
+       if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
+               CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
+               return -EINVAL;
+       }
 
        if (!inout)
                pb->pb_status = ptlrpc_status_ntoh(pb->pb_status);
 
-        return 0;
+       return 0;
 }
 
 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
 {
-        switch (req->rq_reqmsg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
-        default:
-                CERROR("bad lustre msg magic: %08x\n",
-                       req->rq_reqmsg->lm_magic);
-                return -EINVAL;
-        }
+       switch (req->rq_reqmsg->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
+       default:
+               CERROR("bad lustre msg magic: %08x\n",
+                      req->rq_reqmsg->lm_magic);
+               return -EINVAL;
+       }
 }
 
 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
 {
-        switch (req->rq_repmsg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
-        default:
-                CERROR("bad lustre msg magic: %08x\n",
-                       req->rq_repmsg->lm_magic);
-                return -EINVAL;
-        }
+       switch (req->rq_repmsg->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
+       default:
+               CERROR("bad lustre msg magic: %08x\n",
+                      req->rq_repmsg->lm_magic);
+               return -EINVAL;
+       }
 }
 
 static inline __u32 lustre_msg_buflen_v2(struct lustre_msg_v2 *m, __u32 n)
 {
-        if (n >= m->lm_bufcount)
-                return 0;
+       if (n >= m->lm_bufcount)
+               return 0;
 
-        return m->lm_buflens[n];
+       return m->lm_buflens[n];
 }
 
 /**
@@ -743,47 +750,49 @@ static inline __u32 lustre_msg_buflen_v2(struct lustre_msg_v2 *m, __u32 n)
  */
 __u32 lustre_msg_buflen(struct lustre_msg *m, __u32 n)
 {
-        switch (m->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return lustre_msg_buflen_v2(m, n);
-        default:
-                CERROR("incorrect message magic: %08x\n", m->lm_magic);
+       switch (m->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_msg_buflen_v2(m, n);
+       default:
+               CERROR("incorrect message magic: %08x\n", m->lm_magic);
                return 0;
-        }
+       }
 }
 EXPORT_SYMBOL(lustre_msg_buflen);
 
 static inline void
 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, __u32 n, __u32 len)
 {
-        if (n >= m->lm_bufcount)
-                LBUG();
+       if (n >= m->lm_bufcount)
+               LBUG();
 
-        m->lm_buflens[n] = len;
+       m->lm_buflens[n] = len;
 }
 
 void lustre_msg_set_buflen(struct lustre_msg *m, __u32 n, __u32 len)
 {
-        switch (m->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                lustre_msg_set_buflen_v2(m, n, len);
-                return;
-        default:
-                LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
-        }
+       switch (m->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               lustre_msg_set_buflen_v2(m, n, len);
+               return;
+       default:
+               LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
+       }
 }
 
-/* NB return the bufcount for lustre_msg_v2 format, so if message is packed
- * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
+/*
+ * NB return the bufcount for lustre_msg_v2 format, so if message is packed
+ * in V1 format, the result is one bigger. (add struct ptlrpc_body).
+ */
 __u32 lustre_msg_bufcount(struct lustre_msg *m)
 {
-        switch (m->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return m->lm_bufcount;
-        default:
-                CERROR("incorrect message magic: %08x\n", m->lm_magic);
+       switch (m->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return m->lm_bufcount;
+       default:
+               CERROR("incorrect message magic: %08x\n", m->lm_magic);
                return 0;
-        }
+       }
 }
 
 char *lustre_msg_string(struct lustre_msg *m, __u32 index, __u32 max_len)
@@ -792,48 +801,46 @@ char *lustre_msg_string(struct lustre_msg *m, __u32 index, __u32 max_len)
        char *str;
        __u32 slen, blen;
 
-        switch (m->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                str = lustre_msg_buf_v2(m, index, 0);
-                blen = lustre_msg_buflen_v2(m, index);
-                break;
-        default:
-                LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
-        }
-
-        if (str == NULL) {
-                CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
-                return NULL;
-        }
-
-        slen = strnlen(str, blen);
-
-        if (slen == blen) {                     /* not NULL terminated */
-                CERROR("can't unpack non-NULL terminated string in "
-                        "msg %p buffer[%d] len %d\n", m, index, blen);
-                return NULL;
-        }
+       switch (m->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               str = lustre_msg_buf_v2(m, index, 0);
+               blen = lustre_msg_buflen_v2(m, index);
+               break;
+       default:
+               LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
+       }
+
+       if (str == NULL) {
+               CERROR("can't unpack string in msg %p buffer[%d]\n", m, index);
+               return NULL;
+       }
+
+       slen = strnlen(str, blen);
+
+       if (slen == blen) { /* not NULL terminated */
+               CERROR("can't unpack non-NULL terminated string in msg %p buffer[%d] len %d\n",
+                      m, index, blen);
+               return NULL;
+       }
        if (blen > PTLRPC_MAX_BUFLEN) {
                CERROR("buffer length of msg %p buffer[%d] is invalid(%d)\n",
                       m, index, blen);
                return NULL;
        }
 
-        if (max_len == 0) {
-                if (slen != blen - 1) {
-                        CERROR("can't unpack short string in msg %p "
-                               "buffer[%d] len %d: strlen %d\n",
-                               m, index, blen, slen);
-                        return NULL;
-                }
-        } else if (slen > max_len) {
-                CERROR("can't unpack oversized string in msg %p "
-                       "buffer[%d] len %d strlen %d: max %d expected\n",
-                       m, index, blen, slen, max_len);
-                return NULL;
-        }
+       if (max_len == 0) {
+               if (slen != blen - 1) {
+                       CERROR("can't unpack short string in msg %p buffer[%d] len %d: strlen %d\n",
+                              m, index, blen, slen);
+                       return NULL;
+               }
+       } else if (slen > max_len) {
+               CERROR("can't unpack oversized string in msg %p buffer[%d] len %d strlen %d: max %d expected\n",
+                      m, index, blen, slen, max_len);
+               return NULL;
+       }
 
-        return str;
+       return str;
 }
 
 /* Wrap up the normal fixed length cases */
@@ -899,8 +906,10 @@ __u32 lustre_msg_get_flags(struct lustre_msg *msg)
        }
        /* fallthrough */
        default:
-               /* flags might be printed in debug code while message
-                * uninitialized */
+               /*
+                * flags might be printed in debug code while message
+                * uninitialized
+                */
                return 0;
        }
 }
@@ -1168,8 +1177,10 @@ int lustre_msg_get_status(struct lustre_msg *msg)
        }
        /* fallthrough */
        default:
-               /* status might be printed in debug code while message
-               * uninitialized */
+               /*
+                * status might be printed in debug code while message
+                * uninitialized
+                */
                return -EINVAL;
        }
 }
@@ -1276,11 +1287,12 @@ __u32 lustre_msg_get_magic(struct lustre_msg *msg)
        }
 }
 
-__u32 lustre_msg_get_timeout(struct lustre_msg *msg)
+timeout_t lustre_msg_get_timeout(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (pb == NULL) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return 0;
@@ -1293,11 +1305,12 @@ __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
        }
 }
 
-__u32 lustre_msg_get_service_time(struct lustre_msg *msg)
+timeout_t lustre_msg_get_service_timeout(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (pb == NULL) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return 0;
@@ -1363,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:
@@ -1533,11 +1552,13 @@ void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
        }
 }
 
-void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
+void lustre_msg_set_timeout(struct lustre_msg *msg, timeout_t timeout)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
+               LASSERT(timeout >= 0);
                LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_timeout = timeout;
                return;
@@ -1547,13 +1568,16 @@ void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
        }
 }
 
-void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
+void lustre_msg_set_service_timeout(struct lustre_msg *msg,
+                                   timeout_t service_timeout)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
+               LASSERT(service_timeout >= 0);
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
-               pb->pb_service_time = service_time;
+               pb->pb_service_time = service_timeout;
                return;
        }
        default:
@@ -1618,20 +1642,20 @@ void lustre_msg_set_mbits(struct lustre_msg *msg, __u64 mbits)
 
 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
 {
-        int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
+       int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
 
-        req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
-                                         req->rq_pill.rc_area[RCL_SERVER]);
-        if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
-                req->rq_reqmsg->lm_repsize = req->rq_replen;
+       req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
+                                        req->rq_pill.rc_area[RCL_SERVER]);
+       if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
+               req->rq_reqmsg->lm_repsize = req->rq_replen;
 }
 EXPORT_SYMBOL(ptlrpc_request_set_replen);
 
 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
 {
-        req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
-        if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
-                req->rq_reqmsg->lm_repsize = req->rq_replen;
+       req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
+       if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
+               req->rq_reqmsg->lm_repsize = req->rq_replen;
 }
 
 /**
@@ -1645,41 +1669,47 @@ int do_set_info_async(struct obd_import *imp,
                      size_t vallen, void *val,
                      struct ptlrpc_request_set *set)
 {
-        struct ptlrpc_request *req;
-        char                  *tmp;
-        int                    rc;
-        ENTRY;
-
-        req = ptlrpc_request_alloc(imp, &RQF_OBD_SET_INFO);
-        if (req == NULL)
-                RETURN(-ENOMEM);
-
-        req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
-                             RCL_CLIENT, keylen);
-        req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
-                             RCL_CLIENT, vallen);
-        rc = ptlrpc_request_pack(req, version, opcode);
-        if (rc) {
-                ptlrpc_request_free(req);
-                RETURN(rc);
-        }
-
-        tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
-        memcpy(tmp, key, keylen);
-        tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
-        memcpy(tmp, val, vallen);
-
-        ptlrpc_request_set_replen(req);
-
-        if (set) {
-                ptlrpc_set_add_req(set, req);
-                ptlrpc_check_set(NULL, set);
-        } else {
-                rc = ptlrpc_queue_wait(req);
-                ptlrpc_req_finished(req);
-        }
-
-        RETURN(rc);
+       struct ptlrpc_request *req;
+       char *tmp;
+       int rc;
+
+       ENTRY;
+
+       req = ptlrpc_request_alloc(imp, KEY_IS(KEY_CHANGELOG_CLEAR) ?
+                                               &RQF_MDT_SET_INFO :
+                                               &RQF_OBD_SET_INFO);
+       if (req == NULL)
+               RETURN(-ENOMEM);
+
+       req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
+                            RCL_CLIENT, keylen);
+       req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
+                            RCL_CLIENT, vallen);
+       rc = ptlrpc_request_pack(req, version, opcode);
+       if (rc) {
+               ptlrpc_request_free(req);
+               RETURN(rc);
+       }
+
+       if (KEY_IS(KEY_CHANGELOG_CLEAR))
+               do_pack_body(req);
+
+       tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
+       memcpy(tmp, key, keylen);
+       tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
+       memcpy(tmp, val, vallen);
+
+       ptlrpc_request_set_replen(req);
+
+       if (set) {
+               ptlrpc_set_add_req(set, req);
+               ptlrpc_check_set(NULL, set);
+       } else {
+               rc = ptlrpc_queue_wait(req);
+               ptlrpc_req_finished(req);
+       }
+
+       RETURN(rc);
 }
 EXPORT_SYMBOL(do_set_info_async);
 
@@ -1694,8 +1724,8 @@ void lustre_swab_ptlrpc_body(struct ptlrpc_body *body)
        __swab32s(&body->pb_status);
        __swab64s(&body->pb_last_xid);
        __swab16s(&body->pb_tag);
-       CLASSERT(offsetof(typeof(*body), pb_padding0) != 0);
-       CLASSERT(offsetof(typeof(*body), pb_padding1) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*body), pb_padding0) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*body), pb_padding1) == 0);
        __swab64s(&body->pb_last_committed);
        __swab64s(&body->pb_transno);
        __swab32s(&body->pb_flags);
@@ -1710,61 +1740,67 @@ void lustre_swab_ptlrpc_body(struct ptlrpc_body *body)
        __swab64s(&body->pb_pre_versions[2]);
        __swab64s(&body->pb_pre_versions[3]);
        __swab64s(&body->pb_mbits);
-       CLASSERT(offsetof(typeof(*body), pb_padding64_0) != 0);
-       CLASSERT(offsetof(typeof(*body), pb_padding64_1) != 0);
-       CLASSERT(offsetof(typeof(*body), pb_padding64_2) != 0);
-       /* While we need to maintain compatibility between
+       BUILD_BUG_ON(offsetof(typeof(*body), pb_padding64_0) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*body), pb_padding64_1) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*body), pb_padding64_2) == 0);
+       /*
+        * While we need to maintain compatibility between
         * clients and servers without ptlrpc_body_v2 (< 2.3)
         * do not swab any fields beyond pb_jobid, as we are
         * using this swab function for both ptlrpc_body
-        * and ptlrpc_body_v2. */
+        * and ptlrpc_body_v2.
+        */
        /* pb_jobid is an ASCII string and should not be swabbed */
-       CLASSERT(offsetof(typeof(*body), pb_jobid) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*body), pb_jobid) == 0);
 }
 
 void lustre_swab_connect(struct obd_connect_data *ocd)
 {
-        __swab64s(&ocd->ocd_connect_flags);
-        __swab32s(&ocd->ocd_version);
-        __swab32s(&ocd->ocd_grant);
-        __swab64s(&ocd->ocd_ibits_known);
-        __swab32s(&ocd->ocd_index);
-        __swab32s(&ocd->ocd_brw_size);
-        /* ocd_blocksize and ocd_inodespace don't need to be swabbed because
-         * they are 8-byte values */
+       __swab64s(&ocd->ocd_connect_flags);
+       __swab32s(&ocd->ocd_version);
+       __swab32s(&ocd->ocd_grant);
+       __swab64s(&ocd->ocd_ibits_known);
+       __swab32s(&ocd->ocd_index);
+       __swab32s(&ocd->ocd_brw_size);
+       /*
+        * ocd_blocksize and ocd_inodespace don't need to be swabbed because
+        * they are 8-byte values
+        */
        __swab16s(&ocd->ocd_grant_tax_kb);
        __swab32s(&ocd->ocd_grant_max_blks);
-        __swab64s(&ocd->ocd_transno);
-        __swab32s(&ocd->ocd_group);
-        __swab32s(&ocd->ocd_cksum_types);
-        __swab32s(&ocd->ocd_instance);
-        /* Fields after ocd_cksum_types are only accessible by the receiver
-         * if the corresponding flag in ocd_connect_flags is set. Accessing
-         * any field after ocd_maxbytes on the receiver without a valid flag
-         * may result in out-of-bound memory access and kernel oops. */
-        if (ocd->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)
-                __swab32s(&ocd->ocd_max_easize);
-        if (ocd->ocd_connect_flags & OBD_CONNECT_MAXBYTES)
-                __swab64s(&ocd->ocd_maxbytes);
+       __swab64s(&ocd->ocd_transno);
+       __swab32s(&ocd->ocd_group);
+       __swab32s(&ocd->ocd_cksum_types);
+       __swab32s(&ocd->ocd_instance);
+       /*
+        * Fields after ocd_cksum_types are only accessible by the receiver
+        * if the corresponding flag in ocd_connect_flags is set. Accessing
+        * any field after ocd_maxbytes on the receiver without a valid flag
+        * may result in out-of-bound memory access and kernel oops.
+        */
+       if (ocd->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)
+               __swab32s(&ocd->ocd_max_easize);
+       if (ocd->ocd_connect_flags & OBD_CONNECT_MAXBYTES)
+               __swab64s(&ocd->ocd_maxbytes);
        if (ocd->ocd_connect_flags & OBD_CONNECT_MULTIMODRPCS)
                __swab16s(&ocd->ocd_maxmodrpcs);
-       CLASSERT(offsetof(typeof(*ocd), padding0) != 0);
-       CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), padding0) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), padding1) == 0);
        if (ocd->ocd_connect_flags & OBD_CONNECT_FLAGS2)
                __swab64s(&ocd->ocd_connect_flags2);
-        CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
-        CLASSERT(offsetof(typeof(*ocd), padding4) != 0);
-        CLASSERT(offsetof(typeof(*ocd), padding5) != 0);
-        CLASSERT(offsetof(typeof(*ocd), padding6) != 0);
-        CLASSERT(offsetof(typeof(*ocd), padding7) != 0);
-        CLASSERT(offsetof(typeof(*ocd), padding8) != 0);
-        CLASSERT(offsetof(typeof(*ocd), padding9) != 0);
-        CLASSERT(offsetof(typeof(*ocd), paddingA) != 0);
-        CLASSERT(offsetof(typeof(*ocd), paddingB) != 0);
-        CLASSERT(offsetof(typeof(*ocd), paddingC) != 0);
-        CLASSERT(offsetof(typeof(*ocd), paddingD) != 0);
-        CLASSERT(offsetof(typeof(*ocd), paddingE) != 0);
-        CLASSERT(offsetof(typeof(*ocd), paddingF) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), padding3) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), padding4) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), padding5) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), padding6) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), padding7) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), padding8) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), padding9) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), paddingA) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), paddingB) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), paddingC) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), paddingD) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), paddingE) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*ocd), paddingF) == 0);
 }
 
 static void lustre_swab_ost_layout(struct ost_layout *ol)
@@ -1776,7 +1812,7 @@ static void lustre_swab_ost_layout(struct ost_layout *ol)
        __swab32s(&ol->ol_comp_id);
 }
 
-void lustre_swab_obdo (struct obdo  *o)
+void lustre_swab_obdo(struct obdo *o)
 {
        __swab64s(&o->o_valid);
        lustre_swab_ost_id(&o->o_oi);
@@ -1804,14 +1840,14 @@ void lustre_swab_obdo (struct obdo  *o)
        __swab32s(&o->o_gid_h);
        __swab64s(&o->o_data_version);
        __swab32s(&o->o_projid);
-       CLASSERT(offsetof(typeof(*o), o_padding_4) != 0);
-       CLASSERT(offsetof(typeof(*o), o_padding_5) != 0);
-       CLASSERT(offsetof(typeof(*o), o_padding_6) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*o), o_padding_4) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*o), o_padding_5) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*o), o_padding_6) == 0);
 
 }
 EXPORT_SYMBOL(lustre_swab_obdo);
 
-void lustre_swab_obd_statfs (struct obd_statfs *os)
+void lustre_swab_obd_statfs(struct obd_statfs *os)
 {
        __swab64s(&os->os_type);
        __swab64s(&os->os_blocks);
@@ -1826,13 +1862,13 @@ void lustre_swab_obd_statfs (struct obd_statfs *os)
        __swab32s(&os->os_state);
        __swab32s(&os->os_fprecreated);
        __swab32s(&os->os_granted);
-       CLASSERT(offsetof(typeof(*os), os_spare3) != 0);
-       CLASSERT(offsetof(typeof(*os), os_spare4) != 0);
-       CLASSERT(offsetof(typeof(*os), os_spare5) != 0);
-       CLASSERT(offsetof(typeof(*os), os_spare6) != 0);
-       CLASSERT(offsetof(typeof(*os), os_spare7) != 0);
-       CLASSERT(offsetof(typeof(*os), os_spare8) != 0);
-       CLASSERT(offsetof(typeof(*os), os_spare9) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*os), os_spare3) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*os), os_spare4) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*os), os_spare5) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*os), os_spare6) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*os), os_spare7) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*os), os_spare8) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*os), os_spare9) == 0);
 }
 
 void lustre_swab_obd_ioobj(struct obd_ioobj *ioo)
@@ -1849,19 +1885,19 @@ void lustre_swab_niobuf_remote(struct niobuf_remote *nbr)
        __swab32s(&nbr->rnb_flags);
 }
 
-void lustre_swab_ost_body (struct ost_body *b)
+void lustre_swab_ost_body(struct ost_body *b)
 {
-        lustre_swab_obdo (&b->oa);
+       lustre_swab_obdo(&b->oa);
 }
 
 void lustre_swab_ost_last_id(u64 *id)
 {
-        __swab64s(id);
+       __swab64s(id);
 }
 
 void lustre_swab_generic_32s(__u32 *val)
 {
-        __swab32s(val);
+       __swab32s(val);
 }
 
 void lustre_swab_gl_lquota_desc(struct ldlm_gl_lquota_desc *desc)
@@ -1872,7 +1908,7 @@ void lustre_swab_gl_lquota_desc(struct ldlm_gl_lquota_desc *desc)
        __swab64s(&desc->gl_hardlimit);
        __swab64s(&desc->gl_softlimit);
        __swab64s(&desc->gl_time);
-       CLASSERT(offsetof(typeof(*desc), gl_pad2) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*desc), gl_pad2) == 0);
 }
 EXPORT_SYMBOL(lustre_swab_gl_lquota_desc);
 
@@ -1880,7 +1916,7 @@ void lustre_swab_gl_barrier_desc(struct ldlm_gl_barrier_desc *desc)
 {
        __swab32s(&desc->lgbd_status);
        __swab32s(&desc->lgbd_timeout);
-       CLASSERT(offsetof(typeof(*desc), lgbd_padding) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*desc), lgbd_padding) == 0);
 }
 EXPORT_SYMBOL(lustre_swab_gl_barrier_desc);
 
@@ -1922,11 +1958,11 @@ void lustre_swab_barrier_lvb(struct barrier_lvb *lvb)
 {
        __swab32s(&lvb->lvb_status);
        __swab32s(&lvb->lvb_index);
-       CLASSERT(offsetof(typeof(*lvb), lvb_padding) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*lvb), lvb_padding) == 0);
 }
 EXPORT_SYMBOL(lustre_swab_barrier_lvb);
 
-void lustre_swab_mdt_body (struct mdt_body *b)
+void lustre_swab_mdt_body(struct mdt_body *b)
 {
        lustre_swab_lu_fid(&b->mbo_fid1);
        lustre_swab_lu_fid(&b->mbo_fid2);
@@ -1953,23 +1989,23 @@ void lustre_swab_mdt_body (struct mdt_body *b)
        __swab32s(&b->mbo_eadatasize);
        __swab32s(&b->mbo_aclsize);
        __swab32s(&b->mbo_max_mdsize);
-       CLASSERT(offsetof(typeof(*b), mbo_unused3) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*b), mbo_unused3) == 0);
        __swab32s(&b->mbo_uid_h);
        __swab32s(&b->mbo_gid_h);
        __swab32s(&b->mbo_projid);
        __swab64s(&b->mbo_dom_size);
        __swab64s(&b->mbo_dom_blocks);
-       CLASSERT(offsetof(typeof(*b), mbo_padding_8) != 0);
-       CLASSERT(offsetof(typeof(*b), mbo_padding_9) != 0);
-       CLASSERT(offsetof(typeof(*b), mbo_padding_10) != 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);
 }
 
 void lustre_swab_mdt_ioepoch(struct mdt_ioepoch *b)
 {
        /* mio_open_handle is opaque */
-       CLASSERT(offsetof(typeof(*b), mio_unused1) != 0);
-       CLASSERT(offsetof(typeof(*b), mio_unused2) != 0);
-       CLASSERT(offsetof(typeof(*b), mio_padding) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*b), mio_unused1) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*b), mio_unused2) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*b), mio_padding) == 0);
 }
 
 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
@@ -1982,7 +2018,7 @@ void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
        __swab32s(&mti->mti_flags);
        __swab32s(&mti->mti_instance);
        __swab32s(&mti->mti_nid_count);
-       CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
+       BUILD_BUG_ON(sizeof(lnet_nid_t) != sizeof(__u64));
        for (i = 0; i < MTI_NIDS_MAX; i++)
                __swab64s(&mti->mti_nids[i]);
 }
@@ -1998,13 +2034,13 @@ void lustre_swab_mgs_nidtbl_entry(struct mgs_nidtbl_entry *entry)
 
        /* mne_nid_(count|type) must be one byte size because we're gonna
         * access it w/o swapping. */
-       CLASSERT(sizeof(entry->mne_nid_count) == sizeof(__u8));
-       CLASSERT(sizeof(entry->mne_nid_type) == sizeof(__u8));
+       BUILD_BUG_ON(sizeof(entry->mne_nid_count) != sizeof(__u8));
+       BUILD_BUG_ON(sizeof(entry->mne_nid_type) != sizeof(__u8));
 
        /* remove this assertion if ipv6 is supported. */
        LASSERT(entry->mne_nid_type == 0);
        for (i = 0; i < entry->mne_nid_count; i++) {
-               CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
+               BUILD_BUG_ON(sizeof(lnet_nid_t) != sizeof(__u64));
                __swab64s(&entry->u.nids[i]);
        }
 }
@@ -2012,65 +2048,70 @@ EXPORT_SYMBOL(lustre_swab_mgs_nidtbl_entry);
 
 void lustre_swab_mgs_config_body(struct mgs_config_body *body)
 {
-        __swab64s(&body->mcb_offset);
-        __swab32s(&body->mcb_units);
-        __swab16s(&body->mcb_type);
+       __swab64s(&body->mcb_offset);
+       __swab32s(&body->mcb_units);
+       __swab16s(&body->mcb_type);
 }
 
 void lustre_swab_mgs_config_res(struct mgs_config_res *body)
 {
-        __swab64s(&body->mcr_offset);
-        __swab64s(&body->mcr_size);
+       __swab64s(&body->mcr_offset);
+       __swab64s(&body->mcr_size);
 }
 
-static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
+static void lustre_swab_obd_dqinfo(struct obd_dqinfo *i)
 {
-        __swab64s (&i->dqi_bgrace);
-        __swab64s (&i->dqi_igrace);
-        __swab32s (&i->dqi_flags);
-        __swab32s (&i->dqi_valid);
+       __swab64s(&i->dqi_bgrace);
+       __swab64s(&i->dqi_igrace);
+       __swab32s(&i->dqi_flags);
+       __swab32s(&i->dqi_valid);
 }
 
-static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
+static void lustre_swab_obd_dqblk(struct obd_dqblk *b)
 {
-        __swab64s (&b->dqb_ihardlimit);
-        __swab64s (&b->dqb_isoftlimit);
-        __swab64s (&b->dqb_curinodes);
-        __swab64s (&b->dqb_bhardlimit);
-        __swab64s (&b->dqb_bsoftlimit);
-        __swab64s (&b->dqb_curspace);
-        __swab64s (&b->dqb_btime);
-        __swab64s (&b->dqb_itime);
-        __swab32s (&b->dqb_valid);
-        CLASSERT(offsetof(typeof(*b), dqb_padding) != 0);
+       __swab64s(&b->dqb_ihardlimit);
+       __swab64s(&b->dqb_isoftlimit);
+       __swab64s(&b->dqb_curinodes);
+       __swab64s(&b->dqb_bhardlimit);
+       __swab64s(&b->dqb_bsoftlimit);
+       __swab64s(&b->dqb_curspace);
+       __swab64s(&b->dqb_btime);
+       __swab64s(&b->dqb_itime);
+       __swab32s(&b->dqb_valid);
+       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)
 {
-        __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);
+       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)
 {
-        lustre_swab_lu_fid(&gf->gf_fid);
-        __swab64s(&gf->gf_recno);
-        __swab32s(&gf->gf_linkno);
-        __swab32s(&gf->gf_pathlen);
+       lustre_swab_lu_fid(&gf->gf_fid);
+       __swab64s(&gf->gf_recno);
+       __swab32s(&gf->gf_linkno);
+       __swab32s(&gf->gf_pathlen);
 }
 EXPORT_SYMBOL(lustre_swab_fid2path);
 
 static void lustre_swab_fiemap_extent(struct fiemap_extent *fm_extent)
 {
-        __swab64s(&fm_extent->fe_logical);
-        __swab64s(&fm_extent->fe_physical);
-        __swab64s(&fm_extent->fe_length);
-        __swab32s(&fm_extent->fe_flags);
-        __swab32s(&fm_extent->fe_device);
+       __swab64s(&fm_extent->fe_logical);
+       __swab64s(&fm_extent->fe_physical);
+       __swab64s(&fm_extent->fe_length);
+       __swab32s(&fm_extent->fe_flags);
+       __swab32s(&fm_extent->fe_device);
 }
 
 static void lustre_swab_fiemap_hdr(struct fiemap *fiemap)
@@ -2083,14 +2124,25 @@ static void lustre_swab_fiemap_hdr(struct fiemap *fiemap)
        __swab32s(&fiemap->fm_reserved);
 }
 
-void lustre_swab_fiemap(struct fiemap *fiemap)
+int lustre_swab_fiemap(struct fiemap *fiemap, __u32 len)
 {
-       __u32 i;
+       __u32 i, size, count;
 
        lustre_swab_fiemap_hdr(fiemap);
 
-        for (i = 0; i < fiemap->fm_mapped_extents; i++)
-                lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
+       size = fiemap_count_to_size(fiemap->fm_mapped_extents);
+       count = fiemap->fm_mapped_extents;
+       if (unlikely(size > len)) {
+               count = (len - sizeof(struct fiemap)) /
+                       sizeof(struct fiemap_extent);
+               fiemap->fm_mapped_extents = count;
+               size = -EOVERFLOW;
+       }
+       /* still swab extents as we cannot yet pass rc to callers */
+       for (i = 0; i < count; i++)
+               lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
+
+       return size;
 }
 
 void lustre_swab_fiemap_info_key(struct ll_fiemap_info_key *fiemap_info)
@@ -2148,31 +2200,31 @@ void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
        __swab32s(&rr->rr_umask);
        __swab16s(&rr->rr_mirror_id);
 
-       CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*rr), rr_padding_4) == 0);
 };
 
-void lustre_swab_lov_desc (struct lov_desc *ld)
+void lustre_swab_lov_desc(struct lov_desc *ld)
 {
-        __swab32s (&ld->ld_tgt_count);
-        __swab32s (&ld->ld_active_tgt_count);
-        __swab32s (&ld->ld_default_stripe_count);
-        __swab32s (&ld->ld_pattern);
-        __swab64s (&ld->ld_default_stripe_size);
-        __swab64s (&ld->ld_default_stripe_offset);
-        __swab32s (&ld->ld_qos_maxage);
-        /* uuid endian insensitive */
+       __swab32s(&ld->ld_tgt_count);
+       __swab32s(&ld->ld_active_tgt_count);
+       __swab32s(&ld->ld_default_stripe_count);
+       __swab32s(&ld->ld_pattern);
+       __swab64s(&ld->ld_default_stripe_size);
+       __swab64s(&ld->ld_default_stripe_offset);
+       __swab32s(&ld->ld_qos_maxage);
+       /* uuid endian insensitive */
 }
 EXPORT_SYMBOL(lustre_swab_lov_desc);
 
-void lustre_swab_lmv_desc (struct lmv_desc *ld)
+void lustre_swab_lmv_desc(struct lmv_desc *ld)
 {
-        __swab32s (&ld->ld_tgt_count);
-        __swab32s (&ld->ld_active_tgt_count);
-        __swab32s (&ld->ld_default_stripe_count);
-        __swab32s (&ld->ld_pattern);
-        __swab64s (&ld->ld_default_hash_size);
-        __swab32s (&ld->ld_qos_maxage);
-        /* uuid endian insensitive */
+       __swab32s(&ld->ld_tgt_count);
+       __swab32s(&ld->ld_active_tgt_count);
+       __swab32s(&ld->ld_default_stripe_count);
+       __swab32s(&ld->ld_pattern);
+       __swab64s(&ld->ld_default_hash_size);
+       __swab32s(&ld->ld_qos_maxage);
+       /* uuid endian insensitive */
 }
 
 /* This structure is always in little-endian */
@@ -2230,7 +2282,7 @@ void lustre_swab_lmv_user_md(struct lmv_user_md *lum)
        __swab32s(&lum->lum_stripe_offset);
        __swab32s(&lum->lum_hash_type);
        __swab32s(&lum->lum_type);
-       CLASSERT(offsetof(typeof(*lum), lum_padding1) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*lum), lum_padding1) == 0);
        switch (lum->lum_magic) {
        case LMV_USER_MAGIC_SPECIFIC:
                count = lum->lum_stripe_count;
@@ -2346,20 +2398,20 @@ static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
 
 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
 {
-        ENTRY;
-        CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
-        lustre_swab_lov_user_md_common(lum);
-        EXIT;
+       ENTRY;
+       CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
+       lustre_swab_lov_user_md_common(lum);
+       EXIT;
 }
 EXPORT_SYMBOL(lustre_swab_lov_user_md_v1);
 
 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum)
 {
-        ENTRY;
-        CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
-        lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
-        /* lmm_pool_name nothing to do with char */
-        EXIT;
+       ENTRY;
+       CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
+       lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
+       /* lmm_pool_name nothing to do with char */
+       EXIT;
 }
 EXPORT_SYMBOL(lustre_swab_lov_user_md_v3);
 
@@ -2386,8 +2438,8 @@ void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum)
        __swab16s(&lum->lcm_flags);
        __swab16s(&lum->lcm_entry_count);
        __swab16s(&lum->lcm_mirror_count);
-       CLASSERT(offsetof(typeof(*lum), lcm_padding1) != 0);
-       CLASSERT(offsetof(typeof(*lum), lcm_padding2) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*lum), lcm_padding1) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*lum), lcm_padding2) == 0);
 
        for (i = 0; i < ent_count; i++) {
                ent = &lum->lcm_entries[i];
@@ -2406,7 +2458,7 @@ void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum)
                __swab32s(&ent->lcme_offset);
                __swab32s(&ent->lcme_size);
                __swab32s(&ent->lcme_layout_gen);
-               CLASSERT(offsetof(typeof(*ent), lcme_padding_1) != 0);
+               BUILD_BUG_ON(offsetof(typeof(*ent), lcme_padding_1) == 0);
 
                v1 = (struct lov_user_md_v1 *)((char *)lum + off);
                stripe_count = v1->lmm_stripe_count;
@@ -2436,16 +2488,17 @@ void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum)
 EXPORT_SYMBOL(lustre_swab_lov_comp_md_v1);
 
 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
-                                     int stripe_count)
+                                    int stripe_count)
 {
-        int i;
-        ENTRY;
-        for (i = 0; i < stripe_count; i++) {
-                lustre_swab_ost_id(&(lod[i].l_ost_oi));
-                __swab32s(&(lod[i].l_ost_gen));
-                __swab32s(&(lod[i].l_ost_idx));
-        }
-        EXIT;
+       int i;
+
+       ENTRY;
+       for (i = 0; i < stripe_count; i++) {
+               lustre_swab_ost_id(&(lod[i].l_ost_oi));
+               __swab32s(&(lod[i].l_ost_gen));
+               __swab32s(&(lod[i].l_ost_idx));
+       }
+       EXIT;
 }
 EXPORT_SYMBOL(lustre_swab_lov_user_md_objects);
 
@@ -2537,19 +2590,20 @@ void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
 }
 EXPORT_SYMBOL(lustre_swab_lov_mds_md);
 
-void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
+void lustre_swab_ldlm_res_id(struct ldlm_res_id *id)
 {
-        int  i;
+       int i;
 
-        for (i = 0; i < RES_NAME_SIZE; i++)
-                __swab64s (&id->name[i]);
+       for (i = 0; i < RES_NAME_SIZE; i++)
+               __swab64s(&id->name[i]);
 }
 
 void lustre_swab_ldlm_policy_data(union ldlm_wire_policy_data *d)
 {
        /* the lock data is a union and the first two fields are always an
         * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
-        * data the same way. */
+        * data the same way.
+        */
        __swab64s(&d->l_extent.start);
        __swab64s(&d->l_extent.end);
        __swab64s(&d->l_extent.gid);
@@ -2557,7 +2611,7 @@ void lustre_swab_ldlm_policy_data(union ldlm_wire_policy_data *d)
        __swab32s(&d->l_flock.lfw_pid);
 }
 
-void lustre_swab_ldlm_intent (struct ldlm_intent *i)
+void lustre_swab_ldlm_intent(struct ldlm_intent *i)
 {
        __swab64s(&i->opc);
 }
@@ -2565,34 +2619,34 @@ void lustre_swab_ldlm_intent (struct ldlm_intent *i)
 void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r)
 {
        __swab32s(&r->lr_type);
-       CLASSERT(offsetof(typeof(*r), lr_pad) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*r), lr_pad) == 0);
        lustre_swab_ldlm_res_id(&r->lr_name);
 }
 
-void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
+void lustre_swab_ldlm_lock_desc(struct ldlm_lock_desc *l)
 {
-        lustre_swab_ldlm_resource_desc (&l->l_resource);
-        __swab32s (&l->l_req_mode);
-        __swab32s (&l->l_granted_mode);
-        lustre_swab_ldlm_policy_data (&l->l_policy_data);
+       lustre_swab_ldlm_resource_desc(&l->l_resource);
+       __swab32s(&l->l_req_mode);
+       __swab32s(&l->l_granted_mode);
+       lustre_swab_ldlm_policy_data(&l->l_policy_data);
 }
 
-void lustre_swab_ldlm_request (struct ldlm_request *rq)
+void lustre_swab_ldlm_request(struct ldlm_request *rq)
 {
-        __swab32s (&rq->lock_flags);
-        lustre_swab_ldlm_lock_desc (&rq->lock_desc);
-        __swab32s (&rq->lock_count);
-        /* lock_handle[] opaque */
+       __swab32s(&rq->lock_flags);
+       lustre_swab_ldlm_lock_desc(&rq->lock_desc);
+       __swab32s(&rq->lock_count);
+       /* lock_handle[] opaque */
 }
 
-void lustre_swab_ldlm_reply (struct ldlm_reply *r)
+void lustre_swab_ldlm_reply(struct ldlm_reply *r)
 {
-        __swab32s (&r->lock_flags);
-        CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
-        lustre_swab_ldlm_lock_desc (&r->lock_desc);
-        /* lock_handle opaque */
-        __swab64s (&r->lock_policy_res1);
-        __swab64s (&r->lock_policy_res2);
+       __swab32s(&r->lock_flags);
+       BUILD_BUG_ON(offsetof(typeof(*r), lock_padding) == 0);
+       lustre_swab_ldlm_lock_desc(&r->lock_desc);
+       /* lock_handle opaque */
+       __swab64s(&r->lock_policy_res1);
+       __swab64s(&r->lock_policy_res2);
 }
 
 void lustre_swab_quota_body(struct quota_body *b)
@@ -2679,26 +2733,26 @@ void dump_obdo(struct obdo *oa)
 
 void dump_ost_body(struct ost_body *ob)
 {
-        dump_obdo(&ob->oa);
+       dump_obdo(&ob->oa);
 }
 
 void dump_rcs(__u32 *rc)
 {
-        CDEBUG(D_RPCTRACE, "rmf_rcs: %d\n", *rc);
+       CDEBUG(D_RPCTRACE, "rmf_rcs: %d\n", *rc);
 }
 
 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
 {
-        LASSERT(req->rq_reqmsg);
+       LASSERT(req->rq_reqmsg);
 
-        switch (req->rq_reqmsg->lm_magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
-        default:
-                CERROR("bad lustre msg magic: %#08X\n",
-                       req->rq_reqmsg->lm_magic);
-        }
-        return 0;
+       switch (req->rq_reqmsg->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
+       default:
+               CERROR("bad lustre msg magic: %#08X\n",
+                      req->rq_reqmsg->lm_magic);
+       }
+       return 0;
 }
 
 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
@@ -2775,25 +2829,6 @@ void _debug_req(struct ptlrpc_request *req,
 }
 EXPORT_SYMBOL(_debug_req);
 
-void lustre_swab_lustre_capa(struct lustre_capa *c)
-{
-        lustre_swab_lu_fid(&c->lc_fid);
-        __swab64s (&c->lc_opc);
-        __swab64s (&c->lc_uid);
-        __swab64s (&c->lc_gid);
-        __swab32s (&c->lc_flags);
-        __swab32s (&c->lc_keyid);
-        __swab32s (&c->lc_timeout);
-        __swab32s (&c->lc_expiry);
-}
-
-void lustre_swab_lustre_capa_key(struct lustre_capa_key *k)
-{
-        __swab64s (&k->lk_seq);
-        __swab32s (&k->lk_keyid);
-        CLASSERT(offsetof(typeof(*k), lk_padding) != 0);
-}
-
 void lustre_swab_hsm_user_state(struct hsm_user_state *state)
 {
        __swab32s(&state->hus_states);
@@ -2881,20 +2916,37 @@ void lustre_swab_object_update(struct object_update *ou)
        }
 }
 
-void lustre_swab_object_update_request(struct object_update_request *our)
+int lustre_swab_object_update_request(struct object_update_request *our,
+                                     __u32 len)
 {
-       size_t i;
+       __u32 i, size = 0;
+       struct object_update *ou;
+
        __swab32s(&our->ourq_magic);
        __swab16s(&our->ourq_count);
        __swab16s(&our->ourq_padding);
-       for (i = 0; i < our->ourq_count; i++) {
-               struct object_update *ou;
 
+       /* 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);
-               if (ou == NULL)
-                       return;
                lustre_swab_object_update(ou);
        }
+
+       return size;
 }
 
 void lustre_swab_object_update_result(struct object_update_result *our)
@@ -2904,22 +2956,30 @@ void lustre_swab_object_update_result(struct object_update_result *our)
        __swab16s(&our->our_padding);
 }
 
-void lustre_swab_object_update_reply(struct object_update_reply *our)
+int lustre_swab_object_update_reply(struct object_update_reply *our, __u32 len)
 {
-       size_t i;
+       __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;
+                       return -EPROTO;
                lustre_swab_object_update_result(ourp);
        }
+
+       return size;
 }
 
 void lustre_swab_out_update_header(struct out_update_header *ouh)
@@ -2977,16 +3037,16 @@ void lustre_swab_lfsck_request(struct lfsck_request *lr)
        lustre_swab_lu_fid(&lr->lr_fid);
        lustre_swab_lu_fid(&lr->lr_fid2);
        __swab32s(&lr->lr_comp_id);
-       CLASSERT(offsetof(typeof(*lr), lr_padding_0) != 0);
-       CLASSERT(offsetof(typeof(*lr), lr_padding_1) != 0);
-       CLASSERT(offsetof(typeof(*lr), lr_padding_2) != 0);
-       CLASSERT(offsetof(typeof(*lr), lr_padding_3) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_0) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_1) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_2) == 0);
+       BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_3) == 0);
 }
 
 void lustre_swab_lfsck_reply(struct lfsck_reply *lr)
 {
        __swab32s(&lr->lr_status);
-       CLASSERT(offsetof(typeof(*lr), lr_padding_1) != 0);
+       BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_1) == 0);
        __swab64s(&lr->lr_repaired);
 }
 
@@ -3009,7 +3069,7 @@ void lustre_swab_orphan_ent_v2(struct lu_orphan_ent_v2 *ent)
        lustre_swab_lu_fid(&ent->loe_key);
        lustre_swab_orphan_rec(&ent->loe_rec.lor_rec);
        lustre_swab_ost_layout(&ent->loe_rec.lor_layout);
-       CLASSERT(offsetof(typeof(ent->loe_rec), lor_padding) != 0);
+       BUILD_BUG_ON(offsetof(typeof(ent->loe_rec), lor_padding) == 0);
 }
 EXPORT_SYMBOL(lustre_swab_orphan_ent_v2);
 
@@ -3020,8 +3080,8 @@ void lustre_swab_orphan_ent_v3(struct lu_orphan_ent_v3 *ent)
        lustre_swab_ost_layout(&ent->loe_rec.lor_layout);
        __swab32s(&ent->loe_rec.lor_layout_version);
        __swab32s(&ent->loe_rec.lor_range);
-       CLASSERT(offsetof(typeof(ent->loe_rec), lor_padding_1) != 0);
-       CLASSERT(offsetof(typeof(ent->loe_rec), lor_padding_2) != 0);
+       BUILD_BUG_ON(offsetof(typeof(ent->loe_rec), lor_padding_1) == 0);
+       BUILD_BUG_ON(offsetof(typeof(ent->loe_rec), lor_padding_2) == 0);
 }
 EXPORT_SYMBOL(lustre_swab_orphan_ent_v3);