4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
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>
57 #include <lustre_update.h>
59 static inline int lustre_msg_hdr_size_v2(int count)
61 return cfs_size_round(offsetof(struct lustre_msg_v2,
65 int lustre_msg_hdr_size(__u32 magic, int count)
68 case LUSTRE_MSG_MAGIC_V2:
69 return lustre_msg_hdr_size_v2(count);
71 LASSERTF(0, "incorrect message magic: %08x\n", magic);
75 EXPORT_SYMBOL(lustre_msg_hdr_size);
77 void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
81 lustre_set_req_swabbed(req, index);
83 lustre_set_rep_swabbed(req, index);
85 EXPORT_SYMBOL(ptlrpc_buf_set_swabbed);
87 int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
91 return (ptlrpc_req_need_swab(req) &&
92 !lustre_req_swabbed(req, index));
94 return (ptlrpc_rep_need_swab(req) &&
95 !lustre_rep_swabbed(req, index));
97 EXPORT_SYMBOL(ptlrpc_buf_need_swab);
99 static inline int lustre_msg_check_version_v2(struct lustre_msg_v2 *msg,
102 __u32 ver = lustre_msg_get_version(msg);
103 return (ver & LUSTRE_VERSION_MASK) != version;
106 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
108 switch (msg->lm_magic) {
109 case LUSTRE_MSG_MAGIC_V1:
110 CERROR("msg v1 not supported - please upgrade you system\n");
112 case LUSTRE_MSG_MAGIC_V2:
113 return lustre_msg_check_version_v2(msg, version);
115 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
119 EXPORT_SYMBOL(lustre_msg_check_version);
121 /* early reply size */
122 int lustre_msg_early_size()
126 /* Always reply old ptlrpc_body_v2 to keep interoprability
127 * with the old client (< 2.3) which doesn't have pb_jobid
128 * in the ptlrpc_body.
130 * XXX Remove this whenever we dorp interoprability with such
133 __u32 pblen = sizeof(struct ptlrpc_body_v2);
134 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, &pblen);
138 EXPORT_SYMBOL(lustre_msg_early_size);
140 int lustre_msg_size_v2(int count, __u32 *lengths)
145 size = lustre_msg_hdr_size_v2(count);
146 for (i = 0; i < count; i++)
147 size += cfs_size_round(lengths[i]);
151 EXPORT_SYMBOL(lustre_msg_size_v2);
153 /* This returns the size of the buffer that is required to hold a lustre_msg
154 * with the given sub-buffer lengths.
155 * NOTE: this should only be used for NEW requests, and should always be
156 * in the form of a v2 request. If this is a connection to a v1
157 * target then the first buffer will be stripped because the ptlrpc
158 * data is part of the lustre_msg_v1 header. b=14043 */
159 int lustre_msg_size(__u32 magic, int count, __u32 *lens)
161 __u32 size[] = { sizeof(struct ptlrpc_body) };
169 LASSERT(lens[MSG_PTLRPC_BODY_OFF] >= sizeof(struct ptlrpc_body_v2));
172 case LUSTRE_MSG_MAGIC_V2:
173 return lustre_msg_size_v2(count, lens);
175 LASSERTF(0, "incorrect message magic: %08x\n", magic);
179 EXPORT_SYMBOL(lustre_msg_size);
181 /* This is used to determine the size of a buffer that was already packed
182 * and will correctly handle the different message formats. */
183 int lustre_packed_msg_size(struct lustre_msg *msg)
185 switch (msg->lm_magic) {
186 case LUSTRE_MSG_MAGIC_V2:
187 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
189 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
193 EXPORT_SYMBOL(lustre_packed_msg_size);
195 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
201 msg->lm_bufcount = count;
202 /* XXX: lm_secflvr uninitialized here */
203 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
205 for (i = 0; i < count; i++)
206 msg->lm_buflens[i] = lens[i];
211 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
212 for (i = 0; i < count; i++) {
214 LOGL(tmp, lens[i], ptr);
217 EXPORT_SYMBOL(lustre_init_msg_v2);
219 static int lustre_pack_request_v2(struct ptlrpc_request *req,
220 int count, __u32 *lens, char **bufs)
224 reqlen = lustre_msg_size_v2(count, lens);
226 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
230 req->rq_reqlen = reqlen;
232 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
233 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
237 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
238 __u32 *lens, char **bufs)
240 __u32 size[] = { sizeof(struct ptlrpc_body) };
248 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
250 /* only use new format, we don't need to be compatible with 1.4 */
251 magic = LUSTRE_MSG_MAGIC_V2;
254 case LUSTRE_MSG_MAGIC_V2:
255 return lustre_pack_request_v2(req, count, lens, bufs);
257 LASSERTF(0, "incorrect message magic: %08x\n", magic);
261 EXPORT_SYMBOL(lustre_pack_request);
264 struct list_head ptlrpc_rs_debug_lru =
265 LIST_HEAD_INIT(ptlrpc_rs_debug_lru);
266 spinlock_t ptlrpc_rs_debug_lock;
268 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
270 spin_lock(&ptlrpc_rs_debug_lock); \
271 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
272 spin_unlock(&ptlrpc_rs_debug_lock); \
275 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
277 spin_lock(&ptlrpc_rs_debug_lock); \
278 list_del(&(rs)->rs_debug_list); \
279 spin_unlock(&ptlrpc_rs_debug_lock); \
282 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
283 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
286 struct ptlrpc_reply_state *
287 lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt)
289 struct ptlrpc_reply_state *rs = NULL;
291 spin_lock(&svcpt->scp_rep_lock);
293 /* See if we have anything in a pool, and wait if nothing */
294 while (list_empty(&svcpt->scp_rep_idle)) {
295 struct l_wait_info lwi;
298 spin_unlock(&svcpt->scp_rep_lock);
299 /* If we cannot get anything for some long time, we better
300 * bail out instead of waiting infinitely */
301 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
302 rc = l_wait_event(svcpt->scp_rep_waitq,
303 !list_empty(&svcpt->scp_rep_idle), &lwi);
306 spin_lock(&svcpt->scp_rep_lock);
309 rs = list_entry(svcpt->scp_rep_idle.next,
310 struct ptlrpc_reply_state, rs_list);
311 list_del(&rs->rs_list);
313 spin_unlock(&svcpt->scp_rep_lock);
315 memset(rs, 0, svcpt->scp_service->srv_max_reply_size);
316 rs->rs_size = svcpt->scp_service->srv_max_reply_size;
317 rs->rs_svcpt = svcpt;
323 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
325 struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
327 spin_lock(&svcpt->scp_rep_lock);
328 list_add(&rs->rs_list, &svcpt->scp_rep_idle);
329 spin_unlock(&svcpt->scp_rep_lock);
330 wake_up(&svcpt->scp_rep_waitq);
333 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
334 __u32 *lens, char **bufs, int flags)
336 struct ptlrpc_reply_state *rs;
340 LASSERT(req->rq_reply_state == NULL);
342 if ((flags & LPRFL_EARLY_REPLY) == 0) {
343 spin_lock(&req->rq_lock);
344 req->rq_packed_final = 1;
345 spin_unlock(&req->rq_lock);
348 msg_len = lustre_msg_size_v2(count, lens);
349 rc = sptlrpc_svc_alloc_rs(req, msg_len);
353 rs = req->rq_reply_state;
354 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
355 rs->rs_cb_id.cbid_fn = reply_out_callback;
356 rs->rs_cb_id.cbid_arg = rs;
357 rs->rs_svcpt = req->rq_rqbd->rqbd_svcpt;
358 INIT_LIST_HEAD(&rs->rs_exp_list);
359 INIT_LIST_HEAD(&rs->rs_obd_list);
360 INIT_LIST_HEAD(&rs->rs_list);
361 spin_lock_init(&rs->rs_lock);
363 req->rq_replen = msg_len;
364 req->rq_reply_state = rs;
365 req->rq_repmsg = rs->rs_msg;
367 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
368 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
370 PTLRPC_RS_DEBUG_LRU_ADD(rs);
374 EXPORT_SYMBOL(lustre_pack_reply_v2);
376 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
377 char **bufs, int flags)
380 __u32 size[] = { sizeof(struct ptlrpc_body) };
388 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
390 switch (req->rq_reqmsg->lm_magic) {
391 case LUSTRE_MSG_MAGIC_V2:
392 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
395 LASSERTF(0, "incorrect message magic: %08x\n",
396 req->rq_reqmsg->lm_magic);
400 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
401 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
404 EXPORT_SYMBOL(lustre_pack_reply_flags);
406 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
409 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
411 EXPORT_SYMBOL(lustre_pack_reply);
413 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
415 int i, offset, buflen, bufcount;
420 bufcount = m->lm_bufcount;
421 if (unlikely(n >= bufcount)) {
422 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
427 buflen = m->lm_buflens[n];
428 if (unlikely(buflen < min_size)) {
429 CERROR("msg %p buffer[%d] size %d too small "
430 "(required %d, opc=%d)\n", m, n, buflen, min_size,
431 n == MSG_PTLRPC_BODY_OFF ? -1 : lustre_msg_get_opc(m));
435 offset = lustre_msg_hdr_size_v2(bufcount);
436 for (i = 0; i < n; i++)
437 offset += cfs_size_round(m->lm_buflens[i]);
439 return (char *)m + offset;
442 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
444 switch (m->lm_magic) {
445 case LUSTRE_MSG_MAGIC_V2:
446 return lustre_msg_buf_v2(m, n, min_size);
448 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
452 EXPORT_SYMBOL(lustre_msg_buf);
454 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
455 unsigned int newlen, int move_data)
457 char *tail = NULL, *newpos;
461 LASSERT(msg->lm_bufcount > segment);
462 LASSERT(msg->lm_buflens[segment] >= newlen);
464 if (msg->lm_buflens[segment] == newlen)
467 if (move_data && msg->lm_bufcount > segment + 1) {
468 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
469 for (n = segment + 1; n < msg->lm_bufcount; n++)
470 tail_len += cfs_size_round(msg->lm_buflens[n]);
473 msg->lm_buflens[segment] = newlen;
475 if (tail && tail_len) {
476 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
477 LASSERT(newpos <= tail);
479 memmove(newpos, tail, tail_len);
482 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
486 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
487 * we also move data forward from @segment + 1.
489 * if @newlen == 0, we remove the segment completely, but we still keep the
490 * totally bufcount the same to save possible data moving. this will leave a
491 * unused segment with size 0 at the tail, but that's ok.
493 * return new msg size after shrinking.
496 * + if any buffers higher than @segment has been filled in, must call shrink
497 * with non-zero @move_data.
498 * + caller should NOT keep pointers to msg buffers which higher than @segment
501 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
502 unsigned int newlen, int move_data)
504 switch (msg->lm_magic) {
505 case LUSTRE_MSG_MAGIC_V2:
506 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
508 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
511 EXPORT_SYMBOL(lustre_shrink_msg);
513 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
515 PTLRPC_RS_DEBUG_LRU_DEL(rs);
517 LASSERT(atomic_read(&rs->rs_refcount) == 0);
518 LASSERT(!rs->rs_difficult || rs->rs_handled);
519 LASSERT(!rs->rs_on_net);
520 LASSERT(!rs->rs_scheduled);
521 LASSERT(rs->rs_export == NULL);
522 LASSERT(rs->rs_nlocks == 0);
523 LASSERT(list_empty(&rs->rs_exp_list));
524 LASSERT(list_empty(&rs->rs_obd_list));
526 sptlrpc_svc_free_rs(rs);
528 EXPORT_SYMBOL(lustre_free_reply_state);
530 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
532 int swabbed, required_len, i;
534 /* Now we know the sender speaks my language. */
535 required_len = lustre_msg_hdr_size_v2(0);
536 if (len < required_len) {
537 /* can't even look inside the message */
538 CERROR("message length %d too small for lustre_msg\n", len);
542 swabbed = (m->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
545 __swab32s(&m->lm_magic);
546 __swab32s(&m->lm_bufcount);
547 __swab32s(&m->lm_secflvr);
548 __swab32s(&m->lm_repsize);
549 __swab32s(&m->lm_cksum);
550 __swab32s(&m->lm_flags);
551 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
552 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
555 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
556 if (len < required_len) {
557 /* didn't receive all the buffer lengths */
558 CERROR ("message length %d too small for %d buflens\n",
559 len, m->lm_bufcount);
563 for (i = 0; i < m->lm_bufcount; i++) {
565 __swab32s(&m->lm_buflens[i]);
566 required_len += cfs_size_round(m->lm_buflens[i]);
569 if (len < required_len) {
570 CERROR("len: %d, required_len %d\n", len, required_len);
571 CERROR("bufcount: %d\n", m->lm_bufcount);
572 for (i = 0; i < m->lm_bufcount; i++)
573 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
580 int __lustre_unpack_msg(struct lustre_msg *m, int len)
582 int required_len, rc;
585 /* We can provide a slightly better error log, if we check the
586 * message magic and version first. In the future, struct
587 * lustre_msg may grow, and we'd like to log a version mismatch,
588 * rather than a short message.
591 required_len = offsetof(struct lustre_msg, lm_magic) +
593 if (len < required_len) {
594 /* can't even look inside the message */
595 CERROR("message length %d too small for magic/version check\n",
600 rc = lustre_unpack_msg_v2(m, len);
604 EXPORT_SYMBOL(__lustre_unpack_msg);
606 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len)
609 rc = __lustre_unpack_msg(req->rq_reqmsg, len);
611 lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
616 EXPORT_SYMBOL(ptlrpc_unpack_req_msg);
618 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len)
621 rc = __lustre_unpack_msg(req->rq_repmsg, len);
623 lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
628 EXPORT_SYMBOL(ptlrpc_unpack_rep_msg);
630 static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
631 const int inout, int offset)
633 struct ptlrpc_body *pb;
634 struct lustre_msg_v2 *m = inout ? req->rq_reqmsg : req->rq_repmsg;
636 pb = lustre_msg_buf_v2(m, offset, sizeof(struct ptlrpc_body_v2));
638 CERROR("error unpacking ptlrpc body\n");
641 if (ptlrpc_buf_need_swab(req, inout, offset)) {
642 lustre_swab_ptlrpc_body(pb);
643 ptlrpc_buf_set_swabbed(req, inout, offset);
646 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
647 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
652 pb->pb_status = ptlrpc_status_ntoh(pb->pb_status);
657 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
659 switch (req->rq_reqmsg->lm_magic) {
660 case LUSTRE_MSG_MAGIC_V2:
661 return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
663 CERROR("bad lustre msg magic: %08x\n",
664 req->rq_reqmsg->lm_magic);
669 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
671 switch (req->rq_repmsg->lm_magic) {
672 case LUSTRE_MSG_MAGIC_V2:
673 return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
675 CERROR("bad lustre msg magic: %08x\n",
676 req->rq_repmsg->lm_magic);
681 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
683 if (n >= m->lm_bufcount)
686 return m->lm_buflens[n];
690 * lustre_msg_buflen - return the length of buffer \a n in message \a m
691 * \param m lustre_msg (request or reply) to look at
692 * \param n message index (base 0)
694 * returns zero for non-existent message indices
696 int lustre_msg_buflen(struct lustre_msg *m, int n)
698 switch (m->lm_magic) {
699 case LUSTRE_MSG_MAGIC_V2:
700 return lustre_msg_buflen_v2(m, n);
702 CERROR("incorrect message magic: %08x\n", m->lm_magic);
706 EXPORT_SYMBOL(lustre_msg_buflen);
709 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
711 if (n >= m->lm_bufcount)
714 m->lm_buflens[n] = len;
717 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
719 switch (m->lm_magic) {
720 case LUSTRE_MSG_MAGIC_V2:
721 lustre_msg_set_buflen_v2(m, n, len);
724 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
728 EXPORT_SYMBOL(lustre_msg_set_buflen);
730 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
731 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
732 int lustre_msg_bufcount(struct lustre_msg *m)
734 switch (m->lm_magic) {
735 case LUSTRE_MSG_MAGIC_V2:
736 return m->lm_bufcount;
738 CERROR("incorrect message magic: %08x\n", m->lm_magic);
742 EXPORT_SYMBOL(lustre_msg_bufcount);
744 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
746 /* max_len == 0 means the string should fill the buffer */
750 switch (m->lm_magic) {
751 case LUSTRE_MSG_MAGIC_V2:
752 str = lustre_msg_buf_v2(m, index, 0);
753 blen = lustre_msg_buflen_v2(m, index);
756 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
760 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
764 slen = strnlen(str, blen);
766 if (slen == blen) { /* not NULL terminated */
767 CERROR("can't unpack non-NULL terminated string in "
768 "msg %p buffer[%d] len %d\n", m, index, blen);
773 if (slen != blen - 1) {
774 CERROR("can't unpack short string in msg %p "
775 "buffer[%d] len %d: strlen %d\n",
776 m, index, blen, slen);
779 } else if (slen > max_len) {
780 CERROR("can't unpack oversized string in msg %p "
781 "buffer[%d] len %d strlen %d: max %d expected\n",
782 m, index, blen, slen, max_len);
788 EXPORT_SYMBOL(lustre_msg_string);
790 /* Wrap up the normal fixed length cases */
791 static inline void *__lustre_swab_buf(struct lustre_msg *msg, int index,
792 int min_size, void *swabber)
796 LASSERT(msg != NULL);
797 switch (msg->lm_magic) {
798 case LUSTRE_MSG_MAGIC_V2:
799 ptr = lustre_msg_buf_v2(msg, index, min_size);
802 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
806 ((void (*)(void *))swabber)(ptr);
811 static inline struct ptlrpc_body *lustre_msg_ptlrpc_body(struct lustre_msg *msg)
813 return lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
814 sizeof(struct ptlrpc_body_v2));
817 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
819 switch (msg->lm_magic) {
820 case LUSTRE_MSG_MAGIC_V1:
821 case LUSTRE_MSG_MAGIC_V1_SWABBED:
823 case LUSTRE_MSG_MAGIC_V2:
824 /* already in host endian */
825 return msg->lm_flags;
827 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
831 EXPORT_SYMBOL(lustre_msghdr_get_flags);
833 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
835 switch (msg->lm_magic) {
836 case LUSTRE_MSG_MAGIC_V1:
838 case LUSTRE_MSG_MAGIC_V2:
839 msg->lm_flags = flags;
842 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
846 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
848 switch (msg->lm_magic) {
849 case LUSTRE_MSG_MAGIC_V2: {
850 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
852 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
858 /* flags might be printed in debug code while message
863 EXPORT_SYMBOL(lustre_msg_get_flags);
865 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
867 switch (msg->lm_magic) {
868 case LUSTRE_MSG_MAGIC_V2: {
869 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
870 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
871 pb->pb_flags |= flags;
875 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
878 EXPORT_SYMBOL(lustre_msg_add_flags);
880 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
882 switch (msg->lm_magic) {
883 case LUSTRE_MSG_MAGIC_V2: {
884 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
885 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
886 pb->pb_flags = flags;
890 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
893 EXPORT_SYMBOL(lustre_msg_set_flags);
895 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
897 switch (msg->lm_magic) {
898 case LUSTRE_MSG_MAGIC_V2: {
899 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
900 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
901 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
905 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
908 EXPORT_SYMBOL(lustre_msg_clear_flags);
910 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
912 switch (msg->lm_magic) {
913 case LUSTRE_MSG_MAGIC_V2: {
914 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
916 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
919 return pb->pb_op_flags;
925 EXPORT_SYMBOL(lustre_msg_get_op_flags);
927 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
929 switch (msg->lm_magic) {
930 case LUSTRE_MSG_MAGIC_V2: {
931 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
932 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
933 pb->pb_op_flags |= flags;
937 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
940 EXPORT_SYMBOL(lustre_msg_add_op_flags);
942 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
944 switch (msg->lm_magic) {
945 case LUSTRE_MSG_MAGIC_V2: {
946 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
947 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
948 pb->pb_op_flags |= flags;
952 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
955 EXPORT_SYMBOL(lustre_msg_set_op_flags);
957 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
959 switch (msg->lm_magic) {
960 case LUSTRE_MSG_MAGIC_V2: {
961 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
963 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
966 return &pb->pb_handle;
969 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
973 EXPORT_SYMBOL(lustre_msg_get_handle);
975 __u32 lustre_msg_get_type(struct lustre_msg *msg)
977 switch (msg->lm_magic) {
978 case LUSTRE_MSG_MAGIC_V2: {
979 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
981 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
982 return PTL_RPC_MSG_ERR;
987 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
988 return PTL_RPC_MSG_ERR;
991 EXPORT_SYMBOL(lustre_msg_get_type);
993 __u32 lustre_msg_get_version(struct lustre_msg *msg)
995 switch (msg->lm_magic) {
996 case LUSTRE_MSG_MAGIC_V2: {
997 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
999 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1002 return pb->pb_version;
1005 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1009 EXPORT_SYMBOL(lustre_msg_get_version);
1011 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1013 switch (msg->lm_magic) {
1014 case LUSTRE_MSG_MAGIC_V2: {
1015 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1016 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1017 pb->pb_version |= version;
1021 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1024 EXPORT_SYMBOL(lustre_msg_add_version);
1026 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1028 switch (msg->lm_magic) {
1029 case LUSTRE_MSG_MAGIC_V2: {
1030 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1032 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1038 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1043 EXPORT_SYMBOL(lustre_msg_get_opc);
1045 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1047 switch (msg->lm_magic) {
1048 case LUSTRE_MSG_MAGIC_V2: {
1049 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1051 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1054 return pb->pb_last_xid;
1057 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1061 EXPORT_SYMBOL(lustre_msg_get_last_xid);
1063 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1065 switch (msg->lm_magic) {
1066 case LUSTRE_MSG_MAGIC_V2: {
1067 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1069 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1072 return pb->pb_last_committed;
1075 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1079 EXPORT_SYMBOL(lustre_msg_get_last_committed);
1081 __u64 *lustre_msg_get_versions(struct lustre_msg *msg)
1083 switch (msg->lm_magic) {
1084 case LUSTRE_MSG_MAGIC_V1:
1086 case LUSTRE_MSG_MAGIC_V2: {
1087 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1089 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1092 return pb->pb_pre_versions;
1095 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1099 EXPORT_SYMBOL(lustre_msg_get_versions);
1101 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1103 switch (msg->lm_magic) {
1104 case LUSTRE_MSG_MAGIC_V2: {
1105 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1107 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1110 return pb->pb_transno;
1113 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1117 EXPORT_SYMBOL(lustre_msg_get_transno);
1119 int lustre_msg_get_status(struct lustre_msg *msg)
1121 switch (msg->lm_magic) {
1122 case LUSTRE_MSG_MAGIC_V2: {
1123 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1125 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1128 return pb->pb_status;
1131 /* status might be printed in debug code while message
1136 EXPORT_SYMBOL(lustre_msg_get_status);
1138 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1140 switch (msg->lm_magic) {
1141 case LUSTRE_MSG_MAGIC_V2: {
1142 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1144 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1150 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1154 EXPORT_SYMBOL(lustre_msg_get_slv);
1157 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1159 switch (msg->lm_magic) {
1160 case LUSTRE_MSG_MAGIC_V2: {
1161 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1163 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1170 CERROR("invalid msg magic %x\n", msg->lm_magic);
1174 EXPORT_SYMBOL(lustre_msg_set_slv);
1176 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1178 switch (msg->lm_magic) {
1179 case LUSTRE_MSG_MAGIC_V2: {
1180 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1182 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1185 return pb->pb_limit;
1188 CERROR("invalid msg magic %x\n", msg->lm_magic);
1192 EXPORT_SYMBOL(lustre_msg_get_limit);
1195 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1197 switch (msg->lm_magic) {
1198 case LUSTRE_MSG_MAGIC_V2: {
1199 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1201 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1204 pb->pb_limit = limit;
1208 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1212 EXPORT_SYMBOL(lustre_msg_set_limit);
1214 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1216 switch (msg->lm_magic) {
1217 case LUSTRE_MSG_MAGIC_V2: {
1218 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1220 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1223 return pb->pb_conn_cnt;
1226 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1230 EXPORT_SYMBOL(lustre_msg_get_conn_cnt);
1232 int lustre_msg_is_v1(struct lustre_msg *msg)
1234 switch (msg->lm_magic) {
1235 case LUSTRE_MSG_MAGIC_V1:
1236 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1242 EXPORT_SYMBOL(lustre_msg_is_v1);
1244 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1246 switch (msg->lm_magic) {
1247 case LUSTRE_MSG_MAGIC_V2:
1248 return msg->lm_magic;
1250 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1254 EXPORT_SYMBOL(lustre_msg_get_magic);
1256 __u32 lustre_msg_get_timeout(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 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1265 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1269 return pb->pb_timeout;
1272 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1277 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1279 switch (msg->lm_magic) {
1280 case LUSTRE_MSG_MAGIC_V1:
1281 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1283 case LUSTRE_MSG_MAGIC_V2: {
1284 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1286 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1290 return pb->pb_service_time;
1293 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1298 char *lustre_msg_get_jobid(struct lustre_msg *msg)
1300 switch (msg->lm_magic) {
1301 case LUSTRE_MSG_MAGIC_V1:
1302 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1304 case LUSTRE_MSG_MAGIC_V2: {
1305 struct ptlrpc_body *pb =
1306 lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
1307 sizeof(struct ptlrpc_body));
1311 return pb->pb_jobid;
1314 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1318 EXPORT_SYMBOL(lustre_msg_get_jobid);
1320 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1322 switch (msg->lm_magic) {
1323 case LUSTRE_MSG_MAGIC_V2:
1324 return msg->lm_cksum;
1326 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1331 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1333 * In 1.6 and 1.8 the checksum was computed only on struct ptlrpc_body as
1334 * it was in 1.6 (88 bytes, smaller than the full size in 1.8). It makes
1335 * more sense to compute the checksum on the full ptlrpc_body, regardless
1336 * of what size it is, but in order to keep interoperability with 1.8 we
1337 * can optionally also checksum only the first 88 bytes (caller decides). */
1338 # define ptlrpc_body_cksum_size_compat18 88
1340 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg, int compat18)
1342 # warning "remove checksum compatibility support for b1_8"
1343 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1346 switch (msg->lm_magic) {
1347 case LUSTRE_MSG_MAGIC_V2: {
1348 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1349 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1351 unsigned int hsize = 4;
1352 __u32 len = compat18 ? ptlrpc_body_cksum_size_compat18 :
1353 lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF);
1354 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1355 cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb,
1356 len, NULL, 0, (unsigned char *)&crc,
1360 # warning "remove checksum compatibility support for b1_8"
1362 unsigned int hsize = 4;
1363 cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb,
1364 lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF),
1365 NULL, 0, (unsigned char *)&crc, &hsize);
1370 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1375 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1377 switch (msg->lm_magic) {
1378 case LUSTRE_MSG_MAGIC_V2: {
1379 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1380 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1381 pb->pb_handle = *handle;
1385 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1388 EXPORT_SYMBOL(lustre_msg_set_handle);
1390 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1392 switch (msg->lm_magic) {
1393 case LUSTRE_MSG_MAGIC_V2: {
1394 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1395 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1400 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1403 EXPORT_SYMBOL(lustre_msg_set_type);
1405 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1407 switch (msg->lm_magic) {
1408 case LUSTRE_MSG_MAGIC_V2: {
1409 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1410 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1415 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1418 EXPORT_SYMBOL(lustre_msg_set_opc);
1420 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1422 switch (msg->lm_magic) {
1423 case LUSTRE_MSG_MAGIC_V2: {
1424 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1425 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1426 pb->pb_last_xid = last_xid;
1430 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1433 EXPORT_SYMBOL(lustre_msg_set_last_xid);
1435 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1437 switch (msg->lm_magic) {
1438 case LUSTRE_MSG_MAGIC_V2: {
1439 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1440 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1441 pb->pb_last_committed = last_committed;
1445 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1448 EXPORT_SYMBOL(lustre_msg_set_last_committed);
1450 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions)
1452 switch (msg->lm_magic) {
1453 case LUSTRE_MSG_MAGIC_V1:
1455 case LUSTRE_MSG_MAGIC_V2: {
1456 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1457 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1458 pb->pb_pre_versions[0] = versions[0];
1459 pb->pb_pre_versions[1] = versions[1];
1460 pb->pb_pre_versions[2] = versions[2];
1461 pb->pb_pre_versions[3] = versions[3];
1465 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1468 EXPORT_SYMBOL(lustre_msg_set_versions);
1470 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1472 switch (msg->lm_magic) {
1473 case LUSTRE_MSG_MAGIC_V2: {
1474 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1475 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1476 pb->pb_transno = transno;
1480 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1483 EXPORT_SYMBOL(lustre_msg_set_transno);
1485 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1487 switch (msg->lm_magic) {
1488 case LUSTRE_MSG_MAGIC_V2: {
1489 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1490 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1491 pb->pb_status = status;
1495 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1498 EXPORT_SYMBOL(lustre_msg_set_status);
1500 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1502 switch (msg->lm_magic) {
1503 case LUSTRE_MSG_MAGIC_V2: {
1504 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1505 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1506 pb->pb_conn_cnt = conn_cnt;
1510 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1513 EXPORT_SYMBOL(lustre_msg_set_conn_cnt);
1515 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1517 switch (msg->lm_magic) {
1518 case LUSTRE_MSG_MAGIC_V1:
1520 case LUSTRE_MSG_MAGIC_V2: {
1521 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1522 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1523 pb->pb_timeout = timeout;
1527 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1531 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1533 switch (msg->lm_magic) {
1534 case LUSTRE_MSG_MAGIC_V1:
1536 case LUSTRE_MSG_MAGIC_V2: {
1537 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1538 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1539 pb->pb_service_time = service_time;
1543 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1547 void lustre_msg_set_jobid(struct lustre_msg *msg, char *jobid)
1549 switch (msg->lm_magic) {
1550 case LUSTRE_MSG_MAGIC_V1:
1552 case LUSTRE_MSG_MAGIC_V2: {
1553 __u32 opc = lustre_msg_get_opc(msg);
1554 struct ptlrpc_body *pb;
1556 /* Don't set jobid for ldlm ast RPCs, they've been shrinked.
1557 * See the comment in ptlrpc_request_pack(). */
1558 if (!opc || opc == LDLM_BL_CALLBACK ||
1559 opc == LDLM_CP_CALLBACK || opc == LDLM_GL_CALLBACK)
1562 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
1563 sizeof(struct ptlrpc_body));
1564 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1567 memcpy(pb->pb_jobid, jobid, JOBSTATS_JOBID_SIZE);
1568 else if (pb->pb_jobid[0] == '\0')
1569 lustre_get_jobid(pb->pb_jobid);
1573 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1576 EXPORT_SYMBOL(lustre_msg_set_jobid);
1578 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1580 switch (msg->lm_magic) {
1581 case LUSTRE_MSG_MAGIC_V1:
1583 case LUSTRE_MSG_MAGIC_V2:
1584 msg->lm_cksum = cksum;
1587 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1592 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1594 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1596 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1597 req->rq_pill.rc_area[RCL_SERVER]);
1598 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1599 req->rq_reqmsg->lm_repsize = req->rq_replen;
1601 EXPORT_SYMBOL(ptlrpc_request_set_replen);
1603 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
1605 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1606 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1607 req->rq_reqmsg->lm_repsize = req->rq_replen;
1609 EXPORT_SYMBOL(ptlrpc_req_set_repsize);
1612 * Send a remote set_info_async.
1614 * This may go from client to server or server to client.
1616 int do_set_info_async(struct obd_import *imp,
1617 int opcode, int version,
1618 obd_count keylen, void *key,
1619 obd_count vallen, void *val,
1620 struct ptlrpc_request_set *set)
1622 struct ptlrpc_request *req;
1627 req = ptlrpc_request_alloc(imp, &RQF_OBD_SET_INFO);
1631 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1632 RCL_CLIENT, keylen);
1633 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1634 RCL_CLIENT, vallen);
1635 rc = ptlrpc_request_pack(req, version, opcode);
1637 ptlrpc_request_free(req);
1641 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1642 memcpy(tmp, key, keylen);
1643 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1644 memcpy(tmp, val, vallen);
1646 ptlrpc_request_set_replen(req);
1649 ptlrpc_set_add_req(set, req);
1650 ptlrpc_check_set(NULL, set);
1652 rc = ptlrpc_queue_wait(req);
1653 ptlrpc_req_finished(req);
1658 EXPORT_SYMBOL(do_set_info_async);
1660 /* byte flipping routines for all wire types declared in
1661 * lustre_idl.h implemented here.
1663 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1665 __swab32s (&b->pb_type);
1666 __swab32s (&b->pb_version);
1667 __swab32s (&b->pb_opc);
1668 __swab32s (&b->pb_status);
1669 __swab64s (&b->pb_last_xid);
1670 __swab64s (&b->pb_last_seen);
1671 __swab64s (&b->pb_last_committed);
1672 __swab64s (&b->pb_transno);
1673 __swab32s (&b->pb_flags);
1674 __swab32s (&b->pb_op_flags);
1675 __swab32s (&b->pb_conn_cnt);
1676 __swab32s (&b->pb_timeout);
1677 __swab32s (&b->pb_service_time);
1678 __swab32s (&b->pb_limit);
1679 __swab64s (&b->pb_slv);
1680 __swab64s (&b->pb_pre_versions[0]);
1681 __swab64s (&b->pb_pre_versions[1]);
1682 __swab64s (&b->pb_pre_versions[2]);
1683 __swab64s (&b->pb_pre_versions[3]);
1684 CLASSERT(offsetof(typeof(*b), pb_padding) != 0);
1685 /* While we need to maintain compatibility between
1686 * clients and servers without ptlrpc_body_v2 (< 2.3)
1687 * do not swab any fields beyond pb_jobid, as we are
1688 * using this swab function for both ptlrpc_body
1689 * and ptlrpc_body_v2. */
1690 CLASSERT(offsetof(typeof(*b), pb_jobid) != 0);
1692 EXPORT_SYMBOL(lustre_swab_ptlrpc_body);
1694 void lustre_swab_connect(struct obd_connect_data *ocd)
1696 __swab64s(&ocd->ocd_connect_flags);
1697 __swab32s(&ocd->ocd_version);
1698 __swab32s(&ocd->ocd_grant);
1699 __swab64s(&ocd->ocd_ibits_known);
1700 __swab32s(&ocd->ocd_index);
1701 __swab32s(&ocd->ocd_brw_size);
1702 /* ocd_blocksize and ocd_inodespace don't need to be swabbed because
1703 * they are 8-byte values */
1704 __swab16s(&ocd->ocd_grant_extent);
1705 __swab32s(&ocd->ocd_unused);
1706 __swab64s(&ocd->ocd_transno);
1707 __swab32s(&ocd->ocd_group);
1708 __swab32s(&ocd->ocd_cksum_types);
1709 __swab32s(&ocd->ocd_instance);
1710 /* Fields after ocd_cksum_types are only accessible by the receiver
1711 * if the corresponding flag in ocd_connect_flags is set. Accessing
1712 * any field after ocd_maxbytes on the receiver without a valid flag
1713 * may result in out-of-bound memory access and kernel oops. */
1714 if (ocd->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)
1715 __swab32s(&ocd->ocd_max_easize);
1716 if (ocd->ocd_connect_flags & OBD_CONNECT_MAXBYTES)
1717 __swab64s(&ocd->ocd_maxbytes);
1718 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1719 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1720 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1721 CLASSERT(offsetof(typeof(*ocd), padding4) != 0);
1722 CLASSERT(offsetof(typeof(*ocd), padding5) != 0);
1723 CLASSERT(offsetof(typeof(*ocd), padding6) != 0);
1724 CLASSERT(offsetof(typeof(*ocd), padding7) != 0);
1725 CLASSERT(offsetof(typeof(*ocd), padding8) != 0);
1726 CLASSERT(offsetof(typeof(*ocd), padding9) != 0);
1727 CLASSERT(offsetof(typeof(*ocd), paddingA) != 0);
1728 CLASSERT(offsetof(typeof(*ocd), paddingB) != 0);
1729 CLASSERT(offsetof(typeof(*ocd), paddingC) != 0);
1730 CLASSERT(offsetof(typeof(*ocd), paddingD) != 0);
1731 CLASSERT(offsetof(typeof(*ocd), paddingE) != 0);
1732 CLASSERT(offsetof(typeof(*ocd), paddingF) != 0);
1735 void lustre_swab_obdo (struct obdo *o)
1737 __swab64s (&o->o_valid);
1738 lustre_swab_ost_id(&o->o_oi);
1739 __swab64s (&o->o_parent_seq);
1740 __swab64s (&o->o_size);
1741 __swab64s (&o->o_mtime);
1742 __swab64s (&o->o_atime);
1743 __swab64s (&o->o_ctime);
1744 __swab64s (&o->o_blocks);
1745 __swab64s (&o->o_grant);
1746 __swab32s (&o->o_blksize);
1747 __swab32s (&o->o_mode);
1748 __swab32s (&o->o_uid);
1749 __swab32s (&o->o_gid);
1750 __swab32s (&o->o_flags);
1751 __swab32s (&o->o_nlink);
1752 __swab32s (&o->o_parent_oid);
1753 __swab32s (&o->o_misc);
1754 __swab64s (&o->o_ioepoch);
1755 __swab32s (&o->o_stripe_idx);
1756 __swab32s (&o->o_parent_ver);
1757 /* o_handle is opaque */
1758 /* o_lcookie is swabbed elsewhere */
1759 __swab32s (&o->o_uid_h);
1760 __swab32s (&o->o_gid_h);
1761 __swab64s (&o->o_data_version);
1762 CLASSERT(offsetof(typeof(*o), o_padding_4) != 0);
1763 CLASSERT(offsetof(typeof(*o), o_padding_5) != 0);
1764 CLASSERT(offsetof(typeof(*o), o_padding_6) != 0);
1767 EXPORT_SYMBOL(lustre_swab_obdo);
1769 void lustre_swab_obd_statfs (struct obd_statfs *os)
1771 __swab64s (&os->os_type);
1772 __swab64s (&os->os_blocks);
1773 __swab64s (&os->os_bfree);
1774 __swab64s (&os->os_bavail);
1775 __swab64s (&os->os_files);
1776 __swab64s (&os->os_ffree);
1777 /* no need to swab os_fsid */
1778 __swab32s (&os->os_bsize);
1779 __swab32s (&os->os_namelen);
1780 __swab64s (&os->os_maxbytes);
1781 __swab32s (&os->os_state);
1782 CLASSERT(offsetof(typeof(*os), os_fprecreated) != 0);
1783 CLASSERT(offsetof(typeof(*os), os_spare2) != 0);
1784 CLASSERT(offsetof(typeof(*os), os_spare3) != 0);
1785 CLASSERT(offsetof(typeof(*os), os_spare4) != 0);
1786 CLASSERT(offsetof(typeof(*os), os_spare5) != 0);
1787 CLASSERT(offsetof(typeof(*os), os_spare6) != 0);
1788 CLASSERT(offsetof(typeof(*os), os_spare7) != 0);
1789 CLASSERT(offsetof(typeof(*os), os_spare8) != 0);
1790 CLASSERT(offsetof(typeof(*os), os_spare9) != 0);
1792 EXPORT_SYMBOL(lustre_swab_obd_statfs);
1794 void lustre_swab_obd_ioobj(struct obd_ioobj *ioo)
1796 lustre_swab_ost_id(&ioo->ioo_oid);
1797 __swab32s(&ioo->ioo_max_brw);
1798 __swab32s(&ioo->ioo_bufcnt);
1800 EXPORT_SYMBOL(lustre_swab_obd_ioobj);
1802 void lustre_swab_niobuf_remote(struct niobuf_remote *nbr)
1804 __swab64s(&nbr->rnb_offset);
1805 __swab32s(&nbr->rnb_len);
1806 __swab32s(&nbr->rnb_flags);
1808 EXPORT_SYMBOL(lustre_swab_niobuf_remote);
1810 void lustre_swab_ost_body (struct ost_body *b)
1812 lustre_swab_obdo (&b->oa);
1814 EXPORT_SYMBOL(lustre_swab_ost_body);
1816 void lustre_swab_ost_last_id(obd_id *id)
1820 EXPORT_SYMBOL(lustre_swab_ost_last_id);
1822 void lustre_swab_generic_32s(__u32 *val)
1826 EXPORT_SYMBOL(lustre_swab_generic_32s);
1828 void lustre_swab_gl_desc(union ldlm_gl_desc *desc)
1830 lustre_swab_lu_fid(&desc->lquota_desc.gl_id.qid_fid);
1831 __swab64s(&desc->lquota_desc.gl_flags);
1832 __swab64s(&desc->lquota_desc.gl_ver);
1833 __swab64s(&desc->lquota_desc.gl_hardlimit);
1834 __swab64s(&desc->lquota_desc.gl_softlimit);
1835 __swab64s(&desc->lquota_desc.gl_time);
1836 CLASSERT(offsetof(typeof(desc->lquota_desc), gl_pad2) != 0);
1839 void lustre_swab_ost_lvb_v1(struct ost_lvb_v1 *lvb)
1841 __swab64s(&lvb->lvb_size);
1842 __swab64s(&lvb->lvb_mtime);
1843 __swab64s(&lvb->lvb_atime);
1844 __swab64s(&lvb->lvb_ctime);
1845 __swab64s(&lvb->lvb_blocks);
1847 EXPORT_SYMBOL(lustre_swab_ost_lvb_v1);
1849 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1851 __swab64s(&lvb->lvb_size);
1852 __swab64s(&lvb->lvb_mtime);
1853 __swab64s(&lvb->lvb_atime);
1854 __swab64s(&lvb->lvb_ctime);
1855 __swab64s(&lvb->lvb_blocks);
1856 __swab32s(&lvb->lvb_mtime_ns);
1857 __swab32s(&lvb->lvb_atime_ns);
1858 __swab32s(&lvb->lvb_ctime_ns);
1859 __swab32s(&lvb->lvb_padding);
1861 EXPORT_SYMBOL(lustre_swab_ost_lvb);
1863 void lustre_swab_lquota_lvb(struct lquota_lvb *lvb)
1865 __swab64s(&lvb->lvb_flags);
1866 __swab64s(&lvb->lvb_id_may_rel);
1867 __swab64s(&lvb->lvb_id_rel);
1868 __swab64s(&lvb->lvb_id_qunit);
1869 __swab64s(&lvb->lvb_pad1);
1871 EXPORT_SYMBOL(lustre_swab_lquota_lvb);
1873 void lustre_swab_mdt_body (struct mdt_body *b)
1875 lustre_swab_lu_fid(&b->mbo_fid1);
1876 lustre_swab_lu_fid(&b->mbo_fid2);
1877 /* handle is opaque */
1878 __swab64s(&b->mbo_valid);
1879 __swab64s(&b->mbo_size);
1880 __swab64s(&b->mbo_mtime);
1881 __swab64s(&b->mbo_atime);
1882 __swab64s(&b->mbo_ctime);
1883 __swab64s(&b->mbo_blocks);
1884 __swab64s(&b->mbo_ioepoch);
1885 __swab64s(&b->mbo_t_state);
1886 __swab32s(&b->mbo_fsuid);
1887 __swab32s(&b->mbo_fsgid);
1888 __swab32s(&b->mbo_capability);
1889 __swab32s(&b->mbo_mode);
1890 __swab32s(&b->mbo_uid);
1891 __swab32s(&b->mbo_gid);
1892 __swab32s(&b->mbo_flags);
1893 __swab32s(&b->mbo_rdev);
1894 __swab32s(&b->mbo_nlink);
1895 CLASSERT(offsetof(typeof(*b), mbo_unused2) != 0);
1896 __swab32s(&b->mbo_suppgid);
1897 __swab32s(&b->mbo_eadatasize);
1898 __swab32s(&b->mbo_aclsize);
1899 __swab32s(&b->mbo_max_mdsize);
1900 __swab32s(&b->mbo_max_cookiesize);
1901 __swab32s(&b->mbo_uid_h);
1902 __swab32s(&b->mbo_gid_h);
1903 CLASSERT(offsetof(typeof(*b), mbo_padding_5) != 0);
1905 EXPORT_SYMBOL(lustre_swab_mdt_body);
1907 void lustre_swab_mdt_ioepoch (struct mdt_ioepoch *b)
1909 /* handle is opaque */
1910 __swab64s (&b->ioepoch);
1911 __swab32s (&b->flags);
1912 CLASSERT(offsetof(typeof(*b), padding) != 0);
1914 EXPORT_SYMBOL(lustre_swab_mdt_ioepoch);
1916 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1919 __swab32s(&mti->mti_lustre_ver);
1920 __swab32s(&mti->mti_stripe_index);
1921 __swab32s(&mti->mti_config_ver);
1922 __swab32s(&mti->mti_flags);
1923 __swab32s(&mti->mti_instance);
1924 __swab32s(&mti->mti_nid_count);
1925 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1926 for (i = 0; i < MTI_NIDS_MAX; i++)
1927 __swab64s(&mti->mti_nids[i]);
1929 EXPORT_SYMBOL(lustre_swab_mgs_target_info);
1931 void lustre_swab_mgs_nidtbl_entry(struct mgs_nidtbl_entry *entry)
1935 __swab64s(&entry->mne_version);
1936 __swab32s(&entry->mne_instance);
1937 __swab32s(&entry->mne_index);
1938 __swab32s(&entry->mne_length);
1940 /* mne_nid_(count|type) must be one byte size because we're gonna
1941 * access it w/o swapping. */
1942 CLASSERT(sizeof(entry->mne_nid_count) == sizeof(__u8));
1943 CLASSERT(sizeof(entry->mne_nid_type) == sizeof(__u8));
1945 /* remove this assertion if ipv6 is supported. */
1946 LASSERT(entry->mne_nid_type == 0);
1947 for (i = 0; i < entry->mne_nid_count; i++) {
1948 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1949 __swab64s(&entry->u.nids[i]);
1952 EXPORT_SYMBOL(lustre_swab_mgs_nidtbl_entry);
1954 void lustre_swab_mgs_config_body(struct mgs_config_body *body)
1956 __swab64s(&body->mcb_offset);
1957 __swab32s(&body->mcb_units);
1958 __swab16s(&body->mcb_type);
1960 EXPORT_SYMBOL(lustre_swab_mgs_config_body);
1962 void lustre_swab_mgs_config_res(struct mgs_config_res *body)
1964 __swab64s(&body->mcr_offset);
1965 __swab64s(&body->mcr_size);
1967 EXPORT_SYMBOL(lustre_swab_mgs_config_res);
1969 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1971 __swab64s (&i->dqi_bgrace);
1972 __swab64s (&i->dqi_igrace);
1973 __swab32s (&i->dqi_flags);
1974 __swab32s (&i->dqi_valid);
1977 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1979 __swab64s (&b->dqb_ihardlimit);
1980 __swab64s (&b->dqb_isoftlimit);
1981 __swab64s (&b->dqb_curinodes);
1982 __swab64s (&b->dqb_bhardlimit);
1983 __swab64s (&b->dqb_bsoftlimit);
1984 __swab64s (&b->dqb_curspace);
1985 __swab64s (&b->dqb_btime);
1986 __swab64s (&b->dqb_itime);
1987 __swab32s (&b->dqb_valid);
1988 CLASSERT(offsetof(typeof(*b), dqb_padding) != 0);
1991 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1993 __swab32s (&q->qc_cmd);
1994 __swab32s (&q->qc_type);
1995 __swab32s (&q->qc_id);
1996 __swab32s (&q->qc_stat);
1997 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1998 lustre_swab_obd_dqblk (&q->qc_dqblk);
2000 EXPORT_SYMBOL(lustre_swab_obd_quotactl);
2002 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
2004 __swab32s (&p->rp_uid);
2005 __swab32s (&p->rp_gid);
2006 __swab32s (&p->rp_fsuid);
2007 __swab32s (&p->rp_fsuid_h);
2008 __swab32s (&p->rp_fsgid);
2009 __swab32s (&p->rp_fsgid_h);
2010 __swab32s (&p->rp_access_perm);
2011 __swab32s (&p->rp_padding);
2013 EXPORT_SYMBOL(lustre_swab_mdt_remote_perm);
2015 void lustre_swab_fid2path(struct getinfo_fid2path *gf)
2017 lustre_swab_lu_fid(&gf->gf_fid);
2018 __swab64s(&gf->gf_recno);
2019 __swab32s(&gf->gf_linkno);
2020 __swab32s(&gf->gf_pathlen);
2022 EXPORT_SYMBOL(lustre_swab_fid2path);
2024 void lustre_swab_fiemap_extent(struct ll_fiemap_extent *fm_extent)
2026 __swab64s(&fm_extent->fe_logical);
2027 __swab64s(&fm_extent->fe_physical);
2028 __swab64s(&fm_extent->fe_length);
2029 __swab32s(&fm_extent->fe_flags);
2030 __swab32s(&fm_extent->fe_device);
2033 void lustre_swab_fiemap(struct ll_user_fiemap *fiemap)
2037 __swab64s(&fiemap->fm_start);
2038 __swab64s(&fiemap->fm_length);
2039 __swab32s(&fiemap->fm_flags);
2040 __swab32s(&fiemap->fm_mapped_extents);
2041 __swab32s(&fiemap->fm_extent_count);
2042 __swab32s(&fiemap->fm_reserved);
2044 for (i = 0; i < fiemap->fm_mapped_extents; i++)
2045 lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
2047 EXPORT_SYMBOL(lustre_swab_fiemap);
2049 void lustre_swab_idx_info(struct idx_info *ii)
2051 __swab32s(&ii->ii_magic);
2052 __swab32s(&ii->ii_flags);
2053 __swab16s(&ii->ii_count);
2054 __swab32s(&ii->ii_attrs);
2055 lustre_swab_lu_fid(&ii->ii_fid);
2056 __swab64s(&ii->ii_version);
2057 __swab64s(&ii->ii_hash_start);
2058 __swab64s(&ii->ii_hash_end);
2059 __swab16s(&ii->ii_keysize);
2060 __swab16s(&ii->ii_recsize);
2063 void lustre_swab_lip_header(struct lu_idxpage *lip)
2066 __swab32s(&lip->lip_magic);
2067 __swab16s(&lip->lip_flags);
2068 __swab16s(&lip->lip_nr);
2070 EXPORT_SYMBOL(lustre_swab_lip_header);
2072 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
2074 __swab32s(&rr->rr_opcode);
2075 __swab32s(&rr->rr_cap);
2076 __swab32s(&rr->rr_fsuid);
2077 /* rr_fsuid_h is unused */
2078 __swab32s(&rr->rr_fsgid);
2079 /* rr_fsgid_h is unused */
2080 __swab32s(&rr->rr_suppgid1);
2081 /* rr_suppgid1_h is unused */
2082 __swab32s(&rr->rr_suppgid2);
2083 /* rr_suppgid2_h is unused */
2084 lustre_swab_lu_fid(&rr->rr_fid1);
2085 lustre_swab_lu_fid(&rr->rr_fid2);
2086 __swab64s(&rr->rr_mtime);
2087 __swab64s(&rr->rr_atime);
2088 __swab64s(&rr->rr_ctime);
2089 __swab64s(&rr->rr_size);
2090 __swab64s(&rr->rr_blocks);
2091 __swab32s(&rr->rr_bias);
2092 __swab32s(&rr->rr_mode);
2093 __swab32s(&rr->rr_flags);
2094 __swab32s(&rr->rr_flags_h);
2095 __swab32s(&rr->rr_umask);
2097 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
2099 EXPORT_SYMBOL(lustre_swab_mdt_rec_reint);
2101 void lustre_swab_lov_desc (struct lov_desc *ld)
2103 __swab32s (&ld->ld_tgt_count);
2104 __swab32s (&ld->ld_active_tgt_count);
2105 __swab32s (&ld->ld_default_stripe_count);
2106 __swab32s (&ld->ld_pattern);
2107 __swab64s (&ld->ld_default_stripe_size);
2108 __swab64s (&ld->ld_default_stripe_offset);
2109 __swab32s (&ld->ld_qos_maxage);
2110 /* uuid endian insensitive */
2112 EXPORT_SYMBOL(lustre_swab_lov_desc);
2114 void lustre_swab_lmv_desc (struct lmv_desc *ld)
2116 __swab32s (&ld->ld_tgt_count);
2117 __swab32s (&ld->ld_active_tgt_count);
2118 __swab32s (&ld->ld_default_stripe_count);
2119 __swab32s (&ld->ld_pattern);
2120 __swab64s (&ld->ld_default_hash_size);
2121 __swab32s (&ld->ld_qos_maxage);
2122 /* uuid endian insensitive */
2125 /* This structure is always in little-endian */
2126 static void lustre_swab_lmv_mds_md_v1(struct lmv_mds_md_v1 *lmm1)
2130 __swab32s(&lmm1->lmv_magic);
2131 __swab32s(&lmm1->lmv_stripe_count);
2132 __swab32s(&lmm1->lmv_master_mdt_index);
2133 __swab32s(&lmm1->lmv_hash_type);
2134 __swab32s(&lmm1->lmv_layout_version);
2135 for (i = 0; i < lmm1->lmv_stripe_count; i++)
2136 lustre_swab_lu_fid(&lmm1->lmv_stripe_fids[i]);
2139 void lustre_swab_lmv_mds_md(union lmv_mds_md *lmm)
2141 switch (lmm->lmv_magic) {
2143 lustre_swab_lmv_mds_md_v1(&lmm->lmv_md_v1);
2149 EXPORT_SYMBOL(lustre_swab_lmv_mds_md);
2151 void lustre_swab_lmv_user_md(struct lmv_user_md *lum)
2153 __swab32s(&lum->lum_magic);
2154 __swab32s(&lum->lum_stripe_count);
2155 __swab32s(&lum->lum_stripe_offset);
2156 __swab32s(&lum->lum_hash_type);
2157 __swab32s(&lum->lum_type);
2158 CLASSERT(offsetof(typeof(*lum), lum_padding1) != 0);
2160 EXPORT_SYMBOL(lustre_swab_lmv_user_md);
2162 static void print_lum (struct lov_user_md *lum)
2164 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
2165 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
2166 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2167 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lmm_oi_id(&lum->lmm_oi));
2168 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lmm_oi_seq(&lum->lmm_oi));
2169 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2170 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2171 CDEBUG(D_OTHER, "\tlmm_stripe_offset/lmm_layout_gen: %#x\n",
2172 lum->lmm_stripe_offset);
2175 static void lustre_swab_lmm_oi(struct ost_id *oi)
2177 __swab64s(&oi->oi.oi_id);
2178 __swab64s(&oi->oi.oi_seq);
2181 static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
2184 __swab32s(&lum->lmm_magic);
2185 __swab32s(&lum->lmm_pattern);
2186 lustre_swab_lmm_oi(&lum->lmm_oi);
2187 __swab32s(&lum->lmm_stripe_size);
2188 __swab16s(&lum->lmm_stripe_count);
2189 __swab16s(&lum->lmm_stripe_offset);
2194 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
2197 CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
2198 lustre_swab_lov_user_md_common(lum);
2201 EXPORT_SYMBOL(lustre_swab_lov_user_md_v1);
2203 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum)
2206 CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
2207 lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
2208 /* lmm_pool_name nothing to do with char */
2211 EXPORT_SYMBOL(lustre_swab_lov_user_md_v3);
2213 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2216 CDEBUG(D_IOCTL, "swabbing lov_mds_md\n");
2217 __swab32s(&lmm->lmm_magic);
2218 __swab32s(&lmm->lmm_pattern);
2219 lustre_swab_lmm_oi(&lmm->lmm_oi);
2220 __swab32s(&lmm->lmm_stripe_size);
2221 __swab16s(&lmm->lmm_stripe_count);
2222 __swab16s(&lmm->lmm_layout_gen);
2225 EXPORT_SYMBOL(lustre_swab_lov_mds_md);
2227 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
2232 for (i = 0; i < stripe_count; i++) {
2233 lustre_swab_ost_id(&(lod[i].l_ost_oi));
2234 __swab32s(&(lod[i].l_ost_gen));
2235 __swab32s(&(lod[i].l_ost_idx));
2239 EXPORT_SYMBOL(lustre_swab_lov_user_md_objects);
2241 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2245 for (i = 0; i < RES_NAME_SIZE; i++)
2246 __swab64s (&id->name[i]);
2248 EXPORT_SYMBOL(lustre_swab_ldlm_res_id);
2250 void lustre_swab_ldlm_policy_data (ldlm_wire_policy_data_t *d)
2252 /* the lock data is a union and the first two fields are always an
2253 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2254 * data the same way. */
2255 __swab64s(&d->l_extent.start);
2256 __swab64s(&d->l_extent.end);
2257 __swab64s(&d->l_extent.gid);
2258 __swab64s(&d->l_flock.lfw_owner);
2259 __swab32s(&d->l_flock.lfw_pid);
2261 EXPORT_SYMBOL(lustre_swab_ldlm_policy_data);
2263 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2265 __swab64s (&i->opc);
2267 EXPORT_SYMBOL(lustre_swab_ldlm_intent);
2269 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2271 __swab32s (&r->lr_type);
2272 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2273 lustre_swab_ldlm_res_id (&r->lr_name);
2275 EXPORT_SYMBOL(lustre_swab_ldlm_resource_desc);
2277 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2279 lustre_swab_ldlm_resource_desc (&l->l_resource);
2280 __swab32s (&l->l_req_mode);
2281 __swab32s (&l->l_granted_mode);
2282 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2284 EXPORT_SYMBOL(lustre_swab_ldlm_lock_desc);
2286 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2288 __swab32s (&rq->lock_flags);
2289 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2290 __swab32s (&rq->lock_count);
2291 /* lock_handle[] opaque */
2293 EXPORT_SYMBOL(lustre_swab_ldlm_request);
2295 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2297 __swab32s (&r->lock_flags);
2298 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2299 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2300 /* lock_handle opaque */
2301 __swab64s (&r->lock_policy_res1);
2302 __swab64s (&r->lock_policy_res2);
2304 EXPORT_SYMBOL(lustre_swab_ldlm_reply);
2306 void lustre_swab_quota_body(struct quota_body *b)
2308 lustre_swab_lu_fid(&b->qb_fid);
2309 lustre_swab_lu_fid((struct lu_fid *)&b->qb_id);
2310 __swab32s(&b->qb_flags);
2311 __swab64s(&b->qb_count);
2312 __swab64s(&b->qb_usage);
2313 __swab64s(&b->qb_slv_ver);
2316 /* Dump functions */
2317 void dump_ioo(struct obd_ioobj *ioo)
2320 "obd_ioobj: ioo_oid="DOSTID", ioo_max_brw=%#x, "
2321 "ioo_bufct=%d\n", POSTID(&ioo->ioo_oid), ioo->ioo_max_brw,
2324 EXPORT_SYMBOL(dump_ioo);
2326 void dump_rniobuf(struct niobuf_remote *nb)
2328 CDEBUG(D_RPCTRACE, "niobuf_remote: offset="LPU64", len=%d, flags=%x\n",
2329 nb->rnb_offset, nb->rnb_len, nb->rnb_flags);
2331 EXPORT_SYMBOL(dump_rniobuf);
2333 void dump_obdo(struct obdo *oa)
2335 __u32 valid = oa->o_valid;
2337 CDEBUG(D_RPCTRACE, "obdo: o_valid = %08x\n", valid);
2338 if (valid & OBD_MD_FLID)
2339 CDEBUG(D_RPCTRACE, "obdo: id = "DOSTID"\n", POSTID(&oa->o_oi));
2340 if (valid & OBD_MD_FLFID)
2341 CDEBUG(D_RPCTRACE, "obdo: o_parent_seq = "LPX64"\n",
2343 if (valid & OBD_MD_FLSIZE)
2344 CDEBUG(D_RPCTRACE, "obdo: o_size = "LPD64"\n", oa->o_size);
2345 if (valid & OBD_MD_FLMTIME)
2346 CDEBUG(D_RPCTRACE, "obdo: o_mtime = "LPD64"\n", oa->o_mtime);
2347 if (valid & OBD_MD_FLATIME)
2348 CDEBUG(D_RPCTRACE, "obdo: o_atime = "LPD64"\n", oa->o_atime);
2349 if (valid & OBD_MD_FLCTIME)
2350 CDEBUG(D_RPCTRACE, "obdo: o_ctime = "LPD64"\n", oa->o_ctime);
2351 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
2352 CDEBUG(D_RPCTRACE, "obdo: o_blocks = "LPD64"\n", oa->o_blocks);
2353 if (valid & OBD_MD_FLGRANT)
2354 CDEBUG(D_RPCTRACE, "obdo: o_grant = "LPD64"\n", oa->o_grant);
2355 if (valid & OBD_MD_FLBLKSZ)
2356 CDEBUG(D_RPCTRACE, "obdo: o_blksize = %d\n", oa->o_blksize);
2357 if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
2358 CDEBUG(D_RPCTRACE, "obdo: o_mode = %o\n",
2359 oa->o_mode & ((valid & OBD_MD_FLTYPE ? S_IFMT : 0) |
2360 (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
2361 if (valid & OBD_MD_FLUID)
2362 CDEBUG(D_RPCTRACE, "obdo: o_uid = %u\n", oa->o_uid);
2363 if (valid & OBD_MD_FLUID)
2364 CDEBUG(D_RPCTRACE, "obdo: o_uid_h = %u\n", oa->o_uid_h);
2365 if (valid & OBD_MD_FLGID)
2366 CDEBUG(D_RPCTRACE, "obdo: o_gid = %u\n", oa->o_gid);
2367 if (valid & OBD_MD_FLGID)
2368 CDEBUG(D_RPCTRACE, "obdo: o_gid_h = %u\n", oa->o_gid_h);
2369 if (valid & OBD_MD_FLFLAGS)
2370 CDEBUG(D_RPCTRACE, "obdo: o_flags = %x\n", oa->o_flags);
2371 if (valid & OBD_MD_FLNLINK)
2372 CDEBUG(D_RPCTRACE, "obdo: o_nlink = %u\n", oa->o_nlink);
2373 else if (valid & OBD_MD_FLCKSUM)
2374 CDEBUG(D_RPCTRACE, "obdo: o_checksum (o_nlink) = %u\n",
2376 if (valid & OBD_MD_FLGENER)
2377 CDEBUG(D_RPCTRACE, "obdo: o_parent_oid = %x\n",
2379 if (valid & OBD_MD_FLEPOCH)
2380 CDEBUG(D_RPCTRACE, "obdo: o_ioepoch = "LPD64"\n",
2382 if (valid & OBD_MD_FLFID) {
2383 CDEBUG(D_RPCTRACE, "obdo: o_stripe_idx = %u\n",
2385 CDEBUG(D_RPCTRACE, "obdo: o_parent_ver = %x\n",
2388 if (valid & OBD_MD_FLHANDLE)
2389 CDEBUG(D_RPCTRACE, "obdo: o_handle = "LPD64"\n",
2390 oa->o_handle.cookie);
2391 if (valid & OBD_MD_FLCOOKIE)
2392 CDEBUG(D_RPCTRACE, "obdo: o_lcookie = "
2393 "(llog_cookie dumping not yet implemented)\n");
2395 EXPORT_SYMBOL(dump_obdo);
2397 void dump_ost_body(struct ost_body *ob)
2401 EXPORT_SYMBOL(dump_ost_body);
2403 void dump_rcs(__u32 *rc)
2405 CDEBUG(D_RPCTRACE, "rmf_rcs: %d\n", *rc);
2407 EXPORT_SYMBOL(dump_rcs);
2409 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2411 LASSERT(req->rq_reqmsg);
2413 switch (req->rq_reqmsg->lm_magic) {
2414 case LUSTRE_MSG_MAGIC_V2:
2415 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2417 CERROR("bad lustre msg magic: %#08X\n",
2418 req->rq_reqmsg->lm_magic);
2423 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2425 LASSERT(req->rq_repmsg);
2427 switch (req->rq_repmsg->lm_magic) {
2428 case LUSTRE_MSG_MAGIC_V2:
2429 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2431 /* uninitialized yet */
2436 void _debug_req(struct ptlrpc_request *req,
2437 struct libcfs_debug_msg_data *msgdata,
2438 const char *fmt, ... )
2440 int req_ok = req->rq_reqmsg != NULL;
2441 int rep_ok = req->rq_repmsg != NULL;
2442 lnet_nid_t nid = LNET_NID_ANY;
2445 if (ptlrpc_req_need_swab(req)) {
2446 req_ok = req_ok && req_ptlrpc_body_swabbed(req);
2447 rep_ok = rep_ok && rep_ptlrpc_body_swabbed(req);
2450 if (req->rq_import && req->rq_import->imp_connection)
2451 nid = req->rq_import->imp_connection->c_peer.nid;
2452 else if (req->rq_export && req->rq_export->exp_connection)
2453 nid = req->rq_export->exp_connection->c_peer.nid;
2455 va_start(args, fmt);
2456 libcfs_debug_vmsg2(msgdata, fmt, args,
2457 " req@%p x"LPU64"/t"LPD64"("LPD64") o%d->%s@%s:%d/%d"
2458 " lens %d/%d e %d to %d dl "CFS_TIME_T" ref %d "
2459 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2460 req, req->rq_xid, req->rq_transno,
2461 req_ok ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2462 req_ok ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2464 req->rq_import->imp_obd->obd_name :
2466 req->rq_export->exp_client_uuid.uuid :
2468 libcfs_nid2str(nid),
2469 req->rq_request_portal, req->rq_reply_portal,
2470 req->rq_reqlen, req->rq_replen,
2471 req->rq_early_count, req->rq_timedout,
2473 atomic_read(&req->rq_refcount),
2474 DEBUG_REQ_FLAGS(req),
2475 req_ok ? lustre_msg_get_flags(req->rq_reqmsg) : -1,
2476 rep_ok ? lustre_msg_get_flags(req->rq_repmsg) : -1,
2478 rep_ok ? lustre_msg_get_status(req->rq_repmsg) : -1);
2481 EXPORT_SYMBOL(_debug_req);
2483 void lustre_swab_lustre_capa(struct lustre_capa *c)
2485 lustre_swab_lu_fid(&c->lc_fid);
2486 __swab64s (&c->lc_opc);
2487 __swab64s (&c->lc_uid);
2488 __swab64s (&c->lc_gid);
2489 __swab32s (&c->lc_flags);
2490 __swab32s (&c->lc_keyid);
2491 __swab32s (&c->lc_timeout);
2492 __swab32s (&c->lc_expiry);
2494 EXPORT_SYMBOL(lustre_swab_lustre_capa);
2496 void lustre_swab_lustre_capa_key(struct lustre_capa_key *k)
2498 __swab64s (&k->lk_seq);
2499 __swab32s (&k->lk_keyid);
2500 CLASSERT(offsetof(typeof(*k), lk_padding) != 0);
2502 EXPORT_SYMBOL(lustre_swab_lustre_capa_key);
2504 void lustre_swab_hsm_user_state(struct hsm_user_state *state)
2506 __swab32s(&state->hus_states);
2507 __swab32s(&state->hus_archive_id);
2509 EXPORT_SYMBOL(lustre_swab_hsm_user_state);
2511 void lustre_swab_hsm_state_set(struct hsm_state_set *hss)
2513 __swab32s(&hss->hss_valid);
2514 __swab64s(&hss->hss_setmask);
2515 __swab64s(&hss->hss_clearmask);
2516 __swab32s(&hss->hss_archive_id);
2518 EXPORT_SYMBOL(lustre_swab_hsm_state_set);
2520 void lustre_swab_hsm_extent(struct hsm_extent *extent)
2522 __swab64s(&extent->offset);
2523 __swab64s(&extent->length);
2526 void lustre_swab_hsm_current_action(struct hsm_current_action *action)
2528 __swab32s(&action->hca_state);
2529 __swab32s(&action->hca_action);
2530 lustre_swab_hsm_extent(&action->hca_location);
2532 EXPORT_SYMBOL(lustre_swab_hsm_current_action);
2534 void lustre_swab_hsm_user_item(struct hsm_user_item *hui)
2536 lustre_swab_lu_fid(&hui->hui_fid);
2537 lustre_swab_hsm_extent(&hui->hui_extent);
2539 EXPORT_SYMBOL(lustre_swab_hsm_user_item);
2541 void lustre_swab_layout_intent(struct layout_intent *li)
2543 __swab32s(&li->li_opc);
2544 __swab32s(&li->li_flags);
2545 __swab64s(&li->li_start);
2546 __swab64s(&li->li_end);
2548 EXPORT_SYMBOL(lustre_swab_layout_intent);
2550 void lustre_swab_hsm_progress_kernel(struct hsm_progress_kernel *hpk)
2552 lustre_swab_lu_fid(&hpk->hpk_fid);
2553 __swab64s(&hpk->hpk_cookie);
2554 __swab64s(&hpk->hpk_extent.offset);
2555 __swab64s(&hpk->hpk_extent.length);
2556 __swab16s(&hpk->hpk_flags);
2557 __swab16s(&hpk->hpk_errval);
2559 EXPORT_SYMBOL(lustre_swab_hsm_progress_kernel);
2561 void lustre_swab_hsm_request(struct hsm_request *hr)
2563 __swab32s(&hr->hr_action);
2564 __swab32s(&hr->hr_archive_id);
2565 __swab64s(&hr->hr_flags);
2566 __swab32s(&hr->hr_itemcount);
2567 __swab32s(&hr->hr_data_len);
2569 EXPORT_SYMBOL(lustre_swab_hsm_request);
2571 void lustre_swab_object_update(struct object_update *ou)
2573 struct object_update_param *param;
2576 __swab16s(&ou->ou_type);
2577 __swab16s(&ou->ou_params_count);
2578 __swab32s(&ou->ou_master_index);
2579 __swab32s(&ou->ou_flags);
2580 __swab32s(&ou->ou_padding1);
2581 __swab64s(&ou->ou_batchid);
2582 lustre_swab_lu_fid(&ou->ou_fid);
2583 param = &ou->ou_params[0];
2584 for (i = 0; i < ou->ou_params_count; i++) {
2585 __swab16s(¶m->oup_len);
2586 __swab16s(¶m->oup_padding);
2587 __swab32s(¶m->oup_padding2);
2588 param = (struct object_update_param *)((char *)param +
2589 object_update_param_size(param));
2592 EXPORT_SYMBOL(lustre_swab_object_update);
2594 void lustre_swab_object_update_request(struct object_update_request *our)
2597 __swab32s(&our->ourq_magic);
2598 __swab16s(&our->ourq_count);
2599 __swab16s(&our->ourq_padding);
2600 for (i = 0; i < our->ourq_count; i++) {
2601 struct object_update *ou;
2603 ou = object_update_request_get(our, i, NULL);
2606 lustre_swab_object_update(ou);
2609 EXPORT_SYMBOL(lustre_swab_object_update_request);
2611 void lustre_swab_object_update_result(struct object_update_result *our)
2613 __swab32s(&our->our_rc);
2614 __swab16s(&our->our_datalen);
2615 __swab16s(&our->our_padding);
2617 EXPORT_SYMBOL(lustre_swab_object_update_result);
2619 void lustre_swab_object_update_reply(struct object_update_reply *our)
2623 __swab32s(&our->ourp_magic);
2624 __swab16s(&our->ourp_count);
2625 __swab16s(&our->ourp_padding);
2626 for (i = 0; i < our->ourp_count; i++) {
2627 struct object_update_result *ourp;
2629 __swab16s(&our->ourp_lens[i]);
2630 ourp = object_update_result_get(our, i, NULL);
2633 lustre_swab_object_update_result(ourp);
2636 EXPORT_SYMBOL(lustre_swab_object_update_reply);
2638 void lustre_swab_swap_layouts(struct mdc_swap_layouts *msl)
2640 __swab64s(&msl->msl_flags);
2642 EXPORT_SYMBOL(lustre_swab_swap_layouts);
2644 void lustre_swab_close_data(struct close_data *cd)
2646 lustre_swab_lu_fid(&cd->cd_fid);
2647 __swab64s(&cd->cd_data_version);
2649 EXPORT_SYMBOL(lustre_swab_close_data);
2651 void lustre_swab_lfsck_request(struct lfsck_request *lr)
2653 __swab32s(&lr->lr_event);
2654 __swab32s(&lr->lr_index);
2655 __swab32s(&lr->lr_flags);
2656 __swab32s(&lr->lr_valid);
2657 __swab32s(&lr->lr_speed);
2658 __swab16s(&lr->lr_version);
2659 __swab16s(&lr->lr_active);
2660 __swab16s(&lr->lr_param);
2661 __swab16s(&lr->lr_async_windows);
2662 CLASSERT(offsetof(typeof(*lr), lr_padding_1) != 0);
2663 lustre_swab_lu_fid(&lr->lr_fid);
2664 lustre_swab_lu_fid(&lr->lr_fid2);
2665 lustre_swab_lu_fid(&lr->lr_fid3);
2666 CLASSERT(offsetof(typeof(*lr), lr_padding_2) != 0);
2667 CLASSERT(offsetof(typeof(*lr), lr_padding_3) != 0);
2669 EXPORT_SYMBOL(lustre_swab_lfsck_request);
2671 void lustre_swab_lfsck_reply(struct lfsck_reply *lr)
2673 __swab32s(&lr->lr_status);
2674 CLASSERT(offsetof(typeof(*lr), lr_padding_1) != 0);
2675 CLASSERT(offsetof(typeof(*lr), lr_padding_2) != 0);
2677 EXPORT_SYMBOL(lustre_swab_lfsck_reply);
2679 void lustre_swab_orphan_ent(struct lu_orphan_ent *ent)
2681 lustre_swab_lu_fid(&ent->loe_key);
2682 lustre_swab_lu_fid(&ent->loe_rec.lor_fid);
2683 __swab32s(&ent->loe_rec.lor_uid);
2684 __swab32s(&ent->loe_rec.lor_gid);
2686 EXPORT_SYMBOL(lustre_swab_orphan_ent);