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_hdr_size(__u32 magic, int count)
61 case LUSTRE_MSG_MAGIC_V1:
62 return lustre_msg_hdr_size_v1(count - 1);
63 case LUSTRE_MSG_MAGIC_V2:
64 return lustre_msg_hdr_size_v2(count);
66 LASSERTF(0, "incorrect message magic: %08x\n", magic);
70 EXPORT_SYMBOL(lustre_msg_hdr_size);
72 int lustre_msg_swabbed(struct lustre_msg *msg)
74 return (msg->lm_magic == LUSTRE_MSG_MAGIC_V1_SWABBED) ||
75 (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
79 lustre_msg_check_version_v2(struct lustre_msg_v2 *msg, __u32 version)
81 __u32 ver = lustre_msg_get_version(msg);
82 return (ver & LUSTRE_VERSION_MASK) != version;
85 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
87 switch (msg->lm_magic) {
88 case LUSTRE_MSG_MAGIC_V1:
89 case LUSTRE_MSG_MAGIC_V1_SWABBED:
91 case LUSTRE_MSG_MAGIC_V2:
92 case LUSTRE_MSG_MAGIC_V2_SWABBED:
93 return lustre_msg_check_version_v2(msg, version);
95 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
100 static inline int lustre_msg_size_v1(int count, int *lengths)
106 size = lustre_msg_hdr_size_v1(count);
107 for (i = 0; i < count; i++)
108 size += size_round(lengths[i]);
113 int lustre_msg_size_v2(int count, int *lengths)
118 size = lustre_msg_hdr_size_v2(count);
119 for (i = 0; i < count; i++)
120 size += size_round(lengths[i]);
124 EXPORT_SYMBOL(lustre_msg_size_v2);
126 /* This returns the size of the buffer that is required to hold a lustre_msg
127 * with the given sub-buffer lengths.
128 * NOTE: this should only be used for NEW requests, and should always be
129 * in the form of a v2 request. If this is a connection to a v1
130 * target then the first buffer will be stripped because the ptlrpc
131 * data is part of the lustre_msg_v1 header. b=14043 */
132 int lustre_msg_size(__u32 magic, int count, int *lens)
134 int size[] = { sizeof(struct ptlrpc_body) };
142 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
145 case LUSTRE_MSG_MAGIC_V1:
146 return lustre_msg_size_v1(count - 1, lens + 1);
147 case LUSTRE_MSG_MAGIC_V2:
148 return lustre_msg_size_v2(count, lens);
150 LASSERTF(0, "incorrect message magic: %08x\n", magic);
155 /* This is used to determine the size of a buffer that was already packed
156 * and will correctly handle the different message formats. */
157 int lustre_packed_msg_size(struct lustre_msg *msg)
159 switch (msg->lm_magic) {
160 case LUSTRE_MSG_MAGIC_V1: {
161 struct lustre_msg_v1 *v1_msg = (struct lustre_msg_v1 *)msg;
162 return lustre_msg_size_v1(v1_msg->lm_bufcount,
165 case LUSTRE_MSG_MAGIC_V2:
166 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
168 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
174 void lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
176 struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)m;
181 msg->lm_magic = LUSTRE_MSG_MAGIC_V1;
182 msg->lm_version = PTLRPC_MSG_VERSION;
183 msg->lm_bufcount = count;
185 for (i = 0; i < count; i++)
186 msg->lm_buflens[i] = lens[i];
191 ptr = (char *)msg + lustre_msg_hdr_size_v1(count);
192 for (i = 0; i < count; i++) {
194 LOGL(tmp, lens[i], ptr);
198 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
204 msg->lm_bufcount = count;
205 /* XXX: lm_secflvr uninitialized here */
206 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
208 for (i = 0; i < count; i++)
209 msg->lm_buflens[i] = lens[i];
214 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
215 for (i = 0; i < count; i++) {
217 LOGL(tmp, lens[i], ptr);
220 EXPORT_SYMBOL(lustre_init_msg_v2);
222 static int lustre_pack_request_v1(struct ptlrpc_request *req,
223 int count, int *lens, char **bufs)
227 reqlen = lustre_msg_size_v1(count, lens);
229 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
233 req->rq_reqlen = reqlen;
235 lustre_init_msg_v1(req->rq_reqmsg, count, lens, bufs);
239 static int lustre_pack_request_v2(struct ptlrpc_request *req,
240 int count, int *lens, char **bufs)
244 reqlen = lustre_msg_size_v2(count, lens);
246 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
250 req->rq_reqlen = reqlen;
252 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
253 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
254 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
258 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
259 int *lens, char **bufs)
261 int size[] = { sizeof(struct ptlrpc_body) };
269 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
271 /* only use new format, we don't need to be compatible with 1.4 */
272 magic = LUSTRE_MSG_MAGIC_V2;
275 case LUSTRE_MSG_MAGIC_V1:
276 return lustre_pack_request_v1(req, count - 1, lens + 1,
277 bufs ? bufs + 1 : NULL);
278 case LUSTRE_MSG_MAGIC_V2:
279 return lustre_pack_request_v2(req, count, lens, bufs);
281 LASSERTF(0, "incorrect message magic: %08x\n", magic);
287 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
288 spinlock_t ptlrpc_rs_debug_lock;
290 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
292 spin_lock(&ptlrpc_rs_debug_lock); \
293 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
294 spin_unlock(&ptlrpc_rs_debug_lock); \
297 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
299 spin_lock(&ptlrpc_rs_debug_lock); \
300 list_del(&(rs)->rs_debug_list); \
301 spin_unlock(&ptlrpc_rs_debug_lock); \
304 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
305 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
308 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
310 struct ptlrpc_reply_state *rs = NULL;
312 spin_lock(&svc->srv_lock);
313 /* See if we have anything in a pool, and wait if nothing */
314 while (list_empty(&svc->srv_free_rs_list)) {
315 struct l_wait_info lwi;
317 spin_unlock(&svc->srv_lock);
318 /* If we cannot get anything for some long time, we better
319 bail out instead of waiting infinitely */
320 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
321 rc = l_wait_event(svc->srv_free_rs_waitq,
322 !list_empty(&svc->srv_free_rs_list), &lwi);
325 spin_lock(&svc->srv_lock);
328 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
330 list_del(&rs->rs_list);
331 spin_unlock(&svc->srv_lock);
333 memset(rs, 0, svc->srv_max_reply_size);
334 rs->rs_service = svc;
340 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
342 struct ptlrpc_service *svc = rs->rs_service;
346 spin_lock(&svc->srv_lock);
347 list_add(&rs->rs_list, &svc->srv_free_rs_list);
348 spin_unlock(&svc->srv_lock);
349 cfs_waitq_signal(&svc->srv_free_rs_waitq);
352 static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count,
353 int *lens, char **bufs)
355 struct ptlrpc_reply_state *rs;
359 LASSERT (req->rq_reply_state == NULL);
361 msg_len = lustre_msg_size_v1(count, lens);
362 rc = sptlrpc_svc_alloc_rs(req, msg_len);
366 rs = req->rq_reply_state;
367 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
368 rs->rs_cb_id.cbid_fn = reply_out_callback;
369 rs->rs_cb_id.cbid_arg = rs;
370 rs->rs_service = req->rq_rqbd->rqbd_service;
371 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
372 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
374 req->rq_replen = msg_len;
375 req->rq_reply_state = rs;
376 req->rq_repmsg = rs->rs_msg;
377 lustre_init_msg_v1(rs->rs_msg, count, lens, bufs);
379 PTLRPC_RS_DEBUG_LRU_ADD(rs);
384 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
385 int *lens, char **bufs)
387 struct ptlrpc_reply_state *rs;
391 LASSERT(req->rq_reply_state == NULL);
393 msg_len = lustre_msg_size_v2(count, lens);
394 rc = sptlrpc_svc_alloc_rs(req, msg_len);
398 rs = req->rq_reply_state;
399 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
400 rs->rs_cb_id.cbid_fn = reply_out_callback;
401 rs->rs_cb_id.cbid_arg = rs;
402 rs->rs_service = req->rq_rqbd->rqbd_service;
403 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
404 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
406 req->rq_replen = msg_len;
407 req->rq_reply_state = rs;
408 req->rq_repmsg = rs->rs_msg;
409 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
410 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
411 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
413 PTLRPC_RS_DEBUG_LRU_ADD(rs);
417 EXPORT_SYMBOL(lustre_pack_reply_v2);
419 int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
423 int size[] = { sizeof(struct ptlrpc_body) };
431 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
433 switch (req->rq_reqmsg->lm_magic) {
434 case LUSTRE_MSG_MAGIC_V1:
435 case LUSTRE_MSG_MAGIC_V1_SWABBED:
436 rc = lustre_pack_reply_v1(req, count - 1, lens + 1,
437 bufs ? bufs + 1 : NULL);
439 case LUSTRE_MSG_MAGIC_V2:
440 case LUSTRE_MSG_MAGIC_V2_SWABBED:
441 rc = lustre_pack_reply_v2(req, count, lens, bufs);
444 LASSERTF(0, "incorrect message magic: %08x\n",
445 req->rq_reqmsg->lm_magic);
449 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
450 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
454 void *lustre_msg_buf_v1(void *msg, int n, int min_size)
456 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
457 int i, offset, buflen, bufcount;
462 bufcount = m->lm_bufcount;
463 if (unlikely(n >= bufcount)) {
464 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
469 buflen = m->lm_buflens[n];
470 if (unlikely(buflen < min_size)) {
471 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
472 m, n, buflen, min_size);
477 offset = lustre_msg_hdr_size_v1(bufcount);
478 for (i = 0; i < n; i++)
479 offset += size_round(m->lm_buflens[i]);
481 return (char *)m + offset;
484 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
486 int i, offset, buflen, bufcount;
491 bufcount = m->lm_bufcount;
492 if (unlikely(n >= bufcount)) {
493 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
498 buflen = m->lm_buflens[n];
499 if (unlikely(buflen < min_size)) {
500 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
501 m, n, buflen, min_size);
505 offset = lustre_msg_hdr_size_v2(bufcount);
506 for (i = 0; i < n; i++)
507 offset += size_round(m->lm_buflens[i]);
509 return (char *)m + offset;
512 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
514 switch (m->lm_magic) {
515 case LUSTRE_MSG_MAGIC_V1:
516 case LUSTRE_MSG_MAGIC_V1_SWABBED:
517 return lustre_msg_buf_v1(m, n - 1, min_size);
518 case LUSTRE_MSG_MAGIC_V2:
519 case LUSTRE_MSG_MAGIC_V2_SWABBED:
520 return lustre_msg_buf_v2(m, n, min_size);
522 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
527 int lustre_shrink_msg_v1(struct lustre_msg_v1 *msg, int segment,
528 unsigned int newlen, int move_data)
530 char *tail = NULL, *newpos;
534 LASSERT(segment >= 0);
535 LASSERT(msg->lm_bufcount > segment);
536 LASSERT(msg->lm_buflens[segment] >= newlen);
538 if (msg->lm_buflens[segment] == newlen)
541 if (move_data && msg->lm_bufcount > segment + 1) {
542 tail = lustre_msg_buf_v1(msg, segment + 1, 0);
543 for (n = segment + 1; n < msg->lm_bufcount; n++)
544 tail_len += size_round(msg->lm_buflens[n]);
547 msg->lm_buflens[segment] = newlen;
549 if (tail && tail_len) {
550 newpos = lustre_msg_buf_v1(msg, segment + 1, 0);
551 LASSERT(newpos <= tail);
553 memcpy(newpos, tail, tail_len);
556 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
557 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
558 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
559 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
563 return lustre_msg_size_v1(msg->lm_bufcount, (int *)msg->lm_buflens);
566 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
567 unsigned int newlen, int move_data)
569 char *tail = NULL, *newpos;
573 LASSERT(msg->lm_bufcount > segment);
574 LASSERT(msg->lm_buflens[segment] >= newlen);
576 if (msg->lm_buflens[segment] == newlen)
579 if (move_data && msg->lm_bufcount > segment + 1) {
580 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
581 for (n = segment + 1; n < msg->lm_bufcount; n++)
582 tail_len += size_round(msg->lm_buflens[n]);
585 msg->lm_buflens[segment] = newlen;
587 if (tail && tail_len) {
588 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
589 LASSERT(newpos <= tail);
591 memcpy(newpos, tail, tail_len);
594 return lustre_msg_size_v2(msg->lm_bufcount, (int *)msg->lm_buflens);
598 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
599 * we also move data forward from @segment + 1.
601 * if @newlen == 0, we remove the segment completely, but we still keep the
602 * totally bufcount the same to save possible data moving. this will leave a
603 * unused segment with size 0 at the tail, but that's ok.
605 * return new msg size after shrinking.
608 * + if any buffers higher than @segment has been filled in, must call shrink
609 * with non-zero @move_data.
610 * + caller should NOT keep pointers to msg buffers which higher than @segment
613 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
614 unsigned int newlen, int move_data)
616 switch (msg->lm_magic) {
617 case LUSTRE_MSG_MAGIC_V1:
618 return lustre_shrink_msg_v1((struct lustre_msg_v1 *) msg,
619 segment - 1, newlen, move_data);
620 case LUSTRE_MSG_MAGIC_V2:
621 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
623 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
627 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
629 PTLRPC_RS_DEBUG_LRU_DEL(rs);
631 LASSERT (atomic_read(&rs->rs_refcount) == 0);
632 LASSERT (!rs->rs_difficult || rs->rs_handled);
633 LASSERT (!rs->rs_on_net);
634 LASSERT (!rs->rs_scheduled);
635 LASSERT (rs->rs_export == NULL);
636 LASSERT (rs->rs_nlocks == 0);
637 LASSERT (list_empty(&rs->rs_exp_list));
638 LASSERT (list_empty(&rs->rs_obd_list));
640 sptlrpc_svc_free_rs(rs);
643 int lustre_unpack_msg_v1(void *msg, int len)
645 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
646 int flipped, required_len, i;
649 /* Now we know the sender speaks my language. */
650 required_len = lustre_msg_hdr_size_v1(0);
651 if (len < required_len) {
652 /* can't even look inside the message */
653 CERROR("message length %d too small for lustre_msg\n", len);
657 flipped = lustre_msg_swabbed((struct lustre_msg *)m);
660 __swab32s(&m->lm_type);
661 __swab32s(&m->lm_version);
662 __swab32s(&m->lm_opc);
663 __swab64s(&m->lm_last_xid);
664 __swab64s(&m->lm_last_committed);
665 __swab64s(&m->lm_transno);
666 __swab32s(&m->lm_status);
667 __swab32s(&m->lm_flags);
668 __swab32s(&m->lm_conn_cnt);
669 __swab32s(&m->lm_bufcount);
672 if (m->lm_version != PTLRPC_MSG_VERSION) {
673 CERROR("wrong lustre_msg version %08x\n", m->lm_version);
677 required_len = lustre_msg_hdr_size_v1(m->lm_bufcount);
678 if (len < required_len) {
679 /* didn't receive all the buffer lengths */
680 CERROR("message length %d too small for %d buflens\n",
681 len, m->lm_bufcount);
685 for (i = 0; i < m->lm_bufcount; i++) {
687 __swab32s (&m->lm_buflens[i]);
688 required_len += size_round(m->lm_buflens[i]);
691 if (len < required_len) {
692 CERROR("len: %d, required_len %d\n", len, required_len);
693 CERROR("bufcount: %d\n", m->lm_bufcount);
694 for (i = 0; i < m->lm_bufcount; i++)
695 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
702 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
704 int flipped, required_len, i;
706 /* Now we know the sender speaks my language. */
707 required_len = lustre_msg_hdr_size_v2(0);
708 if (len < required_len) {
709 /* can't even look inside the message */
710 CERROR("message length %d too small for lustre_msg\n", len);
714 flipped = lustre_msg_swabbed(m);
717 __swab32s(&m->lm_bufcount);
718 __swab32s(&m->lm_secflvr);
719 __swab32s(&m->lm_repsize);
720 __swab32s(&m->lm_timeout);
721 CLASSERT(offsetof(typeof(*m), lm_padding_1) != 0);
722 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
723 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
726 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
727 if (len < required_len) {
728 /* didn't receive all the buffer lengths */
729 CERROR ("message length %d too small for %d buflens\n",
730 len, m->lm_bufcount);
734 for (i = 0; i < m->lm_bufcount; i++) {
736 __swab32s(&m->lm_buflens[i]);
737 required_len += size_round(m->lm_buflens[i]);
740 if (len < required_len) {
741 CERROR("len: %d, required_len %d\n", len, required_len);
742 CERROR("bufcount: %d\n", m->lm_bufcount);
743 for (i = 0; i < m->lm_bufcount; i++)
744 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
751 int lustre_unpack_msg(struct lustre_msg *m, int len)
753 int required_len, rc;
756 /* We can provide a slightly better error log, if we check the
757 * message magic and version first. In the future, struct
758 * lustre_msg may grow, and we'd like to log a version mismatch,
759 * rather than a short message.
762 required_len = offsetof(struct lustre_msg, lm_magic) +
764 if (len < required_len) {
765 /* can't even look inside the message */
766 CERROR("message length %d too small for magic/version check\n",
771 switch (m->lm_magic) {
772 case LUSTRE_MSG_MAGIC_V1:
773 case LUSTRE_MSG_MAGIC_V1_SWABBED:
774 rc = lustre_unpack_msg_v1(m, len);
776 case LUSTRE_MSG_MAGIC_V2:
777 case LUSTRE_MSG_MAGIC_V2_SWABBED:
778 rc = lustre_unpack_msg_v2(m, len);
781 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
788 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
791 struct ptlrpc_body *pb;
793 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
795 CERROR("error unpacking ptlrpc body\n");
798 if (lustre_msg_swabbed(m))
799 lustre_swab_ptlrpc_body(pb);
801 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
802 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
809 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
811 switch (req->rq_reqmsg->lm_magic) {
812 case LUSTRE_MSG_MAGIC_V1:
813 case LUSTRE_MSG_MAGIC_V1_SWABBED:
815 case LUSTRE_MSG_MAGIC_V2:
816 case LUSTRE_MSG_MAGIC_V2_SWABBED:
817 lustre_set_req_swabbed(req, offset);
818 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
820 CERROR("bad lustre msg magic: %#08X\n",
821 req->rq_reqmsg->lm_magic);
826 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
828 switch (req->rq_repmsg->lm_magic) {
829 case LUSTRE_MSG_MAGIC_V1:
830 case LUSTRE_MSG_MAGIC_V1_SWABBED:
832 case LUSTRE_MSG_MAGIC_V2:
833 case LUSTRE_MSG_MAGIC_V2_SWABBED:
834 lustre_set_rep_swabbed(req, offset);
835 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
837 CERROR("bad lustre msg magic: %#08X\n",
838 req->rq_repmsg->lm_magic);
843 static inline int lustre_msg_buflen_v1(void *msg, int n)
845 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
848 if (n >= m->lm_bufcount)
851 return m->lm_buflens[n];
854 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
856 if (n >= m->lm_bufcount)
859 return m->lm_buflens[n];
863 * lustre_msg_buflen - return the length of buffer @n in message @m
864 * @m - lustre_msg (request or reply) to look at
865 * @n - message index (base 0)
867 * returns zero for non-existent message indices
869 int lustre_msg_buflen(struct lustre_msg *m, int n)
871 switch (m->lm_magic) {
872 case LUSTRE_MSG_MAGIC_V1:
873 case LUSTRE_MSG_MAGIC_V1_SWABBED:
874 return lustre_msg_buflen_v1(m, n - 1);
875 case LUSTRE_MSG_MAGIC_V2:
876 case LUSTRE_MSG_MAGIC_V2_SWABBED:
877 return lustre_msg_buflen_v2(m, n);
879 CERROR("incorrect message magic: %08x\n", m->lm_magic);
883 EXPORT_SYMBOL(lustre_msg_buflen);
885 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
887 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
890 if (n >= m->lm_bufcount)
893 m->lm_buflens[n] = len;
897 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
899 if (n >= m->lm_bufcount)
902 m->lm_buflens[n] = len;
905 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
907 switch (m->lm_magic) {
908 case LUSTRE_MSG_MAGIC_V1:
909 lustre_msg_set_buflen_v1(m, n - 1, len);
911 case LUSTRE_MSG_MAGIC_V2:
912 lustre_msg_set_buflen_v2(m, n, len);
915 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
919 EXPORT_SYMBOL(lustre_msg_set_buflen);
921 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
922 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
923 int lustre_msg_bufcount(struct lustre_msg *m)
925 switch (m->lm_magic) {
926 case LUSTRE_MSG_MAGIC_V1:
927 case LUSTRE_MSG_MAGIC_V1_SWABBED:
928 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
929 case LUSTRE_MSG_MAGIC_V2:
930 case LUSTRE_MSG_MAGIC_V2_SWABBED:
931 return m->lm_bufcount;
933 CERROR("incorrect message magic: %08x\n", m->lm_magic);
937 EXPORT_SYMBOL(lustre_msg_bufcount);
939 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
941 /* max_len == 0 means the string should fill the buffer */
945 switch (m->lm_magic) {
946 case LUSTRE_MSG_MAGIC_V1:
947 case LUSTRE_MSG_MAGIC_V1_SWABBED:
948 str = lustre_msg_buf_v1(m, index - 1, 0);
949 blen = lustre_msg_buflen_v1(m, index - 1);
951 case LUSTRE_MSG_MAGIC_V2:
952 case LUSTRE_MSG_MAGIC_V2_SWABBED:
953 str = lustre_msg_buf_v2(m, index, 0);
954 blen = lustre_msg_buflen_v2(m, index);
957 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
961 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
965 slen = strnlen(str, blen);
967 if (slen == blen) { /* not NULL terminated */
968 CERROR("can't unpack non-NULL terminated string in "
969 "msg %p buffer[%d] len %d\n", m, index, blen);
974 if (slen != blen - 1) {
975 CERROR("can't unpack short string in msg %p "
976 "buffer[%d] len %d: strlen %d\n",
977 m, index, blen, slen);
980 } else if (slen > max_len) {
981 CERROR("can't unpack oversized string in msg %p "
982 "buffer[%d] len %d strlen %d: max %d expected\n",
983 m, index, blen, slen, max_len);
990 /* Wrap up the normal fixed length cases */
991 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
996 switch (msg->lm_magic) {
997 case LUSTRE_MSG_MAGIC_V1:
998 case LUSTRE_MSG_MAGIC_V1_SWABBED:
999 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
1001 case LUSTRE_MSG_MAGIC_V2:
1002 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1003 ptr = lustre_msg_buf_v2(msg, index, min_size);
1006 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1011 if (swabber != NULL && lustre_msg_swabbed(msg))
1012 ((void (*)(void *))swabber)(ptr);
1017 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
1020 lustre_set_req_swabbed(req, index);
1021 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
1024 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
1027 lustre_set_rep_swabbed(req, index);
1028 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
1031 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
1033 switch (msg->lm_magic) {
1034 case LUSTRE_MSG_MAGIC_V1:
1035 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1036 return ((struct lustre_msg_v1 *)msg)->lm_flags &
1038 case LUSTRE_MSG_MAGIC_V2:
1039 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1040 struct ptlrpc_body *pb;
1042 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1044 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1047 return pb->pb_flags;
1050 /* flags might be printed in debug code while message
1056 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
1058 switch (msg->lm_magic) {
1059 case LUSTRE_MSG_MAGIC_V1:
1060 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1061 MSG_GEN_FLAG_MASK & flags;
1063 case LUSTRE_MSG_MAGIC_V2: {
1064 struct ptlrpc_body *pb;
1066 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1067 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1068 pb->pb_flags |= flags;
1072 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1076 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
1078 switch (msg->lm_magic) {
1079 case LUSTRE_MSG_MAGIC_V1:
1080 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK;
1081 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1082 MSG_GEN_FLAG_MASK & flags;
1084 case LUSTRE_MSG_MAGIC_V2: {
1085 struct ptlrpc_body *pb;
1087 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1088 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1089 pb->pb_flags = flags;
1093 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1097 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1099 switch (msg->lm_magic) {
1100 case LUSTRE_MSG_MAGIC_V1:
1101 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1102 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1103 ~(MSG_GEN_FLAG_MASK & flags);
1105 case LUSTRE_MSG_MAGIC_V2:
1106 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1107 struct ptlrpc_body *pb;
1109 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1110 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1111 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
1115 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1119 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1121 switch (msg->lm_magic) {
1122 case LUSTRE_MSG_MAGIC_V1:
1123 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1124 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1126 case LUSTRE_MSG_MAGIC_V2:
1127 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1128 struct ptlrpc_body *pb;
1130 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1132 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1135 return pb->pb_op_flags;
1142 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1144 switch (msg->lm_magic) {
1145 case LUSTRE_MSG_MAGIC_V1:
1146 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1147 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1149 case LUSTRE_MSG_MAGIC_V2: {
1150 struct ptlrpc_body *pb;
1152 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1153 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1154 pb->pb_op_flags |= flags;
1158 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1162 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
1164 switch (msg->lm_magic) {
1165 case LUSTRE_MSG_MAGIC_V1:
1166 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK;
1167 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1168 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1170 case LUSTRE_MSG_MAGIC_V2: {
1171 struct ptlrpc_body *pb;
1173 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1174 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1175 pb->pb_op_flags |= flags;
1179 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1183 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1185 switch (msg->lm_magic) {
1186 case LUSTRE_MSG_MAGIC_V1:
1187 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1188 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1189 case LUSTRE_MSG_MAGIC_V2:
1190 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1191 struct ptlrpc_body *pb;
1193 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1195 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1198 return &pb->pb_handle;
1201 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1206 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1208 switch (msg->lm_magic) {
1209 case LUSTRE_MSG_MAGIC_V1:
1210 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1211 return ((struct lustre_msg_v1 *)msg)->lm_type;
1212 case LUSTRE_MSG_MAGIC_V2:
1213 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1214 struct ptlrpc_body *pb;
1216 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1218 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1219 return PTL_RPC_MSG_ERR;
1224 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1225 return PTL_RPC_MSG_ERR;
1229 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1231 switch (msg->lm_magic) {
1232 case LUSTRE_MSG_MAGIC_V1:
1233 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1234 return ((struct lustre_msg_v1 *)msg)->lm_version;
1235 case LUSTRE_MSG_MAGIC_V2:
1236 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1237 struct ptlrpc_body *pb;
1239 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1241 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1244 return pb->pb_version;
1247 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1252 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1254 switch (msg->lm_magic) {
1255 case LUSTRE_MSG_MAGIC_V1:
1256 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1258 case LUSTRE_MSG_MAGIC_V2:
1259 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1260 struct ptlrpc_body *pb;
1262 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1263 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1264 pb->pb_version |= version;
1268 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1272 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1274 switch (msg->lm_magic) {
1275 case LUSTRE_MSG_MAGIC_V1:
1276 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1277 return ((struct lustre_msg_v1 *)msg)->lm_opc;
1278 case LUSTRE_MSG_MAGIC_V2:
1279 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1280 struct ptlrpc_body *pb;
1282 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1284 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1290 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1295 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1297 switch (msg->lm_magic) {
1298 case LUSTRE_MSG_MAGIC_V1:
1299 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1300 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1301 case LUSTRE_MSG_MAGIC_V2:
1302 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1303 struct ptlrpc_body *pb;
1305 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1307 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1310 return pb->pb_last_xid;
1313 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1318 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1320 switch (msg->lm_magic) {
1321 case LUSTRE_MSG_MAGIC_V1:
1322 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1323 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1324 case LUSTRE_MSG_MAGIC_V2:
1325 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1326 struct ptlrpc_body *pb;
1328 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1330 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1333 return pb->pb_last_committed;
1336 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1341 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1343 switch (msg->lm_magic) {
1344 case LUSTRE_MSG_MAGIC_V1:
1345 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1346 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1347 case LUSTRE_MSG_MAGIC_V2:
1348 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1349 struct ptlrpc_body *pb;
1351 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1353 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1356 return pb->pb_transno;
1359 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1364 int lustre_msg_get_status(struct lustre_msg *msg)
1366 switch (msg->lm_magic) {
1367 case LUSTRE_MSG_MAGIC_V1:
1368 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1369 return ((struct lustre_msg_v1 *)msg)->lm_status;
1370 case LUSTRE_MSG_MAGIC_V2:
1371 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1372 struct ptlrpc_body *pb;
1374 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1376 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1379 return pb->pb_status;
1382 /* status might be printed in debug code while message
1388 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1390 switch (msg->lm_magic) {
1391 case LUSTRE_MSG_MAGIC_V1:
1392 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1394 case LUSTRE_MSG_MAGIC_V2:
1395 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1396 struct ptlrpc_body *pb;
1398 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1400 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1406 CERROR("invalid msg magic %x\n", msg->lm_magic);
1412 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1414 switch (msg->lm_magic) {
1415 case LUSTRE_MSG_MAGIC_V1:
1416 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1418 case LUSTRE_MSG_MAGIC_V2:
1419 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1420 struct ptlrpc_body *pb;
1422 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1424 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1431 CERROR("invalid msg magic %x\n", msg->lm_magic);
1436 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1438 switch (msg->lm_magic) {
1439 case LUSTRE_MSG_MAGIC_V1:
1440 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1442 case LUSTRE_MSG_MAGIC_V2:
1443 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1444 struct ptlrpc_body *pb;
1446 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1448 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1451 return pb->pb_limit;
1454 CERROR("invalid msg magic %x\n", msg->lm_magic);
1460 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1462 switch (msg->lm_magic) {
1463 case LUSTRE_MSG_MAGIC_V1:
1464 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1466 case LUSTRE_MSG_MAGIC_V2:
1467 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1468 struct ptlrpc_body *pb;
1470 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1472 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1475 pb->pb_limit = limit;
1479 CERROR("invalid msg magic %x\n", msg->lm_magic);
1484 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1486 switch (msg->lm_magic) {
1487 case LUSTRE_MSG_MAGIC_V1:
1488 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1489 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1490 case LUSTRE_MSG_MAGIC_V2:
1491 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1492 struct ptlrpc_body *pb;
1494 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1496 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1499 return pb->pb_conn_cnt;
1502 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1507 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1509 switch (msg->lm_magic) {
1510 case LUSTRE_MSG_MAGIC_V1:
1511 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1512 case LUSTRE_MSG_MAGIC_V2:
1513 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1514 return msg->lm_magic;
1516 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1521 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1523 switch (msg->lm_magic) {
1524 case LUSTRE_MSG_MAGIC_V1:
1525 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1527 case LUSTRE_MSG_MAGIC_V2: {
1528 struct ptlrpc_body *pb;
1530 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1531 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1532 pb->pb_handle = *handle;
1536 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1540 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1542 switch (msg->lm_magic) {
1543 case LUSTRE_MSG_MAGIC_V1:
1544 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1546 case LUSTRE_MSG_MAGIC_V2: {
1547 struct ptlrpc_body *pb;
1549 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1550 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1555 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1559 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1561 switch (msg->lm_magic) {
1562 case LUSTRE_MSG_MAGIC_V1:
1563 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1565 case LUSTRE_MSG_MAGIC_V2: {
1566 struct ptlrpc_body *pb;
1568 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1569 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1574 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1578 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1580 switch (msg->lm_magic) {
1581 case LUSTRE_MSG_MAGIC_V1:
1582 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1584 case LUSTRE_MSG_MAGIC_V2: {
1585 struct ptlrpc_body *pb;
1587 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1588 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1589 pb->pb_last_xid = last_xid;
1593 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1597 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1599 switch (msg->lm_magic) {
1600 case LUSTRE_MSG_MAGIC_V1:
1601 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1603 case LUSTRE_MSG_MAGIC_V2: {
1604 struct ptlrpc_body *pb;
1606 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1607 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1608 pb->pb_last_committed = last_committed;
1612 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1616 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1618 switch (msg->lm_magic) {
1619 case LUSTRE_MSG_MAGIC_V1:
1620 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1622 case LUSTRE_MSG_MAGIC_V2: {
1623 struct ptlrpc_body *pb;
1625 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1626 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1627 pb->pb_transno = transno;
1631 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1635 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1637 switch (msg->lm_magic) {
1638 case LUSTRE_MSG_MAGIC_V1:
1639 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1641 case LUSTRE_MSG_MAGIC_V2: {
1642 struct ptlrpc_body *pb;
1644 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1645 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1646 pb->pb_status = status;
1650 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1654 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1656 switch (msg->lm_magic) {
1657 case LUSTRE_MSG_MAGIC_V1:
1658 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1660 case LUSTRE_MSG_MAGIC_V2: {
1661 struct ptlrpc_body *pb;
1663 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1664 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1665 pb->pb_conn_cnt = conn_cnt;
1669 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1673 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1675 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1677 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1678 req->rq_pill.rc_area[RCL_SERVER]);
1679 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1680 req->rq_reqmsg->lm_repsize = req->rq_replen;
1683 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, int *lens)
1685 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1686 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1687 req->rq_reqmsg->lm_repsize = req->rq_replen;
1690 /* byte flipping routines for all wire types declared in
1691 * lustre_idl.h implemented here.
1693 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1695 __swab32s (&b->pb_type);
1696 __swab32s (&b->pb_version);
1697 __swab32s (&b->pb_opc);
1698 __swab32s (&b->pb_status);
1699 __swab64s (&b->pb_last_xid);
1700 __swab64s (&b->pb_last_seen);
1701 __swab64s (&b->pb_last_committed);
1702 __swab64s (&b->pb_transno);
1703 __swab32s (&b->pb_flags);
1704 __swab32s (&b->pb_op_flags);
1705 __swab32s (&b->pb_conn_cnt);
1706 CLASSERT(offsetof(typeof(*b), pb_padding_1) != 0);
1707 CLASSERT(offsetof(typeof(*b), pb_padding_2) != 0);
1708 __swab32s (&b->pb_limit);
1709 __swab64s (&b->pb_slv);
1712 void lustre_swab_connect(struct obd_connect_data *ocd)
1714 __swab64s(&ocd->ocd_connect_flags);
1715 __swab32s(&ocd->ocd_version);
1716 __swab32s(&ocd->ocd_grant);
1717 __swab64s(&ocd->ocd_ibits_known);
1718 __swab32s(&ocd->ocd_index);
1719 __swab32s(&ocd->ocd_brw_size);
1720 __swab32s(&ocd->ocd_nllu);
1721 __swab32s(&ocd->ocd_nllg);
1722 __swab64s(&ocd->ocd_transno);
1723 __swab32s(&ocd->ocd_group);
1724 __swab32s(&ocd->ocd_cksum_types);
1725 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1726 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1729 void lustre_swab_obdo (struct obdo *o)
1731 __swab64s (&o->o_valid);
1732 __swab64s (&o->o_id);
1733 __swab64s (&o->o_gr);
1734 __swab64s (&o->o_fid);
1735 __swab64s (&o->o_size);
1736 __swab64s (&o->o_mtime);
1737 __swab64s (&o->o_atime);
1738 __swab64s (&o->o_ctime);
1739 __swab64s (&o->o_blocks);
1740 __swab64s (&o->o_grant);
1741 __swab32s (&o->o_blksize);
1742 __swab32s (&o->o_mode);
1743 __swab32s (&o->o_uid);
1744 __swab32s (&o->o_gid);
1745 __swab32s (&o->o_flags);
1746 __swab32s (&o->o_nlink);
1747 __swab32s (&o->o_generation);
1748 __swab32s (&o->o_misc);
1749 __swab32s (&o->o_easize);
1750 __swab32s (&o->o_mds);
1751 __swab32s (&o->o_stripe_idx);
1752 __swab32s (&o->o_padding_1);
1753 /* o_inline is opaque */
1756 void lustre_swab_obd_statfs (struct obd_statfs *os)
1758 __swab64s (&os->os_type);
1759 __swab64s (&os->os_blocks);
1760 __swab64s (&os->os_bfree);
1761 __swab64s (&os->os_bavail);
1762 __swab64s (&os->os_files);
1763 __swab64s (&os->os_ffree);
1764 /* no need to swab os_fsid */
1765 __swab32s (&os->os_bsize);
1766 __swab32s (&os->os_namelen);
1767 __swab64s (&os->os_maxbytes);
1768 __swab32s (&os->os_state);
1769 /* no need to swap os_spare */
1772 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1774 __swab64s (&ioo->ioo_id);
1775 __swab64s (&ioo->ioo_gr);
1776 __swab32s (&ioo->ioo_type);
1777 __swab32s (&ioo->ioo_bufcnt);
1780 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1782 __swab64s (&nbr->offset);
1783 __swab32s (&nbr->len);
1784 __swab32s (&nbr->flags);
1787 void lustre_swab_ost_body (struct ost_body *b)
1789 lustre_swab_obdo (&b->oa);
1792 void lustre_swab_ost_last_id(obd_id *id)
1797 void lustre_swab_generic_32s(__u32 *val)
1802 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1804 __swab64s(&lvb->lvb_size);
1805 __swab64s(&lvb->lvb_mtime);
1806 __swab64s(&lvb->lvb_atime);
1807 __swab64s(&lvb->lvb_ctime);
1808 __swab64s(&lvb->lvb_blocks);
1811 void lustre_swab_mds_status_req (struct mds_status_req *r)
1813 __swab32s (&r->flags);
1814 __swab32s (&r->repbuf);
1817 void lustre_swab_mds_body (struct mds_body *b)
1819 lustre_swab_ll_fid (&b->fid1);
1820 lustre_swab_ll_fid (&b->fid2);
1821 /* handle is opaque */
1822 __swab64s (&b->valid);
1823 __swab64s (&b->size);
1824 __swab64s (&b->mtime);
1825 __swab64s (&b->atime);
1826 __swab64s (&b->ctime);
1827 __swab64s (&b->blocks);
1828 __swab64s (&b->io_epoch);
1829 __swab64s (&b->ino);
1830 __swab32s (&b->fsuid);
1831 __swab32s (&b->fsgid);
1832 __swab32s (&b->capability);
1833 __swab32s (&b->mode);
1834 __swab32s (&b->uid);
1835 __swab32s (&b->gid);
1836 __swab32s (&b->flags);
1837 __swab32s (&b->rdev);
1838 __swab32s (&b->nlink);
1839 __swab32s (&b->generation);
1840 __swab32s (&b->suppgid);
1841 __swab32s (&b->eadatasize);
1842 __swab32s (&b->aclsize);
1843 __swab32s (&b->max_mdsize);
1844 __swab32s (&b->max_cookiesize);
1845 __swab32s (&b->padding_4);
1848 void lustre_swab_mdt_body (struct mdt_body *b)
1850 lustre_swab_lu_fid (&b->fid1);
1851 lustre_swab_lu_fid (&b->fid2);
1852 /* handle is opaque */
1853 __swab64s (&b->valid);
1854 __swab64s (&b->size);
1855 __swab64s (&b->mtime);
1856 __swab64s (&b->atime);
1857 __swab64s (&b->ctime);
1858 __swab64s (&b->blocks);
1859 __swab64s (&b->ioepoch);
1860 __swab64s (&b->ino);
1861 __swab32s (&b->fsuid);
1862 __swab32s (&b->fsgid);
1863 __swab32s (&b->capability);
1864 __swab32s (&b->mode);
1865 __swab32s (&b->uid);
1866 __swab32s (&b->gid);
1867 __swab32s (&b->flags);
1868 __swab32s (&b->rdev);
1869 __swab32s (&b->nlink);
1870 __swab32s (&b->generation);
1871 __swab32s (&b->suppgid);
1872 __swab32s (&b->eadatasize);
1873 __swab32s (&b->aclsize);
1874 __swab32s (&b->max_mdsize);
1875 __swab32s (&b->max_cookiesize);
1876 __swab32s (&b->padding_4);
1879 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1881 /* handle is opaque */
1882 __swab64s (&b->ioepoch);
1883 __swab32s (&b->flags);
1884 CLASSERT(offsetof(typeof(*b), padding) != 0);
1887 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1890 __swab32s(&mti->mti_lustre_ver);
1891 __swab32s(&mti->mti_stripe_index);
1892 __swab32s(&mti->mti_config_ver);
1893 __swab32s(&mti->mti_flags);
1894 __swab32s(&mti->mti_nid_count);
1895 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1896 for (i = 0; i < MTI_NIDS_MAX; i++)
1897 __swab64s(&mti->mti_nids[i]);
1900 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1902 __swab64s (&i->dqi_bgrace);
1903 __swab64s (&i->dqi_igrace);
1904 __swab32s (&i->dqi_flags);
1905 __swab32s (&i->dqi_valid);
1908 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1910 __swab64s (&b->dqb_ihardlimit);
1911 __swab64s (&b->dqb_isoftlimit);
1912 __swab64s (&b->dqb_curinodes);
1913 __swab64s (&b->dqb_bhardlimit);
1914 __swab64s (&b->dqb_bsoftlimit);
1915 __swab64s (&b->dqb_curspace);
1916 __swab64s (&b->dqb_btime);
1917 __swab64s (&b->dqb_itime);
1918 __swab32s (&b->dqb_valid);
1919 CLASSERT(offsetof(typeof(*b), padding) != 0);
1922 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1924 __swab32s (&q->qc_cmd);
1925 __swab32s (&q->qc_type);
1926 __swab32s (&q->qc_id);
1927 __swab32s (&q->qc_stat);
1928 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1929 lustre_swab_obd_dqblk (&q->qc_dqblk);
1932 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1934 __swab32s (&p->rp_uid);
1935 __swab32s (&p->rp_gid);
1936 __swab32s (&p->rp_fsuid);
1937 __swab32s (&p->rp_fsgid);
1938 __swab32s (&p->rp_access_perm);
1941 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1943 __swab32s (&p->rp_uid);
1944 __swab32s (&p->rp_gid);
1945 __swab32s (&p->rp_fsuid);
1946 __swab32s (&p->rp_fsgid);
1947 __swab32s (&p->rp_access_perm);
1950 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1952 __swab32s (&sa->sa_opcode);
1953 __swab32s (&sa->sa_fsuid);
1954 __swab32s (&sa->sa_fsgid);
1955 __swab32s (&sa->sa_cap);
1956 __swab32s (&sa->sa_suppgid);
1957 __swab32s (&sa->sa_mode);
1958 lustre_swab_ll_fid (&sa->sa_fid);
1959 __swab64s (&sa->sa_valid);
1960 __swab64s (&sa->sa_size);
1961 __swab64s (&sa->sa_mtime);
1962 __swab64s (&sa->sa_atime);
1963 __swab64s (&sa->sa_ctime);
1964 __swab32s (&sa->sa_uid);
1965 __swab32s (&sa->sa_gid);
1966 __swab32s (&sa->sa_attr_flags);
1967 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1970 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1972 __swab64s(&jr->jr_headsize);
1973 lustre_swab_ll_fid(&jr->jr_fid);
1976 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1978 __swab64s(&jr->jr_headsize);
1979 lustre_swab_lu_fid(&jr->jr_fid);
1982 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1984 __swab32s (&cr->cr_opcode);
1985 __swab32s (&cr->cr_fsuid);
1986 __swab32s (&cr->cr_fsgid);
1987 __swab32s (&cr->cr_cap);
1988 __swab32s (&cr->cr_flags); /* for use with open */
1989 __swab32s (&cr->cr_mode);
1990 lustre_swab_ll_fid (&cr->cr_fid);
1991 lustre_swab_ll_fid (&cr->cr_replayfid);
1992 __swab64s (&cr->cr_time);
1993 __swab64s (&cr->cr_rdev);
1994 __swab32s (&cr->cr_suppgid);
1995 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1996 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1997 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1998 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1999 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
2002 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
2004 __swab32s (&lk->lk_opcode);
2005 __swab32s (&lk->lk_fsuid);
2006 __swab32s (&lk->lk_fsgid);
2007 __swab32s (&lk->lk_cap);
2008 __swab32s (&lk->lk_suppgid1);
2009 __swab32s (&lk->lk_suppgid2);
2010 lustre_swab_ll_fid (&lk->lk_fid1);
2011 lustre_swab_ll_fid (&lk->lk_fid2);
2012 __swab64s (&lk->lk_time);
2013 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
2014 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2015 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2016 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2019 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
2021 __swab32s (&ul->ul_opcode);
2022 __swab32s (&ul->ul_fsuid);
2023 __swab32s (&ul->ul_fsgid);
2024 __swab32s (&ul->ul_cap);
2025 __swab32s (&ul->ul_suppgid);
2026 __swab32s (&ul->ul_mode);
2027 lustre_swab_ll_fid (&ul->ul_fid1);
2028 lustre_swab_ll_fid (&ul->ul_fid2);
2029 __swab64s (&ul->ul_time);
2030 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
2031 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2032 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2033 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2036 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
2038 __swab32s (&rn->rn_opcode);
2039 __swab32s (&rn->rn_fsuid);
2040 __swab32s (&rn->rn_fsgid);
2041 __swab32s (&rn->rn_cap);
2042 __swab32s (&rn->rn_suppgid1);
2043 __swab32s (&rn->rn_suppgid2);
2044 lustre_swab_ll_fid (&rn->rn_fid1);
2045 lustre_swab_ll_fid (&rn->rn_fid2);
2046 __swab64s (&rn->rn_time);
2047 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
2048 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
2049 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2050 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2053 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
2055 __swab32s (&rr->rr_opcode);
2056 __swab32s (&rr->rr_fsuid);
2057 __swab32s (&rr->rr_fsgid);
2058 __swab32s (&rr->rr_cap);
2059 __swab32s (&rr->rr_suppgid1);
2060 __swab32s (&rr->rr_suppgid2);
2061 /* handle is opaque */
2062 lustre_swab_lu_fid (&rr->rr_fid1);
2063 lustre_swab_lu_fid (&rr->rr_fid2);
2064 __swab64s (&rr->rr_mtime);
2065 __swab64s (&rr->rr_atime);
2066 __swab64s (&rr->rr_ctime);
2067 __swab64s (&rr->rr_size);
2068 __swab64s (&rr->rr_blocks);
2069 __swab32s (&rr->rr_bias);
2070 __swab32s (&rr->rr_mode);
2071 __swab32s (&rr->rr_padding_1);
2072 __swab32s (&rr->rr_padding_2);
2073 __swab32s (&rr->rr_padding_3);
2074 __swab32s (&rr->rr_padding_4);
2076 CLASSERT(offsetof(typeof(*rr), rr_padding_1) != 0);
2077 CLASSERT(offsetof(typeof(*rr), rr_padding_2) != 0);
2078 CLASSERT(offsetof(typeof(*rr), rr_padding_3) != 0);
2079 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
2082 void lustre_swab_lov_desc (struct lov_desc *ld)
2084 __swab32s (&ld->ld_tgt_count);
2085 __swab32s (&ld->ld_active_tgt_count);
2086 __swab32s (&ld->ld_default_stripe_count);
2087 __swab64s (&ld->ld_default_stripe_size);
2088 __swab64s (&ld->ld_default_stripe_offset);
2089 __swab32s (&ld->ld_pattern);
2090 __swab32s (&ld->ld_qos_maxage);
2091 /* uuid endian insensitive */
2094 /*begin adding MDT by huanghua@clusterfs.com*/
2095 void lustre_swab_lmv_desc (struct lmv_desc *ld)
2097 __swab32s (&ld->ld_tgt_count);
2098 __swab32s (&ld->ld_active_tgt_count);
2099 /* uuid endian insensitive */
2101 /*end adding MDT by huanghua@clusterfs.com*/
2102 void lustre_swab_md_fld (struct md_fld *mf)
2104 __swab64s(&mf->mf_seq);
2105 __swab64s(&mf->mf_mds);
2108 static void print_lum (struct lov_user_md *lum)
2110 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
2111 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
2112 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2113 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
2114 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
2115 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2116 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2117 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
2120 void lustre_swab_lov_user_md(struct lov_user_md *lum)
2123 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2124 __swab32s(&lum->lmm_magic);
2125 __swab32s(&lum->lmm_pattern);
2126 __swab64s(&lum->lmm_object_id);
2127 __swab64s(&lum->lmm_object_gr);
2128 __swab32s(&lum->lmm_stripe_size);
2129 __swab16s(&lum->lmm_stripe_count);
2130 __swab16s(&lum->lmm_stripe_offset);
2135 static void print_lumj (struct lov_user_md_join *lumj)
2137 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2138 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2139 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2140 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2141 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2142 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2143 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2144 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2147 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2150 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2151 __swab32s(&lumj->lmm_magic);
2152 __swab32s(&lumj->lmm_pattern);
2153 __swab64s(&lumj->lmm_object_id);
2154 __swab64s(&lumj->lmm_object_gr);
2155 __swab32s(&lumj->lmm_stripe_size);
2156 __swab32s(&lumj->lmm_stripe_count);
2157 __swab32s(&lumj->lmm_extent_count);
2162 static void print_lum_objs(struct lov_user_md *lum)
2164 struct lov_user_ost_data *lod;
2167 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2169 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2170 for (i = 0; i < lum->lmm_stripe_count; i++) {
2171 lod = &lum->lmm_objects[i];
2172 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2173 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2174 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2175 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2180 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2182 struct lov_user_ost_data *lod;
2185 for (i = 0; i < lum->lmm_stripe_count; i++) {
2186 lod = &lum->lmm_objects[i];
2187 __swab64s(&lod->l_object_id);
2188 __swab64s(&lod->l_object_gr);
2189 __swab32s(&lod->l_ost_gen);
2190 __swab32s(&lod->l_ost_idx);
2192 print_lum_objs(lum);
2197 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2199 struct lov_ost_data *lod;
2202 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2203 lod = &lmm->lmm_objects[i];
2204 __swab64s(&lod->l_object_id);
2205 __swab64s(&lod->l_object_gr);
2206 __swab32s(&lod->l_ost_gen);
2207 __swab32s(&lod->l_ost_idx);
2209 __swab32s(&lmm->lmm_magic);
2210 __swab32s(&lmm->lmm_pattern);
2211 __swab64s(&lmm->lmm_object_id);
2212 __swab64s(&lmm->lmm_object_gr);
2213 __swab32s(&lmm->lmm_stripe_size);
2214 __swab32s(&lmm->lmm_stripe_count);
2220 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2224 for (i = 0; i < RES_NAME_SIZE; i++)
2225 __swab64s (&id->name[i]);
2228 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2230 /* the lock data is a union and the first two fields are always an
2231 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2232 * data the same way. */
2233 __swab64s(&d->l_extent.start);
2234 __swab64s(&d->l_extent.end);
2235 __swab64s(&d->l_extent.gid);
2236 __swab32s(&d->l_flock.pid);
2239 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2241 __swab64s (&i->opc);
2244 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2246 __swab32s (&r->lr_type);
2247 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2248 lustre_swab_ldlm_res_id (&r->lr_name);
2251 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2253 lustre_swab_ldlm_resource_desc (&l->l_resource);
2254 __swab32s (&l->l_req_mode);
2255 __swab32s (&l->l_granted_mode);
2256 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2259 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2261 __swab32s (&rq->lock_flags);
2262 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2263 __swab32s (&rq->lock_count);
2264 /* lock_handle[] opaque */
2267 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2269 __swab32s (&r->lock_flags);
2270 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2271 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2272 /* lock_handle opaque */
2273 __swab64s (&r->lock_policy_res1);
2274 __swab64s (&r->lock_policy_res2);
2277 /* no one calls this */
2278 int llog_log_swabbed(struct llog_log_hdr *hdr)
2280 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2282 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2287 void lustre_swab_qdata(struct qunit_data *d)
2289 __swab32s (&d->qd_id);
2290 __swab32s (&d->qd_flags);
2291 __swab64s (&d->qd_count);
2294 void lustre_swab_qdata_old(struct qunit_data_old *d)
2296 __swab32s (&d->qd_id);
2297 __swab32s (&d->qd_type);
2298 __swab32s (&d->qd_count);
2299 __swab32s (&d->qd_isblk);
2303 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2305 struct qunit_data_old tmp;
2306 struct qunit_data *ret;
2313 ret = (struct qunit_data *)d;
2314 ret->qd_id = tmp.qd_id;
2315 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2316 ret->qd_count = tmp.qd_count;
2320 EXPORT_SYMBOL(lustre_quota_old_to_new);
2322 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2324 struct qunit_data tmp;
2325 struct qunit_data_old *ret;
2332 ret = (struct qunit_data_old *)d;
2333 ret->qd_id = tmp.qd_id;
2334 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2335 ret->qd_count = (__u32)tmp.qd_count;
2336 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2339 EXPORT_SYMBOL(lustre_quota_new_to_old);
2340 #endif /* __KERNEL__ */
2342 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2344 LASSERT(req->rq_reqmsg);
2346 switch (req->rq_reqmsg->lm_magic) {
2347 case LUSTRE_MSG_MAGIC_V1:
2348 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2350 case LUSTRE_MSG_MAGIC_V2:
2351 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2352 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2354 CERROR("bad lustre msg magic: %#08X\n",
2355 req->rq_reqmsg->lm_magic);
2360 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2362 LASSERT(req->rq_repmsg);
2364 switch (req->rq_repmsg->lm_magic) {
2365 case LUSTRE_MSG_MAGIC_V1:
2366 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2368 case LUSTRE_MSG_MAGIC_V2:
2369 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2370 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2372 /* uninitialized yet */
2377 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2378 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2382 va_start(args, fmt);
2383 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2384 data->msg_fn, data->msg_line, fmt, args,
2385 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d lens"
2386 " %d/%d ref %d fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2387 req, req->rq_xid, req->rq_transno,
2388 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2389 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2390 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2392 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2394 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2396 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2397 (req->rq_import && req->rq_import->imp_client) ?
2398 req->rq_import->imp_client->cli_request_portal : -1,
2399 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2400 DEBUG_REQ_FLAGS(req),
2401 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2402 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2403 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2404 lustre_msg_get_flags(req->rq_repmsg) : -1,
2406 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2407 lustre_msg_get_status(req->rq_repmsg) : -1);
2409 EXPORT_SYMBOL(_debug_req);
2411 void lustre_swab_lustre_capa(struct lustre_capa *c)
2413 lustre_swab_lu_fid(&c->lc_fid);
2414 __swab64s (&c->lc_opc);
2415 __swab32s (&c->lc_uid);
2416 __swab32s (&c->lc_flags);
2417 __swab32s (&c->lc_keyid);
2418 __swab32s (&c->lc_timeout);
2419 __swab64s (&c->lc_expiry);
2422 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2424 __swab64s (&k->lk_mdsid);
2425 __swab32s (&k->lk_keyid);
2426 __swab32s (&k->lk_padding);