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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/ptlrpc/pack_generic.c
34 * (Un)packing of OST requests
36 * Author: Peter J. Braam <braam@clusterfs.com>
37 * Author: Phil Schwan <phil@clusterfs.com>
38 * Author: Eric Barton <eeb@clusterfs.com>
41 #define DEBUG_SUBSYSTEM S_RPC
43 #include <linux/crc32.h>
45 #include <libcfs/libcfs.h>
47 #include <llog_swab.h>
48 #include <lustre_net.h>
49 #include <lustre_swab.h>
50 #include <obd_cksum.h>
51 #include <obd_class.h>
52 #include <obd_support.h>
53 #include <obj_update.h>
55 #include "ptlrpc_internal.h"
57 static inline __u32 lustre_msg_hdr_size_v2(__u32 count)
59 return cfs_size_round(offsetof(struct lustre_msg_v2,
63 __u32 lustre_msg_hdr_size(__u32 magic, __u32 count)
68 case LUSTRE_MSG_MAGIC_V2:
69 return lustre_msg_hdr_size_v2(count);
71 LASSERTF(0, "incorrect message magic: %08x\n", magic);
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 bool 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) && !lustre_rep_swabbed(req, index));
95 static inline int lustre_msg_check_version_v2(struct lustre_msg_v2 *msg,
96 enum lustre_msg_version version)
98 enum lustre_msg_version ver = lustre_msg_get_version(msg);
100 return (ver & LUSTRE_VERSION_MASK) != version;
103 int lustre_msg_check_version(struct lustre_msg *msg,
104 enum lustre_msg_version version)
106 #define LUSTRE_MSG_MAGIC_V1 0x0BD00BD0
107 switch (msg->lm_magic) {
108 case LUSTRE_MSG_MAGIC_V1:
109 CERROR("msg v1 not supported - please upgrade you system\n");
111 case LUSTRE_MSG_MAGIC_V2:
112 return lustre_msg_check_version_v2(msg, version);
114 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
117 #undef LUSTRE_MSG_MAGIC_V1
120 /* early reply size */
121 __u32 lustre_msg_early_size()
123 __u32 pblen = sizeof(struct ptlrpc_body);
125 return lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, &pblen);
127 EXPORT_SYMBOL(lustre_msg_early_size);
129 __u32 lustre_msg_size_v2(int count, __u32 *lengths)
135 size = lustre_msg_hdr_size_v2(count);
136 for (i = 0; i < count; i++)
137 size += cfs_size_round(lengths[i]);
141 EXPORT_SYMBOL(lustre_msg_size_v2);
144 * This returns the size of the buffer that is required to hold a lustre_msg
145 * with the given sub-buffer lengths.
146 * NOTE: this should only be used for NEW requests, and should always be
147 * in the form of a v2 request. If this is a connection to a v1
148 * target then the first buffer will be stripped because the ptlrpc
149 * data is part of the lustre_msg_v1 header. b=14043
151 __u32 lustre_msg_size(__u32 magic, int count, __u32 *lens)
153 __u32 size[] = { sizeof(struct ptlrpc_body) };
161 LASSERT(lens[MSG_PTLRPC_BODY_OFF] >= sizeof(struct ptlrpc_body_v2));
164 case LUSTRE_MSG_MAGIC_V2:
165 return lustre_msg_size_v2(count, lens);
167 LASSERTF(0, "incorrect message magic: %08x\n", magic);
173 * This is used to determine the size of a buffer that was already packed
174 * and will correctly handle the different message formats.
176 __u32 lustre_packed_msg_size(struct lustre_msg *msg)
178 switch (msg->lm_magic) {
179 case LUSTRE_MSG_MAGIC_V2:
180 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
182 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
186 EXPORT_SYMBOL(lustre_packed_msg_size);
188 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
196 msg->lm_bufcount = count;
197 /* XXX: lm_secflvr uninitialized here */
198 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
200 for (i = 0; i < count; i++)
201 msg->lm_buflens[i] = lens[i];
206 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
207 for (i = 0; i < count; i++) {
211 memcpy(ptr, tmp, lens[i]);
212 ptr += cfs_size_round(lens[i]);
215 EXPORT_SYMBOL(lustre_init_msg_v2);
217 static int lustre_pack_request_v2(struct ptlrpc_request *req,
218 int count, __u32 *lens, char **bufs)
222 reqlen = lustre_msg_size_v2(count, lens);
224 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
228 req->rq_reqlen = reqlen;
230 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
231 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
235 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
236 __u32 *lens, char **bufs)
238 __u32 size[] = { sizeof(struct ptlrpc_body) };
246 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
248 /* only use new format, we don't need to be compatible with 1.4 */
249 magic = LUSTRE_MSG_MAGIC_V2;
252 case LUSTRE_MSG_MAGIC_V2:
253 return lustre_pack_request_v2(req, count, lens, bufs);
255 LASSERTF(0, "incorrect message magic: %08x\n", magic);
261 struct list_head ptlrpc_rs_debug_lru =
262 LIST_HEAD_INIT(ptlrpc_rs_debug_lru);
263 spinlock_t ptlrpc_rs_debug_lock;
265 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
267 spin_lock(&ptlrpc_rs_debug_lock); \
268 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
269 spin_unlock(&ptlrpc_rs_debug_lock); \
272 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
274 spin_lock(&ptlrpc_rs_debug_lock); \
275 list_del(&(rs)->rs_debug_list); \
276 spin_unlock(&ptlrpc_rs_debug_lock); \
279 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
280 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
283 struct ptlrpc_reply_state *
284 lustre_get_emerg_rs(struct ptlrpc_service_part *svcpt)
286 struct ptlrpc_reply_state *rs = NULL;
288 spin_lock(&svcpt->scp_rep_lock);
290 /* See if we have anything in a pool, and wait if nothing */
291 while (list_empty(&svcpt->scp_rep_idle)) {
294 spin_unlock(&svcpt->scp_rep_lock);
295 /* If we cannot get anything for some long time, we better
296 * bail out instead of waiting infinitely */
297 rc = wait_event_idle_timeout(svcpt->scp_rep_waitq,
298 !list_empty(&svcpt->scp_rep_idle),
299 cfs_time_seconds(10));
302 spin_lock(&svcpt->scp_rep_lock);
305 rs = list_entry(svcpt->scp_rep_idle.next,
306 struct ptlrpc_reply_state, rs_list);
307 list_del(&rs->rs_list);
309 spin_unlock(&svcpt->scp_rep_lock);
311 memset(rs, 0, svcpt->scp_service->srv_max_reply_size);
312 rs->rs_size = svcpt->scp_service->srv_max_reply_size;
313 rs->rs_svcpt = svcpt;
319 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
321 struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
323 spin_lock(&svcpt->scp_rep_lock);
324 list_add(&rs->rs_list, &svcpt->scp_rep_idle);
325 spin_unlock(&svcpt->scp_rep_lock);
326 wake_up(&svcpt->scp_rep_waitq);
329 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
330 __u32 *lens, char **bufs, int flags)
332 struct ptlrpc_reply_state *rs;
336 LASSERT(req->rq_reply_state == NULL);
339 if ((flags & LPRFL_EARLY_REPLY) == 0) {
340 spin_lock(&req->rq_lock);
341 req->rq_packed_final = 1;
342 spin_unlock(&req->rq_lock);
345 msg_len = lustre_msg_size_v2(count, lens);
346 rc = sptlrpc_svc_alloc_rs(req, msg_len);
350 rs = req->rq_reply_state;
351 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
352 rs->rs_cb_id.cbid_fn = reply_out_callback;
353 rs->rs_cb_id.cbid_arg = rs;
354 rs->rs_svcpt = req->rq_rqbd->rqbd_svcpt;
355 INIT_LIST_HEAD(&rs->rs_exp_list);
356 INIT_LIST_HEAD(&rs->rs_obd_list);
357 INIT_LIST_HEAD(&rs->rs_list);
358 spin_lock_init(&rs->rs_lock);
360 req->rq_replen = msg_len;
361 req->rq_reply_state = rs;
362 req->rq_repmsg = rs->rs_msg;
364 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
365 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
367 PTLRPC_RS_DEBUG_LRU_ADD(rs);
371 EXPORT_SYMBOL(lustre_pack_reply_v2);
373 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, __u32 *lens,
374 char **bufs, int flags)
377 __u32 size[] = { sizeof(struct ptlrpc_body) };
385 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
387 switch (req->rq_reqmsg->lm_magic) {
388 case LUSTRE_MSG_MAGIC_V2:
389 rc = lustre_pack_reply_v2(req, count, lens, bufs, flags);
392 LASSERTF(0, "incorrect message magic: %08x\n",
393 req->rq_reqmsg->lm_magic);
397 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
398 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
402 int lustre_pack_reply(struct ptlrpc_request *req, int count, __u32 *lens,
405 return lustre_pack_reply_flags(req, count, lens, bufs, 0);
407 EXPORT_SYMBOL(lustre_pack_reply);
409 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, __u32 n, __u32 min_size)
411 __u32 i, offset, buflen, bufcount;
414 LASSERT(m->lm_bufcount > 0);
416 bufcount = m->lm_bufcount;
417 if (unlikely(n >= bufcount)) {
418 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
423 buflen = m->lm_buflens[n];
424 if (unlikely(buflen < min_size)) {
425 CERROR("msg %p buffer[%d] size %d too small "
426 "(required %d, opc=%d)\n", m, n, buflen, min_size,
427 n == MSG_PTLRPC_BODY_OFF ? -1 : lustre_msg_get_opc(m));
431 offset = lustre_msg_hdr_size_v2(bufcount);
432 for (i = 0; i < n; i++)
433 offset += cfs_size_round(m->lm_buflens[i]);
435 return (char *)m + offset;
438 void *lustre_msg_buf(struct lustre_msg *m, __u32 n, __u32 min_size)
440 switch (m->lm_magic) {
441 case LUSTRE_MSG_MAGIC_V2:
442 return lustre_msg_buf_v2(m, n, min_size);
444 LASSERTF(0, "incorrect message magic: %08x (msg:%p)\n",
449 EXPORT_SYMBOL(lustre_msg_buf);
451 static int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, __u32 segment,
452 unsigned int newlen, int move_data)
454 char *tail = NULL, *newpos;
458 LASSERT(msg->lm_bufcount > segment);
459 LASSERT(msg->lm_buflens[segment] >= newlen);
461 if (msg->lm_buflens[segment] == newlen)
464 if (move_data && msg->lm_bufcount > segment + 1) {
465 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
466 for (n = segment + 1; n < msg->lm_bufcount; n++)
467 tail_len += cfs_size_round(msg->lm_buflens[n]);
470 msg->lm_buflens[segment] = newlen;
472 if (tail && tail_len) {
473 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
474 LASSERT(newpos <= tail);
476 memmove(newpos, tail, tail_len);
479 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
483 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
484 * we also move data forward from @segment + 1.
486 * if @newlen == 0, we remove the segment completely, but we still keep the
487 * totally bufcount the same to save possible data moving. this will leave a
488 * unused segment with size 0 at the tail, but that's ok.
490 * return new msg size after shrinking.
493 * + if any buffers higher than @segment has been filled in, must call shrink
494 * with non-zero @move_data.
495 * + caller should NOT keep pointers to msg buffers which higher than @segment
498 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
499 unsigned int newlen, int move_data)
501 switch (msg->lm_magic) {
502 case LUSTRE_MSG_MAGIC_V2:
503 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
505 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
508 EXPORT_SYMBOL(lustre_shrink_msg);
510 static int lustre_grow_msg_v2(struct lustre_msg_v2 *msg, __u32 segment,
513 char *tail = NULL, *newpos;
517 LASSERT(msg->lm_bufcount > segment);
518 LASSERT(msg->lm_buflens[segment] <= newlen);
520 if (msg->lm_buflens[segment] == newlen)
523 if (msg->lm_bufcount > segment + 1) {
524 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
525 for (n = segment + 1; n < msg->lm_bufcount; n++)
526 tail_len += cfs_size_round(msg->lm_buflens[n]);
529 msg->lm_buflens[segment] = newlen;
531 if (tail && tail_len) {
532 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
533 memmove(newpos, tail, tail_len);
536 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
540 * for @msg, grow @segment to size @newlen.
541 * Always move higher buffer forward.
543 * return new msg size after growing.
546 * - caller must make sure there is enough space in allocated message buffer
547 * - caller should NOT keep pointers to msg buffers which higher than @segment
550 int lustre_grow_msg(struct lustre_msg *msg, int segment, unsigned int newlen)
552 switch (msg->lm_magic) {
553 case LUSTRE_MSG_MAGIC_V2:
554 return lustre_grow_msg_v2(msg, segment, newlen);
556 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
559 EXPORT_SYMBOL(lustre_grow_msg);
561 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
563 PTLRPC_RS_DEBUG_LRU_DEL(rs);
565 LASSERT(atomic_read(&rs->rs_refcount) == 0);
566 LASSERT(!rs->rs_difficult || rs->rs_handled);
567 LASSERT(!rs->rs_on_net);
568 LASSERT(!rs->rs_scheduled);
569 LASSERT(rs->rs_export == NULL);
570 LASSERT(rs->rs_nlocks == 0);
571 LASSERT(list_empty(&rs->rs_exp_list));
572 LASSERT(list_empty(&rs->rs_obd_list));
574 sptlrpc_svc_free_rs(rs);
577 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
579 int swabbed, required_len, i, buflen;
581 /* Now we know the sender speaks my language. */
582 required_len = lustre_msg_hdr_size_v2(0);
583 if (len < required_len) {
584 /* can't even look inside the message */
585 CERROR("message length %d too small for lustre_msg\n", len);
589 swabbed = (m->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
592 __swab32s(&m->lm_magic);
593 __swab32s(&m->lm_bufcount);
594 __swab32s(&m->lm_secflvr);
595 __swab32s(&m->lm_repsize);
596 __swab32s(&m->lm_cksum);
597 __swab32s(&m->lm_flags);
598 BUILD_BUG_ON(offsetof(typeof(*m), lm_padding_2) == 0);
599 BUILD_BUG_ON(offsetof(typeof(*m), lm_padding_3) == 0);
602 if (m->lm_bufcount == 0 || m->lm_bufcount > PTLRPC_MAX_BUFCOUNT) {
603 CERROR("message bufcount %d is not valid\n", m->lm_bufcount);
606 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
607 if (len < required_len) {
608 /* didn't receive all the buffer lengths */
609 CERROR("message length %d too small for %d buflens\n",
610 len, m->lm_bufcount);
614 for (i = 0; i < m->lm_bufcount; i++) {
616 __swab32s(&m->lm_buflens[i]);
617 buflen = cfs_size_round(m->lm_buflens[i]);
618 if (buflen < 0 || buflen > PTLRPC_MAX_BUFLEN) {
619 CERROR("buffer %d length %d is not valid\n", i, buflen);
622 required_len += buflen;
624 if (len < required_len || required_len > PTLRPC_MAX_BUFLEN) {
625 CERROR("len: %d, required_len %d, bufcount: %d\n",
626 len, required_len, m->lm_bufcount);
627 for (i = 0; i < m->lm_bufcount; i++)
628 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
635 int __lustre_unpack_msg(struct lustre_msg *m, int len)
637 int required_len, rc;
641 * We can provide a slightly better error log, if we check the
642 * message magic and version first. In the future, struct
643 * lustre_msg may grow, and we'd like to log a version mismatch,
644 * rather than a short message.
646 required_len = offsetof(struct lustre_msg, lm_magic) +
648 if (len < required_len) {
649 /* can't even look inside the message */
650 CERROR("message length %d too small for magic/version check\n",
655 rc = lustre_unpack_msg_v2(m, len);
659 EXPORT_SYMBOL(__lustre_unpack_msg);
661 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len)
665 rc = __lustre_unpack_msg(req->rq_reqmsg, len);
667 lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
673 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len)
677 rc = __lustre_unpack_msg(req->rq_repmsg, len);
679 lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
685 static inline int lustre_unpack_ptlrpc_body_v2(struct ptlrpc_request *req,
686 const int inout, int offset)
688 struct ptlrpc_body *pb;
689 struct lustre_msg_v2 *m = inout ? req->rq_reqmsg : req->rq_repmsg;
691 pb = lustre_msg_buf_v2(m, offset, sizeof(struct ptlrpc_body_v2));
693 CERROR("error unpacking ptlrpc body\n");
696 if (ptlrpc_buf_need_swab(req, inout, offset)) {
697 lustre_swab_ptlrpc_body(pb);
698 ptlrpc_buf_set_swabbed(req, inout, offset);
701 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
702 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
707 pb->pb_status = ptlrpc_status_ntoh(pb->pb_status);
712 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
714 switch (req->rq_reqmsg->lm_magic) {
715 case LUSTRE_MSG_MAGIC_V2:
716 return lustre_unpack_ptlrpc_body_v2(req, 1, offset);
718 CERROR("bad lustre msg magic: %08x\n",
719 req->rq_reqmsg->lm_magic);
724 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
726 switch (req->rq_repmsg->lm_magic) {
727 case LUSTRE_MSG_MAGIC_V2:
728 return lustre_unpack_ptlrpc_body_v2(req, 0, offset);
730 CERROR("bad lustre msg magic: %08x\n",
731 req->rq_repmsg->lm_magic);
736 static inline __u32 lustre_msg_buflen_v2(struct lustre_msg_v2 *m, __u32 n)
738 if (n >= m->lm_bufcount)
741 return m->lm_buflens[n];
745 * lustre_msg_buflen - return the length of buffer \a n in message \a m
746 * \param m lustre_msg (request or reply) to look at
747 * \param n message index (base 0)
749 * returns zero for non-existent message indices
751 __u32 lustre_msg_buflen(struct lustre_msg *m, __u32 n)
753 switch (m->lm_magic) {
754 case LUSTRE_MSG_MAGIC_V2:
755 return lustre_msg_buflen_v2(m, n);
757 CERROR("incorrect message magic: %08x\n", m->lm_magic);
761 EXPORT_SYMBOL(lustre_msg_buflen);
764 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, __u32 n, __u32 len)
766 if (n >= m->lm_bufcount)
769 m->lm_buflens[n] = len;
772 void lustre_msg_set_buflen(struct lustre_msg *m, __u32 n, __u32 len)
774 switch (m->lm_magic) {
775 case LUSTRE_MSG_MAGIC_V2:
776 lustre_msg_set_buflen_v2(m, n, len);
779 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
784 * NB return the bufcount for lustre_msg_v2 format, so if message is packed
785 * in V1 format, the result is one bigger. (add struct ptlrpc_body).
787 __u32 lustre_msg_bufcount(struct lustre_msg *m)
789 switch (m->lm_magic) {
790 case LUSTRE_MSG_MAGIC_V2:
791 return m->lm_bufcount;
793 CERROR("incorrect message magic: %08x\n", m->lm_magic);
798 char *lustre_msg_string(struct lustre_msg *m, __u32 index, __u32 max_len)
800 /* max_len == 0 means the string should fill the buffer */
804 switch (m->lm_magic) {
805 case LUSTRE_MSG_MAGIC_V2:
806 str = lustre_msg_buf_v2(m, index, 0);
807 blen = lustre_msg_buflen_v2(m, index);
810 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
814 CERROR("can't unpack string in msg %p buffer[%d]\n", m, index);
818 slen = strnlen(str, blen);
820 if (slen == blen) { /* not NULL terminated */
821 CERROR("can't unpack non-NULL terminated string in msg %p buffer[%d] len %d\n",
825 if (blen > PTLRPC_MAX_BUFLEN) {
826 CERROR("buffer length of msg %p buffer[%d] is invalid(%d)\n",
832 if (slen != blen - 1) {
833 CERROR("can't unpack short string in msg %p buffer[%d] len %d: strlen %d\n",
834 m, index, blen, slen);
837 } else if (slen > max_len) {
838 CERROR("can't unpack oversized string in msg %p buffer[%d] len %d strlen %d: max %d expected\n",
839 m, index, blen, slen, max_len);
846 /* Wrap up the normal fixed length cases */
847 static inline void *__lustre_swab_buf(struct lustre_msg *msg, __u32 index,
848 __u32 min_size, void *swabber)
852 LASSERT(msg != NULL);
853 switch (msg->lm_magic) {
854 case LUSTRE_MSG_MAGIC_V2:
855 ptr = lustre_msg_buf_v2(msg, index, min_size);
858 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
861 if (ptr != NULL && swabber != NULL)
862 ((void (*)(void *))swabber)(ptr);
867 static inline struct ptlrpc_body *lustre_msg_ptlrpc_body(struct lustre_msg *msg)
869 return lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
870 sizeof(struct ptlrpc_body_v2));
873 enum lustre_msghdr lustre_msghdr_get_flags(struct lustre_msg *msg)
875 switch (msg->lm_magic) {
876 case LUSTRE_MSG_MAGIC_V2:
877 /* already in host endian */
878 return msg->lm_flags;
880 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
884 EXPORT_SYMBOL(lustre_msghdr_get_flags);
886 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
888 switch (msg->lm_magic) {
889 case LUSTRE_MSG_MAGIC_V2:
890 msg->lm_flags = flags;
893 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
897 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
899 switch (msg->lm_magic) {
900 case LUSTRE_MSG_MAGIC_V2: {
901 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
905 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
910 * flags might be printed in debug code while message
916 EXPORT_SYMBOL(lustre_msg_get_flags);
918 void lustre_msg_add_flags(struct lustre_msg *msg, __u32 flags)
920 switch (msg->lm_magic) {
921 case LUSTRE_MSG_MAGIC_V2: {
922 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
923 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
924 pb->pb_flags |= flags;
928 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
931 EXPORT_SYMBOL(lustre_msg_add_flags);
933 void lustre_msg_set_flags(struct lustre_msg *msg, __u32 flags)
935 switch (msg->lm_magic) {
936 case LUSTRE_MSG_MAGIC_V2: {
937 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
938 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
939 pb->pb_flags = flags;
943 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
947 void lustre_msg_clear_flags(struct lustre_msg *msg, __u32 flags)
949 switch (msg->lm_magic) {
950 case LUSTRE_MSG_MAGIC_V2: {
951 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
952 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
953 pb->pb_flags &= ~flags;
958 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
961 EXPORT_SYMBOL(lustre_msg_clear_flags);
963 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
965 switch (msg->lm_magic) {
966 case LUSTRE_MSG_MAGIC_V2: {
967 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
969 return pb->pb_op_flags;
971 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
979 void lustre_msg_add_op_flags(struct lustre_msg *msg, __u32 flags)
981 switch (msg->lm_magic) {
982 case LUSTRE_MSG_MAGIC_V2: {
983 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
984 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
985 pb->pb_op_flags |= flags;
989 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
992 EXPORT_SYMBOL(lustre_msg_add_op_flags);
994 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
996 switch (msg->lm_magic) {
997 case LUSTRE_MSG_MAGIC_V2: {
998 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1000 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1003 return &pb->pb_handle;
1006 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1011 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1013 switch (msg->lm_magic) {
1014 case LUSTRE_MSG_MAGIC_V2: {
1015 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1017 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1018 return PTL_RPC_MSG_ERR;
1023 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1024 return PTL_RPC_MSG_ERR;
1027 EXPORT_SYMBOL(lustre_msg_get_type);
1029 enum lustre_msg_version lustre_msg_get_version(struct lustre_msg *msg)
1031 switch (msg->lm_magic) {
1032 case LUSTRE_MSG_MAGIC_V2: {
1033 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1035 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1038 return pb->pb_version;
1041 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1046 void lustre_msg_add_version(struct lustre_msg *msg, __u32 version)
1048 switch (msg->lm_magic) {
1049 case LUSTRE_MSG_MAGIC_V2: {
1050 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1051 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1052 pb->pb_version |= version;
1056 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1060 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1062 switch (msg->lm_magic) {
1063 case LUSTRE_MSG_MAGIC_V2: {
1064 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1066 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1072 CERROR("incorrect message magic: %08x (msg:%p)\n",
1073 msg->lm_magic, msg);
1077 EXPORT_SYMBOL(lustre_msg_get_opc);
1079 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1081 switch (msg->lm_magic) {
1082 case LUSTRE_MSG_MAGIC_V2: {
1083 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1085 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1088 return pb->pb_last_xid;
1091 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1095 EXPORT_SYMBOL(lustre_msg_get_last_xid);
1097 __u16 lustre_msg_get_tag(struct lustre_msg *msg)
1099 switch (msg->lm_magic) {
1100 case LUSTRE_MSG_MAGIC_V2: {
1101 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1103 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1109 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1113 EXPORT_SYMBOL(lustre_msg_get_tag);
1115 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1117 switch (msg->lm_magic) {
1118 case LUSTRE_MSG_MAGIC_V2: {
1119 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1121 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1124 return pb->pb_last_committed;
1127 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1131 EXPORT_SYMBOL(lustre_msg_get_last_committed);
1133 __u64 *lustre_msg_get_versions(struct lustre_msg *msg)
1135 switch (msg->lm_magic) {
1136 case LUSTRE_MSG_MAGIC_V2: {
1137 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1139 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1142 return pb->pb_pre_versions;
1145 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1149 EXPORT_SYMBOL(lustre_msg_get_versions);
1151 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1153 switch (msg->lm_magic) {
1154 case LUSTRE_MSG_MAGIC_V2: {
1155 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1157 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1160 return pb->pb_transno;
1163 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1167 EXPORT_SYMBOL(lustre_msg_get_transno);
1169 int lustre_msg_get_status(struct lustre_msg *msg)
1171 switch (msg->lm_magic) {
1172 case LUSTRE_MSG_MAGIC_V2: {
1173 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1175 return pb->pb_status;
1176 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1181 * status might be printed in debug code while message
1187 EXPORT_SYMBOL(lustre_msg_get_status);
1189 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1191 switch (msg->lm_magic) {
1192 case LUSTRE_MSG_MAGIC_V2: {
1193 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1195 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1201 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1207 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1209 switch (msg->lm_magic) {
1210 case LUSTRE_MSG_MAGIC_V2: {
1211 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1213 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1220 CERROR("invalid msg magic %x\n", msg->lm_magic);
1225 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1227 switch (msg->lm_magic) {
1228 case LUSTRE_MSG_MAGIC_V2: {
1229 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1231 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1234 return pb->pb_limit;
1237 CERROR("invalid msg magic %x\n", msg->lm_magic);
1243 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1245 switch (msg->lm_magic) {
1246 case LUSTRE_MSG_MAGIC_V2: {
1247 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1249 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1252 pb->pb_limit = limit;
1256 CERROR("invalid msg magic %08x\n", msg->lm_magic);
1261 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1263 switch (msg->lm_magic) {
1264 case LUSTRE_MSG_MAGIC_V2: {
1265 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1267 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1270 return pb->pb_conn_cnt;
1273 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1277 EXPORT_SYMBOL(lustre_msg_get_conn_cnt);
1279 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1281 switch (msg->lm_magic) {
1282 case LUSTRE_MSG_MAGIC_V2:
1283 return msg->lm_magic;
1285 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1290 timeout_t lustre_msg_get_timeout(struct lustre_msg *msg)
1292 switch (msg->lm_magic) {
1293 case LUSTRE_MSG_MAGIC_V2: {
1294 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1297 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1300 return pb->pb_timeout;
1303 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1308 timeout_t lustre_msg_get_service_timeout(struct lustre_msg *msg)
1310 switch (msg->lm_magic) {
1311 case LUSTRE_MSG_MAGIC_V2: {
1312 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1315 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1318 return pb->pb_service_time;
1321 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1326 char *lustre_msg_get_jobid(struct lustre_msg *msg)
1328 switch (msg->lm_magic) {
1329 case LUSTRE_MSG_MAGIC_V2: {
1330 struct ptlrpc_body *pb;
1332 /* the old pltrpc_body_v2 is smaller; doesn't include jobid */
1333 if (msg->lm_buflens[MSG_PTLRPC_BODY_OFF] <
1334 sizeof(struct ptlrpc_body))
1337 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
1338 sizeof(struct ptlrpc_body));
1342 return pb->pb_jobid;
1345 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1349 EXPORT_SYMBOL(lustre_msg_get_jobid);
1351 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1353 switch (msg->lm_magic) {
1354 case LUSTRE_MSG_MAGIC_V2:
1355 return msg->lm_cksum;
1357 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1362 __u64 lustre_msg_get_mbits(struct lustre_msg *msg)
1364 switch (msg->lm_magic) {
1365 case LUSTRE_MSG_MAGIC_V2: {
1366 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1368 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1371 return pb->pb_mbits;
1374 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1379 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg, __u32 buf)
1381 switch (msg->lm_magic) {
1382 case LUSTRE_MSG_MAGIC_V2: {
1383 struct ptlrpc_body *pb = lustre_msg_buf_v2(msg, buf, 0);
1384 __u32 len = lustre_msg_buflen(msg, buf);
1387 #if IS_ENABLED(CONFIG_CRC32)
1388 /* about 10x faster than crypto_hash for small buffers */
1389 crc = crc32_le(~(__u32)0, (unsigned char *)pb, len);
1390 #elif IS_ENABLED(CONFIG_CRYPTO_CRC32)
1391 unsigned int hsize = 4;
1393 cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb,
1394 len, NULL, 0, (unsigned char *)&crc,
1397 #error "need either CONFIG_CRC32 or CONFIG_CRYPTO_CRC32 enabled in the kernel"
1402 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1407 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
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_handle = *handle;
1417 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1421 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1423 switch (msg->lm_magic) {
1424 case LUSTRE_MSG_MAGIC_V2: {
1425 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1426 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1431 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1435 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
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);
1445 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1449 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1451 switch (msg->lm_magic) {
1452 case LUSTRE_MSG_MAGIC_V2: {
1453 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1454 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1455 pb->pb_last_xid = last_xid;
1459 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1462 EXPORT_SYMBOL(lustre_msg_set_last_xid);
1464 void lustre_msg_set_tag(struct lustre_msg *msg, __u16 tag)
1466 switch (msg->lm_magic) {
1467 case LUSTRE_MSG_MAGIC_V2: {
1468 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1469 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1474 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1477 EXPORT_SYMBOL(lustre_msg_set_tag);
1479 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1481 switch (msg->lm_magic) {
1482 case LUSTRE_MSG_MAGIC_V2: {
1483 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1484 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1485 pb->pb_last_committed = last_committed;
1489 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1493 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions)
1495 switch (msg->lm_magic) {
1496 case LUSTRE_MSG_MAGIC_V2: {
1497 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1498 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1499 pb->pb_pre_versions[0] = versions[0];
1500 pb->pb_pre_versions[1] = versions[1];
1501 pb->pb_pre_versions[2] = versions[2];
1502 pb->pb_pre_versions[3] = versions[3];
1506 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1509 EXPORT_SYMBOL(lustre_msg_set_versions);
1511 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1513 switch (msg->lm_magic) {
1514 case LUSTRE_MSG_MAGIC_V2: {
1515 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1516 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1517 pb->pb_transno = transno;
1521 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1524 EXPORT_SYMBOL(lustre_msg_set_transno);
1526 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1528 switch (msg->lm_magic) {
1529 case LUSTRE_MSG_MAGIC_V2: {
1530 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1531 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1532 pb->pb_status = status;
1536 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1539 EXPORT_SYMBOL(lustre_msg_set_status);
1541 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1543 switch (msg->lm_magic) {
1544 case LUSTRE_MSG_MAGIC_V2: {
1545 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1546 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1547 pb->pb_conn_cnt = conn_cnt;
1551 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1555 void lustre_msg_set_timeout(struct lustre_msg *msg, timeout_t timeout)
1557 switch (msg->lm_magic) {
1558 case LUSTRE_MSG_MAGIC_V2: {
1559 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1561 LASSERT(timeout >= 0);
1562 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1563 pb->pb_timeout = timeout;
1567 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1571 void lustre_msg_set_service_timeout(struct lustre_msg *msg,
1572 timeout_t service_timeout)
1574 switch (msg->lm_magic) {
1575 case LUSTRE_MSG_MAGIC_V2: {
1576 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1578 LASSERT(service_timeout >= 0);
1579 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1580 pb->pb_service_time = service_timeout;
1584 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1588 void lustre_msg_set_jobid(struct lustre_msg *msg, char *jobid)
1590 switch (msg->lm_magic) {
1591 case LUSTRE_MSG_MAGIC_V2: {
1592 __u32 opc = lustre_msg_get_opc(msg);
1593 struct ptlrpc_body *pb;
1595 /* Don't set jobid for ldlm ast RPCs, they've been shrinked.
1596 * See the comment in ptlrpc_request_pack(). */
1597 if (!opc || opc == LDLM_BL_CALLBACK ||
1598 opc == LDLM_CP_CALLBACK || opc == LDLM_GL_CALLBACK)
1601 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
1602 sizeof(struct ptlrpc_body));
1603 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1606 memcpy(pb->pb_jobid, jobid, sizeof(pb->pb_jobid));
1607 else if (pb->pb_jobid[0] == '\0')
1608 lustre_get_jobid(pb->pb_jobid, sizeof(pb->pb_jobid));
1612 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1615 EXPORT_SYMBOL(lustre_msg_set_jobid);
1617 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1619 switch (msg->lm_magic) {
1620 case LUSTRE_MSG_MAGIC_V2:
1621 msg->lm_cksum = cksum;
1624 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1628 void lustre_msg_set_mbits(struct lustre_msg *msg, __u64 mbits)
1630 switch (msg->lm_magic) {
1631 case LUSTRE_MSG_MAGIC_V2: {
1632 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1634 LASSERTF(pb != NULL, "invalid msg %p: no ptlrpc body!\n", msg);
1635 pb->pb_mbits = mbits;
1639 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1643 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1645 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1647 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1648 req->rq_pill.rc_area[RCL_SERVER]);
1649 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1650 req->rq_reqmsg->lm_repsize = req->rq_replen;
1652 EXPORT_SYMBOL(ptlrpc_request_set_replen);
1654 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
1656 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1657 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1658 req->rq_reqmsg->lm_repsize = req->rq_replen;
1662 * Send a remote set_info_async.
1664 * This may go from client to server or server to client.
1666 int do_set_info_async(struct obd_import *imp,
1667 int opcode, int version,
1668 size_t keylen, void *key,
1669 size_t vallen, void *val,
1670 struct ptlrpc_request_set *set)
1672 struct ptlrpc_request *req;
1678 req = ptlrpc_request_alloc(imp, KEY_IS(KEY_CHANGELOG_CLEAR) ?
1684 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1685 RCL_CLIENT, keylen);
1686 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1687 RCL_CLIENT, vallen);
1688 rc = ptlrpc_request_pack(req, version, opcode);
1690 ptlrpc_request_free(req);
1694 if (KEY_IS(KEY_CHANGELOG_CLEAR))
1697 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1698 memcpy(tmp, key, keylen);
1699 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1700 memcpy(tmp, val, vallen);
1702 ptlrpc_request_set_replen(req);
1705 ptlrpc_set_add_req(set, req);
1706 ptlrpc_check_set(NULL, set);
1708 rc = ptlrpc_queue_wait(req);
1709 ptlrpc_req_finished(req);
1714 EXPORT_SYMBOL(do_set_info_async);
1716 /* byte flipping routines for all wire types declared in
1717 * lustre_idl.h implemented here.
1719 void lustre_swab_ptlrpc_body(struct ptlrpc_body *body)
1721 __swab32s(&body->pb_type);
1722 __swab32s(&body->pb_version);
1723 __swab32s(&body->pb_opc);
1724 __swab32s(&body->pb_status);
1725 __swab64s(&body->pb_last_xid);
1726 __swab16s(&body->pb_tag);
1727 BUILD_BUG_ON(offsetof(typeof(*body), pb_padding0) == 0);
1728 BUILD_BUG_ON(offsetof(typeof(*body), pb_padding1) == 0);
1729 __swab64s(&body->pb_last_committed);
1730 __swab64s(&body->pb_transno);
1731 __swab32s(&body->pb_flags);
1732 __swab32s(&body->pb_op_flags);
1733 __swab32s(&body->pb_conn_cnt);
1734 __swab32s(&body->pb_timeout);
1735 __swab32s(&body->pb_service_time);
1736 __swab32s(&body->pb_limit);
1737 __swab64s(&body->pb_slv);
1738 __swab64s(&body->pb_pre_versions[0]);
1739 __swab64s(&body->pb_pre_versions[1]);
1740 __swab64s(&body->pb_pre_versions[2]);
1741 __swab64s(&body->pb_pre_versions[3]);
1742 __swab64s(&body->pb_mbits);
1743 BUILD_BUG_ON(offsetof(typeof(*body), pb_padding64_0) == 0);
1744 BUILD_BUG_ON(offsetof(typeof(*body), pb_padding64_1) == 0);
1745 BUILD_BUG_ON(offsetof(typeof(*body), pb_padding64_2) == 0);
1747 * While we need to maintain compatibility between
1748 * clients and servers without ptlrpc_body_v2 (< 2.3)
1749 * do not swab any fields beyond pb_jobid, as we are
1750 * using this swab function for both ptlrpc_body
1751 * and ptlrpc_body_v2.
1753 /* pb_jobid is an ASCII string and should not be swabbed */
1754 BUILD_BUG_ON(offsetof(typeof(*body), pb_jobid) == 0);
1757 void lustre_swab_connect(struct obd_connect_data *ocd)
1759 __swab64s(&ocd->ocd_connect_flags);
1760 __swab32s(&ocd->ocd_version);
1761 __swab32s(&ocd->ocd_grant);
1762 __swab64s(&ocd->ocd_ibits_known);
1763 __swab32s(&ocd->ocd_index);
1764 __swab32s(&ocd->ocd_brw_size);
1766 * ocd_blocksize and ocd_inodespace don't need to be swabbed because
1767 * they are 8-byte values
1769 __swab16s(&ocd->ocd_grant_tax_kb);
1770 __swab32s(&ocd->ocd_grant_max_blks);
1771 __swab64s(&ocd->ocd_transno);
1772 __swab32s(&ocd->ocd_group);
1773 __swab32s(&ocd->ocd_cksum_types);
1774 __swab32s(&ocd->ocd_instance);
1776 * Fields after ocd_cksum_types are only accessible by the receiver
1777 * if the corresponding flag in ocd_connect_flags is set. Accessing
1778 * any field after ocd_maxbytes on the receiver without a valid flag
1779 * may result in out-of-bound memory access and kernel oops.
1781 if (ocd->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)
1782 __swab32s(&ocd->ocd_max_easize);
1783 if (ocd->ocd_connect_flags & OBD_CONNECT_MAXBYTES)
1784 __swab64s(&ocd->ocd_maxbytes);
1785 if (ocd->ocd_connect_flags & OBD_CONNECT_MULTIMODRPCS)
1786 __swab16s(&ocd->ocd_maxmodrpcs);
1787 BUILD_BUG_ON(offsetof(typeof(*ocd), padding0) == 0);
1788 BUILD_BUG_ON(offsetof(typeof(*ocd), padding1) == 0);
1789 if (ocd->ocd_connect_flags & OBD_CONNECT_FLAGS2)
1790 __swab64s(&ocd->ocd_connect_flags2);
1791 BUILD_BUG_ON(offsetof(typeof(*ocd), padding3) == 0);
1792 BUILD_BUG_ON(offsetof(typeof(*ocd), padding4) == 0);
1793 BUILD_BUG_ON(offsetof(typeof(*ocd), padding5) == 0);
1794 BUILD_BUG_ON(offsetof(typeof(*ocd), padding6) == 0);
1795 BUILD_BUG_ON(offsetof(typeof(*ocd), padding7) == 0);
1796 BUILD_BUG_ON(offsetof(typeof(*ocd), padding8) == 0);
1797 BUILD_BUG_ON(offsetof(typeof(*ocd), padding9) == 0);
1798 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingA) == 0);
1799 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingB) == 0);
1800 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingC) == 0);
1801 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingD) == 0);
1802 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingE) == 0);
1803 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingF) == 0);
1806 static void lustre_swab_ost_layout(struct ost_layout *ol)
1808 __swab32s(&ol->ol_stripe_size);
1809 __swab32s(&ol->ol_stripe_count);
1810 __swab64s(&ol->ol_comp_start);
1811 __swab64s(&ol->ol_comp_end);
1812 __swab32s(&ol->ol_comp_id);
1815 void lustre_swab_obdo(struct obdo *o)
1817 __swab64s(&o->o_valid);
1818 lustre_swab_ost_id(&o->o_oi);
1819 __swab64s(&o->o_parent_seq);
1820 __swab64s(&o->o_size);
1821 __swab64s(&o->o_mtime);
1822 __swab64s(&o->o_atime);
1823 __swab64s(&o->o_ctime);
1824 __swab64s(&o->o_blocks);
1825 __swab64s(&o->o_grant);
1826 __swab32s(&o->o_blksize);
1827 __swab32s(&o->o_mode);
1828 __swab32s(&o->o_uid);
1829 __swab32s(&o->o_gid);
1830 __swab32s(&o->o_flags);
1831 __swab32s(&o->o_nlink);
1832 __swab32s(&o->o_parent_oid);
1833 __swab32s(&o->o_misc);
1834 __swab64s(&o->o_ioepoch);
1835 __swab32s(&o->o_stripe_idx);
1836 __swab32s(&o->o_parent_ver);
1837 lustre_swab_ost_layout(&o->o_layout);
1838 __swab32s(&o->o_layout_version);
1839 __swab32s(&o->o_uid_h);
1840 __swab32s(&o->o_gid_h);
1841 __swab64s(&o->o_data_version);
1842 __swab32s(&o->o_projid);
1843 BUILD_BUG_ON(offsetof(typeof(*o), o_padding_4) == 0);
1844 BUILD_BUG_ON(offsetof(typeof(*o), o_padding_5) == 0);
1845 BUILD_BUG_ON(offsetof(typeof(*o), o_padding_6) == 0);
1848 EXPORT_SYMBOL(lustre_swab_obdo);
1850 void lustre_swab_obd_statfs(struct obd_statfs *os)
1852 __swab64s(&os->os_type);
1853 __swab64s(&os->os_blocks);
1854 __swab64s(&os->os_bfree);
1855 __swab64s(&os->os_bavail);
1856 __swab64s(&os->os_files);
1857 __swab64s(&os->os_ffree);
1858 /* no need to swab os_fsid */
1859 __swab32s(&os->os_bsize);
1860 __swab32s(&os->os_namelen);
1861 __swab64s(&os->os_maxbytes);
1862 __swab32s(&os->os_state);
1863 __swab32s(&os->os_fprecreated);
1864 __swab32s(&os->os_granted);
1865 BUILD_BUG_ON(offsetof(typeof(*os), os_spare3) == 0);
1866 BUILD_BUG_ON(offsetof(typeof(*os), os_spare4) == 0);
1867 BUILD_BUG_ON(offsetof(typeof(*os), os_spare5) == 0);
1868 BUILD_BUG_ON(offsetof(typeof(*os), os_spare6) == 0);
1869 BUILD_BUG_ON(offsetof(typeof(*os), os_spare7) == 0);
1870 BUILD_BUG_ON(offsetof(typeof(*os), os_spare8) == 0);
1871 BUILD_BUG_ON(offsetof(typeof(*os), os_spare9) == 0);
1874 void lustre_swab_obd_ioobj(struct obd_ioobj *ioo)
1876 lustre_swab_ost_id(&ioo->ioo_oid);
1877 __swab32s(&ioo->ioo_max_brw);
1878 __swab32s(&ioo->ioo_bufcnt);
1881 void lustre_swab_niobuf_remote(struct niobuf_remote *nbr)
1883 __swab64s(&nbr->rnb_offset);
1884 __swab32s(&nbr->rnb_len);
1885 __swab32s(&nbr->rnb_flags);
1888 void lustre_swab_ost_body(struct ost_body *b)
1890 lustre_swab_obdo(&b->oa);
1893 void lustre_swab_ost_last_id(u64 *id)
1898 void lustre_swab_generic_32s(__u32 *val)
1903 void lustre_swab_gl_lquota_desc(struct ldlm_gl_lquota_desc *desc)
1905 lustre_swab_lu_fid(&desc->gl_id.qid_fid);
1906 __swab64s(&desc->gl_flags);
1907 __swab64s(&desc->gl_ver);
1908 __swab64s(&desc->gl_hardlimit);
1909 __swab64s(&desc->gl_softlimit);
1910 __swab64s(&desc->gl_time);
1911 BUILD_BUG_ON(offsetof(typeof(*desc), gl_pad2) == 0);
1913 EXPORT_SYMBOL(lustre_swab_gl_lquota_desc);
1915 void lustre_swab_gl_barrier_desc(struct ldlm_gl_barrier_desc *desc)
1917 __swab32s(&desc->lgbd_status);
1918 __swab32s(&desc->lgbd_timeout);
1919 BUILD_BUG_ON(offsetof(typeof(*desc), lgbd_padding) == 0);
1921 EXPORT_SYMBOL(lustre_swab_gl_barrier_desc);
1923 void lustre_swab_ost_lvb_v1(struct ost_lvb_v1 *lvb)
1925 __swab64s(&lvb->lvb_size);
1926 __swab64s(&lvb->lvb_mtime);
1927 __swab64s(&lvb->lvb_atime);
1928 __swab64s(&lvb->lvb_ctime);
1929 __swab64s(&lvb->lvb_blocks);
1931 EXPORT_SYMBOL(lustre_swab_ost_lvb_v1);
1933 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1935 __swab64s(&lvb->lvb_size);
1936 __swab64s(&lvb->lvb_mtime);
1937 __swab64s(&lvb->lvb_atime);
1938 __swab64s(&lvb->lvb_ctime);
1939 __swab64s(&lvb->lvb_blocks);
1940 __swab32s(&lvb->lvb_mtime_ns);
1941 __swab32s(&lvb->lvb_atime_ns);
1942 __swab32s(&lvb->lvb_ctime_ns);
1943 __swab32s(&lvb->lvb_padding);
1945 EXPORT_SYMBOL(lustre_swab_ost_lvb);
1947 void lustre_swab_lquota_lvb(struct lquota_lvb *lvb)
1949 __swab64s(&lvb->lvb_flags);
1950 __swab64s(&lvb->lvb_id_may_rel);
1951 __swab64s(&lvb->lvb_id_rel);
1952 __swab64s(&lvb->lvb_id_qunit);
1953 __swab64s(&lvb->lvb_pad1);
1955 EXPORT_SYMBOL(lustre_swab_lquota_lvb);
1957 void lustre_swab_barrier_lvb(struct barrier_lvb *lvb)
1959 __swab32s(&lvb->lvb_status);
1960 __swab32s(&lvb->lvb_index);
1961 BUILD_BUG_ON(offsetof(typeof(*lvb), lvb_padding) == 0);
1963 EXPORT_SYMBOL(lustre_swab_barrier_lvb);
1965 void lustre_swab_mdt_body(struct mdt_body *b)
1967 lustre_swab_lu_fid(&b->mbo_fid1);
1968 lustre_swab_lu_fid(&b->mbo_fid2);
1969 /* handle is opaque */
1970 __swab64s(&b->mbo_valid);
1971 __swab64s(&b->mbo_size);
1972 __swab64s(&b->mbo_mtime);
1973 __swab64s(&b->mbo_atime);
1974 __swab64s(&b->mbo_ctime);
1975 __swab64s(&b->mbo_blocks);
1976 __swab64s(&b->mbo_version);
1977 __swab64s(&b->mbo_t_state);
1978 __swab32s(&b->mbo_fsuid);
1979 __swab32s(&b->mbo_fsgid);
1980 __swab32s(&b->mbo_capability);
1981 __swab32s(&b->mbo_mode);
1982 __swab32s(&b->mbo_uid);
1983 __swab32s(&b->mbo_gid);
1984 __swab32s(&b->mbo_flags);
1985 __swab32s(&b->mbo_rdev);
1986 __swab32s(&b->mbo_nlink);
1987 __swab32s(&b->mbo_layout_gen);
1988 __swab32s(&b->mbo_suppgid);
1989 __swab32s(&b->mbo_eadatasize);
1990 __swab32s(&b->mbo_aclsize);
1991 __swab32s(&b->mbo_max_mdsize);
1992 BUILD_BUG_ON(offsetof(typeof(*b), mbo_unused3) == 0);
1993 __swab32s(&b->mbo_uid_h);
1994 __swab32s(&b->mbo_gid_h);
1995 __swab32s(&b->mbo_projid);
1996 __swab64s(&b->mbo_dom_size);
1997 __swab64s(&b->mbo_dom_blocks);
1998 __swab64s(&b->mbo_btime);
1999 BUILD_BUG_ON(offsetof(typeof(*b), mbo_padding_9) == 0);
2000 BUILD_BUG_ON(offsetof(typeof(*b), mbo_padding_10) == 0);
2003 void lustre_swab_mdt_ioepoch(struct mdt_ioepoch *b)
2005 /* mio_open_handle is opaque */
2006 BUILD_BUG_ON(offsetof(typeof(*b), mio_unused1) == 0);
2007 BUILD_BUG_ON(offsetof(typeof(*b), mio_unused2) == 0);
2008 BUILD_BUG_ON(offsetof(typeof(*b), mio_padding) == 0);
2011 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
2015 __swab32s(&mti->mti_lustre_ver);
2016 __swab32s(&mti->mti_stripe_index);
2017 __swab32s(&mti->mti_config_ver);
2018 __swab32s(&mti->mti_flags);
2019 __swab32s(&mti->mti_instance);
2020 __swab32s(&mti->mti_nid_count);
2021 BUILD_BUG_ON(sizeof(lnet_nid_t) != sizeof(__u64));
2022 for (i = 0; i < MTI_NIDS_MAX; i++)
2023 __swab64s(&mti->mti_nids[i]);
2026 void lustre_swab_mgs_nidtbl_entry(struct mgs_nidtbl_entry *entry)
2030 __swab64s(&entry->mne_version);
2031 __swab32s(&entry->mne_instance);
2032 __swab32s(&entry->mne_index);
2033 __swab32s(&entry->mne_length);
2035 /* mne_nid_(count|type) must be one byte size because we're gonna
2036 * access it w/o swapping. */
2037 BUILD_BUG_ON(sizeof(entry->mne_nid_count) != sizeof(__u8));
2038 BUILD_BUG_ON(sizeof(entry->mne_nid_type) != sizeof(__u8));
2040 /* remove this assertion if ipv6 is supported. */
2041 LASSERT(entry->mne_nid_type == 0);
2042 for (i = 0; i < entry->mne_nid_count; i++) {
2043 BUILD_BUG_ON(sizeof(lnet_nid_t) != sizeof(__u64));
2044 __swab64s(&entry->u.nids[i]);
2047 EXPORT_SYMBOL(lustre_swab_mgs_nidtbl_entry);
2049 void lustre_swab_mgs_config_body(struct mgs_config_body *body)
2051 __swab64s(&body->mcb_offset);
2052 __swab32s(&body->mcb_units);
2053 __swab16s(&body->mcb_type);
2056 void lustre_swab_mgs_config_res(struct mgs_config_res *body)
2058 __swab64s(&body->mcr_offset);
2059 __swab64s(&body->mcr_size);
2062 static void lustre_swab_obd_dqinfo(struct obd_dqinfo *i)
2064 __swab64s(&i->dqi_bgrace);
2065 __swab64s(&i->dqi_igrace);
2066 __swab32s(&i->dqi_flags);
2067 __swab32s(&i->dqi_valid);
2070 static void lustre_swab_obd_dqblk(struct obd_dqblk *b)
2072 __swab64s(&b->dqb_ihardlimit);
2073 __swab64s(&b->dqb_isoftlimit);
2074 __swab64s(&b->dqb_curinodes);
2075 __swab64s(&b->dqb_bhardlimit);
2076 __swab64s(&b->dqb_bsoftlimit);
2077 __swab64s(&b->dqb_curspace);
2078 __swab64s(&b->dqb_btime);
2079 __swab64s(&b->dqb_itime);
2080 __swab32s(&b->dqb_valid);
2081 BUILD_BUG_ON(offsetof(typeof(*b), dqb_padding) == 0);
2084 int lustre_swab_obd_quotactl(struct obd_quotactl *q, __u32 len)
2086 if (unlikely(len <= sizeof(struct obd_quotactl)))
2089 __swab32s(&q->qc_cmd);
2090 __swab32s(&q->qc_type);
2091 __swab32s(&q->qc_id);
2092 __swab32s(&q->qc_stat);
2093 lustre_swab_obd_dqinfo(&q->qc_dqinfo);
2094 lustre_swab_obd_dqblk(&q->qc_dqblk);
2099 void lustre_swab_fid2path(struct getinfo_fid2path *gf)
2101 lustre_swab_lu_fid(&gf->gf_fid);
2102 __swab64s(&gf->gf_recno);
2103 __swab32s(&gf->gf_linkno);
2104 __swab32s(&gf->gf_pathlen);
2106 EXPORT_SYMBOL(lustre_swab_fid2path);
2108 static void lustre_swab_fiemap_extent(struct fiemap_extent *fm_extent)
2110 __swab64s(&fm_extent->fe_logical);
2111 __swab64s(&fm_extent->fe_physical);
2112 __swab64s(&fm_extent->fe_length);
2113 __swab32s(&fm_extent->fe_flags);
2114 __swab32s(&fm_extent->fe_device);
2117 static void lustre_swab_fiemap_hdr(struct fiemap *fiemap)
2119 __swab64s(&fiemap->fm_start);
2120 __swab64s(&fiemap->fm_length);
2121 __swab32s(&fiemap->fm_flags);
2122 __swab32s(&fiemap->fm_mapped_extents);
2123 __swab32s(&fiemap->fm_extent_count);
2124 __swab32s(&fiemap->fm_reserved);
2127 int lustre_swab_fiemap(struct fiemap *fiemap, __u32 len)
2129 __u32 i, size, count;
2131 lustre_swab_fiemap_hdr(fiemap);
2133 size = fiemap_count_to_size(fiemap->fm_mapped_extents);
2134 count = fiemap->fm_mapped_extents;
2135 if (unlikely(size > len)) {
2136 count = (len - sizeof(struct fiemap)) /
2137 sizeof(struct fiemap_extent);
2138 fiemap->fm_mapped_extents = count;
2141 /* still swab extents as we cannot yet pass rc to callers */
2142 for (i = 0; i < count; i++)
2143 lustre_swab_fiemap_extent(&fiemap->fm_extents[i]);
2148 void lustre_swab_fiemap_info_key(struct ll_fiemap_info_key *fiemap_info)
2150 lustre_swab_obdo(&fiemap_info->lfik_oa);
2151 lustre_swab_fiemap_hdr(&fiemap_info->lfik_fiemap);
2154 void lustre_swab_idx_info(struct idx_info *ii)
2156 __swab32s(&ii->ii_magic);
2157 __swab32s(&ii->ii_flags);
2158 __swab16s(&ii->ii_count);
2159 __swab32s(&ii->ii_attrs);
2160 lustre_swab_lu_fid(&ii->ii_fid);
2161 __swab64s(&ii->ii_version);
2162 __swab64s(&ii->ii_hash_start);
2163 __swab64s(&ii->ii_hash_end);
2164 __swab16s(&ii->ii_keysize);
2165 __swab16s(&ii->ii_recsize);
2168 void lustre_swab_lip_header(struct lu_idxpage *lip)
2171 __swab32s(&lip->lip_magic);
2172 __swab16s(&lip->lip_flags);
2173 __swab16s(&lip->lip_nr);
2175 EXPORT_SYMBOL(lustre_swab_lip_header);
2177 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
2179 __swab32s(&rr->rr_opcode);
2180 __swab32s(&rr->rr_cap);
2181 __swab32s(&rr->rr_fsuid);
2182 /* rr_fsuid_h is unused */
2183 __swab32s(&rr->rr_fsgid);
2184 /* rr_fsgid_h is unused */
2185 __swab32s(&rr->rr_suppgid1);
2186 /* rr_suppgid1_h is unused */
2187 __swab32s(&rr->rr_suppgid2);
2188 /* rr_suppgid2_h is unused */
2189 lustre_swab_lu_fid(&rr->rr_fid1);
2190 lustre_swab_lu_fid(&rr->rr_fid2);
2191 __swab64s(&rr->rr_mtime);
2192 __swab64s(&rr->rr_atime);
2193 __swab64s(&rr->rr_ctime);
2194 __swab64s(&rr->rr_size);
2195 __swab64s(&rr->rr_blocks);
2196 __swab32s(&rr->rr_bias);
2197 __swab32s(&rr->rr_mode);
2198 __swab32s(&rr->rr_flags);
2199 __swab32s(&rr->rr_flags_h);
2200 __swab32s(&rr->rr_umask);
2201 __swab16s(&rr->rr_mirror_id);
2203 BUILD_BUG_ON(offsetof(typeof(*rr), rr_padding_4) == 0);
2206 void lustre_swab_lov_desc(struct lov_desc *ld)
2208 __swab32s(&ld->ld_tgt_count);
2209 __swab32s(&ld->ld_active_tgt_count);
2210 __swab32s(&ld->ld_default_stripe_count);
2211 __swab32s(&ld->ld_pattern);
2212 __swab64s(&ld->ld_default_stripe_size);
2213 __swab64s(&ld->ld_default_stripe_offset);
2214 __swab32s(&ld->ld_qos_maxage);
2215 /* uuid endian insensitive */
2217 EXPORT_SYMBOL(lustre_swab_lov_desc);
2219 void lustre_swab_lmv_desc(struct lmv_desc *ld)
2221 __swab32s(&ld->ld_tgt_count);
2222 __swab32s(&ld->ld_active_tgt_count);
2223 __swab32s(&ld->ld_default_stripe_count);
2224 __swab32s(&ld->ld_pattern);
2225 __swab64s(&ld->ld_default_hash_size);
2226 __swab32s(&ld->ld_qos_maxage);
2227 /* uuid endian insensitive */
2230 /* This structure is always in little-endian */
2231 static void lustre_swab_lmv_mds_md_v1(struct lmv_mds_md_v1 *lmm1)
2235 __swab32s(&lmm1->lmv_magic);
2236 __swab32s(&lmm1->lmv_stripe_count);
2237 __swab32s(&lmm1->lmv_master_mdt_index);
2238 __swab32s(&lmm1->lmv_hash_type);
2239 __swab32s(&lmm1->lmv_layout_version);
2240 for (i = 0; i < lmm1->lmv_stripe_count; i++)
2241 lustre_swab_lu_fid(&lmm1->lmv_stripe_fids[i]);
2244 void lustre_swab_lmv_mds_md(union lmv_mds_md *lmm)
2246 switch (lmm->lmv_magic) {
2248 lustre_swab_lmv_mds_md_v1(&lmm->lmv_md_v1);
2254 EXPORT_SYMBOL(lustre_swab_lmv_mds_md);
2256 void lustre_swab_lmv_user_md_objects(struct lmv_user_mds_data *lmd,
2261 for (i = 0; i < stripe_count; i++)
2262 __swab32s(&(lmd[i].lum_mds));
2264 EXPORT_SYMBOL(lustre_swab_lmv_user_md_objects);
2267 void lustre_swab_lmv_user_md(struct lmv_user_md *lum)
2271 if (lum->lum_magic == LMV_MAGIC_FOREIGN) {
2272 __swab32s(&lum->lum_magic);
2273 __swab32s(&((struct lmv_foreign_md *)lum)->lfm_length);
2274 __swab32s(&((struct lmv_foreign_md *)lum)->lfm_type);
2275 __swab32s(&((struct lmv_foreign_md *)lum)->lfm_flags);
2279 count = lum->lum_stripe_count;
2280 __swab32s(&lum->lum_magic);
2281 __swab32s(&lum->lum_stripe_count);
2282 __swab32s(&lum->lum_stripe_offset);
2283 __swab32s(&lum->lum_hash_type);
2284 __swab32s(&lum->lum_type);
2285 BUILD_BUG_ON(offsetof(typeof(*lum), lum_padding1) == 0);
2286 switch (lum->lum_magic) {
2287 case LMV_USER_MAGIC_SPECIFIC:
2288 count = lum->lum_stripe_count;
2290 case __swab32(LMV_USER_MAGIC_SPECIFIC):
2291 lustre_swab_lmv_user_md_objects(lum->lum_objects, count);
2297 EXPORT_SYMBOL(lustre_swab_lmv_user_md);
2299 static void lustre_print_v1v3(unsigned int lvl, struct lov_user_md *lum,
2302 CDEBUG(lvl, "%s lov_user_md %p:\n", msg, lum);
2303 CDEBUG(lvl, "\tlmm_magic: %#x\n", lum->lmm_magic);
2304 CDEBUG(lvl, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2305 CDEBUG(lvl, "\tlmm_object_id: %llu\n", lmm_oi_id(&lum->lmm_oi));
2306 CDEBUG(lvl, "\tlmm_object_gr: %llu\n", lmm_oi_seq(&lum->lmm_oi));
2307 CDEBUG(lvl, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2308 CDEBUG(lvl, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2309 CDEBUG(lvl, "\tlmm_stripe_offset/lmm_layout_gen: %#x\n",
2310 lum->lmm_stripe_offset);
2311 if (lum->lmm_magic == LOV_USER_MAGIC_V3) {
2312 struct lov_user_md_v3 *v3 = (void *)lum;
2313 CDEBUG(lvl, "\tlmm_pool_name: %s\n", v3->lmm_pool_name);
2315 if (lum->lmm_magic == LOV_USER_MAGIC_SPECIFIC) {
2316 struct lov_user_md_v3 *v3 = (void *)lum;
2319 if (v3->lmm_pool_name[0] != '\0')
2320 CDEBUG(lvl, "\tlmm_pool_name: %s\n", v3->lmm_pool_name);
2322 CDEBUG(lvl, "\ttarget list:\n");
2323 for (i = 0; i < v3->lmm_stripe_count; i++)
2324 CDEBUG(lvl, "\t\t%u\n", v3->lmm_objects[i].l_ost_idx);
2328 void lustre_print_user_md(unsigned int lvl, struct lov_user_md *lum,
2331 struct lov_comp_md_v1 *comp_v1;
2334 if (likely(!cfs_cdebug_show(lvl, DEBUG_SUBSYSTEM)))
2337 if (lum->lmm_magic == LOV_USER_MAGIC_V1 ||
2338 lum->lmm_magic == LOV_USER_MAGIC_V3) {
2339 lustre_print_v1v3(lvl, lum, msg);
2343 if (lum->lmm_magic != LOV_USER_MAGIC_COMP_V1) {
2344 CDEBUG(lvl, "%s: bad magic: %x\n", msg, lum->lmm_magic);
2348 comp_v1 = (struct lov_comp_md_v1 *)lum;
2349 CDEBUG(lvl, "%s: lov_comp_md_v1 %p:\n", msg, lum);
2350 CDEBUG(lvl, "\tlcm_magic: %#x\n", comp_v1->lcm_magic);
2351 CDEBUG(lvl, "\tlcm_size: %#x\n", comp_v1->lcm_size);
2352 CDEBUG(lvl, "\tlcm_layout_gen: %#x\n", comp_v1->lcm_layout_gen);
2353 CDEBUG(lvl, "\tlcm_flags: %#x\n", comp_v1->lcm_flags);
2354 CDEBUG(lvl, "\tlcm_entry_count: %#x\n\n", comp_v1->lcm_entry_count);
2355 CDEBUG(lvl, "\tlcm_mirror_count: %#x\n\n", comp_v1->lcm_mirror_count);
2357 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
2358 struct lov_comp_md_entry_v1 *ent = &comp_v1->lcm_entries[i];
2359 struct lov_user_md *v1;
2361 CDEBUG(lvl, "\tentry %d:\n", i);
2362 CDEBUG(lvl, "\tlcme_id: %#x\n", ent->lcme_id);
2363 CDEBUG(lvl, "\tlcme_flags: %#x\n", ent->lcme_flags);
2364 if (ent->lcme_flags & LCME_FL_NOSYNC)
2365 CDEBUG(lvl, "\tlcme_timestamp: %llu\n",
2366 ent->lcme_timestamp);
2367 CDEBUG(lvl, "\tlcme_extent.e_start: %llu\n",
2368 ent->lcme_extent.e_start);
2369 CDEBUG(lvl, "\tlcme_extent.e_end: %llu\n",
2370 ent->lcme_extent.e_end);
2371 CDEBUG(lvl, "\tlcme_offset: %#x\n", ent->lcme_offset);
2372 CDEBUG(lvl, "\tlcme_size: %#x\n\n", ent->lcme_size);
2374 v1 = (struct lov_user_md *)((char *)comp_v1 +
2375 comp_v1->lcm_entries[i].lcme_offset);
2376 lustre_print_v1v3(lvl, v1, msg);
2379 EXPORT_SYMBOL(lustre_print_user_md);
2381 static void lustre_swab_lmm_oi(struct ost_id *oi)
2383 __swab64s(&oi->oi.oi_id);
2384 __swab64s(&oi->oi.oi_seq);
2387 static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
2390 __swab32s(&lum->lmm_magic);
2391 __swab32s(&lum->lmm_pattern);
2392 lustre_swab_lmm_oi(&lum->lmm_oi);
2393 __swab32s(&lum->lmm_stripe_size);
2394 __swab16s(&lum->lmm_stripe_count);
2395 __swab16s(&lum->lmm_stripe_offset);
2399 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
2402 CDEBUG(D_IOCTL, "swabbing lov_user_md v1\n");
2403 lustre_swab_lov_user_md_common(lum);
2406 EXPORT_SYMBOL(lustre_swab_lov_user_md_v1);
2408 void lustre_swab_lov_user_md_v3(struct lov_user_md_v3 *lum)
2411 CDEBUG(D_IOCTL, "swabbing lov_user_md v3\n");
2412 lustre_swab_lov_user_md_common((struct lov_user_md_v1 *)lum);
2413 /* lmm_pool_name nothing to do with char */
2416 EXPORT_SYMBOL(lustre_swab_lov_user_md_v3);
2418 void lustre_swab_lov_comp_md_v1(struct lov_comp_md_v1 *lum)
2420 struct lov_comp_md_entry_v1 *ent;
2421 struct lov_user_md_v1 *v1;
2422 struct lov_user_md_v3 *v3;
2426 __u16 ent_count, stripe_count;
2429 cpu_endian = lum->lcm_magic == LOV_USER_MAGIC_COMP_V1;
2430 ent_count = lum->lcm_entry_count;
2432 __swab16s(&ent_count);
2434 CDEBUG(D_IOCTL, "swabbing lov_user_comp_md v1\n");
2435 __swab32s(&lum->lcm_magic);
2436 __swab32s(&lum->lcm_size);
2437 __swab32s(&lum->lcm_layout_gen);
2438 __swab16s(&lum->lcm_flags);
2439 __swab16s(&lum->lcm_entry_count);
2440 __swab16s(&lum->lcm_mirror_count);
2441 BUILD_BUG_ON(offsetof(typeof(*lum), lcm_padding1) == 0);
2442 BUILD_BUG_ON(offsetof(typeof(*lum), lcm_padding2) == 0);
2444 for (i = 0; i < ent_count; i++) {
2445 ent = &lum->lcm_entries[i];
2446 off = ent->lcme_offset;
2447 size = ent->lcme_size;
2453 __swab32s(&ent->lcme_id);
2454 __swab32s(&ent->lcme_flags);
2455 __swab64s(&ent->lcme_timestamp);
2456 __swab64s(&ent->lcme_extent.e_start);
2457 __swab64s(&ent->lcme_extent.e_end);
2458 __swab32s(&ent->lcme_offset);
2459 __swab32s(&ent->lcme_size);
2460 __swab32s(&ent->lcme_layout_gen);
2461 BUILD_BUG_ON(offsetof(typeof(*ent), lcme_padding_1) == 0);
2463 v1 = (struct lov_user_md_v1 *)((char *)lum + off);
2464 stripe_count = v1->lmm_stripe_count;
2466 __swab16s(&stripe_count);
2468 if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1) ||
2469 v1->lmm_magic == LOV_USER_MAGIC_V1) {
2470 lustre_swab_lov_user_md_v1(v1);
2471 if (size > sizeof(*v1))
2472 lustre_swab_lov_user_md_objects(v1->lmm_objects,
2474 } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3) ||
2475 v1->lmm_magic == LOV_USER_MAGIC_V3 ||
2476 v1->lmm_magic == __swab32(LOV_USER_MAGIC_SPECIFIC) ||
2477 v1->lmm_magic == LOV_USER_MAGIC_SPECIFIC) {
2478 v3 = (struct lov_user_md_v3 *)v1;
2479 lustre_swab_lov_user_md_v3(v3);
2480 if (size > sizeof(*v3))
2481 lustre_swab_lov_user_md_objects(v3->lmm_objects,
2484 CERROR("Invalid magic %#x\n", v1->lmm_magic);
2488 EXPORT_SYMBOL(lustre_swab_lov_comp_md_v1);
2490 void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
2496 for (i = 0; i < stripe_count; i++) {
2497 lustre_swab_ost_id(&(lod[i].l_ost_oi));
2498 __swab32s(&(lod[i].l_ost_gen));
2499 __swab32s(&(lod[i].l_ost_idx));
2503 EXPORT_SYMBOL(lustre_swab_lov_user_md_objects);
2505 void lustre_swab_lov_user_md(struct lov_user_md *lum, size_t size)
2507 struct lov_user_md_v1 *v1;
2508 struct lov_user_md_v3 *v3;
2509 struct lov_foreign_md *lfm;
2513 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2514 switch (lum->lmm_magic) {
2515 case __swab32(LOV_MAGIC_V1):
2516 case LOV_USER_MAGIC_V1:
2518 v1 = (struct lov_user_md_v1 *)lum;
2519 stripe_count = v1->lmm_stripe_count;
2521 if (lum->lmm_magic != LOV_USER_MAGIC_V1)
2522 __swab16s(&stripe_count);
2524 lustre_swab_lov_user_md_v1(v1);
2525 if (size > sizeof(*v1))
2526 lustre_swab_lov_user_md_objects(v1->lmm_objects,
2531 case __swab32(LOV_MAGIC_V3):
2532 case LOV_USER_MAGIC_V3:
2534 v3 = (struct lov_user_md_v3 *)lum;
2535 stripe_count = v3->lmm_stripe_count;
2537 if (lum->lmm_magic != LOV_USER_MAGIC_V3)
2538 __swab16s(&stripe_count);
2540 lustre_swab_lov_user_md_v3(v3);
2541 if (size > sizeof(*v3))
2542 lustre_swab_lov_user_md_objects(v3->lmm_objects,
2546 case __swab32(LOV_USER_MAGIC_SPECIFIC):
2547 case LOV_USER_MAGIC_SPECIFIC:
2549 v3 = (struct lov_user_md_v3 *)lum;
2550 stripe_count = v3->lmm_stripe_count;
2552 if (lum->lmm_magic != LOV_USER_MAGIC_SPECIFIC)
2553 __swab16s(&stripe_count);
2555 lustre_swab_lov_user_md_v3(v3);
2556 lustre_swab_lov_user_md_objects(v3->lmm_objects, stripe_count);
2559 case __swab32(LOV_MAGIC_COMP_V1):
2560 case LOV_USER_MAGIC_COMP_V1:
2561 lustre_swab_lov_comp_md_v1((struct lov_comp_md_v1 *)lum);
2563 case __swab32(LOV_MAGIC_FOREIGN):
2564 case LOV_USER_MAGIC_FOREIGN:
2566 lfm = (struct lov_foreign_md *)lum;
2567 __swab32s(&lfm->lfm_magic);
2568 __swab32s(&lfm->lfm_length);
2569 __swab32s(&lfm->lfm_type);
2570 __swab32s(&lfm->lfm_flags);
2574 CDEBUG(D_IOCTL, "Invalid LOV magic %08x\n", lum->lmm_magic);
2577 EXPORT_SYMBOL(lustre_swab_lov_user_md);
2579 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2582 CDEBUG(D_IOCTL, "swabbing lov_mds_md\n");
2583 __swab32s(&lmm->lmm_magic);
2584 __swab32s(&lmm->lmm_pattern);
2585 lustre_swab_lmm_oi(&lmm->lmm_oi);
2586 __swab32s(&lmm->lmm_stripe_size);
2587 __swab16s(&lmm->lmm_stripe_count);
2588 __swab16s(&lmm->lmm_layout_gen);
2591 EXPORT_SYMBOL(lustre_swab_lov_mds_md);
2593 void lustre_swab_ldlm_res_id(struct ldlm_res_id *id)
2597 for (i = 0; i < RES_NAME_SIZE; i++)
2598 __swab64s(&id->name[i]);
2601 void lustre_swab_ldlm_policy_data(union ldlm_wire_policy_data *d)
2603 /* the lock data is a union and the first two fields are always an
2604 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2605 * data the same way.
2607 __swab64s(&d->l_extent.start);
2608 __swab64s(&d->l_extent.end);
2609 __swab64s(&d->l_extent.gid);
2610 __swab64s(&d->l_flock.lfw_owner);
2611 __swab32s(&d->l_flock.lfw_pid);
2614 void lustre_swab_ldlm_intent(struct ldlm_intent *i)
2619 void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r)
2621 __swab32s(&r->lr_type);
2622 BUILD_BUG_ON(offsetof(typeof(*r), lr_pad) == 0);
2623 lustre_swab_ldlm_res_id(&r->lr_name);
2626 void lustre_swab_ldlm_lock_desc(struct ldlm_lock_desc *l)
2628 lustre_swab_ldlm_resource_desc(&l->l_resource);
2629 __swab32s(&l->l_req_mode);
2630 __swab32s(&l->l_granted_mode);
2631 lustre_swab_ldlm_policy_data(&l->l_policy_data);
2634 void lustre_swab_ldlm_request(struct ldlm_request *rq)
2636 __swab32s(&rq->lock_flags);
2637 lustre_swab_ldlm_lock_desc(&rq->lock_desc);
2638 __swab32s(&rq->lock_count);
2639 /* lock_handle[] opaque */
2642 void lustre_swab_ldlm_reply(struct ldlm_reply *r)
2644 __swab32s(&r->lock_flags);
2645 BUILD_BUG_ON(offsetof(typeof(*r), lock_padding) == 0);
2646 lustre_swab_ldlm_lock_desc(&r->lock_desc);
2647 /* lock_handle opaque */
2648 __swab64s(&r->lock_policy_res1);
2649 __swab64s(&r->lock_policy_res2);
2652 void lustre_swab_quota_body(struct quota_body *b)
2654 lustre_swab_lu_fid(&b->qb_fid);
2655 lustre_swab_lu_fid((struct lu_fid *)&b->qb_id);
2656 __swab32s(&b->qb_flags);
2657 __swab64s(&b->qb_count);
2658 __swab64s(&b->qb_usage);
2659 __swab64s(&b->qb_slv_ver);
2662 /* Dump functions */
2663 void dump_ioo(struct obd_ioobj *ioo)
2666 "obd_ioobj: ioo_oid="DOSTID", ioo_max_brw=%#x, "
2667 "ioo_bufct=%d\n", POSTID(&ioo->ioo_oid), ioo->ioo_max_brw,
2671 void dump_rniobuf(struct niobuf_remote *nb)
2673 CDEBUG(D_RPCTRACE, "niobuf_remote: offset=%llu, len=%d, flags=%x\n",
2674 nb->rnb_offset, nb->rnb_len, nb->rnb_flags);
2677 void dump_obdo(struct obdo *oa)
2679 u64 valid = oa->o_valid;
2681 CDEBUG(D_RPCTRACE, "obdo: o_valid = %#llx\n", valid);
2682 if (valid & OBD_MD_FLID)
2683 CDEBUG(D_RPCTRACE, "obdo: id = "DOSTID"\n", POSTID(&oa->o_oi));
2684 if (valid & OBD_MD_FLFID)
2685 CDEBUG(D_RPCTRACE, "obdo: o_parent_seq = %#llx\n",
2687 if (valid & OBD_MD_FLSIZE)
2688 CDEBUG(D_RPCTRACE, "obdo: o_size = %lld\n", oa->o_size);
2689 if (valid & OBD_MD_FLMTIME)
2690 CDEBUG(D_RPCTRACE, "obdo: o_mtime = %lld\n", oa->o_mtime);
2691 if (valid & OBD_MD_FLATIME)
2692 CDEBUG(D_RPCTRACE, "obdo: o_atime = %lld\n", oa->o_atime);
2693 if (valid & OBD_MD_FLCTIME)
2694 CDEBUG(D_RPCTRACE, "obdo: o_ctime = %lld\n", oa->o_ctime);
2695 if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
2696 CDEBUG(D_RPCTRACE, "obdo: o_blocks = %lld\n", oa->o_blocks);
2697 if (valid & OBD_MD_FLGRANT)
2698 CDEBUG(D_RPCTRACE, "obdo: o_grant = %lld\n", oa->o_grant);
2699 if (valid & OBD_MD_FLBLKSZ)
2700 CDEBUG(D_RPCTRACE, "obdo: o_blksize = %d\n", oa->o_blksize);
2701 if (valid & (OBD_MD_FLTYPE | OBD_MD_FLMODE))
2702 CDEBUG(D_RPCTRACE, "obdo: o_mode = %o\n",
2703 oa->o_mode & ((valid & OBD_MD_FLTYPE ? S_IFMT : 0) |
2704 (valid & OBD_MD_FLMODE ? ~S_IFMT : 0)));
2705 if (valid & OBD_MD_FLUID)
2706 CDEBUG(D_RPCTRACE, "obdo: o_uid = %u\n", oa->o_uid);
2707 if (valid & OBD_MD_FLUID)
2708 CDEBUG(D_RPCTRACE, "obdo: o_uid_h = %u\n", oa->o_uid_h);
2709 if (valid & OBD_MD_FLGID)
2710 CDEBUG(D_RPCTRACE, "obdo: o_gid = %u\n", oa->o_gid);
2711 if (valid & OBD_MD_FLGID)
2712 CDEBUG(D_RPCTRACE, "obdo: o_gid_h = %u\n", oa->o_gid_h);
2713 if (valid & OBD_MD_FLFLAGS)
2714 CDEBUG(D_RPCTRACE, "obdo: o_flags = %x\n", oa->o_flags);
2715 if (valid & OBD_MD_FLNLINK)
2716 CDEBUG(D_RPCTRACE, "obdo: o_nlink = %u\n", oa->o_nlink);
2717 else if (valid & OBD_MD_FLCKSUM)
2718 CDEBUG(D_RPCTRACE, "obdo: o_checksum (o_nlink) = %u\n",
2720 if (valid & OBD_MD_FLPARENT)
2721 CDEBUG(D_RPCTRACE, "obdo: o_parent_oid = %x\n",
2723 if (valid & OBD_MD_FLFID) {
2724 CDEBUG(D_RPCTRACE, "obdo: o_stripe_idx = %u\n",
2726 CDEBUG(D_RPCTRACE, "obdo: o_parent_ver = %x\n",
2729 if (valid & OBD_MD_FLHANDLE)
2730 CDEBUG(D_RPCTRACE, "obdo: o_handle = %lld\n",
2731 oa->o_handle.cookie);
2734 void dump_ost_body(struct ost_body *ob)
2739 void dump_rcs(__u32 *rc)
2741 CDEBUG(D_RPCTRACE, "rmf_rcs: %d\n", *rc);
2744 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2746 LASSERT(req->rq_reqmsg);
2748 switch (req->rq_reqmsg->lm_magic) {
2749 case LUSTRE_MSG_MAGIC_V2:
2750 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2752 CERROR("bad lustre msg magic: %#08X\n",
2753 req->rq_reqmsg->lm_magic);
2758 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2760 if (unlikely(!req->rq_repmsg))
2763 switch (req->rq_repmsg->lm_magic) {
2764 case LUSTRE_MSG_MAGIC_V2:
2765 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2767 /* uninitialized yet */
2772 void _debug_req(struct ptlrpc_request *req,
2773 struct libcfs_debug_msg_data *msgdata, const char *fmt, ...)
2775 bool req_ok = req->rq_reqmsg != NULL;
2776 bool rep_ok = false;
2777 lnet_nid_t nid = LNET_NID_ANY;
2778 struct va_format vaf;
2781 int rep_status = -1;
2783 spin_lock(&req->rq_early_free_lock);
2787 if (ptlrpc_req_need_swab(req)) {
2788 req_ok = req_ok && req_ptlrpc_body_swabbed(req);
2789 rep_ok = rep_ok && rep_ptlrpc_body_swabbed(req);
2793 rep_flags = lustre_msg_get_flags(req->rq_repmsg);
2794 rep_status = lustre_msg_get_status(req->rq_repmsg);
2796 spin_unlock(&req->rq_early_free_lock);
2798 if (req->rq_import && req->rq_import->imp_connection)
2799 nid = req->rq_import->imp_connection->c_peer.nid;
2800 else if (req->rq_export && req->rq_export->exp_connection)
2801 nid = req->rq_export->exp_connection->c_peer.nid;
2803 va_start(args, fmt);
2806 libcfs_debug_msg(msgdata,
2807 "%pV req@%p x%llu/t%lld(%lld) o%d->%s@%s:%d/%d lens %d/%d e %d to %lld dl %lld ref %d fl " REQ_FLAGS_FMT "/%x/%x rc %d/%d job:'%s'\n",
2809 req, req->rq_xid, req->rq_transno,
2810 req_ok ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2811 req_ok ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2813 req->rq_import->imp_obd->obd_name :
2815 req->rq_export->exp_client_uuid.uuid :
2817 libcfs_nid2str(nid),
2818 req->rq_request_portal, req->rq_reply_portal,
2819 req->rq_reqlen, req->rq_replen,
2820 req->rq_early_count, (s64)req->rq_timedout,
2821 (s64)req->rq_deadline,
2822 atomic_read(&req->rq_refcount),
2823 DEBUG_REQ_FLAGS(req),
2824 req_ok ? lustre_msg_get_flags(req->rq_reqmsg) : -1,
2825 rep_flags, req->rq_status, rep_status,
2826 req_ok ? lustre_msg_get_jobid(req->rq_reqmsg) ?: ""
2830 EXPORT_SYMBOL(_debug_req);
2832 void lustre_swab_hsm_user_state(struct hsm_user_state *state)
2834 __swab32s(&state->hus_states);
2835 __swab32s(&state->hus_archive_id);
2838 void lustre_swab_hsm_state_set(struct hsm_state_set *hss)
2840 __swab32s(&hss->hss_valid);
2841 __swab64s(&hss->hss_setmask);
2842 __swab64s(&hss->hss_clearmask);
2843 __swab32s(&hss->hss_archive_id);
2846 static void lustre_swab_hsm_extent(struct hsm_extent *extent)
2848 __swab64s(&extent->offset);
2849 __swab64s(&extent->length);
2852 void lustre_swab_hsm_current_action(struct hsm_current_action *action)
2854 __swab32s(&action->hca_state);
2855 __swab32s(&action->hca_action);
2856 lustre_swab_hsm_extent(&action->hca_location);
2859 void lustre_swab_hsm_user_item(struct hsm_user_item *hui)
2861 lustre_swab_lu_fid(&hui->hui_fid);
2862 lustre_swab_hsm_extent(&hui->hui_extent);
2865 void lustre_swab_lu_extent(struct lu_extent *le)
2867 __swab64s(&le->e_start);
2868 __swab64s(&le->e_end);
2871 void lustre_swab_layout_intent(struct layout_intent *li)
2873 __swab32s(&li->li_opc);
2874 __swab32s(&li->li_flags);
2875 lustre_swab_lu_extent(&li->li_extent);
2878 void lustre_swab_hsm_progress_kernel(struct hsm_progress_kernel *hpk)
2880 lustre_swab_lu_fid(&hpk->hpk_fid);
2881 __swab64s(&hpk->hpk_cookie);
2882 __swab64s(&hpk->hpk_extent.offset);
2883 __swab64s(&hpk->hpk_extent.length);
2884 __swab16s(&hpk->hpk_flags);
2885 __swab16s(&hpk->hpk_errval);
2888 void lustre_swab_hsm_request(struct hsm_request *hr)
2890 __swab32s(&hr->hr_action);
2891 __swab32s(&hr->hr_archive_id);
2892 __swab64s(&hr->hr_flags);
2893 __swab32s(&hr->hr_itemcount);
2894 __swab32s(&hr->hr_data_len);
2897 void lustre_swab_object_update(struct object_update *ou)
2899 struct object_update_param *param;
2902 __swab16s(&ou->ou_type);
2903 __swab16s(&ou->ou_params_count);
2904 __swab32s(&ou->ou_result_size);
2905 __swab32s(&ou->ou_flags);
2906 __swab32s(&ou->ou_padding1);
2907 __swab64s(&ou->ou_batchid);
2908 lustre_swab_lu_fid(&ou->ou_fid);
2909 param = &ou->ou_params[0];
2910 for (i = 0; i < ou->ou_params_count; i++) {
2911 __swab16s(¶m->oup_len);
2912 __swab16s(¶m->oup_padding);
2913 __swab32s(¶m->oup_padding2);
2914 param = (struct object_update_param *)((char *)param +
2915 object_update_param_size(param));
2919 int lustre_swab_object_update_request(struct object_update_request *our,
2923 struct object_update *ou;
2925 __swab32s(&our->ourq_magic);
2926 __swab16s(&our->ourq_count);
2927 __swab16s(&our->ourq_padding);
2929 /* Don't need to calculate request size if len is 0. */
2931 size = sizeof(struct object_update_request);
2932 for (i = 0; i < our->ourq_count; i++) {
2933 ou = object_update_request_get(our, i, NULL);
2936 size += sizeof(struct object_update) +
2937 ou->ou_params_count *
2938 sizeof(struct object_update_param);
2940 if (unlikely(size > len))
2944 for (i = 0; i < our->ourq_count; i++) {
2945 ou = object_update_request_get(our, i, NULL);
2946 lustre_swab_object_update(ou);
2952 void lustre_swab_object_update_result(struct object_update_result *our)
2954 __swab32s(&our->our_rc);
2955 __swab16s(&our->our_datalen);
2956 __swab16s(&our->our_padding);
2959 int lustre_swab_object_update_reply(struct object_update_reply *our, __u32 len)
2963 __swab32s(&our->ourp_magic);
2964 __swab16s(&our->ourp_count);
2965 __swab16s(&our->ourp_padding);
2967 size = sizeof(struct object_update_reply) + our->ourp_count *
2968 (sizeof(__u16) + sizeof(struct object_update_result));
2969 if (unlikely(size > len))
2972 for (i = 0; i < our->ourp_count; i++) {
2973 struct object_update_result *ourp;
2975 __swab16s(&our->ourp_lens[i]);
2976 ourp = object_update_result_get(our, i, NULL);
2979 lustre_swab_object_update_result(ourp);
2985 void lustre_swab_out_update_header(struct out_update_header *ouh)
2987 __swab32s(&ouh->ouh_magic);
2988 __swab32s(&ouh->ouh_count);
2989 __swab32s(&ouh->ouh_inline_length);
2990 __swab32s(&ouh->ouh_reply_size);
2992 EXPORT_SYMBOL(lustre_swab_out_update_header);
2994 void lustre_swab_out_update_buffer(struct out_update_buffer *oub)
2996 __swab32s(&oub->oub_size);
2997 __swab32s(&oub->oub_padding);
2999 EXPORT_SYMBOL(lustre_swab_out_update_buffer);
3001 void lustre_swab_swap_layouts(struct mdc_swap_layouts *msl)
3003 __swab64s(&msl->msl_flags);
3006 void lustre_swab_close_data(struct close_data *cd)
3008 lustre_swab_lu_fid(&cd->cd_fid);
3009 __swab64s(&cd->cd_data_version);
3012 void lustre_swab_close_data_resync_done(struct close_data_resync_done *resync)
3016 __swab32s(&resync->resync_count);
3017 /* after swab, resync_count must in CPU endian */
3018 if (resync->resync_count <= INLINE_RESYNC_ARRAY_SIZE) {
3019 for (i = 0; i < resync->resync_count; i++)
3020 __swab32s(&resync->resync_ids_inline[i]);
3023 EXPORT_SYMBOL(lustre_swab_close_data_resync_done);
3025 void lustre_swab_lfsck_request(struct lfsck_request *lr)
3027 __swab32s(&lr->lr_event);
3028 __swab32s(&lr->lr_index);
3029 __swab32s(&lr->lr_flags);
3030 __swab32s(&lr->lr_valid);
3031 __swab32s(&lr->lr_speed);
3032 __swab16s(&lr->lr_version);
3033 __swab16s(&lr->lr_active);
3034 __swab16s(&lr->lr_param);
3035 __swab16s(&lr->lr_async_windows);
3036 __swab32s(&lr->lr_flags);
3037 lustre_swab_lu_fid(&lr->lr_fid);
3038 lustre_swab_lu_fid(&lr->lr_fid2);
3039 __swab32s(&lr->lr_comp_id);
3040 BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_0) == 0);
3041 BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_1) == 0);
3042 BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_2) == 0);
3043 BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_3) == 0);
3046 void lustre_swab_lfsck_reply(struct lfsck_reply *lr)
3048 __swab32s(&lr->lr_status);
3049 BUILD_BUG_ON(offsetof(typeof(*lr), lr_padding_1) == 0);
3050 __swab64s(&lr->lr_repaired);
3053 static void lustre_swab_orphan_rec(struct lu_orphan_rec *rec)
3055 lustre_swab_lu_fid(&rec->lor_fid);
3056 __swab32s(&rec->lor_uid);
3057 __swab32s(&rec->lor_gid);
3060 void lustre_swab_orphan_ent(struct lu_orphan_ent *ent)
3062 lustre_swab_lu_fid(&ent->loe_key);
3063 lustre_swab_orphan_rec(&ent->loe_rec);
3065 EXPORT_SYMBOL(lustre_swab_orphan_ent);
3067 void lustre_swab_orphan_ent_v2(struct lu_orphan_ent_v2 *ent)
3069 lustre_swab_lu_fid(&ent->loe_key);
3070 lustre_swab_orphan_rec(&ent->loe_rec.lor_rec);
3071 lustre_swab_ost_layout(&ent->loe_rec.lor_layout);
3072 BUILD_BUG_ON(offsetof(typeof(ent->loe_rec), lor_padding) == 0);
3074 EXPORT_SYMBOL(lustre_swab_orphan_ent_v2);
3076 void lustre_swab_orphan_ent_v3(struct lu_orphan_ent_v3 *ent)
3078 lustre_swab_lu_fid(&ent->loe_key);
3079 lustre_swab_orphan_rec(&ent->loe_rec.lor_rec);
3080 lustre_swab_ost_layout(&ent->loe_rec.lor_layout);
3081 __swab32s(&ent->loe_rec.lor_layout_version);
3082 __swab32s(&ent->loe_rec.lor_range);
3083 BUILD_BUG_ON(offsetof(typeof(ent->loe_rec), lor_padding_1) == 0);
3084 BUILD_BUG_ON(offsetof(typeof(ent->loe_rec), lor_padding_2) == 0);
3086 EXPORT_SYMBOL(lustre_swab_orphan_ent_v3);
3088 void lustre_swab_ladvise(struct lu_ladvise *ladvise)
3090 __swab16s(&ladvise->lla_advice);
3091 __swab16s(&ladvise->lla_value1);
3092 __swab32s(&ladvise->lla_value2);
3093 __swab64s(&ladvise->lla_start);
3094 __swab64s(&ladvise->lla_end);
3095 __swab32s(&ladvise->lla_value3);
3096 __swab32s(&ladvise->lla_value4);
3098 EXPORT_SYMBOL(lustre_swab_ladvise);
3100 void lustre_swab_ladvise_hdr(struct ladvise_hdr *ladvise_hdr)
3102 __swab32s(&ladvise_hdr->lah_magic);
3103 __swab32s(&ladvise_hdr->lah_count);
3104 __swab64s(&ladvise_hdr->lah_flags);
3105 __swab32s(&ladvise_hdr->lah_value1);
3106 __swab32s(&ladvise_hdr->lah_value2);
3107 __swab64s(&ladvise_hdr->lah_value3);
3109 EXPORT_SYMBOL(lustre_swab_ladvise_hdr);