1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author: Peter J. Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
7 * Author: Eric Barton <eeb@clusterfs.com>
9 * This file is part of the Lustre file system, http://www.lustre.org
10 * Lustre is a trademark of Cluster File Systems, Inc.
12 * You may have signed or agreed to another license before downloading
13 * this software. If so, you are bound by the terms and conditions
14 * of that agreement, and the following does not apply to you. See the
15 * LICENSE file included with this distribution for more information.
17 * If you did not agree to a different license, then this copy of Lustre
18 * is open source software; you can redistribute it and/or modify it
19 * under the terms of version 2 of the GNU General Public License as
20 * published by the Free Software Foundation.
22 * In either case, Lustre is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * license text for more details.
27 * (Un)packing of OST requests
31 #define DEBUG_SUBSYSTEM S_RPC
33 # include <liblustre.h>
36 #include <libcfs/libcfs.h>
38 #include <obd_support.h>
39 #include <obd_class.h>
40 #include <lustre_net.h>
42 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(1,8,0,0)
43 #error "lustre_msg_v1 has been deprecated since 1.6.0, please remove it"
44 #elif LUSTRE_VERSION_CODE > OBD_OCD_VERSION(1,6,50,0)
45 #warning "lustre_msg_v1 has been deprecated since 1.6.0, consider removing it"
48 static inline int lustre_msg_hdr_size_v1(int count)
50 return size_round(offsetof(struct lustre_msg_v1, lm_buflens[count]));
53 static inline int lustre_msg_hdr_size_v2(int count)
55 return size_round(offsetof(struct lustre_msg_v2, lm_buflens[count]));
58 int lustre_msg_swabbed(struct lustre_msg *msg)
60 return (msg->lm_magic == LUSTRE_MSG_MAGIC_V1_SWABBED) ||
61 (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
65 lustre_msg_check_version_v2(struct lustre_msg_v2 *msg, __u32 version)
67 __u32 ver = lustre_msg_get_version(msg);
68 return (ver & LUSTRE_VERSION_MASK) != version;
71 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
73 switch (msg->lm_magic) {
74 case LUSTRE_MSG_MAGIC_V1:
75 case LUSTRE_MSG_MAGIC_V1_SWABBED:
77 case LUSTRE_MSG_MAGIC_V2:
78 case LUSTRE_MSG_MAGIC_V2_SWABBED:
79 return lustre_msg_check_version_v2(msg, version);
81 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
86 static inline int lustre_msg_size_v1(int count, int *lengths)
92 size = lustre_msg_hdr_size_v1(count);
93 for (i = 0; i < count; i++)
94 size += size_round(lengths[i]);
99 int lustre_msg_size_v2(int count, int *lengths)
104 size = lustre_msg_hdr_size_v2(count);
105 for (i = 0; i < count; i++)
106 size += size_round(lengths[i]);
110 EXPORT_SYMBOL(lustre_msg_size_v2);
112 /* This returns the size of the buffer that is required to hold a lustre_msg
113 * with the given sub-buffer lengths.
114 * NOTE: this should only be used for NEW requests, and should always be
115 * in the form of a v2 request. If this is a connection to a v1
116 * target then the first buffer will be stripped because the ptlrpc
117 * data is part of the lustre_msg_v1 header. b=14043 */
118 int lustre_msg_size(__u32 magic, int count, int *lens)
120 int size[] = { sizeof(struct ptlrpc_body) };
128 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
131 case LUSTRE_MSG_MAGIC_V1:
132 return lustre_msg_size_v1(count - 1, lens + 1);
133 case LUSTRE_MSG_MAGIC_V2:
134 return lustre_msg_size_v2(count, lens);
136 LASSERTF(0, "incorrect message magic: %08x\n", magic);
141 /* This is used to determine the size of a buffer that was already packed
142 * and will correctly handle the different message formats. */
143 int lustre_packed_msg_size(struct lustre_msg *msg)
145 switch (msg->lm_magic) {
146 case LUSTRE_MSG_MAGIC_V1: {
147 struct lustre_msg_v1 *v1_msg = (struct lustre_msg_v1 *)msg;
148 return lustre_msg_size_v1(v1_msg->lm_bufcount,
151 case LUSTRE_MSG_MAGIC_V2:
152 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
154 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
160 void lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
162 struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)m;
167 msg->lm_magic = LUSTRE_MSG_MAGIC_V1;
168 msg->lm_version = PTLRPC_MSG_VERSION;
169 msg->lm_bufcount = count;
171 for (i = 0; i < count; i++)
172 msg->lm_buflens[i] = lens[i];
177 ptr = (char *)msg + lustre_msg_hdr_size_v1(count);
178 for (i = 0; i < count; i++) {
180 LOGL(tmp, lens[i], ptr);
184 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
190 msg->lm_bufcount = count;
191 /* XXX: lm_secflvr uninitialized here */
192 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
194 for (i = 0; i < count; i++)
195 msg->lm_buflens[i] = lens[i];
200 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
201 for (i = 0; i < count; i++) {
203 LOGL(tmp, lens[i], ptr);
206 EXPORT_SYMBOL(lustre_init_msg_v2);
208 static int lustre_pack_request_v1(struct ptlrpc_request *req,
209 int count, int *lens, char **bufs)
213 reqlen = lustre_msg_size_v1(count, lens);
215 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
219 req->rq_reqlen = reqlen;
221 lustre_init_msg_v1(req->rq_reqmsg, count, lens, bufs);
225 static int lustre_pack_request_v2(struct ptlrpc_request *req,
226 int count, int *lens, char **bufs)
230 reqlen = lustre_msg_size_v2(count, lens);
232 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
236 req->rq_reqlen = reqlen;
238 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
239 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
240 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
244 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
245 int *lens, char **bufs)
247 int size[] = { sizeof(struct ptlrpc_body) };
255 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
257 /* only use new format, we don't need to be compatible with 1.4 */
258 magic = LUSTRE_MSG_MAGIC_V2;
261 case LUSTRE_MSG_MAGIC_V1:
262 return lustre_pack_request_v1(req, count - 1, lens + 1,
263 bufs ? bufs + 1 : NULL);
264 case LUSTRE_MSG_MAGIC_V2:
265 return lustre_pack_request_v2(req, count, lens, bufs);
267 LASSERTF(0, "incorrect message magic: %08x\n", magic);
273 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
274 spinlock_t ptlrpc_rs_debug_lock;
276 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
278 spin_lock(&ptlrpc_rs_debug_lock); \
279 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
280 spin_unlock(&ptlrpc_rs_debug_lock); \
283 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
285 spin_lock(&ptlrpc_rs_debug_lock); \
286 list_del(&(rs)->rs_debug_list); \
287 spin_unlock(&ptlrpc_rs_debug_lock); \
290 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
291 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
294 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
296 struct ptlrpc_reply_state *rs = NULL;
298 spin_lock(&svc->srv_lock);
299 /* See if we have anything in a pool, and wait if nothing */
300 while (list_empty(&svc->srv_free_rs_list)) {
301 struct l_wait_info lwi;
303 spin_unlock(&svc->srv_lock);
304 /* If we cannot get anything for some long time, we better
305 bail out instead of waiting infinitely */
306 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
307 rc = l_wait_event(svc->srv_free_rs_waitq,
308 !list_empty(&svc->srv_free_rs_list), &lwi);
311 spin_lock(&svc->srv_lock);
314 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
316 list_del(&rs->rs_list);
317 spin_unlock(&svc->srv_lock);
319 memset(rs, 0, svc->srv_max_reply_size);
320 rs->rs_service = svc;
326 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
328 struct ptlrpc_service *svc = rs->rs_service;
332 spin_lock(&svc->srv_lock);
333 list_add(&rs->rs_list, &svc->srv_free_rs_list);
334 spin_unlock(&svc->srv_lock);
335 cfs_waitq_signal(&svc->srv_free_rs_waitq);
338 static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count,
339 int *lens, char **bufs)
341 struct ptlrpc_reply_state *rs;
345 LASSERT (req->rq_reply_state == NULL);
347 msg_len = lustre_msg_size_v1(count, lens);
348 rc = sptlrpc_svc_alloc_rs(req, msg_len);
352 rs = req->rq_reply_state;
353 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
354 rs->rs_cb_id.cbid_fn = reply_out_callback;
355 rs->rs_cb_id.cbid_arg = rs;
356 rs->rs_service = req->rq_rqbd->rqbd_service;
357 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
358 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
360 req->rq_replen = msg_len;
361 req->rq_reply_state = rs;
362 req->rq_repmsg = rs->rs_msg;
363 lustre_init_msg_v1(rs->rs_msg, count, lens, bufs);
365 PTLRPC_RS_DEBUG_LRU_ADD(rs);
370 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
371 int *lens, char **bufs)
373 struct ptlrpc_reply_state *rs;
377 LASSERT(req->rq_reply_state == NULL);
379 msg_len = lustre_msg_size_v2(count, lens);
380 rc = sptlrpc_svc_alloc_rs(req, msg_len);
384 rs = req->rq_reply_state;
385 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
386 rs->rs_cb_id.cbid_fn = reply_out_callback;
387 rs->rs_cb_id.cbid_arg = rs;
388 rs->rs_service = req->rq_rqbd->rqbd_service;
389 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
390 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
392 req->rq_replen = msg_len;
393 req->rq_reply_state = rs;
394 req->rq_repmsg = rs->rs_msg;
395 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
396 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
397 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
399 PTLRPC_RS_DEBUG_LRU_ADD(rs);
403 EXPORT_SYMBOL(lustre_pack_reply_v2);
405 int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
409 int size[] = { sizeof(struct ptlrpc_body) };
417 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
419 switch (req->rq_reqmsg->lm_magic) {
420 case LUSTRE_MSG_MAGIC_V1:
421 case LUSTRE_MSG_MAGIC_V1_SWABBED:
422 rc = lustre_pack_reply_v1(req, count - 1, lens + 1,
423 bufs ? bufs + 1 : NULL);
425 case LUSTRE_MSG_MAGIC_V2:
426 case LUSTRE_MSG_MAGIC_V2_SWABBED:
427 rc = lustre_pack_reply_v2(req, count, lens, bufs);
430 LASSERTF(0, "incorrect message magic: %08x\n",
431 req->rq_reqmsg->lm_magic);
435 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
436 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
440 void *lustre_msg_buf_v1(void *msg, int n, int min_size)
442 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
443 int i, offset, buflen, bufcount;
448 bufcount = m->lm_bufcount;
449 if (unlikely(n >= bufcount)) {
450 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
455 buflen = m->lm_buflens[n];
456 if (unlikely(buflen < min_size)) {
457 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
458 m, n, buflen, min_size);
463 offset = lustre_msg_hdr_size_v1(bufcount);
464 for (i = 0; i < n; i++)
465 offset += size_round(m->lm_buflens[i]);
467 return (char *)m + offset;
470 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
472 int i, offset, buflen, bufcount;
477 bufcount = m->lm_bufcount;
478 if (unlikely(n >= bufcount)) {
479 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
484 buflen = m->lm_buflens[n];
485 if (unlikely(buflen < min_size)) {
486 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
487 m, n, buflen, min_size);
491 offset = lustre_msg_hdr_size_v2(bufcount);
492 for (i = 0; i < n; i++)
493 offset += size_round(m->lm_buflens[i]);
495 return (char *)m + offset;
498 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
500 switch (m->lm_magic) {
501 case LUSTRE_MSG_MAGIC_V1:
502 case LUSTRE_MSG_MAGIC_V1_SWABBED:
503 return lustre_msg_buf_v1(m, n - 1, min_size);
504 case LUSTRE_MSG_MAGIC_V2:
505 case LUSTRE_MSG_MAGIC_V2_SWABBED:
506 return lustre_msg_buf_v2(m, n, min_size);
508 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
513 int lustre_shrink_msg_v1(struct lustre_msg_v1 *msg, int segment,
514 unsigned int newlen, int move_data)
516 char *tail = NULL, *newpos;
520 LASSERT(segment >= 0);
521 LASSERT(msg->lm_bufcount > segment);
522 LASSERT(msg->lm_buflens[segment] >= newlen);
524 if (msg->lm_buflens[segment] == newlen)
527 if (move_data && msg->lm_bufcount > segment + 1) {
528 tail = lustre_msg_buf_v1(msg, segment + 1, 0);
529 for (n = segment + 1; n < msg->lm_bufcount; n++)
530 tail_len += size_round(msg->lm_buflens[n]);
533 msg->lm_buflens[segment] = newlen;
535 if (tail && tail_len) {
536 newpos = lustre_msg_buf_v1(msg, segment + 1, 0);
537 LASSERT(newpos <= tail);
539 memcpy(newpos, tail, tail_len);
542 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
543 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
544 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
545 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
549 return lustre_msg_size_v1(msg->lm_bufcount, (int *)msg->lm_buflens);
552 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
553 unsigned int newlen, int move_data)
555 char *tail = NULL, *newpos;
559 LASSERT(msg->lm_bufcount > segment);
560 LASSERT(msg->lm_buflens[segment] >= newlen);
562 if (msg->lm_buflens[segment] == newlen)
565 if (move_data && msg->lm_bufcount > segment + 1) {
566 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
567 for (n = segment + 1; n < msg->lm_bufcount; n++)
568 tail_len += size_round(msg->lm_buflens[n]);
571 msg->lm_buflens[segment] = newlen;
573 if (tail && tail_len) {
574 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
575 LASSERT(newpos <= tail);
577 memcpy(newpos, tail, tail_len);
580 return lustre_msg_size_v2(msg->lm_bufcount, (int *)msg->lm_buflens);
584 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
585 * we also move data forward from @segment + 1.
587 * if @newlen == 0, we remove the segment completely, but we still keep the
588 * totally bufcount the same to save possible data moving. this will leave a
589 * unused segment with size 0 at the tail, but that's ok.
591 * return new msg size after shrinking.
594 * + if any buffers higher than @segment has been filled in, must call shrink
595 * with non-zero @move_data.
596 * + caller should NOT keep pointers to msg buffers which higher than @segment
599 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
600 unsigned int newlen, int move_data)
602 switch (msg->lm_magic) {
603 case LUSTRE_MSG_MAGIC_V1:
604 return lustre_shrink_msg_v1((struct lustre_msg_v1 *) msg,
605 segment - 1, newlen, move_data);
606 case LUSTRE_MSG_MAGIC_V2:
607 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
609 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
613 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
615 PTLRPC_RS_DEBUG_LRU_DEL(rs);
617 LASSERT (atomic_read(&rs->rs_refcount) == 0);
618 LASSERT (!rs->rs_difficult || rs->rs_handled);
619 LASSERT (!rs->rs_on_net);
620 LASSERT (!rs->rs_scheduled);
621 LASSERT (rs->rs_export == NULL);
622 LASSERT (rs->rs_nlocks == 0);
623 LASSERT (list_empty(&rs->rs_exp_list));
624 LASSERT (list_empty(&rs->rs_obd_list));
626 sptlrpc_svc_free_rs(rs);
629 int lustre_unpack_msg_v1(void *msg, int len)
631 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
632 int flipped, required_len, i;
635 /* Now we know the sender speaks my language. */
636 required_len = lustre_msg_hdr_size_v1(0);
637 if (len < required_len) {
638 /* can't even look inside the message */
639 CERROR("message length %d too small for lustre_msg\n", len);
643 flipped = lustre_msg_swabbed((struct lustre_msg *)m);
646 __swab32s(&m->lm_type);
647 __swab32s(&m->lm_version);
648 __swab32s(&m->lm_opc);
649 __swab64s(&m->lm_last_xid);
650 __swab64s(&m->lm_last_committed);
651 __swab64s(&m->lm_transno);
652 __swab32s(&m->lm_status);
653 __swab32s(&m->lm_flags);
654 __swab32s(&m->lm_conn_cnt);
655 __swab32s(&m->lm_bufcount);
658 if (m->lm_version != PTLRPC_MSG_VERSION) {
659 CERROR("wrong lustre_msg version %08x\n", m->lm_version);
663 required_len = lustre_msg_hdr_size_v1(m->lm_bufcount);
664 if (len < required_len) {
665 /* didn't receive all the buffer lengths */
666 CERROR("message length %d too small for %d buflens\n",
667 len, m->lm_bufcount);
671 for (i = 0; i < m->lm_bufcount; i++) {
673 __swab32s (&m->lm_buflens[i]);
674 required_len += size_round(m->lm_buflens[i]);
677 if (len < required_len) {
678 CERROR("len: %d, required_len %d\n", len, required_len);
679 CERROR("bufcount: %d\n", m->lm_bufcount);
680 for (i = 0; i < m->lm_bufcount; i++)
681 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
688 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
690 int flipped, required_len, i;
692 /* Now we know the sender speaks my language. */
693 required_len = lustre_msg_hdr_size_v2(0);
694 if (len < required_len) {
695 /* can't even look inside the message */
696 CERROR("message length %d too small for lustre_msg\n", len);
700 flipped = lustre_msg_swabbed(m);
703 __swab32s(&m->lm_bufcount);
704 __swab32s(&m->lm_secflvr);
705 __swab32s(&m->lm_repsize);
706 __swab32s(&m->lm_timeout);
707 CLASSERT(offsetof(typeof(*m), lm_padding_1) != 0);
708 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
709 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
712 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
713 if (len < required_len) {
714 /* didn't receive all the buffer lengths */
715 CERROR ("message length %d too small for %d buflens\n",
716 len, m->lm_bufcount);
720 for (i = 0; i < m->lm_bufcount; i++) {
722 __swab32s(&m->lm_buflens[i]);
723 required_len += size_round(m->lm_buflens[i]);
726 if (len < required_len) {
727 CERROR("len: %d, required_len %d\n", len, required_len);
728 CERROR("bufcount: %d\n", m->lm_bufcount);
729 for (i = 0; i < m->lm_bufcount; i++)
730 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
737 int lustre_unpack_msg(struct lustre_msg *m, int len)
739 int required_len, rc;
742 /* We can provide a slightly better error log, if we check the
743 * message magic and version first. In the future, struct
744 * lustre_msg may grow, and we'd like to log a version mismatch,
745 * rather than a short message.
748 required_len = offsetof(struct lustre_msg, lm_magic) +
750 if (len < required_len) {
751 /* can't even look inside the message */
752 CERROR("message length %d too small for magic/version check\n",
757 switch (m->lm_magic) {
758 case LUSTRE_MSG_MAGIC_V1:
759 case LUSTRE_MSG_MAGIC_V1_SWABBED:
760 rc = lustre_unpack_msg_v1(m, len);
762 case LUSTRE_MSG_MAGIC_V2:
763 case LUSTRE_MSG_MAGIC_V2_SWABBED:
764 rc = lustre_unpack_msg_v2(m, len);
767 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
774 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
777 struct ptlrpc_body *pb;
779 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
781 CERROR("error unpacking ptlrpc body");
784 if (lustre_msg_swabbed(m))
785 lustre_swab_ptlrpc_body(pb);
787 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
788 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
795 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
797 switch (req->rq_reqmsg->lm_magic) {
798 case LUSTRE_MSG_MAGIC_V1:
799 case LUSTRE_MSG_MAGIC_V1_SWABBED:
801 case LUSTRE_MSG_MAGIC_V2:
802 case LUSTRE_MSG_MAGIC_V2_SWABBED:
803 lustre_set_req_swabbed(req, offset);
804 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
806 CERROR("bad lustre msg magic: %#08X\n",
807 req->rq_reqmsg->lm_magic);
812 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
814 switch (req->rq_repmsg->lm_magic) {
815 case LUSTRE_MSG_MAGIC_V1:
816 case LUSTRE_MSG_MAGIC_V1_SWABBED:
818 case LUSTRE_MSG_MAGIC_V2:
819 case LUSTRE_MSG_MAGIC_V2_SWABBED:
820 lustre_set_rep_swabbed(req, offset);
821 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
823 CERROR("bad lustre msg magic: %#08X\n",
824 req->rq_repmsg->lm_magic);
829 static inline int lustre_msg_buflen_v1(void *msg, int n)
831 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
834 if (n >= m->lm_bufcount)
837 return m->lm_buflens[n];
840 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
842 if (n >= m->lm_bufcount)
845 return m->lm_buflens[n];
849 * lustre_msg_buflen - return the length of buffer @n in message @m
850 * @m - lustre_msg (request or reply) to look at
851 * @n - message index (base 0)
853 * returns zero for non-existent message indices
855 int lustre_msg_buflen(struct lustre_msg *m, int n)
857 switch (m->lm_magic) {
858 case LUSTRE_MSG_MAGIC_V1:
859 case LUSTRE_MSG_MAGIC_V1_SWABBED:
860 return lustre_msg_buflen_v1(m, n - 1);
861 case LUSTRE_MSG_MAGIC_V2:
862 case LUSTRE_MSG_MAGIC_V2_SWABBED:
863 return lustre_msg_buflen_v2(m, n);
865 CERROR("incorrect message magic: %08x\n", m->lm_magic);
869 EXPORT_SYMBOL(lustre_msg_buflen);
871 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
873 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
876 if (n >= m->lm_bufcount)
879 m->lm_buflens[n] = len;
883 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
885 if (n >= m->lm_bufcount)
888 m->lm_buflens[n] = len;
891 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
893 switch (m->lm_magic) {
894 case LUSTRE_MSG_MAGIC_V1:
895 lustre_msg_set_buflen_v1(m, n - 1, len);
897 case LUSTRE_MSG_MAGIC_V2:
898 lustre_msg_set_buflen_v2(m, n, len);
901 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
905 EXPORT_SYMBOL(lustre_msg_set_buflen);
907 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
908 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
909 int lustre_msg_bufcount(struct lustre_msg *m)
911 switch (m->lm_magic) {
912 case LUSTRE_MSG_MAGIC_V1:
913 case LUSTRE_MSG_MAGIC_V1_SWABBED:
914 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
915 case LUSTRE_MSG_MAGIC_V2:
916 case LUSTRE_MSG_MAGIC_V2_SWABBED:
917 return m->lm_bufcount;
919 CERROR("incorrect message magic: %08x\n", m->lm_magic);
923 EXPORT_SYMBOL(lustre_msg_bufcount);
925 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
927 /* max_len == 0 means the string should fill the buffer */
931 switch (m->lm_magic) {
932 case LUSTRE_MSG_MAGIC_V1:
933 case LUSTRE_MSG_MAGIC_V1_SWABBED:
934 str = lustre_msg_buf_v1(m, index - 1, 0);
935 blen = lustre_msg_buflen_v1(m, index - 1);
937 case LUSTRE_MSG_MAGIC_V2:
938 case LUSTRE_MSG_MAGIC_V2_SWABBED:
939 str = lustre_msg_buf_v2(m, index, 0);
940 blen = lustre_msg_buflen_v2(m, index);
943 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
947 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
951 slen = strnlen(str, blen);
953 if (slen == blen) { /* not NULL terminated */
954 CERROR("can't unpack non-NULL terminated string in "
955 "msg %p buffer[%d] len %d\n", m, index, blen);
960 if (slen != blen - 1) {
961 CERROR("can't unpack short string in msg %p "
962 "buffer[%d] len %d: strlen %d\n",
963 m, index, blen, slen);
966 } else if (slen > max_len) {
967 CERROR("can't unpack oversized string in msg %p "
968 "buffer[%d] len %d strlen %d: max %d expected\n",
969 m, index, blen, slen, max_len);
976 /* Wrap up the normal fixed length cases */
977 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
982 switch (msg->lm_magic) {
983 case LUSTRE_MSG_MAGIC_V1:
984 case LUSTRE_MSG_MAGIC_V1_SWABBED:
985 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
987 case LUSTRE_MSG_MAGIC_V2:
988 case LUSTRE_MSG_MAGIC_V2_SWABBED:
989 ptr = lustre_msg_buf_v2(msg, index, min_size);
992 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
997 if (swabber != NULL && lustre_msg_swabbed(msg))
998 ((void (*)(void *))swabber)(ptr);
1003 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
1006 lustre_set_req_swabbed(req, index);
1007 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
1010 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
1013 lustre_set_rep_swabbed(req, index);
1014 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
1017 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
1019 switch (msg->lm_magic) {
1020 case LUSTRE_MSG_MAGIC_V1:
1021 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1022 return ((struct lustre_msg_v1 *)msg)->lm_flags &
1024 case LUSTRE_MSG_MAGIC_V2:
1025 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1026 struct ptlrpc_body *pb;
1028 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1030 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1033 return pb->pb_flags;
1036 /* flags might be printed in debug code while message
1042 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
1044 switch (msg->lm_magic) {
1045 case LUSTRE_MSG_MAGIC_V1:
1046 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1047 MSG_GEN_FLAG_MASK & flags;
1049 case LUSTRE_MSG_MAGIC_V2: {
1050 struct ptlrpc_body *pb;
1052 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1053 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1054 pb->pb_flags |= flags;
1058 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1062 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
1064 switch (msg->lm_magic) {
1065 case LUSTRE_MSG_MAGIC_V1:
1066 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK;
1067 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1068 MSG_GEN_FLAG_MASK & flags;
1070 case LUSTRE_MSG_MAGIC_V2: {
1071 struct ptlrpc_body *pb;
1073 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1074 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1075 pb->pb_flags = flags;
1079 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1083 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1085 switch (msg->lm_magic) {
1086 case LUSTRE_MSG_MAGIC_V1:
1087 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1088 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1089 ~(MSG_GEN_FLAG_MASK & flags);
1091 case LUSTRE_MSG_MAGIC_V2:
1092 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1093 struct ptlrpc_body *pb;
1095 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1096 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1097 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
1101 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1105 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1107 switch (msg->lm_magic) {
1108 case LUSTRE_MSG_MAGIC_V1:
1109 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1110 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1112 case LUSTRE_MSG_MAGIC_V2:
1113 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1114 struct ptlrpc_body *pb;
1116 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1118 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1121 return pb->pb_op_flags;
1128 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1130 switch (msg->lm_magic) {
1131 case LUSTRE_MSG_MAGIC_V1:
1132 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1133 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1135 case LUSTRE_MSG_MAGIC_V2: {
1136 struct ptlrpc_body *pb;
1138 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1139 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1140 pb->pb_op_flags |= flags;
1144 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1148 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
1150 switch (msg->lm_magic) {
1151 case LUSTRE_MSG_MAGIC_V1:
1152 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK;
1153 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1154 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1156 case LUSTRE_MSG_MAGIC_V2: {
1157 struct ptlrpc_body *pb;
1159 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1160 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1161 pb->pb_op_flags |= flags;
1165 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1169 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1171 switch (msg->lm_magic) {
1172 case LUSTRE_MSG_MAGIC_V1:
1173 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1174 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1175 case LUSTRE_MSG_MAGIC_V2:
1176 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1177 struct ptlrpc_body *pb;
1179 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1181 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1184 return &pb->pb_handle;
1187 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1192 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1194 switch (msg->lm_magic) {
1195 case LUSTRE_MSG_MAGIC_V1:
1196 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1197 return ((struct lustre_msg_v1 *)msg)->lm_type;
1198 case LUSTRE_MSG_MAGIC_V2:
1199 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1200 struct ptlrpc_body *pb;
1202 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1204 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1205 return PTL_RPC_MSG_ERR;
1210 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1211 return PTL_RPC_MSG_ERR;
1215 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1217 switch (msg->lm_magic) {
1218 case LUSTRE_MSG_MAGIC_V1:
1219 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1220 return ((struct lustre_msg_v1 *)msg)->lm_version;
1221 case LUSTRE_MSG_MAGIC_V2:
1222 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1223 struct ptlrpc_body *pb;
1225 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1227 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1230 return pb->pb_version;
1233 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1238 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1240 switch (msg->lm_magic) {
1241 case LUSTRE_MSG_MAGIC_V1:
1242 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1244 case LUSTRE_MSG_MAGIC_V2:
1245 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1246 struct ptlrpc_body *pb;
1248 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1249 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1250 pb->pb_version |= version;
1254 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1258 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1260 switch (msg->lm_magic) {
1261 case LUSTRE_MSG_MAGIC_V1:
1262 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1263 return ((struct lustre_msg_v1 *)msg)->lm_opc;
1264 case LUSTRE_MSG_MAGIC_V2:
1265 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1266 struct ptlrpc_body *pb;
1268 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1270 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1276 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1281 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1283 switch (msg->lm_magic) {
1284 case LUSTRE_MSG_MAGIC_V1:
1285 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1286 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1287 case LUSTRE_MSG_MAGIC_V2:
1288 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1289 struct ptlrpc_body *pb;
1291 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1293 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1296 return pb->pb_last_xid;
1299 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1304 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1306 switch (msg->lm_magic) {
1307 case LUSTRE_MSG_MAGIC_V1:
1308 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1309 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1310 case LUSTRE_MSG_MAGIC_V2:
1311 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1312 struct ptlrpc_body *pb;
1314 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1316 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1319 return pb->pb_last_committed;
1322 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1327 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1329 switch (msg->lm_magic) {
1330 case LUSTRE_MSG_MAGIC_V1:
1331 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1332 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1333 case LUSTRE_MSG_MAGIC_V2:
1334 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1335 struct ptlrpc_body *pb;
1337 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1339 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1342 return pb->pb_transno;
1345 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1350 int lustre_msg_get_status(struct lustre_msg *msg)
1352 switch (msg->lm_magic) {
1353 case LUSTRE_MSG_MAGIC_V1:
1354 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1355 return ((struct lustre_msg_v1 *)msg)->lm_status;
1356 case LUSTRE_MSG_MAGIC_V2:
1357 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1358 struct ptlrpc_body *pb;
1360 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1362 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1365 return pb->pb_status;
1368 /* status might be printed in debug code while message
1374 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1376 switch (msg->lm_magic) {
1377 case LUSTRE_MSG_MAGIC_V1:
1378 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1380 case LUSTRE_MSG_MAGIC_V2:
1381 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1382 struct ptlrpc_body *pb;
1384 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1386 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1392 CERROR("invalid msg magic %x\n", msg->lm_magic);
1398 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1400 switch (msg->lm_magic) {
1401 case LUSTRE_MSG_MAGIC_V1:
1402 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1404 case LUSTRE_MSG_MAGIC_V2:
1405 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1406 struct ptlrpc_body *pb;
1408 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1410 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1417 CERROR("invalid msg magic %x\n", msg->lm_magic);
1422 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1424 switch (msg->lm_magic) {
1425 case LUSTRE_MSG_MAGIC_V1:
1426 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1428 case LUSTRE_MSG_MAGIC_V2:
1429 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1430 struct ptlrpc_body *pb;
1432 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1434 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1437 return pb->pb_limit;
1440 CERROR("invalid msg magic %x\n", msg->lm_magic);
1446 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1448 switch (msg->lm_magic) {
1449 case LUSTRE_MSG_MAGIC_V1:
1450 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1452 case LUSTRE_MSG_MAGIC_V2:
1453 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1454 struct ptlrpc_body *pb;
1456 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1458 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1461 pb->pb_limit = limit;
1465 CERROR("invalid msg magic %x\n", msg->lm_magic);
1470 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1472 switch (msg->lm_magic) {
1473 case LUSTRE_MSG_MAGIC_V1:
1474 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1475 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1476 case LUSTRE_MSG_MAGIC_V2:
1477 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1478 struct ptlrpc_body *pb;
1480 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1482 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1485 return pb->pb_conn_cnt;
1488 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1493 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1495 switch (msg->lm_magic) {
1496 case LUSTRE_MSG_MAGIC_V1:
1497 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1498 case LUSTRE_MSG_MAGIC_V2:
1499 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1500 return msg->lm_magic;
1502 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1507 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1509 switch (msg->lm_magic) {
1510 case LUSTRE_MSG_MAGIC_V1:
1511 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1513 case LUSTRE_MSG_MAGIC_V2: {
1514 struct ptlrpc_body *pb;
1516 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1517 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1518 pb->pb_handle = *handle;
1522 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1526 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1528 switch (msg->lm_magic) {
1529 case LUSTRE_MSG_MAGIC_V1:
1530 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1532 case LUSTRE_MSG_MAGIC_V2: {
1533 struct ptlrpc_body *pb;
1535 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1536 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1541 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1545 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1547 switch (msg->lm_magic) {
1548 case LUSTRE_MSG_MAGIC_V1:
1549 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1551 case LUSTRE_MSG_MAGIC_V2: {
1552 struct ptlrpc_body *pb;
1554 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1555 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1560 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1564 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1566 switch (msg->lm_magic) {
1567 case LUSTRE_MSG_MAGIC_V1:
1568 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1570 case LUSTRE_MSG_MAGIC_V2: {
1571 struct ptlrpc_body *pb;
1573 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1574 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1575 pb->pb_last_xid = last_xid;
1579 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1583 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1585 switch (msg->lm_magic) {
1586 case LUSTRE_MSG_MAGIC_V1:
1587 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1589 case LUSTRE_MSG_MAGIC_V2: {
1590 struct ptlrpc_body *pb;
1592 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1593 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1594 pb->pb_last_committed = last_committed;
1598 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1602 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1604 switch (msg->lm_magic) {
1605 case LUSTRE_MSG_MAGIC_V1:
1606 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1608 case LUSTRE_MSG_MAGIC_V2: {
1609 struct ptlrpc_body *pb;
1611 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1612 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1613 pb->pb_transno = transno;
1617 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1621 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1623 switch (msg->lm_magic) {
1624 case LUSTRE_MSG_MAGIC_V1:
1625 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1627 case LUSTRE_MSG_MAGIC_V2: {
1628 struct ptlrpc_body *pb;
1630 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1631 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1632 pb->pb_status = status;
1636 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1640 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1642 switch (msg->lm_magic) {
1643 case LUSTRE_MSG_MAGIC_V1:
1644 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1646 case LUSTRE_MSG_MAGIC_V2: {
1647 struct ptlrpc_body *pb;
1649 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1650 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1651 pb->pb_conn_cnt = conn_cnt;
1655 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1659 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1661 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1663 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1664 req->rq_pill.rc_area[RCL_SERVER]);
1665 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1666 req->rq_reqmsg->lm_repsize = req->rq_replen;
1669 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, int *lens)
1671 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1672 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1673 req->rq_reqmsg->lm_repsize = req->rq_replen;
1676 /* byte flipping routines for all wire types declared in
1677 * lustre_idl.h implemented here.
1679 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1681 __swab32s (&b->pb_type);
1682 __swab32s (&b->pb_version);
1683 __swab32s (&b->pb_opc);
1684 __swab32s (&b->pb_status);
1685 __swab64s (&b->pb_last_xid);
1686 __swab64s (&b->pb_last_seen);
1687 __swab64s (&b->pb_last_committed);
1688 __swab64s (&b->pb_transno);
1689 __swab32s (&b->pb_flags);
1690 __swab32s (&b->pb_op_flags);
1691 __swab32s (&b->pb_conn_cnt);
1692 CLASSERT(offsetof(typeof(*b), pb_padding_1) != 0);
1693 CLASSERT(offsetof(typeof(*b), pb_padding_2) != 0);
1694 __swab32s (&b->pb_limit);
1695 __swab64s (&b->pb_slv);
1698 void lustre_swab_connect(struct obd_connect_data *ocd)
1700 __swab64s(&ocd->ocd_connect_flags);
1701 __swab32s(&ocd->ocd_version);
1702 __swab32s(&ocd->ocd_grant);
1703 __swab64s(&ocd->ocd_ibits_known);
1704 __swab32s(&ocd->ocd_index);
1705 __swab32s(&ocd->ocd_brw_size);
1706 __swab32s(&ocd->ocd_nllu);
1707 __swab32s(&ocd->ocd_nllg);
1708 __swab64s(&ocd->ocd_transno);
1709 __swab32s(&ocd->ocd_group);
1710 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1711 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1712 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1715 void lustre_swab_obdo (struct obdo *o)
1717 __swab64s (&o->o_valid);
1718 __swab64s (&o->o_id);
1719 __swab64s (&o->o_gr);
1720 __swab64s (&o->o_fid);
1721 __swab64s (&o->o_size);
1722 __swab64s (&o->o_mtime);
1723 __swab64s (&o->o_atime);
1724 __swab64s (&o->o_ctime);
1725 __swab64s (&o->o_blocks);
1726 __swab64s (&o->o_grant);
1727 __swab32s (&o->o_blksize);
1728 __swab32s (&o->o_mode);
1729 __swab32s (&o->o_uid);
1730 __swab32s (&o->o_gid);
1731 __swab32s (&o->o_flags);
1732 __swab32s (&o->o_nlink);
1733 __swab32s (&o->o_generation);
1734 __swab32s (&o->o_misc);
1735 __swab32s (&o->o_easize);
1736 __swab32s (&o->o_mds);
1737 __swab32s (&o->o_stripe_idx);
1738 __swab32s (&o->o_padding_1);
1739 /* o_inline is opaque */
1742 void lustre_swab_obd_statfs (struct obd_statfs *os)
1744 __swab64s (&os->os_type);
1745 __swab64s (&os->os_blocks);
1746 __swab64s (&os->os_bfree);
1747 __swab64s (&os->os_bavail);
1748 __swab64s (&os->os_files);
1749 __swab64s (&os->os_ffree);
1750 /* no need to swab os_fsid */
1751 __swab32s (&os->os_bsize);
1752 __swab32s (&os->os_namelen);
1753 __swab64s (&os->os_maxbytes);
1754 __swab32s (&os->os_state);
1755 /* no need to swap os_spare */
1758 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1760 __swab64s (&ioo->ioo_id);
1761 __swab64s (&ioo->ioo_gr);
1762 __swab32s (&ioo->ioo_type);
1763 __swab32s (&ioo->ioo_bufcnt);
1766 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1768 __swab64s (&nbr->offset);
1769 __swab32s (&nbr->len);
1770 __swab32s (&nbr->flags);
1773 void lustre_swab_ost_body (struct ost_body *b)
1775 lustre_swab_obdo (&b->oa);
1778 void lustre_swab_ost_last_id(obd_id *id)
1783 void lustre_swab_generic_32s(__u32 *val)
1788 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1790 __swab64s(&lvb->lvb_size);
1791 __swab64s(&lvb->lvb_mtime);
1792 __swab64s(&lvb->lvb_atime);
1793 __swab64s(&lvb->lvb_ctime);
1794 __swab64s(&lvb->lvb_blocks);
1797 void lustre_swab_mds_status_req (struct mds_status_req *r)
1799 __swab32s (&r->flags);
1800 __swab32s (&r->repbuf);
1803 void lustre_swab_mds_body (struct mds_body *b)
1805 lustre_swab_ll_fid (&b->fid1);
1806 lustre_swab_ll_fid (&b->fid2);
1807 /* handle is opaque */
1808 __swab64s (&b->valid);
1809 __swab64s (&b->size);
1810 __swab64s (&b->mtime);
1811 __swab64s (&b->atime);
1812 __swab64s (&b->ctime);
1813 __swab64s (&b->blocks);
1814 __swab64s (&b->io_epoch);
1815 __swab64s (&b->ino);
1816 __swab32s (&b->fsuid);
1817 __swab32s (&b->fsgid);
1818 __swab32s (&b->capability);
1819 __swab32s (&b->mode);
1820 __swab32s (&b->uid);
1821 __swab32s (&b->gid);
1822 __swab32s (&b->flags);
1823 __swab32s (&b->rdev);
1824 __swab32s (&b->nlink);
1825 __swab32s (&b->generation);
1826 __swab32s (&b->suppgid);
1827 __swab32s (&b->eadatasize);
1828 __swab32s (&b->aclsize);
1829 __swab32s (&b->max_mdsize);
1830 __swab32s (&b->max_cookiesize);
1831 __swab32s (&b->padding_4);
1834 void lustre_swab_mdt_body (struct mdt_body *b)
1836 lustre_swab_lu_fid (&b->fid1);
1837 lustre_swab_lu_fid (&b->fid2);
1838 /* handle is opaque */
1839 __swab64s (&b->valid);
1840 __swab64s (&b->size);
1841 __swab64s (&b->mtime);
1842 __swab64s (&b->atime);
1843 __swab64s (&b->ctime);
1844 __swab64s (&b->blocks);
1845 __swab64s (&b->ioepoch);
1846 __swab64s (&b->ino);
1847 __swab32s (&b->fsuid);
1848 __swab32s (&b->fsgid);
1849 __swab32s (&b->capability);
1850 __swab32s (&b->mode);
1851 __swab32s (&b->uid);
1852 __swab32s (&b->gid);
1853 __swab32s (&b->flags);
1854 __swab32s (&b->rdev);
1855 __swab32s (&b->nlink);
1856 __swab32s (&b->generation);
1857 __swab32s (&b->suppgid);
1858 __swab32s (&b->eadatasize);
1859 __swab32s (&b->aclsize);
1860 __swab32s (&b->max_mdsize);
1861 __swab32s (&b->max_cookiesize);
1862 __swab32s (&b->padding_4);
1865 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1867 /* handle is opaque */
1868 __swab64s (&b->ioepoch);
1869 __swab32s (&b->flags);
1870 CLASSERT(offsetof(typeof(*b), padding) != 0);
1873 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1876 __swab32s(&mti->mti_lustre_ver);
1877 __swab32s(&mti->mti_stripe_index);
1878 __swab32s(&mti->mti_config_ver);
1879 __swab32s(&mti->mti_flags);
1880 __swab32s(&mti->mti_nid_count);
1881 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1882 for (i = 0; i < MTI_NIDS_MAX; i++)
1883 __swab64s(&mti->mti_nids[i]);
1886 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1888 __swab64s (&i->dqi_bgrace);
1889 __swab64s (&i->dqi_igrace);
1890 __swab32s (&i->dqi_flags);
1891 __swab32s (&i->dqi_valid);
1894 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1896 __swab64s (&b->dqb_ihardlimit);
1897 __swab64s (&b->dqb_isoftlimit);
1898 __swab64s (&b->dqb_curinodes);
1899 __swab64s (&b->dqb_bhardlimit);
1900 __swab64s (&b->dqb_bsoftlimit);
1901 __swab64s (&b->dqb_curspace);
1902 __swab64s (&b->dqb_btime);
1903 __swab64s (&b->dqb_itime);
1904 __swab32s (&b->dqb_valid);
1905 CLASSERT(offsetof(typeof(*b), padding) != 0);
1908 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1910 __swab32s (&q->qc_cmd);
1911 __swab32s (&q->qc_type);
1912 __swab32s (&q->qc_id);
1913 __swab32s (&q->qc_stat);
1914 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1915 lustre_swab_obd_dqblk (&q->qc_dqblk);
1918 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1920 __swab32s (&p->rp_uid);
1921 __swab32s (&p->rp_gid);
1922 __swab32s (&p->rp_fsuid);
1923 __swab32s (&p->rp_fsgid);
1924 __swab32s (&p->rp_access_perm);
1927 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1929 __swab32s (&p->rp_uid);
1930 __swab32s (&p->rp_gid);
1931 __swab32s (&p->rp_fsuid);
1932 __swab32s (&p->rp_fsgid);
1933 __swab32s (&p->rp_access_perm);
1936 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1938 __swab32s (&sa->sa_opcode);
1939 __swab32s (&sa->sa_fsuid);
1940 __swab32s (&sa->sa_fsgid);
1941 __swab32s (&sa->sa_cap);
1942 __swab32s (&sa->sa_suppgid);
1943 __swab32s (&sa->sa_mode);
1944 lustre_swab_ll_fid (&sa->sa_fid);
1945 __swab64s (&sa->sa_valid);
1946 __swab64s (&sa->sa_size);
1947 __swab64s (&sa->sa_mtime);
1948 __swab64s (&sa->sa_atime);
1949 __swab64s (&sa->sa_ctime);
1950 __swab32s (&sa->sa_uid);
1951 __swab32s (&sa->sa_gid);
1952 __swab32s (&sa->sa_attr_flags);
1953 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1956 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1958 __swab64s(&jr->jr_headsize);
1959 lustre_swab_ll_fid(&jr->jr_fid);
1962 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1964 __swab64s(&jr->jr_headsize);
1965 lustre_swab_lu_fid(&jr->jr_fid);
1968 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1970 __swab32s (&cr->cr_opcode);
1971 __swab32s (&cr->cr_fsuid);
1972 __swab32s (&cr->cr_fsgid);
1973 __swab32s (&cr->cr_cap);
1974 __swab32s (&cr->cr_flags); /* for use with open */
1975 __swab32s (&cr->cr_mode);
1976 lustre_swab_ll_fid (&cr->cr_fid);
1977 lustre_swab_ll_fid (&cr->cr_replayfid);
1978 __swab64s (&cr->cr_time);
1979 __swab64s (&cr->cr_rdev);
1980 __swab32s (&cr->cr_suppgid);
1981 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1982 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1983 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1984 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1985 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1988 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1990 __swab32s (&lk->lk_opcode);
1991 __swab32s (&lk->lk_fsuid);
1992 __swab32s (&lk->lk_fsgid);
1993 __swab32s (&lk->lk_cap);
1994 __swab32s (&lk->lk_suppgid1);
1995 __swab32s (&lk->lk_suppgid2);
1996 lustre_swab_ll_fid (&lk->lk_fid1);
1997 lustre_swab_ll_fid (&lk->lk_fid2);
1998 __swab64s (&lk->lk_time);
1999 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
2000 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2001 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2002 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2005 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
2007 __swab32s (&ul->ul_opcode);
2008 __swab32s (&ul->ul_fsuid);
2009 __swab32s (&ul->ul_fsgid);
2010 __swab32s (&ul->ul_cap);
2011 __swab32s (&ul->ul_suppgid);
2012 __swab32s (&ul->ul_mode);
2013 lustre_swab_ll_fid (&ul->ul_fid1);
2014 lustre_swab_ll_fid (&ul->ul_fid2);
2015 __swab64s (&ul->ul_time);
2016 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
2017 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2018 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2019 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2022 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
2024 __swab32s (&rn->rn_opcode);
2025 __swab32s (&rn->rn_fsuid);
2026 __swab32s (&rn->rn_fsgid);
2027 __swab32s (&rn->rn_cap);
2028 __swab32s (&rn->rn_suppgid1);
2029 __swab32s (&rn->rn_suppgid2);
2030 lustre_swab_ll_fid (&rn->rn_fid1);
2031 lustre_swab_ll_fid (&rn->rn_fid2);
2032 __swab64s (&rn->rn_time);
2033 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
2034 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
2035 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2036 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2039 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
2041 __swab32s (&rr->rr_opcode);
2042 __swab32s (&rr->rr_fsuid);
2043 __swab32s (&rr->rr_fsgid);
2044 __swab32s (&rr->rr_cap);
2045 __swab32s (&rr->rr_suppgid1);
2046 __swab32s (&rr->rr_suppgid2);
2047 /* handle is opaque */
2048 lustre_swab_lu_fid (&rr->rr_fid1);
2049 lustre_swab_lu_fid (&rr->rr_fid2);
2050 __swab64s (&rr->rr_mtime);
2051 __swab64s (&rr->rr_atime);
2052 __swab64s (&rr->rr_ctime);
2053 __swab64s (&rr->rr_size);
2054 __swab64s (&rr->rr_blocks);
2055 __swab32s (&rr->rr_bias);
2056 __swab32s (&rr->rr_mode);
2057 __swab32s (&rr->rr_padding_1);
2058 __swab32s (&rr->rr_padding_2);
2059 __swab32s (&rr->rr_padding_3);
2060 __swab32s (&rr->rr_padding_4);
2062 CLASSERT(offsetof(typeof(*rr), rr_padding_1) != 0);
2063 CLASSERT(offsetof(typeof(*rr), rr_padding_2) != 0);
2064 CLASSERT(offsetof(typeof(*rr), rr_padding_3) != 0);
2065 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
2068 void lustre_swab_lov_desc (struct lov_desc *ld)
2070 __swab32s (&ld->ld_tgt_count);
2071 __swab32s (&ld->ld_active_tgt_count);
2072 __swab32s (&ld->ld_default_stripe_count);
2073 __swab64s (&ld->ld_default_stripe_size);
2074 __swab64s (&ld->ld_default_stripe_offset);
2075 __swab32s (&ld->ld_pattern);
2076 __swab32s (&ld->ld_qos_maxage);
2077 /* uuid endian insensitive */
2080 /*begin adding MDT by huanghua@clusterfs.com*/
2081 void lustre_swab_lmv_desc (struct lmv_desc *ld)
2083 __swab32s (&ld->ld_tgt_count);
2084 __swab32s (&ld->ld_active_tgt_count);
2085 /* uuid endian insensitive */
2087 /*end adding MDT by huanghua@clusterfs.com*/
2088 void lustre_swab_md_fld (struct md_fld *mf)
2090 __swab64s(&mf->mf_seq);
2091 __swab64s(&mf->mf_mds);
2094 static void print_lum (struct lov_user_md *lum)
2096 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
2097 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
2098 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2099 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
2100 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
2101 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2102 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2103 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
2106 void lustre_swab_lov_user_md(struct lov_user_md *lum)
2109 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2110 __swab32s(&lum->lmm_magic);
2111 __swab32s(&lum->lmm_pattern);
2112 __swab64s(&lum->lmm_object_id);
2113 __swab64s(&lum->lmm_object_gr);
2114 __swab32s(&lum->lmm_stripe_size);
2115 __swab16s(&lum->lmm_stripe_count);
2116 __swab16s(&lum->lmm_stripe_offset);
2121 static void print_lumj (struct lov_user_md_join *lumj)
2123 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2124 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2125 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2126 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2127 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2128 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2129 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2130 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2133 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2136 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2137 __swab32s(&lumj->lmm_magic);
2138 __swab32s(&lumj->lmm_pattern);
2139 __swab64s(&lumj->lmm_object_id);
2140 __swab64s(&lumj->lmm_object_gr);
2141 __swab32s(&lumj->lmm_stripe_size);
2142 __swab32s(&lumj->lmm_stripe_count);
2143 __swab32s(&lumj->lmm_extent_count);
2148 static void print_lum_objs(struct lov_user_md *lum)
2150 struct lov_user_ost_data *lod;
2153 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2155 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2156 for (i = 0; i < lum->lmm_stripe_count; i++) {
2157 lod = &lum->lmm_objects[i];
2158 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2159 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2160 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2161 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2166 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2168 struct lov_user_ost_data *lod;
2171 for (i = 0; i < lum->lmm_stripe_count; i++) {
2172 lod = &lum->lmm_objects[i];
2173 __swab64s(&lod->l_object_id);
2174 __swab64s(&lod->l_object_gr);
2175 __swab32s(&lod->l_ost_gen);
2176 __swab32s(&lod->l_ost_idx);
2178 print_lum_objs(lum);
2183 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2185 struct lov_ost_data *lod;
2188 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2189 lod = &lmm->lmm_objects[i];
2190 __swab64s(&lod->l_object_id);
2191 __swab64s(&lod->l_object_gr);
2192 __swab32s(&lod->l_ost_gen);
2193 __swab32s(&lod->l_ost_idx);
2195 __swab32s(&lmm->lmm_magic);
2196 __swab32s(&lmm->lmm_pattern);
2197 __swab64s(&lmm->lmm_object_id);
2198 __swab64s(&lmm->lmm_object_gr);
2199 __swab32s(&lmm->lmm_stripe_size);
2200 __swab32s(&lmm->lmm_stripe_count);
2206 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2210 for (i = 0; i < RES_NAME_SIZE; i++)
2211 __swab64s (&id->name[i]);
2214 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2216 /* the lock data is a union and the first two fields are always an
2217 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2218 * data the same way. */
2219 __swab64s(&d->l_extent.start);
2220 __swab64s(&d->l_extent.end);
2221 __swab64s(&d->l_extent.gid);
2222 __swab32s(&d->l_flock.pid);
2225 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2227 __swab64s (&i->opc);
2230 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2232 __swab32s (&r->lr_type);
2233 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2234 lustre_swab_ldlm_res_id (&r->lr_name);
2237 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2239 lustre_swab_ldlm_resource_desc (&l->l_resource);
2240 __swab32s (&l->l_req_mode);
2241 __swab32s (&l->l_granted_mode);
2242 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2245 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2247 __swab32s (&rq->lock_flags);
2248 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2249 __swab32s (&rq->lock_count);
2250 /* lock_handle[] opaque */
2253 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2255 __swab32s (&r->lock_flags);
2256 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2257 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2258 /* lock_handle opaque */
2259 __swab64s (&r->lock_policy_res1);
2260 __swab64s (&r->lock_policy_res2);
2263 /* no one calls this */
2264 int llog_log_swabbed(struct llog_log_hdr *hdr)
2266 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2268 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2273 void lustre_swab_qdata(struct qunit_data *d)
2275 __swab32s (&d->qd_id);
2276 __swab32s (&d->qd_flags);
2277 __swab64s (&d->qd_count);
2280 void lustre_swab_qdata_old(struct qunit_data_old *d)
2282 __swab32s (&d->qd_id);
2283 __swab32s (&d->qd_type);
2284 __swab32s (&d->qd_count);
2285 __swab32s (&d->qd_isblk);
2289 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2291 struct qunit_data_old tmp;
2292 struct qunit_data *ret;
2299 ret = (struct qunit_data *)d;
2300 ret->qd_id = tmp.qd_id;
2301 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2302 ret->qd_count = tmp.qd_count;
2306 EXPORT_SYMBOL(lustre_quota_old_to_new);
2308 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2310 struct qunit_data tmp;
2311 struct qunit_data_old *ret;
2318 ret = (struct qunit_data_old *)d;
2319 ret->qd_id = tmp.qd_id;
2320 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2321 ret->qd_count = (__u32)tmp.qd_count;
2322 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2325 EXPORT_SYMBOL(lustre_quota_new_to_old);
2326 #endif /* __KERNEL__ */
2328 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2330 LASSERT(req->rq_reqmsg);
2332 switch (req->rq_reqmsg->lm_magic) {
2333 case LUSTRE_MSG_MAGIC_V1:
2334 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2336 case LUSTRE_MSG_MAGIC_V2:
2337 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2338 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2340 CERROR("bad lustre msg magic: %#08X\n",
2341 req->rq_reqmsg->lm_magic);
2346 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2348 LASSERT(req->rq_repmsg);
2350 switch (req->rq_repmsg->lm_magic) {
2351 case LUSTRE_MSG_MAGIC_V1:
2352 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2354 case LUSTRE_MSG_MAGIC_V2:
2355 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2356 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2358 /* uninitialized yet */
2363 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2364 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2368 va_start(args, fmt);
2369 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2370 data->msg_fn, data->msg_line, fmt, args,
2371 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d lens"
2372 " %d/%d ref %d fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2373 req, req->rq_xid, req->rq_transno,
2374 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2375 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2376 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2378 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2380 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2382 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2383 (req->rq_import && req->rq_import->imp_client) ?
2384 req->rq_import->imp_client->cli_request_portal : -1,
2385 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2386 DEBUG_REQ_FLAGS(req),
2387 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2388 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2389 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2390 lustre_msg_get_flags(req->rq_repmsg) : -1,
2392 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2393 lustre_msg_get_status(req->rq_repmsg) : -1);
2395 EXPORT_SYMBOL(_debug_req);
2397 void lustre_swab_lustre_capa(struct lustre_capa *c)
2399 lustre_swab_lu_fid(&c->lc_fid);
2400 __swab64s (&c->lc_opc);
2401 __swab32s (&c->lc_uid);
2402 __swab32s (&c->lc_flags);
2403 __swab32s (&c->lc_keyid);
2404 __swab32s (&c->lc_timeout);
2405 __swab64s (&c->lc_expiry);
2408 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2410 __swab64s (&k->lk_mdsid);
2411 __swab32s (&k->lk_keyid);
2412 __swab32s (&k->lk_padding);