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 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
79 lustre_set_req_swabbed(req, index);
81 lustre_set_rep_swabbed(req, index);
84 int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
88 return (ptlrpc_req_need_swab(req) &&
89 !lustre_req_swabbed(req, index));
91 return (ptlrpc_rep_need_swab(req) &&
92 !lustre_rep_swabbed(req, index));
95 static inline int lustre_msg_check_version_v2(struct lustre_msg_v2 *msg,
98 __u32 ver = lustre_msg_get_version(msg);
99 return (ver & LUSTRE_VERSION_MASK) != version;
102 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
104 switch (msg->lm_magic) {
105 case LUSTRE_MSG_MAGIC_V1:
106 CERROR("msg v1 not supported - please upgrade you system\n");
108 case LUSTRE_MSG_MAGIC_V2:
109 return lustre_msg_check_version_v2(msg, version);
111 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
116 /* early reply size */
117 int lustre_msg_early_size()
121 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
124 EXPORT_SYMBOL(lustre_msg_early_size);
126 int lustre_msg_size_v2(int count, __u32 *lengths)
131 size = lustre_msg_hdr_size_v2(count);
132 for (i = 0; i < count; i++)
133 size += size_round(lengths[i]);
137 EXPORT_SYMBOL(lustre_msg_size_v2);
139 /* This returns the size of the buffer that is required to hold a lustre_msg
140 * with the given sub-buffer lengths.
141 * NOTE: this should only be used for NEW requests, and should always be
142 * in the form of a v2 request. If this is a connection to a v1
143 * target then the first buffer will be stripped because the ptlrpc
144 * data is part of the lustre_msg_v1 header. b=14043 */
145 int lustre_msg_size(__u32 magic, int count, __u32 *lens)
147 __u32 size[] = { sizeof(struct ptlrpc_body) };
155 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
158 case LUSTRE_MSG_MAGIC_V2:
159 return lustre_msg_size_v2(count, lens);
161 LASSERTF(0, "incorrect message magic: %08x\n", magic);
166 /* This is used to determine the size of a buffer that was already packed
167 * and will correctly handle the different message formats. */
168 int lustre_packed_msg_size(struct lustre_msg *msg)
170 switch (msg->lm_magic) {
171 case LUSTRE_MSG_MAGIC_V2:
172 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
174 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
179 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
185 msg->lm_bufcount = count;
186 /* XXX: lm_secflvr uninitialized here */
187 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
189 for (i = 0; i < count; i++)
190 msg->lm_buflens[i] = lens[i];
195 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
196 for (i = 0; i < count; i++) {
198 LOGL(tmp, lens[i], ptr);
201 EXPORT_SYMBOL(lustre_init_msg_v2);
203 static int lustre_pack_request_v2(struct ptlrpc_request *req,
204 int count, __u32 *lens, char **bufs)
208 reqlen = lustre_msg_size_v2(count, lens);
210 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
214 req->rq_reqlen = reqlen;
216 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
217 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
221 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
222 __u32 *lens, char **bufs)
224 __u32 size[] = { sizeof(struct ptlrpc_body) };
232 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
234 /* only use new format, we don't need to be compatible with 1.4 */
235 magic = LUSTRE_MSG_MAGIC_V2;
238 case LUSTRE_MSG_MAGIC_V2:
239 return lustre_pack_request_v2(req, count, lens, bufs);
241 LASSERTF(0, "incorrect message magic: %08x\n", magic);
247 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
248 spinlock_t ptlrpc_rs_debug_lock;
250 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
252 spin_lock(&ptlrpc_rs_debug_lock); \
253 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
254 spin_unlock(&ptlrpc_rs_debug_lock); \
257 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
259 spin_lock(&ptlrpc_rs_debug_lock); \
260 list_del(&(rs)->rs_debug_list); \
261 spin_unlock(&ptlrpc_rs_debug_lock); \
264 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
265 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
268 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
270 struct ptlrpc_reply_state *rs = NULL;
272 spin_lock(&svc->srv_lock);
273 /* See if we have anything in a pool, and wait if nothing */
274 while (list_empty(&svc->srv_free_rs_list)) {
275 struct l_wait_info lwi;
277 spin_unlock(&svc->srv_lock);
278 /* If we cannot get anything for some long time, we better
279 bail out instead of waiting infinitely */
280 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
281 rc = l_wait_event(svc->srv_free_rs_waitq,
282 !list_empty(&svc->srv_free_rs_list), &lwi);
285 spin_lock(&svc->srv_lock);
288 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
290 list_del(&rs->rs_list);
291 spin_unlock(&svc->srv_lock);
293 memset(rs, 0, svc->srv_max_reply_size);
294 rs->rs_service = svc;
300 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
302 struct ptlrpc_service *svc = rs->rs_service;
306 spin_lock(&svc->srv_lock);
307 list_add(&rs->rs_list, &svc->srv_free_rs_list);
308 spin_unlock(&svc->srv_lock);
309 cfs_waitq_signal(&svc->srv_free_rs_waitq);
312 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
313 __u32 *lens, char **bufs, int flags)
315 struct ptlrpc_reply_state *rs;
319 LASSERT(req->rq_reply_state == NULL);
321 if ((flags & LPRFL_EARLY_REPLY) == 0)
322 req->rq_packed_final = 1;
324 msg_len = lustre_msg_size_v2(count, lens);
325 rc = sptlrpc_svc_alloc_rs(req, msg_len);
329 rs = req->rq_reply_state;
330 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
331 rs->rs_cb_id.cbid_fn = reply_out_callback;
332 rs->rs_cb_id.cbid_arg = rs;
333 rs->rs_service = req->rq_rqbd->rqbd_service;
334 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
335 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
336 CFS_INIT_LIST_HEAD(&rs->rs_list);
337 spin_lock_init(&rs->rs_lock);
339 req->rq_replen = msg_len;
340 req->rq_reply_state = rs;
341 req->rq_repmsg = rs->rs_msg;
343 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
344 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
346 PTLRPC_RS_DEBUG_LRU_ADD(rs);
350 EXPORT_SYMBOL(lustre_pack_reply_v2);
352 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
353 char **bufs, int flags)
356 __u32 size[] = { sizeof(struct ptlrpc_body) };
364 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
366 switch (req->rq_reqmsg->lm_magic) {
367 case LUSTRE_MSG_MAGIC_V2:
368 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
371 LASSERTF(0, "incorrect message magic: %08x\n",
372 req->rq_reqmsg->lm_magic);
376 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
377 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
381 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
384 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
387 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
389 int i, offset, buflen, bufcount;
394 bufcount = m->lm_bufcount;
395 if (unlikely(n >= bufcount)) {
396 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
401 buflen = m->lm_buflens[n];
402 if (unlikely(buflen < min_size)) {
403 CERROR("msg %p buffer[%d] size %d too small "
404 "(required %d, opc=%d)\n", m, n, buflen, min_size,
405 n == MSG_PTLRPC_BODY_OFF ? -1 : lustre_msg_get_opc(m));
409 offset = lustre_msg_hdr_size_v2(bufcount);
410 for (i = 0; i < n; i++)
411 offset += size_round(m->lm_buflens[i]);
413 return (char *)m + offset;
416 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
418 switch (m->lm_magic) {
419 case LUSTRE_MSG_MAGIC_V2:
420 return lustre_msg_buf_v2(m, n, min_size);
422 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
427 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
428 unsigned int newlen, int move_data)
430 char *tail = NULL, *newpos;
434 LASSERT(msg->lm_bufcount > segment);
435 LASSERT(msg->lm_buflens[segment] >= newlen);
437 if (msg->lm_buflens[segment] == newlen)
440 if (move_data && msg->lm_bufcount > segment + 1) {
441 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
442 for (n = segment + 1; n < msg->lm_bufcount; n++)
443 tail_len += size_round(msg->lm_buflens[n]);
446 msg->lm_buflens[segment] = newlen;
448 if (tail && tail_len) {
449 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
450 LASSERT(newpos <= tail);
452 memmove(newpos, tail, tail_len);
455 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
459 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
460 * we also move data forward from @segment + 1.
462 * if @newlen == 0, we remove the segment completely, but we still keep the
463 * totally bufcount the same to save possible data moving. this will leave a
464 * unused segment with size 0 at the tail, but that's ok.
466 * return new msg size after shrinking.
469 * + if any buffers higher than @segment has been filled in, must call shrink
470 * with non-zero @move_data.
471 * + caller should NOT keep pointers to msg buffers which higher than @segment
474 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
475 unsigned int newlen, int move_data)
477 switch (msg->lm_magic) {
478 case LUSTRE_MSG_MAGIC_V2:
479 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
481 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
485 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
487 PTLRPC_RS_DEBUG_LRU_DEL(rs);
489 LASSERT (atomic_read(&rs->rs_refcount) == 0);
490 LASSERT (!rs->rs_difficult || rs->rs_handled);
491 LASSERT (!rs->rs_on_net);
492 LASSERT (!rs->rs_scheduled);
493 LASSERT (rs->rs_export == NULL);
494 LASSERT (rs->rs_nlocks == 0);
495 LASSERT (list_empty(&rs->rs_exp_list));
496 LASSERT (list_empty(&rs->rs_obd_list));
498 sptlrpc_svc_free_rs(rs);
501 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
503 int swabbed, required_len, i;
505 /* Now we know the sender speaks my language. */
506 required_len = lustre_msg_hdr_size_v2(0);
507 if (len < required_len) {
508 /* can't even look inside the message */
509 CERROR("message length %d too small for lustre_msg\n", len);
513 swabbed = (m->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
516 __swab32s(&m->lm_magic);
517 __swab32s(&m->lm_bufcount);
518 __swab32s(&m->lm_secflvr);
519 __swab32s(&m->lm_repsize);
520 __swab32s(&m->lm_cksum);
521 __swab32s(&m->lm_flags);
522 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
523 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
526 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
527 if (len < required_len) {
528 /* didn't receive all the buffer lengths */
529 CERROR ("message length %d too small for %d buflens\n",
530 len, m->lm_bufcount);
534 for (i = 0; i < m->lm_bufcount; i++) {
536 __swab32s(&m->lm_buflens[i]);
537 required_len += size_round(m->lm_buflens[i]);
540 if (len < required_len) {
541 CERROR("len: %d, required_len %d\n", len, required_len);
542 CERROR("bufcount: %d\n", m->lm_bufcount);
543 for (i = 0; i < m->lm_bufcount; i++)
544 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
551 int __lustre_unpack_msg(struct lustre_msg *m, int len)
553 int required_len, rc;
556 /* We can provide a slightly better error log, if we check the
557 * message magic and version first. In the future, struct
558 * lustre_msg may grow, and we'd like to log a version mismatch,
559 * rather than a short message.
562 required_len = offsetof(struct lustre_msg, lm_magic) +
564 if (len < required_len) {
565 /* can't even look inside the message */
566 CERROR("message length %d too small for magic/version check\n",
571 rc = lustre_unpack_msg_v2(m, len);
575 EXPORT_SYMBOL(__lustre_unpack_msg);
577 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len)
580 rc = __lustre_unpack_msg(req->rq_reqmsg, len);
582 lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
588 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len)
591 rc = __lustre_unpack_msg(req->rq_repmsg, len);
593 lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
599 static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
600 const int inout, int offset)
602 struct ptlrpc_body *pb;
603 struct lustre_msg_v2 *m = inout ? req->rq_reqmsg : req->rq_repmsg;
605 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
607 CERROR("error unpacking ptlrpc body\n");
610 if (ptlrpc_buf_need_swab(req, inout, offset)) {
611 lustre_swab_ptlrpc_body(pb);
612 ptlrpc_buf_set_swabbed(req, inout, offset);
615 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
616 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
623 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
625 switch (req->rq_reqmsg->lm_magic) {
626 case LUSTRE_MSG_MAGIC_V2:
627 return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
629 CERROR("bad lustre msg magic: %08x\n",
630 req->rq_reqmsg->lm_magic);
635 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
637 switch (req->rq_repmsg->lm_magic) {
638 case LUSTRE_MSG_MAGIC_V2:
639 return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
641 CERROR("bad lustre msg magic: %08x\n",
642 req->rq_repmsg->lm_magic);
647 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
649 if (n >= m->lm_bufcount)
652 return m->lm_buflens[n];
656 * lustre_msg_buflen - return the length of buffer \a n in message \a m
657 * \param m lustre_msg (request or reply) to look at
658 * \param n message index (base 0)
660 * returns zero for non-existent message indices
662 int lustre_msg_buflen(struct lustre_msg *m, int n)
664 switch (m->lm_magic) {
665 case LUSTRE_MSG_MAGIC_V2:
666 return lustre_msg_buflen_v2(m, n);
668 CERROR("incorrect message magic: %08x\n", m->lm_magic);
672 EXPORT_SYMBOL(lustre_msg_buflen);
675 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
677 if (n >= m->lm_bufcount)
680 m->lm_buflens[n] = len;
683 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
685 switch (m->lm_magic) {
686 case LUSTRE_MSG_MAGIC_V2:
687 lustre_msg_set_buflen_v2(m, n, len);
690 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
694 EXPORT_SYMBOL(lustre_msg_set_buflen);
696 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
697 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
698 int lustre_msg_bufcount(struct lustre_msg *m)
700 switch (m->lm_magic) {
701 case LUSTRE_MSG_MAGIC_V2:
702 return m->lm_bufcount;
704 CERROR("incorrect message magic: %08x\n", m->lm_magic);
708 EXPORT_SYMBOL(lustre_msg_bufcount);
710 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
712 /* max_len == 0 means the string should fill the buffer */
716 switch (m->lm_magic) {
717 case LUSTRE_MSG_MAGIC_V2:
718 str = lustre_msg_buf_v2(m, index, 0);
719 blen = lustre_msg_buflen_v2(m, index);
722 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
726 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
730 slen = strnlen(str, blen);
732 if (slen == blen) { /* not NULL terminated */
733 CERROR("can't unpack non-NULL terminated string in "
734 "msg %p buffer[%d] len %d\n", m, index, blen);
739 if (slen != blen - 1) {
740 CERROR("can't unpack short string in msg %p "
741 "buffer[%d] len %d: strlen %d\n",
742 m, index, blen, slen);
745 } else if (slen > max_len) {
746 CERROR("can't unpack oversized string in msg %p "
747 "buffer[%d] len %d strlen %d: max %d expected\n",
748 m, index, blen, slen, max_len);
755 /* Wrap up the normal fixed length cases */
756 static inline void *__lustre_swab_buf(struct lustre_msg *msg, int index,
757 int min_size, void *swabber)
761 LASSERT(msg != NULL);
762 switch (msg->lm_magic) {
763 case LUSTRE_MSG_MAGIC_V2:
764 ptr = lustre_msg_buf_v2(msg, index, min_size);
767 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
771 ((void (*)(void *))swabber)(ptr);
776 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
779 if (!ptlrpc_buf_need_swab(req, 1, index))
780 return lustre_msg_buf(req->rq_reqmsg, index, min_size);
782 lustre_set_req_swabbed(req, index);
783 return __lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
786 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index,
787 int min_size, void *swabber)
789 if (!ptlrpc_buf_need_swab(req, 0, index))
790 return lustre_msg_buf(req->rq_repmsg, index, min_size);
792 lustre_set_rep_swabbed(req, index);
793 return __lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
796 static inline struct ptlrpc_body *lustre_msg_ptlrpc_body(struct lustre_msg *msg)
798 return lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
799 sizeof(struct ptlrpc_body));
802 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
804 switch (msg->lm_magic) {
805 case LUSTRE_MSG_MAGIC_V1:
806 case LUSTRE_MSG_MAGIC_V1_SWABBED:
808 case LUSTRE_MSG_MAGIC_V2:
809 /* already in host endian */
810 return msg->lm_flags;
812 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
816 EXPORT_SYMBOL(lustre_msghdr_get_flags);
818 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
820 switch (msg->lm_magic) {
821 case LUSTRE_MSG_MAGIC_V1:
823 case LUSTRE_MSG_MAGIC_V2:
824 msg->lm_flags = flags;
827 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
831 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
833 switch (msg->lm_magic) {
834 case LUSTRE_MSG_MAGIC_V2: {
835 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
837 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
843 /* flags might be printed in debug code while message
849 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
851 switch (msg->lm_magic) {
852 case LUSTRE_MSG_MAGIC_V2: {
853 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
854 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
855 pb->pb_flags |= flags;
859 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
863 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
865 switch (msg->lm_magic) {
866 case LUSTRE_MSG_MAGIC_V2: {
867 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
868 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
869 pb->pb_flags = flags;
873 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
877 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
879 switch (msg->lm_magic) {
880 case LUSTRE_MSG_MAGIC_V2: {
881 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
882 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
883 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
887 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
891 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
893 switch (msg->lm_magic) {
894 case LUSTRE_MSG_MAGIC_V2: {
895 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
897 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
900 return pb->pb_op_flags;
907 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
909 switch (msg->lm_magic) {
910 case LUSTRE_MSG_MAGIC_V2: {
911 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
912 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
913 pb->pb_op_flags |= flags;
917 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
921 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
923 switch (msg->lm_magic) {
924 case LUSTRE_MSG_MAGIC_V2: {
925 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
926 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
927 pb->pb_op_flags |= flags;
931 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
935 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
937 switch (msg->lm_magic) {
938 case LUSTRE_MSG_MAGIC_V2: {
939 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
941 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
944 return &pb->pb_handle;
947 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
952 __u32 lustre_msg_get_type(struct lustre_msg *msg)
954 switch (msg->lm_magic) {
955 case LUSTRE_MSG_MAGIC_V2: {
956 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
958 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
959 return PTL_RPC_MSG_ERR;
964 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
965 return PTL_RPC_MSG_ERR;
969 __u32 lustre_msg_get_version(struct lustre_msg *msg)
971 switch (msg->lm_magic) {
972 case LUSTRE_MSG_MAGIC_V2: {
973 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
975 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
978 return pb->pb_version;
981 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
986 void lustre_msg_add_version(struct lustre_msg *msg, int version)
988 switch (msg->lm_magic) {
989 case LUSTRE_MSG_MAGIC_V2: {
990 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
991 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
992 pb->pb_version |= version;
996 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1000 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1002 switch (msg->lm_magic) {
1003 case LUSTRE_MSG_MAGIC_V2: {
1004 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1006 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1012 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1018 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1020 switch (msg->lm_magic) {
1021 case LUSTRE_MSG_MAGIC_V2: {
1022 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1024 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1027 return pb->pb_last_xid;
1030 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1035 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1037 switch (msg->lm_magic) {
1038 case LUSTRE_MSG_MAGIC_V2: {
1039 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1041 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1044 return pb->pb_last_committed;
1047 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1052 __u64 *lustre_msg_get_versions(struct lustre_msg *msg)
1054 switch (msg->lm_magic) {
1055 case LUSTRE_MSG_MAGIC_V1:
1057 case LUSTRE_MSG_MAGIC_V2: {
1058 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1060 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1063 return pb->pb_pre_versions;
1066 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1071 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1073 switch (msg->lm_magic) {
1074 case LUSTRE_MSG_MAGIC_V2: {
1075 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1077 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1080 return pb->pb_transno;
1083 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1088 int lustre_msg_get_status(struct lustre_msg *msg)
1090 switch (msg->lm_magic) {
1091 case LUSTRE_MSG_MAGIC_V2: {
1092 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1094 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1097 return pb->pb_status;
1100 /* status might be printed in debug code while message
1106 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1108 switch (msg->lm_magic) {
1109 case LUSTRE_MSG_MAGIC_V2: {
1110 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1112 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1118 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1124 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1126 switch (msg->lm_magic) {
1127 case LUSTRE_MSG_MAGIC_V2: {
1128 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1130 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1137 CERROR("invalid msg magic %x\n", msg->lm_magic);
1142 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1144 switch (msg->lm_magic) {
1145 case LUSTRE_MSG_MAGIC_V2: {
1146 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1148 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1151 return pb->pb_limit;
1154 CERROR("invalid msg magic %x\n", msg->lm_magic);
1160 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1162 switch (msg->lm_magic) {
1163 case LUSTRE_MSG_MAGIC_V2: {
1164 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1166 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1169 pb->pb_limit = limit;
1173 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1178 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1180 switch (msg->lm_magic) {
1181 case LUSTRE_MSG_MAGIC_V2: {
1182 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1184 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1187 return pb->pb_conn_cnt;
1190 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1195 int lustre_msg_is_v1(struct lustre_msg *msg)
1197 switch (msg->lm_magic) {
1198 case LUSTRE_MSG_MAGIC_V1:
1199 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1206 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1208 switch (msg->lm_magic) {
1209 case LUSTRE_MSG_MAGIC_V2:
1210 return msg->lm_magic;
1212 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1217 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
1219 switch (msg->lm_magic) {
1220 case LUSTRE_MSG_MAGIC_V1:
1221 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1223 case LUSTRE_MSG_MAGIC_V2: {
1224 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1226 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1230 return pb->pb_timeout;
1233 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1238 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1240 switch (msg->lm_magic) {
1241 case LUSTRE_MSG_MAGIC_V1:
1242 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1244 case LUSTRE_MSG_MAGIC_V2: {
1245 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1247 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1251 return pb->pb_service_time;
1254 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1259 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1261 switch (msg->lm_magic) {
1262 case LUSTRE_MSG_MAGIC_V2:
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_V2: {
1274 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1275 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1276 return crc32_le(~(__u32)0, (unsigned char *)pb, sizeof(*pb));
1279 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1284 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1286 switch (msg->lm_magic) {
1287 case LUSTRE_MSG_MAGIC_V2: {
1288 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1289 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1290 pb->pb_handle = *handle;
1294 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1298 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1300 switch (msg->lm_magic) {
1301 case LUSTRE_MSG_MAGIC_V2: {
1302 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1303 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1308 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1312 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1314 switch (msg->lm_magic) {
1315 case LUSTRE_MSG_MAGIC_V2: {
1316 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1317 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1322 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1326 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1328 switch (msg->lm_magic) {
1329 case LUSTRE_MSG_MAGIC_V2: {
1330 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1331 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1332 pb->pb_last_xid = last_xid;
1336 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1340 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1342 switch (msg->lm_magic) {
1343 case LUSTRE_MSG_MAGIC_V2: {
1344 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1345 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1346 pb->pb_last_committed = last_committed;
1350 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1354 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions)
1356 switch (msg->lm_magic) {
1357 case LUSTRE_MSG_MAGIC_V1:
1359 case LUSTRE_MSG_MAGIC_V2: {
1360 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1361 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1362 pb->pb_pre_versions[0] = versions[0];
1363 pb->pb_pre_versions[1] = versions[1];
1364 pb->pb_pre_versions[2] = versions[2];
1365 pb->pb_pre_versions[3] = versions[3];
1369 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1373 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1375 switch (msg->lm_magic) {
1376 case LUSTRE_MSG_MAGIC_V2: {
1377 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1378 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1379 pb->pb_transno = transno;
1383 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1387 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1389 switch (msg->lm_magic) {
1390 case LUSTRE_MSG_MAGIC_V2: {
1391 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
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 = lustre_msg_ptlrpc_body(msg);
1406 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1407 pb->pb_conn_cnt = conn_cnt;
1411 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1415 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1417 switch (msg->lm_magic) {
1418 case LUSTRE_MSG_MAGIC_V1:
1420 case LUSTRE_MSG_MAGIC_V2: {
1421 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1422 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1423 pb->pb_timeout = timeout;
1427 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1431 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1433 switch (msg->lm_magic) {
1434 case LUSTRE_MSG_MAGIC_V1:
1436 case LUSTRE_MSG_MAGIC_V2: {
1437 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1438 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1439 pb->pb_service_time = service_time;
1443 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1447 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1449 switch (msg->lm_magic) {
1450 case LUSTRE_MSG_MAGIC_V1:
1452 case LUSTRE_MSG_MAGIC_V2:
1453 msg->lm_cksum = cksum;
1456 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1461 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1463 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1465 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1466 req->rq_pill.rc_area[RCL_SERVER]);
1467 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1468 req->rq_reqmsg->lm_repsize = req->rq_replen;
1471 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
1473 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1474 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1475 req->rq_reqmsg->lm_repsize = req->rq_replen;
1478 /* byte flipping routines for all wire types declared in
1479 * lustre_idl.h implemented here.
1481 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1483 __swab32s (&b->pb_type);
1484 __swab32s (&b->pb_version);
1485 __swab32s (&b->pb_opc);
1486 __swab32s (&b->pb_status);
1487 __swab64s (&b->pb_last_xid);
1488 __swab64s (&b->pb_last_seen);
1489 __swab64s (&b->pb_last_committed);
1490 __swab64s (&b->pb_transno);
1491 __swab32s (&b->pb_flags);
1492 __swab32s (&b->pb_op_flags);
1493 __swab32s (&b->pb_conn_cnt);
1494 __swab32s (&b->pb_timeout);
1495 __swab32s (&b->pb_service_time);
1496 __swab32s (&b->pb_limit);
1497 __swab64s (&b->pb_slv);
1498 __swab64s (&b->pb_pre_versions[0]);
1499 __swab64s (&b->pb_pre_versions[1]);
1500 __swab64s (&b->pb_pre_versions[2]);
1501 __swab64s (&b->pb_pre_versions[3]);
1502 CLASSERT(offsetof(typeof(*b), pb_padding) != 0);
1505 void lustre_swab_connect(struct obd_connect_data *ocd)
1507 __swab64s(&ocd->ocd_connect_flags);
1508 __swab32s(&ocd->ocd_version);
1509 __swab32s(&ocd->ocd_grant);
1510 __swab64s(&ocd->ocd_ibits_known);
1511 __swab32s(&ocd->ocd_index);
1512 __swab32s(&ocd->ocd_brw_size);
1513 __swab32s(&ocd->ocd_nllu);
1514 __swab32s(&ocd->ocd_nllg);
1515 __swab64s(&ocd->ocd_transno);
1516 __swab32s(&ocd->ocd_group);
1517 __swab32s(&ocd->ocd_cksum_types);
1518 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1519 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1522 void lustre_swab_obdo (struct obdo *o)
1524 __swab64s (&o->o_valid);
1525 __swab64s (&o->o_id);
1526 __swab64s (&o->o_gr);
1527 __swab64s (&o->o_fid);
1528 __swab64s (&o->o_size);
1529 __swab64s (&o->o_mtime);
1530 __swab64s (&o->o_atime);
1531 __swab64s (&o->o_ctime);
1532 __swab64s (&o->o_blocks);
1533 __swab64s (&o->o_grant);
1534 __swab32s (&o->o_blksize);
1535 __swab32s (&o->o_mode);
1536 __swab32s (&o->o_uid);
1537 __swab32s (&o->o_gid);
1538 __swab32s (&o->o_flags);
1539 __swab32s (&o->o_nlink);
1540 __swab32s (&o->o_generation);
1541 __swab32s (&o->o_misc);
1542 __swab32s (&o->o_easize);
1543 __swab32s (&o->o_mds);
1544 __swab32s (&o->o_stripe_idx);
1545 __swab32s (&o->o_padding_1);
1546 /* o_inline is opaque */
1549 void lustre_swab_obd_statfs (struct obd_statfs *os)
1551 __swab64s (&os->os_type);
1552 __swab64s (&os->os_blocks);
1553 __swab64s (&os->os_bfree);
1554 __swab64s (&os->os_bavail);
1555 __swab64s (&os->os_files);
1556 __swab64s (&os->os_ffree);
1557 /* no need to swab os_fsid */
1558 __swab32s (&os->os_bsize);
1559 __swab32s (&os->os_namelen);
1560 __swab64s (&os->os_maxbytes);
1561 __swab32s (&os->os_state);
1562 /* no need to swap os_spare */
1565 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1567 __swab64s (&ioo->ioo_id);
1568 __swab64s (&ioo->ioo_gr);
1569 __swab32s (&ioo->ioo_type);
1570 __swab32s (&ioo->ioo_bufcnt);
1573 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1575 __swab64s (&nbr->offset);
1576 __swab32s (&nbr->len);
1577 __swab32s (&nbr->flags);
1580 void lustre_swab_ost_body (struct ost_body *b)
1582 lustre_swab_obdo (&b->oa);
1585 void lustre_swab_ost_last_id(obd_id *id)
1590 void lustre_swab_generic_32s(__u32 *val)
1595 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1597 __swab64s(&lvb->lvb_size);
1598 __swab64s(&lvb->lvb_mtime);
1599 __swab64s(&lvb->lvb_atime);
1600 __swab64s(&lvb->lvb_ctime);
1601 __swab64s(&lvb->lvb_blocks);
1604 void lustre_swab_mds_status_req (struct mds_status_req *r)
1606 __swab32s (&r->flags);
1607 __swab32s (&r->repbuf);
1610 void lustre_swab_mds_body (struct mds_body *b)
1612 lustre_swab_ll_fid (&b->fid1);
1613 lustre_swab_ll_fid (&b->fid2);
1614 /* handle is opaque */
1615 __swab64s (&b->valid);
1616 __swab64s (&b->size);
1617 __swab64s (&b->mtime);
1618 __swab64s (&b->atime);
1619 __swab64s (&b->ctime);
1620 __swab64s (&b->blocks);
1621 __swab64s (&b->io_epoch);
1622 __swab64s (&b->ino);
1623 __swab32s (&b->fsuid);
1624 __swab32s (&b->fsgid);
1625 __swab32s (&b->capability);
1626 __swab32s (&b->mode);
1627 __swab32s (&b->uid);
1628 __swab32s (&b->gid);
1629 __swab32s (&b->flags);
1630 __swab32s (&b->rdev);
1631 __swab32s (&b->nlink);
1632 __swab32s (&b->generation);
1633 __swab32s (&b->suppgid);
1634 __swab32s (&b->eadatasize);
1635 __swab32s (&b->aclsize);
1636 __swab32s (&b->max_mdsize);
1637 __swab32s (&b->max_cookiesize);
1638 __swab32s (&b->padding_4);
1641 void lustre_swab_mdt_body (struct mdt_body *b)
1643 lustre_swab_lu_fid (&b->fid1);
1644 lustre_swab_lu_fid (&b->fid2);
1645 /* handle is opaque */
1646 __swab64s (&b->valid);
1647 __swab64s (&b->size);
1648 __swab64s (&b->mtime);
1649 __swab64s (&b->atime);
1650 __swab64s (&b->ctime);
1651 __swab64s (&b->blocks);
1652 __swab64s (&b->ioepoch);
1653 __swab64s (&b->ino);
1654 __swab32s (&b->fsuid);
1655 __swab32s (&b->fsgid);
1656 __swab32s (&b->capability);
1657 __swab32s (&b->mode);
1658 __swab32s (&b->uid);
1659 __swab32s (&b->gid);
1660 __swab32s (&b->flags);
1661 __swab32s (&b->rdev);
1662 __swab32s (&b->nlink);
1663 __swab32s (&b->generation);
1664 __swab32s (&b->suppgid);
1665 __swab32s (&b->eadatasize);
1666 __swab32s (&b->aclsize);
1667 __swab32s (&b->max_mdsize);
1668 __swab32s (&b->max_cookiesize);
1669 __swab32s (&b->padding_4);
1672 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1674 /* handle is opaque */
1675 __swab64s (&b->ioepoch);
1676 __swab32s (&b->flags);
1677 CLASSERT(offsetof(typeof(*b), padding) != 0);
1680 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1683 __swab32s(&mti->mti_lustre_ver);
1684 __swab32s(&mti->mti_stripe_index);
1685 __swab32s(&mti->mti_config_ver);
1686 __swab32s(&mti->mti_flags);
1687 __swab32s(&mti->mti_nid_count);
1688 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1689 for (i = 0; i < MTI_NIDS_MAX; i++)
1690 __swab64s(&mti->mti_nids[i]);
1693 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1695 __swab64s (&i->dqi_bgrace);
1696 __swab64s (&i->dqi_igrace);
1697 __swab32s (&i->dqi_flags);
1698 __swab32s (&i->dqi_valid);
1701 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1703 __swab64s (&b->dqb_ihardlimit);
1704 __swab64s (&b->dqb_isoftlimit);
1705 __swab64s (&b->dqb_curinodes);
1706 __swab64s (&b->dqb_bhardlimit);
1707 __swab64s (&b->dqb_bsoftlimit);
1708 __swab64s (&b->dqb_curspace);
1709 __swab64s (&b->dqb_btime);
1710 __swab64s (&b->dqb_itime);
1711 __swab32s (&b->dqb_valid);
1712 CLASSERT(offsetof(typeof(*b), padding) != 0);
1715 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1717 __swab32s (&q->qc_cmd);
1718 __swab32s (&q->qc_type);
1719 __swab32s (&q->qc_id);
1720 __swab32s (&q->qc_stat);
1721 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1722 lustre_swab_obd_dqblk (&q->qc_dqblk);
1725 void lustre_swab_quota_adjust_qunit (struct quota_adjust_qunit *q)
1727 __swab32s (&q->qaq_flags);
1728 __swab32s (&q->qaq_id);
1729 __swab64s (&q->qaq_bunit_sz);
1730 __swab64s (&q->qaq_iunit_sz);
1731 __swab64s (&q->padding1);
1734 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1736 __swab32s (&p->rp_uid);
1737 __swab32s (&p->rp_gid);
1738 __swab32s (&p->rp_fsuid);
1739 __swab32s (&p->rp_fsgid);
1740 __swab32s (&p->rp_access_perm);
1743 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1745 __swab32s (&p->rp_uid);
1746 __swab32s (&p->rp_gid);
1747 __swab32s (&p->rp_fsuid);
1748 __swab32s (&p->rp_fsgid);
1749 __swab32s (&p->rp_access_perm);
1752 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1754 __swab32s (&sa->sa_opcode);
1755 __swab32s (&sa->sa_fsuid);
1756 __swab32s (&sa->sa_fsgid);
1757 __swab32s (&sa->sa_cap);
1758 __swab32s (&sa->sa_suppgid);
1759 __swab32s (&sa->sa_mode);
1760 lustre_swab_ll_fid (&sa->sa_fid);
1761 __swab64s (&sa->sa_valid);
1762 __swab64s (&sa->sa_size);
1763 __swab64s (&sa->sa_mtime);
1764 __swab64s (&sa->sa_atime);
1765 __swab64s (&sa->sa_ctime);
1766 __swab32s (&sa->sa_uid);
1767 __swab32s (&sa->sa_gid);
1768 __swab32s (&sa->sa_attr_flags);
1769 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1772 void lustre_swab_fid2path(struct getinfo_fid2path *gf)
1774 lustre_swab_lu_fid(&gf->gf_fid);
1775 __swab64s(&gf->gf_recno);
1776 __swab32s(&gf->gf_linkno);
1777 __swab32s(&gf->gf_pathlen);
1779 EXPORT_SYMBOL(lustre_swab_fid2path);
1781 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1783 __swab64s(&jr->jr_headsize);
1784 lustre_swab_ll_fid(&jr->jr_fid);
1787 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1789 __swab64s(&jr->jr_headsize);
1790 lustre_swab_lu_fid(&jr->jr_fid);
1793 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1795 __swab32s (&cr->cr_opcode);
1796 __swab32s (&cr->cr_fsuid);
1797 __swab32s (&cr->cr_fsgid);
1798 __swab32s (&cr->cr_cap);
1799 __swab32s (&cr->cr_flags); /* for use with open */
1800 __swab32s (&cr->cr_mode);
1801 lustre_swab_ll_fid (&cr->cr_fid);
1802 lustre_swab_ll_fid (&cr->cr_replayfid);
1803 __swab64s (&cr->cr_time);
1804 __swab64s (&cr->cr_rdev);
1805 __swab32s (&cr->cr_suppgid);
1806 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1807 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1808 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1809 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1810 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1813 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1815 __swab32s (&lk->lk_opcode);
1816 __swab32s (&lk->lk_fsuid);
1817 __swab32s (&lk->lk_fsgid);
1818 __swab32s (&lk->lk_cap);
1819 __swab32s (&lk->lk_suppgid1);
1820 __swab32s (&lk->lk_suppgid2);
1821 lustre_swab_ll_fid (&lk->lk_fid1);
1822 lustre_swab_ll_fid (&lk->lk_fid2);
1823 __swab64s (&lk->lk_time);
1824 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1825 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1826 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1827 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1830 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1832 __swab32s (&ul->ul_opcode);
1833 __swab32s (&ul->ul_fsuid);
1834 __swab32s (&ul->ul_fsgid);
1835 __swab32s (&ul->ul_cap);
1836 __swab32s (&ul->ul_suppgid);
1837 __swab32s (&ul->ul_mode);
1838 lustre_swab_ll_fid (&ul->ul_fid1);
1839 lustre_swab_ll_fid (&ul->ul_fid2);
1840 __swab64s (&ul->ul_time);
1841 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1842 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1843 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1844 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1847 void lustre_swab_fiemap_extent(struct ll_fiemap_extent *fm_extent)
1849 __swab64s(&fm_extent->fe_logical);
1850 __swab64s(&fm_extent->fe_physical);
1851 __swab64s(&fm_extent->fe_length);
1852 __swab32s(&fm_extent->fe_flags);
1853 __swab32s(&fm_extent->fe_device);
1856 void lustre_swab_fiemap(struct ll_user_fiemap *fiemap)
1860 __swab64s(&fiemap->fm_start);
1861 __swab64s(&fiemap->fm_length);
1862 __swab32s(&fiemap->fm_flags);
1863 __swab32s(&fiemap->fm_mapped_extents);
1864 __swab32s(&fiemap->fm_extent_count);
1865 __swab32s(&fiemap->fm_reserved);
1867 for (i = 0; i < fiemap->fm_mapped_extents; i++)
1868 lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
1871 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1873 __swab32s (&rn->rn_opcode);
1874 __swab32s (&rn->rn_fsuid);
1875 __swab32s (&rn->rn_fsgid);
1876 __swab32s (&rn->rn_cap);
1877 __swab32s (&rn->rn_suppgid1);
1878 __swab32s (&rn->rn_suppgid2);
1879 lustre_swab_ll_fid (&rn->rn_fid1);
1880 lustre_swab_ll_fid (&rn->rn_fid2);
1881 __swab64s (&rn->rn_time);
1882 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1883 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1884 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1885 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1888 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
1890 __swab32s (&rr->rr_opcode);
1891 __swab32s (&rr->rr_cap);
1892 __swab32s (&rr->rr_fsuid);
1893 /* rr_fsuid_h is unused */
1894 __swab32s (&rr->rr_fsgid);
1895 /* rr_fsgid_h is unused */
1896 __swab32s (&rr->rr_suppgid1);
1897 /* rr_suppgid1_h is unused */
1898 __swab32s (&rr->rr_suppgid2);
1899 /* rr_suppgid2_h is unused */
1900 lustre_swab_lu_fid (&rr->rr_fid1);
1901 lustre_swab_lu_fid (&rr->rr_fid2);
1902 __swab64s (&rr->rr_mtime);
1903 __swab64s (&rr->rr_atime);
1904 __swab64s (&rr->rr_ctime);
1905 __swab64s (&rr->rr_size);
1906 __swab64s (&rr->rr_blocks);
1907 __swab32s (&rr->rr_bias);
1908 __swab32s (&rr->rr_mode);
1909 __swab32s (&rr->rr_padding_1);
1910 __swab32s (&rr->rr_padding_2);
1911 __swab32s (&rr->rr_padding_3);
1912 __swab32s (&rr->rr_padding_4);
1914 CLASSERT(offsetof(typeof(*rr), rr_padding_1) != 0);
1915 CLASSERT(offsetof(typeof(*rr), rr_padding_2) != 0);
1916 CLASSERT(offsetof(typeof(*rr), rr_padding_3) != 0);
1917 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
1920 void lustre_swab_lov_desc (struct lov_desc *ld)
1922 __swab32s (&ld->ld_tgt_count);
1923 __swab32s (&ld->ld_active_tgt_count);
1924 __swab32s (&ld->ld_default_stripe_count);
1925 __swab32s (&ld->ld_pattern);
1926 __swab64s (&ld->ld_default_stripe_size);
1927 __swab64s (&ld->ld_default_stripe_offset);
1928 __swab32s (&ld->ld_qos_maxage);
1929 /* uuid endian insensitive */
1932 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1934 __swab32s (&ld->ld_tgt_count);
1935 __swab32s (&ld->ld_active_tgt_count);
1936 __swab32s (&ld->ld_default_stripe_count);
1937 __swab32s (&ld->ld_pattern);
1938 __swab64s (&ld->ld_default_hash_size);
1939 __swab32s (&ld->ld_qos_maxage);
1940 /* uuid endian insensitive */
1943 void lustre_swab_lmv_stripe_md (struct lmv_stripe_md *mea)
1945 __swab32s(&mea->mea_magic);
1946 __swab32s(&mea->mea_count);
1947 __swab32s(&mea->mea_master);
1948 CLASSERT(offsetof(typeof(*mea), mea_padding) != 0);
1952 static void print_lum (struct lov_user_md *lum)
1954 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1955 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1956 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1957 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1958 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
1959 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1960 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1961 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1964 static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
1967 __swab32s(&lum->lmm_magic);
1968 __swab32s(&lum->lmm_pattern);
1969 __swab64s(&lum->lmm_object_id);
1970 __swab64s(&lum->lmm_object_gr);
1971 __swab32s(&lum->lmm_stripe_size);
1972 __swab16s(&lum->lmm_stripe_count);
1973 __swab16s(&lum->lmm_stripe_offset);
1978 static void print_lumj (struct lov_user_md_join *lumj)
1980 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
1981 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
1982 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
1983 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
1984 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
1985 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
1986 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
1987 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
1990 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
1993 CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
1994 lustre_swab_lov_user_md_common(lum);
1998 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum)
2001 CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
2002 lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
2003 /* lmm_pool_name nothing to do with char */
2007 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2010 CDEBUG(D_IOCTL, "swabbing lov_mds_md\n");
2011 __swab32s(&lmm->lmm_magic);
2012 __swab32s(&lmm->lmm_pattern);
2013 __swab64s(&lmm->lmm_object_id);
2014 __swab64s(&lmm->lmm_object_gr);
2015 __swab32s(&lmm->lmm_stripe_size);
2016 __swab32s(&lmm->lmm_stripe_count);
2020 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2023 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2024 __swab32s(&lumj->lmm_magic);
2025 __swab32s(&lumj->lmm_pattern);
2026 __swab64s(&lumj->lmm_object_id);
2027 __swab64s(&lumj->lmm_object_gr);
2028 __swab32s(&lumj->lmm_stripe_size);
2029 __swab32s(&lumj->lmm_stripe_count);
2030 __swab32s(&lumj->lmm_extent_count);
2035 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
2040 for (i = 0; i < stripe_count; i++) {
2041 __swab64s(&(lod[i].l_object_id));
2042 __swab64s(&(lod[i].l_object_gr));
2043 __swab32s(&(lod[i].l_ost_gen));
2044 __swab32s(&(lod[i].l_ost_idx));
2050 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2054 for (i = 0; i < RES_NAME_SIZE; i++)
2055 __swab64s (&id->name[i]);
2058 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2060 /* the lock data is a union and the first two fields are always an
2061 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2062 * data the same way. */
2063 __swab64s(&d->l_extent.start);
2064 __swab64s(&d->l_extent.end);
2065 __swab64s(&d->l_extent.gid);
2066 __swab32s(&d->l_flock.pid);
2069 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2071 __swab64s (&i->opc);
2074 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2076 __swab32s (&r->lr_type);
2077 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2078 lustre_swab_ldlm_res_id (&r->lr_name);
2081 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2083 lustre_swab_ldlm_resource_desc (&l->l_resource);
2084 __swab32s (&l->l_req_mode);
2085 __swab32s (&l->l_granted_mode);
2086 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2089 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2091 __swab32s (&rq->lock_flags);
2092 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2093 __swab32s (&rq->lock_count);
2094 /* lock_handle[] opaque */
2097 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2099 __swab32s (&r->lock_flags);
2100 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2101 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2102 /* lock_handle opaque */
2103 __swab64s (&r->lock_policy_res1);
2104 __swab64s (&r->lock_policy_res2);
2107 /* no one calls this */
2108 int llog_log_swabbed(struct llog_log_hdr *hdr)
2110 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2112 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2117 void lustre_swab_qdata(struct qunit_data *d)
2119 __swab32s (&d->qd_id);
2120 __swab32s (&d->qd_flags);
2121 __swab64s (&d->qd_count);
2122 __swab64s (&d->qd_qunit);
2123 __swab64s (&d->padding);
2129 * got qdata from request(req/rep)
2131 struct qunit_data *quota_get_qdata(void *request, int is_req, int is_exp)
2133 struct ptlrpc_request *req = (struct ptlrpc_request *)request;
2134 struct qunit_data *qdata;
2135 __u64 flags = is_exp ? req->rq_export->exp_connect_flags :
2136 req->rq_import->imp_connect_data.ocd_connect_flags;
2139 /* support for quota64 */
2140 LASSERT(flags & OBD_CONNECT_QUOTA64);
2141 /* support for change_qs */
2142 LASSERT(flags & OBD_CONNECT_CHANGE_QS);
2144 if (is_req == QUOTA_REQUEST)
2145 qdata = lustre_swab_reqbuf(req, REQ_REC_OFF,
2146 sizeof(struct qunit_data),
2149 qdata = lustre_swab_repbuf(req, REPLY_REC_OFF,
2150 sizeof(struct qunit_data),
2153 return ERR_PTR(-EPROTO);
2155 QDATA_SET_CHANGE_QS(qdata);
2158 EXPORT_SYMBOL(quota_get_qdata);
2161 * copy qdata to request(req/rep)
2163 int quota_copy_qdata(void *request, struct qunit_data *qdata,
2164 int is_req, int is_exp)
2166 struct ptlrpc_request *req = (struct ptlrpc_request *)request;
2168 __u64 flags = is_exp ? req->rq_export->exp_connect_flags :
2169 req->rq_import->imp_connect_data.ocd_connect_flags;
2173 /* support for quota64 */
2174 LASSERT(flags & OBD_CONNECT_QUOTA64);
2175 /* support for change_qs */
2176 LASSERT(flags & OBD_CONNECT_CHANGE_QS);
2178 if (is_req == QUOTA_REQUEST)
2179 target = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF,
2180 sizeof(struct qunit_data));
2182 target = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
2183 sizeof(struct qunit_data));
2187 memcpy(target, qdata, sizeof(*qdata));
2190 EXPORT_SYMBOL(quota_copy_qdata);
2191 #endif /* __KERNEL__ */
2193 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2195 LASSERT(req->rq_reqmsg);
2197 switch (req->rq_reqmsg->lm_magic) {
2198 case LUSTRE_MSG_MAGIC_V2:
2199 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2201 CERROR("bad lustre msg magic: %#08X\n",
2202 req->rq_reqmsg->lm_magic);
2207 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2209 LASSERT(req->rq_repmsg);
2211 switch (req->rq_repmsg->lm_magic) {
2212 case LUSTRE_MSG_MAGIC_V2:
2213 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2215 /* uninitialized yet */
2220 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2221 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2224 va_start(args, fmt);
2225 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2226 data->msg_fn, data->msg_line, fmt, args,
2227 " req@%p x"LPU64"/t"LPD64"("LPD64") o%d->%s@%s:%d/%d"
2228 " lens %d/%d e %d to %d dl "CFS_TIME_T" ref %d "
2229 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2230 req, req->rq_xid, req->rq_transno,
2231 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2232 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2233 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2235 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2237 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2239 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2240 req->rq_request_portal, req->rq_reply_portal,
2241 req->rq_reqlen, req->rq_replen,
2242 req->rq_early_count, req->rq_timedout, req->rq_deadline,
2243 atomic_read(&req->rq_refcount), DEBUG_REQ_FLAGS(req),
2244 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2245 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2246 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2247 lustre_msg_get_flags(req->rq_repmsg) : -1,
2249 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2250 lustre_msg_get_status(req->rq_repmsg) : -1);
2252 EXPORT_SYMBOL(_debug_req);
2254 void lustre_swab_lustre_capa(struct lustre_capa *c)
2256 lustre_swab_lu_fid(&c->lc_fid);
2257 __swab64s (&c->lc_opc);
2258 __swab64s (&c->lc_uid);
2259 __swab64s (&c->lc_gid);
2260 __swab32s (&c->lc_flags);
2261 __swab32s (&c->lc_keyid);
2262 __swab32s (&c->lc_timeout);
2263 __swab32s (&c->lc_expiry);
2266 void lustre_swab_lustre_capa_key(struct lustre_capa_key *k)
2268 __swab64s (&k->lk_mdsid);
2269 __swab32s (&k->lk_keyid);
2270 __swab32s (&k->lk_padding);
2273 void lustre_swab_lnlh(struct lnl_hdr *l)
2275 __swab16s(&l->lnl_magic);
2276 /* __u8 l->lnl_transport */
2277 __swab16s(&l->lnl_msgtype);
2278 __swab16s(&l->lnl_msglen);
2280 EXPORT_SYMBOL(lustre_swab_lnlh);