1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author: Peter J. Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
7 * Author: Eric Barton <eeb@clusterfs.com>
9 * This file is part of the Lustre file system, http://www.lustre.org
10 * Lustre is a trademark of Cluster File Systems, Inc.
12 * You may have signed or agreed to another license before downloading
13 * this software. If so, you are bound by the terms and conditions
14 * of that agreement, and the following does not apply to you. See the
15 * LICENSE file included with this distribution for more information.
17 * If you did not agree to a different license, then this copy of Lustre
18 * is open source software; you can redistribute it and/or modify it
19 * under the terms of version 2 of the GNU General Public License as
20 * published by the Free Software Foundation.
22 * In either case, Lustre is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * license text for more details.
27 * (Un)packing of OST requests
31 #define DEBUG_SUBSYSTEM S_RPC
33 # include <liblustre.h>
36 #include <libcfs/libcfs.h>
38 #include <obd_support.h>
39 #include <obd_class.h>
40 #include <lustre_net.h>
41 #include <obd_cksum.h>
43 static inline int lustre_msg_hdr_size_v2(int count)
45 return size_round(offsetof(struct lustre_msg_v2, lm_buflens[count]));
48 int lustre_msg_hdr_size(__u32 magic, int count)
51 case LUSTRE_MSG_MAGIC_V2:
52 return lustre_msg_hdr_size_v2(count);
54 LASSERTF(0, "incorrect message magic: %08x\n", magic);
58 EXPORT_SYMBOL(lustre_msg_hdr_size);
60 int lustre_msg_swabbed(struct lustre_msg *msg)
62 return (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
66 lustre_msg_check_version_v2(struct lustre_msg_v2 *msg, __u32 version)
68 __u32 ver = lustre_msg_get_version(msg);
69 return (ver & LUSTRE_VERSION_MASK) != version;
72 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
74 switch (msg->lm_magic) {
75 case LUSTRE_MSG_MAGIC_V1:
76 case LUSTRE_MSG_MAGIC_V1_SWABBED:
77 CERROR("msg v1 not supported - please upgrade you system\n");
79 case LUSTRE_MSG_MAGIC_V2:
80 case LUSTRE_MSG_MAGIC_V2_SWABBED:
81 return lustre_msg_check_version_v2(msg, version);
83 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
88 /* early reply size */
89 int lustre_msg_early_size() {
92 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
95 EXPORT_SYMBOL(lustre_msg_early_size);
97 int lustre_msg_size_v2(int count, int *lengths)
102 size = lustre_msg_hdr_size_v2(count);
103 for (i = 0; i < count; i++)
104 size += size_round(lengths[i]);
108 EXPORT_SYMBOL(lustre_msg_size_v2);
110 /* This returns the size of the buffer that is required to hold a lustre_msg
111 * with the given sub-buffer lengths.
112 * NOTE: this should only be used for NEW requests, and should always be
113 * in the form of a v2 request. If this is a connection to a v1
114 * target then the first buffer will be stripped because the ptlrpc
115 * data is part of the lustre_msg_v1 header. b=14043 */
116 int lustre_msg_size(__u32 magic, int count, int *lens)
118 int size[] = { sizeof(struct ptlrpc_body) };
126 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
129 case LUSTRE_MSG_MAGIC_V2:
130 return lustre_msg_size_v2(count, lens);
132 LASSERTF(0, "incorrect message magic: %08x\n", magic);
137 /* This is used to determine the size of a buffer that was already packed
138 * and will correctly handle the different message formats. */
139 int lustre_packed_msg_size(struct lustre_msg *msg)
141 switch (msg->lm_magic) {
142 case LUSTRE_MSG_MAGIC_V2:
143 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
145 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
150 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
156 msg->lm_bufcount = count;
157 /* XXX: lm_secflvr uninitialized here */
158 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
160 for (i = 0; i < count; i++)
161 msg->lm_buflens[i] = lens[i];
166 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
167 for (i = 0; i < count; i++) {
169 LOGL(tmp, lens[i], ptr);
172 EXPORT_SYMBOL(lustre_init_msg_v2);
174 static int lustre_pack_request_v2(struct ptlrpc_request *req,
175 int count, int *lens, char **bufs)
179 reqlen = lustre_msg_size_v2(count, lens);
181 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
185 req->rq_reqlen = reqlen;
187 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
188 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
189 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
193 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
194 int *lens, char **bufs)
196 int size[] = { sizeof(struct ptlrpc_body) };
204 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
206 /* only use new format, we don't need to be compatible with 1.4 */
207 magic = LUSTRE_MSG_MAGIC_V2;
210 case LUSTRE_MSG_MAGIC_V2:
211 return lustre_pack_request_v2(req, count, lens, bufs);
213 LASSERTF(0, "incorrect message magic: %08x\n", magic);
219 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
220 spinlock_t ptlrpc_rs_debug_lock;
222 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
224 spin_lock(&ptlrpc_rs_debug_lock); \
225 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
226 spin_unlock(&ptlrpc_rs_debug_lock); \
229 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
231 spin_lock(&ptlrpc_rs_debug_lock); \
232 list_del(&(rs)->rs_debug_list); \
233 spin_unlock(&ptlrpc_rs_debug_lock); \
236 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
237 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
240 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
242 struct ptlrpc_reply_state *rs = NULL;
244 spin_lock(&svc->srv_lock);
245 /* See if we have anything in a pool, and wait if nothing */
246 while (list_empty(&svc->srv_free_rs_list)) {
247 struct l_wait_info lwi;
249 spin_unlock(&svc->srv_lock);
250 /* If we cannot get anything for some long time, we better
251 bail out instead of waiting infinitely */
252 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
253 rc = l_wait_event(svc->srv_free_rs_waitq,
254 !list_empty(&svc->srv_free_rs_list), &lwi);
257 spin_lock(&svc->srv_lock);
260 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
262 list_del(&rs->rs_list);
263 spin_unlock(&svc->srv_lock);
265 memset(rs, 0, svc->srv_max_reply_size);
266 rs->rs_service = svc;
272 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
274 struct ptlrpc_service *svc = rs->rs_service;
278 spin_lock(&svc->srv_lock);
279 list_add(&rs->rs_list, &svc->srv_free_rs_list);
280 spin_unlock(&svc->srv_lock);
281 cfs_waitq_signal(&svc->srv_free_rs_waitq);
284 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
285 int *lens, char **bufs, int flags)
287 struct ptlrpc_reply_state *rs;
291 LASSERT(req->rq_reply_state == NULL);
293 if ((flags & LPRFL_EARLY_REPLY) == 0)
294 req->rq_packed_final = 1;
296 msg_len = lustre_msg_size_v2(count, lens);
297 rc = sptlrpc_svc_alloc_rs(req, msg_len);
301 rs = req->rq_reply_state;
302 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
303 rs->rs_cb_id.cbid_fn = reply_out_callback;
304 rs->rs_cb_id.cbid_arg = rs;
305 rs->rs_service = req->rq_rqbd->rqbd_service;
306 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
307 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
309 req->rq_replen = msg_len;
310 req->rq_reply_state = rs;
311 req->rq_repmsg = rs->rs_msg;
313 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
314 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
315 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
317 PTLRPC_RS_DEBUG_LRU_ADD(rs);
321 EXPORT_SYMBOL(lustre_pack_reply_v2);
323 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, int *lens,
324 char **bufs, int flags)
327 int size[] = { sizeof(struct ptlrpc_body) };
335 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
337 switch (req->rq_reqmsg->lm_magic) {
338 case LUSTRE_MSG_MAGIC_V2:
339 case LUSTRE_MSG_MAGIC_V2_SWABBED:
340 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
343 LASSERTF(0, "incorrect message magic: %08x\n",
344 req->rq_reqmsg->lm_magic);
348 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
349 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
353 int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
356 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
359 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
361 int i, offset, buflen, bufcount;
366 bufcount = m->lm_bufcount;
367 if (unlikely(n >= bufcount)) {
368 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
373 buflen = m->lm_buflens[n];
374 if (unlikely(buflen < min_size)) {
375 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
376 m, n, buflen, min_size);
380 offset = lustre_msg_hdr_size_v2(bufcount);
381 for (i = 0; i < n; i++)
382 offset += size_round(m->lm_buflens[i]);
384 return (char *)m + offset;
387 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
389 switch (m->lm_magic) {
390 case LUSTRE_MSG_MAGIC_V2:
391 case LUSTRE_MSG_MAGIC_V2_SWABBED:
392 return lustre_msg_buf_v2(m, n, min_size);
394 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
399 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
400 unsigned int newlen, int move_data)
402 char *tail = NULL, *newpos;
406 LASSERT(msg->lm_bufcount > segment);
407 LASSERT(msg->lm_buflens[segment] >= newlen);
409 if (msg->lm_buflens[segment] == newlen)
412 if (move_data && msg->lm_bufcount > segment + 1) {
413 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
414 for (n = segment + 1; n < msg->lm_bufcount; n++)
415 tail_len += size_round(msg->lm_buflens[n]);
418 msg->lm_buflens[segment] = newlen;
420 if (tail && tail_len) {
421 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
422 LASSERT(newpos <= tail);
424 memcpy(newpos, tail, tail_len);
427 return lustre_msg_size_v2(msg->lm_bufcount, (int *)msg->lm_buflens);
431 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
432 * we also move data forward from @segment + 1.
434 * if @newlen == 0, we remove the segment completely, but we still keep the
435 * totally bufcount the same to save possible data moving. this will leave a
436 * unused segment with size 0 at the tail, but that's ok.
438 * return new msg size after shrinking.
441 * + if any buffers higher than @segment has been filled in, must call shrink
442 * with non-zero @move_data.
443 * + caller should NOT keep pointers to msg buffers which higher than @segment
446 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
447 unsigned int newlen, int move_data)
449 switch (msg->lm_magic) {
450 case LUSTRE_MSG_MAGIC_V2:
451 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
453 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
457 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
459 PTLRPC_RS_DEBUG_LRU_DEL(rs);
461 LASSERT (atomic_read(&rs->rs_refcount) == 0);
462 LASSERT (!rs->rs_difficult || rs->rs_handled);
463 LASSERT (!rs->rs_on_net);
464 LASSERT (!rs->rs_scheduled);
465 LASSERT (rs->rs_export == NULL);
466 LASSERT (rs->rs_nlocks == 0);
467 LASSERT (list_empty(&rs->rs_exp_list));
468 LASSERT (list_empty(&rs->rs_obd_list));
470 sptlrpc_svc_free_rs(rs);
473 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
475 int flipped, required_len, i;
477 /* Now we know the sender speaks my language. */
478 required_len = lustre_msg_hdr_size_v2(0);
479 if (len < required_len) {
480 /* can't even look inside the message */
481 CERROR("message length %d too small for lustre_msg\n", len);
485 flipped = lustre_msg_swabbed(m);
488 __swab32s(&m->lm_bufcount);
489 __swab32s(&m->lm_secflvr);
490 __swab32s(&m->lm_repsize);
491 __swab32s(&m->lm_cksum);
492 __swab32s(&m->lm_flags);
493 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
494 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
497 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
498 if (len < required_len) {
499 /* didn't receive all the buffer lengths */
500 CERROR ("message length %d too small for %d buflens\n",
501 len, m->lm_bufcount);
505 for (i = 0; i < m->lm_bufcount; i++) {
507 __swab32s(&m->lm_buflens[i]);
508 required_len += size_round(m->lm_buflens[i]);
511 if (len < required_len) {
512 CERROR("len: %d, required_len %d\n", len, required_len);
513 CERROR("bufcount: %d\n", m->lm_bufcount);
514 for (i = 0; i < m->lm_bufcount; i++)
515 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
522 int lustre_unpack_msg(struct lustre_msg *m, int len)
524 int required_len, rc;
527 /* We can provide a slightly better error log, if we check the
528 * message magic and version first. In the future, struct
529 * lustre_msg may grow, and we'd like to log a version mismatch,
530 * rather than a short message.
533 required_len = offsetof(struct lustre_msg, lm_magic) +
535 if (len < required_len) {
536 /* can't even look inside the message */
537 CERROR("message length %d too small for magic/version check\n",
542 switch (m->lm_magic) {
543 case LUSTRE_MSG_MAGIC_V2:
544 case LUSTRE_MSG_MAGIC_V2_SWABBED:
545 rc = lustre_unpack_msg_v2(m, len);
548 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
555 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
558 struct ptlrpc_body *pb;
560 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
562 CERROR("error unpacking ptlrpc body\n");
565 if (lustre_msg_swabbed(m))
566 lustre_swab_ptlrpc_body(pb);
568 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
569 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
576 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
578 switch (req->rq_reqmsg->lm_magic) {
579 case LUSTRE_MSG_MAGIC_V2:
580 case LUSTRE_MSG_MAGIC_V2_SWABBED:
581 lustre_set_req_swabbed(req, offset);
582 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
584 CERROR("bad lustre msg magic: %#08X\n",
585 req->rq_reqmsg->lm_magic);
590 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
592 switch (req->rq_repmsg->lm_magic) {
593 case LUSTRE_MSG_MAGIC_V2:
594 case LUSTRE_MSG_MAGIC_V2_SWABBED:
595 lustre_set_rep_swabbed(req, offset);
596 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
598 CERROR("bad lustre msg magic: %#08X\n",
599 req->rq_repmsg->lm_magic);
604 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
606 if (n >= m->lm_bufcount)
609 return m->lm_buflens[n];
613 * lustre_msg_buflen - return the length of buffer @n in message @m
614 * @m - lustre_msg (request or reply) to look at
615 * @n - message index (base 0)
617 * returns zero for non-existent message indices
619 int lustre_msg_buflen(struct lustre_msg *m, int n)
621 switch (m->lm_magic) {
622 case LUSTRE_MSG_MAGIC_V2:
623 case LUSTRE_MSG_MAGIC_V2_SWABBED:
624 return lustre_msg_buflen_v2(m, n);
626 CERROR("incorrect message magic: %08x\n", m->lm_magic);
630 EXPORT_SYMBOL(lustre_msg_buflen);
633 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
635 if (n >= m->lm_bufcount)
638 m->lm_buflens[n] = len;
641 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
643 switch (m->lm_magic) {
644 case LUSTRE_MSG_MAGIC_V2:
645 lustre_msg_set_buflen_v2(m, n, len);
648 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
652 EXPORT_SYMBOL(lustre_msg_set_buflen);
654 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
655 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
656 int lustre_msg_bufcount(struct lustre_msg *m)
658 switch (m->lm_magic) {
659 case LUSTRE_MSG_MAGIC_V2:
660 case LUSTRE_MSG_MAGIC_V2_SWABBED:
661 return m->lm_bufcount;
663 CERROR("incorrect message magic: %08x\n", m->lm_magic);
667 EXPORT_SYMBOL(lustre_msg_bufcount);
669 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
671 /* max_len == 0 means the string should fill the buffer */
675 switch (m->lm_magic) {
676 case LUSTRE_MSG_MAGIC_V2:
677 case LUSTRE_MSG_MAGIC_V2_SWABBED:
678 str = lustre_msg_buf_v2(m, index, 0);
679 blen = lustre_msg_buflen_v2(m, index);
682 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
686 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
690 slen = strnlen(str, blen);
692 if (slen == blen) { /* not NULL terminated */
693 CERROR("can't unpack non-NULL terminated string in "
694 "msg %p buffer[%d] len %d\n", m, index, blen);
699 if (slen != blen - 1) {
700 CERROR("can't unpack short string in msg %p "
701 "buffer[%d] len %d: strlen %d\n",
702 m, index, blen, slen);
705 } else if (slen > max_len) {
706 CERROR("can't unpack oversized string in msg %p "
707 "buffer[%d] len %d strlen %d: max %d expected\n",
708 m, index, blen, slen, max_len);
715 /* Wrap up the normal fixed length cases */
716 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
721 switch (msg->lm_magic) {
722 case LUSTRE_MSG_MAGIC_V2:
723 case LUSTRE_MSG_MAGIC_V2_SWABBED:
724 ptr = lustre_msg_buf_v2(msg, index, min_size);
727 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
732 if (swabber != NULL && lustre_msg_swabbed(msg))
733 ((void (*)(void *))swabber)(ptr);
738 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
741 lustre_set_req_swabbed(req, index);
742 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
745 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
748 lustre_set_rep_swabbed(req, index);
749 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
752 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
754 switch (msg->lm_magic) {
755 case LUSTRE_MSG_MAGIC_V1:
756 case LUSTRE_MSG_MAGIC_V1_SWABBED:
758 case LUSTRE_MSG_MAGIC_V2:
759 case LUSTRE_MSG_MAGIC_V2_SWABBED:
760 /* already in host endian */
761 return msg->lm_flags;
763 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
768 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
770 switch (msg->lm_magic) {
771 case LUSTRE_MSG_MAGIC_V1:
773 case LUSTRE_MSG_MAGIC_V2:
774 msg->lm_flags = flags;
777 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
781 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
783 switch (msg->lm_magic) {
784 case LUSTRE_MSG_MAGIC_V2:
785 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
786 struct ptlrpc_body *pb;
788 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
790 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
796 /* flags might be printed in debug code while message
802 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
804 switch (msg->lm_magic) {
805 case LUSTRE_MSG_MAGIC_V2: {
806 struct ptlrpc_body *pb;
808 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
809 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
810 pb->pb_flags |= flags;
814 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
818 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
820 switch (msg->lm_magic) {
821 case LUSTRE_MSG_MAGIC_V2: {
822 struct ptlrpc_body *pb;
824 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
825 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
826 pb->pb_flags = flags;
830 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
834 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
836 switch (msg->lm_magic) {
837 case LUSTRE_MSG_MAGIC_V2:
838 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
839 struct ptlrpc_body *pb;
841 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
842 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
843 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
847 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
851 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
853 switch (msg->lm_magic) {
854 case LUSTRE_MSG_MAGIC_V2:
855 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
856 struct ptlrpc_body *pb;
858 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
860 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
863 return pb->pb_op_flags;
870 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
872 switch (msg->lm_magic) {
873 case LUSTRE_MSG_MAGIC_V2: {
874 struct ptlrpc_body *pb;
876 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
877 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
878 pb->pb_op_flags |= flags;
882 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
886 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
888 switch (msg->lm_magic) {
889 case LUSTRE_MSG_MAGIC_V2: {
890 struct ptlrpc_body *pb;
892 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
893 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
894 pb->pb_op_flags |= flags;
898 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
902 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
904 switch (msg->lm_magic) {
905 case LUSTRE_MSG_MAGIC_V2:
906 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
907 struct ptlrpc_body *pb;
909 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
911 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
914 return &pb->pb_handle;
917 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
922 __u32 lustre_msg_get_type(struct lustre_msg *msg)
924 switch (msg->lm_magic) {
925 case LUSTRE_MSG_MAGIC_V2:
926 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
927 struct ptlrpc_body *pb;
929 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
931 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
932 return PTL_RPC_MSG_ERR;
937 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
938 return PTL_RPC_MSG_ERR;
942 __u32 lustre_msg_get_version(struct lustre_msg *msg)
944 switch (msg->lm_magic) {
945 case LUSTRE_MSG_MAGIC_V2:
946 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
947 struct ptlrpc_body *pb;
949 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
951 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
954 return pb->pb_version;
957 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
962 void lustre_msg_add_version(struct lustre_msg *msg, int version)
964 switch (msg->lm_magic) {
965 case LUSTRE_MSG_MAGIC_V2:
966 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
967 struct ptlrpc_body *pb;
969 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
970 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
971 pb->pb_version |= version;
975 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
979 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
981 switch (msg->lm_magic) {
982 case LUSTRE_MSG_MAGIC_V2:
983 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
984 struct ptlrpc_body *pb;
986 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
988 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
994 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
999 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1001 switch (msg->lm_magic) {
1002 case LUSTRE_MSG_MAGIC_V2:
1003 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1004 struct ptlrpc_body *pb;
1006 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1008 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1011 return pb->pb_last_xid;
1014 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1019 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1021 switch (msg->lm_magic) {
1022 case LUSTRE_MSG_MAGIC_V2:
1023 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1024 struct ptlrpc_body *pb;
1026 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1028 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1031 return pb->pb_last_committed;
1034 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1039 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1041 switch (msg->lm_magic) {
1042 case LUSTRE_MSG_MAGIC_V2:
1043 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1044 struct ptlrpc_body *pb;
1046 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1048 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1051 return pb->pb_transno;
1054 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1059 int lustre_msg_get_status(struct lustre_msg *msg)
1061 switch (msg->lm_magic) {
1062 case LUSTRE_MSG_MAGIC_V2:
1063 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1064 struct ptlrpc_body *pb;
1066 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1068 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1071 return pb->pb_status;
1074 /* status might be printed in debug code while message
1080 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1082 switch (msg->lm_magic) {
1083 case LUSTRE_MSG_MAGIC_V2:
1084 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1085 struct ptlrpc_body *pb;
1087 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1089 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1095 CERROR("invalid msg magic %x\n", msg->lm_magic);
1101 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1103 switch (msg->lm_magic) {
1104 case LUSTRE_MSG_MAGIC_V2:
1105 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1106 struct ptlrpc_body *pb;
1108 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1110 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1117 CERROR("invalid msg magic %x\n", msg->lm_magic);
1122 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1124 switch (msg->lm_magic) {
1125 case LUSTRE_MSG_MAGIC_V2:
1126 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1127 struct ptlrpc_body *pb;
1129 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1131 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1134 return pb->pb_limit;
1137 CERROR("invalid msg magic %x\n", msg->lm_magic);
1143 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1145 switch (msg->lm_magic) {
1146 case LUSTRE_MSG_MAGIC_V2:
1147 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1148 struct ptlrpc_body *pb;
1150 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1152 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1155 pb->pb_limit = limit;
1159 CERROR("invalid msg magic %x\n", msg->lm_magic);
1164 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1166 switch (msg->lm_magic) {
1167 case LUSTRE_MSG_MAGIC_V2:
1168 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1169 struct ptlrpc_body *pb;
1171 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1173 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1176 return pb->pb_conn_cnt;
1179 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1184 int lustre_msg_is_v1(struct lustre_msg *msg)
1186 switch (msg->lm_magic) {
1187 case LUSTRE_MSG_MAGIC_V1:
1188 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1195 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1197 switch (msg->lm_magic) {
1198 case LUSTRE_MSG_MAGIC_V2:
1199 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1200 return msg->lm_magic;
1202 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1207 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
1209 switch (msg->lm_magic) {
1210 case LUSTRE_MSG_MAGIC_V1:
1211 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1213 case LUSTRE_MSG_MAGIC_V2:
1214 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1215 struct ptlrpc_body *pb;
1217 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1219 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1223 return pb->pb_timeout;
1226 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1231 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1233 switch (msg->lm_magic) {
1234 case LUSTRE_MSG_MAGIC_V1:
1235 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1237 case LUSTRE_MSG_MAGIC_V2:
1238 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1239 struct ptlrpc_body *pb;
1241 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1243 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1247 return pb->pb_service_time;
1250 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1255 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1257 switch (msg->lm_magic) {
1258 case LUSTRE_MSG_MAGIC_V1:
1259 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1261 case LUSTRE_MSG_MAGIC_V2:
1262 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1263 return msg->lm_cksum;
1265 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1270 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1272 switch (msg->lm_magic) {
1273 case LUSTRE_MSG_MAGIC_V1:
1274 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1276 case LUSTRE_MSG_MAGIC_V2:
1277 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1278 struct ptlrpc_body *pb;
1279 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1280 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1281 return crc32_le(~(__u32)0, (char *)pb, sizeof(*pb));
1284 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1289 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1291 switch (msg->lm_magic) {
1292 case LUSTRE_MSG_MAGIC_V2: {
1293 struct ptlrpc_body *pb;
1295 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1296 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1297 pb->pb_handle = *handle;
1301 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1305 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1307 switch (msg->lm_magic) {
1308 case LUSTRE_MSG_MAGIC_V2: {
1309 struct ptlrpc_body *pb;
1311 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1312 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1317 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1321 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1323 switch (msg->lm_magic) {
1324 case LUSTRE_MSG_MAGIC_V2: {
1325 struct ptlrpc_body *pb;
1327 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1328 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1333 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1337 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1339 switch (msg->lm_magic) {
1340 case LUSTRE_MSG_MAGIC_V2: {
1341 struct ptlrpc_body *pb;
1343 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1344 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1345 pb->pb_last_xid = last_xid;
1349 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1353 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1355 switch (msg->lm_magic) {
1356 case LUSTRE_MSG_MAGIC_V2: {
1357 struct ptlrpc_body *pb;
1359 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1360 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1361 pb->pb_last_committed = last_committed;
1365 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1369 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1371 switch (msg->lm_magic) {
1372 case LUSTRE_MSG_MAGIC_V2: {
1373 struct ptlrpc_body *pb;
1375 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1376 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1377 pb->pb_transno = transno;
1381 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1385 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1387 switch (msg->lm_magic) {
1388 case LUSTRE_MSG_MAGIC_V2: {
1389 struct ptlrpc_body *pb;
1391 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1392 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1393 pb->pb_status = status;
1397 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1401 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1403 switch (msg->lm_magic) {
1404 case LUSTRE_MSG_MAGIC_V2: {
1405 struct ptlrpc_body *pb;
1407 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1408 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1409 pb->pb_conn_cnt = conn_cnt;
1413 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1417 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1419 switch (msg->lm_magic) {
1420 case LUSTRE_MSG_MAGIC_V1:
1422 case LUSTRE_MSG_MAGIC_V2: {
1423 struct ptlrpc_body *pb;
1425 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1426 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1427 pb->pb_timeout = timeout;
1431 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1435 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1437 switch (msg->lm_magic) {
1438 case LUSTRE_MSG_MAGIC_V1:
1440 case LUSTRE_MSG_MAGIC_V2: {
1441 struct ptlrpc_body *pb;
1443 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1444 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1445 pb->pb_service_time = service_time;
1449 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1453 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1455 switch (msg->lm_magic) {
1456 case LUSTRE_MSG_MAGIC_V1:
1458 case LUSTRE_MSG_MAGIC_V2:
1459 msg->lm_cksum = cksum;
1462 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1467 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1469 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1471 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1472 req->rq_pill.rc_area[RCL_SERVER]);
1473 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1474 req->rq_reqmsg->lm_repsize = req->rq_replen;
1477 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, int *lens)
1479 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1480 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1481 req->rq_reqmsg->lm_repsize = req->rq_replen;
1484 /* byte flipping routines for all wire types declared in
1485 * lustre_idl.h implemented here.
1487 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1489 __swab32s (&b->pb_type);
1490 __swab32s (&b->pb_version);
1491 __swab32s (&b->pb_opc);
1492 __swab32s (&b->pb_status);
1493 __swab64s (&b->pb_last_xid);
1494 __swab64s (&b->pb_last_seen);
1495 __swab64s (&b->pb_last_committed);
1496 __swab64s (&b->pb_transno);
1497 __swab32s (&b->pb_flags);
1498 __swab32s (&b->pb_op_flags);
1499 __swab32s (&b->pb_conn_cnt);
1500 __swab32s (&b->pb_timeout);
1501 __swab32s (&b->pb_service_time);
1502 __swab32s (&b->pb_limit);
1503 __swab64s (&b->pb_slv);
1506 void lustre_swab_connect(struct obd_connect_data *ocd)
1508 __swab64s(&ocd->ocd_connect_flags);
1509 __swab32s(&ocd->ocd_version);
1510 __swab32s(&ocd->ocd_grant);
1511 __swab64s(&ocd->ocd_ibits_known);
1512 __swab32s(&ocd->ocd_index);
1513 __swab32s(&ocd->ocd_brw_size);
1514 __swab32s(&ocd->ocd_nllu);
1515 __swab32s(&ocd->ocd_nllg);
1516 __swab64s(&ocd->ocd_transno);
1517 __swab32s(&ocd->ocd_group);
1518 __swab32s(&ocd->ocd_cksum_types);
1519 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1520 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1523 void lustre_swab_obdo (struct obdo *o)
1525 __swab64s (&o->o_valid);
1526 __swab64s (&o->o_id);
1527 __swab64s (&o->o_gr);
1528 __swab64s (&o->o_fid);
1529 __swab64s (&o->o_size);
1530 __swab64s (&o->o_mtime);
1531 __swab64s (&o->o_atime);
1532 __swab64s (&o->o_ctime);
1533 __swab64s (&o->o_blocks);
1534 __swab64s (&o->o_grant);
1535 __swab32s (&o->o_blksize);
1536 __swab32s (&o->o_mode);
1537 __swab32s (&o->o_uid);
1538 __swab32s (&o->o_gid);
1539 __swab32s (&o->o_flags);
1540 __swab32s (&o->o_nlink);
1541 __swab32s (&o->o_generation);
1542 __swab32s (&o->o_misc);
1543 __swab32s (&o->o_easize);
1544 __swab32s (&o->o_mds);
1545 __swab32s (&o->o_stripe_idx);
1546 __swab32s (&o->o_padding_1);
1547 /* o_inline is opaque */
1550 void lustre_swab_obd_statfs (struct obd_statfs *os)
1552 __swab64s (&os->os_type);
1553 __swab64s (&os->os_blocks);
1554 __swab64s (&os->os_bfree);
1555 __swab64s (&os->os_bavail);
1556 __swab64s (&os->os_files);
1557 __swab64s (&os->os_ffree);
1558 /* no need to swab os_fsid */
1559 __swab32s (&os->os_bsize);
1560 __swab32s (&os->os_namelen);
1561 __swab64s (&os->os_maxbytes);
1562 __swab32s (&os->os_state);
1563 /* no need to swap os_spare */
1566 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1568 __swab64s (&ioo->ioo_id);
1569 __swab64s (&ioo->ioo_gr);
1570 __swab32s (&ioo->ioo_type);
1571 __swab32s (&ioo->ioo_bufcnt);
1574 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1576 __swab64s (&nbr->offset);
1577 __swab32s (&nbr->len);
1578 __swab32s (&nbr->flags);
1581 void lustre_swab_ost_body (struct ost_body *b)
1583 lustre_swab_obdo (&b->oa);
1586 void lustre_swab_ost_last_id(obd_id *id)
1591 void lustre_swab_generic_32s(__u32 *val)
1596 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1598 __swab64s(&lvb->lvb_size);
1599 __swab64s(&lvb->lvb_mtime);
1600 __swab64s(&lvb->lvb_atime);
1601 __swab64s(&lvb->lvb_ctime);
1602 __swab64s(&lvb->lvb_blocks);
1605 void lustre_swab_mds_status_req (struct mds_status_req *r)
1607 __swab32s (&r->flags);
1608 __swab32s (&r->repbuf);
1611 void lustre_swab_mds_body (struct mds_body *b)
1613 lustre_swab_ll_fid (&b->fid1);
1614 lustre_swab_ll_fid (&b->fid2);
1615 /* handle is opaque */
1616 __swab64s (&b->valid);
1617 __swab64s (&b->size);
1618 __swab64s (&b->mtime);
1619 __swab64s (&b->atime);
1620 __swab64s (&b->ctime);
1621 __swab64s (&b->blocks);
1622 __swab64s (&b->io_epoch);
1623 __swab64s (&b->ino);
1624 __swab32s (&b->fsuid);
1625 __swab32s (&b->fsgid);
1626 __swab32s (&b->capability);
1627 __swab32s (&b->mode);
1628 __swab32s (&b->uid);
1629 __swab32s (&b->gid);
1630 __swab32s (&b->flags);
1631 __swab32s (&b->rdev);
1632 __swab32s (&b->nlink);
1633 __swab32s (&b->generation);
1634 __swab32s (&b->suppgid);
1635 __swab32s (&b->eadatasize);
1636 __swab32s (&b->aclsize);
1637 __swab32s (&b->max_mdsize);
1638 __swab32s (&b->max_cookiesize);
1639 __swab32s (&b->padding_4);
1642 void lustre_swab_mdt_body (struct mdt_body *b)
1644 lustre_swab_lu_fid (&b->fid1);
1645 lustre_swab_lu_fid (&b->fid2);
1646 /* handle is opaque */
1647 __swab64s (&b->valid);
1648 __swab64s (&b->size);
1649 __swab64s (&b->mtime);
1650 __swab64s (&b->atime);
1651 __swab64s (&b->ctime);
1652 __swab64s (&b->blocks);
1653 __swab64s (&b->ioepoch);
1654 __swab64s (&b->ino);
1655 __swab32s (&b->fsuid);
1656 __swab32s (&b->fsgid);
1657 __swab32s (&b->capability);
1658 __swab32s (&b->mode);
1659 __swab32s (&b->uid);
1660 __swab32s (&b->gid);
1661 __swab32s (&b->flags);
1662 __swab32s (&b->rdev);
1663 __swab32s (&b->nlink);
1664 __swab32s (&b->generation);
1665 __swab32s (&b->suppgid);
1666 __swab32s (&b->eadatasize);
1667 __swab32s (&b->aclsize);
1668 __swab32s (&b->max_mdsize);
1669 __swab32s (&b->max_cookiesize);
1670 __swab32s (&b->padding_4);
1673 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1675 /* handle is opaque */
1676 __swab64s (&b->ioepoch);
1677 __swab32s (&b->flags);
1678 CLASSERT(offsetof(typeof(*b), padding) != 0);
1681 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1684 __swab32s(&mti->mti_lustre_ver);
1685 __swab32s(&mti->mti_stripe_index);
1686 __swab32s(&mti->mti_config_ver);
1687 __swab32s(&mti->mti_flags);
1688 __swab32s(&mti->mti_nid_count);
1689 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1690 for (i = 0; i < MTI_NIDS_MAX; i++)
1691 __swab64s(&mti->mti_nids[i]);
1694 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1696 __swab64s (&i->dqi_bgrace);
1697 __swab64s (&i->dqi_igrace);
1698 __swab32s (&i->dqi_flags);
1699 __swab32s (&i->dqi_valid);
1702 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1704 __swab64s (&b->dqb_ihardlimit);
1705 __swab64s (&b->dqb_isoftlimit);
1706 __swab64s (&b->dqb_curinodes);
1707 __swab64s (&b->dqb_bhardlimit);
1708 __swab64s (&b->dqb_bsoftlimit);
1709 __swab64s (&b->dqb_curspace);
1710 __swab64s (&b->dqb_btime);
1711 __swab64s (&b->dqb_itime);
1712 __swab32s (&b->dqb_valid);
1713 CLASSERT(offsetof(typeof(*b), padding) != 0);
1716 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1718 __swab32s (&q->qc_cmd);
1719 __swab32s (&q->qc_type);
1720 __swab32s (&q->qc_id);
1721 __swab32s (&q->qc_stat);
1722 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1723 lustre_swab_obd_dqblk (&q->qc_dqblk);
1726 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1728 __swab32s (&p->rp_uid);
1729 __swab32s (&p->rp_gid);
1730 __swab32s (&p->rp_fsuid);
1731 __swab32s (&p->rp_fsgid);
1732 __swab32s (&p->rp_access_perm);
1735 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1737 __swab32s (&p->rp_uid);
1738 __swab32s (&p->rp_gid);
1739 __swab32s (&p->rp_fsuid);
1740 __swab32s (&p->rp_fsgid);
1741 __swab32s (&p->rp_access_perm);
1744 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1746 __swab32s (&sa->sa_opcode);
1747 __swab32s (&sa->sa_fsuid);
1748 __swab32s (&sa->sa_fsgid);
1749 __swab32s (&sa->sa_cap);
1750 __swab32s (&sa->sa_suppgid);
1751 __swab32s (&sa->sa_mode);
1752 lustre_swab_ll_fid (&sa->sa_fid);
1753 __swab64s (&sa->sa_valid);
1754 __swab64s (&sa->sa_size);
1755 __swab64s (&sa->sa_mtime);
1756 __swab64s (&sa->sa_atime);
1757 __swab64s (&sa->sa_ctime);
1758 __swab32s (&sa->sa_uid);
1759 __swab32s (&sa->sa_gid);
1760 __swab32s (&sa->sa_attr_flags);
1761 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1764 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1766 __swab64s(&jr->jr_headsize);
1767 lustre_swab_ll_fid(&jr->jr_fid);
1770 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1772 __swab64s(&jr->jr_headsize);
1773 lustre_swab_lu_fid(&jr->jr_fid);
1776 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1778 __swab32s (&cr->cr_opcode);
1779 __swab32s (&cr->cr_fsuid);
1780 __swab32s (&cr->cr_fsgid);
1781 __swab32s (&cr->cr_cap);
1782 __swab32s (&cr->cr_flags); /* for use with open */
1783 __swab32s (&cr->cr_mode);
1784 lustre_swab_ll_fid (&cr->cr_fid);
1785 lustre_swab_ll_fid (&cr->cr_replayfid);
1786 __swab64s (&cr->cr_time);
1787 __swab64s (&cr->cr_rdev);
1788 __swab32s (&cr->cr_suppgid);
1789 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1790 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1791 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1792 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1793 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1796 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1798 __swab32s (&lk->lk_opcode);
1799 __swab32s (&lk->lk_fsuid);
1800 __swab32s (&lk->lk_fsgid);
1801 __swab32s (&lk->lk_cap);
1802 __swab32s (&lk->lk_suppgid1);
1803 __swab32s (&lk->lk_suppgid2);
1804 lustre_swab_ll_fid (&lk->lk_fid1);
1805 lustre_swab_ll_fid (&lk->lk_fid2);
1806 __swab64s (&lk->lk_time);
1807 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1808 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1809 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1810 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1813 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1815 __swab32s (&ul->ul_opcode);
1816 __swab32s (&ul->ul_fsuid);
1817 __swab32s (&ul->ul_fsgid);
1818 __swab32s (&ul->ul_cap);
1819 __swab32s (&ul->ul_suppgid);
1820 __swab32s (&ul->ul_mode);
1821 lustre_swab_ll_fid (&ul->ul_fid1);
1822 lustre_swab_ll_fid (&ul->ul_fid2);
1823 __swab64s (&ul->ul_time);
1824 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1825 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1826 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1827 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1830 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1832 __swab32s (&rn->rn_opcode);
1833 __swab32s (&rn->rn_fsuid);
1834 __swab32s (&rn->rn_fsgid);
1835 __swab32s (&rn->rn_cap);
1836 __swab32s (&rn->rn_suppgid1);
1837 __swab32s (&rn->rn_suppgid2);
1838 lustre_swab_ll_fid (&rn->rn_fid1);
1839 lustre_swab_ll_fid (&rn->rn_fid2);
1840 __swab64s (&rn->rn_time);
1841 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1842 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1843 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1844 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1847 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
1849 __swab32s (&rr->rr_opcode);
1850 __swab32s (&rr->rr_fsuid);
1851 __swab32s (&rr->rr_fsgid);
1852 __swab32s (&rr->rr_cap);
1853 __swab32s (&rr->rr_suppgid1);
1854 __swab32s (&rr->rr_suppgid2);
1855 /* handle is opaque */
1856 lustre_swab_lu_fid (&rr->rr_fid1);
1857 lustre_swab_lu_fid (&rr->rr_fid2);
1858 __swab64s (&rr->rr_mtime);
1859 __swab64s (&rr->rr_atime);
1860 __swab64s (&rr->rr_ctime);
1861 __swab64s (&rr->rr_size);
1862 __swab64s (&rr->rr_blocks);
1863 __swab32s (&rr->rr_bias);
1864 __swab32s (&rr->rr_mode);
1865 __swab32s (&rr->rr_padding_1);
1866 __swab32s (&rr->rr_padding_2);
1867 __swab32s (&rr->rr_padding_3);
1868 __swab32s (&rr->rr_padding_4);
1870 CLASSERT(offsetof(typeof(*rr), rr_padding_1) != 0);
1871 CLASSERT(offsetof(typeof(*rr), rr_padding_2) != 0);
1872 CLASSERT(offsetof(typeof(*rr), rr_padding_3) != 0);
1873 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
1876 void lustre_swab_lov_desc (struct lov_desc *ld)
1878 __swab32s (&ld->ld_tgt_count);
1879 __swab32s (&ld->ld_active_tgt_count);
1880 __swab32s (&ld->ld_default_stripe_count);
1881 __swab64s (&ld->ld_default_stripe_size);
1882 __swab64s (&ld->ld_default_stripe_offset);
1883 __swab32s (&ld->ld_pattern);
1884 __swab32s (&ld->ld_qos_maxage);
1885 /* uuid endian insensitive */
1888 /*begin adding MDT by huanghua@clusterfs.com*/
1889 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1891 __swab32s (&ld->ld_tgt_count);
1892 __swab32s (&ld->ld_active_tgt_count);
1893 /* uuid endian insensitive */
1895 /*end adding MDT by huanghua@clusterfs.com*/
1896 void lustre_swab_md_fld (struct md_fld *mf)
1898 __swab64s(&mf->mf_seq);
1899 __swab64s(&mf->mf_mds);
1902 static void print_lum (struct lov_user_md *lum)
1904 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1905 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1906 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1907 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1908 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
1909 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1910 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1911 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1914 void lustre_swab_lov_user_md(struct lov_user_md *lum)
1917 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
1918 __swab32s(&lum->lmm_magic);
1919 __swab32s(&lum->lmm_pattern);
1920 __swab64s(&lum->lmm_object_id);
1921 __swab64s(&lum->lmm_object_gr);
1922 __swab32s(&lum->lmm_stripe_size);
1923 __swab16s(&lum->lmm_stripe_count);
1924 __swab16s(&lum->lmm_stripe_offset);
1929 static void print_lumj (struct lov_user_md_join *lumj)
1931 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
1932 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
1933 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
1934 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
1935 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
1936 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
1937 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
1938 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
1941 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
1944 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
1945 __swab32s(&lumj->lmm_magic);
1946 __swab32s(&lumj->lmm_pattern);
1947 __swab64s(&lumj->lmm_object_id);
1948 __swab64s(&lumj->lmm_object_gr);
1949 __swab32s(&lumj->lmm_stripe_size);
1950 __swab32s(&lumj->lmm_stripe_count);
1951 __swab32s(&lumj->lmm_extent_count);
1956 static void print_lum_objs(struct lov_user_md *lum)
1958 struct lov_user_ost_data *lod;
1961 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
1963 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
1964 for (i = 0; i < lum->lmm_stripe_count; i++) {
1965 lod = &lum->lmm_objects[i];
1966 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
1967 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
1968 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
1969 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
1974 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
1976 struct lov_user_ost_data *lod;
1979 for (i = 0; i < lum->lmm_stripe_count; i++) {
1980 lod = &lum->lmm_objects[i];
1981 __swab64s(&lod->l_object_id);
1982 __swab64s(&lod->l_object_gr);
1983 __swab32s(&lod->l_ost_gen);
1984 __swab32s(&lod->l_ost_idx);
1986 print_lum_objs(lum);
1991 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
1993 struct lov_ost_data *lod;
1996 for (i = 0; i < lmm->lmm_stripe_count; i++) {
1997 lod = &lmm->lmm_objects[i];
1998 __swab64s(&lod->l_object_id);
1999 __swab64s(&lod->l_object_gr);
2000 __swab32s(&lod->l_ost_gen);
2001 __swab32s(&lod->l_ost_idx);
2003 __swab32s(&lmm->lmm_magic);
2004 __swab32s(&lmm->lmm_pattern);
2005 __swab64s(&lmm->lmm_object_id);
2006 __swab64s(&lmm->lmm_object_gr);
2007 __swab32s(&lmm->lmm_stripe_size);
2008 __swab32s(&lmm->lmm_stripe_count);
2014 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2018 for (i = 0; i < RES_NAME_SIZE; i++)
2019 __swab64s (&id->name[i]);
2022 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2024 /* the lock data is a union and the first two fields are always an
2025 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2026 * data the same way. */
2027 __swab64s(&d->l_extent.start);
2028 __swab64s(&d->l_extent.end);
2029 __swab64s(&d->l_extent.gid);
2030 __swab32s(&d->l_flock.pid);
2033 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2035 __swab64s (&i->opc);
2038 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2040 __swab32s (&r->lr_type);
2041 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2042 lustre_swab_ldlm_res_id (&r->lr_name);
2045 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2047 lustre_swab_ldlm_resource_desc (&l->l_resource);
2048 __swab32s (&l->l_req_mode);
2049 __swab32s (&l->l_granted_mode);
2050 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2053 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2055 __swab32s (&rq->lock_flags);
2056 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2057 __swab32s (&rq->lock_count);
2058 /* lock_handle[] opaque */
2061 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2063 __swab32s (&r->lock_flags);
2064 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2065 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2066 /* lock_handle opaque */
2067 __swab64s (&r->lock_policy_res1);
2068 __swab64s (&r->lock_policy_res2);
2071 /* no one calls this */
2072 int llog_log_swabbed(struct llog_log_hdr *hdr)
2074 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2076 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2081 void lustre_swab_qdata(struct qunit_data *d)
2083 __swab32s (&d->qd_id);
2084 __swab32s (&d->qd_flags);
2085 __swab64s (&d->qd_count);
2088 void lustre_swab_qdata_old(struct qunit_data_old *d)
2090 __swab32s (&d->qd_id);
2091 __swab32s (&d->qd_type);
2092 __swab32s (&d->qd_count);
2093 __swab32s (&d->qd_isblk);
2097 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2099 struct qunit_data_old tmp;
2100 struct qunit_data *ret;
2107 ret = (struct qunit_data *)d;
2108 ret->qd_id = tmp.qd_id;
2109 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2110 ret->qd_count = tmp.qd_count;
2114 EXPORT_SYMBOL(lustre_quota_old_to_new);
2116 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2118 struct qunit_data tmp;
2119 struct qunit_data_old *ret;
2126 ret = (struct qunit_data_old *)d;
2127 ret->qd_id = tmp.qd_id;
2128 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2129 ret->qd_count = (__u32)tmp.qd_count;
2130 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2133 EXPORT_SYMBOL(lustre_quota_new_to_old);
2134 #endif /* __KERNEL__ */
2136 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2138 LASSERT(req->rq_reqmsg);
2140 switch (req->rq_reqmsg->lm_magic) {
2141 case LUSTRE_MSG_MAGIC_V2:
2142 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2143 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2145 CERROR("bad lustre msg magic: %#08X\n",
2146 req->rq_reqmsg->lm_magic);
2151 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2153 LASSERT(req->rq_repmsg);
2155 switch (req->rq_repmsg->lm_magic) {
2156 case LUSTRE_MSG_MAGIC_V2:
2157 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2158 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2160 /* uninitialized yet */
2165 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2166 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2170 va_start(args, fmt);
2171 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2172 data->msg_fn, data->msg_line, fmt, args,
2173 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d/%d"
2174 " lens %d/%d e %d to %d dl %ld ref %d "
2175 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2176 req, req->rq_xid, req->rq_transno,
2177 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2178 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2179 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2181 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2183 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2185 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2186 req->rq_request_portal, req->rq_reply_portal,
2187 req->rq_reqlen, req->rq_replen,
2188 req->rq_early_count, req->rq_timeout, req->rq_deadline,
2189 atomic_read(&req->rq_refcount), DEBUG_REQ_FLAGS(req),
2190 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2191 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2192 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2193 lustre_msg_get_flags(req->rq_repmsg) : -1,
2195 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2196 lustre_msg_get_status(req->rq_repmsg) : -1);
2198 EXPORT_SYMBOL(_debug_req);
2200 void lustre_swab_lustre_capa(struct lustre_capa *c)
2202 lustre_swab_lu_fid(&c->lc_fid);
2203 __swab64s (&c->lc_opc);
2204 __swab32s (&c->lc_uid);
2205 __swab32s (&c->lc_flags);
2206 __swab32s (&c->lc_keyid);
2207 __swab32s (&c->lc_timeout);
2208 __swab64s (&c->lc_expiry);
2211 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2213 __swab64s (&k->lk_mdsid);
2214 __swab32s (&k->lk_keyid);
2215 __swab32s (&k->lk_padding);