1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ptlrpc/pack_generic.c
38 * (Un)packing of OST requests
40 * Author: Peter J. Braam <braam@clusterfs.com>
41 * Author: Phil Schwan <phil@clusterfs.com>
42 * Author: Eric Barton <eeb@clusterfs.com>
45 #define DEBUG_SUBSYSTEM S_RPC
47 # include <liblustre.h>
50 #include <libcfs/libcfs.h>
52 #include <obd_support.h>
53 #include <obd_class.h>
54 #include <lustre_net.h>
55 #include <obd_cksum.h>
56 #include <lustre/ll_fiemap.h>
58 static inline int lustre_msg_hdr_size_v2(int count)
60 return size_round(offsetof(struct lustre_msg_v2, lm_buflens[count]));
63 int lustre_msg_hdr_size(__u32 magic, int count)
66 case LUSTRE_MSG_MAGIC_V2:
67 return lustre_msg_hdr_size_v2(count);
69 LASSERTF(0, "incorrect message magic: %08x\n", magic);
73 EXPORT_SYMBOL(lustre_msg_hdr_size);
75 int lustre_msg_need_swab(struct lustre_msg *msg)
77 return (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
81 * \ret 0 - if need swabbed
84 static int ptlrpc_reqbuf_need_swab(struct ptlrpc_request *req, int index)
86 return (lustre_req_need_swab(req) && !lustre_req_swabbed(req, index));
90 * \ret 0 - if need swabbed
93 static int ptlrpc_repbuf_need_swab(struct ptlrpc_request *req, int index)
95 return (lustre_rep_need_swab(req) && !lustre_rep_swabbed(req, index));
99 * ptlrpc_req_need_swab - check the @req if need swab.
100 * @req - ptlrpc_request need to look at.
101 * @inout - =1 reqbuf, =0 repbuf.
102 * @index - message offset
107 int ptlrpc_req_need_swab(struct ptlrpc_request *req, int inout, int index)
110 return ptlrpc_reqbuf_need_swab(req, index);
112 return ptlrpc_repbuf_need_swab(req, index);
115 void ptlrpc_req_set_swabbed(struct ptlrpc_request *req, int inout, int index)
118 lustre_set_req_swabbed(req, index);
120 lustre_set_rep_swabbed(req, index);
125 lustre_msg_check_version_v2(struct lustre_msg_v2 *msg, __u32 version)
127 __u32 ver = lustre_msg_get_version(msg);
128 return (ver & LUSTRE_VERSION_MASK) != version;
131 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
133 switch (msg->lm_magic) {
134 case LUSTRE_MSG_MAGIC_V1:
135 CERROR("msg v1 not supported - please upgrade you system\n");
137 case LUSTRE_MSG_MAGIC_V2:
138 return lustre_msg_check_version_v2(msg, version);
140 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
145 /* early reply size */
146 int lustre_msg_early_size() {
149 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
152 EXPORT_SYMBOL(lustre_msg_early_size);
154 int lustre_msg_size_v2(int count, __u32 *lengths)
159 size = lustre_msg_hdr_size_v2(count);
160 for (i = 0; i < count; i++)
161 size += size_round(lengths[i]);
165 EXPORT_SYMBOL(lustre_msg_size_v2);
167 /* This returns the size of the buffer that is required to hold a lustre_msg
168 * with the given sub-buffer lengths.
169 * NOTE: this should only be used for NEW requests, and should always be
170 * in the form of a v2 request. If this is a connection to a v1
171 * target then the first buffer will be stripped because the ptlrpc
172 * data is part of the lustre_msg_v1 header. b=14043 */
173 int lustre_msg_size(__u32 magic, int count, __u32 *lens)
175 __u32 size[] = { sizeof(struct ptlrpc_body) };
183 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
186 case LUSTRE_MSG_MAGIC_V2:
187 return lustre_msg_size_v2(count, lens);
189 LASSERTF(0, "incorrect message magic: %08x\n", magic);
194 /* This is used to determine the size of a buffer that was already packed
195 * and will correctly handle the different message formats. */
196 int lustre_packed_msg_size(struct lustre_msg *msg)
198 switch (msg->lm_magic) {
199 case LUSTRE_MSG_MAGIC_V2:
200 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
202 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
207 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
213 msg->lm_bufcount = count;
214 /* XXX: lm_secflvr uninitialized here */
215 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
217 for (i = 0; i < count; i++)
218 msg->lm_buflens[i] = lens[i];
223 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
224 for (i = 0; i < count; i++) {
226 LOGL(tmp, lens[i], ptr);
229 EXPORT_SYMBOL(lustre_init_msg_v2);
231 static int lustre_pack_request_v2(struct ptlrpc_request *req,
232 int count, __u32 *lens, char **bufs)
236 reqlen = lustre_msg_size_v2(count, lens);
238 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
242 req->rq_reqlen = reqlen;
244 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
245 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
246 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
250 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
251 __u32 *lens, char **bufs)
253 __u32 size[] = { sizeof(struct ptlrpc_body) };
261 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
263 /* only use new format, we don't need to be compatible with 1.4 */
264 magic = LUSTRE_MSG_MAGIC_V2;
267 case LUSTRE_MSG_MAGIC_V2:
268 return lustre_pack_request_v2(req, count, lens, bufs);
270 LASSERTF(0, "incorrect message magic: %08x\n", magic);
276 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
277 spinlock_t ptlrpc_rs_debug_lock;
279 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
281 spin_lock(&ptlrpc_rs_debug_lock); \
282 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
283 spin_unlock(&ptlrpc_rs_debug_lock); \
286 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
288 spin_lock(&ptlrpc_rs_debug_lock); \
289 list_del(&(rs)->rs_debug_list); \
290 spin_unlock(&ptlrpc_rs_debug_lock); \
293 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
294 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
297 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
299 struct ptlrpc_reply_state *rs = NULL;
301 spin_lock(&svc->srv_lock);
302 /* See if we have anything in a pool, and wait if nothing */
303 while (list_empty(&svc->srv_free_rs_list)) {
304 struct l_wait_info lwi;
306 spin_unlock(&svc->srv_lock);
307 /* If we cannot get anything for some long time, we better
308 bail out instead of waiting infinitely */
309 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
310 rc = l_wait_event(svc->srv_free_rs_waitq,
311 !list_empty(&svc->srv_free_rs_list), &lwi);
314 spin_lock(&svc->srv_lock);
317 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
319 list_del(&rs->rs_list);
320 spin_unlock(&svc->srv_lock);
322 memset(rs, 0, svc->srv_max_reply_size);
323 rs->rs_service = svc;
329 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
331 struct ptlrpc_service *svc = rs->rs_service;
335 spin_lock(&svc->srv_lock);
336 list_add(&rs->rs_list, &svc->srv_free_rs_list);
337 spin_unlock(&svc->srv_lock);
338 cfs_waitq_signal(&svc->srv_free_rs_waitq);
341 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
342 __u32 *lens, char **bufs, int flags)
344 struct ptlrpc_reply_state *rs;
348 LASSERT(req->rq_reply_state == NULL);
350 if ((flags & LPRFL_EARLY_REPLY) == 0)
351 req->rq_packed_final = 1;
353 msg_len = lustre_msg_size_v2(count, lens);
354 rc = sptlrpc_svc_alloc_rs(req, msg_len);
358 rs = req->rq_reply_state;
359 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
360 rs->rs_cb_id.cbid_fn = reply_out_callback;
361 rs->rs_cb_id.cbid_arg = rs;
362 rs->rs_service = req->rq_rqbd->rqbd_service;
363 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
364 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
366 req->rq_replen = msg_len;
367 req->rq_reply_state = rs;
368 req->rq_repmsg = rs->rs_msg;
370 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
371 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
372 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
374 PTLRPC_RS_DEBUG_LRU_ADD(rs);
378 EXPORT_SYMBOL(lustre_pack_reply_v2);
380 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
381 char **bufs, int flags)
384 __u32 size[] = { sizeof(struct ptlrpc_body) };
392 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
394 switch (req->rq_reqmsg->lm_magic) {
395 case LUSTRE_MSG_MAGIC_V2:
396 case LUSTRE_MSG_MAGIC_V2_SWABBED:
397 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
400 LASSERTF(0, "incorrect message magic: %08x\n",
401 req->rq_reqmsg->lm_magic);
405 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
406 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
410 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
413 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
416 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
418 int i, offset, buflen, bufcount;
423 bufcount = m->lm_bufcount;
424 if (unlikely(n >= bufcount)) {
425 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
430 buflen = m->lm_buflens[n];
431 if (unlikely(buflen < min_size)) {
432 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
433 m, n, buflen, min_size);
437 offset = lustre_msg_hdr_size_v2(bufcount);
438 for (i = 0; i < n; i++)
439 offset += size_round(m->lm_buflens[i]);
441 return (char *)m + offset;
444 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
446 switch (m->lm_magic) {
447 case LUSTRE_MSG_MAGIC_V2:
448 case LUSTRE_MSG_MAGIC_V2_SWABBED:
449 return lustre_msg_buf_v2(m, n, min_size);
451 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
456 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int 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 += 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 memcpy(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);
514 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
516 PTLRPC_RS_DEBUG_LRU_DEL(rs);
518 LASSERT (atomic_read(&rs->rs_refcount) == 0);
519 LASSERT (!rs->rs_difficult || rs->rs_handled);
520 LASSERT (!rs->rs_on_net);
521 LASSERT (!rs->rs_scheduled);
522 LASSERT (rs->rs_export == NULL);
523 LASSERT (rs->rs_nlocks == 0);
524 LASSERT (list_empty(&rs->rs_exp_list));
525 LASSERT (list_empty(&rs->rs_obd_list));
527 sptlrpc_svc_free_rs(rs);
530 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
532 int flipped, required_len, i;
534 /* Now we know the sender speaks my language. */
535 required_len = lustre_msg_hdr_size_v2(0);
536 if (len < required_len) {
537 /* can't even look inside the message */
538 CERROR("message length %d too small for lustre_msg\n", len);
542 flipped = lustre_msg_need_swab(m);
544 __swab32s(&m->lm_magic);
545 __swab32s(&m->lm_bufcount);
546 __swab32s(&m->lm_secflvr);
547 __swab32s(&m->lm_repsize);
548 __swab32s(&m->lm_cksum);
549 __swab32s(&m->lm_flags);
550 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
551 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
554 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
555 if (len < required_len) {
556 /* didn't receive all the buffer lengths */
557 CERROR ("message length %d too small for %d buflens\n",
558 len, m->lm_bufcount);
562 for (i = 0; i < m->lm_bufcount; i++) {
564 __swab32s(&m->lm_buflens[i]);
565 required_len += size_round(m->lm_buflens[i]);
568 if (len < required_len) {
569 CERROR("len: %d, required_len %d\n", len, required_len);
570 CERROR("bufcount: %d\n", m->lm_bufcount);
571 for (i = 0; i < m->lm_bufcount; i++)
572 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
579 int lustre_unpack_msg(struct lustre_msg *m, int len)
581 int required_len, rc;
584 /* We can provide a slightly better error log, if we check the
585 * message magic and version first. In the future, struct
586 * lustre_msg may grow, and we'd like to log a version mismatch,
587 * rather than a short message.
590 required_len = offsetof(struct lustre_msg, lm_magic) +
592 if (len < required_len) {
593 /* can't even look inside the message */
594 CERROR("message length %d too small for magic/version check\n",
599 switch (m->lm_magic) {
600 case LUSTRE_MSG_MAGIC_V2:
601 case LUSTRE_MSG_MAGIC_V2_SWABBED:
602 rc = lustre_unpack_msg_v2(m, len);
605 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
612 static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
616 struct ptlrpc_body *pb;
617 struct lustre_msg_v2 *m = inout ? req->rq_reqmsg : req->rq_repmsg;
619 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
621 CERROR("error unpacking ptlrpc body\n");
624 if (ptlrpc_req_need_swab(req, inout, offset)) {
625 lustre_swab_ptlrpc_body(pb);
626 ptlrpc_req_set_swabbed(req, inout, offset);
629 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
630 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
637 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
639 switch (req->rq_reqmsg->lm_magic) {
640 case LUSTRE_MSG_MAGIC_V2:
641 return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
643 CERROR("bad lustre msg magic: %#08X\n",
644 req->rq_reqmsg->lm_magic);
649 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
651 switch (req->rq_repmsg->lm_magic) {
652 case LUSTRE_MSG_MAGIC_V2:
653 return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
655 CERROR("bad lustre msg magic: %#08X\n",
656 req->rq_repmsg->lm_magic);
661 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
663 if (n >= m->lm_bufcount)
666 return m->lm_buflens[n];
670 * lustre_msg_buflen - return the length of buffer @n in message @m
671 * @m - lustre_msg (request or reply) to look at
672 * @n - message index (base 0)
674 * returns zero for non-existent message indices
676 int lustre_msg_buflen(struct lustre_msg *m, int n)
678 switch (m->lm_magic) {
679 case LUSTRE_MSG_MAGIC_V2:
680 case LUSTRE_MSG_MAGIC_V2_SWABBED:
681 return lustre_msg_buflen_v2(m, n);
683 CERROR("incorrect message magic: %08x\n", m->lm_magic);
687 EXPORT_SYMBOL(lustre_msg_buflen);
690 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
692 if (n >= m->lm_bufcount)
695 m->lm_buflens[n] = len;
698 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
700 switch (m->lm_magic) {
701 case LUSTRE_MSG_MAGIC_V2:
702 lustre_msg_set_buflen_v2(m, n, len);
705 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
709 EXPORT_SYMBOL(lustre_msg_set_buflen);
711 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
712 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
713 int lustre_msg_bufcount(struct lustre_msg *m)
715 switch (m->lm_magic) {
716 case LUSTRE_MSG_MAGIC_V2:
717 case LUSTRE_MSG_MAGIC_V2_SWABBED:
718 return m->lm_bufcount;
720 CERROR("incorrect message magic: %08x\n", m->lm_magic);
724 EXPORT_SYMBOL(lustre_msg_bufcount);
726 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
728 /* max_len == 0 means the string should fill the buffer */
732 switch (m->lm_magic) {
733 case LUSTRE_MSG_MAGIC_V2:
734 case LUSTRE_MSG_MAGIC_V2_SWABBED:
735 str = lustre_msg_buf_v2(m, index, 0);
736 blen = lustre_msg_buflen_v2(m, index);
739 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
743 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
747 slen = strnlen(str, blen);
749 if (slen == blen) { /* not NULL terminated */
750 CERROR("can't unpack non-NULL terminated string in "
751 "msg %p buffer[%d] len %d\n", m, index, blen);
756 if (slen != blen - 1) {
757 CERROR("can't unpack short string in msg %p "
758 "buffer[%d] len %d: strlen %d\n",
759 m, index, blen, slen);
762 } else if (slen > max_len) {
763 CERROR("can't unpack oversized string in msg %p "
764 "buffer[%d] len %d strlen %d: max %d expected\n",
765 m, index, blen, slen, max_len);
772 /* Wrap up the normal fixed length cases */
773 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
778 switch (msg->lm_magic) {
779 case LUSTRE_MSG_MAGIC_V2:
780 case LUSTRE_MSG_MAGIC_V2_SWABBED:
781 ptr = lustre_msg_buf_v2(msg, index, min_size);
784 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
790 ((void (*)(void *))swabber)(ptr);
795 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
798 if (!ptlrpc_reqbuf_need_swab(req, index))
801 lustre_set_req_swabbed(req, index);
802 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
805 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
808 if (!ptlrpc_repbuf_need_swab(req, index))
811 lustre_set_rep_swabbed(req, index);
812 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
815 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
817 switch (msg->lm_magic) {
818 case LUSTRE_MSG_MAGIC_V1:
819 case LUSTRE_MSG_MAGIC_V1_SWABBED:
821 case LUSTRE_MSG_MAGIC_V2:
822 case LUSTRE_MSG_MAGIC_V2_SWABBED:
823 /* already in host endian */
824 return msg->lm_flags;
826 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
830 EXPORT_SYMBOL(lustre_msghdr_get_flags);
832 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
834 switch (msg->lm_magic) {
835 case LUSTRE_MSG_MAGIC_V1:
837 case LUSTRE_MSG_MAGIC_V2:
838 msg->lm_flags = flags;
841 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
845 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
847 switch (msg->lm_magic) {
848 case LUSTRE_MSG_MAGIC_V2:
849 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
850 struct ptlrpc_body *pb;
852 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
854 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
860 /* flags might be printed in debug code while message
866 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
868 switch (msg->lm_magic) {
869 case LUSTRE_MSG_MAGIC_V2: {
870 struct ptlrpc_body *pb;
872 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
873 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
874 pb->pb_flags |= flags;
878 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
882 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
884 switch (msg->lm_magic) {
885 case LUSTRE_MSG_MAGIC_V2: {
886 struct ptlrpc_body *pb;
888 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
889 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
890 pb->pb_flags = flags;
894 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
898 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
900 switch (msg->lm_magic) {
901 case LUSTRE_MSG_MAGIC_V2:
902 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
903 struct ptlrpc_body *pb;
905 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
906 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
907 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
911 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
915 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
917 switch (msg->lm_magic) {
918 case LUSTRE_MSG_MAGIC_V2:
919 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
920 struct ptlrpc_body *pb;
922 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
924 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
927 return pb->pb_op_flags;
934 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
936 switch (msg->lm_magic) {
937 case LUSTRE_MSG_MAGIC_V2: {
938 struct ptlrpc_body *pb;
940 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
941 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
942 pb->pb_op_flags |= flags;
946 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
950 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
952 switch (msg->lm_magic) {
953 case LUSTRE_MSG_MAGIC_V2: {
954 struct ptlrpc_body *pb;
956 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
957 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
958 pb->pb_op_flags |= flags;
962 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
966 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
968 switch (msg->lm_magic) {
969 case LUSTRE_MSG_MAGIC_V2:
970 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
971 struct ptlrpc_body *pb;
973 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
975 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
978 return &pb->pb_handle;
981 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
986 __u32 lustre_msg_get_type(struct lustre_msg *msg)
988 switch (msg->lm_magic) {
989 case LUSTRE_MSG_MAGIC_V2:
990 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
991 struct ptlrpc_body *pb;
993 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
995 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
996 return PTL_RPC_MSG_ERR;
1001 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1002 return PTL_RPC_MSG_ERR;
1006 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1008 switch (msg->lm_magic) {
1009 case LUSTRE_MSG_MAGIC_V2:
1010 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1011 struct ptlrpc_body *pb;
1013 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1015 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1018 return pb->pb_version;
1021 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1026 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1028 switch (msg->lm_magic) {
1029 case LUSTRE_MSG_MAGIC_V2:
1030 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1031 struct ptlrpc_body *pb;
1033 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1034 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1035 pb->pb_version |= version;
1039 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1043 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1045 switch (msg->lm_magic) {
1046 case LUSTRE_MSG_MAGIC_V2:
1047 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1048 struct ptlrpc_body *pb;
1050 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1052 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1058 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1063 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1065 switch (msg->lm_magic) {
1066 case LUSTRE_MSG_MAGIC_V2:
1067 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1068 struct ptlrpc_body *pb;
1070 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1072 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1075 return pb->pb_last_xid;
1078 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1083 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1085 switch (msg->lm_magic) {
1086 case LUSTRE_MSG_MAGIC_V2:
1087 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1088 struct ptlrpc_body *pb;
1090 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1092 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1095 return pb->pb_last_committed;
1098 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1103 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1105 switch (msg->lm_magic) {
1106 case LUSTRE_MSG_MAGIC_V2:
1107 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1108 struct ptlrpc_body *pb;
1110 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1112 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1115 return pb->pb_transno;
1118 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1123 int lustre_msg_get_status(struct lustre_msg *msg)
1125 switch (msg->lm_magic) {
1126 case LUSTRE_MSG_MAGIC_V2:
1127 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1128 struct ptlrpc_body *pb;
1130 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1132 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1135 return pb->pb_status;
1138 /* status might be printed in debug code while message
1144 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1146 switch (msg->lm_magic) {
1147 case LUSTRE_MSG_MAGIC_V2:
1148 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1149 struct ptlrpc_body *pb;
1151 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1153 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1159 CERROR("invalid msg magic %x\n", msg->lm_magic);
1165 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1167 switch (msg->lm_magic) {
1168 case LUSTRE_MSG_MAGIC_V2:
1169 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1170 struct ptlrpc_body *pb;
1172 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1174 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1181 CERROR("invalid msg magic %x\n", msg->lm_magic);
1186 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1188 switch (msg->lm_magic) {
1189 case LUSTRE_MSG_MAGIC_V2:
1190 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1191 struct ptlrpc_body *pb;
1193 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1195 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1198 return pb->pb_limit;
1201 CERROR("invalid msg magic %x\n", msg->lm_magic);
1207 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1209 switch (msg->lm_magic) {
1210 case LUSTRE_MSG_MAGIC_V2:
1211 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1212 struct ptlrpc_body *pb;
1214 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1216 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1219 pb->pb_limit = limit;
1223 CERROR("invalid msg magic %x\n", msg->lm_magic);
1228 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1230 switch (msg->lm_magic) {
1231 case LUSTRE_MSG_MAGIC_V2:
1232 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1233 struct ptlrpc_body *pb;
1235 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1237 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1240 return pb->pb_conn_cnt;
1243 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1248 int lustre_msg_is_v1(struct lustre_msg *msg)
1250 switch (msg->lm_magic) {
1251 case LUSTRE_MSG_MAGIC_V1:
1252 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1259 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1261 switch (msg->lm_magic) {
1262 case LUSTRE_MSG_MAGIC_V2:
1263 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1264 return msg->lm_magic;
1266 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1271 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
1273 switch (msg->lm_magic) {
1274 case LUSTRE_MSG_MAGIC_V1:
1275 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1277 case LUSTRE_MSG_MAGIC_V2:
1278 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1279 struct ptlrpc_body *pb;
1281 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1283 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1287 return pb->pb_timeout;
1290 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1295 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1297 switch (msg->lm_magic) {
1298 case LUSTRE_MSG_MAGIC_V1:
1299 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1301 case LUSTRE_MSG_MAGIC_V2:
1302 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1303 struct ptlrpc_body *pb;
1305 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1307 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1311 return pb->pb_service_time;
1314 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1319 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1321 switch (msg->lm_magic) {
1322 case LUSTRE_MSG_MAGIC_V1:
1323 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1325 case LUSTRE_MSG_MAGIC_V2:
1326 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1327 return msg->lm_cksum;
1329 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1334 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1336 switch (msg->lm_magic) {
1337 case LUSTRE_MSG_MAGIC_V1:
1338 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1340 case LUSTRE_MSG_MAGIC_V2:
1341 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1342 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 return crc32_le(~(__u32)0, (unsigned char *)pb, sizeof(*pb));
1348 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1353 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
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_handle = *handle;
1365 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1369 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
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);
1381 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1385 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
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);
1397 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1401 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
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_last_xid = last_xid;
1413 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1417 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1419 switch (msg->lm_magic) {
1420 case LUSTRE_MSG_MAGIC_V2: {
1421 struct ptlrpc_body *pb;
1423 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1424 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1425 pb->pb_last_committed = last_committed;
1429 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1433 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1435 switch (msg->lm_magic) {
1436 case LUSTRE_MSG_MAGIC_V2: {
1437 struct ptlrpc_body *pb;
1439 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1440 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1441 pb->pb_transno = transno;
1445 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1449 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1451 switch (msg->lm_magic) {
1452 case LUSTRE_MSG_MAGIC_V2: {
1453 struct ptlrpc_body *pb;
1455 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1456 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1457 pb->pb_status = status;
1461 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1465 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1467 switch (msg->lm_magic) {
1468 case LUSTRE_MSG_MAGIC_V2: {
1469 struct ptlrpc_body *pb;
1471 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1472 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1473 pb->pb_conn_cnt = conn_cnt;
1477 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1481 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1483 switch (msg->lm_magic) {
1484 case LUSTRE_MSG_MAGIC_V1:
1486 case LUSTRE_MSG_MAGIC_V2: {
1487 struct ptlrpc_body *pb;
1489 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1490 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1491 pb->pb_timeout = timeout;
1495 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1499 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1501 switch (msg->lm_magic) {
1502 case LUSTRE_MSG_MAGIC_V1:
1504 case LUSTRE_MSG_MAGIC_V2: {
1505 struct ptlrpc_body *pb;
1507 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
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_cksum(struct lustre_msg *msg, __u32 cksum)
1519 switch (msg->lm_magic) {
1520 case LUSTRE_MSG_MAGIC_V1:
1522 case LUSTRE_MSG_MAGIC_V2:
1523 msg->lm_cksum = cksum;
1526 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1531 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1533 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1535 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1536 req->rq_pill.rc_area[RCL_SERVER]);
1537 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1538 req->rq_reqmsg->lm_repsize = req->rq_replen;
1541 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
1543 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1544 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1545 req->rq_reqmsg->lm_repsize = req->rq_replen;
1548 /* byte flipping routines for all wire types declared in
1549 * lustre_idl.h implemented here.
1551 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1553 __swab32s (&b->pb_type);
1554 __swab32s (&b->pb_version);
1555 __swab32s (&b->pb_opc);
1556 __swab32s (&b->pb_status);
1557 __swab64s (&b->pb_last_xid);
1558 __swab64s (&b->pb_last_seen);
1559 __swab64s (&b->pb_last_committed);
1560 __swab64s (&b->pb_transno);
1561 __swab32s (&b->pb_flags);
1562 __swab32s (&b->pb_op_flags);
1563 __swab32s (&b->pb_conn_cnt);
1564 __swab32s (&b->pb_timeout);
1565 __swab32s (&b->pb_service_time);
1566 __swab32s (&b->pb_limit);
1567 __swab64s (&b->pb_slv);
1568 __swab64s (&b->pb_pre_versions[0]);
1569 __swab64s (&b->pb_pre_versions[1]);
1570 __swab64s (&b->pb_pre_versions[2]);
1571 __swab64s (&b->pb_pre_versions[3]);
1572 CLASSERT(offsetof(typeof(*b), pb_padding) != 0);
1575 void lustre_swab_connect(struct obd_connect_data *ocd)
1577 __swab64s(&ocd->ocd_connect_flags);
1578 __swab32s(&ocd->ocd_version);
1579 __swab32s(&ocd->ocd_grant);
1580 __swab64s(&ocd->ocd_ibits_known);
1581 __swab32s(&ocd->ocd_index);
1582 __swab32s(&ocd->ocd_brw_size);
1583 __swab32s(&ocd->ocd_nllu);
1584 __swab32s(&ocd->ocd_nllg);
1585 __swab64s(&ocd->ocd_transno);
1586 __swab32s(&ocd->ocd_group);
1587 __swab32s(&ocd->ocd_cksum_types);
1588 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1589 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1592 void lustre_swab_obdo (struct obdo *o)
1594 __swab64s (&o->o_valid);
1595 __swab64s (&o->o_id);
1596 __swab64s (&o->o_gr);
1597 __swab64s (&o->o_fid);
1598 __swab64s (&o->o_size);
1599 __swab64s (&o->o_mtime);
1600 __swab64s (&o->o_atime);
1601 __swab64s (&o->o_ctime);
1602 __swab64s (&o->o_blocks);
1603 __swab64s (&o->o_grant);
1604 __swab32s (&o->o_blksize);
1605 __swab32s (&o->o_mode);
1606 __swab32s (&o->o_uid);
1607 __swab32s (&o->o_gid);
1608 __swab32s (&o->o_flags);
1609 __swab32s (&o->o_nlink);
1610 __swab32s (&o->o_generation);
1611 __swab32s (&o->o_misc);
1612 __swab32s (&o->o_easize);
1613 __swab32s (&o->o_mds);
1614 __swab32s (&o->o_stripe_idx);
1615 __swab32s (&o->o_padding_1);
1616 /* o_inline is opaque */
1619 void lustre_swab_obd_statfs (struct obd_statfs *os)
1621 __swab64s (&os->os_type);
1622 __swab64s (&os->os_blocks);
1623 __swab64s (&os->os_bfree);
1624 __swab64s (&os->os_bavail);
1625 __swab64s (&os->os_files);
1626 __swab64s (&os->os_ffree);
1627 /* no need to swab os_fsid */
1628 __swab32s (&os->os_bsize);
1629 __swab32s (&os->os_namelen);
1630 __swab64s (&os->os_maxbytes);
1631 __swab32s (&os->os_state);
1632 /* no need to swap os_spare */
1635 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1637 __swab64s (&ioo->ioo_id);
1638 __swab64s (&ioo->ioo_gr);
1639 __swab32s (&ioo->ioo_type);
1640 __swab32s (&ioo->ioo_bufcnt);
1643 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1645 __swab64s (&nbr->offset);
1646 __swab32s (&nbr->len);
1647 __swab32s (&nbr->flags);
1650 void lustre_swab_ost_body (struct ost_body *b)
1652 lustre_swab_obdo (&b->oa);
1655 void lustre_swab_ost_last_id(obd_id *id)
1660 void lustre_swab_generic_32s(__u32 *val)
1665 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1667 __swab64s(&lvb->lvb_size);
1668 __swab64s(&lvb->lvb_mtime);
1669 __swab64s(&lvb->lvb_atime);
1670 __swab64s(&lvb->lvb_ctime);
1671 __swab64s(&lvb->lvb_blocks);
1674 void lustre_swab_mds_status_req (struct mds_status_req *r)
1676 __swab32s (&r->flags);
1677 __swab32s (&r->repbuf);
1680 void lustre_swab_mds_body (struct mds_body *b)
1682 lustre_swab_ll_fid (&b->fid1);
1683 lustre_swab_ll_fid (&b->fid2);
1684 /* handle is opaque */
1685 __swab64s (&b->valid);
1686 __swab64s (&b->size);
1687 __swab64s (&b->mtime);
1688 __swab64s (&b->atime);
1689 __swab64s (&b->ctime);
1690 __swab64s (&b->blocks);
1691 __swab64s (&b->io_epoch);
1692 __swab64s (&b->ino);
1693 __swab32s (&b->fsuid);
1694 __swab32s (&b->fsgid);
1695 __swab32s (&b->capability);
1696 __swab32s (&b->mode);
1697 __swab32s (&b->uid);
1698 __swab32s (&b->gid);
1699 __swab32s (&b->flags);
1700 __swab32s (&b->rdev);
1701 __swab32s (&b->nlink);
1702 __swab32s (&b->generation);
1703 __swab32s (&b->suppgid);
1704 __swab32s (&b->eadatasize);
1705 __swab32s (&b->aclsize);
1706 __swab32s (&b->max_mdsize);
1707 __swab32s (&b->max_cookiesize);
1708 __swab32s (&b->padding_4);
1711 void lustre_swab_mdt_body (struct mdt_body *b)
1713 lustre_swab_lu_fid (&b->fid1);
1714 lustre_swab_lu_fid (&b->fid2);
1715 /* handle is opaque */
1716 __swab64s (&b->valid);
1717 __swab64s (&b->size);
1718 __swab64s (&b->mtime);
1719 __swab64s (&b->atime);
1720 __swab64s (&b->ctime);
1721 __swab64s (&b->blocks);
1722 __swab64s (&b->ioepoch);
1723 __swab64s (&b->ino);
1724 __swab32s (&b->fsuid);
1725 __swab32s (&b->fsgid);
1726 __swab32s (&b->capability);
1727 __swab32s (&b->mode);
1728 __swab32s (&b->uid);
1729 __swab32s (&b->gid);
1730 __swab32s (&b->flags);
1731 __swab32s (&b->rdev);
1732 __swab32s (&b->nlink);
1733 __swab32s (&b->generation);
1734 __swab32s (&b->suppgid);
1735 __swab32s (&b->eadatasize);
1736 __swab32s (&b->aclsize);
1737 __swab32s (&b->max_mdsize);
1738 __swab32s (&b->max_cookiesize);
1739 __swab32s (&b->padding_4);
1742 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1744 /* handle is opaque */
1745 __swab64s (&b->ioepoch);
1746 __swab32s (&b->flags);
1747 CLASSERT(offsetof(typeof(*b), padding) != 0);
1750 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1753 __swab32s(&mti->mti_lustre_ver);
1754 __swab32s(&mti->mti_stripe_index);
1755 __swab32s(&mti->mti_config_ver);
1756 __swab32s(&mti->mti_flags);
1757 __swab32s(&mti->mti_nid_count);
1758 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1759 for (i = 0; i < MTI_NIDS_MAX; i++)
1760 __swab64s(&mti->mti_nids[i]);
1763 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1765 __swab64s (&i->dqi_bgrace);
1766 __swab64s (&i->dqi_igrace);
1767 __swab32s (&i->dqi_flags);
1768 __swab32s (&i->dqi_valid);
1771 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1773 __swab64s (&b->dqb_ihardlimit);
1774 __swab64s (&b->dqb_isoftlimit);
1775 __swab64s (&b->dqb_curinodes);
1776 __swab64s (&b->dqb_bhardlimit);
1777 __swab64s (&b->dqb_bsoftlimit);
1778 __swab64s (&b->dqb_curspace);
1779 __swab64s (&b->dqb_btime);
1780 __swab64s (&b->dqb_itime);
1781 __swab32s (&b->dqb_valid);
1782 CLASSERT(offsetof(typeof(*b), padding) != 0);
1785 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1787 __swab32s (&q->qc_cmd);
1788 __swab32s (&q->qc_type);
1789 __swab32s (&q->qc_id);
1790 __swab32s (&q->qc_stat);
1791 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1792 lustre_swab_obd_dqblk (&q->qc_dqblk);
1795 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1797 __swab32s (&p->rp_uid);
1798 __swab32s (&p->rp_gid);
1799 __swab32s (&p->rp_fsuid);
1800 __swab32s (&p->rp_fsgid);
1801 __swab32s (&p->rp_access_perm);
1804 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1806 __swab32s (&p->rp_uid);
1807 __swab32s (&p->rp_gid);
1808 __swab32s (&p->rp_fsuid);
1809 __swab32s (&p->rp_fsgid);
1810 __swab32s (&p->rp_access_perm);
1813 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1815 __swab32s (&sa->sa_opcode);
1816 __swab32s (&sa->sa_fsuid);
1817 __swab32s (&sa->sa_fsgid);
1818 __swab32s (&sa->sa_cap);
1819 __swab32s (&sa->sa_suppgid);
1820 __swab32s (&sa->sa_mode);
1821 lustre_swab_ll_fid (&sa->sa_fid);
1822 __swab64s (&sa->sa_valid);
1823 __swab64s (&sa->sa_size);
1824 __swab64s (&sa->sa_mtime);
1825 __swab64s (&sa->sa_atime);
1826 __swab64s (&sa->sa_ctime);
1827 __swab32s (&sa->sa_uid);
1828 __swab32s (&sa->sa_gid);
1829 __swab32s (&sa->sa_attr_flags);
1830 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1833 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1835 __swab64s(&jr->jr_headsize);
1836 lustre_swab_ll_fid(&jr->jr_fid);
1839 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1841 __swab64s(&jr->jr_headsize);
1842 lustre_swab_lu_fid(&jr->jr_fid);
1845 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1847 __swab32s (&cr->cr_opcode);
1848 __swab32s (&cr->cr_fsuid);
1849 __swab32s (&cr->cr_fsgid);
1850 __swab32s (&cr->cr_cap);
1851 __swab32s (&cr->cr_flags); /* for use with open */
1852 __swab32s (&cr->cr_mode);
1853 lustre_swab_ll_fid (&cr->cr_fid);
1854 lustre_swab_ll_fid (&cr->cr_replayfid);
1855 __swab64s (&cr->cr_time);
1856 __swab64s (&cr->cr_rdev);
1857 __swab32s (&cr->cr_suppgid);
1858 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1859 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1860 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1861 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1862 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1865 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1867 __swab32s (&lk->lk_opcode);
1868 __swab32s (&lk->lk_fsuid);
1869 __swab32s (&lk->lk_fsgid);
1870 __swab32s (&lk->lk_cap);
1871 __swab32s (&lk->lk_suppgid1);
1872 __swab32s (&lk->lk_suppgid2);
1873 lustre_swab_ll_fid (&lk->lk_fid1);
1874 lustre_swab_ll_fid (&lk->lk_fid2);
1875 __swab64s (&lk->lk_time);
1876 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1877 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1878 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1879 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1882 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1884 __swab32s (&ul->ul_opcode);
1885 __swab32s (&ul->ul_fsuid);
1886 __swab32s (&ul->ul_fsgid);
1887 __swab32s (&ul->ul_cap);
1888 __swab32s (&ul->ul_suppgid);
1889 __swab32s (&ul->ul_mode);
1890 lustre_swab_ll_fid (&ul->ul_fid1);
1891 lustre_swab_ll_fid (&ul->ul_fid2);
1892 __swab64s (&ul->ul_time);
1893 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1894 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1895 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1896 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1899 void lustre_swab_fiemap_extent(struct ll_fiemap_extent *fm_extent)
1901 __swab64s(&fm_extent->fe_logical);
1902 __swab64s(&fm_extent->fe_physical);
1903 __swab64s(&fm_extent->fe_length);
1904 __swab32s(&fm_extent->fe_flags);
1905 __swab32s(&fm_extent->fe_device);
1908 void lustre_swab_fiemap(struct ll_user_fiemap *fiemap)
1912 __swab64s(&fiemap->fm_start);
1913 __swab64s(&fiemap->fm_length);
1914 __swab32s(&fiemap->fm_flags);
1915 __swab32s(&fiemap->fm_mapped_extents);
1916 __swab32s(&fiemap->fm_extent_count);
1917 __swab32s(&fiemap->fm_reserved);
1919 for (i = 0; i < fiemap->fm_mapped_extents; i++)
1920 lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
1923 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1925 __swab32s (&rn->rn_opcode);
1926 __swab32s (&rn->rn_fsuid);
1927 __swab32s (&rn->rn_fsgid);
1928 __swab32s (&rn->rn_cap);
1929 __swab32s (&rn->rn_suppgid1);
1930 __swab32s (&rn->rn_suppgid2);
1931 lustre_swab_ll_fid (&rn->rn_fid1);
1932 lustre_swab_ll_fid (&rn->rn_fid2);
1933 __swab64s (&rn->rn_time);
1934 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1935 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1936 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1937 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1940 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
1942 __swab32s (&rr->rr_opcode);
1943 __swab32s (&rr->rr_fsuid);
1944 __swab32s (&rr->rr_fsgid);
1945 __swab32s (&rr->rr_cap);
1946 __swab32s (&rr->rr_suppgid1);
1947 __swab32s (&rr->rr_suppgid2);
1948 /* handle is opaque */
1949 lustre_swab_lu_fid (&rr->rr_fid1);
1950 lustre_swab_lu_fid (&rr->rr_fid2);
1951 __swab64s (&rr->rr_mtime);
1952 __swab64s (&rr->rr_atime);
1953 __swab64s (&rr->rr_ctime);
1954 __swab64s (&rr->rr_size);
1955 __swab64s (&rr->rr_blocks);
1956 __swab32s (&rr->rr_bias);
1957 __swab32s (&rr->rr_mode);
1958 __swab32s (&rr->rr_padding_1);
1959 __swab32s (&rr->rr_padding_2);
1960 __swab32s (&rr->rr_padding_3);
1961 __swab32s (&rr->rr_padding_4);
1963 CLASSERT(offsetof(typeof(*rr), rr_padding_1) != 0);
1964 CLASSERT(offsetof(typeof(*rr), rr_padding_2) != 0);
1965 CLASSERT(offsetof(typeof(*rr), rr_padding_3) != 0);
1966 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
1969 void lustre_swab_lov_desc (struct lov_desc *ld)
1971 __swab32s (&ld->ld_tgt_count);
1972 __swab32s (&ld->ld_active_tgt_count);
1973 __swab32s (&ld->ld_default_stripe_count);
1974 __swab64s (&ld->ld_default_stripe_size);
1975 __swab64s (&ld->ld_default_stripe_offset);
1976 __swab32s (&ld->ld_pattern);
1977 __swab32s (&ld->ld_qos_maxage);
1978 /* uuid endian insensitive */
1981 /*begin adding MDT by huanghua@clusterfs.com*/
1982 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1984 __swab32s (&ld->ld_tgt_count);
1985 __swab32s (&ld->ld_active_tgt_count);
1986 /* uuid endian insensitive */
1988 /*end adding MDT by huanghua@clusterfs.com*/
1989 void lustre_swab_md_fld (struct md_fld *mf)
1991 __swab64s(&mf->mf_seq);
1992 __swab64s(&mf->mf_mds);
1995 static void print_lum (struct lov_user_md *lum)
1997 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1998 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1999 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2000 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
2001 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
2002 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2003 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2004 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
2007 static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
2010 __swab32s(&lum->lmm_magic);
2011 __swab32s(&lum->lmm_pattern);
2012 __swab64s(&lum->lmm_object_id);
2013 __swab64s(&lum->lmm_object_gr);
2014 __swab32s(&lum->lmm_stripe_size);
2015 __swab16s(&lum->lmm_stripe_count);
2016 __swab16s(&lum->lmm_stripe_offset);
2021 static void print_lumj (struct lov_user_md_join *lumj)
2023 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2024 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2025 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2026 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2027 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2028 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2029 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2030 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2033 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
2036 CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
2037 lustre_swab_lov_user_md_common(lum);
2041 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum)
2044 CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
2045 lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
2046 /* lmm_pool_name nothing to do with char */
2050 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2053 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2054 __swab32s(&lumj->lmm_magic);
2055 __swab32s(&lumj->lmm_pattern);
2056 __swab64s(&lumj->lmm_object_id);
2057 __swab64s(&lumj->lmm_object_gr);
2058 __swab32s(&lumj->lmm_stripe_size);
2059 __swab32s(&lumj->lmm_stripe_count);
2060 __swab32s(&lumj->lmm_extent_count);
2065 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
2070 for (i = 0; i < stripe_count; i++) {
2071 __swab64s(&(lod[i].l_object_id));
2072 __swab64s(&(lod[i].l_object_gr));
2073 __swab32s(&(lod[i].l_ost_gen));
2074 __swab32s(&(lod[i].l_ost_idx));
2080 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2084 for (i = 0; i < RES_NAME_SIZE; i++)
2085 __swab64s (&id->name[i]);
2088 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2090 /* the lock data is a union and the first two fields are always an
2091 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2092 * data the same way. */
2093 __swab64s(&d->l_extent.start);
2094 __swab64s(&d->l_extent.end);
2095 __swab64s(&d->l_extent.gid);
2096 __swab32s(&d->l_flock.pid);
2099 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2101 __swab64s (&i->opc);
2104 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2106 __swab32s (&r->lr_type);
2107 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2108 lustre_swab_ldlm_res_id (&r->lr_name);
2111 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2113 lustre_swab_ldlm_resource_desc (&l->l_resource);
2114 __swab32s (&l->l_req_mode);
2115 __swab32s (&l->l_granted_mode);
2116 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2119 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2121 __swab32s (&rq->lock_flags);
2122 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2123 __swab32s (&rq->lock_count);
2124 /* lock_handle[] opaque */
2127 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2129 __swab32s (&r->lock_flags);
2130 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2131 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2132 /* lock_handle opaque */
2133 __swab64s (&r->lock_policy_res1);
2134 __swab64s (&r->lock_policy_res2);
2137 /* no one calls this */
2138 int llog_log_swabbed(struct llog_log_hdr *hdr)
2140 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2142 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2147 void lustre_swab_qdata(struct qunit_data *d)
2149 __swab32s (&d->qd_id);
2150 __swab32s (&d->qd_flags);
2151 __swab64s (&d->qd_count);
2154 void lustre_swab_qdata_old(struct qunit_data_old *d)
2156 __swab32s (&d->qd_id);
2157 __swab32s (&d->qd_type);
2158 __swab32s (&d->qd_count);
2159 __swab32s (&d->qd_isblk);
2163 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2165 struct qunit_data_old tmp;
2166 struct qunit_data *ret;
2173 ret = (struct qunit_data *)d;
2174 ret->qd_id = tmp.qd_id;
2175 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2176 ret->qd_count = tmp.qd_count;
2180 EXPORT_SYMBOL(lustre_quota_old_to_new);
2182 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2184 struct qunit_data tmp;
2185 struct qunit_data_old *ret;
2192 ret = (struct qunit_data_old *)d;
2193 ret->qd_id = tmp.qd_id;
2194 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2195 ret->qd_count = (__u32)tmp.qd_count;
2196 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2199 EXPORT_SYMBOL(lustre_quota_new_to_old);
2200 #endif /* __KERNEL__ */
2202 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2204 LASSERT(req->rq_reqmsg);
2206 switch (req->rq_reqmsg->lm_magic) {
2207 case LUSTRE_MSG_MAGIC_V2:
2208 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2209 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2211 CERROR("bad lustre msg magic: %#08X\n",
2212 req->rq_reqmsg->lm_magic);
2217 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2219 LASSERT(req->rq_repmsg);
2221 switch (req->rq_repmsg->lm_magic) {
2222 case LUSTRE_MSG_MAGIC_V2:
2223 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2224 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2226 /* uninitialized yet */
2231 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2232 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2236 va_start(args, fmt);
2237 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2238 data->msg_fn, data->msg_line, fmt, args,
2239 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d/%d"
2240 " lens %d/%d e %d to %d dl "CFS_TIME_T" ref %d "
2241 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2242 req, req->rq_xid, req->rq_transno,
2243 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2244 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2245 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2247 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2249 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2251 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2252 req->rq_request_portal, req->rq_reply_portal,
2253 req->rq_reqlen, req->rq_replen,
2254 req->rq_early_count, req->rq_timeout, req->rq_deadline,
2255 atomic_read(&req->rq_refcount), DEBUG_REQ_FLAGS(req),
2256 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2257 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2258 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2259 lustre_msg_get_flags(req->rq_repmsg) : -1,
2261 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2262 lustre_msg_get_status(req->rq_repmsg) : -1);
2264 EXPORT_SYMBOL(_debug_req);
2266 void lustre_swab_lustre_capa(struct lustre_capa *c)
2268 lustre_swab_lu_fid(&c->lc_fid);
2269 __swab64s (&c->lc_opc);
2270 __swab32s (&c->lc_uid);
2271 __swab32s (&c->lc_flags);
2272 __swab32s (&c->lc_keyid);
2273 __swab32s (&c->lc_timeout);
2274 __swab64s (&c->lc_expiry);
2277 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2279 __swab64s (&k->lk_mdsid);
2280 __swab32s (&k->lk_keyid);
2281 __swab32s (&k->lk_padding);