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 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
581 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
582 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
583 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
587 return lustre_msg_size_v2(msg->lm_bufcount, (int *)msg->lm_buflens);
591 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
592 * we also move data forward from @segment + 1.
594 * if @newlen == 0, we remove the segment completely, but we still keep the
595 * totally bufcount the same to save possible data moving. this will leave a
596 * unused segment with size 0 at the tail, but that's ok.
598 * return new msg size after shrinking.
601 * + if any buffers higher than @segment has been filled in, must call shrink
602 * with non-zero @move_data.
603 * + caller should NOT keep pointers to msg buffers which higher than @segment
606 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
607 unsigned int newlen, int move_data)
609 switch (msg->lm_magic) {
610 case LUSTRE_MSG_MAGIC_V1:
611 return lustre_shrink_msg_v1((struct lustre_msg_v1 *) msg,
612 segment - 1, newlen, move_data);
613 case LUSTRE_MSG_MAGIC_V2:
614 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
616 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
620 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
622 PTLRPC_RS_DEBUG_LRU_DEL(rs);
624 LASSERT (atomic_read(&rs->rs_refcount) == 0);
625 LASSERT (!rs->rs_difficult || rs->rs_handled);
626 LASSERT (!rs->rs_on_net);
627 LASSERT (!rs->rs_scheduled);
628 LASSERT (rs->rs_export == NULL);
629 LASSERT (rs->rs_nlocks == 0);
630 LASSERT (list_empty(&rs->rs_exp_list));
631 LASSERT (list_empty(&rs->rs_obd_list));
633 sptlrpc_svc_free_rs(rs);
636 int lustre_unpack_msg_v1(void *msg, int len)
638 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
639 int flipped, required_len, i;
642 /* Now we know the sender speaks my language. */
643 required_len = lustre_msg_hdr_size_v1(0);
644 if (len < required_len) {
645 /* can't even look inside the message */
646 CERROR("message length %d too small for lustre_msg\n", len);
650 flipped = lustre_msg_swabbed((struct lustre_msg *)m);
653 __swab32s(&m->lm_type);
654 __swab32s(&m->lm_version);
655 __swab32s(&m->lm_opc);
656 __swab64s(&m->lm_last_xid);
657 __swab64s(&m->lm_last_committed);
658 __swab64s(&m->lm_transno);
659 __swab32s(&m->lm_status);
660 __swab32s(&m->lm_flags);
661 __swab32s(&m->lm_conn_cnt);
662 __swab32s(&m->lm_bufcount);
665 if (m->lm_version != PTLRPC_MSG_VERSION) {
666 CERROR("wrong lustre_msg version %08x\n", m->lm_version);
670 required_len = lustre_msg_hdr_size_v1(m->lm_bufcount);
671 if (len < required_len) {
672 /* didn't receive all the buffer lengths */
673 CERROR("message length %d too small for %d buflens\n",
674 len, m->lm_bufcount);
678 for (i = 0; i < m->lm_bufcount; i++) {
680 __swab32s (&m->lm_buflens[i]);
681 required_len += size_round(m->lm_buflens[i]);
684 if (len < required_len) {
685 CERROR("len: %d, required_len %d\n", len, required_len);
686 CERROR("bufcount: %d\n", m->lm_bufcount);
687 for (i = 0; i < m->lm_bufcount; i++)
688 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
695 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
697 int flipped, required_len, i;
699 /* Now we know the sender speaks my language. */
700 required_len = lustre_msg_hdr_size_v2(0);
701 if (len < required_len) {
702 /* can't even look inside the message */
703 CERROR("message length %d too small for lustre_msg\n", len);
707 flipped = lustre_msg_swabbed(m);
710 __swab32s(&m->lm_bufcount);
711 __swab32s(&m->lm_secflvr);
712 __swab32s(&m->lm_repsize);
713 __swab32s(&m->lm_timeout);
714 CLASSERT(offsetof(typeof(*m), lm_padding_1) != 0);
715 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
716 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
719 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
720 if (len < required_len) {
721 /* didn't receive all the buffer lengths */
722 CERROR ("message length %d too small for %d buflens\n",
723 len, m->lm_bufcount);
727 for (i = 0; i < m->lm_bufcount; i++) {
729 __swab32s(&m->lm_buflens[i]);
730 required_len += size_round(m->lm_buflens[i]);
733 if (len < required_len) {
734 CERROR("len: %d, required_len %d\n", len, required_len);
735 CERROR("bufcount: %d\n", m->lm_bufcount);
736 for (i = 0; i < m->lm_bufcount; i++)
737 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
744 int lustre_unpack_msg(struct lustre_msg *m, int len)
746 int required_len, rc;
749 /* We can provide a slightly better error log, if we check the
750 * message magic and version first. In the future, struct
751 * lustre_msg may grow, and we'd like to log a version mismatch,
752 * rather than a short message.
755 required_len = offsetof(struct lustre_msg, lm_magic) +
757 if (len < required_len) {
758 /* can't even look inside the message */
759 CERROR("message length %d too small for magic/version check\n",
764 switch (m->lm_magic) {
765 case LUSTRE_MSG_MAGIC_V1:
766 case LUSTRE_MSG_MAGIC_V1_SWABBED:
767 rc = lustre_unpack_msg_v1(m, len);
769 case LUSTRE_MSG_MAGIC_V2:
770 case LUSTRE_MSG_MAGIC_V2_SWABBED:
771 rc = lustre_unpack_msg_v2(m, len);
774 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
781 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
784 struct ptlrpc_body *pb;
786 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
788 CERROR("error unpacking ptlrpc body");
791 if (lustre_msg_swabbed(m))
792 lustre_swab_ptlrpc_body(pb);
794 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
795 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
802 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
804 switch (req->rq_reqmsg->lm_magic) {
805 case LUSTRE_MSG_MAGIC_V1:
806 case LUSTRE_MSG_MAGIC_V1_SWABBED:
808 case LUSTRE_MSG_MAGIC_V2:
809 case LUSTRE_MSG_MAGIC_V2_SWABBED:
810 lustre_set_req_swabbed(req, offset);
811 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
813 CERROR("bad lustre msg magic: %#08X\n",
814 req->rq_reqmsg->lm_magic);
819 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
821 switch (req->rq_repmsg->lm_magic) {
822 case LUSTRE_MSG_MAGIC_V1:
823 case LUSTRE_MSG_MAGIC_V1_SWABBED:
825 case LUSTRE_MSG_MAGIC_V2:
826 case LUSTRE_MSG_MAGIC_V2_SWABBED:
827 lustre_set_rep_swabbed(req, offset);
828 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
830 CERROR("bad lustre msg magic: %#08X\n",
831 req->rq_repmsg->lm_magic);
836 static inline int lustre_msg_buflen_v1(void *msg, int n)
838 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
841 if (n >= m->lm_bufcount)
844 return m->lm_buflens[n];
847 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
849 if (n >= m->lm_bufcount)
852 return m->lm_buflens[n];
856 * lustre_msg_buflen - return the length of buffer @n in message @m
857 * @m - lustre_msg (request or reply) to look at
858 * @n - message index (base 0)
860 * returns zero for non-existent message indices
862 int lustre_msg_buflen(struct lustre_msg *m, int n)
864 switch (m->lm_magic) {
865 case LUSTRE_MSG_MAGIC_V1:
866 case LUSTRE_MSG_MAGIC_V1_SWABBED:
867 return lustre_msg_buflen_v1(m, n - 1);
868 case LUSTRE_MSG_MAGIC_V2:
869 case LUSTRE_MSG_MAGIC_V2_SWABBED:
870 return lustre_msg_buflen_v2(m, n);
872 CERROR("incorrect message magic: %08x\n", m->lm_magic);
876 EXPORT_SYMBOL(lustre_msg_buflen);
878 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
880 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
883 if (n >= m->lm_bufcount)
886 m->lm_buflens[n] = len;
890 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
892 if (n >= m->lm_bufcount)
895 m->lm_buflens[n] = len;
898 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
900 switch (m->lm_magic) {
901 case LUSTRE_MSG_MAGIC_V1:
902 lustre_msg_set_buflen_v1(m, n - 1, len);
904 case LUSTRE_MSG_MAGIC_V2:
905 lustre_msg_set_buflen_v2(m, n, len);
908 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
912 EXPORT_SYMBOL(lustre_msg_set_buflen);
914 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
915 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
916 int lustre_msg_bufcount(struct lustre_msg *m)
918 switch (m->lm_magic) {
919 case LUSTRE_MSG_MAGIC_V1:
920 case LUSTRE_MSG_MAGIC_V1_SWABBED:
921 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
922 case LUSTRE_MSG_MAGIC_V2:
923 case LUSTRE_MSG_MAGIC_V2_SWABBED:
924 return m->lm_bufcount;
926 CERROR("incorrect message magic: %08x\n", m->lm_magic);
930 EXPORT_SYMBOL(lustre_msg_bufcount);
932 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
934 /* max_len == 0 means the string should fill the buffer */
938 switch (m->lm_magic) {
939 case LUSTRE_MSG_MAGIC_V1:
940 case LUSTRE_MSG_MAGIC_V1_SWABBED:
941 str = lustre_msg_buf_v1(m, index - 1, 0);
942 blen = lustre_msg_buflen_v1(m, index - 1);
944 case LUSTRE_MSG_MAGIC_V2:
945 case LUSTRE_MSG_MAGIC_V2_SWABBED:
946 str = lustre_msg_buf_v2(m, index, 0);
947 blen = lustre_msg_buflen_v2(m, index);
950 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
954 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
958 slen = strnlen(str, blen);
960 if (slen == blen) { /* not NULL terminated */
961 CERROR("can't unpack non-NULL terminated string in "
962 "msg %p buffer[%d] len %d\n", m, index, blen);
967 if (slen != blen - 1) {
968 CERROR("can't unpack short string in msg %p "
969 "buffer[%d] len %d: strlen %d\n",
970 m, index, blen, slen);
973 } else if (slen > max_len) {
974 CERROR("can't unpack oversized string in msg %p "
975 "buffer[%d] len %d strlen %d: max %d expected\n",
976 m, index, blen, slen, max_len);
983 /* Wrap up the normal fixed length cases */
984 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
989 switch (msg->lm_magic) {
990 case LUSTRE_MSG_MAGIC_V1:
991 case LUSTRE_MSG_MAGIC_V1_SWABBED:
992 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
994 case LUSTRE_MSG_MAGIC_V2:
995 case LUSTRE_MSG_MAGIC_V2_SWABBED:
996 ptr = lustre_msg_buf_v2(msg, index, min_size);
999 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1004 if (swabber != NULL && lustre_msg_swabbed(msg))
1005 ((void (*)(void *))swabber)(ptr);
1010 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
1013 lustre_set_req_swabbed(req, index);
1014 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
1017 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
1020 lustre_set_rep_swabbed(req, index);
1021 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
1024 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
1026 switch (msg->lm_magic) {
1027 case LUSTRE_MSG_MAGIC_V1:
1028 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1029 return ((struct lustre_msg_v1 *)msg)->lm_flags &
1031 case LUSTRE_MSG_MAGIC_V2:
1032 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1033 struct ptlrpc_body *pb;
1035 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1037 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1040 return pb->pb_flags;
1043 /* flags might be printed in debug code while message
1049 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
1051 switch (msg->lm_magic) {
1052 case LUSTRE_MSG_MAGIC_V1:
1053 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1054 MSG_GEN_FLAG_MASK & flags;
1056 case LUSTRE_MSG_MAGIC_V2: {
1057 struct ptlrpc_body *pb;
1059 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1060 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1061 pb->pb_flags |= flags;
1065 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1069 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
1071 switch (msg->lm_magic) {
1072 case LUSTRE_MSG_MAGIC_V1:
1073 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK;
1074 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1075 MSG_GEN_FLAG_MASK & flags;
1077 case LUSTRE_MSG_MAGIC_V2: {
1078 struct ptlrpc_body *pb;
1080 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1081 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1082 pb->pb_flags = flags;
1086 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1090 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1092 switch (msg->lm_magic) {
1093 case LUSTRE_MSG_MAGIC_V1:
1094 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1095 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1096 ~(MSG_GEN_FLAG_MASK & flags);
1098 case LUSTRE_MSG_MAGIC_V2:
1099 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1100 struct ptlrpc_body *pb;
1102 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1103 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1104 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
1108 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1112 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1114 switch (msg->lm_magic) {
1115 case LUSTRE_MSG_MAGIC_V1:
1116 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1117 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1119 case LUSTRE_MSG_MAGIC_V2:
1120 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1121 struct ptlrpc_body *pb;
1123 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1125 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1128 return pb->pb_op_flags;
1135 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1137 switch (msg->lm_magic) {
1138 case LUSTRE_MSG_MAGIC_V1:
1139 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1140 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1142 case LUSTRE_MSG_MAGIC_V2: {
1143 struct ptlrpc_body *pb;
1145 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1146 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1147 pb->pb_op_flags |= flags;
1151 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1155 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
1157 switch (msg->lm_magic) {
1158 case LUSTRE_MSG_MAGIC_V1:
1159 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK;
1160 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1161 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1163 case LUSTRE_MSG_MAGIC_V2: {
1164 struct ptlrpc_body *pb;
1166 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1167 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1168 pb->pb_op_flags |= flags;
1172 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1176 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1178 switch (msg->lm_magic) {
1179 case LUSTRE_MSG_MAGIC_V1:
1180 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1181 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1182 case LUSTRE_MSG_MAGIC_V2:
1183 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1184 struct ptlrpc_body *pb;
1186 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1188 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1191 return &pb->pb_handle;
1194 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1199 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1201 switch (msg->lm_magic) {
1202 case LUSTRE_MSG_MAGIC_V1:
1203 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1204 return ((struct lustre_msg_v1 *)msg)->lm_type;
1205 case LUSTRE_MSG_MAGIC_V2:
1206 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1207 struct ptlrpc_body *pb;
1209 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1211 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1212 return PTL_RPC_MSG_ERR;
1217 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1218 return PTL_RPC_MSG_ERR;
1222 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1224 switch (msg->lm_magic) {
1225 case LUSTRE_MSG_MAGIC_V1:
1226 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1227 return ((struct lustre_msg_v1 *)msg)->lm_version;
1228 case LUSTRE_MSG_MAGIC_V2:
1229 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1230 struct ptlrpc_body *pb;
1232 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1234 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1237 return pb->pb_version;
1240 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1245 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1247 switch (msg->lm_magic) {
1248 case LUSTRE_MSG_MAGIC_V1:
1249 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1251 case LUSTRE_MSG_MAGIC_V2:
1252 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1253 struct ptlrpc_body *pb;
1255 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1256 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1257 pb->pb_version |= version;
1261 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1265 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1267 switch (msg->lm_magic) {
1268 case LUSTRE_MSG_MAGIC_V1:
1269 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1270 return ((struct lustre_msg_v1 *)msg)->lm_opc;
1271 case LUSTRE_MSG_MAGIC_V2:
1272 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1273 struct ptlrpc_body *pb;
1275 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1277 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1283 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1288 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1290 switch (msg->lm_magic) {
1291 case LUSTRE_MSG_MAGIC_V1:
1292 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1293 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1294 case LUSTRE_MSG_MAGIC_V2:
1295 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1296 struct ptlrpc_body *pb;
1298 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1300 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1303 return pb->pb_last_xid;
1306 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1311 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1313 switch (msg->lm_magic) {
1314 case LUSTRE_MSG_MAGIC_V1:
1315 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1316 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1317 case LUSTRE_MSG_MAGIC_V2:
1318 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1319 struct ptlrpc_body *pb;
1321 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1323 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1326 return pb->pb_last_committed;
1329 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1334 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1336 switch (msg->lm_magic) {
1337 case LUSTRE_MSG_MAGIC_V1:
1338 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1339 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1340 case LUSTRE_MSG_MAGIC_V2:
1341 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1342 struct ptlrpc_body *pb;
1344 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1346 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1349 return pb->pb_transno;
1352 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1357 int lustre_msg_get_status(struct lustre_msg *msg)
1359 switch (msg->lm_magic) {
1360 case LUSTRE_MSG_MAGIC_V1:
1361 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1362 return ((struct lustre_msg_v1 *)msg)->lm_status;
1363 case LUSTRE_MSG_MAGIC_V2:
1364 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1365 struct ptlrpc_body *pb;
1367 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1369 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1372 return pb->pb_status;
1375 /* status might be printed in debug code while message
1381 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1383 switch (msg->lm_magic) {
1384 case LUSTRE_MSG_MAGIC_V1:
1385 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1387 case LUSTRE_MSG_MAGIC_V2:
1388 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1389 struct ptlrpc_body *pb;
1391 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1393 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1399 CERROR("invalid msg magic %x\n", msg->lm_magic);
1405 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1407 switch (msg->lm_magic) {
1408 case LUSTRE_MSG_MAGIC_V1:
1409 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1411 case LUSTRE_MSG_MAGIC_V2:
1412 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1413 struct ptlrpc_body *pb;
1415 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1417 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1424 CERROR("invalid msg magic %x\n", msg->lm_magic);
1429 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1431 switch (msg->lm_magic) {
1432 case LUSTRE_MSG_MAGIC_V1:
1433 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1435 case LUSTRE_MSG_MAGIC_V2:
1436 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1437 struct ptlrpc_body *pb;
1439 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1441 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1444 return pb->pb_limit;
1447 CERROR("invalid msg magic %x\n", msg->lm_magic);
1453 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1455 switch (msg->lm_magic) {
1456 case LUSTRE_MSG_MAGIC_V1:
1457 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1459 case LUSTRE_MSG_MAGIC_V2:
1460 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1461 struct ptlrpc_body *pb;
1463 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1465 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1468 pb->pb_limit = limit;
1472 CERROR("invalid msg magic %x\n", msg->lm_magic);
1477 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1479 switch (msg->lm_magic) {
1480 case LUSTRE_MSG_MAGIC_V1:
1481 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1482 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1483 case LUSTRE_MSG_MAGIC_V2:
1484 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1485 struct ptlrpc_body *pb;
1487 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1489 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1492 return pb->pb_conn_cnt;
1495 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1500 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1502 switch (msg->lm_magic) {
1503 case LUSTRE_MSG_MAGIC_V1:
1504 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1505 case LUSTRE_MSG_MAGIC_V2:
1506 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1507 return msg->lm_magic;
1509 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1514 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1516 switch (msg->lm_magic) {
1517 case LUSTRE_MSG_MAGIC_V1:
1518 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1520 case LUSTRE_MSG_MAGIC_V2: {
1521 struct ptlrpc_body *pb;
1523 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1524 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1525 pb->pb_handle = *handle;
1529 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1533 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1535 switch (msg->lm_magic) {
1536 case LUSTRE_MSG_MAGIC_V1:
1537 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1539 case LUSTRE_MSG_MAGIC_V2: {
1540 struct ptlrpc_body *pb;
1542 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1543 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1548 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1552 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1554 switch (msg->lm_magic) {
1555 case LUSTRE_MSG_MAGIC_V1:
1556 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1558 case LUSTRE_MSG_MAGIC_V2: {
1559 struct ptlrpc_body *pb;
1561 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1562 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1567 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1571 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1573 switch (msg->lm_magic) {
1574 case LUSTRE_MSG_MAGIC_V1:
1575 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1577 case LUSTRE_MSG_MAGIC_V2: {
1578 struct ptlrpc_body *pb;
1580 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1581 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1582 pb->pb_last_xid = last_xid;
1586 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1590 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1592 switch (msg->lm_magic) {
1593 case LUSTRE_MSG_MAGIC_V1:
1594 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1596 case LUSTRE_MSG_MAGIC_V2: {
1597 struct ptlrpc_body *pb;
1599 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1600 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1601 pb->pb_last_committed = last_committed;
1605 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1609 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1611 switch (msg->lm_magic) {
1612 case LUSTRE_MSG_MAGIC_V1:
1613 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1615 case LUSTRE_MSG_MAGIC_V2: {
1616 struct ptlrpc_body *pb;
1618 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1619 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1620 pb->pb_transno = transno;
1624 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1628 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1630 switch (msg->lm_magic) {
1631 case LUSTRE_MSG_MAGIC_V1:
1632 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1634 case LUSTRE_MSG_MAGIC_V2: {
1635 struct ptlrpc_body *pb;
1637 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1638 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1639 pb->pb_status = status;
1643 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1647 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1649 switch (msg->lm_magic) {
1650 case LUSTRE_MSG_MAGIC_V1:
1651 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1653 case LUSTRE_MSG_MAGIC_V2: {
1654 struct ptlrpc_body *pb;
1656 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1657 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1658 pb->pb_conn_cnt = conn_cnt;
1662 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1666 /* byte flipping routines for all wire types declared in
1667 * lustre_idl.h implemented here.
1669 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1671 __swab32s (&b->pb_type);
1672 __swab32s (&b->pb_version);
1673 __swab32s (&b->pb_opc);
1674 __swab32s (&b->pb_status);
1675 __swab64s (&b->pb_last_xid);
1676 __swab64s (&b->pb_last_seen);
1677 __swab64s (&b->pb_last_committed);
1678 __swab64s (&b->pb_transno);
1679 __swab32s (&b->pb_flags);
1680 __swab32s (&b->pb_op_flags);
1681 __swab32s (&b->pb_conn_cnt);
1682 CLASSERT(offsetof(typeof(*b), pb_padding_1) != 0);
1683 CLASSERT(offsetof(typeof(*b), pb_padding_2) != 0);
1684 __swab32s (&b->pb_limit);
1685 __swab64s (&b->pb_slv);
1688 void lustre_swab_connect(struct obd_connect_data *ocd)
1690 __swab64s(&ocd->ocd_connect_flags);
1691 __swab32s(&ocd->ocd_version);
1692 __swab32s(&ocd->ocd_grant);
1693 __swab64s(&ocd->ocd_ibits_known);
1694 __swab32s(&ocd->ocd_index);
1695 __swab32s(&ocd->ocd_brw_size);
1696 __swab32s(&ocd->ocd_nllu);
1697 __swab32s(&ocd->ocd_nllg);
1698 __swab64s(&ocd->ocd_transno);
1699 __swab32s(&ocd->ocd_group);
1700 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1701 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1702 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1705 void lustre_swab_obdo (struct obdo *o)
1707 __swab64s (&o->o_valid);
1708 __swab64s (&o->o_id);
1709 __swab64s (&o->o_gr);
1710 __swab64s (&o->o_fid);
1711 __swab64s (&o->o_size);
1712 __swab64s (&o->o_mtime);
1713 __swab64s (&o->o_atime);
1714 __swab64s (&o->o_ctime);
1715 __swab64s (&o->o_blocks);
1716 __swab64s (&o->o_grant);
1717 __swab32s (&o->o_blksize);
1718 __swab32s (&o->o_mode);
1719 __swab32s (&o->o_uid);
1720 __swab32s (&o->o_gid);
1721 __swab32s (&o->o_flags);
1722 __swab32s (&o->o_nlink);
1723 __swab32s (&o->o_generation);
1724 __swab32s (&o->o_misc);
1725 __swab32s (&o->o_easize);
1726 __swab32s (&o->o_mds);
1727 __swab32s (&o->o_stripe_idx);
1728 __swab32s (&o->o_padding_1);
1729 /* o_inline is opaque */
1732 void lustre_swab_obd_statfs (struct obd_statfs *os)
1734 __swab64s (&os->os_type);
1735 __swab64s (&os->os_blocks);
1736 __swab64s (&os->os_bfree);
1737 __swab64s (&os->os_bavail);
1738 __swab64s (&os->os_files);
1739 __swab64s (&os->os_ffree);
1740 /* no need to swab os_fsid */
1741 __swab32s (&os->os_bsize);
1742 __swab32s (&os->os_namelen);
1743 __swab64s (&os->os_maxbytes);
1744 __swab32s (&os->os_state);
1745 /* no need to swap os_spare */
1748 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1750 __swab64s (&ioo->ioo_id);
1751 __swab64s (&ioo->ioo_gr);
1752 __swab32s (&ioo->ioo_type);
1753 __swab32s (&ioo->ioo_bufcnt);
1756 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1758 __swab64s (&nbr->offset);
1759 __swab32s (&nbr->len);
1760 __swab32s (&nbr->flags);
1763 void lustre_swab_ost_body (struct ost_body *b)
1765 lustre_swab_obdo (&b->oa);
1768 void lustre_swab_ost_last_id(obd_id *id)
1773 void lustre_swab_generic_32s(__u32 *val)
1778 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1780 __swab64s(&lvb->lvb_size);
1781 __swab64s(&lvb->lvb_mtime);
1782 __swab64s(&lvb->lvb_atime);
1783 __swab64s(&lvb->lvb_ctime);
1784 __swab64s(&lvb->lvb_blocks);
1787 void lustre_swab_mds_status_req (struct mds_status_req *r)
1789 __swab32s (&r->flags);
1790 __swab32s (&r->repbuf);
1793 void lustre_swab_mds_body (struct mds_body *b)
1795 lustre_swab_ll_fid (&b->fid1);
1796 lustre_swab_ll_fid (&b->fid2);
1797 /* handle is opaque */
1798 __swab64s (&b->valid);
1799 __swab64s (&b->size);
1800 __swab64s (&b->mtime);
1801 __swab64s (&b->atime);
1802 __swab64s (&b->ctime);
1803 __swab64s (&b->blocks);
1804 __swab64s (&b->io_epoch);
1805 __swab64s (&b->ino);
1806 __swab32s (&b->fsuid);
1807 __swab32s (&b->fsgid);
1808 __swab32s (&b->capability);
1809 __swab32s (&b->mode);
1810 __swab32s (&b->uid);
1811 __swab32s (&b->gid);
1812 __swab32s (&b->flags);
1813 __swab32s (&b->rdev);
1814 __swab32s (&b->nlink);
1815 __swab32s (&b->generation);
1816 __swab32s (&b->suppgid);
1817 __swab32s (&b->eadatasize);
1818 __swab32s (&b->aclsize);
1819 __swab32s (&b->max_mdsize);
1820 __swab32s (&b->max_cookiesize);
1821 __swab32s (&b->padding_4);
1824 void lustre_swab_mdt_body (struct mdt_body *b)
1826 lustre_swab_lu_fid (&b->fid1);
1827 lustre_swab_lu_fid (&b->fid2);
1828 /* handle is opaque */
1829 __swab64s (&b->valid);
1830 __swab64s (&b->size);
1831 __swab64s (&b->mtime);
1832 __swab64s (&b->atime);
1833 __swab64s (&b->ctime);
1834 __swab64s (&b->blocks);
1835 __swab64s (&b->ioepoch);
1836 __swab32s (&b->fsuid);
1837 __swab32s (&b->fsgid);
1838 __swab32s (&b->capability);
1839 __swab32s (&b->mode);
1840 __swab32s (&b->uid);
1841 __swab32s (&b->gid);
1842 __swab32s (&b->flags);
1843 __swab32s (&b->rdev);
1844 __swab32s (&b->nlink);
1845 __swab32s (&b->suppgid);
1846 __swab32s (&b->eadatasize);
1847 __swab32s (&b->aclsize);
1848 __swab32s (&b->max_mdsize);
1849 __swab32s (&b->max_cookiesize);
1852 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1854 /* handle is opaque */
1855 __swab64s (&b->ioepoch);
1856 __swab32s (&b->flags);
1857 CLASSERT(offsetof(typeof(*b), padding) != 0);
1860 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1863 __swab32s(&mti->mti_lustre_ver);
1864 __swab32s(&mti->mti_stripe_index);
1865 __swab32s(&mti->mti_config_ver);
1866 __swab32s(&mti->mti_flags);
1867 __swab32s(&mti->mti_nid_count);
1868 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1869 for (i = 0; i < MTI_NIDS_MAX; i++)
1870 __swab64s(&mti->mti_nids[i]);
1873 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1875 __swab64s (&i->dqi_bgrace);
1876 __swab64s (&i->dqi_igrace);
1877 __swab32s (&i->dqi_flags);
1878 __swab32s (&i->dqi_valid);
1881 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1883 __swab64s (&b->dqb_ihardlimit);
1884 __swab64s (&b->dqb_isoftlimit);
1885 __swab64s (&b->dqb_curinodes);
1886 __swab64s (&b->dqb_bhardlimit);
1887 __swab64s (&b->dqb_bsoftlimit);
1888 __swab64s (&b->dqb_curspace);
1889 __swab64s (&b->dqb_btime);
1890 __swab64s (&b->dqb_itime);
1891 __swab32s (&b->dqb_valid);
1892 CLASSERT(offsetof(typeof(*b), padding) != 0);
1895 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1897 __swab32s (&q->qc_cmd);
1898 __swab32s (&q->qc_type);
1899 __swab32s (&q->qc_id);
1900 __swab32s (&q->qc_stat);
1901 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1902 lustre_swab_obd_dqblk (&q->qc_dqblk);
1905 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1907 __swab32s (&p->rp_uid);
1908 __swab32s (&p->rp_gid);
1909 __swab32s (&p->rp_fsuid);
1910 __swab32s (&p->rp_fsgid);
1911 __swab32s (&p->rp_access_perm);
1914 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1916 __swab32s (&p->rp_uid);
1917 __swab32s (&p->rp_gid);
1918 __swab32s (&p->rp_fsuid);
1919 __swab32s (&p->rp_fsgid);
1920 __swab32s (&p->rp_access_perm);
1923 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1925 __swab32s (&sa->sa_opcode);
1926 __swab32s (&sa->sa_fsuid);
1927 __swab32s (&sa->sa_fsgid);
1928 __swab32s (&sa->sa_cap);
1929 __swab32s (&sa->sa_suppgid);
1930 __swab32s (&sa->sa_mode);
1931 lustre_swab_ll_fid (&sa->sa_fid);
1932 __swab64s (&sa->sa_valid);
1933 __swab64s (&sa->sa_size);
1934 __swab64s (&sa->sa_mtime);
1935 __swab64s (&sa->sa_atime);
1936 __swab64s (&sa->sa_ctime);
1937 __swab32s (&sa->sa_uid);
1938 __swab32s (&sa->sa_gid);
1939 __swab32s (&sa->sa_attr_flags);
1940 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1943 void lustre_swab_mdt_rec_setattr (struct mdt_rec_setattr *sa)
1945 __swab32s (&sa->sa_opcode);
1946 __swab32s (&sa->sa_fsuid);
1947 __swab32s (&sa->sa_fsgid);
1948 __swab32s (&sa->sa_cap);
1949 __swab32s (&sa->sa_suppgid);
1950 __swab32s (&sa->sa_mode);
1951 lustre_swab_lu_fid (&sa->sa_fid);
1952 __swab64s (&sa->sa_valid);
1953 __swab64s (&sa->sa_size);
1954 __swab64s (&sa->sa_blocks);
1955 __swab64s (&sa->sa_mtime);
1956 __swab64s (&sa->sa_atime);
1957 __swab64s (&sa->sa_ctime);
1958 __swab32s (&sa->sa_uid);
1959 __swab32s (&sa->sa_gid);
1960 __swab32s (&sa->sa_attr_flags);
1961 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1964 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1966 __swab64s(&jr->jr_headsize);
1967 lustre_swab_ll_fid(&jr->jr_fid);
1970 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1972 __swab64s(&jr->jr_headsize);
1973 lustre_swab_lu_fid(&jr->jr_fid);
1976 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1978 __swab32s (&cr->cr_opcode);
1979 __swab32s (&cr->cr_fsuid);
1980 __swab32s (&cr->cr_fsgid);
1981 __swab32s (&cr->cr_cap);
1982 __swab32s (&cr->cr_flags); /* for use with open */
1983 __swab32s (&cr->cr_mode);
1984 lustre_swab_ll_fid (&cr->cr_fid);
1985 lustre_swab_ll_fid (&cr->cr_replayfid);
1986 __swab64s (&cr->cr_time);
1987 __swab64s (&cr->cr_rdev);
1988 __swab32s (&cr->cr_suppgid);
1989 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1990 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1991 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1992 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1993 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1996 void lustre_swab_mdt_rec_create (struct mdt_rec_create *cr)
1998 __swab32s (&cr->cr_opcode);
1999 __swab32s (&cr->cr_fsuid);
2000 __swab32s (&cr->cr_fsgid);
2001 __swab32s (&cr->cr_cap);
2002 __swab32s (&cr->cr_flags); /* for use with open */
2003 __swab32s (&cr->cr_mode);
2004 /* handle is opaque */
2005 lustre_swab_lu_fid (&cr->cr_fid1);
2006 lustre_swab_lu_fid (&cr->cr_fid2);
2007 __swab64s (&cr->cr_time);
2008 __swab64s (&cr->cr_rdev);
2009 __swab64s (&cr->cr_ioepoch);
2010 __swab32s (&cr->cr_suppgid1);
2011 __swab32s (&cr->cr_suppgid2);
2012 __swab32s (&cr->cr_bias);
2013 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
2016 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
2018 __swab32s (&lk->lk_opcode);
2019 __swab32s (&lk->lk_fsuid);
2020 __swab32s (&lk->lk_fsgid);
2021 __swab32s (&lk->lk_cap);
2022 __swab32s (&lk->lk_suppgid1);
2023 __swab32s (&lk->lk_suppgid2);
2024 lustre_swab_ll_fid (&lk->lk_fid1);
2025 lustre_swab_ll_fid (&lk->lk_fid2);
2026 __swab64s (&lk->lk_time);
2027 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
2028 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2029 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2030 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2033 void lustre_swab_mdt_rec_link (struct mdt_rec_link *lk)
2035 __swab32s (&lk->lk_opcode);
2036 __swab32s (&lk->lk_fsuid);
2037 __swab32s (&lk->lk_fsgid);
2038 __swab32s (&lk->lk_cap);
2039 __swab32s (&lk->lk_suppgid1);
2040 __swab32s (&lk->lk_suppgid2);
2041 lustre_swab_lu_fid (&lk->lk_fid1);
2042 lustre_swab_lu_fid (&lk->lk_fid2);
2043 __swab64s (&lk->lk_time);
2044 __swab32s (&lk->lk_bias);
2045 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2046 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2047 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2050 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
2052 __swab32s (&ul->ul_opcode);
2053 __swab32s (&ul->ul_fsuid);
2054 __swab32s (&ul->ul_fsgid);
2055 __swab32s (&ul->ul_cap);
2056 __swab32s (&ul->ul_suppgid);
2057 __swab32s (&ul->ul_mode);
2058 lustre_swab_ll_fid (&ul->ul_fid1);
2059 lustre_swab_ll_fid (&ul->ul_fid2);
2060 __swab64s (&ul->ul_time);
2061 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
2062 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2063 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2064 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2067 void lustre_swab_mdt_rec_unlink (struct mdt_rec_unlink *ul)
2069 __swab32s (&ul->ul_opcode);
2070 __swab32s (&ul->ul_fsuid);
2071 __swab32s (&ul->ul_fsgid);
2072 __swab32s (&ul->ul_cap);
2073 __swab32s (&ul->ul_suppgid);
2074 __swab32s (&ul->ul_mode);
2075 lustre_swab_lu_fid (&ul->ul_fid1);
2076 lustre_swab_lu_fid (&ul->ul_fid2);
2077 __swab64s (&ul->ul_time);
2078 __swab32s (&ul->ul_bias);
2079 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2080 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2081 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2084 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
2086 __swab32s (&rn->rn_opcode);
2087 __swab32s (&rn->rn_fsuid);
2088 __swab32s (&rn->rn_fsgid);
2089 __swab32s (&rn->rn_cap);
2090 __swab32s (&rn->rn_suppgid1);
2091 __swab32s (&rn->rn_suppgid2);
2092 lustre_swab_ll_fid (&rn->rn_fid1);
2093 lustre_swab_ll_fid (&rn->rn_fid2);
2094 __swab64s (&rn->rn_time);
2095 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
2096 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
2097 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2098 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2101 void lustre_swab_mdt_rec_rename (struct mdt_rec_rename *rn)
2103 __swab32s (&rn->rn_opcode);
2104 __swab32s (&rn->rn_fsuid);
2105 __swab32s (&rn->rn_fsgid);
2106 __swab32s (&rn->rn_cap);
2107 __swab32s (&rn->rn_suppgid1);
2108 __swab32s (&rn->rn_suppgid2);
2109 lustre_swab_lu_fid (&rn->rn_fid1);
2110 lustre_swab_lu_fid (&rn->rn_fid2);
2111 __swab64s (&rn->rn_time);
2112 __swab32s (&rn->rn_mode);
2113 __swab32s (&rn->rn_bias);
2114 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2115 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2118 void lustre_swab_lov_desc (struct lov_desc *ld)
2120 __swab32s (&ld->ld_tgt_count);
2121 __swab32s (&ld->ld_active_tgt_count);
2122 __swab32s (&ld->ld_default_stripe_count);
2123 __swab64s (&ld->ld_default_stripe_size);
2124 __swab64s (&ld->ld_default_stripe_offset);
2125 __swab32s (&ld->ld_pattern);
2126 __swab32s (&ld->ld_qos_maxage);
2127 /* uuid endian insensitive */
2130 /*begin adding MDT by huanghua@clusterfs.com*/
2131 void lustre_swab_lmv_desc (struct lmv_desc *ld)
2133 __swab32s (&ld->ld_tgt_count);
2134 __swab32s (&ld->ld_active_tgt_count);
2135 /* uuid endian insensitive */
2137 /*end adding MDT by huanghua@clusterfs.com*/
2138 void lustre_swab_md_fld (struct md_fld *mf)
2140 __swab64s(&mf->mf_seq);
2141 __swab64s(&mf->mf_mds);
2144 static void print_lum (struct lov_user_md *lum)
2146 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
2147 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
2148 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2149 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
2150 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
2151 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2152 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2153 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
2156 void lustre_swab_lov_user_md(struct lov_user_md *lum)
2159 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2160 __swab32s(&lum->lmm_magic);
2161 __swab32s(&lum->lmm_pattern);
2162 __swab64s(&lum->lmm_object_id);
2163 __swab64s(&lum->lmm_object_gr);
2164 __swab32s(&lum->lmm_stripe_size);
2165 __swab16s(&lum->lmm_stripe_count);
2166 __swab16s(&lum->lmm_stripe_offset);
2171 static void print_lumj (struct lov_user_md_join *lumj)
2173 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2174 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2175 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2176 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2177 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2178 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2179 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2180 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2183 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2186 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2187 __swab32s(&lumj->lmm_magic);
2188 __swab32s(&lumj->lmm_pattern);
2189 __swab64s(&lumj->lmm_object_id);
2190 __swab64s(&lumj->lmm_object_gr);
2191 __swab32s(&lumj->lmm_stripe_size);
2192 __swab32s(&lumj->lmm_stripe_count);
2193 __swab32s(&lumj->lmm_extent_count);
2198 static void print_lum_objs(struct lov_user_md *lum)
2200 struct lov_user_ost_data *lod;
2203 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2205 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2206 for (i = 0; i < lum->lmm_stripe_count; i++) {
2207 lod = &lum->lmm_objects[i];
2208 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2209 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2210 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2211 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2216 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2218 struct lov_user_ost_data *lod;
2221 for (i = 0; i < lum->lmm_stripe_count; i++) {
2222 lod = &lum->lmm_objects[i];
2223 __swab64s(&lod->l_object_id);
2224 __swab64s(&lod->l_object_gr);
2225 __swab32s(&lod->l_ost_gen);
2226 __swab32s(&lod->l_ost_idx);
2228 print_lum_objs(lum);
2233 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2235 struct lov_ost_data *lod;
2238 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2239 lod = &lmm->lmm_objects[i];
2240 __swab64s(&lod->l_object_id);
2241 __swab64s(&lod->l_object_gr);
2242 __swab32s(&lod->l_ost_gen);
2243 __swab32s(&lod->l_ost_idx);
2245 __swab32s(&lmm->lmm_magic);
2246 __swab32s(&lmm->lmm_pattern);
2247 __swab64s(&lmm->lmm_object_id);
2248 __swab64s(&lmm->lmm_object_gr);
2249 __swab32s(&lmm->lmm_stripe_size);
2250 __swab32s(&lmm->lmm_stripe_count);
2256 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2260 for (i = 0; i < RES_NAME_SIZE; i++)
2261 __swab64s (&id->name[i]);
2264 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2266 /* the lock data is a union and the first two fields are always an
2267 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2268 * data the same way. */
2269 __swab64s(&d->l_extent.start);
2270 __swab64s(&d->l_extent.end);
2271 __swab64s(&d->l_extent.gid);
2272 __swab32s(&d->l_flock.pid);
2275 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2277 __swab64s (&i->opc);
2280 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2282 __swab32s (&r->lr_type);
2283 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2284 lustre_swab_ldlm_res_id (&r->lr_name);
2287 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2289 lustre_swab_ldlm_resource_desc (&l->l_resource);
2290 __swab32s (&l->l_req_mode);
2291 __swab32s (&l->l_granted_mode);
2292 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2295 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2297 __swab32s (&rq->lock_flags);
2298 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2299 __swab32s (&rq->lock_count);
2300 /* lock_handle[] opaque */
2303 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2305 __swab32s (&r->lock_flags);
2306 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2307 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2308 /* lock_handle opaque */
2309 __swab64s (&r->lock_policy_res1);
2310 __swab64s (&r->lock_policy_res2);
2313 /* no one calls this */
2314 int llog_log_swabbed(struct llog_log_hdr *hdr)
2316 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2318 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2323 void lustre_swab_qdata(struct qunit_data *d)
2325 __swab32s (&d->qd_id);
2326 __swab32s (&d->qd_flags);
2327 __swab64s (&d->qd_count);
2330 void lustre_swab_qdata_old(struct qunit_data_old *d)
2332 __swab32s (&d->qd_id);
2333 __swab32s (&d->qd_type);
2334 __swab32s (&d->qd_count);
2335 __swab32s (&d->qd_isblk);
2339 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2341 struct qunit_data_old tmp;
2342 struct qunit_data *ret;
2349 ret = (struct qunit_data *)d;
2350 ret->qd_id = tmp.qd_id;
2351 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2352 ret->qd_count = tmp.qd_count;
2356 EXPORT_SYMBOL(lustre_quota_old_to_new);
2358 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2360 struct qunit_data tmp;
2361 struct qunit_data_old *ret;
2368 ret = (struct qunit_data_old *)d;
2369 ret->qd_id = tmp.qd_id;
2370 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2371 ret->qd_count = (__u32)tmp.qd_count;
2372 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2375 EXPORT_SYMBOL(lustre_quota_new_to_old);
2376 #endif /* __KERNEL__ */
2378 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2380 LASSERT(req->rq_reqmsg);
2382 switch (req->rq_reqmsg->lm_magic) {
2383 case LUSTRE_MSG_MAGIC_V1:
2384 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2386 case LUSTRE_MSG_MAGIC_V2:
2387 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2388 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2390 CERROR("bad lustre msg magic: %#08X\n",
2391 req->rq_reqmsg->lm_magic);
2396 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2398 LASSERT(req->rq_repmsg);
2400 switch (req->rq_repmsg->lm_magic) {
2401 case LUSTRE_MSG_MAGIC_V1:
2402 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2404 case LUSTRE_MSG_MAGIC_V2:
2405 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2406 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2408 /* uninitialized yet */
2413 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2414 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2418 va_start(args, fmt);
2419 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2420 data->msg_fn, data->msg_line, fmt, args,
2421 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d lens"
2422 " %d/%d ref %d fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2423 req, req->rq_xid, req->rq_transno,
2424 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2425 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2426 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2428 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2430 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2432 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2433 (req->rq_import && req->rq_import->imp_client) ?
2434 req->rq_import->imp_client->cli_request_portal : -1,
2435 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2436 DEBUG_REQ_FLAGS(req),
2437 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2438 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2439 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2440 lustre_msg_get_flags(req->rq_repmsg) : -1,
2442 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2443 lustre_msg_get_status(req->rq_repmsg) : -1);
2445 EXPORT_SYMBOL(_debug_req);
2447 void lustre_swab_lustre_capa(struct lustre_capa *c)
2449 lustre_swab_lu_fid(&c->lc_fid);
2450 __swab64s (&c->lc_opc);
2451 __swab32s (&c->lc_uid);
2452 __swab32s (&c->lc_flags);
2453 __swab32s (&c->lc_keyid);
2454 __swab32s (&c->lc_timeout);
2455 __swab64s (&c->lc_expiry);
2458 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2460 __swab64s (&k->lk_mdsid);
2461 __swab32s (&k->lk_keyid);
2462 __swab32s (&k->lk_padding);