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);
323 CFS_INIT_LIST_HEAD(&rs->rs_list);
324 spin_lock_init(&rs->rs_lock);
326 req->rq_replen = msg_len;
327 req->rq_reply_state = rs;
328 req->rq_repmsg = rs->rs_msg;
330 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
331 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
332 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
334 PTLRPC_RS_DEBUG_LRU_ADD(rs);
338 EXPORT_SYMBOL(lustre_pack_reply_v2);
340 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
341 char **bufs, int flags)
344 __u32 size[] = { sizeof(struct ptlrpc_body) };
352 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
354 switch (req->rq_reqmsg->lm_magic) {
355 case LUSTRE_MSG_MAGIC_V2:
356 case LUSTRE_MSG_MAGIC_V2_SWABBED:
357 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
360 LASSERTF(0, "incorrect message magic: %08x\n",
361 req->rq_reqmsg->lm_magic);
365 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
366 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
370 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
373 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
376 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
378 int i, offset, buflen, bufcount;
383 bufcount = m->lm_bufcount;
384 if (unlikely(n >= bufcount)) {
385 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
390 buflen = m->lm_buflens[n];
391 if (unlikely(buflen < min_size)) {
392 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
393 m, n, buflen, min_size);
397 offset = lustre_msg_hdr_size_v2(bufcount);
398 for (i = 0; i < n; i++)
399 offset += size_round(m->lm_buflens[i]);
401 return (char *)m + offset;
404 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
406 switch (m->lm_magic) {
407 case LUSTRE_MSG_MAGIC_V2:
408 case LUSTRE_MSG_MAGIC_V2_SWABBED:
409 return lustre_msg_buf_v2(m, n, min_size);
411 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
416 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
417 unsigned int newlen, int move_data)
419 char *tail = NULL, *newpos;
423 LASSERT(msg->lm_bufcount > segment);
424 LASSERT(msg->lm_buflens[segment] >= newlen);
426 if (msg->lm_buflens[segment] == newlen)
429 if (move_data && msg->lm_bufcount > segment + 1) {
430 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
431 for (n = segment + 1; n < msg->lm_bufcount; n++)
432 tail_len += size_round(msg->lm_buflens[n]);
435 msg->lm_buflens[segment] = newlen;
437 if (tail && tail_len) {
438 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
439 LASSERT(newpos <= tail);
441 memcpy(newpos, tail, tail_len);
444 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
448 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
449 * we also move data forward from @segment + 1.
451 * if @newlen == 0, we remove the segment completely, but we still keep the
452 * totally bufcount the same to save possible data moving. this will leave a
453 * unused segment with size 0 at the tail, but that's ok.
455 * return new msg size after shrinking.
458 * + if any buffers higher than @segment has been filled in, must call shrink
459 * with non-zero @move_data.
460 * + caller should NOT keep pointers to msg buffers which higher than @segment
463 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
464 unsigned int newlen, int move_data)
466 switch (msg->lm_magic) {
467 case LUSTRE_MSG_MAGIC_V2:
468 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
470 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
474 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
476 PTLRPC_RS_DEBUG_LRU_DEL(rs);
478 LASSERT (atomic_read(&rs->rs_refcount) == 0);
479 LASSERT (!rs->rs_difficult || rs->rs_handled);
480 LASSERT (!rs->rs_on_net);
481 LASSERT (!rs->rs_scheduled);
482 LASSERT (rs->rs_export == NULL);
483 LASSERT (rs->rs_nlocks == 0);
484 LASSERT (list_empty(&rs->rs_exp_list));
485 LASSERT (list_empty(&rs->rs_obd_list));
487 sptlrpc_svc_free_rs(rs);
490 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
492 int flipped, required_len, i;
494 /* Now we know the sender speaks my language. */
495 required_len = lustre_msg_hdr_size_v2(0);
496 if (len < required_len) {
497 /* can't even look inside the message */
498 CERROR("message length %d too small for lustre_msg\n", len);
502 flipped = lustre_msg_swabbed(m);
505 __swab32s(&m->lm_bufcount);
506 __swab32s(&m->lm_secflvr);
507 __swab32s(&m->lm_repsize);
508 __swab32s(&m->lm_cksum);
509 __swab32s(&m->lm_flags);
510 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
511 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
514 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
515 if (len < required_len) {
516 /* didn't receive all the buffer lengths */
517 CERROR ("message length %d too small for %d buflens\n",
518 len, m->lm_bufcount);
522 for (i = 0; i < m->lm_bufcount; i++) {
524 __swab32s(&m->lm_buflens[i]);
525 required_len += size_round(m->lm_buflens[i]);
528 if (len < required_len) {
529 CERROR("len: %d, required_len %d\n", len, required_len);
530 CERROR("bufcount: %d\n", m->lm_bufcount);
531 for (i = 0; i < m->lm_bufcount; i++)
532 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
539 int lustre_unpack_msg(struct lustre_msg *m, int len)
541 int required_len, rc;
544 /* We can provide a slightly better error log, if we check the
545 * message magic and version first. In the future, struct
546 * lustre_msg may grow, and we'd like to log a version mismatch,
547 * rather than a short message.
550 required_len = offsetof(struct lustre_msg, lm_magic) +
552 if (len < required_len) {
553 /* can't even look inside the message */
554 CERROR("message length %d too small for magic/version check\n",
559 switch (m->lm_magic) {
560 case LUSTRE_MSG_MAGIC_V2:
561 case LUSTRE_MSG_MAGIC_V2_SWABBED:
562 rc = lustre_unpack_msg_v2(m, len);
565 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
572 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
575 struct ptlrpc_body *pb;
577 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
579 CERROR("error unpacking ptlrpc body\n");
582 if (lustre_msg_swabbed(m))
583 lustre_swab_ptlrpc_body(pb);
585 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
586 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
593 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
595 switch (req->rq_reqmsg->lm_magic) {
596 case LUSTRE_MSG_MAGIC_V2:
597 case LUSTRE_MSG_MAGIC_V2_SWABBED:
598 lustre_set_req_swabbed(req, offset);
599 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
601 CERROR("bad lustre msg magic: %#08X\n",
602 req->rq_reqmsg->lm_magic);
607 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
609 switch (req->rq_repmsg->lm_magic) {
610 case LUSTRE_MSG_MAGIC_V2:
611 case LUSTRE_MSG_MAGIC_V2_SWABBED:
612 lustre_set_rep_swabbed(req, offset);
613 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
615 CERROR("bad lustre msg magic: %#08X\n",
616 req->rq_repmsg->lm_magic);
621 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
623 if (n >= m->lm_bufcount)
626 return m->lm_buflens[n];
630 * lustre_msg_buflen - return the length of buffer @n in message @m
631 * @m - lustre_msg (request or reply) to look at
632 * @n - message index (base 0)
634 * returns zero for non-existent message indices
636 int lustre_msg_buflen(struct lustre_msg *m, int n)
638 switch (m->lm_magic) {
639 case LUSTRE_MSG_MAGIC_V2:
640 case LUSTRE_MSG_MAGIC_V2_SWABBED:
641 return lustre_msg_buflen_v2(m, n);
643 CERROR("incorrect message magic: %08x\n", m->lm_magic);
647 EXPORT_SYMBOL(lustre_msg_buflen);
650 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
652 if (n >= m->lm_bufcount)
655 m->lm_buflens[n] = len;
658 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
660 switch (m->lm_magic) {
661 case LUSTRE_MSG_MAGIC_V2:
662 lustre_msg_set_buflen_v2(m, n, len);
665 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
669 EXPORT_SYMBOL(lustre_msg_set_buflen);
671 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
672 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
673 int lustre_msg_bufcount(struct lustre_msg *m)
675 switch (m->lm_magic) {
676 case LUSTRE_MSG_MAGIC_V2:
677 case LUSTRE_MSG_MAGIC_V2_SWABBED:
678 return m->lm_bufcount;
680 CERROR("incorrect message magic: %08x\n", m->lm_magic);
684 EXPORT_SYMBOL(lustre_msg_bufcount);
686 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
688 /* max_len == 0 means the string should fill the buffer */
692 switch (m->lm_magic) {
693 case LUSTRE_MSG_MAGIC_V2:
694 case LUSTRE_MSG_MAGIC_V2_SWABBED:
695 str = lustre_msg_buf_v2(m, index, 0);
696 blen = lustre_msg_buflen_v2(m, index);
699 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
703 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
707 slen = strnlen(str, blen);
709 if (slen == blen) { /* not NULL terminated */
710 CERROR("can't unpack non-NULL terminated string in "
711 "msg %p buffer[%d] len %d\n", m, index, blen);
716 if (slen != blen - 1) {
717 CERROR("can't unpack short string in msg %p "
718 "buffer[%d] len %d: strlen %d\n",
719 m, index, blen, slen);
722 } else if (slen > max_len) {
723 CERROR("can't unpack oversized string in msg %p "
724 "buffer[%d] len %d strlen %d: max %d expected\n",
725 m, index, blen, slen, max_len);
732 /* Wrap up the normal fixed length cases */
733 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
738 LASSERT(msg != NULL);
739 switch (msg->lm_magic) {
740 case LUSTRE_MSG_MAGIC_V2:
741 case LUSTRE_MSG_MAGIC_V2_SWABBED:
742 ptr = lustre_msg_buf_v2(msg, index, min_size);
745 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
750 if (swabber != NULL && lustre_msg_swabbed(msg))
751 ((void (*)(void *))swabber)(ptr);
756 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
759 if (lustre_req_swabbed(req, index))
760 return lustre_msg_buf(req->rq_reqmsg, index, min_size);
762 lustre_set_req_swabbed(req, index);
763 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
766 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
769 if (lustre_rep_swabbed(req, index))
770 return lustre_msg_buf(req->rq_repmsg, index, min_size);
772 lustre_set_rep_swabbed(req, index);
773 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
776 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
778 switch (msg->lm_magic) {
779 case LUSTRE_MSG_MAGIC_V1:
780 case LUSTRE_MSG_MAGIC_V1_SWABBED:
782 case LUSTRE_MSG_MAGIC_V2:
783 case LUSTRE_MSG_MAGIC_V2_SWABBED:
784 /* already in host endian */
785 return msg->lm_flags;
787 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
791 EXPORT_SYMBOL(lustre_msghdr_get_flags);
793 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
795 switch (msg->lm_magic) {
796 case LUSTRE_MSG_MAGIC_V1:
798 case LUSTRE_MSG_MAGIC_V2:
799 msg->lm_flags = flags;
802 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
806 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
808 switch (msg->lm_magic) {
809 case LUSTRE_MSG_MAGIC_V2:
810 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
811 struct ptlrpc_body *pb;
813 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
815 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
821 /* flags might be printed in debug code while message
827 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
829 switch (msg->lm_magic) {
830 case LUSTRE_MSG_MAGIC_V2: {
831 struct ptlrpc_body *pb;
833 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
834 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
835 pb->pb_flags |= flags;
839 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
843 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
845 switch (msg->lm_magic) {
846 case LUSTRE_MSG_MAGIC_V2: {
847 struct ptlrpc_body *pb;
849 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
850 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
851 pb->pb_flags = flags;
855 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
859 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
861 switch (msg->lm_magic) {
862 case LUSTRE_MSG_MAGIC_V2:
863 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
864 struct ptlrpc_body *pb;
866 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
867 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
868 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
872 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
876 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
878 switch (msg->lm_magic) {
879 case LUSTRE_MSG_MAGIC_V2:
880 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
881 struct ptlrpc_body *pb;
883 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
885 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
888 return pb->pb_op_flags;
895 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
897 switch (msg->lm_magic) {
898 case LUSTRE_MSG_MAGIC_V2: {
899 struct ptlrpc_body *pb;
901 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
902 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
903 pb->pb_op_flags |= flags;
907 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
911 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
913 switch (msg->lm_magic) {
914 case LUSTRE_MSG_MAGIC_V2: {
915 struct ptlrpc_body *pb;
917 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
918 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
919 pb->pb_op_flags |= flags;
923 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
927 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
929 switch (msg->lm_magic) {
930 case LUSTRE_MSG_MAGIC_V2:
931 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
932 struct ptlrpc_body *pb;
934 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
936 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
939 return &pb->pb_handle;
942 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
947 __u32 lustre_msg_get_type(struct lustre_msg *msg)
949 switch (msg->lm_magic) {
950 case LUSTRE_MSG_MAGIC_V2:
951 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
952 struct ptlrpc_body *pb;
954 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
956 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
957 return PTL_RPC_MSG_ERR;
962 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
963 return PTL_RPC_MSG_ERR;
967 __u32 lustre_msg_get_version(struct lustre_msg *msg)
969 switch (msg->lm_magic) {
970 case LUSTRE_MSG_MAGIC_V2:
971 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
972 struct ptlrpc_body *pb;
974 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
976 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
979 return pb->pb_version;
982 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
987 void lustre_msg_add_version(struct lustre_msg *msg, int version)
989 switch (msg->lm_magic) {
990 case LUSTRE_MSG_MAGIC_V2:
991 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
992 struct ptlrpc_body *pb;
994 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
995 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
996 pb->pb_version |= version;
1000 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1004 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1006 switch (msg->lm_magic) {
1007 case LUSTRE_MSG_MAGIC_V2:
1008 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1009 struct ptlrpc_body *pb;
1011 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1013 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1019 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1024 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1026 switch (msg->lm_magic) {
1027 case LUSTRE_MSG_MAGIC_V2:
1028 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1029 struct ptlrpc_body *pb;
1031 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1033 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1036 return pb->pb_last_xid;
1039 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1044 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1046 switch (msg->lm_magic) {
1047 case LUSTRE_MSG_MAGIC_V2:
1048 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1049 struct ptlrpc_body *pb;
1051 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1053 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1056 return pb->pb_last_committed;
1059 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1064 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1066 switch (msg->lm_magic) {
1067 case LUSTRE_MSG_MAGIC_V2:
1068 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1069 struct ptlrpc_body *pb;
1071 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1073 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1076 return pb->pb_transno;
1079 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1084 int lustre_msg_get_status(struct lustre_msg *msg)
1086 switch (msg->lm_magic) {
1087 case LUSTRE_MSG_MAGIC_V2:
1088 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1089 struct ptlrpc_body *pb;
1091 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1093 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1096 return pb->pb_status;
1099 /* status might be printed in debug code while message
1105 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1107 switch (msg->lm_magic) {
1108 case LUSTRE_MSG_MAGIC_V2:
1109 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1110 struct ptlrpc_body *pb;
1112 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1114 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1120 CERROR("invalid msg magic %x\n", msg->lm_magic);
1126 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1128 switch (msg->lm_magic) {
1129 case LUSTRE_MSG_MAGIC_V2:
1130 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1131 struct ptlrpc_body *pb;
1133 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1135 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1142 CERROR("invalid msg magic %x\n", msg->lm_magic);
1147 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1149 switch (msg->lm_magic) {
1150 case LUSTRE_MSG_MAGIC_V2:
1151 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1152 struct ptlrpc_body *pb;
1154 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1156 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1159 return pb->pb_limit;
1162 CERROR("invalid msg magic %x\n", msg->lm_magic);
1168 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1170 switch (msg->lm_magic) {
1171 case LUSTRE_MSG_MAGIC_V2:
1172 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1173 struct ptlrpc_body *pb;
1175 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1177 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1180 pb->pb_limit = limit;
1184 CERROR("invalid msg magic %x\n", msg->lm_magic);
1189 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1191 switch (msg->lm_magic) {
1192 case LUSTRE_MSG_MAGIC_V2:
1193 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1194 struct ptlrpc_body *pb;
1196 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1198 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1201 return pb->pb_conn_cnt;
1204 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1209 int lustre_msg_is_v1(struct lustre_msg *msg)
1211 switch (msg->lm_magic) {
1212 case LUSTRE_MSG_MAGIC_V1:
1213 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1220 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1222 switch (msg->lm_magic) {
1223 case LUSTRE_MSG_MAGIC_V2:
1224 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1225 return msg->lm_magic;
1227 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1232 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
1234 switch (msg->lm_magic) {
1235 case LUSTRE_MSG_MAGIC_V1:
1236 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1238 case LUSTRE_MSG_MAGIC_V2:
1239 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1240 struct ptlrpc_body *pb;
1242 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1244 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1248 return pb->pb_timeout;
1251 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1256 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1258 switch (msg->lm_magic) {
1259 case LUSTRE_MSG_MAGIC_V1:
1260 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1262 case LUSTRE_MSG_MAGIC_V2:
1263 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1264 struct ptlrpc_body *pb;
1266 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1268 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1272 return pb->pb_service_time;
1275 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1280 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1282 switch (msg->lm_magic) {
1283 case LUSTRE_MSG_MAGIC_V1:
1284 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1286 case LUSTRE_MSG_MAGIC_V2:
1287 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1288 return msg->lm_cksum;
1290 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1295 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1297 switch (msg->lm_magic) {
1298 case LUSTRE_MSG_MAGIC_V1:
1299 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1301 case LUSTRE_MSG_MAGIC_V2:
1302 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1303 struct ptlrpc_body *pb;
1304 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1305 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1306 return crc32_le(~(__u32)0, (unsigned char *)pb, sizeof(*pb));
1309 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1314 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1316 switch (msg->lm_magic) {
1317 case LUSTRE_MSG_MAGIC_V2: {
1318 struct ptlrpc_body *pb;
1320 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1321 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1322 pb->pb_handle = *handle;
1326 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1330 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1332 switch (msg->lm_magic) {
1333 case LUSTRE_MSG_MAGIC_V2: {
1334 struct ptlrpc_body *pb;
1336 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1337 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1342 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1346 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1348 switch (msg->lm_magic) {
1349 case LUSTRE_MSG_MAGIC_V2: {
1350 struct ptlrpc_body *pb;
1352 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1353 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1358 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1362 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1364 switch (msg->lm_magic) {
1365 case LUSTRE_MSG_MAGIC_V2: {
1366 struct ptlrpc_body *pb;
1368 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1369 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1370 pb->pb_last_xid = last_xid;
1374 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1378 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1380 switch (msg->lm_magic) {
1381 case LUSTRE_MSG_MAGIC_V2: {
1382 struct ptlrpc_body *pb;
1384 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1385 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1386 pb->pb_last_committed = last_committed;
1390 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1394 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1396 switch (msg->lm_magic) {
1397 case LUSTRE_MSG_MAGIC_V2: {
1398 struct ptlrpc_body *pb;
1400 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1401 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1402 pb->pb_transno = transno;
1406 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1410 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1412 switch (msg->lm_magic) {
1413 case LUSTRE_MSG_MAGIC_V2: {
1414 struct ptlrpc_body *pb;
1416 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1417 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1418 pb->pb_status = status;
1422 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1426 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1428 switch (msg->lm_magic) {
1429 case LUSTRE_MSG_MAGIC_V2: {
1430 struct ptlrpc_body *pb;
1432 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1433 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1434 pb->pb_conn_cnt = conn_cnt;
1438 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1442 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1444 switch (msg->lm_magic) {
1445 case LUSTRE_MSG_MAGIC_V1:
1447 case LUSTRE_MSG_MAGIC_V2: {
1448 struct ptlrpc_body *pb;
1450 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1451 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1452 pb->pb_timeout = timeout;
1456 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1460 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1462 switch (msg->lm_magic) {
1463 case LUSTRE_MSG_MAGIC_V1:
1465 case LUSTRE_MSG_MAGIC_V2: {
1466 struct ptlrpc_body *pb;
1468 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1469 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1470 pb->pb_service_time = service_time;
1474 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1478 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1480 switch (msg->lm_magic) {
1481 case LUSTRE_MSG_MAGIC_V1:
1483 case LUSTRE_MSG_MAGIC_V2:
1484 msg->lm_cksum = cksum;
1487 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1492 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1494 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1496 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1497 req->rq_pill.rc_area[RCL_SERVER]);
1498 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1499 req->rq_reqmsg->lm_repsize = req->rq_replen;
1502 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
1504 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1505 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1506 req->rq_reqmsg->lm_repsize = req->rq_replen;
1509 /* byte flipping routines for all wire types declared in
1510 * lustre_idl.h implemented here.
1512 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1514 __swab32s (&b->pb_type);
1515 __swab32s (&b->pb_version);
1516 __swab32s (&b->pb_opc);
1517 __swab32s (&b->pb_status);
1518 __swab64s (&b->pb_last_xid);
1519 __swab64s (&b->pb_last_seen);
1520 __swab64s (&b->pb_last_committed);
1521 __swab64s (&b->pb_transno);
1522 __swab32s (&b->pb_flags);
1523 __swab32s (&b->pb_op_flags);
1524 __swab32s (&b->pb_conn_cnt);
1525 __swab32s (&b->pb_timeout);
1526 __swab32s (&b->pb_service_time);
1527 __swab32s (&b->pb_limit);
1528 __swab64s (&b->pb_slv);
1529 __swab64s (&b->pb_pre_versions[0]);
1530 __swab64s (&b->pb_pre_versions[1]);
1531 __swab64s (&b->pb_pre_versions[2]);
1532 __swab64s (&b->pb_pre_versions[3]);
1533 CLASSERT(offsetof(typeof(*b), pb_padding) != 0);
1536 void lustre_swab_connect(struct obd_connect_data *ocd)
1538 __swab64s(&ocd->ocd_connect_flags);
1539 __swab32s(&ocd->ocd_version);
1540 __swab32s(&ocd->ocd_grant);
1541 __swab64s(&ocd->ocd_ibits_known);
1542 __swab32s(&ocd->ocd_index);
1543 __swab32s(&ocd->ocd_brw_size);
1544 __swab32s(&ocd->ocd_nllu);
1545 __swab32s(&ocd->ocd_nllg);
1546 __swab64s(&ocd->ocd_transno);
1547 __swab32s(&ocd->ocd_group);
1548 __swab32s(&ocd->ocd_cksum_types);
1549 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1550 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1553 void lustre_swab_obdo (struct obdo *o)
1555 __swab64s (&o->o_valid);
1556 __swab64s (&o->o_id);
1557 __swab64s (&o->o_gr);
1558 __swab64s (&o->o_fid);
1559 __swab64s (&o->o_size);
1560 __swab64s (&o->o_mtime);
1561 __swab64s (&o->o_atime);
1562 __swab64s (&o->o_ctime);
1563 __swab64s (&o->o_blocks);
1564 __swab64s (&o->o_grant);
1565 __swab32s (&o->o_blksize);
1566 __swab32s (&o->o_mode);
1567 __swab32s (&o->o_uid);
1568 __swab32s (&o->o_gid);
1569 __swab32s (&o->o_flags);
1570 __swab32s (&o->o_nlink);
1571 __swab32s (&o->o_generation);
1572 __swab32s (&o->o_misc);
1573 __swab32s (&o->o_easize);
1574 __swab32s (&o->o_mds);
1575 __swab32s (&o->o_stripe_idx);
1576 __swab32s (&o->o_padding_1);
1577 /* o_inline is opaque */
1580 void lustre_swab_obd_statfs (struct obd_statfs *os)
1582 __swab64s (&os->os_type);
1583 __swab64s (&os->os_blocks);
1584 __swab64s (&os->os_bfree);
1585 __swab64s (&os->os_bavail);
1586 __swab64s (&os->os_files);
1587 __swab64s (&os->os_ffree);
1588 /* no need to swab os_fsid */
1589 __swab32s (&os->os_bsize);
1590 __swab32s (&os->os_namelen);
1591 __swab64s (&os->os_maxbytes);
1592 __swab32s (&os->os_state);
1593 /* no need to swap os_spare */
1596 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1598 __swab64s (&ioo->ioo_id);
1599 __swab64s (&ioo->ioo_gr);
1600 __swab32s (&ioo->ioo_type);
1601 __swab32s (&ioo->ioo_bufcnt);
1604 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1606 __swab64s (&nbr->offset);
1607 __swab32s (&nbr->len);
1608 __swab32s (&nbr->flags);
1611 void lustre_swab_ost_body (struct ost_body *b)
1613 lustre_swab_obdo (&b->oa);
1616 void lustre_swab_ost_last_id(obd_id *id)
1621 void lustre_swab_generic_32s(__u32 *val)
1626 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1628 __swab64s(&lvb->lvb_size);
1629 __swab64s(&lvb->lvb_mtime);
1630 __swab64s(&lvb->lvb_atime);
1631 __swab64s(&lvb->lvb_ctime);
1632 __swab64s(&lvb->lvb_blocks);
1635 void lustre_swab_mds_status_req (struct mds_status_req *r)
1637 __swab32s (&r->flags);
1638 __swab32s (&r->repbuf);
1641 void lustre_swab_mds_body (struct mds_body *b)
1643 lustre_swab_ll_fid (&b->fid1);
1644 lustre_swab_ll_fid (&b->fid2);
1645 /* handle is opaque */
1646 __swab64s (&b->valid);
1647 __swab64s (&b->size);
1648 __swab64s (&b->mtime);
1649 __swab64s (&b->atime);
1650 __swab64s (&b->ctime);
1651 __swab64s (&b->blocks);
1652 __swab64s (&b->io_epoch);
1653 __swab64s (&b->ino);
1654 __swab32s (&b->fsuid);
1655 __swab32s (&b->fsgid);
1656 __swab32s (&b->capability);
1657 __swab32s (&b->mode);
1658 __swab32s (&b->uid);
1659 __swab32s (&b->gid);
1660 __swab32s (&b->flags);
1661 __swab32s (&b->rdev);
1662 __swab32s (&b->nlink);
1663 __swab32s (&b->generation);
1664 __swab32s (&b->suppgid);
1665 __swab32s (&b->eadatasize);
1666 __swab32s (&b->aclsize);
1667 __swab32s (&b->max_mdsize);
1668 __swab32s (&b->max_cookiesize);
1669 __swab32s (&b->padding_4);
1672 void lustre_swab_mdt_body (struct mdt_body *b)
1674 lustre_swab_lu_fid (&b->fid1);
1675 lustre_swab_lu_fid (&b->fid2);
1676 /* handle is opaque */
1677 __swab64s (&b->valid);
1678 __swab64s (&b->size);
1679 __swab64s (&b->mtime);
1680 __swab64s (&b->atime);
1681 __swab64s (&b->ctime);
1682 __swab64s (&b->blocks);
1683 __swab64s (&b->ioepoch);
1684 __swab64s (&b->ino);
1685 __swab32s (&b->fsuid);
1686 __swab32s (&b->fsgid);
1687 __swab32s (&b->capability);
1688 __swab32s (&b->mode);
1689 __swab32s (&b->uid);
1690 __swab32s (&b->gid);
1691 __swab32s (&b->flags);
1692 __swab32s (&b->rdev);
1693 __swab32s (&b->nlink);
1694 __swab32s (&b->generation);
1695 __swab32s (&b->suppgid);
1696 __swab32s (&b->eadatasize);
1697 __swab32s (&b->aclsize);
1698 __swab32s (&b->max_mdsize);
1699 __swab32s (&b->max_cookiesize);
1700 __swab32s (&b->padding_4);
1703 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1705 /* handle is opaque */
1706 __swab64s (&b->ioepoch);
1707 __swab32s (&b->flags);
1708 CLASSERT(offsetof(typeof(*b), padding) != 0);
1711 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1714 __swab32s(&mti->mti_lustre_ver);
1715 __swab32s(&mti->mti_stripe_index);
1716 __swab32s(&mti->mti_config_ver);
1717 __swab32s(&mti->mti_flags);
1718 __swab32s(&mti->mti_nid_count);
1719 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1720 for (i = 0; i < MTI_NIDS_MAX; i++)
1721 __swab64s(&mti->mti_nids[i]);
1724 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1726 __swab64s (&i->dqi_bgrace);
1727 __swab64s (&i->dqi_igrace);
1728 __swab32s (&i->dqi_flags);
1729 __swab32s (&i->dqi_valid);
1732 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1734 __swab64s (&b->dqb_ihardlimit);
1735 __swab64s (&b->dqb_isoftlimit);
1736 __swab64s (&b->dqb_curinodes);
1737 __swab64s (&b->dqb_bhardlimit);
1738 __swab64s (&b->dqb_bsoftlimit);
1739 __swab64s (&b->dqb_curspace);
1740 __swab64s (&b->dqb_btime);
1741 __swab64s (&b->dqb_itime);
1742 __swab32s (&b->dqb_valid);
1743 CLASSERT(offsetof(typeof(*b), padding) != 0);
1746 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1748 __swab32s (&q->qc_cmd);
1749 __swab32s (&q->qc_type);
1750 __swab32s (&q->qc_id);
1751 __swab32s (&q->qc_stat);
1752 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1753 lustre_swab_obd_dqblk (&q->qc_dqblk);
1756 void lustre_swab_quota_adjust_qunit (struct quota_adjust_qunit *q)
1758 __swab32s (&q->qaq_flags);
1759 __swab32s (&q->qaq_id);
1760 __swab64s (&q->qaq_bunit_sz);
1761 __swab64s (&q->qaq_iunit_sz);
1762 __swab64s (&q->padding1);
1765 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1767 __swab32s (&p->rp_uid);
1768 __swab32s (&p->rp_gid);
1769 __swab32s (&p->rp_fsuid);
1770 __swab32s (&p->rp_fsgid);
1771 __swab32s (&p->rp_access_perm);
1774 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1776 __swab32s (&p->rp_uid);
1777 __swab32s (&p->rp_gid);
1778 __swab32s (&p->rp_fsuid);
1779 __swab32s (&p->rp_fsgid);
1780 __swab32s (&p->rp_access_perm);
1783 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1785 __swab32s (&sa->sa_opcode);
1786 __swab32s (&sa->sa_fsuid);
1787 __swab32s (&sa->sa_fsgid);
1788 __swab32s (&sa->sa_cap);
1789 __swab32s (&sa->sa_suppgid);
1790 __swab32s (&sa->sa_mode);
1791 lustre_swab_ll_fid (&sa->sa_fid);
1792 __swab64s (&sa->sa_valid);
1793 __swab64s (&sa->sa_size);
1794 __swab64s (&sa->sa_mtime);
1795 __swab64s (&sa->sa_atime);
1796 __swab64s (&sa->sa_ctime);
1797 __swab32s (&sa->sa_uid);
1798 __swab32s (&sa->sa_gid);
1799 __swab32s (&sa->sa_attr_flags);
1800 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1803 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1805 __swab64s(&jr->jr_headsize);
1806 lustre_swab_ll_fid(&jr->jr_fid);
1809 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1811 __swab64s(&jr->jr_headsize);
1812 lustre_swab_lu_fid(&jr->jr_fid);
1815 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1817 __swab32s (&cr->cr_opcode);
1818 __swab32s (&cr->cr_fsuid);
1819 __swab32s (&cr->cr_fsgid);
1820 __swab32s (&cr->cr_cap);
1821 __swab32s (&cr->cr_flags); /* for use with open */
1822 __swab32s (&cr->cr_mode);
1823 lustre_swab_ll_fid (&cr->cr_fid);
1824 lustre_swab_ll_fid (&cr->cr_replayfid);
1825 __swab64s (&cr->cr_time);
1826 __swab64s (&cr->cr_rdev);
1827 __swab32s (&cr->cr_suppgid);
1828 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1829 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1830 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1831 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1832 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1835 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1837 __swab32s (&lk->lk_opcode);
1838 __swab32s (&lk->lk_fsuid);
1839 __swab32s (&lk->lk_fsgid);
1840 __swab32s (&lk->lk_cap);
1841 __swab32s (&lk->lk_suppgid1);
1842 __swab32s (&lk->lk_suppgid2);
1843 lustre_swab_ll_fid (&lk->lk_fid1);
1844 lustre_swab_ll_fid (&lk->lk_fid2);
1845 __swab64s (&lk->lk_time);
1846 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1847 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1848 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1849 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1852 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1854 __swab32s (&ul->ul_opcode);
1855 __swab32s (&ul->ul_fsuid);
1856 __swab32s (&ul->ul_fsgid);
1857 __swab32s (&ul->ul_cap);
1858 __swab32s (&ul->ul_suppgid);
1859 __swab32s (&ul->ul_mode);
1860 lustre_swab_ll_fid (&ul->ul_fid1);
1861 lustre_swab_ll_fid (&ul->ul_fid2);
1862 __swab64s (&ul->ul_time);
1863 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1864 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1865 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1866 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1869 void lustre_swab_fiemap_extent(struct ll_fiemap_extent *fm_extent)
1871 __swab64s(&fm_extent->fe_logical);
1872 __swab64s(&fm_extent->fe_physical);
1873 __swab64s(&fm_extent->fe_length);
1874 __swab32s(&fm_extent->fe_flags);
1875 __swab32s(&fm_extent->fe_device);
1878 void lustre_swab_fiemap(struct ll_user_fiemap *fiemap)
1882 __swab64s(&fiemap->fm_start);
1883 __swab64s(&fiemap->fm_length);
1884 __swab32s(&fiemap->fm_flags);
1885 __swab32s(&fiemap->fm_mapped_extents);
1886 __swab32s(&fiemap->fm_extent_count);
1887 __swab32s(&fiemap->fm_reserved);
1889 for (i = 0; i < fiemap->fm_mapped_extents; i++)
1890 lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
1893 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1895 __swab32s (&rn->rn_opcode);
1896 __swab32s (&rn->rn_fsuid);
1897 __swab32s (&rn->rn_fsgid);
1898 __swab32s (&rn->rn_cap);
1899 __swab32s (&rn->rn_suppgid1);
1900 __swab32s (&rn->rn_suppgid2);
1901 lustre_swab_ll_fid (&rn->rn_fid1);
1902 lustre_swab_ll_fid (&rn->rn_fid2);
1903 __swab64s (&rn->rn_time);
1904 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1905 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1906 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1907 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1910 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
1912 __swab32s (&rr->rr_opcode);
1913 __swab32s (&rr->rr_cap);
1914 __swab32s (&rr->rr_fsuid);
1915 /* rr_fsuid_h is unused */
1916 __swab32s (&rr->rr_fsgid);
1917 /* rr_fsgid_h is unused */
1918 __swab32s (&rr->rr_suppgid1);
1919 /* rr_suppgid1_h is unused */
1920 __swab32s (&rr->rr_suppgid2);
1921 /* rr_suppgid2_h is unused */
1922 lustre_swab_lu_fid (&rr->rr_fid1);
1923 lustre_swab_lu_fid (&rr->rr_fid2);
1924 __swab64s (&rr->rr_mtime);
1925 __swab64s (&rr->rr_atime);
1926 __swab64s (&rr->rr_ctime);
1927 __swab64s (&rr->rr_size);
1928 __swab64s (&rr->rr_blocks);
1929 __swab32s (&rr->rr_bias);
1930 __swab32s (&rr->rr_mode);
1931 __swab32s (&rr->rr_padding_1);
1932 __swab32s (&rr->rr_padding_2);
1933 __swab32s (&rr->rr_padding_3);
1934 __swab32s (&rr->rr_padding_4);
1936 CLASSERT(offsetof(typeof(*rr), rr_padding_1) != 0);
1937 CLASSERT(offsetof(typeof(*rr), rr_padding_2) != 0);
1938 CLASSERT(offsetof(typeof(*rr), rr_padding_3) != 0);
1939 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
1942 void lustre_swab_lov_desc (struct lov_desc *ld)
1944 __swab32s (&ld->ld_tgt_count);
1945 __swab32s (&ld->ld_active_tgt_count);
1946 __swab32s (&ld->ld_default_stripe_count);
1947 __swab32s (&ld->ld_pattern);
1948 __swab64s (&ld->ld_default_stripe_size);
1949 __swab64s (&ld->ld_default_stripe_offset);
1950 __swab32s (&ld->ld_qos_maxage);
1951 /* uuid endian insensitive */
1954 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1956 __swab32s (&ld->ld_tgt_count);
1957 __swab32s (&ld->ld_active_tgt_count);
1958 __swab32s (&ld->ld_default_stripe_count);
1959 __swab32s (&ld->ld_pattern);
1960 __swab64s (&ld->ld_default_hash_size);
1961 __swab32s (&ld->ld_qos_maxage);
1962 /* uuid endian insensitive */
1965 void lustre_swab_lmv_stripe_md (struct lmv_stripe_md *mea)
1967 __swab32s(&mea->mea_magic);
1968 __swab32s(&mea->mea_count);
1969 __swab32s(&mea->mea_master);
1970 CLASSERT(offsetof(typeof(*mea), mea_padding) != 0);
1974 static void print_lum (struct lov_user_md *lum)
1976 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1977 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1978 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1979 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1980 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
1981 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1982 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1983 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1986 static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
1989 __swab32s(&lum->lmm_magic);
1990 __swab32s(&lum->lmm_pattern);
1991 __swab64s(&lum->lmm_object_id);
1992 __swab64s(&lum->lmm_object_gr);
1993 __swab32s(&lum->lmm_stripe_size);
1994 __swab16s(&lum->lmm_stripe_count);
1995 __swab16s(&lum->lmm_stripe_offset);
2000 static void print_lumj (struct lov_user_md_join *lumj)
2002 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2003 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2004 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2005 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2006 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2007 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2008 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2009 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2012 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
2015 CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
2016 lustre_swab_lov_user_md_common(lum);
2020 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum)
2023 CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
2024 lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
2025 /* lmm_pool_name nothing to do with char */
2029 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2032 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2033 __swab32s(&lumj->lmm_magic);
2034 __swab32s(&lumj->lmm_pattern);
2035 __swab64s(&lumj->lmm_object_id);
2036 __swab64s(&lumj->lmm_object_gr);
2037 __swab32s(&lumj->lmm_stripe_size);
2038 __swab32s(&lumj->lmm_stripe_count);
2039 __swab32s(&lumj->lmm_extent_count);
2044 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
2049 for (i = 0; i < stripe_count; i++) {
2050 __swab64s(&(lod[i].l_object_id));
2051 __swab64s(&(lod[i].l_object_gr));
2052 __swab32s(&(lod[i].l_ost_gen));
2053 __swab32s(&(lod[i].l_ost_idx));
2059 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2063 for (i = 0; i < RES_NAME_SIZE; i++)
2064 __swab64s (&id->name[i]);
2067 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2069 /* the lock data is a union and the first two fields are always an
2070 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2071 * data the same way. */
2072 __swab64s(&d->l_extent.start);
2073 __swab64s(&d->l_extent.end);
2074 __swab64s(&d->l_extent.gid);
2075 __swab32s(&d->l_flock.pid);
2078 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2080 __swab64s (&i->opc);
2083 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2085 __swab32s (&r->lr_type);
2086 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2087 lustre_swab_ldlm_res_id (&r->lr_name);
2090 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2092 lustre_swab_ldlm_resource_desc (&l->l_resource);
2093 __swab32s (&l->l_req_mode);
2094 __swab32s (&l->l_granted_mode);
2095 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2098 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2100 __swab32s (&rq->lock_flags);
2101 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2102 __swab32s (&rq->lock_count);
2103 /* lock_handle[] opaque */
2106 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2108 __swab32s (&r->lock_flags);
2109 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2110 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2111 /* lock_handle opaque */
2112 __swab64s (&r->lock_policy_res1);
2113 __swab64s (&r->lock_policy_res2);
2116 /* no one calls this */
2117 int llog_log_swabbed(struct llog_log_hdr *hdr)
2119 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2121 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2126 void lustre_swab_qdata(struct qunit_data *d)
2128 __swab32s (&d->qd_id);
2129 __swab32s (&d->qd_flags);
2130 __swab64s (&d->qd_count);
2131 __swab64s (&d->qd_qunit);
2132 __swab64s (&d->padding);
2138 * got qdata from request(req/rep)
2140 int quota_get_qdata(void *request, struct qunit_data *qdata,
2141 int is_req, int is_exp)
2143 struct ptlrpc_request *req = (struct ptlrpc_request *)request;
2144 struct qunit_data *new;
2145 __u64 flags = is_exp ? req->rq_export->exp_connect_flags :
2146 req->rq_import->imp_connect_data.ocd_connect_flags;
2152 /* support for quota64 and change_qs */
2153 if (flags & OBD_CONNECT_CHANGE_QS) {
2154 if (!(flags & OBD_CONNECT_QUOTA64)) {
2155 CDEBUG(D_ERROR, "Wire protocol for qunit is broken!\n");
2158 if (is_req == QUOTA_REQUEST)
2159 new = lustre_swab_reqbuf(req, REQ_REC_OFF,
2160 sizeof(struct qunit_data),
2163 new = lustre_swab_repbuf(req, REPLY_REC_OFF,
2164 sizeof(struct qunit_data),
2167 GOTO(out, rc = -EPROTO);
2169 QDATA_SET_CHANGE_QS(qdata);
2172 QDATA_CLR_CHANGE_QS(qdata);
2178 EXPORT_SYMBOL(quota_get_qdata);
2181 * copy qdata to request(req/rep)
2183 int quota_copy_qdata(void *request, struct qunit_data *qdata,
2184 int is_req, int is_exp)
2186 struct ptlrpc_request *req = (struct ptlrpc_request *)request;
2188 __u64 flags = is_exp ? req->rq_export->exp_connect_flags :
2189 req->rq_import->imp_connect_data.ocd_connect_flags;
2195 /* support for quota64 and change_qs */
2196 if (flags & OBD_CONNECT_CHANGE_QS) {
2197 if (!(flags & OBD_CONNECT_QUOTA64)) {
2198 CERROR("Wire protocol for qunit is broken!\n");
2201 if (is_req == QUOTA_REQUEST)
2202 target = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF,
2203 sizeof(struct qunit_data));
2205 target = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
2206 sizeof(struct qunit_data));
2208 GOTO(out, rc = -EPROTO);
2209 memcpy(target, qdata, sizeof(*qdata));
2216 EXPORT_SYMBOL(quota_copy_qdata);
2217 #endif /* __KERNEL__ */
2219 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2221 LASSERT(req->rq_reqmsg);
2223 switch (req->rq_reqmsg->lm_magic) {
2224 case LUSTRE_MSG_MAGIC_V2:
2225 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2226 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2228 CERROR("bad lustre msg magic: %#08X\n",
2229 req->rq_reqmsg->lm_magic);
2234 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2236 LASSERT(req->rq_repmsg);
2238 switch (req->rq_repmsg->lm_magic) {
2239 case LUSTRE_MSG_MAGIC_V2:
2240 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2241 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2243 /* uninitialized yet */
2248 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2249 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2253 va_start(args, fmt);
2254 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2255 data->msg_fn, data->msg_line, fmt, args,
2256 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d/%d"
2257 " lens %d/%d e %d to %d dl "CFS_TIME_T" ref %d "
2258 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2259 req, req->rq_xid, req->rq_transno,
2260 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2261 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2262 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2264 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2266 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2268 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2269 req->rq_request_portal, req->rq_reply_portal,
2270 req->rq_reqlen, req->rq_replen,
2271 req->rq_early_count, !!req->rq_timeout, req->rq_deadline,
2272 atomic_read(&req->rq_refcount), DEBUG_REQ_FLAGS(req),
2273 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2274 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2275 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2276 lustre_msg_get_flags(req->rq_repmsg) : -1,
2278 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2279 lustre_msg_get_status(req->rq_repmsg) : -1);
2281 EXPORT_SYMBOL(_debug_req);
2283 void lustre_swab_lustre_capa(struct lustre_capa *c)
2285 lustre_swab_lu_fid(&c->lc_fid);
2286 __swab64s (&c->lc_opc);
2287 __swab64s (&c->lc_uid);
2288 __swab64s (&c->lc_gid);
2289 __swab32s (&c->lc_flags);
2290 __swab32s (&c->lc_keyid);
2291 __swab32s (&c->lc_timeout);
2292 __swab32s (&c->lc_expiry);
2295 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2297 __swab64s (&k->lk_mdsid);
2298 __swab32s (&k->lk_keyid);
2299 __swab32s (&k->lk_padding);