4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/ptlrpc/pack_generic.c
34 * (Un)packing of OST requests
36 * Author: Peter J. Braam <braam@clusterfs.com>
37 * Author: Phil Schwan <phil@clusterfs.com>
38 * Author: Eric Barton <eeb@clusterfs.com>
41 #define DEBUG_SUBSYSTEM S_RPC
43 #include <libcfs/libcfs.h>
45 #include <llog_swab.h>
46 #include <lustre_net.h>
47 #include <lustre_swab.h>
48 #include <obd_cksum.h>
49 #include <obd_class.h>
50 #include <obd_support.h>
51 #include <obj_update.h>
53 #include "ptlrpc_internal.h"
55 static inline __u32 lustre_msg_hdr_size_v2(__u32 count)
57 return cfs_size_round(offsetof(struct lustre_msg_v2,
61 __u32 lustre_msg_hdr_size(__u32 magic, __u32 count)
66 case LUSTRE_MSG_MAGIC_V2:
67 return lustre_msg_hdr_size_v2(count);
69 LASSERTF(0, "incorrect message magic: %08x\n", magic);
74 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
78 lustre_set_req_swabbed(req, index);
80 lustre_set_rep_swabbed(req, index);
83 bool ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
87 return (ptlrpc_req_need_swab(req) &&
88 !lustre_req_swabbed(req, index));
90 return (ptlrpc_rep_need_swab(req) && !lustre_rep_swabbed(req, index));
93 static inline int lustre_msg_check_version_v2(struct lustre_msg_v2 *msg,
94 enum lustre_msg_version version)
96 enum lustre_msg_version ver = lustre_msg_get_version(msg);
98 return (ver & LUSTRE_VERSION_MASK) != version;
101 int lustre_msg_check_version(struct lustre_msg *msg,
102 enum lustre_msg_version version)
104 #define LUSTRE_MSG_MAGIC_V1 0x0BD00BD0
105 switch (msg->lm_magic) {
106 case LUSTRE_MSG_MAGIC_V1:
107 CERROR("msg v1 not supported - please upgrade you system\n");
109 case LUSTRE_MSG_MAGIC_V2:
110 return lustre_msg_check_version_v2(msg, version);
112 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
115 #undef LUSTRE_MSG_MAGIC_V1
118 /* early reply size */
119 __u32 lustre_msg_early_size()
123 /* Always reply old ptlrpc_body_v2 to keep interoprability
124 * with the old client (< 2.3) which doesn't have pb_jobid
125 * in the ptlrpc_body.
127 * XXX Remove this whenever we dorp interoprability with such
130 __u32 pblen = sizeof(struct ptlrpc_body_v2);
131 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, &pblen);
135 EXPORT_SYMBOL(lustre_msg_early_size);
137 __u32 lustre_msg_size_v2(int count, __u32 *lengths)
143 size = lustre_msg_hdr_size_v2(count);
144 for (i = 0; i < count; i++)
145 size += cfs_size_round(lengths[i]);
149 EXPORT_SYMBOL(lustre_msg_size_v2);
151 /* This returns the size of the buffer that is required to hold a lustre_msg
152 * with the given sub-buffer lengths.
153 * NOTE: this should only be used for NEW requests, and should always be
154 * in the form of a v2 request. If this is a connection to a v1
155 * target then the first buffer will be stripped because the ptlrpc
156 * data is part of the lustre_msg_v1 header. b=14043 */
157 __u32 lustre_msg_size(__u32 magic, int count, __u32 *lens)
159 __u32 size[] = { sizeof(struct ptlrpc_body) };
167 LASSERT(lens[MSG_PTLRPC_BODY_OFF] >= sizeof(struct ptlrpc_body_v2));
170 case LUSTRE_MSG_MAGIC_V2:
171 return lustre_msg_size_v2(count, lens);
173 LASSERTF(0, "incorrect message magic: %08x\n", magic);
178 /* This is used to determine the size of a buffer that was already packed
179 * and will correctly handle the different message formats. */
180 __u32 lustre_packed_msg_size(struct lustre_msg *msg)
182 switch (msg->lm_magic) {
183 case LUSTRE_MSG_MAGIC_V2:
184 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
186 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
190 EXPORT_SYMBOL(lustre_packed_msg_size);
192 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
200 msg->lm_bufcount = count;
201 /* XXX: lm_secflvr uninitialized here */
202 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
204 for (i = 0; i < count; i++)
205 msg->lm_buflens[i] = lens[i];
210 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
211 for (i = 0; i < count; i++) {
215 memcpy(ptr, tmp, lens[i]);
216 ptr += cfs_size_round(lens[i]);
219 EXPORT_SYMBOL(lustre_init_msg_v2);
221 static int lustre_pack_request_v2(struct ptlrpc_request *req,
222 int count, __u32 *lens, char **bufs)
226 reqlen = lustre_msg_size_v2(count, lens);
228 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
232 req->rq_reqlen = reqlen;
234 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
235 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
239 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
240 __u32 *lens, char **bufs)
242 __u32 size[] = { sizeof(struct ptlrpc_body) };
250 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
252 /* only use new format, we don't need to be compatible with 1.4 */
253 magic = LUSTRE_MSG_MAGIC_V2;
256 case LUSTRE_MSG_MAGIC_V2:
257 return lustre_pack_request_v2(req, count, lens, bufs);
259 LASSERTF(0, "incorrect message magic: %08x\n", magic);
265 struct list_head ptlrpc_rs_debug_lru =
266 LIST_HEAD_INIT(ptlrpc_rs_debug_lru);
267 spinlock_t ptlrpc_rs_debug_lock;
269 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
271 spin_lock(&ptlrpc_rs_debug_lock); \
272 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
273 spin_unlock(&ptlrpc_rs_debug_lock); \
276 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
278 spin_lock(&ptlrpc_rs_debug_lock); \
279 list_del(&(rs)->rs_debug_list); \
280 spin_unlock(&ptlrpc_rs_debug_lock); \
283 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
284 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
287 struct ptlrpc_reply_state *
288 lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt)
290 struct ptlrpc_reply_state *rs = NULL;
292 spin_lock(&svcpt->scp_rep_lock);
294 /* See if we have anything in a pool, and wait if nothing */
295 while (list_empty(&svcpt->scp_rep_idle)) {
296 struct l_wait_info lwi;
299 spin_unlock(&svcpt->scp_rep_lock);
300 /* If we cannot get anything for some long time, we better
301 * bail out instead of waiting infinitely */
302 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
303 rc = l_wait_event(svcpt->scp_rep_waitq,
304 !list_empty(&svcpt->scp_rep_idle), &lwi);
307 spin_lock(&svcpt->scp_rep_lock);
310 rs = list_entry(svcpt->scp_rep_idle.next,
311 struct ptlrpc_reply_state, rs_list);
312 list_del(&rs->rs_list);
314 spin_unlock(&svcpt->scp_rep_lock);
316 memset(rs, 0, svcpt->scp_service->srv_max_reply_size);
317 rs->rs_size = svcpt->scp_service->srv_max_reply_size;
318 rs->rs_svcpt = svcpt;
324 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
326 struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
328 spin_lock(&svcpt->scp_rep_lock);
329 list_add(&rs->rs_list, &svcpt->scp_rep_idle);
330 spin_unlock(&svcpt->scp_rep_lock);
331 wake_up(&svcpt->scp_rep_waitq);
334 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
335 __u32 *lens, char **bufs, int flags)
337 struct ptlrpc_reply_state *rs;
341 LASSERT(req->rq_reply_state == NULL);
344 if ((flags & LPRFL_EARLY_REPLY) == 0) {
345 spin_lock(&req->rq_lock);
346 req->rq_packed_final = 1;
347 spin_unlock(&req->rq_lock);
350 msg_len = lustre_msg_size_v2(count, lens);
351 rc = sptlrpc_svc_alloc_rs(req, msg_len);
355 rs = req->rq_reply_state;
356 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
357 rs->rs_cb_id.cbid_fn = reply_out_callback;
358 rs->rs_cb_id.cbid_arg = rs;
359 rs->rs_svcpt = req->rq_rqbd->rqbd_svcpt;
360 INIT_LIST_HEAD(&rs->rs_exp_list);
361 INIT_LIST_HEAD(&rs->rs_obd_list);
362 INIT_LIST_HEAD(&rs->rs_list);
363 spin_lock_init(&rs->rs_lock);
365 req->rq_replen = msg_len;
366 req->rq_reply_state = rs;
367 req->rq_repmsg = rs->rs_msg;
369 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
370 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
372 PTLRPC_RS_DEBUG_LRU_ADD(rs);
376 EXPORT_SYMBOL(lustre_pack_reply_v2);
378 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
379 char **bufs, int flags)
382 __u32 size[] = { sizeof(struct ptlrpc_body) };
390 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
392 switch (req->rq_reqmsg->lm_magic) {
393 case LUSTRE_MSG_MAGIC_V2:
394 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
397 LASSERTF(0, "incorrect message magic: %08x\n",
398 req->rq_reqmsg->lm_magic);
402 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
403 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
407 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
410 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
412 EXPORT_SYMBOL(lustre_pack_reply);
414 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, __u32 n, __u32 min_size)
416 __u32 i, offset, buflen, bufcount;
419 LASSERT(m->lm_bufcount > 0);
421 bufcount = m->lm_bufcount;
422 if (unlikely(n >= bufcount)) {
423 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
428 buflen = m->lm_buflens[n];
429 if (unlikely(buflen < min_size)) {
430 CERROR("msg %p buffer[%d] size %d too small "
431 "(required %d, opc=%d)\n", m, n, buflen, min_size,
432 n == MSG_PTLRPC_BODY_OFF ? -1 : lustre_msg_get_opc(m));
436 offset = lustre_msg_hdr_size_v2(bufcount);
437 for (i = 0; i < n; i++)
438 offset += cfs_size_round(m->lm_buflens[i]);
440 return (char *)m + offset;
443 void *lustre_msg_buf(struct lustre_msg *m, __u32 n, __u32 min_size)
445 switch (m->lm_magic) {
446 case LUSTRE_MSG_MAGIC_V2:
447 return lustre_msg_buf_v2(m, n, min_size);
449 LASSERTF(0, "incorrect message magic: %08x (msg:%p)\n",
454 EXPORT_SYMBOL(lustre_msg_buf);
456 static int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, __u32 segment,
457 unsigned int newlen, int move_data)
459 char *tail = NULL, *newpos;
463 LASSERT(msg->lm_bufcount > segment);
464 LASSERT(msg->lm_buflens[segment] >= newlen);
466 if (msg->lm_buflens[segment] == newlen)
469 if (move_data && msg->lm_bufcount > segment + 1) {
470 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
471 for (n = segment + 1; n < msg->lm_bufcount; n++)
472 tail_len += cfs_size_round(msg->lm_buflens[n]);
475 msg->lm_buflens[segment] = newlen;
477 if (tail && tail_len) {
478 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
479 LASSERT(newpos <= tail);
481 memmove(newpos, tail, tail_len);
484 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
488 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
489 * we also move data forward from @segment + 1.
491 * if @newlen == 0, we remove the segment completely, but we still keep the
492 * totally bufcount the same to save possible data moving. this will leave a
493 * unused segment with size 0 at the tail, but that's ok.
495 * return new msg size after shrinking.
498 * + if any buffers higher than @segment has been filled in, must call shrink
499 * with non-zero @move_data.
500 * + caller should NOT keep pointers to msg buffers which higher than @segment
503 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
504 unsigned int newlen, int move_data)
506 switch (msg->lm_magic) {
507 case LUSTRE_MSG_MAGIC_V2:
508 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
510 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
513 EXPORT_SYMBOL(lustre_shrink_msg);
515 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
517 PTLRPC_RS_DEBUG_LRU_DEL(rs);
519 LASSERT(atomic_read(&rs->rs_refcount) == 0);
520 LASSERT(!rs->rs_difficult || rs->rs_handled);
521 LASSERT(!rs->rs_on_net);
522 LASSERT(!rs->rs_scheduled);
523 LASSERT(rs->rs_export == NULL);
524 LASSERT(rs->rs_nlocks == 0);
525 LASSERT(list_empty(&rs->rs_exp_list));
526 LASSERT(list_empty(&rs->rs_obd_list));
528 sptlrpc_svc_free_rs(rs);
531 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
533 int swabbed, required_len, i, buflen;
535 /* Now we know the sender speaks my language. */
536 required_len = lustre_msg_hdr_size_v2(0);
537 if (len < required_len) {
538 /* can't even look inside the message */
539 CERROR("message length %d too small for lustre_msg\n", len);
543 swabbed = (m->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
546 __swab32s(&m->lm_magic);
547 __swab32s(&m->lm_bufcount);
548 __swab32s(&m->lm_secflvr);
549 __swab32s(&m->lm_repsize);
550 __swab32s(&m->lm_cksum);
551 __swab32s(&m->lm_flags);
552 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
553 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
556 if (m->lm_bufcount == 0 || m->lm_bufcount > PTLRPC_MAX_BUFCOUNT) {
557 CERROR("message bufcount %d is not valid\n", m->lm_bufcount);
560 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
561 if (len < required_len) {
562 /* didn't receive all the buffer lengths */
563 CERROR("message length %d too small for %d buflens\n",
564 len, m->lm_bufcount);
568 for (i = 0; i < m->lm_bufcount; i++) {
570 __swab32s(&m->lm_buflens[i]);
571 buflen = cfs_size_round(m->lm_buflens[i]);
572 if (buflen < 0 || buflen > PTLRPC_MAX_BUFLEN) {
573 CERROR("buffer %d length %d is not valid\n", i, buflen);
576 required_len += buflen;
578 if (len < required_len || required_len > PTLRPC_MAX_BUFLEN) {
579 CERROR("len: %d, required_len %d, bufcount: %d\n",
580 len, required_len, m->lm_bufcount);
581 for (i = 0; i < m->lm_bufcount; i++)
582 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
589 int __lustre_unpack_msg(struct lustre_msg *m, int len)
591 int required_len, rc;
594 /* We can provide a slightly better error log, if we check the
595 * message magic and version first. In the future, struct
596 * lustre_msg may grow, and we'd like to log a version mismatch,
597 * rather than a short message.
600 required_len = offsetof(struct lustre_msg, lm_magic) +
602 if (len < required_len) {
603 /* can't even look inside the message */
604 CERROR("message length %d too small for magic/version check\n",
609 rc = lustre_unpack_msg_v2(m, len);
613 EXPORT_SYMBOL(__lustre_unpack_msg);
615 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len)
618 rc = __lustre_unpack_msg(req->rq_reqmsg, len);
620 lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
626 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len)
629 rc = __lustre_unpack_msg(req->rq_repmsg, len);
631 lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
637 static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
638 const int inout, int offset)
640 struct ptlrpc_body *pb;
641 struct lustre_msg_v2 *m = inout ? req->rq_reqmsg : req->rq_repmsg;
643 pb = lustre_msg_buf_v2(m, offset, sizeof(struct ptlrpc_body_v2));
645 CERROR("error unpacking ptlrpc body\n");
648 if (ptlrpc_buf_need_swab(req, inout, offset)) {
649 lustre_swab_ptlrpc_body(pb);
650 ptlrpc_buf_set_swabbed(req, inout, offset);
653 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
654 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
659 pb->pb_status = ptlrpc_status_ntoh(pb->pb_status);
664 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
666 switch (req->rq_reqmsg->lm_magic) {
667 case LUSTRE_MSG_MAGIC_V2:
668 return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
670 CERROR("bad lustre msg magic: %08x\n",
671 req->rq_reqmsg->lm_magic);
676 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
678 switch (req->rq_repmsg->lm_magic) {
679 case LUSTRE_MSG_MAGIC_V2:
680 return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
682 CERROR("bad lustre msg magic: %08x\n",
683 req->rq_repmsg->lm_magic);
688 static inline __u32 lustre_msg_buflen_v2(struct lustre_msg_v2 *m, __u32 n)
690 if (n >= m->lm_bufcount)
693 return m->lm_buflens[n];
697 * lustre_msg_buflen - return the length of buffer \a n in message \a m
698 * \param m lustre_msg (request or reply) to look at
699 * \param n message index (base 0)
701 * returns zero for non-existent message indices
703 __u32 lustre_msg_buflen(struct lustre_msg *m, __u32 n)
705 switch (m->lm_magic) {
706 case LUSTRE_MSG_MAGIC_V2:
707 return lustre_msg_buflen_v2(m, n);
709 CERROR("incorrect message magic: %08x\n", m->lm_magic);
713 EXPORT_SYMBOL(lustre_msg_buflen);
716 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, __u32 n, __u32 len)
718 if (n >= m->lm_bufcount)
721 m->lm_buflens[n] = len;
724 void lustre_msg_set_buflen(struct lustre_msg *m, __u32 n, __u32 len)
726 switch (m->lm_magic) {
727 case LUSTRE_MSG_MAGIC_V2:
728 lustre_msg_set_buflen_v2(m, n, len);
731 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
735 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
736 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
737 __u32 lustre_msg_bufcount(struct lustre_msg *m)
739 switch (m->lm_magic) {
740 case LUSTRE_MSG_MAGIC_V2:
741 return m->lm_bufcount;
743 CERROR("incorrect message magic: %08x\n", m->lm_magic);
748 char *lustre_msg_string(struct lustre_msg *m, __u32 index, __u32 max_len)
750 /* max_len == 0 means the string should fill the buffer */
754 switch (m->lm_magic) {
755 case LUSTRE_MSG_MAGIC_V2:
756 str = lustre_msg_buf_v2(m, index, 0);
757 blen = lustre_msg_buflen_v2(m, index);
760 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
764 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
768 slen = strnlen(str, blen);
770 if (slen == blen) { /* not NULL terminated */
771 CERROR("can't unpack non-NULL terminated string in "
772 "msg %p buffer[%d] len %d\n", m, index, blen);
775 if (blen > PTLRPC_MAX_BUFLEN) {
776 CERROR("buffer length of msg %p buffer[%d] is invalid(%d)\n",
782 if (slen != blen - 1) {
783 CERROR("can't unpack short string in msg %p "
784 "buffer[%d] len %d: strlen %d\n",
785 m, index, blen, slen);
788 } else if (slen > max_len) {
789 CERROR("can't unpack oversized string in msg %p "
790 "buffer[%d] len %d strlen %d: max %d expected\n",
791 m, index, blen, slen, max_len);
798 /* Wrap up the normal fixed length cases */
799 static inline void *__lustre_swab_buf(struct lustre_msg *msg, __u32 index,
800 __u32 min_size, void *swabber)
804 LASSERT(msg != NULL);
805 switch (msg->lm_magic) {
806 case LUSTRE_MSG_MAGIC_V2:
807 ptr = lustre_msg_buf_v2(msg, index, min_size);
810 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
813 if (ptr != NULL && swabber != NULL)
814 ((void (*)(void *))swabber)(ptr);
819 static inline struct ptlrpc_body *lustre_msg_ptlrpc_body(struct lustre_msg *msg)
821 return lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
822 sizeof(struct ptlrpc_body_v2));
825 enum lustre_msghdr lustre_msghdr_get_flags(struct lustre_msg *msg)
827 switch (msg->lm_magic) {
828 case LUSTRE_MSG_MAGIC_V2:
829 /* already in host endian */
830 return msg->lm_flags;
832 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
836 EXPORT_SYMBOL(lustre_msghdr_get_flags);
838 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
840 switch (msg->lm_magic) {
841 case LUSTRE_MSG_MAGIC_V2:
842 msg->lm_flags = flags;
845 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
849 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
851 switch (msg->lm_magic) {
852 case LUSTRE_MSG_MAGIC_V2: {
853 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
857 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
861 /* flags might be printed in debug code while message
866 EXPORT_SYMBOL(lustre_msg_get_flags);
868 void lustre_msg_add_flags(struct lustre_msg *msg, __u32 flags)
870 switch (msg->lm_magic) {
871 case LUSTRE_MSG_MAGIC_V2: {
872 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
873 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
874 pb->pb_flags |= flags;
878 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
881 EXPORT_SYMBOL(lustre_msg_add_flags);
883 void lustre_msg_set_flags(struct lustre_msg *msg, __u32 flags)
885 switch (msg->lm_magic) {
886 case LUSTRE_MSG_MAGIC_V2: {
887 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
888 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
889 pb->pb_flags = flags;
893 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
897 void lustre_msg_clear_flags(struct lustre_msg *msg, __u32 flags)
899 switch (msg->lm_magic) {
900 case LUSTRE_MSG_MAGIC_V2: {
901 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
902 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
903 pb->pb_flags &= ~flags;
908 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
911 EXPORT_SYMBOL(lustre_msg_clear_flags);
913 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
915 switch (msg->lm_magic) {
916 case LUSTRE_MSG_MAGIC_V2: {
917 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
919 return pb->pb_op_flags;
921 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
929 void lustre_msg_add_op_flags(struct lustre_msg *msg, __u32 flags)
931 switch (msg->lm_magic) {
932 case LUSTRE_MSG_MAGIC_V2: {
933 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
934 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
935 pb->pb_op_flags |= flags;
939 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
942 EXPORT_SYMBOL(lustre_msg_add_op_flags);
944 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
946 switch (msg->lm_magic) {
947 case LUSTRE_MSG_MAGIC_V2: {
948 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
950 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
953 return &pb->pb_handle;
956 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
961 __u32 lustre_msg_get_type(struct lustre_msg *msg)
963 switch (msg->lm_magic) {
964 case LUSTRE_MSG_MAGIC_V2: {
965 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
967 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
968 return PTL_RPC_MSG_ERR;
973 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
974 return PTL_RPC_MSG_ERR;
977 EXPORT_SYMBOL(lustre_msg_get_type);
979 enum lustre_msg_version lustre_msg_get_version(struct lustre_msg *msg)
981 switch (msg->lm_magic) {
982 case LUSTRE_MSG_MAGIC_V2: {
983 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
985 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
988 return pb->pb_version;
991 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
996 void lustre_msg_add_version(struct lustre_msg *msg, __u32 version)
998 switch (msg->lm_magic) {
999 case LUSTRE_MSG_MAGIC_V2: {
1000 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1001 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1002 pb->pb_version |= version;
1006 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1010 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1012 switch (msg->lm_magic) {
1013 case LUSTRE_MSG_MAGIC_V2: {
1014 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1016 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1022 CERROR("incorrect message magic: %08x (msg:%p)\n",
1023 msg->lm_magic, msg);
1027 EXPORT_SYMBOL(lustre_msg_get_opc);
1029 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1031 switch (msg->lm_magic) {
1032 case LUSTRE_MSG_MAGIC_V2: {
1033 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1035 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1038 return pb->pb_last_xid;
1041 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1045 EXPORT_SYMBOL(lustre_msg_get_last_xid);
1047 __u16 lustre_msg_get_tag(struct lustre_msg *msg)
1049 switch (msg->lm_magic) {
1050 case LUSTRE_MSG_MAGIC_V2: {
1051 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1053 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1059 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1063 EXPORT_SYMBOL(lustre_msg_get_tag);
1065 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1067 switch (msg->lm_magic) {
1068 case LUSTRE_MSG_MAGIC_V2: {
1069 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1071 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1074 return pb->pb_last_committed;
1077 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1081 EXPORT_SYMBOL(lustre_msg_get_last_committed);
1083 __u64 *lustre_msg_get_versions(struct lustre_msg *msg)
1085 switch (msg->lm_magic) {
1086 case LUSTRE_MSG_MAGIC_V2: {
1087 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1089 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1092 return pb->pb_pre_versions;
1095 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1099 EXPORT_SYMBOL(lustre_msg_get_versions);
1101 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1103 switch (msg->lm_magic) {
1104 case LUSTRE_MSG_MAGIC_V2: {
1105 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1107 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1110 return pb->pb_transno;
1113 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1117 EXPORT_SYMBOL(lustre_msg_get_transno);
1119 int lustre_msg_get_status(struct lustre_msg *msg)
1121 switch (msg->lm_magic) {
1122 case LUSTRE_MSG_MAGIC_V2: {
1123 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1125 return pb->pb_status;
1126 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1130 /* status might be printed in debug code while message
1135 EXPORT_SYMBOL(lustre_msg_get_status);
1137 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1139 switch (msg->lm_magic) {
1140 case LUSTRE_MSG_MAGIC_V2: {
1141 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1143 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1149 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1155 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1157 switch (msg->lm_magic) {
1158 case LUSTRE_MSG_MAGIC_V2: {
1159 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1161 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1168 CERROR("invalid msg magic %x\n", msg->lm_magic);
1173 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1175 switch (msg->lm_magic) {
1176 case LUSTRE_MSG_MAGIC_V2: {
1177 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1179 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1182 return pb->pb_limit;
1185 CERROR("invalid msg magic %x\n", msg->lm_magic);
1191 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1193 switch (msg->lm_magic) {
1194 case LUSTRE_MSG_MAGIC_V2: {
1195 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1197 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1200 pb->pb_limit = limit;
1204 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1209 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1211 switch (msg->lm_magic) {
1212 case LUSTRE_MSG_MAGIC_V2: {
1213 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1215 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1218 return pb->pb_conn_cnt;
1221 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1225 EXPORT_SYMBOL(lustre_msg_get_conn_cnt);
1227 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1229 switch (msg->lm_magic) {
1230 case LUSTRE_MSG_MAGIC_V2:
1231 return msg->lm_magic;
1233 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1238 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
1240 switch (msg->lm_magic) {
1241 case LUSTRE_MSG_MAGIC_V2: {
1242 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1244 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1247 return pb->pb_timeout;
1250 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1255 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1257 switch (msg->lm_magic) {
1258 case LUSTRE_MSG_MAGIC_V2: {
1259 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1261 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1264 return pb->pb_service_time;
1267 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1272 char *lustre_msg_get_jobid(struct lustre_msg *msg)
1274 switch (msg->lm_magic) {
1275 case LUSTRE_MSG_MAGIC_V2: {
1276 struct ptlrpc_body *pb =
1277 lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
1278 sizeof(struct ptlrpc_body));
1282 return pb->pb_jobid;
1285 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1289 EXPORT_SYMBOL(lustre_msg_get_jobid);
1291 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1293 switch (msg->lm_magic) {
1294 case LUSTRE_MSG_MAGIC_V2:
1295 return msg->lm_cksum;
1297 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1302 __u64 lustre_msg_get_mbits(struct lustre_msg *msg)
1304 switch (msg->lm_magic) {
1305 case LUSTRE_MSG_MAGIC_V2: {
1306 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1308 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1311 return pb->pb_mbits;
1314 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1319 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1321 switch (msg->lm_magic) {
1322 case LUSTRE_MSG_MAGIC_V2: {
1323 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1324 __u32 len = lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF);
1326 unsigned int hsize = 4;
1329 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1330 cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb,
1331 len, NULL, 0, (unsigned char *)&crc,
1336 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1341 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1343 switch (msg->lm_magic) {
1344 case LUSTRE_MSG_MAGIC_V2: {
1345 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1346 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1347 pb->pb_handle = *handle;
1351 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1355 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1357 switch (msg->lm_magic) {
1358 case LUSTRE_MSG_MAGIC_V2: {
1359 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1360 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1365 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1369 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1371 switch (msg->lm_magic) {
1372 case LUSTRE_MSG_MAGIC_V2: {
1373 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1374 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1379 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1383 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1385 switch (msg->lm_magic) {
1386 case LUSTRE_MSG_MAGIC_V2: {
1387 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1388 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1389 pb->pb_last_xid = last_xid;
1393 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1396 EXPORT_SYMBOL(lustre_msg_set_last_xid);
1398 void lustre_msg_set_tag(struct lustre_msg *msg, __u16 tag)
1400 switch (msg->lm_magic) {
1401 case LUSTRE_MSG_MAGIC_V2: {
1402 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1403 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1408 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1411 EXPORT_SYMBOL(lustre_msg_set_tag);
1413 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1415 switch (msg->lm_magic) {
1416 case LUSTRE_MSG_MAGIC_V2: {
1417 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1418 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1419 pb->pb_last_committed = last_committed;
1423 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1427 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions)
1429 switch (msg->lm_magic) {
1430 case LUSTRE_MSG_MAGIC_V2: {
1431 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1432 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1433 pb->pb_pre_versions[0] = versions[0];
1434 pb->pb_pre_versions[1] = versions[1];
1435 pb->pb_pre_versions[2] = versions[2];
1436 pb->pb_pre_versions[3] = versions[3];
1440 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1443 EXPORT_SYMBOL(lustre_msg_set_versions);
1445 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1447 switch (msg->lm_magic) {
1448 case LUSTRE_MSG_MAGIC_V2: {
1449 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1450 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1451 pb->pb_transno = transno;
1455 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1458 EXPORT_SYMBOL(lustre_msg_set_transno);
1460 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1462 switch (msg->lm_magic) {
1463 case LUSTRE_MSG_MAGIC_V2: {
1464 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1465 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1466 pb->pb_status = status;
1470 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1473 EXPORT_SYMBOL(lustre_msg_set_status);
1475 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1477 switch (msg->lm_magic) {
1478 case LUSTRE_MSG_MAGIC_V2: {
1479 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1480 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1481 pb->pb_conn_cnt = conn_cnt;
1485 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1489 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1491 switch (msg->lm_magic) {
1492 case LUSTRE_MSG_MAGIC_V2: {
1493 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1494 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1495 pb->pb_timeout = timeout;
1499 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1503 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1505 switch (msg->lm_magic) {
1506 case LUSTRE_MSG_MAGIC_V2: {
1507 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1508 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1509 pb->pb_service_time = service_time;
1513 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1517 void lustre_msg_set_jobid(struct lustre_msg *msg, char *jobid)
1519 switch (msg->lm_magic) {
1520 case LUSTRE_MSG_MAGIC_V2: {
1521 __u32 opc = lustre_msg_get_opc(msg);
1522 struct ptlrpc_body *pb;
1524 /* Don't set jobid for ldlm ast RPCs, they've been shrinked.
1525 * See the comment in ptlrpc_request_pack(). */
1526 if (!opc || opc == LDLM_BL_CALLBACK ||
1527 opc == LDLM_CP_CALLBACK || opc == LDLM_GL_CALLBACK)
1530 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
1531 sizeof(struct ptlrpc_body));
1532 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1535 memcpy(pb->pb_jobid, jobid, sizeof(pb->pb_jobid));
1536 else if (pb->pb_jobid[0] == '\0')
1537 lustre_get_jobid(pb->pb_jobid, sizeof(pb->pb_jobid));
1541 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1544 EXPORT_SYMBOL(lustre_msg_set_jobid);
1546 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1548 switch (msg->lm_magic) {
1549 case LUSTRE_MSG_MAGIC_V2:
1550 msg->lm_cksum = cksum;
1553 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1557 void lustre_msg_set_mbits(struct lustre_msg *msg, __u64 mbits)
1559 switch (msg->lm_magic) {
1560 case LUSTRE_MSG_MAGIC_V2: {
1561 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1563 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1564 pb->pb_mbits = mbits;
1568 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1572 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1574 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1576 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1577 req->rq_pill.rc_area[RCL_SERVER]);
1578 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1579 req->rq_reqmsg->lm_repsize = req->rq_replen;
1581 EXPORT_SYMBOL(ptlrpc_request_set_replen);
1583 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
1585 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1586 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1587 req->rq_reqmsg->lm_repsize = req->rq_replen;
1591 * Send a remote set_info_async.
1593 * This may go from client to server or server to client.
1595 int do_set_info_async(struct obd_import *imp,
1596 int opcode, int version,
1597 size_t keylen, void *key,
1598 size_t vallen, void *val,
1599 struct ptlrpc_request_set *set)
1601 struct ptlrpc_request *req;
1606 req = ptlrpc_request_alloc(imp, &RQF_OBD_SET_INFO);
1610 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1611 RCL_CLIENT, keylen);
1612 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1613 RCL_CLIENT, vallen);
1614 rc = ptlrpc_request_pack(req, version, opcode);
1616 ptlrpc_request_free(req);
1620 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1621 memcpy(tmp, key, keylen);
1622 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1623 memcpy(tmp, val, vallen);
1625 ptlrpc_request_set_replen(req);
1628 ptlrpc_set_add_req(set, req);
1629 ptlrpc_check_set(NULL, set);
1631 rc = ptlrpc_queue_wait(req);
1632 ptlrpc_req_finished(req);
1637 EXPORT_SYMBOL(do_set_info_async);
1639 /* byte flipping routines for all wire types declared in
1640 * lustre_idl.h implemented here.
1642 void lustre_swab_ptlrpc_body(struct ptlrpc_body *body)
1644 __swab32s(&body->pb_type);
1645 __swab32s(&body->pb_version);
1646 __swab32s(&body->pb_opc);
1647 __swab32s(&body->pb_status);
1648 __swab64s(&body->pb_last_xid);
1649 __swab16s(&body->pb_tag);
1650 CLASSERT(offsetof(typeof(*body), pb_padding0) != 0);
1651 CLASSERT(offsetof(typeof(*body), pb_padding1) != 0);
1652 __swab64s(&body->pb_last_committed);
1653 __swab64s(&body->pb_transno);
1654 __swab32s(&body->pb_flags);
1655 __swab32s(&body->pb_op_flags);
1656 __swab32s(&body->pb_conn_cnt);
1657 __swab32s(&body->pb_timeout);
1658 __swab32s(&body->pb_service_time);
1659 __swab32s(&body->pb_limit);
1660 __swab64s(&body->pb_slv);
1661 __swab64s(&body->pb_pre_versions[0]);
1662 __swab64s(&body->pb_pre_versions[1]);
1663 __swab64s(&body->pb_pre_versions[2]);
1664 __swab64s(&body->pb_pre_versions[3]);
1665 __swab64s(&body->pb_mbits);
1666 CLASSERT(offsetof(typeof(*body), pb_padding64_0) != 0);
1667 CLASSERT(offsetof(typeof(*body), pb_padding64_1) != 0);
1668 CLASSERT(offsetof(typeof(*body), pb_padding64_2) != 0);
1669 /* While we need to maintain compatibility between
1670 * clients and servers without ptlrpc_body_v2 (< 2.3)
1671 * do not swab any fields beyond pb_jobid, as we are
1672 * using this swab function for both ptlrpc_body
1673 * and ptlrpc_body_v2. */
1674 /* pb_jobid is an ASCII string and should not be swabbed */
1675 CLASSERT(offsetof(typeof(*body), pb_jobid) != 0);
1678 void lustre_swab_connect(struct obd_connect_data *ocd)
1680 __swab64s(&ocd->ocd_connect_flags);
1681 __swab32s(&ocd->ocd_version);
1682 __swab32s(&ocd->ocd_grant);
1683 __swab64s(&ocd->ocd_ibits_known);
1684 __swab32s(&ocd->ocd_index);
1685 __swab32s(&ocd->ocd_brw_size);
1686 /* ocd_blocksize and ocd_inodespace don't need to be swabbed because
1687 * they are 8-byte values */
1688 __swab16s(&ocd->ocd_grant_tax_kb);
1689 __swab32s(&ocd->ocd_grant_max_blks);
1690 __swab64s(&ocd->ocd_transno);
1691 __swab32s(&ocd->ocd_group);
1692 __swab32s(&ocd->ocd_cksum_types);
1693 __swab32s(&ocd->ocd_instance);
1694 /* Fields after ocd_cksum_types are only accessible by the receiver
1695 * if the corresponding flag in ocd_connect_flags is set. Accessing
1696 * any field after ocd_maxbytes on the receiver without a valid flag
1697 * may result in out-of-bound memory access and kernel oops. */
1698 if (ocd->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)
1699 __swab32s(&ocd->ocd_max_easize);
1700 if (ocd->ocd_connect_flags & OBD_CONNECT_MAXBYTES)
1701 __swab64s(&ocd->ocd_maxbytes);
1702 if (ocd->ocd_connect_flags & OBD_CONNECT_MULTIMODRPCS)
1703 __swab16s(&ocd->ocd_maxmodrpcs);
1704 CLASSERT(offsetof(typeof(*ocd), padding0) != 0);
1705 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1706 if (ocd->ocd_connect_flags & OBD_CONNECT_FLAGS2)
1707 __swab64s(&ocd->ocd_connect_flags2);
1708 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1709 CLASSERT(offsetof(typeof(*ocd), padding4) != 0);
1710 CLASSERT(offsetof(typeof(*ocd), padding5) != 0);
1711 CLASSERT(offsetof(typeof(*ocd), padding6) != 0);
1712 CLASSERT(offsetof(typeof(*ocd), padding7) != 0);
1713 CLASSERT(offsetof(typeof(*ocd), padding8) != 0);
1714 CLASSERT(offsetof(typeof(*ocd), padding9) != 0);
1715 CLASSERT(offsetof(typeof(*ocd), paddingA) != 0);
1716 CLASSERT(offsetof(typeof(*ocd), paddingB) != 0);
1717 CLASSERT(offsetof(typeof(*ocd), paddingC) != 0);
1718 CLASSERT(offsetof(typeof(*ocd), paddingD) != 0);
1719 CLASSERT(offsetof(typeof(*ocd), paddingE) != 0);
1720 CLASSERT(offsetof(typeof(*ocd), paddingF) != 0);
1723 static void lustre_swab_ost_layout(struct ost_layout *ol)
1725 __swab32s(&ol->ol_stripe_size);
1726 __swab32s(&ol->ol_stripe_count);
1727 __swab64s(&ol->ol_comp_start);
1728 __swab64s(&ol->ol_comp_end);
1729 __swab32s(&ol->ol_comp_id);
1732 void lustre_swab_obdo (struct obdo *o)
1734 __swab64s(&o->o_valid);
1735 lustre_swab_ost_id(&o->o_oi);
1736 __swab64s(&o->o_parent_seq);
1737 __swab64s(&o->o_size);
1738 __swab64s(&o->o_mtime);
1739 __swab64s(&o->o_atime);
1740 __swab64s(&o->o_ctime);
1741 __swab64s(&o->o_blocks);
1742 __swab64s(&o->o_grant);
1743 __swab32s(&o->o_blksize);
1744 __swab32s(&o->o_mode);
1745 __swab32s(&o->o_uid);
1746 __swab32s(&o->o_gid);
1747 __swab32s(&o->o_flags);
1748 __swab32s(&o->o_nlink);
1749 __swab32s(&o->o_parent_oid);
1750 __swab32s(&o->o_misc);
1751 __swab64s(&o->o_ioepoch);
1752 __swab32s(&o->o_stripe_idx);
1753 __swab32s(&o->o_parent_ver);
1754 lustre_swab_ost_layout(&o->o_layout);
1755 __swab32s(&o->o_layout_version);
1756 __swab32s(&o->o_uid_h);
1757 __swab32s(&o->o_gid_h);
1758 __swab64s(&o->o_data_version);
1759 __swab32s(&o->o_projid);
1760 CLASSERT(offsetof(typeof(*o), o_padding_4) != 0);
1761 CLASSERT(offsetof(typeof(*o), o_padding_5) != 0);
1762 CLASSERT(offsetof(typeof(*o), o_padding_6) != 0);
1765 EXPORT_SYMBOL(lustre_swab_obdo);
1767 void lustre_swab_obd_statfs (struct obd_statfs *os)
1769 __swab64s(&os->os_type);
1770 __swab64s(&os->os_blocks);
1771 __swab64s(&os->os_bfree);
1772 __swab64s(&os->os_bavail);
1773 __swab64s(&os->os_files);
1774 __swab64s(&os->os_ffree);
1775 /* no need to swab os_fsid */
1776 __swab32s(&os->os_bsize);
1777 __swab32s(&os->os_namelen);
1778 __swab64s(&os->os_maxbytes);
1779 __swab32s(&os->os_state);
1780 __swab32s(&os->os_fprecreated);
1781 __swab32s(&os->os_granted);
1782 CLASSERT(offsetof(typeof(*os), os_spare3) != 0);
1783 CLASSERT(offsetof(typeof(*os), os_spare4) != 0);
1784 CLASSERT(offsetof(typeof(*os), os_spare5) != 0);
1785 CLASSERT(offsetof(typeof(*os), os_spare6) != 0);
1786 CLASSERT(offsetof(typeof(*os), os_spare7) != 0);
1787 CLASSERT(offsetof(typeof(*os), os_spare8) != 0);
1788 CLASSERT(offsetof(typeof(*os), os_spare9) != 0);
1791 void lustre_swab_obd_ioobj(struct obd_ioobj *ioo)
1793 lustre_swab_ost_id(&ioo->ioo_oid);
1794 __swab32s(&ioo->ioo_max_brw);
1795 __swab32s(&ioo->ioo_bufcnt);
1798 void lustre_swab_niobuf_remote(struct niobuf_remote *nbr)
1800 __swab64s(&nbr->rnb_offset);
1801 __swab32s(&nbr->rnb_len);
1802 __swab32s(&nbr->rnb_flags);
1805 void lustre_swab_ost_body (struct ost_body *b)
1807 lustre_swab_obdo (&b->oa);
1810 void lustre_swab_ost_last_id(u64 *id)
1815 void lustre_swab_generic_32s(__u32 *val)
1820 void lustre_swab_gl_lquota_desc(struct ldlm_gl_lquota_desc *desc)
1822 lustre_swab_lu_fid(&desc->gl_id.qid_fid);
1823 __swab64s(&desc->gl_flags);
1824 __swab64s(&desc->gl_ver);
1825 __swab64s(&desc->gl_hardlimit);
1826 __swab64s(&desc->gl_softlimit);
1827 __swab64s(&desc->gl_time);
1828 CLASSERT(offsetof(typeof(*desc), gl_pad2) != 0);
1830 EXPORT_SYMBOL(lustre_swab_gl_lquota_desc);
1832 void lustre_swab_gl_barrier_desc(struct ldlm_gl_barrier_desc *desc)
1834 __swab32s(&desc->lgbd_status);
1835 __swab32s(&desc->lgbd_timeout);
1836 CLASSERT(offsetof(typeof(*desc), lgbd_padding) != 0);
1838 EXPORT_SYMBOL(lustre_swab_gl_barrier_desc);
1840 void lustre_swab_ost_lvb_v1(struct ost_lvb_v1 *lvb)
1842 __swab64s(&lvb->lvb_size);
1843 __swab64s(&lvb->lvb_mtime);
1844 __swab64s(&lvb->lvb_atime);
1845 __swab64s(&lvb->lvb_ctime);
1846 __swab64s(&lvb->lvb_blocks);
1848 EXPORT_SYMBOL(lustre_swab_ost_lvb_v1);
1850 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1852 __swab64s(&lvb->lvb_size);
1853 __swab64s(&lvb->lvb_mtime);
1854 __swab64s(&lvb->lvb_atime);
1855 __swab64s(&lvb->lvb_ctime);
1856 __swab64s(&lvb->lvb_blocks);
1857 __swab32s(&lvb->lvb_mtime_ns);
1858 __swab32s(&lvb->lvb_atime_ns);
1859 __swab32s(&lvb->lvb_ctime_ns);
1860 __swab32s(&lvb->lvb_padding);
1862 EXPORT_SYMBOL(lustre_swab_ost_lvb);
1864 void lustre_swab_lquota_lvb(struct lquota_lvb *lvb)
1866 __swab64s(&lvb->lvb_flags);
1867 __swab64s(&lvb->lvb_id_may_rel);
1868 __swab64s(&lvb->lvb_id_rel);
1869 __swab64s(&lvb->lvb_id_qunit);
1870 __swab64s(&lvb->lvb_pad1);
1872 EXPORT_SYMBOL(lustre_swab_lquota_lvb);
1874 void lustre_swab_barrier_lvb(struct barrier_lvb *lvb)
1876 __swab32s(&lvb->lvb_status);
1877 __swab32s(&lvb->lvb_index);
1878 CLASSERT(offsetof(typeof(*lvb), lvb_padding) != 0);
1880 EXPORT_SYMBOL(lustre_swab_barrier_lvb);
1882 void lustre_swab_mdt_body (struct mdt_body *b)
1884 lustre_swab_lu_fid(&b->mbo_fid1);
1885 lustre_swab_lu_fid(&b->mbo_fid2);
1886 /* handle is opaque */
1887 __swab64s(&b->mbo_valid);
1888 __swab64s(&b->mbo_size);
1889 __swab64s(&b->mbo_mtime);
1890 __swab64s(&b->mbo_atime);
1891 __swab64s(&b->mbo_ctime);
1892 __swab64s(&b->mbo_blocks);
1893 __swab64s(&b->mbo_version);
1894 __swab64s(&b->mbo_t_state);
1895 __swab32s(&b->mbo_fsuid);
1896 __swab32s(&b->mbo_fsgid);
1897 __swab32s(&b->mbo_capability);
1898 __swab32s(&b->mbo_mode);
1899 __swab32s(&b->mbo_uid);
1900 __swab32s(&b->mbo_gid);
1901 __swab32s(&b->mbo_flags);
1902 __swab32s(&b->mbo_rdev);
1903 __swab32s(&b->mbo_nlink);
1904 __swab32s(&b->mbo_layout_gen);
1905 __swab32s(&b->mbo_suppgid);
1906 __swab32s(&b->mbo_eadatasize);
1907 __swab32s(&b->mbo_aclsize);
1908 __swab32s(&b->mbo_max_mdsize);
1909 CLASSERT(offsetof(typeof(*b), mbo_unused3) != 0);
1910 __swab32s(&b->mbo_uid_h);
1911 __swab32s(&b->mbo_gid_h);
1912 __swab32s(&b->mbo_projid);
1913 __swab64s(&b->mbo_dom_size);
1914 __swab64s(&b->mbo_dom_blocks);
1915 CLASSERT(offsetof(typeof(*b), mbo_padding_8) != 0);
1916 CLASSERT(offsetof(typeof(*b), mbo_padding_9) != 0);
1917 CLASSERT(offsetof(typeof(*b), mbo_padding_10) != 0);
1920 void lustre_swab_mdt_ioepoch(struct mdt_ioepoch *b)
1922 /* mio_open_handle is opaque */
1923 CLASSERT(offsetof(typeof(*b), mio_unused1) != 0);
1924 CLASSERT(offsetof(typeof(*b), mio_unused2) != 0);
1925 CLASSERT(offsetof(typeof(*b), mio_padding) != 0);
1928 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1932 __swab32s(&mti->mti_lustre_ver);
1933 __swab32s(&mti->mti_stripe_index);
1934 __swab32s(&mti->mti_config_ver);
1935 __swab32s(&mti->mti_flags);
1936 __swab32s(&mti->mti_instance);
1937 __swab32s(&mti->mti_nid_count);
1938 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1939 for (i = 0; i < MTI_NIDS_MAX; i++)
1940 __swab64s(&mti->mti_nids[i]);
1943 void lustre_swab_mgs_nidtbl_entry(struct mgs_nidtbl_entry *entry)
1947 __swab64s(&entry->mne_version);
1948 __swab32s(&entry->mne_instance);
1949 __swab32s(&entry->mne_index);
1950 __swab32s(&entry->mne_length);
1952 /* mne_nid_(count|type) must be one byte size because we're gonna
1953 * access it w/o swapping. */
1954 CLASSERT(sizeof(entry->mne_nid_count) == sizeof(__u8));
1955 CLASSERT(sizeof(entry->mne_nid_type) == sizeof(__u8));
1957 /* remove this assertion if ipv6 is supported. */
1958 LASSERT(entry->mne_nid_type == 0);
1959 for (i = 0; i < entry->mne_nid_count; i++) {
1960 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1961 __swab64s(&entry->u.nids[i]);
1964 EXPORT_SYMBOL(lustre_swab_mgs_nidtbl_entry);
1966 void lustre_swab_mgs_config_body(struct mgs_config_body *body)
1968 __swab64s(&body->mcb_offset);
1969 __swab32s(&body->mcb_units);
1970 __swab16s(&body->mcb_type);
1973 void lustre_swab_mgs_config_res(struct mgs_config_res *body)
1975 __swab64s(&body->mcr_offset);
1976 __swab64s(&body->mcr_size);
1979 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1981 __swab64s (&i->dqi_bgrace);
1982 __swab64s (&i->dqi_igrace);
1983 __swab32s (&i->dqi_flags);
1984 __swab32s (&i->dqi_valid);
1987 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1989 __swab64s (&b->dqb_ihardlimit);
1990 __swab64s (&b->dqb_isoftlimit);
1991 __swab64s (&b->dqb_curinodes);
1992 __swab64s (&b->dqb_bhardlimit);
1993 __swab64s (&b->dqb_bsoftlimit);
1994 __swab64s (&b->dqb_curspace);
1995 __swab64s (&b->dqb_btime);
1996 __swab64s (&b->dqb_itime);
1997 __swab32s (&b->dqb_valid);
1998 CLASSERT(offsetof(typeof(*b), dqb_padding) != 0);
2001 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
2003 __swab32s (&q->qc_cmd);
2004 __swab32s (&q->qc_type);
2005 __swab32s (&q->qc_id);
2006 __swab32s (&q->qc_stat);
2007 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
2008 lustre_swab_obd_dqblk (&q->qc_dqblk);
2011 void lustre_swab_fid2path(struct getinfo_fid2path *gf)
2013 lustre_swab_lu_fid(&gf->gf_fid);
2014 __swab64s(&gf->gf_recno);
2015 __swab32s(&gf->gf_linkno);
2016 __swab32s(&gf->gf_pathlen);
2018 EXPORT_SYMBOL(lustre_swab_fid2path);
2020 static void lustre_swab_fiemap_extent(struct fiemap_extent *fm_extent)
2022 __swab64s(&fm_extent->fe_logical);
2023 __swab64s(&fm_extent->fe_physical);
2024 __swab64s(&fm_extent->fe_length);
2025 __swab32s(&fm_extent->fe_flags);
2026 __swab32s(&fm_extent->fe_device);
2029 static void lustre_swab_fiemap_hdr(struct fiemap *fiemap)
2031 __swab64s(&fiemap->fm_start);
2032 __swab64s(&fiemap->fm_length);
2033 __swab32s(&fiemap->fm_flags);
2034 __swab32s(&fiemap->fm_mapped_extents);
2035 __swab32s(&fiemap->fm_extent_count);
2036 __swab32s(&fiemap->fm_reserved);
2039 void lustre_swab_fiemap(struct fiemap *fiemap)
2043 lustre_swab_fiemap_hdr(fiemap);
2045 for (i = 0; i < fiemap->fm_mapped_extents; i++)
2046 lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
2049 void lustre_swab_fiemap_info_key(struct ll_fiemap_info_key *fiemap_info)
2051 lustre_swab_obdo(&fiemap_info->lfik_oa);
2052 lustre_swab_fiemap_hdr(&fiemap_info->lfik_fiemap);
2055 void lustre_swab_idx_info(struct idx_info *ii)
2057 __swab32s(&ii->ii_magic);
2058 __swab32s(&ii->ii_flags);
2059 __swab16s(&ii->ii_count);
2060 __swab32s(&ii->ii_attrs);
2061 lustre_swab_lu_fid(&ii->ii_fid);
2062 __swab64s(&ii->ii_version);
2063 __swab64s(&ii->ii_hash_start);
2064 __swab64s(&ii->ii_hash_end);
2065 __swab16s(&ii->ii_keysize);
2066 __swab16s(&ii->ii_recsize);
2069 void lustre_swab_lip_header(struct lu_idxpage *lip)
2072 __swab32s(&lip->lip_magic);
2073 __swab16s(&lip->lip_flags);
2074 __swab16s(&lip->lip_nr);
2076 EXPORT_SYMBOL(lustre_swab_lip_header);
2078 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
2080 __swab32s(&rr->rr_opcode);
2081 __swab32s(&rr->rr_cap);
2082 __swab32s(&rr->rr_fsuid);
2083 /* rr_fsuid_h is unused */
2084 __swab32s(&rr->rr_fsgid);
2085 /* rr_fsgid_h is unused */
2086 __swab32s(&rr->rr_suppgid1);
2087 /* rr_suppgid1_h is unused */
2088 __swab32s(&rr->rr_suppgid2);
2089 /* rr_suppgid2_h is unused */
2090 lustre_swab_lu_fid(&rr->rr_fid1);
2091 lustre_swab_lu_fid(&rr->rr_fid2);
2092 __swab64s(&rr->rr_mtime);
2093 __swab64s(&rr->rr_atime);
2094 __swab64s(&rr->rr_ctime);
2095 __swab64s(&rr->rr_size);
2096 __swab64s(&rr->rr_blocks);
2097 __swab32s(&rr->rr_bias);
2098 __swab32s(&rr->rr_mode);
2099 __swab32s(&rr->rr_flags);
2100 __swab32s(&rr->rr_flags_h);
2101 __swab32s(&rr->rr_umask);
2102 __swab16s(&rr->rr_mirror_id);
2104 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
2107 void lustre_swab_lov_desc (struct lov_desc *ld)
2109 __swab32s (&ld->ld_tgt_count);
2110 __swab32s (&ld->ld_active_tgt_count);
2111 __swab32s (&ld->ld_default_stripe_count);
2112 __swab32s (&ld->ld_pattern);
2113 __swab64s (&ld->ld_default_stripe_size);
2114 __swab64s (&ld->ld_default_stripe_offset);
2115 __swab32s (&ld->ld_qos_maxage);
2116 /* uuid endian insensitive */
2118 EXPORT_SYMBOL(lustre_swab_lov_desc);
2120 void lustre_swab_lmv_desc (struct lmv_desc *ld)
2122 __swab32s (&ld->ld_tgt_count);
2123 __swab32s (&ld->ld_active_tgt_count);
2124 __swab32s (&ld->ld_default_stripe_count);
2125 __swab32s (&ld->ld_pattern);
2126 __swab64s (&ld->ld_default_hash_size);
2127 __swab32s (&ld->ld_qos_maxage);
2128 /* uuid endian insensitive */
2131 /* This structure is always in little-endian */
2132 static void lustre_swab_lmv_mds_md_v1(struct lmv_mds_md_v1 *lmm1)
2136 __swab32s(&lmm1->lmv_magic);
2137 __swab32s(&lmm1->lmv_stripe_count);
2138 __swab32s(&lmm1->lmv_master_mdt_index);
2139 __swab32s(&lmm1->lmv_hash_type);
2140 __swab32s(&lmm1->lmv_layout_version);
2141 for (i = 0; i < lmm1->lmv_stripe_count; i++)
2142 lustre_swab_lu_fid(&lmm1->lmv_stripe_fids[i]);
2145 void lustre_swab_lmv_mds_md(union lmv_mds_md *lmm)
2147 switch (lmm->lmv_magic) {
2149 lustre_swab_lmv_mds_md_v1(&lmm->lmv_md_v1);
2155 EXPORT_SYMBOL(lustre_swab_lmv_mds_md);
2157 void lustre_swab_lmv_user_md_objects(struct lmv_user_mds_data *lmd,
2162 for (i = 0; i < stripe_count; i++)
2163 __swab32s(&(lmd[i].lum_mds));
2165 EXPORT_SYMBOL(lustre_swab_lmv_user_md_objects);
2168 void lustre_swab_lmv_user_md(struct lmv_user_md *lum)
2170 __u32 count = lum->lum_stripe_count;
2172 __swab32s(&lum->lum_magic);
2173 __swab32s(&lum->lum_stripe_count);
2174 __swab32s(&lum->lum_stripe_offset);
2175 __swab32s(&lum->lum_hash_type);
2176 __swab32s(&lum->lum_type);
2177 CLASSERT(offsetof(typeof(*lum), lum_padding1) != 0);
2178 switch (lum->lum_magic) {
2179 case LMV_USER_MAGIC_SPECIFIC:
2180 count = lum->lum_stripe_count;
2181 case __swab32(LMV_USER_MAGIC_SPECIFIC):
2182 lustre_swab_lmv_user_md_objects(lum->lum_objects, count);
2188 EXPORT_SYMBOL(lustre_swab_lmv_user_md);
2190 static void lustre_print_v1v3(unsigned int lvl, struct lov_user_md *lum,
2193 CDEBUG(lvl, "%s lov_user_md %p:\n", msg, lum);
2194 CDEBUG(lvl, "\tlmm_magic: %#x\n", lum->lmm_magic);
2195 CDEBUG(lvl, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2196 CDEBUG(lvl, "\tlmm_object_id: %llu\n", lmm_oi_id(&lum->lmm_oi));
2197 CDEBUG(lvl, "\tlmm_object_gr: %llu\n", lmm_oi_seq(&lum->lmm_oi));
2198 CDEBUG(lvl, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2199 CDEBUG(lvl, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2200 CDEBUG(lvl, "\tlmm_stripe_offset/lmm_layout_gen: %#x\n",
2201 lum->lmm_stripe_offset);
2202 if (lum->lmm_magic == LOV_USER_MAGIC_V3) {
2203 struct lov_user_md_v3 *v3 = (void *)lum;
2204 CDEBUG(lvl, "\tlmm_pool_name: %s\n", v3->lmm_pool_name);
2206 if (lum->lmm_magic == LOV_USER_MAGIC_SPECIFIC) {
2207 struct lov_user_md_v3 *v3 = (void *)lum;
2210 if (v3->lmm_pool_name[0] != '\0')
2211 CDEBUG(lvl, "\tlmm_pool_name: %s\n", v3->lmm_pool_name);
2213 CDEBUG(lvl, "\ttarget list:\n");
2214 for (i = 0; i < v3->lmm_stripe_count; i++)
2215 CDEBUG(lvl, "\t\t%u\n", v3->lmm_objects[i].l_ost_idx);
2219 void lustre_print_user_md(unsigned int lvl, struct lov_user_md *lum,
2222 struct lov_comp_md_v1 *comp_v1;
2225 if (likely(!cfs_cdebug_show(lvl, DEBUG_SUBSYSTEM)))
2228 if (lum->lmm_magic == LOV_USER_MAGIC_V1 ||
2229 lum->lmm_magic == LOV_USER_MAGIC_V3) {
2230 lustre_print_v1v3(lvl, lum, msg);
2234 if (lum->lmm_magic != LOV_USER_MAGIC_COMP_V1) {
2235 CDEBUG(lvl, "%s: bad magic: %x\n", msg, lum->lmm_magic);
2239 comp_v1 = (struct lov_comp_md_v1 *)lum;
2240 CDEBUG(lvl, "%s: lov_comp_md_v1 %p:\n", msg, lum);
2241 CDEBUG(lvl, "\tlcm_magic: %#x\n", comp_v1->lcm_magic);
2242 CDEBUG(lvl, "\tlcm_size: %#x\n", comp_v1->lcm_size);
2243 CDEBUG(lvl, "\tlcm_layout_gen: %#x\n", comp_v1->lcm_layout_gen);
2244 CDEBUG(lvl, "\tlcm_flags: %#x\n", comp_v1->lcm_flags);
2245 CDEBUG(lvl, "\tlcm_entry_count: %#x\n\n", comp_v1->lcm_entry_count);
2246 CDEBUG(lvl, "\tlcm_mirror_count: %#x\n\n", comp_v1->lcm_mirror_count);
2248 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
2249 struct lov_comp_md_entry_v1 *ent = &comp_v1->lcm_entries[i];
2250 struct lov_user_md *v1;
2252 CDEBUG(lvl, "\tentry %d:\n", i);
2253 CDEBUG(lvl, "\tlcme_id: %#x\n", ent->lcme_id);
2254 CDEBUG(lvl, "\tlcme_flags: %#x\n", ent->lcme_flags);
2255 if (ent->lcme_flags & LCME_FL_NOSYNC)
2256 CDEBUG(lvl, "\tlcme_timestamp: %llu\n",
2257 ent->lcme_timestamp);
2258 CDEBUG(lvl, "\tlcme_extent.e_start: %llu\n",
2259 ent->lcme_extent.e_start);
2260 CDEBUG(lvl, "\tlcme_extent.e_end: %llu\n",
2261 ent->lcme_extent.e_end);
2262 CDEBUG(lvl, "\tlcme_offset: %#x\n", ent->lcme_offset);
2263 CDEBUG(lvl, "\tlcme_size: %#x\n\n", ent->lcme_size);
2265 v1 = (struct lov_user_md *)((char *)comp_v1 +
2266 comp_v1->lcm_entries[i].lcme_offset);
2267 lustre_print_v1v3(lvl, v1, msg);
2270 EXPORT_SYMBOL(lustre_print_user_md);
2272 static void lustre_swab_lmm_oi(struct ost_id *oi)
2274 __swab64s(&oi->oi.oi_id);
2275 __swab64s(&oi->oi.oi_seq);
2278 static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
2281 __swab32s(&lum->lmm_magic);
2282 __swab32s(&lum->lmm_pattern);
2283 lustre_swab_lmm_oi(&lum->lmm_oi);
2284 __swab32s(&lum->lmm_stripe_size);
2285 __swab16s(&lum->lmm_stripe_count);
2286 __swab16s(&lum->lmm_stripe_offset);
2290 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
2293 CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
2294 lustre_swab_lov_user_md_common(lum);
2297 EXPORT_SYMBOL(lustre_swab_lov_user_md_v1);
2299 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum)
2302 CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
2303 lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
2304 /* lmm_pool_name nothing to do with char */
2307 EXPORT_SYMBOL(lustre_swab_lov_user_md_v3);
2309 void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum)
2311 struct lov_comp_md_entry_v1 *ent;
2312 struct lov_user_md_v1 *v1;
2313 struct lov_user_md_v3 *v3;
2317 __u16 ent_count, stripe_count;
2320 cpu_endian = lum->lcm_magic == LOV_USER_MAGIC_COMP_V1;
2321 ent_count = lum->lcm_entry_count;
2323 __swab16s(&ent_count);
2325 CDEBUG(D_IOCTL, "swabbing lov_user_comp_md v1\n");
2326 __swab32s(&lum->lcm_magic);
2327 __swab32s(&lum->lcm_size);
2328 __swab32s(&lum->lcm_layout_gen);
2329 __swab16s(&lum->lcm_flags);
2330 __swab16s(&lum->lcm_entry_count);
2331 __swab16s(&lum->lcm_mirror_count);
2332 CLASSERT(offsetof(typeof(*lum), lcm_padding1) != 0);
2333 CLASSERT(offsetof(typeof(*lum), lcm_padding2) != 0);
2335 for (i = 0; i < ent_count; i++) {
2336 ent = &lum->lcm_entries[i];
2337 off = ent->lcme_offset;
2338 size = ent->lcme_size;
2344 __swab32s(&ent->lcme_id);
2345 __swab32s(&ent->lcme_flags);
2346 __swab64s(&ent->lcme_timestamp);
2347 __swab64s(&ent->lcme_extent.e_start);
2348 __swab64s(&ent->lcme_extent.e_end);
2349 __swab32s(&ent->lcme_offset);
2350 __swab32s(&ent->lcme_size);
2351 __swab32s(&ent->lcme_layout_gen);
2352 CLASSERT(offsetof(typeof(*ent), lcme_padding_1) != 0);
2354 v1 = (struct lov_user_md_v1 *)((char *)lum + off);
2355 stripe_count = v1->lmm_stripe_count;
2357 __swab16s(&stripe_count);
2359 if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1) ||
2360 v1->lmm_magic == LOV_USER_MAGIC_V1) {
2361 lustre_swab_lov_user_md_v1(v1);
2362 if (size > sizeof(*v1))
2363 lustre_swab_lov_user_md_objects(v1->lmm_objects,
2365 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3) ||
2366 v1->lmm_magic == LOV_USER_MAGIC_V3 ||
2367 v1->lmm_magic == __swab32(LOV_USER_MAGIC_SPECIFIC) ||
2368 v1->lmm_magic == LOV_USER_MAGIC_SPECIFIC) {
2369 v3 = (struct lov_user_md_v3 *)v1;
2370 lustre_swab_lov_user_md_v3(v3);
2371 if (size > sizeof(*v3))
2372 lustre_swab_lov_user_md_objects(v3->lmm_objects,
2375 CERROR("Invalid magic %#x\n", v1->lmm_magic);
2379 EXPORT_SYMBOL(lustre_swab_lov_comp_md_v1);
2381 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
2386 for (i = 0; i < stripe_count; i++) {
2387 lustre_swab_ost_id(&(lod[i].l_ost_oi));
2388 __swab32s(&(lod[i].l_ost_gen));
2389 __swab32s(&(lod[i].l_ost_idx));
2393 EXPORT_SYMBOL(lustre_swab_lov_user_md_objects);
2395 void lustre_swab_lov_user_md(struct lov_user_md *lum, size_t size)
2397 struct lov_user_md_v1 *v1;
2398 struct lov_user_md_v3 *v3;
2402 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2403 switch (lum->lmm_magic) {
2404 case __swab32(LOV_MAGIC_V1):
2405 case LOV_USER_MAGIC_V1:
2407 v1 = (struct lov_user_md_v1 *)lum;
2408 stripe_count = v1->lmm_stripe_count;
2410 if (lum->lmm_magic != LOV_USER_MAGIC_V1)
2411 __swab16s(&stripe_count);
2413 lustre_swab_lov_user_md_v1(v1);
2414 if (size > sizeof(*v1))
2415 lustre_swab_lov_user_md_objects(v1->lmm_objects,
2420 case __swab32(LOV_MAGIC_V3):
2421 case LOV_USER_MAGIC_V3:
2423 v3 = (struct lov_user_md_v3 *)lum;
2424 stripe_count = v3->lmm_stripe_count;
2426 if (lum->lmm_magic != LOV_USER_MAGIC_V3)
2427 __swab16s(&stripe_count);
2429 lustre_swab_lov_user_md_v3(v3);
2430 if (size > sizeof(*v3))
2431 lustre_swab_lov_user_md_objects(v3->lmm_objects,
2435 case __swab32(LOV_USER_MAGIC_SPECIFIC):
2436 case LOV_USER_MAGIC_SPECIFIC:
2438 v3 = (struct lov_user_md_v3 *)lum;
2439 stripe_count = v3->lmm_stripe_count;
2441 if (lum->lmm_magic != LOV_USER_MAGIC_SPECIFIC)
2442 __swab16s(&stripe_count);
2444 lustre_swab_lov_user_md_v3(v3);
2445 lustre_swab_lov_user_md_objects(v3->lmm_objects, stripe_count);
2448 case __swab32(LOV_MAGIC_COMP_V1):
2449 case LOV_USER_MAGIC_COMP_V1:
2450 lustre_swab_lov_comp_md_v1((struct lov_comp_md_v1 *)lum);
2453 CDEBUG(D_IOCTL, "Invalid LOV magic %08x\n", lum->lmm_magic);
2456 EXPORT_SYMBOL(lustre_swab_lov_user_md);
2458 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2461 CDEBUG(D_IOCTL, "swabbing lov_mds_md\n");
2462 __swab32s(&lmm->lmm_magic);
2463 __swab32s(&lmm->lmm_pattern);
2464 lustre_swab_lmm_oi(&lmm->lmm_oi);
2465 __swab32s(&lmm->lmm_stripe_size);
2466 __swab16s(&lmm->lmm_stripe_count);
2467 __swab16s(&lmm->lmm_layout_gen);
2470 EXPORT_SYMBOL(lustre_swab_lov_mds_md);
2472 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2476 for (i = 0; i < RES_NAME_SIZE; i++)
2477 __swab64s (&id->name[i]);
2480 void lustre_swab_ldlm_policy_data(union ldlm_wire_policy_data *d)
2482 /* the lock data is a union and the first two fields are always an
2483 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2484 * data the same way. */
2485 __swab64s(&d->l_extent.start);
2486 __swab64s(&d->l_extent.end);
2487 __swab64s(&d->l_extent.gid);
2488 __swab64s(&d->l_flock.lfw_owner);
2489 __swab32s(&d->l_flock.lfw_pid);
2492 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2497 void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r)
2499 __swab32s(&r->lr_type);
2500 CLASSERT(offsetof(typeof(*r), lr_pad) != 0);
2501 lustre_swab_ldlm_res_id(&r->lr_name);
2504 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2506 lustre_swab_ldlm_resource_desc (&l->l_resource);
2507 __swab32s (&l->l_req_mode);
2508 __swab32s (&l->l_granted_mode);
2509 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2512 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2514 __swab32s (&rq->lock_flags);
2515 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2516 __swab32s (&rq->lock_count);
2517 /* lock_handle[] opaque */
2520 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2522 __swab32s (&r->lock_flags);
2523 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2524 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2525 /* lock_handle opaque */
2526 __swab64s (&r->lock_policy_res1);
2527 __swab64s (&r->lock_policy_res2);
2530 void lustre_swab_quota_body(struct quota_body *b)
2532 lustre_swab_lu_fid(&b->qb_fid);
2533 lustre_swab_lu_fid((struct lu_fid *)&b->qb_id);
2534 __swab32s(&b->qb_flags);
2535 __swab64s(&b->qb_count);
2536 __swab64s(&b->qb_usage);
2537 __swab64s(&b->qb_slv_ver);
2540 /* Dump functions */
2541 void dump_ioo(struct obd_ioobj *ioo)
2544 "obd_ioobj: ioo_oid="DOSTID", ioo_max_brw=%#x, "
2545 "ioo_bufct=%d\n", POSTID(&ioo->ioo_oid), ioo->ioo_max_brw,
2549 void dump_rniobuf(struct niobuf_remote *nb)
2551 CDEBUG(D_RPCTRACE, "niobuf_remote: offset=%llu, len=%d, flags=%x\n",
2552 nb->rnb_offset, nb->rnb_len, nb->rnb_flags);
2555 void dump_obdo(struct obdo *oa)
2557 u64 valid = oa->o_valid;
2559 CDEBUG(D_RPCTRACE, "obdo: o_valid = %#llx\n", valid);
2560 if (valid & OBD_MD_FLID)
2561 CDEBUG(D_RPCTRACE, "obdo: id = "DOSTID"\n", POSTID(&oa->o_oi));
2562 if (valid & OBD_MD_FLFID)
2563 CDEBUG(D_RPCTRACE, "obdo: o_parent_seq = %#llx\n",
2565 if (valid & OBD_MD_FLSIZE)
2566 CDEBUG(D_RPCTRACE, "obdo: o_size = %lld\n", oa->o_size);
2567 if (valid & OBD_MD_FLMTIME)
2568 CDEBUG(D_RPCTRACE, "obdo: o_mtime = %lld\n", oa->o_mtime);
2569 if (valid & OBD_MD_FLATIME)
2570 CDEBUG(D_RPCTRACE, "obdo: o_atime = %lld\n", oa->o_atime);
2571 if (valid & OBD_MD_FLCTIME)
2572 CDEBUG(D_RPCTRACE, "obdo: o_ctime = %lld\n", oa->o_ctime);
2573 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
2574 CDEBUG(D_RPCTRACE, "obdo: o_blocks = %lld\n", oa->o_blocks);
2575 if (valid & OBD_MD_FLGRANT)
2576 CDEBUG(D_RPCTRACE, "obdo: o_grant = %lld\n", oa->o_grant);
2577 if (valid & OBD_MD_FLBLKSZ)
2578 CDEBUG(D_RPCTRACE, "obdo: o_blksize = %d\n", oa->o_blksize);
2579 if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
2580 CDEBUG(D_RPCTRACE, "obdo: o_mode = %o\n",
2581 oa->o_mode & ((valid & OBD_MD_FLTYPE ? S_IFMT : 0) |
2582 (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
2583 if (valid & OBD_MD_FLUID)
2584 CDEBUG(D_RPCTRACE, "obdo: o_uid = %u\n", oa->o_uid);
2585 if (valid & OBD_MD_FLUID)
2586 CDEBUG(D_RPCTRACE, "obdo: o_uid_h = %u\n", oa->o_uid_h);
2587 if (valid & OBD_MD_FLGID)
2588 CDEBUG(D_RPCTRACE, "obdo: o_gid = %u\n", oa->o_gid);
2589 if (valid & OBD_MD_FLGID)
2590 CDEBUG(D_RPCTRACE, "obdo: o_gid_h = %u\n", oa->o_gid_h);
2591 if (valid & OBD_MD_FLFLAGS)
2592 CDEBUG(D_RPCTRACE, "obdo: o_flags = %x\n", oa->o_flags);
2593 if (valid & OBD_MD_FLNLINK)
2594 CDEBUG(D_RPCTRACE, "obdo: o_nlink = %u\n", oa->o_nlink);
2595 else if (valid & OBD_MD_FLCKSUM)
2596 CDEBUG(D_RPCTRACE, "obdo: o_checksum (o_nlink) = %u\n",
2598 if (valid & OBD_MD_FLPARENT)
2599 CDEBUG(D_RPCTRACE, "obdo: o_parent_oid = %x\n",
2601 if (valid & OBD_MD_FLFID) {
2602 CDEBUG(D_RPCTRACE, "obdo: o_stripe_idx = %u\n",
2604 CDEBUG(D_RPCTRACE, "obdo: o_parent_ver = %x\n",
2607 if (valid & OBD_MD_FLHANDLE)
2608 CDEBUG(D_RPCTRACE, "obdo: o_handle = %lld\n",
2609 oa->o_handle.cookie);
2612 void dump_ost_body(struct ost_body *ob)
2617 void dump_rcs(__u32 *rc)
2619 CDEBUG(D_RPCTRACE, "rmf_rcs: %d\n", *rc);
2622 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2624 LASSERT(req->rq_reqmsg);
2626 switch (req->rq_reqmsg->lm_magic) {
2627 case LUSTRE_MSG_MAGIC_V2:
2628 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2630 CERROR("bad lustre msg magic: %#08X\n",
2631 req->rq_reqmsg->lm_magic);
2636 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2638 if (unlikely(!req->rq_repmsg))
2641 switch (req->rq_repmsg->lm_magic) {
2642 case LUSTRE_MSG_MAGIC_V2:
2643 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2645 /* uninitialized yet */
2650 void _debug_req(struct ptlrpc_request *req,
2651 struct libcfs_debug_msg_data *msgdata, const char *fmt, ...)
2653 bool req_ok = req->rq_reqmsg != NULL;
2654 bool rep_ok = false;
2655 lnet_nid_t nid = LNET_NID_ANY;
2658 int rep_status = -1;
2660 spin_lock(&req->rq_early_free_lock);
2664 if (ptlrpc_req_need_swab(req)) {
2665 req_ok = req_ok && req_ptlrpc_body_swabbed(req);
2666 rep_ok = rep_ok && rep_ptlrpc_body_swabbed(req);
2670 rep_flags = lustre_msg_get_flags(req->rq_repmsg);
2671 rep_status = lustre_msg_get_status(req->rq_repmsg);
2673 spin_unlock(&req->rq_early_free_lock);
2675 if (req->rq_import && req->rq_import->imp_connection)
2676 nid = req->rq_import->imp_connection->c_peer.nid;
2677 else if (req->rq_export && req->rq_export->exp_connection)
2678 nid = req->rq_export->exp_connection->c_peer.nid;
2680 va_start(args, fmt);
2681 libcfs_debug_vmsg2(msgdata, fmt, args,
2682 " 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",
2683 req, req->rq_xid, req->rq_transno,
2684 req_ok ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2685 req_ok ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2687 req->rq_import->imp_obd->obd_name :
2689 req->rq_export->exp_client_uuid.uuid :
2691 libcfs_nid2str(nid),
2692 req->rq_request_portal, req->rq_reply_portal,
2693 req->rq_reqlen, req->rq_replen,
2694 req->rq_early_count, (s64)req->rq_timedout,
2695 (s64)req->rq_deadline,
2696 atomic_read(&req->rq_refcount),
2697 DEBUG_REQ_FLAGS(req),
2698 req_ok ? lustre_msg_get_flags(req->rq_reqmsg) : -1,
2699 rep_flags, req->rq_status, rep_status);
2702 EXPORT_SYMBOL(_debug_req);
2704 void lustre_swab_lustre_capa(struct lustre_capa *c)
2706 lustre_swab_lu_fid(&c->lc_fid);
2707 __swab64s (&c->lc_opc);
2708 __swab64s (&c->lc_uid);
2709 __swab64s (&c->lc_gid);
2710 __swab32s (&c->lc_flags);
2711 __swab32s (&c->lc_keyid);
2712 __swab32s (&c->lc_timeout);
2713 __swab32s (&c->lc_expiry);
2716 void lustre_swab_lustre_capa_key(struct lustre_capa_key *k)
2718 __swab64s (&k->lk_seq);
2719 __swab32s (&k->lk_keyid);
2720 CLASSERT(offsetof(typeof(*k), lk_padding) != 0);
2723 void lustre_swab_hsm_user_state(struct hsm_user_state *state)
2725 __swab32s(&state->hus_states);
2726 __swab32s(&state->hus_archive_id);
2729 void lustre_swab_hsm_state_set(struct hsm_state_set *hss)
2731 __swab32s(&hss->hss_valid);
2732 __swab64s(&hss->hss_setmask);
2733 __swab64s(&hss->hss_clearmask);
2734 __swab32s(&hss->hss_archive_id);
2737 static void lustre_swab_hsm_extent(struct hsm_extent *extent)
2739 __swab64s(&extent->offset);
2740 __swab64s(&extent->length);
2743 void lustre_swab_hsm_current_action(struct hsm_current_action *action)
2745 __swab32s(&action->hca_state);
2746 __swab32s(&action->hca_action);
2747 lustre_swab_hsm_extent(&action->hca_location);
2750 void lustre_swab_hsm_user_item(struct hsm_user_item *hui)
2752 lustre_swab_lu_fid(&hui->hui_fid);
2753 lustre_swab_hsm_extent(&hui->hui_extent);
2756 void lustre_swab_lu_extent(struct lu_extent *le)
2758 __swab64s(&le->e_start);
2759 __swab64s(&le->e_end);
2762 void lustre_swab_layout_intent(struct layout_intent *li)
2764 __swab32s(&li->li_opc);
2765 __swab32s(&li->li_flags);
2766 lustre_swab_lu_extent(&li->li_extent);
2769 void lustre_swab_hsm_progress_kernel(struct hsm_progress_kernel *hpk)
2771 lustre_swab_lu_fid(&hpk->hpk_fid);
2772 __swab64s(&hpk->hpk_cookie);
2773 __swab64s(&hpk->hpk_extent.offset);
2774 __swab64s(&hpk->hpk_extent.length);
2775 __swab16s(&hpk->hpk_flags);
2776 __swab16s(&hpk->hpk_errval);
2779 void lustre_swab_hsm_request(struct hsm_request *hr)
2781 __swab32s(&hr->hr_action);
2782 __swab32s(&hr->hr_archive_id);
2783 __swab64s(&hr->hr_flags);
2784 __swab32s(&hr->hr_itemcount);
2785 __swab32s(&hr->hr_data_len);
2788 void lustre_swab_object_update(struct object_update *ou)
2790 struct object_update_param *param;
2793 __swab16s(&ou->ou_type);
2794 __swab16s(&ou->ou_params_count);
2795 __swab32s(&ou->ou_result_size);
2796 __swab32s(&ou->ou_flags);
2797 __swab32s(&ou->ou_padding1);
2798 __swab64s(&ou->ou_batchid);
2799 lustre_swab_lu_fid(&ou->ou_fid);
2800 param = &ou->ou_params[0];
2801 for (i = 0; i < ou->ou_params_count; i++) {
2802 __swab16s(¶m->oup_len);
2803 __swab16s(¶m->oup_padding);
2804 __swab32s(¶m->oup_padding2);
2805 param = (struct object_update_param *)((char *)param +
2806 object_update_param_size(param));
2810 void lustre_swab_object_update_request(struct object_update_request *our)
2813 __swab32s(&our->ourq_magic);
2814 __swab16s(&our->ourq_count);
2815 __swab16s(&our->ourq_padding);
2816 for (i = 0; i < our->ourq_count; i++) {
2817 struct object_update *ou;
2819 ou = object_update_request_get(our, i, NULL);
2822 lustre_swab_object_update(ou);
2826 void lustre_swab_object_update_result(struct object_update_result *our)
2828 __swab32s(&our->our_rc);
2829 __swab16s(&our->our_datalen);
2830 __swab16s(&our->our_padding);
2833 void lustre_swab_object_update_reply(struct object_update_reply *our)
2837 __swab32s(&our->ourp_magic);
2838 __swab16s(&our->ourp_count);
2839 __swab16s(&our->ourp_padding);
2840 for (i = 0; i < our->ourp_count; i++) {
2841 struct object_update_result *ourp;
2843 __swab16s(&our->ourp_lens[i]);
2844 ourp = object_update_result_get(our, i, NULL);
2847 lustre_swab_object_update_result(ourp);
2851 void lustre_swab_out_update_header(struct out_update_header *ouh)
2853 __swab32s(&ouh->ouh_magic);
2854 __swab32s(&ouh->ouh_count);
2855 __swab32s(&ouh->ouh_inline_length);
2856 __swab32s(&ouh->ouh_reply_size);
2858 EXPORT_SYMBOL(lustre_swab_out_update_header);
2860 void lustre_swab_out_update_buffer(struct out_update_buffer *oub)
2862 __swab32s(&oub->oub_size);
2863 __swab32s(&oub->oub_padding);
2865 EXPORT_SYMBOL(lustre_swab_out_update_buffer);
2867 void lustre_swab_swap_layouts(struct mdc_swap_layouts *msl)
2869 __swab64s(&msl->msl_flags);
2872 void lustre_swab_close_data(struct close_data *cd)
2874 lustre_swab_lu_fid(&cd->cd_fid);
2875 __swab64s(&cd->cd_data_version);
2878 void lustre_swab_close_data_resync_done(struct close_data_resync_done *resync)
2882 __swab32s(&resync->resync_count);
2883 /* after swab, resync_count must in CPU endian */
2884 if (resync->resync_count <= INLINE_RESYNC_ARRAY_SIZE) {
2885 for (i = 0; i < resync->resync_count; i++)
2886 __swab32s(&resync->resync_ids_inline[i]);
2889 EXPORT_SYMBOL(lustre_swab_close_data_resync_done);
2891 void lustre_swab_lfsck_request(struct lfsck_request *lr)
2893 __swab32s(&lr->lr_event);
2894 __swab32s(&lr->lr_index);
2895 __swab32s(&lr->lr_flags);
2896 __swab32s(&lr->lr_valid);
2897 __swab32s(&lr->lr_speed);
2898 __swab16s(&lr->lr_version);
2899 __swab16s(&lr->lr_active);
2900 __swab16s(&lr->lr_param);
2901 __swab16s(&lr->lr_async_windows);
2902 __swab32s(&lr->lr_flags);
2903 lustre_swab_lu_fid(&lr->lr_fid);
2904 lustre_swab_lu_fid(&lr->lr_fid2);
2905 __swab32s(&lr->lr_comp_id);
2906 CLASSERT(offsetof(typeof(*lr), lr_padding_0) != 0);
2907 CLASSERT(offsetof(typeof(*lr), lr_padding_1) != 0);
2908 CLASSERT(offsetof(typeof(*lr), lr_padding_2) != 0);
2909 CLASSERT(offsetof(typeof(*lr), lr_padding_3) != 0);
2912 void lustre_swab_lfsck_reply(struct lfsck_reply *lr)
2914 __swab32s(&lr->lr_status);
2915 CLASSERT(offsetof(typeof(*lr), lr_padding_1) != 0);
2916 __swab64s(&lr->lr_repaired);
2919 static void lustre_swab_orphan_rec(struct lu_orphan_rec *rec)
2921 lustre_swab_lu_fid(&rec->lor_fid);
2922 __swab32s(&rec->lor_uid);
2923 __swab32s(&rec->lor_gid);
2926 void lustre_swab_orphan_ent(struct lu_orphan_ent *ent)
2928 lustre_swab_lu_fid(&ent->loe_key);
2929 lustre_swab_orphan_rec(&ent->loe_rec);
2931 EXPORT_SYMBOL(lustre_swab_orphan_ent);
2933 void lustre_swab_orphan_ent_v2(struct lu_orphan_ent_v2 *ent)
2935 lustre_swab_lu_fid(&ent->loe_key);
2936 lustre_swab_orphan_rec(&ent->loe_rec.lor_rec);
2937 lustre_swab_ost_layout(&ent->loe_rec.lor_layout);
2938 CLASSERT(offsetof(typeof(ent->loe_rec), lor_padding) != 0);
2940 EXPORT_SYMBOL(lustre_swab_orphan_ent_v2);
2942 void lustre_swab_orphan_ent_v3(struct lu_orphan_ent_v3 *ent)
2944 lustre_swab_lu_fid(&ent->loe_key);
2945 lustre_swab_orphan_rec(&ent->loe_rec.lor_rec);
2946 lustre_swab_ost_layout(&ent->loe_rec.lor_layout);
2947 __swab32s(&ent->loe_rec.lor_layout_version);
2948 __swab32s(&ent->loe_rec.lor_range);
2949 CLASSERT(offsetof(typeof(ent->loe_rec), lor_padding_1) != 0);
2950 CLASSERT(offsetof(typeof(ent->loe_rec), lor_padding_2) != 0);
2952 EXPORT_SYMBOL(lustre_swab_orphan_ent_v3);
2954 void lustre_swab_ladvise(struct lu_ladvise *ladvise)
2956 __swab16s(&ladvise->lla_advice);
2957 __swab16s(&ladvise->lla_value1);
2958 __swab32s(&ladvise->lla_value2);
2959 __swab64s(&ladvise->lla_start);
2960 __swab64s(&ladvise->lla_end);
2961 __swab32s(&ladvise->lla_value3);
2962 __swab32s(&ladvise->lla_value4);
2964 EXPORT_SYMBOL(lustre_swab_ladvise);
2966 void lustre_swab_ladvise_hdr(struct ladvise_hdr *ladvise_hdr)
2968 __swab32s(&ladvise_hdr->lah_magic);
2969 __swab32s(&ladvise_hdr->lah_count);
2970 __swab64s(&ladvise_hdr->lah_flags);
2971 __swab32s(&ladvise_hdr->lah_value1);
2972 __swab32s(&ladvise_hdr->lah_value2);
2973 __swab64s(&ladvise_hdr->lah_value3);
2975 EXPORT_SYMBOL(lustre_swab_ladvise_hdr);