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>
57 static inline int lustre_msg_hdr_size_v2(int count)
59 return size_round(offsetof(struct lustre_msg_v2, lm_buflens[count]));
62 int lustre_msg_hdr_size(__u32 magic, int count)
65 case LUSTRE_MSG_MAGIC_V2:
66 return lustre_msg_hdr_size_v2(count);
68 LASSERTF(0, "incorrect message magic: %08x\n", magic);
72 EXPORT_SYMBOL(lustre_msg_hdr_size);
74 int lustre_msg_swabbed(struct lustre_msg *msg)
76 return (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
80 lustre_msg_check_version_v2(struct lustre_msg_v2 *msg, __u32 version)
82 __u32 ver = lustre_msg_get_version(msg);
83 return (ver & LUSTRE_VERSION_MASK) != version;
86 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
88 switch (msg->lm_magic) {
89 case LUSTRE_MSG_MAGIC_V1:
90 case LUSTRE_MSG_MAGIC_V1_SWABBED:
91 CERROR("msg v1 not supported - please upgrade you system\n");
93 case LUSTRE_MSG_MAGIC_V2:
94 case LUSTRE_MSG_MAGIC_V2_SWABBED:
95 return lustre_msg_check_version_v2(msg, version);
97 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
102 /* early reply size */
103 int lustre_msg_early_size() {
106 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
109 EXPORT_SYMBOL(lustre_msg_early_size);
111 int lustre_msg_size_v2(int count, __u32 *lengths)
116 size = lustre_msg_hdr_size_v2(count);
117 for (i = 0; i < count; i++)
118 size += size_round(lengths[i]);
122 EXPORT_SYMBOL(lustre_msg_size_v2);
124 /* This returns the size of the buffer that is required to hold a lustre_msg
125 * with the given sub-buffer lengths.
126 * NOTE: this should only be used for NEW requests, and should always be
127 * in the form of a v2 request. If this is a connection to a v1
128 * target then the first buffer will be stripped because the ptlrpc
129 * data is part of the lustre_msg_v1 header. b=14043 */
130 int lustre_msg_size(__u32 magic, int count, __u32 *lens)
132 __u32 size[] = { sizeof(struct ptlrpc_body) };
140 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
143 case LUSTRE_MSG_MAGIC_V2:
144 return lustre_msg_size_v2(count, lens);
146 LASSERTF(0, "incorrect message magic: %08x\n", magic);
151 /* This is used to determine the size of a buffer that was already packed
152 * and will correctly handle the different message formats. */
153 int lustre_packed_msg_size(struct lustre_msg *msg)
155 switch (msg->lm_magic) {
156 case LUSTRE_MSG_MAGIC_V2:
157 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
159 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
164 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
170 msg->lm_bufcount = count;
171 /* XXX: lm_secflvr uninitialized here */
172 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
174 for (i = 0; i < count; i++)
175 msg->lm_buflens[i] = lens[i];
180 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
181 for (i = 0; i < count; i++) {
183 LOGL(tmp, lens[i], ptr);
186 EXPORT_SYMBOL(lustre_init_msg_v2);
188 static int lustre_pack_request_v2(struct ptlrpc_request *req,
189 int count, __u32 *lens, char **bufs)
193 reqlen = lustre_msg_size_v2(count, lens);
195 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
199 req->rq_reqlen = reqlen;
201 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
202 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
203 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
207 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
208 __u32 *lens, char **bufs)
210 __u32 size[] = { sizeof(struct ptlrpc_body) };
218 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
220 /* only use new format, we don't need to be compatible with 1.4 */
221 magic = LUSTRE_MSG_MAGIC_V2;
224 case LUSTRE_MSG_MAGIC_V2:
225 return lustre_pack_request_v2(req, count, lens, bufs);
227 LASSERTF(0, "incorrect message magic: %08x\n", magic);
233 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
234 spinlock_t ptlrpc_rs_debug_lock;
236 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
238 spin_lock(&ptlrpc_rs_debug_lock); \
239 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
240 spin_unlock(&ptlrpc_rs_debug_lock); \
243 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
245 spin_lock(&ptlrpc_rs_debug_lock); \
246 list_del(&(rs)->rs_debug_list); \
247 spin_unlock(&ptlrpc_rs_debug_lock); \
250 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
251 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
254 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
256 struct ptlrpc_reply_state *rs = NULL;
258 spin_lock(&svc->srv_lock);
259 /* See if we have anything in a pool, and wait if nothing */
260 while (list_empty(&svc->srv_free_rs_list)) {
261 struct l_wait_info lwi;
263 spin_unlock(&svc->srv_lock);
264 /* If we cannot get anything for some long time, we better
265 bail out instead of waiting infinitely */
266 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
267 rc = l_wait_event(svc->srv_free_rs_waitq,
268 !list_empty(&svc->srv_free_rs_list), &lwi);
271 spin_lock(&svc->srv_lock);
274 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
276 list_del(&rs->rs_list);
277 spin_unlock(&svc->srv_lock);
279 memset(rs, 0, svc->srv_max_reply_size);
280 rs->rs_service = svc;
286 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
288 struct ptlrpc_service *svc = rs->rs_service;
292 spin_lock(&svc->srv_lock);
293 list_add(&rs->rs_list, &svc->srv_free_rs_list);
294 spin_unlock(&svc->srv_lock);
295 cfs_waitq_signal(&svc->srv_free_rs_waitq);
298 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
299 __u32 *lens, char **bufs, int flags)
301 struct ptlrpc_reply_state *rs;
305 LASSERT(req->rq_reply_state == NULL);
307 if ((flags & LPRFL_EARLY_REPLY) == 0)
308 req->rq_packed_final = 1;
310 msg_len = lustre_msg_size_v2(count, lens);
311 rc = sptlrpc_svc_alloc_rs(req, msg_len);
315 rs = req->rq_reply_state;
316 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
317 rs->rs_cb_id.cbid_fn = reply_out_callback;
318 rs->rs_cb_id.cbid_arg = rs;
319 rs->rs_service = req->rq_rqbd->rqbd_service;
320 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
321 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
323 req->rq_replen = msg_len;
324 req->rq_reply_state = rs;
325 req->rq_repmsg = rs->rs_msg;
327 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
328 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
329 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
331 PTLRPC_RS_DEBUG_LRU_ADD(rs);
335 EXPORT_SYMBOL(lustre_pack_reply_v2);
337 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
338 char **bufs, int flags)
341 __u32 size[] = { sizeof(struct ptlrpc_body) };
349 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
351 switch (req->rq_reqmsg->lm_magic) {
352 case LUSTRE_MSG_MAGIC_V2:
353 case LUSTRE_MSG_MAGIC_V2_SWABBED:
354 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
357 LASSERTF(0, "incorrect message magic: %08x\n",
358 req->rq_reqmsg->lm_magic);
362 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
363 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
367 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
370 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
373 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
375 int i, offset, buflen, bufcount;
380 bufcount = m->lm_bufcount;
381 if (unlikely(n >= bufcount)) {
382 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
387 buflen = m->lm_buflens[n];
388 if (unlikely(buflen < min_size)) {
389 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
390 m, n, buflen, min_size);
394 offset = lustre_msg_hdr_size_v2(bufcount);
395 for (i = 0; i < n; i++)
396 offset += size_round(m->lm_buflens[i]);
398 return (char *)m + offset;
401 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
403 switch (m->lm_magic) {
404 case LUSTRE_MSG_MAGIC_V2:
405 case LUSTRE_MSG_MAGIC_V2_SWABBED:
406 return lustre_msg_buf_v2(m, n, min_size);
408 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
413 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
414 unsigned int newlen, int move_data)
416 char *tail = NULL, *newpos;
420 LASSERT(msg->lm_bufcount > segment);
421 LASSERT(msg->lm_buflens[segment] >= newlen);
423 if (msg->lm_buflens[segment] == newlen)
426 if (move_data && msg->lm_bufcount > segment + 1) {
427 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
428 for (n = segment + 1; n < msg->lm_bufcount; n++)
429 tail_len += size_round(msg->lm_buflens[n]);
432 msg->lm_buflens[segment] = newlen;
434 if (tail && tail_len) {
435 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
436 LASSERT(newpos <= tail);
438 memcpy(newpos, tail, tail_len);
441 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
445 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
446 * we also move data forward from @segment + 1.
448 * if @newlen == 0, we remove the segment completely, but we still keep the
449 * totally bufcount the same to save possible data moving. this will leave a
450 * unused segment with size 0 at the tail, but that's ok.
452 * return new msg size after shrinking.
455 * + if any buffers higher than @segment has been filled in, must call shrink
456 * with non-zero @move_data.
457 * + caller should NOT keep pointers to msg buffers which higher than @segment
460 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
461 unsigned int newlen, int move_data)
463 switch (msg->lm_magic) {
464 case LUSTRE_MSG_MAGIC_V2:
465 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
467 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
471 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
473 PTLRPC_RS_DEBUG_LRU_DEL(rs);
475 LASSERT (atomic_read(&rs->rs_refcount) == 0);
476 LASSERT (!rs->rs_difficult || rs->rs_handled);
477 LASSERT (!rs->rs_on_net);
478 LASSERT (!rs->rs_scheduled);
479 LASSERT (rs->rs_export == NULL);
480 LASSERT (rs->rs_nlocks == 0);
481 LASSERT (list_empty(&rs->rs_exp_list));
482 LASSERT (list_empty(&rs->rs_obd_list));
484 sptlrpc_svc_free_rs(rs);
487 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
489 int flipped, required_len, i;
491 /* Now we know the sender speaks my language. */
492 required_len = lustre_msg_hdr_size_v2(0);
493 if (len < required_len) {
494 /* can't even look inside the message */
495 CERROR("message length %d too small for lustre_msg\n", len);
499 flipped = lustre_msg_swabbed(m);
502 __swab32s(&m->lm_bufcount);
503 __swab32s(&m->lm_secflvr);
504 __swab32s(&m->lm_repsize);
505 __swab32s(&m->lm_cksum);
506 __swab32s(&m->lm_flags);
507 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
508 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
511 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
512 if (len < required_len) {
513 /* didn't receive all the buffer lengths */
514 CERROR ("message length %d too small for %d buflens\n",
515 len, m->lm_bufcount);
519 for (i = 0; i < m->lm_bufcount; i++) {
521 __swab32s(&m->lm_buflens[i]);
522 required_len += size_round(m->lm_buflens[i]);
525 if (len < required_len) {
526 CERROR("len: %d, required_len %d\n", len, required_len);
527 CERROR("bufcount: %d\n", m->lm_bufcount);
528 for (i = 0; i < m->lm_bufcount; i++)
529 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
536 int lustre_unpack_msg(struct lustre_msg *m, int len)
538 int required_len, rc;
541 /* We can provide a slightly better error log, if we check the
542 * message magic and version first. In the future, struct
543 * lustre_msg may grow, and we'd like to log a version mismatch,
544 * rather than a short message.
547 required_len = offsetof(struct lustre_msg, lm_magic) +
549 if (len < required_len) {
550 /* can't even look inside the message */
551 CERROR("message length %d too small for magic/version check\n",
556 switch (m->lm_magic) {
557 case LUSTRE_MSG_MAGIC_V2:
558 case LUSTRE_MSG_MAGIC_V2_SWABBED:
559 rc = lustre_unpack_msg_v2(m, len);
562 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
569 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
572 struct ptlrpc_body *pb;
574 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
576 CERROR("error unpacking ptlrpc body\n");
579 if (lustre_msg_swabbed(m))
580 lustre_swab_ptlrpc_body(pb);
582 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
583 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
590 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
592 switch (req->rq_reqmsg->lm_magic) {
593 case LUSTRE_MSG_MAGIC_V2:
594 case LUSTRE_MSG_MAGIC_V2_SWABBED:
595 lustre_set_req_swabbed(req, offset);
596 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
598 CERROR("bad lustre msg magic: %#08X\n",
599 req->rq_reqmsg->lm_magic);
604 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
606 switch (req->rq_repmsg->lm_magic) {
607 case LUSTRE_MSG_MAGIC_V2:
608 case LUSTRE_MSG_MAGIC_V2_SWABBED:
609 lustre_set_rep_swabbed(req, offset);
610 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
612 CERROR("bad lustre msg magic: %#08X\n",
613 req->rq_repmsg->lm_magic);
618 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
620 if (n >= m->lm_bufcount)
623 return m->lm_buflens[n];
627 * lustre_msg_buflen - return the length of buffer @n in message @m
628 * @m - lustre_msg (request or reply) to look at
629 * @n - message index (base 0)
631 * returns zero for non-existent message indices
633 int lustre_msg_buflen(struct lustre_msg *m, int n)
635 switch (m->lm_magic) {
636 case LUSTRE_MSG_MAGIC_V2:
637 case LUSTRE_MSG_MAGIC_V2_SWABBED:
638 return lustre_msg_buflen_v2(m, n);
640 CERROR("incorrect message magic: %08x\n", m->lm_magic);
644 EXPORT_SYMBOL(lustre_msg_buflen);
647 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
649 if (n >= m->lm_bufcount)
652 m->lm_buflens[n] = len;
655 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
657 switch (m->lm_magic) {
658 case LUSTRE_MSG_MAGIC_V2:
659 lustre_msg_set_buflen_v2(m, n, len);
662 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
666 EXPORT_SYMBOL(lustre_msg_set_buflen);
668 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
669 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
670 int lustre_msg_bufcount(struct lustre_msg *m)
672 switch (m->lm_magic) {
673 case LUSTRE_MSG_MAGIC_V2:
674 case LUSTRE_MSG_MAGIC_V2_SWABBED:
675 return m->lm_bufcount;
677 CERROR("incorrect message magic: %08x\n", m->lm_magic);
681 EXPORT_SYMBOL(lustre_msg_bufcount);
683 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
685 /* max_len == 0 means the string should fill the buffer */
689 switch (m->lm_magic) {
690 case LUSTRE_MSG_MAGIC_V2:
691 case LUSTRE_MSG_MAGIC_V2_SWABBED:
692 str = lustre_msg_buf_v2(m, index, 0);
693 blen = lustre_msg_buflen_v2(m, index);
696 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
700 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
704 slen = strnlen(str, blen);
706 if (slen == blen) { /* not NULL terminated */
707 CERROR("can't unpack non-NULL terminated string in "
708 "msg %p buffer[%d] len %d\n", m, index, blen);
713 if (slen != blen - 1) {
714 CERROR("can't unpack short string in msg %p "
715 "buffer[%d] len %d: strlen %d\n",
716 m, index, blen, slen);
719 } else if (slen > max_len) {
720 CERROR("can't unpack oversized string in msg %p "
721 "buffer[%d] len %d strlen %d: max %d expected\n",
722 m, index, blen, slen, max_len);
729 /* Wrap up the normal fixed length cases */
730 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
735 switch (msg->lm_magic) {
736 case LUSTRE_MSG_MAGIC_V2:
737 case LUSTRE_MSG_MAGIC_V2_SWABBED:
738 ptr = lustre_msg_buf_v2(msg, index, min_size);
741 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
746 if (swabber != NULL && lustre_msg_swabbed(msg))
747 ((void (*)(void *))swabber)(ptr);
752 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
755 lustre_set_req_swabbed(req, index);
756 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
759 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
762 lustre_set_rep_swabbed(req, index);
763 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
766 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
768 switch (msg->lm_magic) {
769 case LUSTRE_MSG_MAGIC_V1:
770 case LUSTRE_MSG_MAGIC_V1_SWABBED:
772 case LUSTRE_MSG_MAGIC_V2:
773 case LUSTRE_MSG_MAGIC_V2_SWABBED:
774 /* already in host endian */
775 return msg->lm_flags;
777 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
782 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
784 switch (msg->lm_magic) {
785 case LUSTRE_MSG_MAGIC_V1:
787 case LUSTRE_MSG_MAGIC_V2:
788 msg->lm_flags = flags;
791 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
795 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
797 switch (msg->lm_magic) {
798 case LUSTRE_MSG_MAGIC_V2:
799 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
800 struct ptlrpc_body *pb;
802 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
804 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
810 /* flags might be printed in debug code while message
816 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
818 switch (msg->lm_magic) {
819 case LUSTRE_MSG_MAGIC_V2: {
820 struct ptlrpc_body *pb;
822 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
823 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
824 pb->pb_flags |= flags;
828 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
832 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
834 switch (msg->lm_magic) {
835 case LUSTRE_MSG_MAGIC_V2: {
836 struct ptlrpc_body *pb;
838 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
839 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
840 pb->pb_flags = flags;
844 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
848 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
850 switch (msg->lm_magic) {
851 case LUSTRE_MSG_MAGIC_V2:
852 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
853 struct ptlrpc_body *pb;
855 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
856 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
857 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
861 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
865 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
867 switch (msg->lm_magic) {
868 case LUSTRE_MSG_MAGIC_V2:
869 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
870 struct ptlrpc_body *pb;
872 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
874 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
877 return pb->pb_op_flags;
884 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
886 switch (msg->lm_magic) {
887 case LUSTRE_MSG_MAGIC_V2: {
888 struct ptlrpc_body *pb;
890 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
891 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
892 pb->pb_op_flags |= flags;
896 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
900 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
902 switch (msg->lm_magic) {
903 case LUSTRE_MSG_MAGIC_V2: {
904 struct ptlrpc_body *pb;
906 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
907 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
908 pb->pb_op_flags |= flags;
912 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
916 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
918 switch (msg->lm_magic) {
919 case LUSTRE_MSG_MAGIC_V2:
920 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
921 struct ptlrpc_body *pb;
923 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
925 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
928 return &pb->pb_handle;
931 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
936 __u32 lustre_msg_get_type(struct lustre_msg *msg)
938 switch (msg->lm_magic) {
939 case LUSTRE_MSG_MAGIC_V2:
940 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
941 struct ptlrpc_body *pb;
943 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
945 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
946 return PTL_RPC_MSG_ERR;
951 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
952 return PTL_RPC_MSG_ERR;
956 __u32 lustre_msg_get_version(struct lustre_msg *msg)
958 switch (msg->lm_magic) {
959 case LUSTRE_MSG_MAGIC_V2:
960 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
961 struct ptlrpc_body *pb;
963 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
965 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
968 return pb->pb_version;
971 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
976 void lustre_msg_add_version(struct lustre_msg *msg, int version)
978 switch (msg->lm_magic) {
979 case LUSTRE_MSG_MAGIC_V2:
980 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
981 struct ptlrpc_body *pb;
983 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
984 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
985 pb->pb_version |= version;
989 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
993 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
995 switch (msg->lm_magic) {
996 case LUSTRE_MSG_MAGIC_V2:
997 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
998 struct ptlrpc_body *pb;
1000 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1002 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1008 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1013 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1015 switch (msg->lm_magic) {
1016 case LUSTRE_MSG_MAGIC_V2:
1017 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1018 struct ptlrpc_body *pb;
1020 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1022 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1025 return pb->pb_last_xid;
1028 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1033 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1035 switch (msg->lm_magic) {
1036 case LUSTRE_MSG_MAGIC_V2:
1037 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1038 struct ptlrpc_body *pb;
1040 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1042 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1045 return pb->pb_last_committed;
1048 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1053 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1055 switch (msg->lm_magic) {
1056 case LUSTRE_MSG_MAGIC_V2:
1057 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1058 struct ptlrpc_body *pb;
1060 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1062 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1065 return pb->pb_transno;
1068 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1073 int lustre_msg_get_status(struct lustre_msg *msg)
1075 switch (msg->lm_magic) {
1076 case LUSTRE_MSG_MAGIC_V2:
1077 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1078 struct ptlrpc_body *pb;
1080 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1082 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1085 return pb->pb_status;
1088 /* status might be printed in debug code while message
1094 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1096 switch (msg->lm_magic) {
1097 case LUSTRE_MSG_MAGIC_V2:
1098 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1099 struct ptlrpc_body *pb;
1101 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1103 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1109 CERROR("invalid msg magic %x\n", msg->lm_magic);
1115 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1117 switch (msg->lm_magic) {
1118 case LUSTRE_MSG_MAGIC_V2:
1119 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1120 struct ptlrpc_body *pb;
1122 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1124 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1131 CERROR("invalid msg magic %x\n", msg->lm_magic);
1136 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1138 switch (msg->lm_magic) {
1139 case LUSTRE_MSG_MAGIC_V2:
1140 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1141 struct ptlrpc_body *pb;
1143 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1145 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1148 return pb->pb_limit;
1151 CERROR("invalid msg magic %x\n", msg->lm_magic);
1157 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1159 switch (msg->lm_magic) {
1160 case LUSTRE_MSG_MAGIC_V2:
1161 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1162 struct ptlrpc_body *pb;
1164 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1166 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1169 pb->pb_limit = limit;
1173 CERROR("invalid msg magic %x\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 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1183 struct ptlrpc_body *pb;
1185 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1187 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1190 return pb->pb_conn_cnt;
1193 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1198 int lustre_msg_is_v1(struct lustre_msg *msg)
1200 switch (msg->lm_magic) {
1201 case LUSTRE_MSG_MAGIC_V1:
1202 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1209 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1211 switch (msg->lm_magic) {
1212 case LUSTRE_MSG_MAGIC_V2:
1213 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1214 return msg->lm_magic;
1216 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1221 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
1223 switch (msg->lm_magic) {
1224 case LUSTRE_MSG_MAGIC_V1:
1225 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1227 case LUSTRE_MSG_MAGIC_V2:
1228 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1229 struct ptlrpc_body *pb;
1231 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1233 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1237 return pb->pb_timeout;
1240 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1245 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1247 switch (msg->lm_magic) {
1248 case LUSTRE_MSG_MAGIC_V1:
1249 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1251 case LUSTRE_MSG_MAGIC_V2:
1252 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1253 struct ptlrpc_body *pb;
1255 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1257 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1261 return pb->pb_service_time;
1264 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1269 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1271 switch (msg->lm_magic) {
1272 case LUSTRE_MSG_MAGIC_V1:
1273 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1275 case LUSTRE_MSG_MAGIC_V2:
1276 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1277 return msg->lm_cksum;
1279 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1284 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1286 switch (msg->lm_magic) {
1287 case LUSTRE_MSG_MAGIC_V1:
1288 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1290 case LUSTRE_MSG_MAGIC_V2:
1291 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1292 struct ptlrpc_body *pb;
1293 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1294 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1295 return crc32_le(~(__u32)0, (unsigned char *)pb, sizeof(*pb));
1298 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1303 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1305 switch (msg->lm_magic) {
1306 case LUSTRE_MSG_MAGIC_V2: {
1307 struct ptlrpc_body *pb;
1309 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1310 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1311 pb->pb_handle = *handle;
1315 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1319 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1321 switch (msg->lm_magic) {
1322 case LUSTRE_MSG_MAGIC_V2: {
1323 struct ptlrpc_body *pb;
1325 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1326 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1331 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1335 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1337 switch (msg->lm_magic) {
1338 case LUSTRE_MSG_MAGIC_V2: {
1339 struct ptlrpc_body *pb;
1341 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1342 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1347 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1351 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1353 switch (msg->lm_magic) {
1354 case LUSTRE_MSG_MAGIC_V2: {
1355 struct ptlrpc_body *pb;
1357 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1358 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1359 pb->pb_last_xid = last_xid;
1363 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1367 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1369 switch (msg->lm_magic) {
1370 case LUSTRE_MSG_MAGIC_V2: {
1371 struct ptlrpc_body *pb;
1373 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1374 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1375 pb->pb_last_committed = last_committed;
1379 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1383 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1385 switch (msg->lm_magic) {
1386 case LUSTRE_MSG_MAGIC_V2: {
1387 struct ptlrpc_body *pb;
1389 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1390 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1391 pb->pb_transno = transno;
1395 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1399 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1401 switch (msg->lm_magic) {
1402 case LUSTRE_MSG_MAGIC_V2: {
1403 struct ptlrpc_body *pb;
1405 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1406 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1407 pb->pb_status = status;
1411 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1415 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1417 switch (msg->lm_magic) {
1418 case LUSTRE_MSG_MAGIC_V2: {
1419 struct ptlrpc_body *pb;
1421 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1422 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1423 pb->pb_conn_cnt = conn_cnt;
1427 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1431 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1433 switch (msg->lm_magic) {
1434 case LUSTRE_MSG_MAGIC_V1:
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_timeout = timeout;
1445 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1449 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1451 switch (msg->lm_magic) {
1452 case LUSTRE_MSG_MAGIC_V1:
1454 case LUSTRE_MSG_MAGIC_V2: {
1455 struct ptlrpc_body *pb;
1457 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1458 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1459 pb->pb_service_time = service_time;
1463 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1467 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1469 switch (msg->lm_magic) {
1470 case LUSTRE_MSG_MAGIC_V1:
1472 case LUSTRE_MSG_MAGIC_V2:
1473 msg->lm_cksum = cksum;
1476 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1481 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1483 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1485 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1486 req->rq_pill.rc_area[RCL_SERVER]);
1487 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1488 req->rq_reqmsg->lm_repsize = req->rq_replen;
1491 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
1493 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1494 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1495 req->rq_reqmsg->lm_repsize = req->rq_replen;
1498 /* byte flipping routines for all wire types declared in
1499 * lustre_idl.h implemented here.
1501 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1503 __swab32s (&b->pb_type);
1504 __swab32s (&b->pb_version);
1505 __swab32s (&b->pb_opc);
1506 __swab32s (&b->pb_status);
1507 __swab64s (&b->pb_last_xid);
1508 __swab64s (&b->pb_last_seen);
1509 __swab64s (&b->pb_last_committed);
1510 __swab64s (&b->pb_transno);
1511 __swab32s (&b->pb_flags);
1512 __swab32s (&b->pb_op_flags);
1513 __swab32s (&b->pb_conn_cnt);
1514 __swab32s (&b->pb_timeout);
1515 __swab32s (&b->pb_service_time);
1516 __swab32s (&b->pb_limit);
1517 __swab64s (&b->pb_slv);
1518 __swab64s (&b->pb_pre_versions[0]);
1519 __swab64s (&b->pb_pre_versions[1]);
1520 __swab64s (&b->pb_pre_versions[2]);
1521 __swab64s (&b->pb_pre_versions[3]);
1522 CLASSERT(offsetof(typeof(*b), pb_padding) != 0);
1525 void lustre_swab_connect(struct obd_connect_data *ocd)
1527 __swab64s(&ocd->ocd_connect_flags);
1528 __swab32s(&ocd->ocd_version);
1529 __swab32s(&ocd->ocd_grant);
1530 __swab64s(&ocd->ocd_ibits_known);
1531 __swab32s(&ocd->ocd_index);
1532 __swab32s(&ocd->ocd_brw_size);
1533 __swab32s(&ocd->ocd_nllu);
1534 __swab32s(&ocd->ocd_nllg);
1535 __swab64s(&ocd->ocd_transno);
1536 __swab32s(&ocd->ocd_group);
1537 __swab32s(&ocd->ocd_cksum_types);
1538 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1539 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1542 void lustre_swab_obdo (struct obdo *o)
1544 __swab64s (&o->o_valid);
1545 __swab64s (&o->o_id);
1546 __swab64s (&o->o_gr);
1547 __swab64s (&o->o_fid);
1548 __swab64s (&o->o_size);
1549 __swab64s (&o->o_mtime);
1550 __swab64s (&o->o_atime);
1551 __swab64s (&o->o_ctime);
1552 __swab64s (&o->o_blocks);
1553 __swab64s (&o->o_grant);
1554 __swab32s (&o->o_blksize);
1555 __swab32s (&o->o_mode);
1556 __swab32s (&o->o_uid);
1557 __swab32s (&o->o_gid);
1558 __swab32s (&o->o_flags);
1559 __swab32s (&o->o_nlink);
1560 __swab32s (&o->o_generation);
1561 __swab32s (&o->o_misc);
1562 __swab32s (&o->o_easize);
1563 __swab32s (&o->o_mds);
1564 __swab32s (&o->o_stripe_idx);
1565 __swab32s (&o->o_padding_1);
1566 /* o_inline is opaque */
1569 void lustre_swab_obd_statfs (struct obd_statfs *os)
1571 __swab64s (&os->os_type);
1572 __swab64s (&os->os_blocks);
1573 __swab64s (&os->os_bfree);
1574 __swab64s (&os->os_bavail);
1575 __swab64s (&os->os_files);
1576 __swab64s (&os->os_ffree);
1577 /* no need to swab os_fsid */
1578 __swab32s (&os->os_bsize);
1579 __swab32s (&os->os_namelen);
1580 __swab64s (&os->os_maxbytes);
1581 __swab32s (&os->os_state);
1582 /* no need to swap os_spare */
1585 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1587 __swab64s (&ioo->ioo_id);
1588 __swab64s (&ioo->ioo_gr);
1589 __swab32s (&ioo->ioo_type);
1590 __swab32s (&ioo->ioo_bufcnt);
1593 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1595 __swab64s (&nbr->offset);
1596 __swab32s (&nbr->len);
1597 __swab32s (&nbr->flags);
1600 void lustre_swab_ost_body (struct ost_body *b)
1602 lustre_swab_obdo (&b->oa);
1605 void lustre_swab_ost_last_id(obd_id *id)
1610 void lustre_swab_generic_32s(__u32 *val)
1615 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1617 __swab64s(&lvb->lvb_size);
1618 __swab64s(&lvb->lvb_mtime);
1619 __swab64s(&lvb->lvb_atime);
1620 __swab64s(&lvb->lvb_ctime);
1621 __swab64s(&lvb->lvb_blocks);
1624 void lustre_swab_mds_status_req (struct mds_status_req *r)
1626 __swab32s (&r->flags);
1627 __swab32s (&r->repbuf);
1630 void lustre_swab_mds_body (struct mds_body *b)
1632 lustre_swab_ll_fid (&b->fid1);
1633 lustre_swab_ll_fid (&b->fid2);
1634 /* handle is opaque */
1635 __swab64s (&b->valid);
1636 __swab64s (&b->size);
1637 __swab64s (&b->mtime);
1638 __swab64s (&b->atime);
1639 __swab64s (&b->ctime);
1640 __swab64s (&b->blocks);
1641 __swab64s (&b->io_epoch);
1642 __swab64s (&b->ino);
1643 __swab32s (&b->fsuid);
1644 __swab32s (&b->fsgid);
1645 __swab32s (&b->capability);
1646 __swab32s (&b->mode);
1647 __swab32s (&b->uid);
1648 __swab32s (&b->gid);
1649 __swab32s (&b->flags);
1650 __swab32s (&b->rdev);
1651 __swab32s (&b->nlink);
1652 __swab32s (&b->generation);
1653 __swab32s (&b->suppgid);
1654 __swab32s (&b->eadatasize);
1655 __swab32s (&b->aclsize);
1656 __swab32s (&b->max_mdsize);
1657 __swab32s (&b->max_cookiesize);
1658 __swab32s (&b->padding_4);
1661 void lustre_swab_mdt_body (struct mdt_body *b)
1663 lustre_swab_lu_fid (&b->fid1);
1664 lustre_swab_lu_fid (&b->fid2);
1665 /* handle is opaque */
1666 __swab64s (&b->valid);
1667 __swab64s (&b->size);
1668 __swab64s (&b->mtime);
1669 __swab64s (&b->atime);
1670 __swab64s (&b->ctime);
1671 __swab64s (&b->blocks);
1672 __swab64s (&b->ioepoch);
1673 __swab64s (&b->ino);
1674 __swab32s (&b->fsuid);
1675 __swab32s (&b->fsgid);
1676 __swab32s (&b->capability);
1677 __swab32s (&b->mode);
1678 __swab32s (&b->uid);
1679 __swab32s (&b->gid);
1680 __swab32s (&b->flags);
1681 __swab32s (&b->rdev);
1682 __swab32s (&b->nlink);
1683 __swab32s (&b->generation);
1684 __swab32s (&b->suppgid);
1685 __swab32s (&b->eadatasize);
1686 __swab32s (&b->aclsize);
1687 __swab32s (&b->max_mdsize);
1688 __swab32s (&b->max_cookiesize);
1689 __swab32s (&b->padding_4);
1692 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1694 /* handle is opaque */
1695 __swab64s (&b->ioepoch);
1696 __swab32s (&b->flags);
1697 CLASSERT(offsetof(typeof(*b), padding) != 0);
1700 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1703 __swab32s(&mti->mti_lustre_ver);
1704 __swab32s(&mti->mti_stripe_index);
1705 __swab32s(&mti->mti_config_ver);
1706 __swab32s(&mti->mti_flags);
1707 __swab32s(&mti->mti_nid_count);
1708 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1709 for (i = 0; i < MTI_NIDS_MAX; i++)
1710 __swab64s(&mti->mti_nids[i]);
1713 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1715 __swab64s (&i->dqi_bgrace);
1716 __swab64s (&i->dqi_igrace);
1717 __swab32s (&i->dqi_flags);
1718 __swab32s (&i->dqi_valid);
1721 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1723 __swab64s (&b->dqb_ihardlimit);
1724 __swab64s (&b->dqb_isoftlimit);
1725 __swab64s (&b->dqb_curinodes);
1726 __swab64s (&b->dqb_bhardlimit);
1727 __swab64s (&b->dqb_bsoftlimit);
1728 __swab64s (&b->dqb_curspace);
1729 __swab64s (&b->dqb_btime);
1730 __swab64s (&b->dqb_itime);
1731 __swab32s (&b->dqb_valid);
1732 CLASSERT(offsetof(typeof(*b), padding) != 0);
1735 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1737 __swab32s (&q->qc_cmd);
1738 __swab32s (&q->qc_type);
1739 __swab32s (&q->qc_id);
1740 __swab32s (&q->qc_stat);
1741 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1742 lustre_swab_obd_dqblk (&q->qc_dqblk);
1745 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1747 __swab32s (&p->rp_uid);
1748 __swab32s (&p->rp_gid);
1749 __swab32s (&p->rp_fsuid);
1750 __swab32s (&p->rp_fsgid);
1751 __swab32s (&p->rp_access_perm);
1754 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1756 __swab32s (&p->rp_uid);
1757 __swab32s (&p->rp_gid);
1758 __swab32s (&p->rp_fsuid);
1759 __swab32s (&p->rp_fsgid);
1760 __swab32s (&p->rp_access_perm);
1763 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1765 __swab32s (&sa->sa_opcode);
1766 __swab32s (&sa->sa_fsuid);
1767 __swab32s (&sa->sa_fsgid);
1768 __swab32s (&sa->sa_cap);
1769 __swab32s (&sa->sa_suppgid);
1770 __swab32s (&sa->sa_mode);
1771 lustre_swab_ll_fid (&sa->sa_fid);
1772 __swab64s (&sa->sa_valid);
1773 __swab64s (&sa->sa_size);
1774 __swab64s (&sa->sa_mtime);
1775 __swab64s (&sa->sa_atime);
1776 __swab64s (&sa->sa_ctime);
1777 __swab32s (&sa->sa_uid);
1778 __swab32s (&sa->sa_gid);
1779 __swab32s (&sa->sa_attr_flags);
1780 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1783 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1785 __swab64s(&jr->jr_headsize);
1786 lustre_swab_ll_fid(&jr->jr_fid);
1789 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1791 __swab64s(&jr->jr_headsize);
1792 lustre_swab_lu_fid(&jr->jr_fid);
1795 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1797 __swab32s (&cr->cr_opcode);
1798 __swab32s (&cr->cr_fsuid);
1799 __swab32s (&cr->cr_fsgid);
1800 __swab32s (&cr->cr_cap);
1801 __swab32s (&cr->cr_flags); /* for use with open */
1802 __swab32s (&cr->cr_mode);
1803 lustre_swab_ll_fid (&cr->cr_fid);
1804 lustre_swab_ll_fid (&cr->cr_replayfid);
1805 __swab64s (&cr->cr_time);
1806 __swab64s (&cr->cr_rdev);
1807 __swab32s (&cr->cr_suppgid);
1808 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1809 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1810 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1811 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1812 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1815 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1817 __swab32s (&lk->lk_opcode);
1818 __swab32s (&lk->lk_fsuid);
1819 __swab32s (&lk->lk_fsgid);
1820 __swab32s (&lk->lk_cap);
1821 __swab32s (&lk->lk_suppgid1);
1822 __swab32s (&lk->lk_suppgid2);
1823 lustre_swab_ll_fid (&lk->lk_fid1);
1824 lustre_swab_ll_fid (&lk->lk_fid2);
1825 __swab64s (&lk->lk_time);
1826 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1827 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1828 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1829 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1832 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1834 __swab32s (&ul->ul_opcode);
1835 __swab32s (&ul->ul_fsuid);
1836 __swab32s (&ul->ul_fsgid);
1837 __swab32s (&ul->ul_cap);
1838 __swab32s (&ul->ul_suppgid);
1839 __swab32s (&ul->ul_mode);
1840 lustre_swab_ll_fid (&ul->ul_fid1);
1841 lustre_swab_ll_fid (&ul->ul_fid2);
1842 __swab64s (&ul->ul_time);
1843 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1844 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1845 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1846 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1849 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1851 __swab32s (&rn->rn_opcode);
1852 __swab32s (&rn->rn_fsuid);
1853 __swab32s (&rn->rn_fsgid);
1854 __swab32s (&rn->rn_cap);
1855 __swab32s (&rn->rn_suppgid1);
1856 __swab32s (&rn->rn_suppgid2);
1857 lustre_swab_ll_fid (&rn->rn_fid1);
1858 lustre_swab_ll_fid (&rn->rn_fid2);
1859 __swab64s (&rn->rn_time);
1860 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1861 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1862 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1863 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1866 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
1868 __swab32s (&rr->rr_opcode);
1869 __swab32s (&rr->rr_fsuid);
1870 __swab32s (&rr->rr_fsgid);
1871 __swab32s (&rr->rr_cap);
1872 __swab32s (&rr->rr_suppgid1);
1873 __swab32s (&rr->rr_suppgid2);
1874 /* handle is opaque */
1875 lustre_swab_lu_fid (&rr->rr_fid1);
1876 lustre_swab_lu_fid (&rr->rr_fid2);
1877 __swab64s (&rr->rr_mtime);
1878 __swab64s (&rr->rr_atime);
1879 __swab64s (&rr->rr_ctime);
1880 __swab64s (&rr->rr_size);
1881 __swab64s (&rr->rr_blocks);
1882 __swab32s (&rr->rr_bias);
1883 __swab32s (&rr->rr_mode);
1884 __swab32s (&rr->rr_padding_1);
1885 __swab32s (&rr->rr_padding_2);
1886 __swab32s (&rr->rr_padding_3);
1887 __swab32s (&rr->rr_padding_4);
1889 CLASSERT(offsetof(typeof(*rr), rr_padding_1) != 0);
1890 CLASSERT(offsetof(typeof(*rr), rr_padding_2) != 0);
1891 CLASSERT(offsetof(typeof(*rr), rr_padding_3) != 0);
1892 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
1895 void lustre_swab_lov_desc (struct lov_desc *ld)
1897 __swab32s (&ld->ld_tgt_count);
1898 __swab32s (&ld->ld_active_tgt_count);
1899 __swab32s (&ld->ld_default_stripe_count);
1900 __swab64s (&ld->ld_default_stripe_size);
1901 __swab64s (&ld->ld_default_stripe_offset);
1902 __swab32s (&ld->ld_pattern);
1903 __swab32s (&ld->ld_qos_maxage);
1904 /* uuid endian insensitive */
1907 /*begin adding MDT by huanghua@clusterfs.com*/
1908 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1910 __swab32s (&ld->ld_tgt_count);
1911 __swab32s (&ld->ld_active_tgt_count);
1912 /* uuid endian insensitive */
1914 /*end adding MDT by huanghua@clusterfs.com*/
1915 void lustre_swab_md_fld (struct md_fld *mf)
1917 __swab64s(&mf->mf_seq);
1918 __swab64s(&mf->mf_mds);
1921 static void print_lum (struct lov_user_md *lum)
1923 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1924 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1925 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1926 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1927 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
1928 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1929 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1930 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1933 void lustre_swab_lov_user_md(struct lov_user_md *lum)
1936 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
1937 __swab32s(&lum->lmm_magic);
1938 __swab32s(&lum->lmm_pattern);
1939 __swab64s(&lum->lmm_object_id);
1940 __swab64s(&lum->lmm_object_gr);
1941 __swab32s(&lum->lmm_stripe_size);
1942 __swab16s(&lum->lmm_stripe_count);
1943 __swab16s(&lum->lmm_stripe_offset);
1948 static void print_lumj (struct lov_user_md_join *lumj)
1950 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
1951 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
1952 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
1953 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
1954 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
1955 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
1956 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
1957 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
1960 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
1963 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
1964 __swab32s(&lumj->lmm_magic);
1965 __swab32s(&lumj->lmm_pattern);
1966 __swab64s(&lumj->lmm_object_id);
1967 __swab64s(&lumj->lmm_object_gr);
1968 __swab32s(&lumj->lmm_stripe_size);
1969 __swab32s(&lumj->lmm_stripe_count);
1970 __swab32s(&lumj->lmm_extent_count);
1975 static void print_lum_objs(struct lov_user_md *lum)
1977 struct lov_user_ost_data *lod;
1980 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
1982 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
1983 for (i = 0; i < lum->lmm_stripe_count; i++) {
1984 lod = &lum->lmm_objects[i];
1985 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
1986 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
1987 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
1988 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
1993 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
1995 struct lov_user_ost_data *lod;
1998 for (i = 0; i < lum->lmm_stripe_count; i++) {
1999 lod = &lum->lmm_objects[i];
2000 __swab64s(&lod->l_object_id);
2001 __swab64s(&lod->l_object_gr);
2002 __swab32s(&lod->l_ost_gen);
2003 __swab32s(&lod->l_ost_idx);
2005 print_lum_objs(lum);
2010 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2012 struct lov_ost_data *lod;
2015 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2016 lod = &lmm->lmm_objects[i];
2017 __swab64s(&lod->l_object_id);
2018 __swab64s(&lod->l_object_gr);
2019 __swab32s(&lod->l_ost_gen);
2020 __swab32s(&lod->l_ost_idx);
2022 __swab32s(&lmm->lmm_magic);
2023 __swab32s(&lmm->lmm_pattern);
2024 __swab64s(&lmm->lmm_object_id);
2025 __swab64s(&lmm->lmm_object_gr);
2026 __swab32s(&lmm->lmm_stripe_size);
2027 __swab32s(&lmm->lmm_stripe_count);
2033 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2037 for (i = 0; i < RES_NAME_SIZE; i++)
2038 __swab64s (&id->name[i]);
2041 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2043 /* the lock data is a union and the first two fields are always an
2044 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2045 * data the same way. */
2046 __swab64s(&d->l_extent.start);
2047 __swab64s(&d->l_extent.end);
2048 __swab64s(&d->l_extent.gid);
2049 __swab32s(&d->l_flock.pid);
2052 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2054 __swab64s (&i->opc);
2057 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2059 __swab32s (&r->lr_type);
2060 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2061 lustre_swab_ldlm_res_id (&r->lr_name);
2064 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2066 lustre_swab_ldlm_resource_desc (&l->l_resource);
2067 __swab32s (&l->l_req_mode);
2068 __swab32s (&l->l_granted_mode);
2069 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2072 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2074 __swab32s (&rq->lock_flags);
2075 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2076 __swab32s (&rq->lock_count);
2077 /* lock_handle[] opaque */
2080 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2082 __swab32s (&r->lock_flags);
2083 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2084 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2085 /* lock_handle opaque */
2086 __swab64s (&r->lock_policy_res1);
2087 __swab64s (&r->lock_policy_res2);
2090 /* no one calls this */
2091 int llog_log_swabbed(struct llog_log_hdr *hdr)
2093 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2095 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2100 void lustre_swab_qdata(struct qunit_data *d)
2102 __swab32s (&d->qd_id);
2103 __swab32s (&d->qd_flags);
2104 __swab64s (&d->qd_count);
2107 void lustre_swab_qdata_old(struct qunit_data_old *d)
2109 __swab32s (&d->qd_id);
2110 __swab32s (&d->qd_type);
2111 __swab32s (&d->qd_count);
2112 __swab32s (&d->qd_isblk);
2116 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2118 struct qunit_data_old tmp;
2119 struct qunit_data *ret;
2126 ret = (struct qunit_data *)d;
2127 ret->qd_id = tmp.qd_id;
2128 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2129 ret->qd_count = tmp.qd_count;
2133 EXPORT_SYMBOL(lustre_quota_old_to_new);
2135 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2137 struct qunit_data tmp;
2138 struct qunit_data_old *ret;
2145 ret = (struct qunit_data_old *)d;
2146 ret->qd_id = tmp.qd_id;
2147 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2148 ret->qd_count = (__u32)tmp.qd_count;
2149 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2152 EXPORT_SYMBOL(lustre_quota_new_to_old);
2153 #endif /* __KERNEL__ */
2155 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2157 LASSERT(req->rq_reqmsg);
2159 switch (req->rq_reqmsg->lm_magic) {
2160 case LUSTRE_MSG_MAGIC_V2:
2161 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2162 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2164 CERROR("bad lustre msg magic: %#08X\n",
2165 req->rq_reqmsg->lm_magic);
2170 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2172 LASSERT(req->rq_repmsg);
2174 switch (req->rq_repmsg->lm_magic) {
2175 case LUSTRE_MSG_MAGIC_V2:
2176 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2177 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2179 /* uninitialized yet */
2184 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2185 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2189 va_start(args, fmt);
2190 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2191 data->msg_fn, data->msg_line, fmt, args,
2192 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d/%d"
2193 " lens %d/%d e %d to %d dl "CFS_TIME_T" ref %d "
2194 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2195 req, req->rq_xid, req->rq_transno,
2196 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2197 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2198 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2200 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2202 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2204 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2205 req->rq_request_portal, req->rq_reply_portal,
2206 req->rq_reqlen, req->rq_replen,
2207 req->rq_early_count, req->rq_timeout, req->rq_deadline,
2208 atomic_read(&req->rq_refcount), DEBUG_REQ_FLAGS(req),
2209 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2210 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2211 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2212 lustre_msg_get_flags(req->rq_repmsg) : -1,
2214 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2215 lustre_msg_get_status(req->rq_repmsg) : -1);
2217 EXPORT_SYMBOL(_debug_req);
2219 void lustre_swab_lustre_capa(struct lustre_capa *c)
2221 lustre_swab_lu_fid(&c->lc_fid);
2222 __swab64s (&c->lc_opc);
2223 __swab32s (&c->lc_uid);
2224 __swab32s (&c->lc_flags);
2225 __swab32s (&c->lc_keyid);
2226 __swab32s (&c->lc_timeout);
2227 __swab64s (&c->lc_expiry);
2230 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2232 __swab64s (&k->lk_mdsid);
2233 __swab32s (&k->lk_keyid);
2234 __swab32s (&k->lk_padding);