1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ptlrpc/pack_generic.c
38 * (Un)packing of OST requests
40 * Author: Peter J. Braam <braam@clusterfs.com>
41 * Author: Phil Schwan <phil@clusterfs.com>
42 * Author: Eric Barton <eeb@clusterfs.com>
45 #define DEBUG_SUBSYSTEM S_RPC
47 # include <liblustre.h>
50 #include <libcfs/libcfs.h>
52 #include <obd_support.h>
53 #include <obd_class.h>
54 #include <lustre_net.h>
55 #include <obd_cksum.h>
56 #include <lustre/ll_fiemap.h>
58 static inline int lustre_msg_hdr_size_v2(int count)
60 return size_round(offsetof(struct lustre_msg_v2, lm_buflens[count]));
63 int lustre_msg_hdr_size(__u32 magic, int count)
66 case LUSTRE_MSG_MAGIC_V2:
67 return lustre_msg_hdr_size_v2(count);
69 LASSERTF(0, "incorrect message magic: %08x\n", magic);
73 EXPORT_SYMBOL(lustre_msg_hdr_size);
75 int lustre_msg_swabbed(struct lustre_msg *msg)
77 return (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
81 lustre_msg_check_version_v2(struct lustre_msg_v2 *msg, __u32 version)
83 __u32 ver = lustre_msg_get_version(msg);
84 return (ver & LUSTRE_VERSION_MASK) != version;
87 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
89 switch (msg->lm_magic) {
90 case LUSTRE_MSG_MAGIC_V1:
91 case LUSTRE_MSG_MAGIC_V1_SWABBED:
92 CERROR("msg v1 not supported - please upgrade you system\n");
94 case LUSTRE_MSG_MAGIC_V2:
95 case LUSTRE_MSG_MAGIC_V2_SWABBED:
96 return lustre_msg_check_version_v2(msg, version);
98 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
103 /* early reply size */
104 int lustre_msg_early_size() {
107 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
110 EXPORT_SYMBOL(lustre_msg_early_size);
112 int lustre_msg_size_v2(int count, __u32 *lengths)
117 size = lustre_msg_hdr_size_v2(count);
118 for (i = 0; i < count; i++)
119 size += size_round(lengths[i]);
123 EXPORT_SYMBOL(lustre_msg_size_v2);
125 /* This returns the size of the buffer that is required to hold a lustre_msg
126 * with the given sub-buffer lengths.
127 * NOTE: this should only be used for NEW requests, and should always be
128 * in the form of a v2 request. If this is a connection to a v1
129 * target then the first buffer will be stripped because the ptlrpc
130 * data is part of the lustre_msg_v1 header. b=14043 */
131 int lustre_msg_size(__u32 magic, int count, __u32 *lens)
133 __u32 size[] = { sizeof(struct ptlrpc_body) };
141 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
144 case LUSTRE_MSG_MAGIC_V2:
145 return lustre_msg_size_v2(count, lens);
147 LASSERTF(0, "incorrect message magic: %08x\n", magic);
152 /* This is used to determine the size of a buffer that was already packed
153 * and will correctly handle the different message formats. */
154 int lustre_packed_msg_size(struct lustre_msg *msg)
156 switch (msg->lm_magic) {
157 case LUSTRE_MSG_MAGIC_V2:
158 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
160 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
165 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
171 msg->lm_bufcount = count;
172 /* XXX: lm_secflvr uninitialized here */
173 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
175 for (i = 0; i < count; i++)
176 msg->lm_buflens[i] = lens[i];
181 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
182 for (i = 0; i < count; i++) {
184 LOGL(tmp, lens[i], ptr);
187 EXPORT_SYMBOL(lustre_init_msg_v2);
189 static int lustre_pack_request_v2(struct ptlrpc_request *req,
190 int count, __u32 *lens, char **bufs)
194 reqlen = lustre_msg_size_v2(count, lens);
196 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
200 req->rq_reqlen = reqlen;
202 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
203 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
204 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
208 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
209 __u32 *lens, char **bufs)
211 __u32 size[] = { sizeof(struct ptlrpc_body) };
219 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
221 /* only use new format, we don't need to be compatible with 1.4 */
222 magic = LUSTRE_MSG_MAGIC_V2;
225 case LUSTRE_MSG_MAGIC_V2:
226 return lustre_pack_request_v2(req, count, lens, bufs);
228 LASSERTF(0, "incorrect message magic: %08x\n", magic);
234 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
235 spinlock_t ptlrpc_rs_debug_lock;
237 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
239 spin_lock(&ptlrpc_rs_debug_lock); \
240 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
241 spin_unlock(&ptlrpc_rs_debug_lock); \
244 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
246 spin_lock(&ptlrpc_rs_debug_lock); \
247 list_del(&(rs)->rs_debug_list); \
248 spin_unlock(&ptlrpc_rs_debug_lock); \
251 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
252 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
255 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
257 struct ptlrpc_reply_state *rs = NULL;
259 spin_lock(&svc->srv_lock);
260 /* See if we have anything in a pool, and wait if nothing */
261 while (list_empty(&svc->srv_free_rs_list)) {
262 struct l_wait_info lwi;
264 spin_unlock(&svc->srv_lock);
265 /* If we cannot get anything for some long time, we better
266 bail out instead of waiting infinitely */
267 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
268 rc = l_wait_event(svc->srv_free_rs_waitq,
269 !list_empty(&svc->srv_free_rs_list), &lwi);
272 spin_lock(&svc->srv_lock);
275 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
277 list_del(&rs->rs_list);
278 spin_unlock(&svc->srv_lock);
280 memset(rs, 0, svc->srv_max_reply_size);
281 rs->rs_service = svc;
287 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
289 struct ptlrpc_service *svc = rs->rs_service;
293 spin_lock(&svc->srv_lock);
294 list_add(&rs->rs_list, &svc->srv_free_rs_list);
295 spin_unlock(&svc->srv_lock);
296 cfs_waitq_signal(&svc->srv_free_rs_waitq);
299 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
300 __u32 *lens, char **bufs, int flags)
302 struct ptlrpc_reply_state *rs;
306 LASSERT(req->rq_reply_state == NULL);
308 if ((flags & LPRFL_EARLY_REPLY) == 0)
309 req->rq_packed_final = 1;
311 msg_len = lustre_msg_size_v2(count, lens);
312 rc = sptlrpc_svc_alloc_rs(req, msg_len);
316 rs = req->rq_reply_state;
317 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
318 rs->rs_cb_id.cbid_fn = reply_out_callback;
319 rs->rs_cb_id.cbid_arg = rs;
320 rs->rs_service = req->rq_rqbd->rqbd_service;
321 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
322 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
324 req->rq_replen = msg_len;
325 req->rq_reply_state = rs;
326 req->rq_repmsg = rs->rs_msg;
328 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
329 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
330 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
332 PTLRPC_RS_DEBUG_LRU_ADD(rs);
336 EXPORT_SYMBOL(lustre_pack_reply_v2);
338 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
339 char **bufs, int flags)
342 __u32 size[] = { sizeof(struct ptlrpc_body) };
350 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
352 switch (req->rq_reqmsg->lm_magic) {
353 case LUSTRE_MSG_MAGIC_V2:
354 case LUSTRE_MSG_MAGIC_V2_SWABBED:
355 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
358 LASSERTF(0, "incorrect message magic: %08x\n",
359 req->rq_reqmsg->lm_magic);
363 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
364 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
368 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
371 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
374 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
376 int i, offset, buflen, bufcount;
381 bufcount = m->lm_bufcount;
382 if (unlikely(n >= bufcount)) {
383 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
388 buflen = m->lm_buflens[n];
389 if (unlikely(buflen < min_size)) {
390 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
391 m, n, buflen, min_size);
395 offset = lustre_msg_hdr_size_v2(bufcount);
396 for (i = 0; i < n; i++)
397 offset += size_round(m->lm_buflens[i]);
399 return (char *)m + offset;
402 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
404 switch (m->lm_magic) {
405 case LUSTRE_MSG_MAGIC_V2:
406 case LUSTRE_MSG_MAGIC_V2_SWABBED:
407 return lustre_msg_buf_v2(m, n, min_size);
409 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
414 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
415 unsigned int newlen, int move_data)
417 char *tail = NULL, *newpos;
421 LASSERT(msg->lm_bufcount > segment);
422 LASSERT(msg->lm_buflens[segment] >= newlen);
424 if (msg->lm_buflens[segment] == newlen)
427 if (move_data && msg->lm_bufcount > segment + 1) {
428 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
429 for (n = segment + 1; n < msg->lm_bufcount; n++)
430 tail_len += size_round(msg->lm_buflens[n]);
433 msg->lm_buflens[segment] = newlen;
435 if (tail && tail_len) {
436 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
437 LASSERT(newpos <= tail);
439 memcpy(newpos, tail, tail_len);
442 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
446 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
447 * we also move data forward from @segment + 1.
449 * if @newlen == 0, we remove the segment completely, but we still keep the
450 * totally bufcount the same to save possible data moving. this will leave a
451 * unused segment with size 0 at the tail, but that's ok.
453 * return new msg size after shrinking.
456 * + if any buffers higher than @segment has been filled in, must call shrink
457 * with non-zero @move_data.
458 * + caller should NOT keep pointers to msg buffers which higher than @segment
461 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
462 unsigned int newlen, int move_data)
464 switch (msg->lm_magic) {
465 case LUSTRE_MSG_MAGIC_V2:
466 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
468 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
472 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
474 PTLRPC_RS_DEBUG_LRU_DEL(rs);
476 LASSERT (atomic_read(&rs->rs_refcount) == 0);
477 LASSERT (!rs->rs_difficult || rs->rs_handled);
478 LASSERT (!rs->rs_on_net);
479 LASSERT (!rs->rs_scheduled);
480 LASSERT (rs->rs_export == NULL);
481 LASSERT (rs->rs_nlocks == 0);
482 LASSERT (list_empty(&rs->rs_exp_list));
483 LASSERT (list_empty(&rs->rs_obd_list));
485 sptlrpc_svc_free_rs(rs);
488 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
490 int flipped, required_len, i;
492 /* Now we know the sender speaks my language. */
493 required_len = lustre_msg_hdr_size_v2(0);
494 if (len < required_len) {
495 /* can't even look inside the message */
496 CERROR("message length %d too small for lustre_msg\n", len);
500 flipped = lustre_msg_swabbed(m);
503 __swab32s(&m->lm_bufcount);
504 __swab32s(&m->lm_secflvr);
505 __swab32s(&m->lm_repsize);
506 __swab32s(&m->lm_cksum);
507 __swab32s(&m->lm_flags);
508 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
509 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
512 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
513 if (len < required_len) {
514 /* didn't receive all the buffer lengths */
515 CERROR ("message length %d too small for %d buflens\n",
516 len, m->lm_bufcount);
520 for (i = 0; i < m->lm_bufcount; i++) {
522 __swab32s(&m->lm_buflens[i]);
523 required_len += size_round(m->lm_buflens[i]);
526 if (len < required_len) {
527 CERROR("len: %d, required_len %d\n", len, required_len);
528 CERROR("bufcount: %d\n", m->lm_bufcount);
529 for (i = 0; i < m->lm_bufcount; i++)
530 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
537 int lustre_unpack_msg(struct lustre_msg *m, int len)
539 int required_len, rc;
542 /* We can provide a slightly better error log, if we check the
543 * message magic and version first. In the future, struct
544 * lustre_msg may grow, and we'd like to log a version mismatch,
545 * rather than a short message.
548 required_len = offsetof(struct lustre_msg, lm_magic) +
550 if (len < required_len) {
551 /* can't even look inside the message */
552 CERROR("message length %d too small for magic/version check\n",
557 switch (m->lm_magic) {
558 case LUSTRE_MSG_MAGIC_V2:
559 case LUSTRE_MSG_MAGIC_V2_SWABBED:
560 rc = lustre_unpack_msg_v2(m, len);
563 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
570 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
573 struct ptlrpc_body *pb;
575 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
577 CERROR("error unpacking ptlrpc body\n");
580 if (lustre_msg_swabbed(m))
581 lustre_swab_ptlrpc_body(pb);
583 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
584 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
591 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
593 switch (req->rq_reqmsg->lm_magic) {
594 case LUSTRE_MSG_MAGIC_V2:
595 case LUSTRE_MSG_MAGIC_V2_SWABBED:
596 lustre_set_req_swabbed(req, offset);
597 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
599 CERROR("bad lustre msg magic: %#08X\n",
600 req->rq_reqmsg->lm_magic);
605 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
607 switch (req->rq_repmsg->lm_magic) {
608 case LUSTRE_MSG_MAGIC_V2:
609 case LUSTRE_MSG_MAGIC_V2_SWABBED:
610 lustre_set_rep_swabbed(req, offset);
611 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
613 CERROR("bad lustre msg magic: %#08X\n",
614 req->rq_repmsg->lm_magic);
619 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
621 if (n >= m->lm_bufcount)
624 return m->lm_buflens[n];
628 * lustre_msg_buflen - return the length of buffer @n in message @m
629 * @m - lustre_msg (request or reply) to look at
630 * @n - message index (base 0)
632 * returns zero for non-existent message indices
634 int lustre_msg_buflen(struct lustre_msg *m, int n)
636 switch (m->lm_magic) {
637 case LUSTRE_MSG_MAGIC_V2:
638 case LUSTRE_MSG_MAGIC_V2_SWABBED:
639 return lustre_msg_buflen_v2(m, n);
641 CERROR("incorrect message magic: %08x\n", m->lm_magic);
645 EXPORT_SYMBOL(lustre_msg_buflen);
648 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
650 if (n >= m->lm_bufcount)
653 m->lm_buflens[n] = len;
656 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
658 switch (m->lm_magic) {
659 case LUSTRE_MSG_MAGIC_V2:
660 lustre_msg_set_buflen_v2(m, n, len);
663 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
667 EXPORT_SYMBOL(lustre_msg_set_buflen);
669 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
670 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
671 int lustre_msg_bufcount(struct lustre_msg *m)
673 switch (m->lm_magic) {
674 case LUSTRE_MSG_MAGIC_V2:
675 case LUSTRE_MSG_MAGIC_V2_SWABBED:
676 return m->lm_bufcount;
678 CERROR("incorrect message magic: %08x\n", m->lm_magic);
682 EXPORT_SYMBOL(lustre_msg_bufcount);
684 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
686 /* max_len == 0 means the string should fill the buffer */
690 switch (m->lm_magic) {
691 case LUSTRE_MSG_MAGIC_V2:
692 case LUSTRE_MSG_MAGIC_V2_SWABBED:
693 str = lustre_msg_buf_v2(m, index, 0);
694 blen = lustre_msg_buflen_v2(m, index);
697 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
701 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
705 slen = strnlen(str, blen);
707 if (slen == blen) { /* not NULL terminated */
708 CERROR("can't unpack non-NULL terminated string in "
709 "msg %p buffer[%d] len %d\n", m, index, blen);
714 if (slen != blen - 1) {
715 CERROR("can't unpack short string in msg %p "
716 "buffer[%d] len %d: strlen %d\n",
717 m, index, blen, slen);
720 } else if (slen > max_len) {
721 CERROR("can't unpack oversized string in msg %p "
722 "buffer[%d] len %d strlen %d: max %d expected\n",
723 m, index, blen, slen, max_len);
730 /* Wrap up the normal fixed length cases */
731 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
736 switch (msg->lm_magic) {
737 case LUSTRE_MSG_MAGIC_V2:
738 case LUSTRE_MSG_MAGIC_V2_SWABBED:
739 ptr = lustre_msg_buf_v2(msg, index, min_size);
742 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
747 if (swabber != NULL && lustre_msg_swabbed(msg))
748 ((void (*)(void *))swabber)(ptr);
753 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
756 lustre_set_req_swabbed(req, index);
757 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
760 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
763 lustre_set_rep_swabbed(req, index);
764 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
767 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
769 switch (msg->lm_magic) {
770 case LUSTRE_MSG_MAGIC_V1:
771 case LUSTRE_MSG_MAGIC_V1_SWABBED:
773 case LUSTRE_MSG_MAGIC_V2:
774 case LUSTRE_MSG_MAGIC_V2_SWABBED:
775 /* already in host endian */
776 return msg->lm_flags;
778 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
783 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
785 switch (msg->lm_magic) {
786 case LUSTRE_MSG_MAGIC_V1:
788 case LUSTRE_MSG_MAGIC_V2:
789 msg->lm_flags = flags;
792 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
796 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
798 switch (msg->lm_magic) {
799 case LUSTRE_MSG_MAGIC_V2:
800 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
801 struct ptlrpc_body *pb;
803 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
805 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
811 /* flags might be printed in debug code while message
817 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
819 switch (msg->lm_magic) {
820 case LUSTRE_MSG_MAGIC_V2: {
821 struct ptlrpc_body *pb;
823 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
824 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
825 pb->pb_flags |= flags;
829 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
833 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
835 switch (msg->lm_magic) {
836 case LUSTRE_MSG_MAGIC_V2: {
837 struct ptlrpc_body *pb;
839 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
840 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
841 pb->pb_flags = flags;
845 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
849 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
851 switch (msg->lm_magic) {
852 case LUSTRE_MSG_MAGIC_V2:
853 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
854 struct ptlrpc_body *pb;
856 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
857 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
858 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
862 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
866 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
868 switch (msg->lm_magic) {
869 case LUSTRE_MSG_MAGIC_V2:
870 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
871 struct ptlrpc_body *pb;
873 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
875 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
878 return pb->pb_op_flags;
885 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
887 switch (msg->lm_magic) {
888 case LUSTRE_MSG_MAGIC_V2: {
889 struct ptlrpc_body *pb;
891 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
892 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
893 pb->pb_op_flags |= flags;
897 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
901 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
903 switch (msg->lm_magic) {
904 case LUSTRE_MSG_MAGIC_V2: {
905 struct ptlrpc_body *pb;
907 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
908 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
909 pb->pb_op_flags |= flags;
913 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
917 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
919 switch (msg->lm_magic) {
920 case LUSTRE_MSG_MAGIC_V2:
921 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
922 struct ptlrpc_body *pb;
924 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
926 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
929 return &pb->pb_handle;
932 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
937 __u32 lustre_msg_get_type(struct lustre_msg *msg)
939 switch (msg->lm_magic) {
940 case LUSTRE_MSG_MAGIC_V2:
941 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
942 struct ptlrpc_body *pb;
944 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
946 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
947 return PTL_RPC_MSG_ERR;
952 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
953 return PTL_RPC_MSG_ERR;
957 __u32 lustre_msg_get_version(struct lustre_msg *msg)
959 switch (msg->lm_magic) {
960 case LUSTRE_MSG_MAGIC_V2:
961 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
962 struct ptlrpc_body *pb;
964 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
966 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
969 return pb->pb_version;
972 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
977 void lustre_msg_add_version(struct lustre_msg *msg, int version)
979 switch (msg->lm_magic) {
980 case LUSTRE_MSG_MAGIC_V2:
981 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
982 struct ptlrpc_body *pb;
984 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
985 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
986 pb->pb_version |= version;
990 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
994 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
996 switch (msg->lm_magic) {
997 case LUSTRE_MSG_MAGIC_V2:
998 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
999 struct ptlrpc_body *pb;
1001 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1003 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1009 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1014 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1016 switch (msg->lm_magic) {
1017 case LUSTRE_MSG_MAGIC_V2:
1018 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1019 struct ptlrpc_body *pb;
1021 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1023 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1026 return pb->pb_last_xid;
1029 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1034 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1036 switch (msg->lm_magic) {
1037 case LUSTRE_MSG_MAGIC_V2:
1038 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1039 struct ptlrpc_body *pb;
1041 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1043 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1046 return pb->pb_last_committed;
1049 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1054 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1056 switch (msg->lm_magic) {
1057 case LUSTRE_MSG_MAGIC_V2:
1058 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1059 struct ptlrpc_body *pb;
1061 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1063 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1066 return pb->pb_transno;
1069 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1074 int lustre_msg_get_status(struct lustre_msg *msg)
1076 switch (msg->lm_magic) {
1077 case LUSTRE_MSG_MAGIC_V2:
1078 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1079 struct ptlrpc_body *pb;
1081 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1083 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1086 return pb->pb_status;
1089 /* status might be printed in debug code while message
1095 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1097 switch (msg->lm_magic) {
1098 case LUSTRE_MSG_MAGIC_V2:
1099 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1100 struct ptlrpc_body *pb;
1102 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1104 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1110 CERROR("invalid msg magic %x\n", msg->lm_magic);
1116 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1118 switch (msg->lm_magic) {
1119 case LUSTRE_MSG_MAGIC_V2:
1120 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1121 struct ptlrpc_body *pb;
1123 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1125 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1132 CERROR("invalid msg magic %x\n", msg->lm_magic);
1137 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1139 switch (msg->lm_magic) {
1140 case LUSTRE_MSG_MAGIC_V2:
1141 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1142 struct ptlrpc_body *pb;
1144 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1146 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1149 return pb->pb_limit;
1152 CERROR("invalid msg magic %x\n", msg->lm_magic);
1158 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1160 switch (msg->lm_magic) {
1161 case LUSTRE_MSG_MAGIC_V2:
1162 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1163 struct ptlrpc_body *pb;
1165 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1167 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1170 pb->pb_limit = limit;
1174 CERROR("invalid msg magic %x\n", msg->lm_magic);
1179 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1181 switch (msg->lm_magic) {
1182 case LUSTRE_MSG_MAGIC_V2:
1183 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1184 struct ptlrpc_body *pb;
1186 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1188 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1191 return pb->pb_conn_cnt;
1194 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1199 int lustre_msg_is_v1(struct lustre_msg *msg)
1201 switch (msg->lm_magic) {
1202 case LUSTRE_MSG_MAGIC_V1:
1203 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1210 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1212 switch (msg->lm_magic) {
1213 case LUSTRE_MSG_MAGIC_V2:
1214 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1215 return msg->lm_magic;
1217 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1222 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
1224 switch (msg->lm_magic) {
1225 case LUSTRE_MSG_MAGIC_V1:
1226 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1228 case LUSTRE_MSG_MAGIC_V2:
1229 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1230 struct ptlrpc_body *pb;
1232 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1234 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1238 return pb->pb_timeout;
1241 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1246 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1248 switch (msg->lm_magic) {
1249 case LUSTRE_MSG_MAGIC_V1:
1250 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1252 case LUSTRE_MSG_MAGIC_V2:
1253 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1254 struct ptlrpc_body *pb;
1256 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1258 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1262 return pb->pb_service_time;
1265 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1270 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1272 switch (msg->lm_magic) {
1273 case LUSTRE_MSG_MAGIC_V1:
1274 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1276 case LUSTRE_MSG_MAGIC_V2:
1277 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1278 return msg->lm_cksum;
1280 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1285 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1287 switch (msg->lm_magic) {
1288 case LUSTRE_MSG_MAGIC_V1:
1289 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1291 case LUSTRE_MSG_MAGIC_V2:
1292 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1293 struct ptlrpc_body *pb;
1294 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1295 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1296 return crc32_le(~(__u32)0, (unsigned char *)pb, sizeof(*pb));
1299 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1304 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1306 switch (msg->lm_magic) {
1307 case LUSTRE_MSG_MAGIC_V2: {
1308 struct ptlrpc_body *pb;
1310 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1311 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1312 pb->pb_handle = *handle;
1316 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1320 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1322 switch (msg->lm_magic) {
1323 case LUSTRE_MSG_MAGIC_V2: {
1324 struct ptlrpc_body *pb;
1326 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1327 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1332 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1336 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1338 switch (msg->lm_magic) {
1339 case LUSTRE_MSG_MAGIC_V2: {
1340 struct ptlrpc_body *pb;
1342 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1343 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1348 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1352 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1354 switch (msg->lm_magic) {
1355 case LUSTRE_MSG_MAGIC_V2: {
1356 struct ptlrpc_body *pb;
1358 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1359 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1360 pb->pb_last_xid = last_xid;
1364 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1368 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1370 switch (msg->lm_magic) {
1371 case LUSTRE_MSG_MAGIC_V2: {
1372 struct ptlrpc_body *pb;
1374 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1375 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1376 pb->pb_last_committed = last_committed;
1380 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1384 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1386 switch (msg->lm_magic) {
1387 case LUSTRE_MSG_MAGIC_V2: {
1388 struct ptlrpc_body *pb;
1390 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1391 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1392 pb->pb_transno = transno;
1396 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1400 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1402 switch (msg->lm_magic) {
1403 case LUSTRE_MSG_MAGIC_V2: {
1404 struct ptlrpc_body *pb;
1406 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1407 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1408 pb->pb_status = status;
1412 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1416 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1418 switch (msg->lm_magic) {
1419 case LUSTRE_MSG_MAGIC_V2: {
1420 struct ptlrpc_body *pb;
1422 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1423 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1424 pb->pb_conn_cnt = conn_cnt;
1428 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1432 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1434 switch (msg->lm_magic) {
1435 case LUSTRE_MSG_MAGIC_V1:
1437 case LUSTRE_MSG_MAGIC_V2: {
1438 struct ptlrpc_body *pb;
1440 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1441 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1442 pb->pb_timeout = timeout;
1446 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1450 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1452 switch (msg->lm_magic) {
1453 case LUSTRE_MSG_MAGIC_V1:
1455 case LUSTRE_MSG_MAGIC_V2: {
1456 struct ptlrpc_body *pb;
1458 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1459 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1460 pb->pb_service_time = service_time;
1464 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1468 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1470 switch (msg->lm_magic) {
1471 case LUSTRE_MSG_MAGIC_V1:
1473 case LUSTRE_MSG_MAGIC_V2:
1474 msg->lm_cksum = cksum;
1477 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1482 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1484 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1486 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1487 req->rq_pill.rc_area[RCL_SERVER]);
1488 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1489 req->rq_reqmsg->lm_repsize = req->rq_replen;
1492 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
1494 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1495 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1496 req->rq_reqmsg->lm_repsize = req->rq_replen;
1499 /* byte flipping routines for all wire types declared in
1500 * lustre_idl.h implemented here.
1502 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1504 __swab32s (&b->pb_type);
1505 __swab32s (&b->pb_version);
1506 __swab32s (&b->pb_opc);
1507 __swab32s (&b->pb_status);
1508 __swab64s (&b->pb_last_xid);
1509 __swab64s (&b->pb_last_seen);
1510 __swab64s (&b->pb_last_committed);
1511 __swab64s (&b->pb_transno);
1512 __swab32s (&b->pb_flags);
1513 __swab32s (&b->pb_op_flags);
1514 __swab32s (&b->pb_conn_cnt);
1515 __swab32s (&b->pb_timeout);
1516 __swab32s (&b->pb_service_time);
1517 __swab32s (&b->pb_limit);
1518 __swab64s (&b->pb_slv);
1519 __swab64s (&b->pb_pre_versions[0]);
1520 __swab64s (&b->pb_pre_versions[1]);
1521 __swab64s (&b->pb_pre_versions[2]);
1522 __swab64s (&b->pb_pre_versions[3]);
1523 CLASSERT(offsetof(typeof(*b), pb_padding) != 0);
1526 void lustre_swab_connect(struct obd_connect_data *ocd)
1528 __swab64s(&ocd->ocd_connect_flags);
1529 __swab32s(&ocd->ocd_version);
1530 __swab32s(&ocd->ocd_grant);
1531 __swab64s(&ocd->ocd_ibits_known);
1532 __swab32s(&ocd->ocd_index);
1533 __swab32s(&ocd->ocd_brw_size);
1534 __swab32s(&ocd->ocd_nllu);
1535 __swab32s(&ocd->ocd_nllg);
1536 __swab64s(&ocd->ocd_transno);
1537 __swab32s(&ocd->ocd_group);
1538 __swab32s(&ocd->ocd_cksum_types);
1539 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1540 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1543 void lustre_swab_obdo (struct obdo *o)
1545 __swab64s (&o->o_valid);
1546 __swab64s (&o->o_id);
1547 __swab64s (&o->o_gr);
1548 __swab64s (&o->o_fid);
1549 __swab64s (&o->o_size);
1550 __swab64s (&o->o_mtime);
1551 __swab64s (&o->o_atime);
1552 __swab64s (&o->o_ctime);
1553 __swab64s (&o->o_blocks);
1554 __swab64s (&o->o_grant);
1555 __swab32s (&o->o_blksize);
1556 __swab32s (&o->o_mode);
1557 __swab32s (&o->o_uid);
1558 __swab32s (&o->o_gid);
1559 __swab32s (&o->o_flags);
1560 __swab32s (&o->o_nlink);
1561 __swab32s (&o->o_generation);
1562 __swab32s (&o->o_misc);
1563 __swab32s (&o->o_easize);
1564 __swab32s (&o->o_mds);
1565 __swab32s (&o->o_stripe_idx);
1566 __swab32s (&o->o_padding_1);
1567 /* o_inline is opaque */
1570 void lustre_swab_obd_statfs (struct obd_statfs *os)
1572 __swab64s (&os->os_type);
1573 __swab64s (&os->os_blocks);
1574 __swab64s (&os->os_bfree);
1575 __swab64s (&os->os_bavail);
1576 __swab64s (&os->os_files);
1577 __swab64s (&os->os_ffree);
1578 /* no need to swab os_fsid */
1579 __swab32s (&os->os_bsize);
1580 __swab32s (&os->os_namelen);
1581 __swab64s (&os->os_maxbytes);
1582 __swab32s (&os->os_state);
1583 /* no need to swap os_spare */
1586 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1588 __swab64s (&ioo->ioo_id);
1589 __swab64s (&ioo->ioo_gr);
1590 __swab32s (&ioo->ioo_type);
1591 __swab32s (&ioo->ioo_bufcnt);
1594 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1596 __swab64s (&nbr->offset);
1597 __swab32s (&nbr->len);
1598 __swab32s (&nbr->flags);
1601 void lustre_swab_ost_body (struct ost_body *b)
1603 lustre_swab_obdo (&b->oa);
1606 void lustre_swab_ost_last_id(obd_id *id)
1611 void lustre_swab_generic_32s(__u32 *val)
1616 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1618 __swab64s(&lvb->lvb_size);
1619 __swab64s(&lvb->lvb_mtime);
1620 __swab64s(&lvb->lvb_atime);
1621 __swab64s(&lvb->lvb_ctime);
1622 __swab64s(&lvb->lvb_blocks);
1625 void lustre_swab_mds_status_req (struct mds_status_req *r)
1627 __swab32s (&r->flags);
1628 __swab32s (&r->repbuf);
1631 void lustre_swab_mds_body (struct mds_body *b)
1633 lustre_swab_ll_fid (&b->fid1);
1634 lustre_swab_ll_fid (&b->fid2);
1635 /* handle is opaque */
1636 __swab64s (&b->valid);
1637 __swab64s (&b->size);
1638 __swab64s (&b->mtime);
1639 __swab64s (&b->atime);
1640 __swab64s (&b->ctime);
1641 __swab64s (&b->blocks);
1642 __swab64s (&b->io_epoch);
1643 __swab64s (&b->ino);
1644 __swab32s (&b->fsuid);
1645 __swab32s (&b->fsgid);
1646 __swab32s (&b->capability);
1647 __swab32s (&b->mode);
1648 __swab32s (&b->uid);
1649 __swab32s (&b->gid);
1650 __swab32s (&b->flags);
1651 __swab32s (&b->rdev);
1652 __swab32s (&b->nlink);
1653 __swab32s (&b->generation);
1654 __swab32s (&b->suppgid);
1655 __swab32s (&b->eadatasize);
1656 __swab32s (&b->aclsize);
1657 __swab32s (&b->max_mdsize);
1658 __swab32s (&b->max_cookiesize);
1659 __swab32s (&b->padding_4);
1662 void lustre_swab_mdt_body (struct mdt_body *b)
1664 lustre_swab_lu_fid (&b->fid1);
1665 lustre_swab_lu_fid (&b->fid2);
1666 /* handle is opaque */
1667 __swab64s (&b->valid);
1668 __swab64s (&b->size);
1669 __swab64s (&b->mtime);
1670 __swab64s (&b->atime);
1671 __swab64s (&b->ctime);
1672 __swab64s (&b->blocks);
1673 __swab64s (&b->ioepoch);
1674 __swab64s (&b->ino);
1675 __swab32s (&b->fsuid);
1676 __swab32s (&b->fsgid);
1677 __swab32s (&b->capability);
1678 __swab32s (&b->mode);
1679 __swab32s (&b->uid);
1680 __swab32s (&b->gid);
1681 __swab32s (&b->flags);
1682 __swab32s (&b->rdev);
1683 __swab32s (&b->nlink);
1684 __swab32s (&b->generation);
1685 __swab32s (&b->suppgid);
1686 __swab32s (&b->eadatasize);
1687 __swab32s (&b->aclsize);
1688 __swab32s (&b->max_mdsize);
1689 __swab32s (&b->max_cookiesize);
1690 __swab32s (&b->padding_4);
1693 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1695 /* handle is opaque */
1696 __swab64s (&b->ioepoch);
1697 __swab32s (&b->flags);
1698 CLASSERT(offsetof(typeof(*b), padding) != 0);
1701 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1704 __swab32s(&mti->mti_lustre_ver);
1705 __swab32s(&mti->mti_stripe_index);
1706 __swab32s(&mti->mti_config_ver);
1707 __swab32s(&mti->mti_flags);
1708 __swab32s(&mti->mti_nid_count);
1709 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1710 for (i = 0; i < MTI_NIDS_MAX; i++)
1711 __swab64s(&mti->mti_nids[i]);
1714 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1716 __swab64s (&i->dqi_bgrace);
1717 __swab64s (&i->dqi_igrace);
1718 __swab32s (&i->dqi_flags);
1719 __swab32s (&i->dqi_valid);
1722 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1724 __swab64s (&b->dqb_ihardlimit);
1725 __swab64s (&b->dqb_isoftlimit);
1726 __swab64s (&b->dqb_curinodes);
1727 __swab64s (&b->dqb_bhardlimit);
1728 __swab64s (&b->dqb_bsoftlimit);
1729 __swab64s (&b->dqb_curspace);
1730 __swab64s (&b->dqb_btime);
1731 __swab64s (&b->dqb_itime);
1732 __swab32s (&b->dqb_valid);
1733 CLASSERT(offsetof(typeof(*b), padding) != 0);
1736 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1738 __swab32s (&q->qc_cmd);
1739 __swab32s (&q->qc_type);
1740 __swab32s (&q->qc_id);
1741 __swab32s (&q->qc_stat);
1742 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1743 lustre_swab_obd_dqblk (&q->qc_dqblk);
1746 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1748 __swab32s (&p->rp_uid);
1749 __swab32s (&p->rp_gid);
1750 __swab32s (&p->rp_fsuid);
1751 __swab32s (&p->rp_fsgid);
1752 __swab32s (&p->rp_access_perm);
1755 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1757 __swab32s (&p->rp_uid);
1758 __swab32s (&p->rp_gid);
1759 __swab32s (&p->rp_fsuid);
1760 __swab32s (&p->rp_fsgid);
1761 __swab32s (&p->rp_access_perm);
1764 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1766 __swab32s (&sa->sa_opcode);
1767 __swab32s (&sa->sa_fsuid);
1768 __swab32s (&sa->sa_fsgid);
1769 __swab32s (&sa->sa_cap);
1770 __swab32s (&sa->sa_suppgid);
1771 __swab32s (&sa->sa_mode);
1772 lustre_swab_ll_fid (&sa->sa_fid);
1773 __swab64s (&sa->sa_valid);
1774 __swab64s (&sa->sa_size);
1775 __swab64s (&sa->sa_mtime);
1776 __swab64s (&sa->sa_atime);
1777 __swab64s (&sa->sa_ctime);
1778 __swab32s (&sa->sa_uid);
1779 __swab32s (&sa->sa_gid);
1780 __swab32s (&sa->sa_attr_flags);
1781 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1784 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1786 __swab64s(&jr->jr_headsize);
1787 lustre_swab_ll_fid(&jr->jr_fid);
1790 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1792 __swab64s(&jr->jr_headsize);
1793 lustre_swab_lu_fid(&jr->jr_fid);
1796 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1798 __swab32s (&cr->cr_opcode);
1799 __swab32s (&cr->cr_fsuid);
1800 __swab32s (&cr->cr_fsgid);
1801 __swab32s (&cr->cr_cap);
1802 __swab32s (&cr->cr_flags); /* for use with open */
1803 __swab32s (&cr->cr_mode);
1804 lustre_swab_ll_fid (&cr->cr_fid);
1805 lustre_swab_ll_fid (&cr->cr_replayfid);
1806 __swab64s (&cr->cr_time);
1807 __swab64s (&cr->cr_rdev);
1808 __swab32s (&cr->cr_suppgid);
1809 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1810 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1811 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1812 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1813 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1816 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1818 __swab32s (&lk->lk_opcode);
1819 __swab32s (&lk->lk_fsuid);
1820 __swab32s (&lk->lk_fsgid);
1821 __swab32s (&lk->lk_cap);
1822 __swab32s (&lk->lk_suppgid1);
1823 __swab32s (&lk->lk_suppgid2);
1824 lustre_swab_ll_fid (&lk->lk_fid1);
1825 lustre_swab_ll_fid (&lk->lk_fid2);
1826 __swab64s (&lk->lk_time);
1827 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1828 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1829 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1830 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1833 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1835 __swab32s (&ul->ul_opcode);
1836 __swab32s (&ul->ul_fsuid);
1837 __swab32s (&ul->ul_fsgid);
1838 __swab32s (&ul->ul_cap);
1839 __swab32s (&ul->ul_suppgid);
1840 __swab32s (&ul->ul_mode);
1841 lustre_swab_ll_fid (&ul->ul_fid1);
1842 lustre_swab_ll_fid (&ul->ul_fid2);
1843 __swab64s (&ul->ul_time);
1844 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1845 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1846 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1847 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1850 void lustre_swab_fiemap_extent(struct ll_fiemap_extent *fm_extent)
1852 __swab64s(&fm_extent->fe_logical);
1853 __swab64s(&fm_extent->fe_physical);
1854 __swab64s(&fm_extent->fe_length);
1855 __swab32s(&fm_extent->fe_flags);
1856 __swab32s(&fm_extent->fe_device);
1859 void lustre_swab_fiemap(struct ll_user_fiemap *fiemap)
1863 __swab64s(&fiemap->fm_start);
1864 __swab64s(&fiemap->fm_length);
1865 __swab32s(&fiemap->fm_flags);
1866 __swab32s(&fiemap->fm_mapped_extents);
1867 __swab32s(&fiemap->fm_extent_count);
1868 __swab32s(&fiemap->fm_reserved);
1870 for (i = 0; i < fiemap->fm_mapped_extents; i++)
1871 lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
1874 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1876 __swab32s (&rn->rn_opcode);
1877 __swab32s (&rn->rn_fsuid);
1878 __swab32s (&rn->rn_fsgid);
1879 __swab32s (&rn->rn_cap);
1880 __swab32s (&rn->rn_suppgid1);
1881 __swab32s (&rn->rn_suppgid2);
1882 lustre_swab_ll_fid (&rn->rn_fid1);
1883 lustre_swab_ll_fid (&rn->rn_fid2);
1884 __swab64s (&rn->rn_time);
1885 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1886 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1887 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1888 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1891 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
1893 __swab32s (&rr->rr_opcode);
1894 __swab32s (&rr->rr_fsuid);
1895 __swab32s (&rr->rr_fsgid);
1896 __swab32s (&rr->rr_cap);
1897 __swab32s (&rr->rr_suppgid1);
1898 __swab32s (&rr->rr_suppgid2);
1899 /* handle is opaque */
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 __swab64s (&ld->ld_default_stripe_size);
1926 __swab64s (&ld->ld_default_stripe_offset);
1927 __swab32s (&ld->ld_pattern);
1928 __swab32s (&ld->ld_qos_maxage);
1929 /* uuid endian insensitive */
1932 /*begin adding MDT by huanghua@clusterfs.com*/
1933 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1935 __swab32s (&ld->ld_tgt_count);
1936 __swab32s (&ld->ld_active_tgt_count);
1937 /* uuid endian insensitive */
1939 /*end adding MDT by huanghua@clusterfs.com*/
1940 void lustre_swab_md_fld (struct md_fld *mf)
1942 __swab64s(&mf->mf_seq);
1943 __swab64s(&mf->mf_mds);
1946 static void print_lum (struct lov_user_md *lum)
1948 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1949 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1950 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1951 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1952 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
1953 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1954 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1955 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1958 static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
1961 __swab32s(&lum->lmm_magic);
1962 __swab32s(&lum->lmm_pattern);
1963 __swab64s(&lum->lmm_object_id);
1964 __swab64s(&lum->lmm_object_gr);
1965 __swab32s(&lum->lmm_stripe_size);
1966 __swab16s(&lum->lmm_stripe_count);
1967 __swab16s(&lum->lmm_stripe_offset);
1972 static void print_lumj (struct lov_user_md_join *lumj)
1974 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
1975 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
1976 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
1977 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
1978 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
1979 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
1980 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
1981 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
1984 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
1987 CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
1988 lustre_swab_lov_user_md_common(lum);
1992 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum)
1995 CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
1996 lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
1997 /* lmm_pool_name nothing to do with char */
2001 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2004 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2005 __swab32s(&lumj->lmm_magic);
2006 __swab32s(&lumj->lmm_pattern);
2007 __swab64s(&lumj->lmm_object_id);
2008 __swab64s(&lumj->lmm_object_gr);
2009 __swab32s(&lumj->lmm_stripe_size);
2010 __swab32s(&lumj->lmm_stripe_count);
2011 __swab32s(&lumj->lmm_extent_count);
2016 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
2021 for (i = 0; i < stripe_count; i++) {
2022 __swab64s(&(lod[i].l_object_id));
2023 __swab64s(&(lod[i].l_object_gr));
2024 __swab32s(&(lod[i].l_ost_gen));
2025 __swab32s(&(lod[i].l_ost_idx));
2031 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2035 for (i = 0; i < RES_NAME_SIZE; i++)
2036 __swab64s (&id->name[i]);
2039 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2041 /* the lock data is a union and the first two fields are always an
2042 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2043 * data the same way. */
2044 __swab64s(&d->l_extent.start);
2045 __swab64s(&d->l_extent.end);
2046 __swab64s(&d->l_extent.gid);
2047 __swab32s(&d->l_flock.pid);
2050 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2052 __swab64s (&i->opc);
2055 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2057 __swab32s (&r->lr_type);
2058 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2059 lustre_swab_ldlm_res_id (&r->lr_name);
2062 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2064 lustre_swab_ldlm_resource_desc (&l->l_resource);
2065 __swab32s (&l->l_req_mode);
2066 __swab32s (&l->l_granted_mode);
2067 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2070 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2072 __swab32s (&rq->lock_flags);
2073 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2074 __swab32s (&rq->lock_count);
2075 /* lock_handle[] opaque */
2078 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2080 __swab32s (&r->lock_flags);
2081 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2082 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2083 /* lock_handle opaque */
2084 __swab64s (&r->lock_policy_res1);
2085 __swab64s (&r->lock_policy_res2);
2088 /* no one calls this */
2089 int llog_log_swabbed(struct llog_log_hdr *hdr)
2091 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2093 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2098 void lustre_swab_qdata(struct qunit_data *d)
2100 __swab32s (&d->qd_id);
2101 __swab32s (&d->qd_flags);
2102 __swab64s (&d->qd_count);
2105 void lustre_swab_qdata_old(struct qunit_data_old *d)
2107 __swab32s (&d->qd_id);
2108 __swab32s (&d->qd_type);
2109 __swab32s (&d->qd_count);
2110 __swab32s (&d->qd_isblk);
2114 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2116 struct qunit_data_old tmp;
2117 struct qunit_data *ret;
2124 ret = (struct qunit_data *)d;
2125 ret->qd_id = tmp.qd_id;
2126 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2127 ret->qd_count = tmp.qd_count;
2131 EXPORT_SYMBOL(lustre_quota_old_to_new);
2133 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2135 struct qunit_data tmp;
2136 struct qunit_data_old *ret;
2143 ret = (struct qunit_data_old *)d;
2144 ret->qd_id = tmp.qd_id;
2145 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2146 ret->qd_count = (__u32)tmp.qd_count;
2147 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2150 EXPORT_SYMBOL(lustre_quota_new_to_old);
2151 #endif /* __KERNEL__ */
2153 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2155 LASSERT(req->rq_reqmsg);
2157 switch (req->rq_reqmsg->lm_magic) {
2158 case LUSTRE_MSG_MAGIC_V2:
2159 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2160 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2162 CERROR("bad lustre msg magic: %#08X\n",
2163 req->rq_reqmsg->lm_magic);
2168 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2170 LASSERT(req->rq_repmsg);
2172 switch (req->rq_repmsg->lm_magic) {
2173 case LUSTRE_MSG_MAGIC_V2:
2174 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2175 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2177 /* uninitialized yet */
2182 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2183 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2187 va_start(args, fmt);
2188 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2189 data->msg_fn, data->msg_line, fmt, args,
2190 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d/%d"
2191 " lens %d/%d e %d to %d dl "CFS_TIME_T" ref %d "
2192 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2193 req, req->rq_xid, req->rq_transno,
2194 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2195 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2196 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2198 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2200 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2202 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2203 req->rq_request_portal, req->rq_reply_portal,
2204 req->rq_reqlen, req->rq_replen,
2205 req->rq_early_count, req->rq_timeout, req->rq_deadline,
2206 atomic_read(&req->rq_refcount), DEBUG_REQ_FLAGS(req),
2207 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2208 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2209 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2210 lustre_msg_get_flags(req->rq_repmsg) : -1,
2212 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2213 lustre_msg_get_status(req->rq_repmsg) : -1);
2215 EXPORT_SYMBOL(_debug_req);
2217 void lustre_swab_lustre_capa(struct lustre_capa *c)
2219 lustre_swab_lu_fid(&c->lc_fid);
2220 __swab64s (&c->lc_opc);
2221 __swab32s (&c->lc_uid);
2222 __swab32s (&c->lc_flags);
2223 __swab32s (&c->lc_keyid);
2224 __swab32s (&c->lc_timeout);
2225 __swab64s (&c->lc_expiry);
2228 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2230 __swab64s (&k->lk_mdsid);
2231 __swab32s (&k->lk_keyid);
2232 __swab32s (&k->lk_padding);