Whamcloud - gitweb
LU-14291 ptlrpc: format UPDATE messages in server-only code
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
index 21163e6..e4bacc2 100644 (file)
@@ -40,6 +40,8 @@
 
 #define DEBUG_SUBSYSTEM S_RPC
 
+#include <linux/crc32.h>
+
 #include <libcfs/libcfs.h>
 
 #include <llog_swab.h>
 #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)
 {
-        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)
 {
-        switch (magic) {
-        case LUSTRE_MSG_MAGIC_V2:
-                return lustre_msg_hdr_size_v2(count);
-        default:
-                LASSERTF(0, "incorrect message magic: %08x\n", magic);
+       LASSERT(count > 0);
+
+       switch (magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_msg_hdr_size_v2(count);
+       default:
+               LASSERTF(0, "incorrect message magic: %08x\n", magic);
                return 0;
-        }
+       }
 }
 
 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,
@@ -116,91 +118,88 @@ int lustre_msg_check_version(struct lustre_msg *msg,
 /* early reply size */
 __u32 lustre_msg_early_size()
 {
-       static __u32 size;
-       if (!size) {
-               /* Always reply old ptlrpc_body_v2 to keep interoprability
-                * with the old client (< 2.3) which doesn't have pb_jobid
-                * in the ptlrpc_body.
-                *
-                * XXX Remove this whenever we dorp interoprability with such
-                *     client.
-                */
-               __u32 pblen = sizeof(struct ptlrpc_body_v2);
-               size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, &pblen);
-       }
-       return size;
+       __u32 pblen = sizeof(struct ptlrpc_body);
+
+       return lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, &pblen);
 }
 EXPORT_SYMBOL(lustre_msg_early_size);
 
 __u32 lustre_msg_size_v2(int count, __u32 *lengths)
 {
        __u32 size;
-        int i;
+       int i;
 
-        size = lustre_msg_hdr_size_v2(count);
-        for (i = 0; i < count; i++)
-                size += cfs_size_round(lengths[i]);
+       LASSERT(count > 0);
+       size = lustre_msg_hdr_size_v2(count);
+       for (i = 0; i < count; i++)
+               size += cfs_size_round(lengths[i]);
 
-        return size;
+       return size;
 }
 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);
 
 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
-                        char **bufs)
+                       char **bufs)
 {
-        char *ptr;
-        int i;
+       char *ptr;
+       int i;
+
+       LASSERT(count > 0);
 
-        msg->lm_bufcount = count;
-        /* XXX: lm_secflvr uninitialized here */
-        msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
+       msg->lm_bufcount = count;
+       /* XXX: lm_secflvr uninitialized here */
+       msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
 
-        for (i = 0; i < count; i++)
-                msg->lm_buflens[i] = lens[i];
+       for (i = 0; i < count; i++)
+               msg->lm_buflens[i] = lens[i];
 
-        if (bufs == NULL)
-                return;
+       if (bufs == NULL)
+               return;
 
        ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
        for (i = 0; i < count; i++) {
@@ -214,46 +213,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
@@ -288,16 +287,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);
        }
@@ -327,27 +325,28 @@ void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
 }
 
 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
-                         __u32 *lens, char **bufs, int flags)
+                        __u32 *lens, char **bufs, int flags)
 {
-        struct ptlrpc_reply_state *rs;
-        int                        msg_len, rc;
-        ENTRY;
+       struct ptlrpc_reply_state *rs;
+       int msg_len, rc;
+       ENTRY;
 
-        LASSERT(req->rq_reply_state == NULL);
+       LASSERT(req->rq_reply_state == NULL);
+       LASSERT(count > 0);
 
-        if ((flags & LPRFL_EARLY_REPLY) == 0) {
+       if ((flags & LPRFL_EARLY_REPLY) == 0) {
                spin_lock(&req->rq_lock);
                req->rq_packed_final = 1;
                spin_unlock(&req->rq_lock);
-        }
+       }
 
-        msg_len = lustre_msg_size_v2(count, lens);
-        rc = sptlrpc_svc_alloc_rs(req, msg_len);
-        if (rc)
-                RETURN(rc);
+       msg_len = lustre_msg_size_v2(count, lens);
+       rc = sptlrpc_svc_alloc_rs(req, msg_len);
+       if (rc)
+               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;
@@ -356,52 +355,52 @@ int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
        INIT_LIST_HEAD(&rs->rs_list);
        spin_lock_init(&rs->rs_lock);
 
-        req->rq_replen = msg_len;
-        req->rq_reply_state = rs;
-        req->rq_repmsg = rs->rs_msg;
+       req->rq_replen = msg_len;
+       req->rq_reply_state = rs;
+       req->rq_repmsg = rs->rs_msg;
 
-        lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
-        lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
+       lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
+       lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
 
-        PTLRPC_RS_DEBUG_LRU_ADD(rs);
+       PTLRPC_RS_DEBUG_LRU_ADD(rs);
 
-        RETURN(0);
+       RETURN(0);
 }
 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);
 
@@ -409,28 +408,29 @@ void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, __u32 n, __u32 min_size)
 {
        __u32 i, offset, buflen, bufcount;
 
-        LASSERT(m != NULL);
+       LASSERT(m != NULL);
+       LASSERT(m->lm_bufcount > 0);
 
-        bufcount = m->lm_bufcount;
-        if (unlikely(n >= bufcount)) {
-                CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
-                       m, n, bufcount);
-                return NULL;
-        }
+       bufcount = m->lm_bufcount;
+       if (unlikely(n >= bufcount)) {
+               CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
+                      m, n, bufcount);
+               return NULL;
+       }
 
-        buflen = m->lm_buflens[n];
-        if (unlikely(buflen < min_size)) {
-                CERROR("msg %p buffer[%d] size %d too small "
-                       "(required %d, opc=%d)\n", m, n, buflen, min_size,
-                       n == MSG_PTLRPC_BODY_OFF ? -1 : lustre_msg_get_opc(m));
-                return NULL;
-        }
+       buflen = m->lm_buflens[n];
+       if (unlikely(buflen < min_size)) {
+               CERROR("msg %p buffer[%d] size %d too small "
+                      "(required %d, opc=%d)\n", m, n, buflen, min_size,
+                      n == MSG_PTLRPC_BODY_OFF ? -1 : lustre_msg_get_opc(m));
+               return NULL;
+       }
 
-        offset = lustre_msg_hdr_size_v2(bufcount);
-        for (i = 0; i < n; i++)
-                offset += cfs_size_round(m->lm_buflens[i]);
+       offset = lustre_msg_hdr_size_v2(bufcount);
+       for (i = 0; i < n; i++)
+               offset += cfs_size_round(m->lm_buflens[i]);
 
-        return (char *)m + offset;
+       return (char *)m + offset;
 }
 
 void *lustre_msg_buf(struct lustre_msg *m, __u32 n, __u32 min_size)
@@ -449,32 +449,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);
 }
 
 /*
@@ -494,17 +494,68 @@ 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);
 
+static int lustre_grow_msg_v2(struct lustre_msg_v2 *msg, __u32 segment,
+                             unsigned int newlen)
+{
+       char *tail = NULL, *newpos;
+       int tail_len = 0, n;
+
+       LASSERT(msg);
+       LASSERT(msg->lm_bufcount > segment);
+       LASSERT(msg->lm_buflens[segment] <= newlen);
+
+       if (msg->lm_buflens[segment] == newlen)
+               goto out;
+
+       if (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;
+
+       if (tail && tail_len) {
+               newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
+               memmove(newpos, tail, tail_len);
+       }
+out:
+       return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
+}
+
+/*
+ * for @msg, grow @segment to size @newlen.
+ * Always move higher buffer forward.
+ *
+ * return new msg size after growing.
+ *
+ * CAUTION:
+ * - caller must make sure there is enough space in allocated message buffer
+ * - caller should NOT keep pointers to msg buffers which higher than @segment
+ *   after call shrink.
+ */
+int lustre_grow_msg(struct lustre_msg *msg, int segment, unsigned int newlen)
+{
+       switch (msg->lm_magic) {
+       case LUSTRE_MSG_MAGIC_V2:
+               return lustre_grow_msg_v2(msg, segment, newlen);
+       default:
+               LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
+       }
+}
+EXPORT_SYMBOL(lustre_grow_msg);
+
 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
 {
        PTLRPC_RS_DEBUG_LRU_DEL(rs);
@@ -523,159 +574,169 @@ void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
 
 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
 {
-        int swabbed, required_len, i;
-
-        /* Now we know the sender speaks my language. */
-        required_len = lustre_msg_hdr_size_v2(0);
-        if (len < required_len) {
-                /* can't even look inside the message */
-                CERROR("message length %d too small for lustre_msg\n", len);
-                return -EINVAL;
-        }
-
-        swabbed = (m->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
-
-        if (swabbed) {
-                __swab32s(&m->lm_magic);
-                __swab32s(&m->lm_bufcount);
-                __swab32s(&m->lm_secflvr);
-                __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);
-        }
-
-        required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
-        if (len < required_len) {
-                /* didn't receive all the buffer lengths */
-                CERROR ("message length %d too small for %d buflens\n",
-                        len, m->lm_bufcount);
-                return -EINVAL;
-        }
-
-        for (i = 0; i < m->lm_bufcount; i++) {
-                if (swabbed)
-                        __swab32s(&m->lm_buflens[i]);
-                required_len += cfs_size_round(m->lm_buflens[i]);
-        }
-
-        if (len < required_len) {
-                CERROR("len: %d, required_len %d\n", len, required_len);
-                CERROR("bufcount: %d\n", m->lm_bufcount);
-                for (i = 0; i < m->lm_bufcount; i++)
-                        CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
-                return -EINVAL;
-        }
-
-        return swabbed;
+       int swabbed, required_len, i, buflen;
+
+       /* Now we know the sender speaks my language. */
+       required_len = lustre_msg_hdr_size_v2(0);
+       if (len < required_len) {
+               /* can't even look inside the message */
+               CERROR("message length %d too small for lustre_msg\n", len);
+               return -EINVAL;
+       }
+
+       swabbed = (m->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
+
+       if (swabbed) {
+               __swab32s(&m->lm_magic);
+               __swab32s(&m->lm_bufcount);
+               __swab32s(&m->lm_secflvr);
+               __swab32s(&m->lm_repsize);
+               __swab32s(&m->lm_cksum);
+               __swab32s(&m->lm_flags);
+               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) {
+               CERROR("message bufcount %d is not valid\n", m->lm_bufcount);
+               return -EINVAL;
+       }
+       required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
+       if (len < required_len) {
+               /* didn't receive all the buffer lengths */
+               CERROR("message length %d too small for %d buflens\n",
+                      len, m->lm_bufcount);
+               return -EINVAL;
+       }
+
+       for (i = 0; i < m->lm_bufcount; i++) {
+               if (swabbed)
+                       __swab32s(&m->lm_buflens[i]);
+               buflen = cfs_size_round(m->lm_buflens[i]);
+               if (buflen < 0 || buflen > PTLRPC_MAX_BUFLEN) {
+                       CERROR("buffer %d length %d is not valid\n", i, buflen);
+                       return -EINVAL;
+               }
+               required_len += buflen;
+       }
+       if (len < required_len || required_len > PTLRPC_MAX_BUFLEN) {
+               CERROR("len: %d, required_len %d, bufcount: %d\n",
+                      len, required_len, m->lm_bufcount);
+               for (i = 0; i < m->lm_bufcount; i++)
+                       CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
+               return -EINVAL;
+       }
+
+       return swabbed;
 }
 
 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];
 }
 
 /**
@@ -687,47 +748,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)
@@ -736,43 +799,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;
-        }
-
-        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;
+       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;
+       }
+
+       return str;
 }
 
 /* Wrap up the normal fixed length cases */
@@ -836,10 +902,12 @@ __u32 lustre_msg_get_flags(struct lustre_msg *msg)
 
                CERROR("invalid msg %p: no ptlrpc body!\n", msg);
        }
-       /* no break */
+       /* fallthrough */
        default:
-               /* flags might be printed in debug code while message
-                * uninitialized */
+               /*
+                * flags might be printed in debug code while message
+                * uninitialized
+                */
                return 0;
        }
 }
@@ -900,7 +968,7 @@ __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
 
                CERROR("invalid msg %p: no ptlrpc body!\n", msg);
        }
-       /* no break */
+       /* fallthrough */
        default:
                return 0;
        }
@@ -1105,10 +1173,12 @@ int lustre_msg_get_status(struct lustre_msg *msg)
                        return pb->pb_status;
                CERROR("invalid msg %p: no ptlrpc body!\n", msg);
        }
-       /* no break */
+       /* fallthrough */
        default:
-               /* status might be printed in debug code while message
-               * uninitialized */
+               /*
+                * status might be printed in debug code while message
+                * uninitialized
+                */
                return -EINVAL;
        }
 }
@@ -1215,11 +1285,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;
@@ -1232,11 +1303,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;
@@ -1253,8 +1325,14 @@ char *lustre_msg_get_jobid(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
-               struct ptlrpc_body *pb =
-                       lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
+               struct ptlrpc_body *pb;
+
+               /* the old pltrpc_body_v2 is smaller; doesn't include jobid */
+               if (msg->lm_buflens[MSG_PTLRPC_BODY_OFF] <
+                   sizeof(struct ptlrpc_body))
+                       return NULL;
+
+               pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
                                          sizeof(struct ptlrpc_body));
                if (!pb)
                        return NULL;
@@ -1296,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:
@@ -1466,11 +1550,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;
@@ -1480,13 +1566,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:
@@ -1551,20 +1640,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;
 }
 
 /**
@@ -1578,41 +1667,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);
 
@@ -1627,8 +1722,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);
@@ -1643,61 +1738,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)
@@ -1709,7 +1810,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);
@@ -1737,14 +1838,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);
@@ -1758,14 +1859,14 @@ void lustre_swab_obd_statfs (struct obd_statfs *os)
        __swab64s(&os->os_maxbytes);
        __swab32s(&os->os_state);
        __swab32s(&os->os_fprecreated);
-       CLASSERT(offsetof(typeof(*os), os_spare2) != 0);
-       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);
+       __swab32s(&os->os_granted);
+       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)
@@ -1782,19 +1883,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)
@@ -1805,7 +1906,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);
 
@@ -1813,7 +1914,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);
 
@@ -1855,11 +1956,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);
@@ -1886,23 +1987,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_handle is opaque */
-       CLASSERT(offsetof(typeof(*b), mio_unused1) != 0);
-       CLASSERT(offsetof(typeof(*b), mio_unused2) != 0);
-       CLASSERT(offsetof(typeof(*b), mio_padding) != 0);
+       /* mio_open_handle is opaque */
+       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)
@@ -1915,7 +2016,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]);
 }
@@ -1931,13 +2032,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]);
        }
 }
@@ -1945,80 +2046,107 @@ 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);
 }
 
-void lustre_swab_fiemap(struct fiemap *fiemap)
+static void lustre_swab_fiemap_hdr(struct fiemap *fiemap)
 {
-       __u32 i;
+       __swab64s(&fiemap->fm_start);
+       __swab64s(&fiemap->fm_length);
+       __swab32s(&fiemap->fm_flags);
+       __swab32s(&fiemap->fm_mapped_extents);
+       __swab32s(&fiemap->fm_extent_count);
+       __swab32s(&fiemap->fm_reserved);
+}
+
+int lustre_swab_fiemap(struct fiemap *fiemap, __u32 len)
+{
+       __u32 i, size, count;
 
-        __swab64s(&fiemap->fm_start);
-        __swab64s(&fiemap->fm_length);
-        __swab32s(&fiemap->fm_flags);
-        __swab32s(&fiemap->fm_mapped_extents);
-        __swab32s(&fiemap->fm_extent_count);
-        __swab32s(&fiemap->fm_reserved);
+       lustre_swab_fiemap_hdr(fiemap);
+
+       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]);
 
-        for (i = 0; i < fiemap->fm_mapped_extents; i++)
-                lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
+       return size;
+}
+
+void lustre_swab_fiemap_info_key(struct ll_fiemap_info_key *fiemap_info)
+{
+       lustre_swab_obdo(&fiemap_info->lfik_oa);
+       lustre_swab_fiemap_hdr(&fiemap_info->lfik_fiemap);
 }
 
 void lustre_swab_idx_info(struct idx_info *ii)
@@ -2068,32 +2196,33 @@ void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
        __swab32s(&rr->rr_flags);
        __swab32s(&rr->rr_flags_h);
        __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 */
@@ -2135,17 +2264,27 @@ EXPORT_SYMBOL(lustre_swab_lmv_user_md_objects);
 
 void lustre_swab_lmv_user_md(struct lmv_user_md *lum)
 {
-       __u32 count = lum->lum_stripe_count;
+       __u32 count;
 
+       if (lum->lum_magic == LMV_MAGIC_FOREIGN) {
+               __swab32s(&lum->lum_magic);
+               __swab32s(&((struct lmv_foreign_md *)lum)->lfm_length);
+               __swab32s(&((struct lmv_foreign_md *)lum)->lfm_type);
+               __swab32s(&((struct lmv_foreign_md *)lum)->lfm_flags);
+               return;
+       }
+
+       count = lum->lum_stripe_count;
        __swab32s(&lum->lum_magic);
        __swab32s(&lum->lum_stripe_count);
        __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;
+               /* fallthrough */
        case __swab32(LMV_USER_MAGIC_SPECIFIC):
                lustre_swab_lmv_user_md_objects(lum->lum_objects, count);
                break;
@@ -2220,6 +2359,9 @@ void lustre_print_user_md(unsigned int lvl, struct lov_user_md *lum,
                CDEBUG(lvl, "\tentry %d:\n", i);
                CDEBUG(lvl, "\tlcme_id: %#x\n", ent->lcme_id);
                CDEBUG(lvl, "\tlcme_flags: %#x\n", ent->lcme_flags);
+               if (ent->lcme_flags & LCME_FL_NOSYNC)
+                       CDEBUG(lvl, "\tlcme_timestamp: %llu\n",
+                                       ent->lcme_timestamp);
                CDEBUG(lvl, "\tlcme_extent.e_start: %llu\n",
                       ent->lcme_extent.e_start);
                CDEBUG(lvl, "\tlcme_extent.e_end: %llu\n",
@@ -2254,20 +2396,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);
 
@@ -2294,8 +2436,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];
@@ -2308,13 +2450,13 @@ void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum)
                }
                __swab32s(&ent->lcme_id);
                __swab32s(&ent->lcme_flags);
+               __swab64s(&ent->lcme_timestamp);
                __swab64s(&ent->lcme_extent.e_start);
                __swab64s(&ent->lcme_extent.e_end);
                __swab32s(&ent->lcme_offset);
                __swab32s(&ent->lcme_size);
                __swab32s(&ent->lcme_layout_gen);
-               CLASSERT(offsetof(typeof(*ent), lcme_padding_1) != 0);
-               CLASSERT(offsetof(typeof(*ent), lcme_padding_2) != 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;
@@ -2343,6 +2485,95 @@ 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 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);
+
+void lustre_swab_lov_user_md(struct lov_user_md *lum, size_t size)
+{
+       struct lov_user_md_v1 *v1;
+       struct lov_user_md_v3 *v3;
+       struct lov_foreign_md *lfm;
+       __u16 stripe_count;
+       ENTRY;
+
+       CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
+       switch (lum->lmm_magic) {
+       case __swab32(LOV_MAGIC_V1):
+       case LOV_USER_MAGIC_V1:
+       {
+               v1 = (struct lov_user_md_v1 *)lum;
+               stripe_count = v1->lmm_stripe_count;
+
+               if (lum->lmm_magic != LOV_USER_MAGIC_V1)
+                       __swab16s(&stripe_count);
+
+               lustre_swab_lov_user_md_v1(v1);
+               if (size > sizeof(*v1))
+                       lustre_swab_lov_user_md_objects(v1->lmm_objects,
+                                                       stripe_count);
+
+               break;
+       }
+       case __swab32(LOV_MAGIC_V3):
+       case LOV_USER_MAGIC_V3:
+       {
+               v3 = (struct lov_user_md_v3 *)lum;
+               stripe_count = v3->lmm_stripe_count;
+
+               if (lum->lmm_magic != LOV_USER_MAGIC_V3)
+                       __swab16s(&stripe_count);
+
+               lustre_swab_lov_user_md_v3(v3);
+               if (size > sizeof(*v3))
+                       lustre_swab_lov_user_md_objects(v3->lmm_objects,
+                                                       stripe_count);
+               break;
+       }
+       case __swab32(LOV_USER_MAGIC_SPECIFIC):
+       case LOV_USER_MAGIC_SPECIFIC:
+       {
+               v3 = (struct lov_user_md_v3 *)lum;
+               stripe_count = v3->lmm_stripe_count;
+
+               if (lum->lmm_magic != LOV_USER_MAGIC_SPECIFIC)
+                       __swab16s(&stripe_count);
+
+               lustre_swab_lov_user_md_v3(v3);
+               lustre_swab_lov_user_md_objects(v3->lmm_objects, stripe_count);
+               break;
+       }
+       case __swab32(LOV_MAGIC_COMP_V1):
+       case LOV_USER_MAGIC_COMP_V1:
+               lustre_swab_lov_comp_md_v1((struct lov_comp_md_v1 *)lum);
+               break;
+       case __swab32(LOV_MAGIC_FOREIGN):
+       case LOV_USER_MAGIC_FOREIGN:
+       {
+               lfm = (struct lov_foreign_md *)lum;
+               __swab32s(&lfm->lfm_magic);
+               __swab32s(&lfm->lfm_length);
+               __swab32s(&lfm->lfm_type);
+               __swab32s(&lfm->lfm_flags);
+               break;
+       }
+       default:
+               CDEBUG(D_IOCTL, "Invalid LOV magic %08x\n", lum->lmm_magic);
+       }
+}
+EXPORT_SYMBOL(lustre_swab_lov_user_md);
+
 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
 {
        ENTRY;
@@ -2357,33 +2588,20 @@ void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
 }
 EXPORT_SYMBOL(lustre_swab_lov_mds_md);
 
-void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
-                                     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;
-}
-EXPORT_SYMBOL(lustre_swab_lov_user_md_objects);
-
-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);
@@ -2391,7 +2609,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);
 }
@@ -2399,34 +2617,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)
@@ -2464,78 +2682,75 @@ void dump_obdo(struct obdo *oa)
        if (valid & OBD_MD_FLFID)
                CDEBUG(D_RPCTRACE, "obdo: o_parent_seq = %#llx\n",
                       oa->o_parent_seq);
-        if (valid & OBD_MD_FLSIZE)
+       if (valid & OBD_MD_FLSIZE)
                CDEBUG(D_RPCTRACE, "obdo: o_size = %lld\n", oa->o_size);
-        if (valid & OBD_MD_FLMTIME)
+       if (valid & OBD_MD_FLMTIME)
                CDEBUG(D_RPCTRACE, "obdo: o_mtime = %lld\n", oa->o_mtime);
-        if (valid & OBD_MD_FLATIME)
+       if (valid & OBD_MD_FLATIME)
                CDEBUG(D_RPCTRACE, "obdo: o_atime = %lld\n", oa->o_atime);
-        if (valid & OBD_MD_FLCTIME)
+       if (valid & OBD_MD_FLCTIME)
                CDEBUG(D_RPCTRACE, "obdo: o_ctime = %lld\n", oa->o_ctime);
-        if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
+       if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
                CDEBUG(D_RPCTRACE, "obdo: o_blocks = %lld\n", oa->o_blocks);
-        if (valid & OBD_MD_FLGRANT)
+       if (valid & OBD_MD_FLGRANT)
                CDEBUG(D_RPCTRACE, "obdo: o_grant = %lld\n", oa->o_grant);
-        if (valid & OBD_MD_FLBLKSZ)
-                CDEBUG(D_RPCTRACE, "obdo: o_blksize = %d\n", oa->o_blksize);
-        if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
-                CDEBUG(D_RPCTRACE, "obdo: o_mode = %o\n",
-                       oa->o_mode & ((valid & OBD_MD_FLTYPE ?  S_IFMT : 0) |
-                                     (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
-        if (valid & OBD_MD_FLUID)
-                CDEBUG(D_RPCTRACE, "obdo: o_uid = %u\n", oa->o_uid);
-        if (valid & OBD_MD_FLUID)
-                CDEBUG(D_RPCTRACE, "obdo: o_uid_h = %u\n", oa->o_uid_h);
-        if (valid & OBD_MD_FLGID)
-                CDEBUG(D_RPCTRACE, "obdo: o_gid = %u\n", oa->o_gid);
-        if (valid & OBD_MD_FLGID)
-                CDEBUG(D_RPCTRACE, "obdo: o_gid_h = %u\n", oa->o_gid_h);
-        if (valid & OBD_MD_FLFLAGS)
-                CDEBUG(D_RPCTRACE, "obdo: o_flags = %x\n", oa->o_flags);
-        if (valid & OBD_MD_FLNLINK)
-                CDEBUG(D_RPCTRACE, "obdo: o_nlink = %u\n", oa->o_nlink);
-        else if (valid & OBD_MD_FLCKSUM)
-                CDEBUG(D_RPCTRACE, "obdo: o_checksum (o_nlink) = %u\n",
-                       oa->o_nlink);
-        if (valid & OBD_MD_FLGENER)
-                CDEBUG(D_RPCTRACE, "obdo: o_parent_oid = %x\n",
-                       oa->o_parent_oid);
-        if (valid & OBD_MD_FLEPOCH)
-               CDEBUG(D_RPCTRACE, "obdo: o_ioepoch = %lld\n",
-                       oa->o_ioepoch);
-        if (valid & OBD_MD_FLFID) {
-                CDEBUG(D_RPCTRACE, "obdo: o_stripe_idx = %u\n",
-                       oa->o_stripe_idx);
-                CDEBUG(D_RPCTRACE, "obdo: o_parent_ver = %x\n",
-                       oa->o_parent_ver);
-        }
-        if (valid & OBD_MD_FLHANDLE)
+       if (valid & OBD_MD_FLBLKSZ)
+               CDEBUG(D_RPCTRACE, "obdo: o_blksize = %d\n", oa->o_blksize);
+       if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
+               CDEBUG(D_RPCTRACE, "obdo: o_mode = %o\n",
+                      oa->o_mode & ((valid & OBD_MD_FLTYPE ?  S_IFMT : 0) |
+                                    (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
+       if (valid & OBD_MD_FLUID)
+               CDEBUG(D_RPCTRACE, "obdo: o_uid = %u\n", oa->o_uid);
+       if (valid & OBD_MD_FLUID)
+               CDEBUG(D_RPCTRACE, "obdo: o_uid_h = %u\n", oa->o_uid_h);
+       if (valid & OBD_MD_FLGID)
+               CDEBUG(D_RPCTRACE, "obdo: o_gid = %u\n", oa->o_gid);
+       if (valid & OBD_MD_FLGID)
+               CDEBUG(D_RPCTRACE, "obdo: o_gid_h = %u\n", oa->o_gid_h);
+       if (valid & OBD_MD_FLFLAGS)
+               CDEBUG(D_RPCTRACE, "obdo: o_flags = %x\n", oa->o_flags);
+       if (valid & OBD_MD_FLNLINK)
+               CDEBUG(D_RPCTRACE, "obdo: o_nlink = %u\n", oa->o_nlink);
+       else if (valid & OBD_MD_FLCKSUM)
+               CDEBUG(D_RPCTRACE, "obdo: o_checksum (o_nlink) = %u\n",
+                      oa->o_nlink);
+       if (valid & OBD_MD_FLPARENT)
+               CDEBUG(D_RPCTRACE, "obdo: o_parent_oid = %x\n",
+                      oa->o_parent_oid);
+       if (valid & OBD_MD_FLFID) {
+               CDEBUG(D_RPCTRACE, "obdo: o_stripe_idx = %u\n",
+                      oa->o_stripe_idx);
+               CDEBUG(D_RPCTRACE, "obdo: o_parent_ver = %x\n",
+                      oa->o_parent_ver);
+       }
+       if (valid & OBD_MD_FLHANDLE)
                CDEBUG(D_RPCTRACE, "obdo: o_handle = %lld\n",
-                       oa->o_handle.cookie);
+                      oa->o_handle.cookie);
 }
 
 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)
@@ -2558,6 +2773,7 @@ void _debug_req(struct ptlrpc_request *req,
        bool req_ok = req->rq_reqmsg != NULL;
        bool rep_ok = false;
        lnet_nid_t nid = LNET_NID_ANY;
+       struct va_format vaf;
        va_list args;
        int rep_flags = -1;
        int rep_status = -1;
@@ -2583,48 +2799,34 @@ void _debug_req(struct ptlrpc_request *req,
                nid = req->rq_export->exp_connection->c_peer.nid;
 
        va_start(args, fmt);
-       libcfs_debug_vmsg2(msgdata, fmt, args,
-                          " req@%p x%llu/t%lld(%lld) o%d->%s@%s:%d/%d lens %d/%d e %d to %lld dl %lld ref %d fl " REQ_FLAGS_FMT "/%x/%x rc %d/%d\n",
-                          req, req->rq_xid, req->rq_transno,
-                          req_ok ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
-                          req_ok ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
-                          req->rq_import ?
-                               req->rq_import->imp_obd->obd_name :
-                               req->rq_export ?
-                                       req->rq_export->exp_client_uuid.uuid :
-                                       "<?>",
-                          libcfs_nid2str(nid),
-                          req->rq_request_portal, req->rq_reply_portal,
-                          req->rq_reqlen, req->rq_replen,
-                          req->rq_early_count, (s64)req->rq_timedout,
-                          (s64)req->rq_deadline,
-                          atomic_read(&req->rq_refcount),
-                          DEBUG_REQ_FLAGS(req),
-                          req_ok ? lustre_msg_get_flags(req->rq_reqmsg) : -1,
-                          rep_flags, req->rq_status, rep_status);
+       vaf.fmt = fmt;
+       vaf.va = &args;
+       libcfs_debug_msg(msgdata,
+                        "%pV req@%p x%llu/t%lld(%lld) o%d->%s@%s:%d/%d lens %d/%d e %d to %lld dl %lld ref %d fl " REQ_FLAGS_FMT "/%x/%x rc %d/%d job:'%s'\n",
+                        &vaf,
+                        req, req->rq_xid, req->rq_transno,
+                        req_ok ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
+                        req_ok ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
+                        req->rq_import ?
+                        req->rq_import->imp_obd->obd_name :
+                        req->rq_export ?
+                        req->rq_export->exp_client_uuid.uuid :
+                        "<?>",
+                        libcfs_nid2str(nid),
+                        req->rq_request_portal, req->rq_reply_portal,
+                        req->rq_reqlen, req->rq_replen,
+                        req->rq_early_count, (s64)req->rq_timedout,
+                        (s64)req->rq_deadline,
+                        atomic_read(&req->rq_refcount),
+                        DEBUG_REQ_FLAGS(req),
+                        req_ok ? lustre_msg_get_flags(req->rq_reqmsg) : -1,
+                        rep_flags, req->rq_status, rep_status,
+                        req_ok ? lustre_msg_get_jobid(req->rq_reqmsg) ?: ""
+                               : "");
        va_end(args);
 }
 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);
@@ -2690,85 +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));
-       }
-}
-
-void lustre_swab_object_update_request(struct object_update_request *our)
-{
-       size_t i;
-       __swab32s(&our->ourq_magic);
-       __swab16s(&our->ourq_count);
-       __swab16s(&our->ourq_padding);
-       for (i = 0; i < our->ourq_count; i++) {
-               struct object_update *ou;
-
-               ou = object_update_request_get(our, i, NULL);
-               if (ou == NULL)
-                       return;
-               lustre_swab_object_update(ou);
-       }
-}
-
-void lustre_swab_object_update_result(struct object_update_result *our)
-{
-       __swab32s(&our->our_rc);
-       __swab16s(&our->our_datalen);
-       __swab16s(&our->our_padding);
-}
-
-void lustre_swab_object_update_reply(struct object_update_reply *our)
-{
-       size_t i;
-
-       __swab32s(&our->ourp_magic);
-       __swab16s(&our->ourp_count);
-       __swab16s(&our->ourp_padding);
-       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;
-               lustre_swab_object_update_result(ourp);
-       }
-}
-
-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);
@@ -2808,16 +2931,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);
 }
 
@@ -2840,7 +2963,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);
 
@@ -2851,8 +2974,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);