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 (c) 2002, 2010, Oracle and/or its affiliates. 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 cfs_size_round(offsetof(struct lustre_msg_v2,
64 int lustre_msg_hdr_size(__u32 magic, int count)
67 case LUSTRE_MSG_MAGIC_V2:
68 return lustre_msg_hdr_size_v2(count);
70 LASSERTF(0, "incorrect message magic: %08x\n", magic);
74 EXPORT_SYMBOL(lustre_msg_hdr_size);
76 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
80 lustre_set_req_swabbed(req, index);
82 lustre_set_rep_swabbed(req, index);
85 int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
89 return (ptlrpc_req_need_swab(req) &&
90 !lustre_req_swabbed(req, index));
92 return (ptlrpc_rep_need_swab(req) &&
93 !lustre_rep_swabbed(req, index));
96 static inline int lustre_msg_check_version_v2(struct lustre_msg_v2 *msg,
99 __u32 ver = lustre_msg_get_version(msg);
100 return (ver & LUSTRE_VERSION_MASK) != version;
103 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
105 switch (msg->lm_magic) {
106 case LUSTRE_MSG_MAGIC_V1:
107 CERROR("msg v1 not supported - please upgrade you system\n");
109 case LUSTRE_MSG_MAGIC_V2:
110 return lustre_msg_check_version_v2(msg, version);
112 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
117 /* early reply size */
118 int lustre_msg_early_size()
122 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
125 EXPORT_SYMBOL(lustre_msg_early_size);
127 int lustre_msg_size_v2(int count, __u32 *lengths)
132 size = lustre_msg_hdr_size_v2(count);
133 for (i = 0; i < count; i++)
134 size += cfs_size_round(lengths[i]);
138 EXPORT_SYMBOL(lustre_msg_size_v2);
140 /* This returns the size of the buffer that is required to hold a lustre_msg
141 * with the given sub-buffer lengths.
142 * NOTE: this should only be used for NEW requests, and should always be
143 * in the form of a v2 request. If this is a connection to a v1
144 * target then the first buffer will be stripped because the ptlrpc
145 * data is part of the lustre_msg_v1 header. b=14043 */
146 int lustre_msg_size(__u32 magic, int count, __u32 *lens)
148 __u32 size[] = { sizeof(struct ptlrpc_body) };
156 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
159 case LUSTRE_MSG_MAGIC_V2:
160 return lustre_msg_size_v2(count, lens);
162 LASSERTF(0, "incorrect message magic: %08x\n", magic);
167 /* This is used to determine the size of a buffer that was already packed
168 * and will correctly handle the different message formats. */
169 int lustre_packed_msg_size(struct lustre_msg *msg)
171 switch (msg->lm_magic) {
172 case LUSTRE_MSG_MAGIC_V2:
173 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
175 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
180 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
186 msg->lm_bufcount = count;
187 /* XXX: lm_secflvr uninitialized here */
188 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
190 for (i = 0; i < count; i++)
191 msg->lm_buflens[i] = lens[i];
196 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
197 for (i = 0; i < count; i++) {
199 LOGL(tmp, lens[i], ptr);
202 EXPORT_SYMBOL(lustre_init_msg_v2);
204 static int lustre_pack_request_v2(struct ptlrpc_request *req,
205 int count, __u32 *lens, char **bufs)
209 reqlen = lustre_msg_size_v2(count, lens);
211 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
215 req->rq_reqlen = reqlen;
217 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
218 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
222 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
223 __u32 *lens, char **bufs)
225 __u32 size[] = { sizeof(struct ptlrpc_body) };
233 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
235 /* only use new format, we don't need to be compatible with 1.4 */
236 magic = LUSTRE_MSG_MAGIC_V2;
239 case LUSTRE_MSG_MAGIC_V2:
240 return lustre_pack_request_v2(req, count, lens, bufs);
242 LASSERTF(0, "incorrect message magic: %08x\n", magic);
248 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
249 cfs_spinlock_t ptlrpc_rs_debug_lock;
251 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
253 cfs_spin_lock(&ptlrpc_rs_debug_lock); \
254 cfs_list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
255 cfs_spin_unlock(&ptlrpc_rs_debug_lock); \
258 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
260 cfs_spin_lock(&ptlrpc_rs_debug_lock); \
261 cfs_list_del(&(rs)->rs_debug_list); \
262 cfs_spin_unlock(&ptlrpc_rs_debug_lock); \
265 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
266 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
269 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
271 struct ptlrpc_reply_state *rs = NULL;
273 cfs_spin_lock(&svc->srv_lock);
274 /* See if we have anything in a pool, and wait if nothing */
275 while (cfs_list_empty(&svc->srv_free_rs_list)) {
276 struct l_wait_info lwi;
278 cfs_spin_unlock(&svc->srv_lock);
279 /* If we cannot get anything for some long time, we better
280 bail out instead of waiting infinitely */
281 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
282 rc = l_wait_event(svc->srv_free_rs_waitq,
283 !cfs_list_empty(&svc->srv_free_rs_list),
287 cfs_spin_lock(&svc->srv_lock);
290 rs = cfs_list_entry(svc->srv_free_rs_list.next,
291 struct ptlrpc_reply_state, rs_list);
292 cfs_list_del(&rs->rs_list);
293 cfs_spin_unlock(&svc->srv_lock);
295 memset(rs, 0, svc->srv_max_reply_size);
296 rs->rs_service = svc;
302 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
304 struct ptlrpc_service *svc = rs->rs_service;
308 cfs_spin_lock(&svc->srv_lock);
309 cfs_list_add(&rs->rs_list, &svc->srv_free_rs_list);
310 cfs_spin_unlock(&svc->srv_lock);
311 cfs_waitq_signal(&svc->srv_free_rs_waitq);
314 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
315 __u32 *lens, char **bufs, int flags)
317 struct ptlrpc_reply_state *rs;
321 LASSERT(req->rq_reply_state == NULL);
323 if ((flags & LPRFL_EARLY_REPLY) == 0) {
324 cfs_spin_lock(&req->rq_lock);
325 req->rq_packed_final = 1;
326 cfs_spin_unlock(&req->rq_lock);
329 msg_len = lustre_msg_size_v2(count, lens);
330 rc = sptlrpc_svc_alloc_rs(req, msg_len);
334 rs = req->rq_reply_state;
335 cfs_atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
336 rs->rs_cb_id.cbid_fn = reply_out_callback;
337 rs->rs_cb_id.cbid_arg = rs;
338 rs->rs_service = req->rq_rqbd->rqbd_service;
339 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
340 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
341 CFS_INIT_LIST_HEAD(&rs->rs_list);
342 cfs_spin_lock_init(&rs->rs_lock);
344 req->rq_replen = msg_len;
345 req->rq_reply_state = rs;
346 req->rq_repmsg = rs->rs_msg;
348 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
349 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
351 PTLRPC_RS_DEBUG_LRU_ADD(rs);
355 EXPORT_SYMBOL(lustre_pack_reply_v2);
357 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
358 char **bufs, int flags)
361 __u32 size[] = { sizeof(struct ptlrpc_body) };
369 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
371 switch (req->rq_reqmsg->lm_magic) {
372 case LUSTRE_MSG_MAGIC_V2:
373 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
376 LASSERTF(0, "incorrect message magic: %08x\n",
377 req->rq_reqmsg->lm_magic);
381 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
382 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
386 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
389 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
392 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
394 int i, offset, buflen, bufcount;
399 bufcount = m->lm_bufcount;
400 if (unlikely(n >= bufcount)) {
401 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
406 buflen = m->lm_buflens[n];
407 if (unlikely(buflen < min_size)) {
408 CERROR("msg %p buffer[%d] size %d too small "
409 "(required %d, opc=%d)\n", m, n, buflen, min_size,
410 n == MSG_PTLRPC_BODY_OFF ? -1 : lustre_msg_get_opc(m));
414 offset = lustre_msg_hdr_size_v2(bufcount);
415 for (i = 0; i < n; i++)
416 offset += cfs_size_round(m->lm_buflens[i]);
418 return (char *)m + offset;
421 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
423 switch (m->lm_magic) {
424 case LUSTRE_MSG_MAGIC_V2:
425 return lustre_msg_buf_v2(m, n, min_size);
427 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
432 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
433 unsigned int newlen, int move_data)
435 char *tail = NULL, *newpos;
439 LASSERT(msg->lm_bufcount > segment);
440 LASSERT(msg->lm_buflens[segment] >= newlen);
442 if (msg->lm_buflens[segment] == newlen)
445 if (move_data && msg->lm_bufcount > segment + 1) {
446 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
447 for (n = segment + 1; n < msg->lm_bufcount; n++)
448 tail_len += cfs_size_round(msg->lm_buflens[n]);
451 msg->lm_buflens[segment] = newlen;
453 if (tail && tail_len) {
454 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
455 LASSERT(newpos <= tail);
457 memmove(newpos, tail, tail_len);
460 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
464 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
465 * we also move data forward from @segment + 1.
467 * if @newlen == 0, we remove the segment completely, but we still keep the
468 * totally bufcount the same to save possible data moving. this will leave a
469 * unused segment with size 0 at the tail, but that's ok.
471 * return new msg size after shrinking.
474 * + if any buffers higher than @segment has been filled in, must call shrink
475 * with non-zero @move_data.
476 * + caller should NOT keep pointers to msg buffers which higher than @segment
479 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
480 unsigned int newlen, int move_data)
482 switch (msg->lm_magic) {
483 case LUSTRE_MSG_MAGIC_V2:
484 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
486 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
490 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
492 PTLRPC_RS_DEBUG_LRU_DEL(rs);
494 LASSERT (cfs_atomic_read(&rs->rs_refcount) == 0);
495 LASSERT (!rs->rs_difficult || rs->rs_handled);
496 LASSERT (!rs->rs_on_net);
497 LASSERT (!rs->rs_scheduled);
498 LASSERT (rs->rs_export == NULL);
499 LASSERT (rs->rs_nlocks == 0);
500 LASSERT (cfs_list_empty(&rs->rs_exp_list));
501 LASSERT (cfs_list_empty(&rs->rs_obd_list));
503 sptlrpc_svc_free_rs(rs);
506 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
508 int swabbed, required_len, i;
510 /* Now we know the sender speaks my language. */
511 required_len = lustre_msg_hdr_size_v2(0);
512 if (len < required_len) {
513 /* can't even look inside the message */
514 CERROR("message length %d too small for lustre_msg\n", len);
518 swabbed = (m->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
521 __swab32s(&m->lm_magic);
522 __swab32s(&m->lm_bufcount);
523 __swab32s(&m->lm_secflvr);
524 __swab32s(&m->lm_repsize);
525 __swab32s(&m->lm_cksum);
526 __swab32s(&m->lm_flags);
527 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
528 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
531 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
532 if (len < required_len) {
533 /* didn't receive all the buffer lengths */
534 CERROR ("message length %d too small for %d buflens\n",
535 len, m->lm_bufcount);
539 for (i = 0; i < m->lm_bufcount; i++) {
541 __swab32s(&m->lm_buflens[i]);
542 required_len += cfs_size_round(m->lm_buflens[i]);
545 if (len < required_len) {
546 CERROR("len: %d, required_len %d\n", len, required_len);
547 CERROR("bufcount: %d\n", m->lm_bufcount);
548 for (i = 0; i < m->lm_bufcount; i++)
549 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
556 int __lustre_unpack_msg(struct lustre_msg *m, int len)
558 int required_len, rc;
561 /* We can provide a slightly better error log, if we check the
562 * message magic and version first. In the future, struct
563 * lustre_msg may grow, and we'd like to log a version mismatch,
564 * rather than a short message.
567 required_len = offsetof(struct lustre_msg, lm_magic) +
569 if (len < required_len) {
570 /* can't even look inside the message */
571 CERROR("message length %d too small for magic/version check\n",
576 rc = lustre_unpack_msg_v2(m, len);
580 EXPORT_SYMBOL(__lustre_unpack_msg);
582 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len)
585 rc = __lustre_unpack_msg(req->rq_reqmsg, len);
587 lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
593 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len)
596 rc = __lustre_unpack_msg(req->rq_repmsg, len);
598 lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
604 static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
605 const int inout, int offset)
607 struct ptlrpc_body *pb;
608 struct lustre_msg_v2 *m = inout ? req->rq_reqmsg : req->rq_repmsg;
610 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
612 CERROR("error unpacking ptlrpc body\n");
615 if (ptlrpc_buf_need_swab(req, inout, offset)) {
616 lustre_swab_ptlrpc_body(pb);
617 ptlrpc_buf_set_swabbed(req, inout, offset);
620 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
621 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
628 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
630 switch (req->rq_reqmsg->lm_magic) {
631 case LUSTRE_MSG_MAGIC_V2:
632 return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
634 CERROR("bad lustre msg magic: %08x\n",
635 req->rq_reqmsg->lm_magic);
640 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
642 switch (req->rq_repmsg->lm_magic) {
643 case LUSTRE_MSG_MAGIC_V2:
644 return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
646 CERROR("bad lustre msg magic: %08x\n",
647 req->rq_repmsg->lm_magic);
652 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
654 if (n >= m->lm_bufcount)
657 return m->lm_buflens[n];
661 * lustre_msg_buflen - return the length of buffer \a n in message \a m
662 * \param m lustre_msg (request or reply) to look at
663 * \param n message index (base 0)
665 * returns zero for non-existent message indices
667 int lustre_msg_buflen(struct lustre_msg *m, int n)
669 switch (m->lm_magic) {
670 case LUSTRE_MSG_MAGIC_V2:
671 return lustre_msg_buflen_v2(m, n);
673 CERROR("incorrect message magic: %08x\n", m->lm_magic);
677 EXPORT_SYMBOL(lustre_msg_buflen);
680 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
682 if (n >= m->lm_bufcount)
685 m->lm_buflens[n] = len;
688 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
690 switch (m->lm_magic) {
691 case LUSTRE_MSG_MAGIC_V2:
692 lustre_msg_set_buflen_v2(m, n, len);
695 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
699 EXPORT_SYMBOL(lustre_msg_set_buflen);
701 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
702 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
703 int lustre_msg_bufcount(struct lustre_msg *m)
705 switch (m->lm_magic) {
706 case LUSTRE_MSG_MAGIC_V2:
707 return m->lm_bufcount;
709 CERROR("incorrect message magic: %08x\n", m->lm_magic);
713 EXPORT_SYMBOL(lustre_msg_bufcount);
715 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
717 /* max_len == 0 means the string should fill the buffer */
721 switch (m->lm_magic) {
722 case LUSTRE_MSG_MAGIC_V2:
723 str = lustre_msg_buf_v2(m, index, 0);
724 blen = lustre_msg_buflen_v2(m, index);
727 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
731 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
735 slen = strnlen(str, blen);
737 if (slen == blen) { /* not NULL terminated */
738 CERROR("can't unpack non-NULL terminated string in "
739 "msg %p buffer[%d] len %d\n", m, index, blen);
744 if (slen != blen - 1) {
745 CERROR("can't unpack short string in msg %p "
746 "buffer[%d] len %d: strlen %d\n",
747 m, index, blen, slen);
750 } else if (slen > max_len) {
751 CERROR("can't unpack oversized string in msg %p "
752 "buffer[%d] len %d strlen %d: max %d expected\n",
753 m, index, blen, slen, max_len);
760 /* Wrap up the normal fixed length cases */
761 static inline void *__lustre_swab_buf(struct lustre_msg *msg, int index,
762 int min_size, void *swabber)
766 LASSERT(msg != NULL);
767 switch (msg->lm_magic) {
768 case LUSTRE_MSG_MAGIC_V2:
769 ptr = lustre_msg_buf_v2(msg, index, min_size);
772 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
776 ((void (*)(void *))swabber)(ptr);
781 static inline struct ptlrpc_body *lustre_msg_ptlrpc_body(struct lustre_msg *msg)
783 return lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
784 sizeof(struct ptlrpc_body));
787 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
789 switch (msg->lm_magic) {
790 case LUSTRE_MSG_MAGIC_V1:
791 case LUSTRE_MSG_MAGIC_V1_SWABBED:
793 case LUSTRE_MSG_MAGIC_V2:
794 /* already in host endian */
795 return msg->lm_flags;
797 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
801 EXPORT_SYMBOL(lustre_msghdr_get_flags);
803 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
805 switch (msg->lm_magic) {
806 case LUSTRE_MSG_MAGIC_V1:
808 case LUSTRE_MSG_MAGIC_V2:
809 msg->lm_flags = flags;
812 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
816 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
818 switch (msg->lm_magic) {
819 case LUSTRE_MSG_MAGIC_V2: {
820 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
822 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
828 /* flags might be printed in debug code while message
834 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
836 switch (msg->lm_magic) {
837 case LUSTRE_MSG_MAGIC_V2: {
838 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
839 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
840 pb->pb_flags |= flags;
844 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
848 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
850 switch (msg->lm_magic) {
851 case LUSTRE_MSG_MAGIC_V2: {
852 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
853 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
854 pb->pb_flags = flags;
858 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
862 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
864 switch (msg->lm_magic) {
865 case LUSTRE_MSG_MAGIC_V2: {
866 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
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 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
882 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
885 return pb->pb_op_flags;
892 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
894 switch (msg->lm_magic) {
895 case LUSTRE_MSG_MAGIC_V2: {
896 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
897 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
898 pb->pb_op_flags |= flags;
902 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
906 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
908 switch (msg->lm_magic) {
909 case LUSTRE_MSG_MAGIC_V2: {
910 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
911 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
912 pb->pb_op_flags |= flags;
916 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
920 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
922 switch (msg->lm_magic) {
923 case LUSTRE_MSG_MAGIC_V2: {
924 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
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 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
943 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
944 return PTL_RPC_MSG_ERR;
949 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
950 return PTL_RPC_MSG_ERR;
954 __u32 lustre_msg_get_version(struct lustre_msg *msg)
956 switch (msg->lm_magic) {
957 case LUSTRE_MSG_MAGIC_V2: {
958 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
960 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
963 return pb->pb_version;
966 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
971 void lustre_msg_add_version(struct lustre_msg *msg, int version)
973 switch (msg->lm_magic) {
974 case LUSTRE_MSG_MAGIC_V2: {
975 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
976 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
977 pb->pb_version |= version;
981 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
985 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
987 switch (msg->lm_magic) {
988 case LUSTRE_MSG_MAGIC_V2: {
989 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
991 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
997 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1003 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1005 switch (msg->lm_magic) {
1006 case LUSTRE_MSG_MAGIC_V2: {
1007 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1009 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1012 return pb->pb_last_xid;
1015 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1020 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1022 switch (msg->lm_magic) {
1023 case LUSTRE_MSG_MAGIC_V2: {
1024 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1026 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1029 return pb->pb_last_committed;
1032 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1037 __u64 *lustre_msg_get_versions(struct lustre_msg *msg)
1039 switch (msg->lm_magic) {
1040 case LUSTRE_MSG_MAGIC_V1:
1042 case LUSTRE_MSG_MAGIC_V2: {
1043 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1045 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1048 return pb->pb_pre_versions;
1051 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1056 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1058 switch (msg->lm_magic) {
1059 case LUSTRE_MSG_MAGIC_V2: {
1060 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1062 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1065 return pb->pb_transno;
1068 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1073 int lustre_msg_get_status(struct lustre_msg *msg)
1075 switch (msg->lm_magic) {
1076 case LUSTRE_MSG_MAGIC_V2: {
1077 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1079 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1082 return pb->pb_status;
1085 /* status might be printed in debug code while message
1091 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1093 switch (msg->lm_magic) {
1094 case LUSTRE_MSG_MAGIC_V2: {
1095 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1097 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1103 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1109 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1111 switch (msg->lm_magic) {
1112 case LUSTRE_MSG_MAGIC_V2: {
1113 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1115 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1122 CERROR("invalid msg magic %x\n", msg->lm_magic);
1127 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1129 switch (msg->lm_magic) {
1130 case LUSTRE_MSG_MAGIC_V2: {
1131 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1133 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1136 return pb->pb_limit;
1139 CERROR("invalid msg magic %x\n", msg->lm_magic);
1145 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1147 switch (msg->lm_magic) {
1148 case LUSTRE_MSG_MAGIC_V2: {
1149 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1151 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1154 pb->pb_limit = limit;
1158 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1163 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1165 switch (msg->lm_magic) {
1166 case LUSTRE_MSG_MAGIC_V2: {
1167 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1169 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1172 return pb->pb_conn_cnt;
1175 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1180 int lustre_msg_is_v1(struct lustre_msg *msg)
1182 switch (msg->lm_magic) {
1183 case LUSTRE_MSG_MAGIC_V1:
1184 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1191 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1193 switch (msg->lm_magic) {
1194 case LUSTRE_MSG_MAGIC_V2:
1195 return msg->lm_magic;
1197 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1202 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
1204 switch (msg->lm_magic) {
1205 case LUSTRE_MSG_MAGIC_V1:
1206 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1208 case LUSTRE_MSG_MAGIC_V2: {
1209 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1211 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1215 return pb->pb_timeout;
1218 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1223 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1225 switch (msg->lm_magic) {
1226 case LUSTRE_MSG_MAGIC_V1:
1227 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1229 case LUSTRE_MSG_MAGIC_V2: {
1230 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1232 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1236 return pb->pb_service_time;
1239 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1244 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1246 switch (msg->lm_magic) {
1247 case LUSTRE_MSG_MAGIC_V2:
1248 return msg->lm_cksum;
1250 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1255 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 0, 0)
1257 * In 1.6 and 1.8 the checksum was computed only on struct ptlrpc_body as
1258 * it was in 1.6 (88 bytes, smaller than the full size in 1.8). It makes
1259 * more sense to compute the checksum on the full ptlrpc_body, regardless
1260 * of what size it is, but in order to keep interoperability with 1.8 we
1261 * can optionally also checksum only the first 88 bytes (caller decides). */
1262 # define ptlrpc_body_cksum_size_compat18 88
1264 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg, int compat18)
1266 # warning "remove checksum compatibility support for b1_8"
1267 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1270 switch (msg->lm_magic) {
1271 case LUSTRE_MSG_MAGIC_V2: {
1272 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1273 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 0, 0)
1274 __u32 len = compat18 ? ptlrpc_body_cksum_size_compat18 :
1275 lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF);
1276 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1277 return crc32_le(~(__u32)0, (unsigned char *)pb, len);
1279 # warning "remove checksum compatibility support for b1_8"
1280 return crc32_le(~(__u32)0, (unsigned char *)pb,
1281 lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF));
1285 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1290 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1292 switch (msg->lm_magic) {
1293 case LUSTRE_MSG_MAGIC_V2: {
1294 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1295 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1296 pb->pb_handle = *handle;
1300 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1304 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1306 switch (msg->lm_magic) {
1307 case LUSTRE_MSG_MAGIC_V2: {
1308 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1309 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1314 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1318 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1320 switch (msg->lm_magic) {
1321 case LUSTRE_MSG_MAGIC_V2: {
1322 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1323 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1328 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1332 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1334 switch (msg->lm_magic) {
1335 case LUSTRE_MSG_MAGIC_V2: {
1336 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1337 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1338 pb->pb_last_xid = last_xid;
1342 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1346 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1348 switch (msg->lm_magic) {
1349 case LUSTRE_MSG_MAGIC_V2: {
1350 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1351 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1352 pb->pb_last_committed = last_committed;
1356 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1360 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions)
1362 switch (msg->lm_magic) {
1363 case LUSTRE_MSG_MAGIC_V1:
1365 case LUSTRE_MSG_MAGIC_V2: {
1366 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1367 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1368 pb->pb_pre_versions[0] = versions[0];
1369 pb->pb_pre_versions[1] = versions[1];
1370 pb->pb_pre_versions[2] = versions[2];
1371 pb->pb_pre_versions[3] = versions[3];
1375 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1379 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1381 switch (msg->lm_magic) {
1382 case LUSTRE_MSG_MAGIC_V2: {
1383 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1384 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1385 pb->pb_transno = transno;
1389 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1393 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1395 switch (msg->lm_magic) {
1396 case LUSTRE_MSG_MAGIC_V2: {
1397 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1398 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1399 pb->pb_status = status;
1403 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1407 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1409 switch (msg->lm_magic) {
1410 case LUSTRE_MSG_MAGIC_V2: {
1411 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1412 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1413 pb->pb_conn_cnt = conn_cnt;
1417 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1421 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1423 switch (msg->lm_magic) {
1424 case LUSTRE_MSG_MAGIC_V1:
1426 case LUSTRE_MSG_MAGIC_V2: {
1427 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1428 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1429 pb->pb_timeout = timeout;
1433 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1437 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1439 switch (msg->lm_magic) {
1440 case LUSTRE_MSG_MAGIC_V1:
1442 case LUSTRE_MSG_MAGIC_V2: {
1443 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1444 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1445 pb->pb_service_time = service_time;
1449 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1453 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1455 switch (msg->lm_magic) {
1456 case LUSTRE_MSG_MAGIC_V1:
1458 case LUSTRE_MSG_MAGIC_V2:
1459 msg->lm_cksum = cksum;
1462 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1467 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1469 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1471 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1472 req->rq_pill.rc_area[RCL_SERVER]);
1473 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1474 req->rq_reqmsg->lm_repsize = req->rq_replen;
1477 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
1479 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1480 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1481 req->rq_reqmsg->lm_repsize = req->rq_replen;
1485 * Send a remote set_info_async.
1487 * This may go from client to server or server to client.
1489 int do_set_info_async(struct obd_import *imp,
1490 int opcode, int version,
1491 obd_count keylen, void *key,
1492 obd_count vallen, void *val,
1493 struct ptlrpc_request_set *set)
1495 struct ptlrpc_request *req;
1500 req = ptlrpc_request_alloc(imp, &RQF_OBD_SET_INFO);
1504 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1505 RCL_CLIENT, keylen);
1506 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1507 RCL_CLIENT, vallen);
1508 rc = ptlrpc_request_pack(req, version, opcode);
1510 ptlrpc_request_free(req);
1514 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1515 memcpy(tmp, key, keylen);
1516 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1517 memcpy(tmp, val, vallen);
1519 ptlrpc_request_set_replen(req);
1522 ptlrpc_set_add_req(set, req);
1523 ptlrpc_check_set(NULL, set);
1525 rc = ptlrpc_queue_wait(req);
1526 ptlrpc_req_finished(req);
1531 EXPORT_SYMBOL(do_set_info_async);
1533 /* byte flipping routines for all wire types declared in
1534 * lustre_idl.h implemented here.
1536 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1538 __swab32s (&b->pb_type);
1539 __swab32s (&b->pb_version);
1540 __swab32s (&b->pb_opc);
1541 __swab32s (&b->pb_status);
1542 __swab64s (&b->pb_last_xid);
1543 __swab64s (&b->pb_last_seen);
1544 __swab64s (&b->pb_last_committed);
1545 __swab64s (&b->pb_transno);
1546 __swab32s (&b->pb_flags);
1547 __swab32s (&b->pb_op_flags);
1548 __swab32s (&b->pb_conn_cnt);
1549 __swab32s (&b->pb_timeout);
1550 __swab32s (&b->pb_service_time);
1551 __swab32s (&b->pb_limit);
1552 __swab64s (&b->pb_slv);
1553 __swab64s (&b->pb_pre_versions[0]);
1554 __swab64s (&b->pb_pre_versions[1]);
1555 __swab64s (&b->pb_pre_versions[2]);
1556 __swab64s (&b->pb_pre_versions[3]);
1557 CLASSERT(offsetof(typeof(*b), pb_padding) != 0);
1560 void lustre_swab_connect(struct obd_connect_data *ocd)
1562 __swab64s(&ocd->ocd_connect_flags);
1563 __swab32s(&ocd->ocd_version);
1564 __swab32s(&ocd->ocd_grant);
1565 __swab64s(&ocd->ocd_ibits_known);
1566 __swab32s(&ocd->ocd_index);
1567 __swab32s(&ocd->ocd_brw_size);
1568 __swab32s(&ocd->ocd_nllu);
1569 __swab32s(&ocd->ocd_nllg);
1570 __swab64s(&ocd->ocd_transno);
1571 __swab32s(&ocd->ocd_group);
1572 __swab32s(&ocd->ocd_cksum_types);
1573 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1574 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1577 void lustre_swab_obdo (struct obdo *o)
1579 __swab64s (&o->o_valid);
1580 __swab64s (&o->o_id);
1581 __swab64s (&o->o_seq);
1582 __swab64s (&o->o_parent_seq);
1583 __swab64s (&o->o_size);
1584 __swab64s (&o->o_mtime);
1585 __swab64s (&o->o_atime);
1586 __swab64s (&o->o_ctime);
1587 __swab64s (&o->o_blocks);
1588 __swab64s (&o->o_grant);
1589 __swab32s (&o->o_blksize);
1590 __swab32s (&o->o_mode);
1591 __swab32s (&o->o_uid);
1592 __swab32s (&o->o_gid);
1593 __swab32s (&o->o_flags);
1594 __swab32s (&o->o_nlink);
1595 __swab32s (&o->o_parent_oid);
1596 __swab32s (&o->o_misc);
1597 __swab64s (&o->o_ioepoch);
1598 __swab32s (&o->o_stripe_idx);
1599 __swab32s (&o->o_parent_ver);
1600 /* o_handle is opaque */
1601 /* o_lcookie is swabbed elsewhere */
1602 __swab32s (&o->o_uid_h);
1603 __swab32s (&o->o_gid_h);
1604 CLASSERT(offsetof(typeof(*o), o_padding_3) != 0);
1605 CLASSERT(offsetof(typeof(*o), o_padding_4) != 0);
1606 CLASSERT(offsetof(typeof(*o), o_padding_5) != 0);
1607 CLASSERT(offsetof(typeof(*o), o_padding_6) != 0);
1611 void lustre_swab_obd_statfs (struct obd_statfs *os)
1613 __swab64s (&os->os_type);
1614 __swab64s (&os->os_blocks);
1615 __swab64s (&os->os_bfree);
1616 __swab64s (&os->os_bavail);
1617 __swab64s (&os->os_files);
1618 __swab64s (&os->os_ffree);
1619 /* no need to swab os_fsid */
1620 __swab32s (&os->os_bsize);
1621 __swab32s (&os->os_namelen);
1622 __swab64s (&os->os_maxbytes);
1623 __swab32s (&os->os_state);
1624 CLASSERT(offsetof(typeof(*os), os_spare1) != 0);
1625 CLASSERT(offsetof(typeof(*os), os_spare2) != 0);
1626 CLASSERT(offsetof(typeof(*os), os_spare3) != 0);
1627 CLASSERT(offsetof(typeof(*os), os_spare4) != 0);
1628 CLASSERT(offsetof(typeof(*os), os_spare5) != 0);
1629 CLASSERT(offsetof(typeof(*os), os_spare6) != 0);
1630 CLASSERT(offsetof(typeof(*os), os_spare7) != 0);
1631 CLASSERT(offsetof(typeof(*os), os_spare8) != 0);
1632 CLASSERT(offsetof(typeof(*os), os_spare9) != 0);
1635 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1637 __swab64s (&ioo->ioo_id);
1638 __swab64s (&ioo->ioo_seq);
1639 __swab32s (&ioo->ioo_type);
1640 __swab32s (&ioo->ioo_bufcnt);
1643 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1645 __swab64s (&nbr->offset);
1646 __swab32s (&nbr->len);
1647 __swab32s (&nbr->flags);
1650 void lustre_swab_ost_body (struct ost_body *b)
1652 lustre_swab_obdo (&b->oa);
1655 void lustre_swab_ost_last_id(obd_id *id)
1660 void lustre_swab_generic_32s(__u32 *val)
1665 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1667 __swab64s(&lvb->lvb_size);
1668 __swab64s(&lvb->lvb_mtime);
1669 __swab64s(&lvb->lvb_atime);
1670 __swab64s(&lvb->lvb_ctime);
1671 __swab64s(&lvb->lvb_blocks);
1674 void lustre_swab_mds_status_req (struct mds_status_req *r)
1676 __swab32s (&r->flags);
1677 __swab32s (&r->repbuf);
1680 void lustre_swab_mds_body (struct mds_body *b)
1682 lustre_swab_ll_fid (&b->fid1);
1683 lustre_swab_ll_fid (&b->fid2);
1684 /* handle is opaque */
1685 __swab64s (&b->valid);
1686 __swab64s (&b->size);
1687 __swab64s (&b->mtime);
1688 __swab64s (&b->atime);
1689 __swab64s (&b->ctime);
1690 __swab64s (&b->blocks);
1691 __swab64s (&b->io_epoch);
1692 __swab64s (&b->ino);
1693 __swab32s (&b->fsuid);
1694 __swab32s (&b->fsgid);
1695 __swab32s (&b->capability);
1696 __swab32s (&b->mode);
1697 __swab32s (&b->uid);
1698 __swab32s (&b->gid);
1699 __swab32s (&b->flags);
1700 __swab32s (&b->rdev);
1701 __swab32s (&b->nlink);
1702 __swab32s (&b->generation);
1703 __swab32s (&b->suppgid);
1704 __swab32s (&b->eadatasize);
1705 __swab32s (&b->aclsize);
1706 __swab32s (&b->max_mdsize);
1707 __swab32s (&b->max_cookiesize);
1708 CLASSERT(offsetof(typeof(*b), padding_4) != 0);
1711 void lustre_swab_mdt_body (struct mdt_body *b)
1713 lustre_swab_lu_fid (&b->fid1);
1714 lustre_swab_lu_fid (&b->fid2);
1715 /* handle is opaque */
1716 __swab64s (&b->valid);
1717 __swab64s (&b->size);
1718 __swab64s (&b->mtime);
1719 __swab64s (&b->atime);
1720 __swab64s (&b->ctime);
1721 __swab64s (&b->blocks);
1722 __swab64s (&b->ioepoch);
1723 __swab64s (&b->ino);
1724 __swab32s (&b->fsuid);
1725 __swab32s (&b->fsgid);
1726 __swab32s (&b->capability);
1727 __swab32s (&b->mode);
1728 __swab32s (&b->uid);
1729 __swab32s (&b->gid);
1730 __swab32s (&b->flags);
1731 __swab32s (&b->rdev);
1732 __swab32s (&b->nlink);
1733 __swab32s (&b->generation);
1734 __swab32s (&b->suppgid);
1735 __swab32s (&b->eadatasize);
1736 __swab32s (&b->aclsize);
1737 __swab32s (&b->max_mdsize);
1738 __swab32s (&b->max_cookiesize);
1739 __swab32s (&b->uid_h);
1740 __swab32s (&b->gid_h);
1741 CLASSERT(offsetof(typeof(*b), padding_5) != 0);
1744 void lustre_swab_mdt_ioepoch (struct mdt_ioepoch *b)
1746 /* handle is opaque */
1747 __swab64s (&b->ioepoch);
1748 __swab32s (&b->flags);
1749 CLASSERT(offsetof(typeof(*b), padding) != 0);
1752 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1755 __swab32s(&mti->mti_lustre_ver);
1756 __swab32s(&mti->mti_stripe_index);
1757 __swab32s(&mti->mti_config_ver);
1758 __swab32s(&mti->mti_flags);
1759 __swab32s(&mti->mti_nid_count);
1760 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1761 for (i = 0; i < MTI_NIDS_MAX; i++)
1762 __swab64s(&mti->mti_nids[i]);
1765 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1767 __swab64s (&i->dqi_bgrace);
1768 __swab64s (&i->dqi_igrace);
1769 __swab32s (&i->dqi_flags);
1770 __swab32s (&i->dqi_valid);
1773 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1775 __swab64s (&b->dqb_ihardlimit);
1776 __swab64s (&b->dqb_isoftlimit);
1777 __swab64s (&b->dqb_curinodes);
1778 __swab64s (&b->dqb_bhardlimit);
1779 __swab64s (&b->dqb_bsoftlimit);
1780 __swab64s (&b->dqb_curspace);
1781 __swab64s (&b->dqb_btime);
1782 __swab64s (&b->dqb_itime);
1783 __swab32s (&b->dqb_valid);
1784 CLASSERT(offsetof(typeof(*b), padding) != 0);
1787 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1789 __swab32s (&q->qc_cmd);
1790 __swab32s (&q->qc_type);
1791 __swab32s (&q->qc_id);
1792 __swab32s (&q->qc_stat);
1793 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1794 lustre_swab_obd_dqblk (&q->qc_dqblk);
1797 void lustre_swab_quota_adjust_qunit (struct quota_adjust_qunit *q)
1799 __swab32s (&q->qaq_flags);
1800 __swab32s (&q->qaq_id);
1801 __swab64s (&q->qaq_bunit_sz);
1802 __swab64s (&q->qaq_iunit_sz);
1803 __swab64s (&q->padding1);
1806 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1808 __swab32s (&p->rp_uid);
1809 __swab32s (&p->rp_gid);
1810 __swab32s (&p->rp_fsuid);
1811 __swab32s (&p->rp_fsgid);
1812 __swab32s (&p->rp_access_perm);
1815 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1817 __swab32s (&p->rp_uid);
1818 __swab32s (&p->rp_gid);
1819 __swab32s (&p->rp_fsuid);
1820 __swab32s (&p->rp_fsuid_h);
1821 __swab32s (&p->rp_fsgid);
1822 __swab32s (&p->rp_fsgid_h);
1823 __swab32s (&p->rp_access_perm);
1826 void lustre_swab_fid2path(struct getinfo_fid2path *gf)
1828 lustre_swab_lu_fid(&gf->gf_fid);
1829 __swab64s(&gf->gf_recno);
1830 __swab32s(&gf->gf_linkno);
1831 __swab32s(&gf->gf_pathlen);
1833 EXPORT_SYMBOL(lustre_swab_fid2path);
1835 void lustre_swab_fiemap_extent(struct ll_fiemap_extent *fm_extent)
1837 __swab64s(&fm_extent->fe_logical);
1838 __swab64s(&fm_extent->fe_physical);
1839 __swab64s(&fm_extent->fe_length);
1840 __swab32s(&fm_extent->fe_flags);
1841 __swab32s(&fm_extent->fe_device);
1844 void lustre_swab_fiemap(struct ll_user_fiemap *fiemap)
1848 __swab64s(&fiemap->fm_start);
1849 __swab64s(&fiemap->fm_length);
1850 __swab32s(&fiemap->fm_flags);
1851 __swab32s(&fiemap->fm_mapped_extents);
1852 __swab32s(&fiemap->fm_extent_count);
1853 __swab32s(&fiemap->fm_reserved);
1855 for (i = 0; i < fiemap->fm_mapped_extents; i++)
1856 lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
1859 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
1861 __swab32s (&rr->rr_opcode);
1862 __swab32s (&rr->rr_cap);
1863 __swab32s (&rr->rr_fsuid);
1864 /* rr_fsuid_h is unused */
1865 __swab32s (&rr->rr_fsgid);
1866 /* rr_fsgid_h is unused */
1867 __swab32s (&rr->rr_suppgid1);
1868 /* rr_suppgid1_h is unused */
1869 __swab32s (&rr->rr_suppgid2);
1870 /* rr_suppgid2_h is unused */
1871 lustre_swab_lu_fid (&rr->rr_fid1);
1872 lustre_swab_lu_fid (&rr->rr_fid2);
1873 __swab64s (&rr->rr_mtime);
1874 __swab64s (&rr->rr_atime);
1875 __swab64s (&rr->rr_ctime);
1876 __swab64s (&rr->rr_size);
1877 __swab64s (&rr->rr_blocks);
1878 __swab32s (&rr->rr_bias);
1879 __swab32s (&rr->rr_mode);
1880 __swab32s (&rr->rr_flags);
1882 CLASSERT(offsetof(typeof(*rr), rr_padding_2) != 0);
1883 CLASSERT(offsetof(typeof(*rr), rr_padding_3) != 0);
1884 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
1887 void lustre_swab_lov_desc (struct lov_desc *ld)
1889 __swab32s (&ld->ld_tgt_count);
1890 __swab32s (&ld->ld_active_tgt_count);
1891 __swab32s (&ld->ld_default_stripe_count);
1892 __swab32s (&ld->ld_pattern);
1893 __swab64s (&ld->ld_default_stripe_size);
1894 __swab64s (&ld->ld_default_stripe_offset);
1895 __swab32s (&ld->ld_qos_maxage);
1896 /* uuid endian insensitive */
1899 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1901 __swab32s (&ld->ld_tgt_count);
1902 __swab32s (&ld->ld_active_tgt_count);
1903 __swab32s (&ld->ld_default_stripe_count);
1904 __swab32s (&ld->ld_pattern);
1905 __swab64s (&ld->ld_default_hash_size);
1906 __swab32s (&ld->ld_qos_maxage);
1907 /* uuid endian insensitive */
1910 void lustre_swab_lmv_stripe_md (struct lmv_stripe_md *mea)
1912 __swab32s(&mea->mea_magic);
1913 __swab32s(&mea->mea_count);
1914 __swab32s(&mea->mea_master);
1915 CLASSERT(offsetof(typeof(*mea), mea_padding) != 0);
1919 static void print_lum (struct lov_user_md *lum)
1921 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1922 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1923 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1924 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1925 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_seq);
1926 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1927 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1928 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1931 static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
1934 __swab32s(&lum->lmm_magic);
1935 __swab32s(&lum->lmm_pattern);
1936 __swab64s(&lum->lmm_object_id);
1937 __swab64s(&lum->lmm_object_seq);
1938 __swab32s(&lum->lmm_stripe_size);
1939 __swab16s(&lum->lmm_stripe_count);
1940 __swab16s(&lum->lmm_stripe_offset);
1945 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
1948 CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
1949 lustre_swab_lov_user_md_common(lum);
1953 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum)
1956 CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
1957 lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
1958 /* lmm_pool_name nothing to do with char */
1962 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
1965 CDEBUG(D_IOCTL, "swabbing lov_mds_md\n");
1966 __swab32s(&lmm->lmm_magic);
1967 __swab32s(&lmm->lmm_pattern);
1968 __swab64s(&lmm->lmm_object_id);
1969 __swab64s(&lmm->lmm_object_seq);
1970 __swab32s(&lmm->lmm_stripe_size);
1971 __swab32s(&lmm->lmm_stripe_count);
1975 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
1980 for (i = 0; i < stripe_count; i++) {
1981 __swab64s(&(lod[i].l_object_id));
1982 __swab64s(&(lod[i].l_object_seq));
1983 __swab32s(&(lod[i].l_ost_gen));
1984 __swab32s(&(lod[i].l_ost_idx));
1990 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
1994 for (i = 0; i < RES_NAME_SIZE; i++)
1995 __swab64s (&id->name[i]);
1998 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2000 /* the lock data is a union and the first two fields are always an
2001 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2002 * data the same way. */
2003 __swab64s(&d->l_extent.start);
2004 __swab64s(&d->l_extent.end);
2005 __swab64s(&d->l_extent.gid);
2006 __swab32s(&d->l_flock.pid);
2009 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2011 __swab64s (&i->opc);
2014 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2016 __swab32s (&r->lr_type);
2017 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2018 lustre_swab_ldlm_res_id (&r->lr_name);
2021 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2023 lustre_swab_ldlm_resource_desc (&l->l_resource);
2024 __swab32s (&l->l_req_mode);
2025 __swab32s (&l->l_granted_mode);
2026 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2029 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2031 __swab32s (&rq->lock_flags);
2032 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2033 __swab32s (&rq->lock_count);
2034 /* lock_handle[] opaque */
2037 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2039 __swab32s (&r->lock_flags);
2040 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2041 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2042 /* lock_handle opaque */
2043 __swab64s (&r->lock_policy_res1);
2044 __swab64s (&r->lock_policy_res2);
2047 /* no one calls this */
2048 int llog_log_swabbed(struct llog_log_hdr *hdr)
2050 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2052 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2057 void lustre_swab_qdata(struct qunit_data *d)
2059 __swab32s (&d->qd_id);
2060 __swab32s (&d->qd_flags);
2061 __swab64s (&d->qd_count);
2062 __swab64s (&d->qd_qunit);
2063 CLASSERT(offsetof(typeof(*d), padding) != 0);
2066 /* Dump functions */
2067 void dump_ioo(struct obd_ioobj *ioo)
2070 "obd_ioobj: ioo_id="LPD64", ioo_seq="LPD64", ioo_type=%d, "
2071 "ioo_bufct=%d\n", ioo->ioo_id, ioo->ioo_seq, ioo->ioo_type,
2075 void dump_rniobuf(struct niobuf_remote *nb)
2077 CDEBUG(D_RPCTRACE, "niobuf_remote: offset="LPU64", len=%d, flags=%x\n",
2078 nb->offset, nb->len, nb->flags);
2081 void dump_obdo(struct obdo *oa)
2083 __u32 valid = oa->o_valid;
2085 CDEBUG(D_RPCTRACE, "obdo: o_valid = %08x\n", valid);
2086 if (valid & OBD_MD_FLID)
2087 CDEBUG(D_RPCTRACE, "obdo: o_id = "LPD64"\n", oa->o_id);
2088 if (valid & OBD_MD_FLGROUP)
2089 CDEBUG(D_RPCTRACE, "obdo: o_seq = "LPD64"\n", oa->o_seq);
2090 if (valid & OBD_MD_FLFID)
2091 CDEBUG(D_RPCTRACE, "obdo: o_parent_seq = "LPX64"\n",
2093 if (valid & OBD_MD_FLSIZE)
2094 CDEBUG(D_RPCTRACE, "obdo: o_size = "LPD64"\n", oa->o_size);
2095 if (valid & OBD_MD_FLMTIME)
2096 CDEBUG(D_RPCTRACE, "obdo: o_mtime = "LPD64"\n", oa->o_mtime);
2097 if (valid & OBD_MD_FLATIME)
2098 CDEBUG(D_RPCTRACE, "obdo: o_atime = "LPD64"\n", oa->o_atime);
2099 if (valid & OBD_MD_FLCTIME)
2100 CDEBUG(D_RPCTRACE, "obdo: o_ctime = "LPD64"\n", oa->o_ctime);
2101 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
2102 CDEBUG(D_RPCTRACE, "obdo: o_blocks = "LPD64"\n", oa->o_blocks);
2103 if (valid & OBD_MD_FLGRANT)
2104 CDEBUG(D_RPCTRACE, "obdo: o_grant = "LPD64"\n", oa->o_grant);
2105 if (valid & OBD_MD_FLBLKSZ)
2106 CDEBUG(D_RPCTRACE, "obdo: o_blksize = %d\n", oa->o_blksize);
2107 if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
2108 CDEBUG(D_RPCTRACE, "obdo: o_mode = %o\n",
2109 oa->o_mode & ((valid & OBD_MD_FLTYPE ? S_IFMT : 0) |
2110 (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
2111 if (valid & OBD_MD_FLUID)
2112 CDEBUG(D_RPCTRACE, "obdo: o_uid = %u\n", oa->o_uid);
2113 if (valid & OBD_MD_FLUID)
2114 CDEBUG(D_RPCTRACE, "obdo: o_uid_h = %u\n", oa->o_uid_h);
2115 if (valid & OBD_MD_FLGID)
2116 CDEBUG(D_RPCTRACE, "obdo: o_gid = %u\n", oa->o_gid);
2117 if (valid & OBD_MD_FLGID)
2118 CDEBUG(D_RPCTRACE, "obdo: o_gid_h = %u\n", oa->o_gid_h);
2119 if (valid & OBD_MD_FLFLAGS)
2120 CDEBUG(D_RPCTRACE, "obdo: o_flags = %x\n", oa->o_flags);
2121 if (valid & OBD_MD_FLNLINK)
2122 CDEBUG(D_RPCTRACE, "obdo: o_nlink = %u\n", oa->o_nlink);
2123 else if (valid & OBD_MD_FLCKSUM)
2124 CDEBUG(D_RPCTRACE, "obdo: o_checksum (o_nlink) = %u\n",
2126 if (valid & OBD_MD_FLGENER)
2127 CDEBUG(D_RPCTRACE, "obdo: o_parent_oid = %x\n",
2129 if (valid & OBD_MD_FLEPOCH)
2130 CDEBUG(D_RPCTRACE, "obdo: o_ioepoch = "LPD64"\n",
2132 if (valid & OBD_MD_FLFID) {
2133 CDEBUG(D_RPCTRACE, "obdo: o_stripe_idx = %u\n",
2135 CDEBUG(D_RPCTRACE, "obdo: o_parent_ver = %x\n",
2138 if (valid & OBD_MD_FLHANDLE)
2139 CDEBUG(D_RPCTRACE, "obdo: o_handle = "LPD64"\n",
2140 oa->o_handle.cookie);
2141 if (valid & OBD_MD_FLCOOKIE)
2142 CDEBUG(D_RPCTRACE, "obdo: o_lcookie = "
2143 "(llog_cookie dumping not yet implemented)\n");
2146 void dump_ost_body(struct ost_body *ob)
2151 void dump_rcs(__u32 *rc)
2153 CDEBUG(D_RPCTRACE, "rmf_rcs: %d\n", *rc);
2159 * got qdata from request(req/rep)
2161 struct qunit_data *quota_get_qdata(void *r, int is_req, int is_exp)
2163 struct ptlrpc_request *req = (struct ptlrpc_request *)r;
2164 struct qunit_data *qdata;
2165 __u64 flags = is_exp ? req->rq_export->exp_connect_flags :
2166 req->rq_import->imp_connect_data.ocd_connect_flags;
2169 /* support for quota64 */
2170 LASSERT(flags & OBD_CONNECT_QUOTA64);
2171 /* support for change_qs */
2172 LASSERT(flags & OBD_CONNECT_CHANGE_QS);
2174 if (is_req == QUOTA_REQUEST)
2175 qdata = req_capsule_client_get(&req->rq_pill, &RMF_QUNIT_DATA);
2177 qdata = req_capsule_server_get(&req->rq_pill, &RMF_QUNIT_DATA);
2179 return ERR_PTR(-EPROTO);
2181 QDATA_SET_CHANGE_QS(qdata);
2184 EXPORT_SYMBOL(quota_get_qdata);
2187 * copy qdata to request(req/rep)
2189 int quota_copy_qdata(void *r, struct qunit_data *qdata, int is_req,
2192 struct ptlrpc_request *req = (struct ptlrpc_request *)r;
2194 __u64 flags = is_exp ? req->rq_export->exp_connect_flags :
2195 req->rq_import->imp_connect_data.ocd_connect_flags;
2199 /* support for quota64 */
2200 LASSERT(flags & OBD_CONNECT_QUOTA64);
2201 /* support for change_qs */
2202 LASSERT(flags & OBD_CONNECT_CHANGE_QS);
2204 if (is_req == QUOTA_REQUEST)
2205 target = req_capsule_client_get(&req->rq_pill, &RMF_QUNIT_DATA);
2207 target = req_capsule_server_get(&req->rq_pill, &RMF_QUNIT_DATA);
2211 LASSERT(target != qdata);
2212 memcpy(target, qdata, sizeof(*qdata));
2215 EXPORT_SYMBOL(quota_copy_qdata);
2216 #endif /* __KERNEL__ */
2218 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2220 LASSERT(req->rq_reqmsg);
2222 switch (req->rq_reqmsg->lm_magic) {
2223 case LUSTRE_MSG_MAGIC_V2:
2224 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2226 CERROR("bad lustre msg magic: %#08X\n",
2227 req->rq_reqmsg->lm_magic);
2232 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2234 LASSERT(req->rq_repmsg);
2236 switch (req->rq_repmsg->lm_magic) {
2237 case LUSTRE_MSG_MAGIC_V2:
2238 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2240 /* uninitialized yet */
2245 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2246 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2249 va_start(args, fmt);
2250 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2251 data->msg_fn, data->msg_line, fmt, args,
2252 " req@%p x"LPU64"/t"LPD64"("LPD64") o%d->%s@%s:%d/%d"
2253 " lens %d/%d e %d to %d dl "CFS_TIME_T" ref %d "
2254 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2255 req, req->rq_xid, req->rq_transno,
2256 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2257 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2258 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2260 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2262 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2264 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2265 req->rq_request_portal, req->rq_reply_portal,
2266 req->rq_reqlen, req->rq_replen,
2267 req->rq_early_count, req->rq_timedout,
2269 cfs_atomic_read(&req->rq_refcount),
2270 DEBUG_REQ_FLAGS(req),
2271 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2272 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2273 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2274 lustre_msg_get_flags(req->rq_repmsg) : -1,
2276 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2277 lustre_msg_get_status(req->rq_repmsg) : -1);
2279 EXPORT_SYMBOL(_debug_req);
2281 void lustre_swab_lustre_capa(struct lustre_capa *c)
2283 lustre_swab_lu_fid(&c->lc_fid);
2284 __swab64s (&c->lc_opc);
2285 __swab64s (&c->lc_uid);
2286 __swab64s (&c->lc_gid);
2287 __swab32s (&c->lc_flags);
2288 __swab32s (&c->lc_keyid);
2289 __swab32s (&c->lc_timeout);
2290 __swab32s (&c->lc_expiry);
2293 void lustre_swab_lustre_capa_key(struct lustre_capa_key *k)
2295 __swab64s (&k->lk_seq);
2296 __swab32s (&k->lk_keyid);
2297 CLASSERT(offsetof(typeof(*k), lk_padding) != 0);