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 int lustre_msg_size(__u32 magic, int count, int *lens)
116 int size[] = { sizeof(struct ptlrpc_body) };
124 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
127 case LUSTRE_MSG_MAGIC_V1:
128 return lustre_msg_size_v1(count - 1, lens + 1);
129 case LUSTRE_MSG_MAGIC_V2:
130 return lustre_msg_size_v2(count, lens);
132 LASSERTF(0, "incorrect message magic: %08x\n", magic);
138 void lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
140 struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)m;
145 msg->lm_magic = LUSTRE_MSG_MAGIC_V1;
146 msg->lm_version = PTLRPC_MSG_VERSION;
147 msg->lm_bufcount = count;
149 for (i = 0; i < count; i++)
150 msg->lm_buflens[i] = lens[i];
155 ptr = (char *)msg + lustre_msg_hdr_size_v1(count);
156 for (i = 0; i < count; i++) {
158 LOGL(tmp, lens[i], ptr);
162 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
168 msg->lm_bufcount = count;
169 /* XXX: lm_secflvr uninitialized here */
170 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
172 for (i = 0; i < count; i++)
173 msg->lm_buflens[i] = lens[i];
178 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
179 for (i = 0; i < count; i++) {
181 LOGL(tmp, lens[i], ptr);
184 EXPORT_SYMBOL(lustre_init_msg_v2);
186 static int lustre_pack_request_v1(struct ptlrpc_request *req,
187 int count, int *lens, char **bufs)
191 reqlen = lustre_msg_size_v1(count, lens);
193 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
197 req->rq_reqlen = reqlen;
199 lustre_init_msg_v1(req->rq_reqmsg, count, lens, bufs);
203 static int lustre_pack_request_v2(struct ptlrpc_request *req,
204 int count, int *lens, char **bufs)
208 reqlen = lustre_msg_size_v2(count, lens);
210 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
214 req->rq_reqlen = reqlen;
216 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
217 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
218 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
222 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
223 int *lens, char **bufs)
225 int size[] = { sizeof(struct ptlrpc_body) };
233 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
235 /* if we choose policy other than null, we have also choosed
236 * to use new message format.
238 if (magic == LUSTRE_MSG_MAGIC_V1 &&
239 req->rq_sec_flavor != SPTLRPC_FLVR_NULL)
240 magic = LUSTRE_MSG_MAGIC_V2;
243 case LUSTRE_MSG_MAGIC_V1:
244 return lustre_pack_request_v1(req, count - 1, lens + 1,
245 bufs ? bufs + 1 : NULL);
246 case LUSTRE_MSG_MAGIC_V2:
247 return lustre_pack_request_v2(req, count, lens, bufs);
249 LASSERTF(0, "incorrect message magic: %08x\n", magic);
255 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
256 spinlock_t ptlrpc_rs_debug_lock;
258 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
260 spin_lock(&ptlrpc_rs_debug_lock); \
261 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
262 spin_unlock(&ptlrpc_rs_debug_lock); \
265 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
267 spin_lock(&ptlrpc_rs_debug_lock); \
268 list_del(&(rs)->rs_debug_list); \
269 spin_unlock(&ptlrpc_rs_debug_lock); \
272 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
273 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
276 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
278 struct ptlrpc_reply_state *rs = NULL;
280 spin_lock(&svc->srv_lock);
281 /* See if we have anything in a pool, and wait if nothing */
282 while (list_empty(&svc->srv_free_rs_list)) {
283 struct l_wait_info lwi;
285 spin_unlock(&svc->srv_lock);
286 /* If we cannot get anything for some long time, we better
287 bail out instead of waiting infinitely */
288 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
289 rc = l_wait_event(svc->srv_free_rs_waitq,
290 !list_empty(&svc->srv_free_rs_list), &lwi);
293 spin_lock(&svc->srv_lock);
296 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
298 list_del(&rs->rs_list);
299 spin_unlock(&svc->srv_lock);
301 memset(rs, 0, svc->srv_max_reply_size);
302 rs->rs_service = svc;
308 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
310 struct ptlrpc_service *svc = rs->rs_service;
314 spin_lock(&svc->srv_lock);
315 list_add(&rs->rs_list, &svc->srv_free_rs_list);
316 spin_unlock(&svc->srv_lock);
317 cfs_waitq_signal(&svc->srv_free_rs_waitq);
320 static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count,
321 int *lens, char **bufs)
323 struct ptlrpc_reply_state *rs;
327 LASSERT (req->rq_reply_state == NULL);
329 msg_len = lustre_msg_size_v1(count, lens);
330 rc = sptlrpc_svc_alloc_rs(req, msg_len);
334 rs = req->rq_reply_state;
335 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
336 rs->rs_cb_id.cbid_fn = reply_out_callback;
337 rs->rs_cb_id.cbid_arg = rs;
338 rs->rs_service = req->rq_rqbd->rqbd_service;
339 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
340 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
342 req->rq_replen = msg_len;
343 req->rq_reply_state = rs;
344 req->rq_repmsg = rs->rs_msg;
345 lustre_init_msg_v1(rs->rs_msg, count, lens, bufs);
347 PTLRPC_RS_DEBUG_LRU_ADD(rs);
352 int lustre_pack_reply_v2(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_v2(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_v2(rs->rs_msg, count, lens, bufs);
378 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
379 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
381 PTLRPC_RS_DEBUG_LRU_ADD(rs);
385 EXPORT_SYMBOL(lustre_pack_reply_v2);
387 int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
391 int size[] = { sizeof(struct ptlrpc_body) };
399 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
401 switch (req->rq_reqmsg->lm_magic) {
402 case LUSTRE_MSG_MAGIC_V1:
403 case LUSTRE_MSG_MAGIC_V1_SWABBED:
404 rc = lustre_pack_reply_v1(req, count - 1, lens + 1,
405 bufs ? bufs + 1 : NULL);
407 case LUSTRE_MSG_MAGIC_V2:
408 case LUSTRE_MSG_MAGIC_V2_SWABBED:
409 rc = lustre_pack_reply_v2(req, count, lens, bufs);
412 LASSERTF(0, "incorrect message magic: %08x\n",
413 req->rq_reqmsg->lm_magic);
417 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
418 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
422 void *lustre_msg_buf_v1(void *msg, int n, int min_size)
424 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
425 int i, offset, buflen, bufcount;
430 bufcount = m->lm_bufcount;
431 if (unlikely(n >= bufcount)) {
432 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
437 buflen = m->lm_buflens[n];
438 if (unlikely(buflen < min_size)) {
439 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
440 m, n, buflen, min_size);
445 offset = lustre_msg_hdr_size_v1(bufcount);
446 for (i = 0; i < n; i++)
447 offset += size_round(m->lm_buflens[i]);
449 return (char *)m + offset;
452 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
454 int i, offset, buflen, bufcount;
459 bufcount = m->lm_bufcount;
460 if (unlikely(n >= bufcount)) {
461 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
466 buflen = m->lm_buflens[n];
467 if (unlikely(buflen < min_size)) {
468 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
469 m, n, buflen, min_size);
473 offset = lustre_msg_hdr_size_v2(bufcount);
474 for (i = 0; i < n; i++)
475 offset += size_round(m->lm_buflens[i]);
477 return (char *)m + offset;
480 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
482 switch (m->lm_magic) {
483 case LUSTRE_MSG_MAGIC_V1:
484 case LUSTRE_MSG_MAGIC_V1_SWABBED:
485 return lustre_msg_buf_v1(m, n - 1, min_size);
486 case LUSTRE_MSG_MAGIC_V2:
487 case LUSTRE_MSG_MAGIC_V2_SWABBED:
488 return lustre_msg_buf_v2(m, n, min_size);
490 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
495 int lustre_shrink_msg_v1(struct lustre_msg_v1 *msg, int segment,
496 unsigned int newlen, int move_data)
498 char *tail = NULL, *newpos;
502 LASSERT(segment >= 0);
503 LASSERT(msg->lm_bufcount > segment);
504 LASSERT(msg->lm_buflens[segment] >= newlen);
506 if (msg->lm_buflens[segment] == newlen)
509 if (move_data && msg->lm_bufcount > segment + 1) {
510 tail = lustre_msg_buf_v1(msg, segment + 1, 0);
511 for (n = segment + 1; n < msg->lm_bufcount; n++)
512 tail_len += size_round(msg->lm_buflens[n]);
515 msg->lm_buflens[segment] = newlen;
517 if (tail && tail_len) {
518 newpos = lustre_msg_buf_v1(msg, segment + 1, 0);
519 LASSERT(newpos <= tail);
521 memcpy(newpos, tail, tail_len);
524 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
525 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
526 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
527 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
531 return lustre_msg_size_v1(msg->lm_bufcount, msg->lm_buflens);
534 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
535 unsigned int newlen, int move_data)
537 char *tail = NULL, *newpos;
541 LASSERT(msg->lm_bufcount > segment);
542 LASSERT(msg->lm_buflens[segment] >= newlen);
544 if (msg->lm_buflens[segment] == newlen)
547 if (move_data && msg->lm_bufcount > segment + 1) {
548 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
549 for (n = segment + 1; n < msg->lm_bufcount; n++)
550 tail_len += size_round(msg->lm_buflens[n]);
553 msg->lm_buflens[segment] = newlen;
555 if (tail && tail_len) {
556 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
557 LASSERT(newpos <= tail);
559 memcpy(newpos, tail, tail_len);
562 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
563 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
564 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
565 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
569 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
573 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
574 * we also move data forward from @segment + 1.
576 * if @newlen == 0, we remove the segment completely, but we still keep the
577 * totally bufcount the same to save possible data moving. this will leave a
578 * unused segment with size 0 at the tail, but that's ok.
580 * return new msg size after shrinking.
583 * + if any buffers higher than @segment has been filled in, must call shrink
584 * with non-zero @move_data.
585 * + caller should NOT keep pointers to msg buffers which higher than @segment
588 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
589 unsigned int newlen, int move_data)
591 switch (msg->lm_magic) {
592 case LUSTRE_MSG_MAGIC_V1:
593 return lustre_shrink_msg_v1((struct lustre_msg_v1 *) msg,
594 segment - 1, newlen, move_data);
595 case LUSTRE_MSG_MAGIC_V2:
596 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
598 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
602 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
604 PTLRPC_RS_DEBUG_LRU_DEL(rs);
606 LASSERT (atomic_read(&rs->rs_refcount) == 0);
607 LASSERT (!rs->rs_difficult || rs->rs_handled);
608 LASSERT (!rs->rs_on_net);
609 LASSERT (!rs->rs_scheduled);
610 LASSERT (rs->rs_export == NULL);
611 LASSERT (rs->rs_nlocks == 0);
612 LASSERT (list_empty(&rs->rs_exp_list));
613 LASSERT (list_empty(&rs->rs_obd_list));
615 sptlrpc_svc_free_rs(rs);
618 int lustre_unpack_msg_v1(void *msg, int len)
620 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
621 int flipped, required_len, i;
624 /* Now we know the sender speaks my language. */
625 required_len = lustre_msg_hdr_size_v1(0);
626 if (len < required_len) {
627 /* can't even look inside the message */
628 CERROR("message length %d too small for lustre_msg\n", len);
632 flipped = lustre_msg_swabbed((struct lustre_msg *)m);
635 __swab32s(&m->lm_type);
636 __swab32s(&m->lm_version);
637 __swab32s(&m->lm_opc);
638 __swab64s(&m->lm_last_xid);
639 __swab64s(&m->lm_last_committed);
640 __swab64s(&m->lm_transno);
641 __swab32s(&m->lm_status);
642 __swab32s(&m->lm_flags);
643 __swab32s(&m->lm_conn_cnt);
644 __swab32s(&m->lm_bufcount);
647 if (m->lm_version != PTLRPC_MSG_VERSION) {
648 CERROR("wrong lustre_msg version %08x\n", m->lm_version);
652 required_len = lustre_msg_hdr_size_v1(m->lm_bufcount);
653 if (len < required_len) {
654 /* didn't receive all the buffer lengths */
655 CERROR("message length %d too small for %d buflens\n",
656 len, m->lm_bufcount);
660 for (i = 0; i < m->lm_bufcount; i++) {
662 __swab32s (&m->lm_buflens[i]);
663 required_len += size_round(m->lm_buflens[i]);
666 if (len < required_len) {
667 CERROR("len: %d, required_len %d\n", len, required_len);
668 CERROR("bufcount: %d\n", m->lm_bufcount);
669 for (i = 0; i < m->lm_bufcount; i++)
670 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
677 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
679 int flipped, required_len, i;
681 /* Now we know the sender speaks my language. */
682 required_len = lustre_msg_hdr_size_v2(0);
683 if (len < required_len) {
684 /* can't even look inside the message */
685 CERROR("message length %d too small for lustre_msg\n", len);
689 flipped = lustre_msg_swabbed(m);
692 __swab32s(&m->lm_bufcount);
693 __swab32s(&m->lm_secflvr);
694 __swab32s(&m->lm_repsize);
695 __swab32s(&m->lm_timeout);
696 CLASSERT(offsetof(typeof(*m), lm_padding_1) != 0);
697 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
698 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
701 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
702 if (len < required_len) {
703 /* didn't receive all the buffer lengths */
704 CERROR ("message length %d too small for %d buflens\n",
705 len, m->lm_bufcount);
709 for (i = 0; i < m->lm_bufcount; i++) {
711 __swab32s(&m->lm_buflens[i]);
712 required_len += size_round(m->lm_buflens[i]);
715 if (len < required_len) {
716 CERROR("len: %d, required_len %d\n", len, required_len);
717 CERROR("bufcount: %d\n", m->lm_bufcount);
718 for (i = 0; i < m->lm_bufcount; i++)
719 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
726 int lustre_unpack_msg(struct lustre_msg *m, int len)
728 int required_len, rc;
731 /* We can provide a slightly better error log, if we check the
732 * message magic and version first. In the future, struct
733 * lustre_msg may grow, and we'd like to log a version mismatch,
734 * rather than a short message.
737 required_len = offsetof(struct lustre_msg, lm_magic) +
739 if (len < required_len) {
740 /* can't even look inside the message */
741 CERROR("message length %d too small for magic/version check\n",
746 switch (m->lm_magic) {
747 case LUSTRE_MSG_MAGIC_V1:
748 case LUSTRE_MSG_MAGIC_V1_SWABBED:
749 rc = lustre_unpack_msg_v1(m, len);
751 case LUSTRE_MSG_MAGIC_V2:
752 case LUSTRE_MSG_MAGIC_V2_SWABBED:
753 rc = lustre_unpack_msg_v2(m, len);
756 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
763 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
766 struct ptlrpc_body *pb;
768 pb = lustre_swab_buf(m, offset, sizeof(*pb), lustre_swab_ptlrpc_body);
770 CERROR("error unpacking ptlrpc body");
774 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
775 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
782 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
784 switch (req->rq_reqmsg->lm_magic) {
785 case LUSTRE_MSG_MAGIC_V1:
786 case LUSTRE_MSG_MAGIC_V1_SWABBED:
788 case LUSTRE_MSG_MAGIC_V2:
789 case LUSTRE_MSG_MAGIC_V2_SWABBED:
790 lustre_set_req_swabbed(req, offset);
791 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
793 CERROR("bad lustre msg magic: %#08X\n",
794 req->rq_reqmsg->lm_magic);
799 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
801 switch (req->rq_repmsg->lm_magic) {
802 case LUSTRE_MSG_MAGIC_V1:
803 case LUSTRE_MSG_MAGIC_V1_SWABBED:
805 case LUSTRE_MSG_MAGIC_V2:
806 case LUSTRE_MSG_MAGIC_V2_SWABBED:
807 lustre_set_rep_swabbed(req, offset);
808 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
810 CERROR("bad lustre msg magic: %#08X\n",
811 req->rq_repmsg->lm_magic);
816 static inline int lustre_msg_buflen_v1(void *msg, int n)
818 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
821 if (n >= m->lm_bufcount)
824 return m->lm_buflens[n];
827 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
829 if (n >= m->lm_bufcount)
832 return m->lm_buflens[n];
836 * lustre_msg_buflen - return the length of buffer @n in message @m
837 * @m - lustre_msg (request or reply) to look at
838 * @n - message index (base 0)
840 * returns zero for non-existent message indices
842 int lustre_msg_buflen(struct lustre_msg *m, int n)
844 switch (m->lm_magic) {
845 case LUSTRE_MSG_MAGIC_V1:
846 case LUSTRE_MSG_MAGIC_V1_SWABBED:
847 return lustre_msg_buflen_v1(m, n - 1);
848 case LUSTRE_MSG_MAGIC_V2:
849 case LUSTRE_MSG_MAGIC_V2_SWABBED:
850 return lustre_msg_buflen_v2(m, n);
852 CERROR("incorrect message magic: %08x\n", m->lm_magic);
856 EXPORT_SYMBOL(lustre_msg_buflen);
858 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
860 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
863 if (n >= m->lm_bufcount)
866 m->lm_buflens[n] = len;
870 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
872 if (n >= m->lm_bufcount)
875 m->lm_buflens[n] = len;
878 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
880 switch (m->lm_magic) {
881 case LUSTRE_MSG_MAGIC_V1:
882 lustre_msg_set_buflen_v1(m, n - 1, len);
884 case LUSTRE_MSG_MAGIC_V2:
885 lustre_msg_set_buflen_v2(m, n, len);
888 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
892 EXPORT_SYMBOL(lustre_msg_set_buflen);
894 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
895 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
896 int lustre_msg_bufcount(struct lustre_msg *m)
898 switch (m->lm_magic) {
899 case LUSTRE_MSG_MAGIC_V1:
900 case LUSTRE_MSG_MAGIC_V1_SWABBED:
901 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
902 case LUSTRE_MSG_MAGIC_V2:
903 case LUSTRE_MSG_MAGIC_V2_SWABBED:
904 return m->lm_bufcount;
906 CERROR("incorrect message magic: %08x\n", m->lm_magic);
910 EXPORT_SYMBOL(lustre_msg_bufcount);
912 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
914 /* max_len == 0 means the string should fill the buffer */
918 switch (m->lm_magic) {
919 case LUSTRE_MSG_MAGIC_V1:
920 case LUSTRE_MSG_MAGIC_V1_SWABBED:
921 str = lustre_msg_buf_v1(m, index - 1, 0);
922 blen = lustre_msg_buflen_v1(m, index - 1);
924 case LUSTRE_MSG_MAGIC_V2:
925 case LUSTRE_MSG_MAGIC_V2_SWABBED:
926 str = lustre_msg_buf_v2(m, index, 0);
927 blen = lustre_msg_buflen_v2(m, index);
930 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
934 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
938 slen = strnlen(str, blen);
940 if (slen == blen) { /* not NULL terminated */
941 CERROR("can't unpack non-NULL terminated string in "
942 "msg %p buffer[%d] len %d\n", m, index, blen);
947 if (slen != blen - 1) {
948 CERROR("can't unpack short string in msg %p "
949 "buffer[%d] len %d: strlen %d\n",
950 m, index, blen, slen);
953 } else if (slen > max_len) {
954 CERROR("can't unpack oversized string in msg %p "
955 "buffer[%d] len %d strlen %d: max %d expected\n",
956 m, index, blen, slen, max_len);
963 /* Wrap up the normal fixed length cases */
964 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
969 switch (msg->lm_magic) {
970 case LUSTRE_MSG_MAGIC_V1:
971 case LUSTRE_MSG_MAGIC_V1_SWABBED:
972 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
974 case LUSTRE_MSG_MAGIC_V2:
975 case LUSTRE_MSG_MAGIC_V2_SWABBED:
976 ptr = lustre_msg_buf_v2(msg, index, min_size);
979 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
984 if (swabber != NULL && lustre_msg_swabbed(msg))
985 ((void (*)(void *))swabber)(ptr);
990 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
993 lustre_set_req_swabbed(req, index);
994 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
997 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
1000 lustre_set_rep_swabbed(req, index);
1001 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
1004 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
1006 switch (msg->lm_magic) {
1007 case LUSTRE_MSG_MAGIC_V1:
1008 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1009 return ((struct lustre_msg_v1 *)msg)->lm_flags &
1011 case LUSTRE_MSG_MAGIC_V2:
1012 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1013 struct ptlrpc_body *pb;
1015 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1017 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1020 return pb->pb_flags;
1023 /* flags might be printed in debug code while message
1029 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
1031 switch (msg->lm_magic) {
1032 case LUSTRE_MSG_MAGIC_V1:
1033 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1034 MSG_GEN_FLAG_MASK & flags;
1036 case LUSTRE_MSG_MAGIC_V2: {
1037 struct ptlrpc_body *pb;
1039 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1040 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1041 pb->pb_flags |= flags;
1045 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1049 void lustre_msg_set_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 &= ~MSG_GEN_FLAG_MASK;
1054 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1055 MSG_GEN_FLAG_MASK & flags;
1057 case LUSTRE_MSG_MAGIC_V2: {
1058 struct ptlrpc_body *pb;
1060 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1061 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1062 pb->pb_flags = flags;
1066 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1070 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1072 switch (msg->lm_magic) {
1073 case LUSTRE_MSG_MAGIC_V1:
1074 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1075 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1076 ~(MSG_GEN_FLAG_MASK & flags);
1078 case LUSTRE_MSG_MAGIC_V2:
1079 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1080 struct ptlrpc_body *pb;
1082 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1083 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1084 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
1088 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1092 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1094 switch (msg->lm_magic) {
1095 case LUSTRE_MSG_MAGIC_V1:
1096 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1097 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1099 case LUSTRE_MSG_MAGIC_V2:
1100 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1101 struct ptlrpc_body *pb;
1103 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1105 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1108 return pb->pb_op_flags;
1115 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1117 switch (msg->lm_magic) {
1118 case LUSTRE_MSG_MAGIC_V1:
1119 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1120 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1122 case LUSTRE_MSG_MAGIC_V2: {
1123 struct ptlrpc_body *pb;
1125 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1126 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1127 pb->pb_op_flags |= flags;
1131 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1135 void lustre_msg_set_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 &= ~MSG_OP_FLAG_MASK;
1140 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1141 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1143 case LUSTRE_MSG_MAGIC_V2: {
1144 struct ptlrpc_body *pb;
1146 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1147 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1148 pb->pb_op_flags |= flags;
1152 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1156 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1158 switch (msg->lm_magic) {
1159 case LUSTRE_MSG_MAGIC_V1:
1160 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1161 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1162 case LUSTRE_MSG_MAGIC_V2:
1163 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1164 struct ptlrpc_body *pb;
1166 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1168 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1171 return &pb->pb_handle;
1174 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1179 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1181 switch (msg->lm_magic) {
1182 case LUSTRE_MSG_MAGIC_V1:
1183 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1184 return ((struct lustre_msg_v1 *)msg)->lm_type;
1185 case LUSTRE_MSG_MAGIC_V2:
1186 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1187 struct ptlrpc_body *pb;
1189 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1191 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1192 return PTL_RPC_MSG_ERR;
1197 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1198 return PTL_RPC_MSG_ERR;
1202 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1204 switch (msg->lm_magic) {
1205 case LUSTRE_MSG_MAGIC_V1:
1206 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1207 return ((struct lustre_msg_v1 *)msg)->lm_version;
1208 case LUSTRE_MSG_MAGIC_V2:
1209 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1210 struct ptlrpc_body *pb;
1212 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1214 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1217 return pb->pb_version;
1220 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1225 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1227 switch (msg->lm_magic) {
1228 case LUSTRE_MSG_MAGIC_V1:
1229 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1231 case LUSTRE_MSG_MAGIC_V2:
1232 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1233 struct ptlrpc_body *pb;
1235 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1236 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1237 pb->pb_version |= version;
1241 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1245 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1247 switch (msg->lm_magic) {
1248 case LUSTRE_MSG_MAGIC_V1:
1249 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1250 return ((struct lustre_msg_v1 *)msg)->lm_opc;
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));
1257 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1263 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1268 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1270 switch (msg->lm_magic) {
1271 case LUSTRE_MSG_MAGIC_V1:
1272 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1273 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1274 case LUSTRE_MSG_MAGIC_V2:
1275 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1276 struct ptlrpc_body *pb;
1278 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1280 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1283 return pb->pb_last_xid;
1286 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1291 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1293 switch (msg->lm_magic) {
1294 case LUSTRE_MSG_MAGIC_V1:
1295 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1296 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1297 case LUSTRE_MSG_MAGIC_V2:
1298 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1299 struct ptlrpc_body *pb;
1301 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1303 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1306 return pb->pb_last_committed;
1309 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1314 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1316 switch (msg->lm_magic) {
1317 case LUSTRE_MSG_MAGIC_V1:
1318 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1319 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1320 case LUSTRE_MSG_MAGIC_V2:
1321 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1322 struct ptlrpc_body *pb;
1324 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1326 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1329 return pb->pb_transno;
1332 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1337 int lustre_msg_get_status(struct lustre_msg *msg)
1339 switch (msg->lm_magic) {
1340 case LUSTRE_MSG_MAGIC_V1:
1341 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1342 return ((struct lustre_msg_v1 *)msg)->lm_status;
1343 case LUSTRE_MSG_MAGIC_V2:
1344 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1345 struct ptlrpc_body *pb;
1347 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1349 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1352 return pb->pb_status;
1355 /* status might be printed in debug code while message
1361 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1363 switch (msg->lm_magic) {
1364 case LUSTRE_MSG_MAGIC_V1:
1365 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1367 case LUSTRE_MSG_MAGIC_V2:
1368 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1369 struct ptlrpc_body *pb;
1371 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1373 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1379 CERROR("invalid msg magic %x\n", msg->lm_magic);
1385 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1387 switch (msg->lm_magic) {
1388 case LUSTRE_MSG_MAGIC_V1:
1389 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1391 case LUSTRE_MSG_MAGIC_V2:
1392 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1393 struct ptlrpc_body *pb;
1395 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1397 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1404 CERROR("invalid msg magic %x\n", msg->lm_magic);
1409 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1411 switch (msg->lm_magic) {
1412 case LUSTRE_MSG_MAGIC_V1:
1413 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1415 case LUSTRE_MSG_MAGIC_V2:
1416 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1417 struct ptlrpc_body *pb;
1419 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1421 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1424 return pb->pb_limit;
1427 CERROR("invalid msg magic %x\n", msg->lm_magic);
1433 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1435 switch (msg->lm_magic) {
1436 case LUSTRE_MSG_MAGIC_V1:
1437 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1439 case LUSTRE_MSG_MAGIC_V2:
1440 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1441 struct ptlrpc_body *pb;
1443 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1445 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1448 pb->pb_limit = limit;
1452 CERROR("invalid msg magic %x\n", msg->lm_magic);
1457 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1459 switch (msg->lm_magic) {
1460 case LUSTRE_MSG_MAGIC_V1:
1461 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1462 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1463 case LUSTRE_MSG_MAGIC_V2:
1464 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1465 struct ptlrpc_body *pb;
1467 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1469 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1472 return pb->pb_conn_cnt;
1475 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1480 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1482 switch (msg->lm_magic) {
1483 case LUSTRE_MSG_MAGIC_V1:
1484 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1485 case LUSTRE_MSG_MAGIC_V2:
1486 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1487 return msg->lm_magic;
1489 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1494 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1496 switch (msg->lm_magic) {
1497 case LUSTRE_MSG_MAGIC_V1:
1498 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1500 case LUSTRE_MSG_MAGIC_V2: {
1501 struct ptlrpc_body *pb;
1503 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1504 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1505 pb->pb_handle = *handle;
1509 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1513 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1515 switch (msg->lm_magic) {
1516 case LUSTRE_MSG_MAGIC_V1:
1517 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1519 case LUSTRE_MSG_MAGIC_V2: {
1520 struct ptlrpc_body *pb;
1522 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1523 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1528 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1532 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1534 switch (msg->lm_magic) {
1535 case LUSTRE_MSG_MAGIC_V1:
1536 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1538 case LUSTRE_MSG_MAGIC_V2: {
1539 struct ptlrpc_body *pb;
1541 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1542 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1547 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1551 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1553 switch (msg->lm_magic) {
1554 case LUSTRE_MSG_MAGIC_V1:
1555 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1557 case LUSTRE_MSG_MAGIC_V2: {
1558 struct ptlrpc_body *pb;
1560 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1561 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1562 pb->pb_last_xid = last_xid;
1566 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1570 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1572 switch (msg->lm_magic) {
1573 case LUSTRE_MSG_MAGIC_V1:
1574 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1576 case LUSTRE_MSG_MAGIC_V2: {
1577 struct ptlrpc_body *pb;
1579 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1580 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1581 pb->pb_last_committed = last_committed;
1585 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1589 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1591 switch (msg->lm_magic) {
1592 case LUSTRE_MSG_MAGIC_V1:
1593 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1595 case LUSTRE_MSG_MAGIC_V2: {
1596 struct ptlrpc_body *pb;
1598 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1599 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1600 pb->pb_transno = transno;
1604 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1608 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1610 switch (msg->lm_magic) {
1611 case LUSTRE_MSG_MAGIC_V1:
1612 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1614 case LUSTRE_MSG_MAGIC_V2: {
1615 struct ptlrpc_body *pb;
1617 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1618 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1619 pb->pb_status = status;
1623 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1627 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1629 switch (msg->lm_magic) {
1630 case LUSTRE_MSG_MAGIC_V1:
1631 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1633 case LUSTRE_MSG_MAGIC_V2: {
1634 struct ptlrpc_body *pb;
1636 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1637 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1638 pb->pb_conn_cnt = conn_cnt;
1642 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1646 /* byte flipping routines for all wire types declared in
1647 * lustre_idl.h implemented here.
1649 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1651 __swab32s (&b->pb_type);
1652 __swab32s (&b->pb_version);
1653 __swab32s (&b->pb_opc);
1654 __swab32s (&b->pb_status);
1655 __swab64s (&b->pb_last_xid);
1656 __swab64s (&b->pb_last_seen);
1657 __swab64s (&b->pb_last_committed);
1658 __swab64s (&b->pb_transno);
1659 __swab32s (&b->pb_flags);
1660 __swab32s (&b->pb_op_flags);
1661 __swab32s (&b->pb_conn_cnt);
1662 CLASSERT(offsetof(typeof(*b), pb_padding_1) != 0);
1663 CLASSERT(offsetof(typeof(*b), pb_padding_2) != 0);
1664 __swab32s (&b->pb_limit);
1665 __swab64s (&b->pb_slv);
1668 void lustre_swab_connect(struct obd_connect_data *ocd)
1670 __swab64s(&ocd->ocd_connect_flags);
1671 __swab32s(&ocd->ocd_version);
1672 __swab32s(&ocd->ocd_grant);
1673 __swab64s(&ocd->ocd_ibits_known);
1674 __swab32s(&ocd->ocd_index);
1675 __swab32s(&ocd->ocd_brw_size);
1676 __swab32s(&ocd->ocd_nllu);
1677 __swab32s(&ocd->ocd_nllg);
1678 __swab64s(&ocd->ocd_transno);
1679 __swab32s(&ocd->ocd_group);
1680 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1681 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1682 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1685 void lustre_swab_obdo (struct obdo *o)
1687 __swab64s (&o->o_valid);
1688 __swab64s (&o->o_id);
1689 __swab64s (&o->o_gr);
1690 __swab64s (&o->o_fid);
1691 __swab64s (&o->o_size);
1692 __swab64s (&o->o_mtime);
1693 __swab64s (&o->o_atime);
1694 __swab64s (&o->o_ctime);
1695 __swab64s (&o->o_blocks);
1696 __swab64s (&o->o_grant);
1697 __swab32s (&o->o_blksize);
1698 __swab32s (&o->o_mode);
1699 __swab32s (&o->o_uid);
1700 __swab32s (&o->o_gid);
1701 __swab32s (&o->o_flags);
1702 __swab32s (&o->o_nlink);
1703 __swab32s (&o->o_generation);
1704 __swab32s (&o->o_misc);
1705 __swab32s (&o->o_easize);
1706 __swab32s (&o->o_mds);
1707 __swab32s (&o->o_stripe_idx);
1708 __swab32s (&o->o_padding_1);
1709 /* o_inline is opaque */
1712 void lustre_swab_obd_statfs (struct obd_statfs *os)
1714 __swab64s (&os->os_type);
1715 __swab64s (&os->os_blocks);
1716 __swab64s (&os->os_bfree);
1717 __swab64s (&os->os_bavail);
1718 __swab64s (&os->os_files);
1719 __swab64s (&os->os_ffree);
1720 /* no need to swab os_fsid */
1721 __swab32s (&os->os_bsize);
1722 __swab32s (&os->os_namelen);
1723 __swab64s (&os->os_maxbytes);
1724 __swab32s (&os->os_state);
1725 /* no need to swap os_spare */
1728 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1730 __swab64s (&ioo->ioo_id);
1731 __swab64s (&ioo->ioo_gr);
1732 __swab32s (&ioo->ioo_type);
1733 __swab32s (&ioo->ioo_bufcnt);
1736 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1738 __swab64s (&nbr->offset);
1739 __swab32s (&nbr->len);
1740 __swab32s (&nbr->flags);
1743 void lustre_swab_ost_body (struct ost_body *b)
1745 lustre_swab_obdo (&b->oa);
1748 void lustre_swab_ost_last_id(obd_id *id)
1753 void lustre_swab_generic_32s(__u32 *val)
1758 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1760 __swab64s(&lvb->lvb_size);
1761 __swab64s(&lvb->lvb_mtime);
1762 __swab64s(&lvb->lvb_atime);
1763 __swab64s(&lvb->lvb_ctime);
1764 __swab64s(&lvb->lvb_blocks);
1767 void lustre_swab_mds_status_req (struct mds_status_req *r)
1769 __swab32s (&r->flags);
1770 __swab32s (&r->repbuf);
1773 void lustre_swab_mds_body (struct mds_body *b)
1775 lustre_swab_ll_fid (&b->fid1);
1776 lustre_swab_ll_fid (&b->fid2);
1777 /* handle is opaque */
1778 __swab64s (&b->valid);
1779 __swab64s (&b->size);
1780 __swab64s (&b->mtime);
1781 __swab64s (&b->atime);
1782 __swab64s (&b->ctime);
1783 __swab64s (&b->blocks);
1784 __swab64s (&b->io_epoch);
1785 __swab64s (&b->ino);
1786 __swab32s (&b->fsuid);
1787 __swab32s (&b->fsgid);
1788 __swab32s (&b->capability);
1789 __swab32s (&b->mode);
1790 __swab32s (&b->uid);
1791 __swab32s (&b->gid);
1792 __swab32s (&b->flags);
1793 __swab32s (&b->rdev);
1794 __swab32s (&b->nlink);
1795 __swab32s (&b->generation);
1796 __swab32s (&b->suppgid);
1797 __swab32s (&b->eadatasize);
1798 __swab32s (&b->aclsize);
1799 __swab32s (&b->max_mdsize);
1800 __swab32s (&b->max_cookiesize);
1801 __swab32s (&b->padding_4);
1804 void lustre_swab_mdt_body (struct mdt_body *b)
1806 lustre_swab_lu_fid (&b->fid1);
1807 lustre_swab_lu_fid (&b->fid2);
1808 /* handle is opaque */
1809 __swab64s (&b->valid);
1810 __swab64s (&b->size);
1811 __swab64s (&b->mtime);
1812 __swab64s (&b->atime);
1813 __swab64s (&b->ctime);
1814 __swab64s (&b->blocks);
1815 __swab64s (&b->ioepoch);
1816 __swab32s (&b->fsuid);
1817 __swab32s (&b->fsgid);
1818 __swab32s (&b->capability);
1819 __swab32s (&b->mode);
1820 __swab32s (&b->uid);
1821 __swab32s (&b->gid);
1822 __swab32s (&b->flags);
1823 __swab32s (&b->rdev);
1824 __swab32s (&b->nlink);
1825 __swab32s (&b->suppgid);
1826 __swab32s (&b->eadatasize);
1827 __swab32s (&b->aclsize);
1828 __swab32s (&b->max_mdsize);
1829 __swab32s (&b->max_cookiesize);
1832 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1834 /* handle is opaque */
1835 __swab64s (&b->ioepoch);
1836 __swab32s (&b->flags);
1837 CLASSERT(offsetof(typeof(*b), padding) != 0);
1840 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1843 __swab32s(&mti->mti_lustre_ver);
1844 __swab32s(&mti->mti_stripe_index);
1845 __swab32s(&mti->mti_config_ver);
1846 __swab32s(&mti->mti_flags);
1847 __swab32s(&mti->mti_nid_count);
1848 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1849 for (i = 0; i < MTI_NIDS_MAX; i++)
1850 __swab64s(&mti->mti_nids[i]);
1853 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1855 __swab64s (&i->dqi_bgrace);
1856 __swab64s (&i->dqi_igrace);
1857 __swab32s (&i->dqi_flags);
1858 __swab32s (&i->dqi_valid);
1861 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1863 __swab64s (&b->dqb_ihardlimit);
1864 __swab64s (&b->dqb_isoftlimit);
1865 __swab64s (&b->dqb_curinodes);
1866 __swab64s (&b->dqb_bhardlimit);
1867 __swab64s (&b->dqb_bsoftlimit);
1868 __swab64s (&b->dqb_curspace);
1869 __swab64s (&b->dqb_btime);
1870 __swab64s (&b->dqb_itime);
1871 __swab32s (&b->dqb_valid);
1872 CLASSERT(offsetof(typeof(*b), padding) != 0);
1875 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1877 __swab32s (&q->qc_cmd);
1878 __swab32s (&q->qc_type);
1879 __swab32s (&q->qc_id);
1880 __swab32s (&q->qc_stat);
1881 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1882 lustre_swab_obd_dqblk (&q->qc_dqblk);
1885 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1887 __swab32s (&p->rp_uid);
1888 __swab32s (&p->rp_gid);
1889 __swab32s (&p->rp_fsuid);
1890 __swab32s (&p->rp_fsgid);
1891 __swab32s (&p->rp_access_perm);
1894 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1896 __swab32s (&p->rp_uid);
1897 __swab32s (&p->rp_gid);
1898 __swab32s (&p->rp_fsuid);
1899 __swab32s (&p->rp_fsgid);
1900 __swab32s (&p->rp_access_perm);
1903 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1905 __swab32s (&sa->sa_opcode);
1906 __swab32s (&sa->sa_fsuid);
1907 __swab32s (&sa->sa_fsgid);
1908 __swab32s (&sa->sa_cap);
1909 __swab32s (&sa->sa_suppgid);
1910 __swab32s (&sa->sa_mode);
1911 lustre_swab_ll_fid (&sa->sa_fid);
1912 __swab64s (&sa->sa_valid);
1913 __swab64s (&sa->sa_size);
1914 __swab64s (&sa->sa_mtime);
1915 __swab64s (&sa->sa_atime);
1916 __swab64s (&sa->sa_ctime);
1917 __swab32s (&sa->sa_uid);
1918 __swab32s (&sa->sa_gid);
1919 __swab32s (&sa->sa_attr_flags);
1920 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1923 void lustre_swab_mdt_rec_setattr (struct mdt_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_lu_fid (&sa->sa_fid);
1932 __swab64s (&sa->sa_valid);
1933 __swab64s (&sa->sa_size);
1934 __swab64s (&sa->sa_blocks);
1935 __swab64s (&sa->sa_mtime);
1936 __swab64s (&sa->sa_atime);
1937 __swab64s (&sa->sa_ctime);
1938 __swab32s (&sa->sa_uid);
1939 __swab32s (&sa->sa_gid);
1940 __swab32s (&sa->sa_attr_flags);
1941 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1944 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1946 __swab64s(&jr->jr_headsize);
1947 lustre_swab_ll_fid(&jr->jr_fid);
1950 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1952 __swab64s(&jr->jr_headsize);
1953 lustre_swab_lu_fid(&jr->jr_fid);
1956 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1958 __swab32s (&cr->cr_opcode);
1959 __swab32s (&cr->cr_fsuid);
1960 __swab32s (&cr->cr_fsgid);
1961 __swab32s (&cr->cr_cap);
1962 __swab32s (&cr->cr_flags); /* for use with open */
1963 __swab32s (&cr->cr_mode);
1964 lustre_swab_ll_fid (&cr->cr_fid);
1965 lustre_swab_ll_fid (&cr->cr_replayfid);
1966 __swab64s (&cr->cr_time);
1967 __swab64s (&cr->cr_rdev);
1968 __swab32s (&cr->cr_suppgid);
1969 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1970 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1971 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1972 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1973 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1976 void lustre_swab_mdt_rec_create (struct mdt_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 /* handle is opaque */
1985 lustre_swab_lu_fid (&cr->cr_fid1);
1986 lustre_swab_lu_fid (&cr->cr_fid2);
1987 __swab64s (&cr->cr_time);
1988 __swab64s (&cr->cr_rdev);
1989 __swab64s (&cr->cr_ioepoch);
1990 __swab32s (&cr->cr_suppgid1);
1991 __swab32s (&cr->cr_suppgid2);
1992 __swab32s (&cr->cr_bias);
1993 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1996 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1998 __swab32s (&lk->lk_opcode);
1999 __swab32s (&lk->lk_fsuid);
2000 __swab32s (&lk->lk_fsgid);
2001 __swab32s (&lk->lk_cap);
2002 __swab32s (&lk->lk_suppgid1);
2003 __swab32s (&lk->lk_suppgid2);
2004 lustre_swab_ll_fid (&lk->lk_fid1);
2005 lustre_swab_ll_fid (&lk->lk_fid2);
2006 __swab64s (&lk->lk_time);
2007 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
2008 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2009 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2010 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2013 void lustre_swab_mdt_rec_link (struct mdt_rec_link *lk)
2015 __swab32s (&lk->lk_opcode);
2016 __swab32s (&lk->lk_fsuid);
2017 __swab32s (&lk->lk_fsgid);
2018 __swab32s (&lk->lk_cap);
2019 __swab32s (&lk->lk_suppgid1);
2020 __swab32s (&lk->lk_suppgid2);
2021 lustre_swab_lu_fid (&lk->lk_fid1);
2022 lustre_swab_lu_fid (&lk->lk_fid2);
2023 __swab64s (&lk->lk_time);
2024 __swab32s (&lk->lk_bias);
2025 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2026 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2027 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2030 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
2032 __swab32s (&ul->ul_opcode);
2033 __swab32s (&ul->ul_fsuid);
2034 __swab32s (&ul->ul_fsgid);
2035 __swab32s (&ul->ul_cap);
2036 __swab32s (&ul->ul_suppgid);
2037 __swab32s (&ul->ul_mode);
2038 lustre_swab_ll_fid (&ul->ul_fid1);
2039 lustre_swab_ll_fid (&ul->ul_fid2);
2040 __swab64s (&ul->ul_time);
2041 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
2042 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2043 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2044 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2047 void lustre_swab_mdt_rec_unlink (struct mdt_rec_unlink *ul)
2049 __swab32s (&ul->ul_opcode);
2050 __swab32s (&ul->ul_fsuid);
2051 __swab32s (&ul->ul_fsgid);
2052 __swab32s (&ul->ul_cap);
2053 __swab32s (&ul->ul_suppgid);
2054 __swab32s (&ul->ul_mode);
2055 lustre_swab_lu_fid (&ul->ul_fid1);
2056 lustre_swab_lu_fid (&ul->ul_fid2);
2057 __swab64s (&ul->ul_time);
2058 __swab32s (&ul->ul_bias);
2059 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2060 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2061 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2064 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
2066 __swab32s (&rn->rn_opcode);
2067 __swab32s (&rn->rn_fsuid);
2068 __swab32s (&rn->rn_fsgid);
2069 __swab32s (&rn->rn_cap);
2070 __swab32s (&rn->rn_suppgid1);
2071 __swab32s (&rn->rn_suppgid2);
2072 lustre_swab_ll_fid (&rn->rn_fid1);
2073 lustre_swab_ll_fid (&rn->rn_fid2);
2074 __swab64s (&rn->rn_time);
2075 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
2076 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
2077 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2078 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2081 void lustre_swab_mdt_rec_rename (struct mdt_rec_rename *rn)
2083 __swab32s (&rn->rn_opcode);
2084 __swab32s (&rn->rn_fsuid);
2085 __swab32s (&rn->rn_fsgid);
2086 __swab32s (&rn->rn_cap);
2087 __swab32s (&rn->rn_suppgid1);
2088 __swab32s (&rn->rn_suppgid2);
2089 lustre_swab_lu_fid (&rn->rn_fid1);
2090 lustre_swab_lu_fid (&rn->rn_fid2);
2091 __swab64s (&rn->rn_time);
2092 __swab32s (&rn->rn_mode);
2093 __swab32s (&rn->rn_bias);
2094 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2095 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2098 void lustre_swab_lov_desc (struct lov_desc *ld)
2100 __swab32s (&ld->ld_tgt_count);
2101 __swab32s (&ld->ld_active_tgt_count);
2102 __swab32s (&ld->ld_default_stripe_count);
2103 __swab64s (&ld->ld_default_stripe_size);
2104 __swab64s (&ld->ld_default_stripe_offset);
2105 __swab32s (&ld->ld_pattern);
2106 __swab32s (&ld->ld_qos_maxage);
2107 /* uuid endian insensitive */
2110 /*begin adding MDT by huanghua@clusterfs.com*/
2111 void lustre_swab_lmv_desc (struct lmv_desc *ld)
2113 __swab32s (&ld->ld_tgt_count);
2114 __swab32s (&ld->ld_active_tgt_count);
2115 /* uuid endian insensitive */
2117 /*end adding MDT by huanghua@clusterfs.com*/
2118 void lustre_swab_md_fld (struct md_fld *mf)
2120 __swab64s(&mf->mf_seq);
2121 __swab64s(&mf->mf_mds);
2124 static void print_lum (struct lov_user_md *lum)
2126 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
2127 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
2128 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2129 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
2130 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
2131 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2132 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2133 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
2136 void lustre_swab_lov_user_md(struct lov_user_md *lum)
2139 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2140 __swab32s(&lum->lmm_magic);
2141 __swab32s(&lum->lmm_pattern);
2142 __swab64s(&lum->lmm_object_id);
2143 __swab64s(&lum->lmm_object_gr);
2144 __swab32s(&lum->lmm_stripe_size);
2145 __swab16s(&lum->lmm_stripe_count);
2146 __swab16s(&lum->lmm_stripe_offset);
2151 static void print_lumj (struct lov_user_md_join *lumj)
2153 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2154 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2155 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2156 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2157 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2158 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2159 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2160 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2163 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2166 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2167 __swab32s(&lumj->lmm_magic);
2168 __swab32s(&lumj->lmm_pattern);
2169 __swab64s(&lumj->lmm_object_id);
2170 __swab64s(&lumj->lmm_object_gr);
2171 __swab32s(&lumj->lmm_stripe_size);
2172 __swab32s(&lumj->lmm_stripe_count);
2173 __swab32s(&lumj->lmm_extent_count);
2178 static void print_lum_objs(struct lov_user_md *lum)
2180 struct lov_user_ost_data *lod;
2183 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2185 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2186 for (i = 0; i < lum->lmm_stripe_count; i++) {
2187 lod = &lum->lmm_objects[i];
2188 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2189 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2190 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2191 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2196 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2198 struct lov_user_ost_data *lod;
2201 for (i = 0; i < lum->lmm_stripe_count; i++) {
2202 lod = &lum->lmm_objects[i];
2203 __swab64s(&lod->l_object_id);
2204 __swab64s(&lod->l_object_gr);
2205 __swab32s(&lod->l_ost_gen);
2206 __swab32s(&lod->l_ost_idx);
2208 print_lum_objs(lum);
2213 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2215 struct lov_ost_data *lod;
2218 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2219 lod = &lmm->lmm_objects[i];
2220 __swab64s(&lod->l_object_id);
2221 __swab64s(&lod->l_object_gr);
2222 __swab32s(&lod->l_ost_gen);
2223 __swab32s(&lod->l_ost_idx);
2225 __swab32s(&lmm->lmm_magic);
2226 __swab32s(&lmm->lmm_pattern);
2227 __swab64s(&lmm->lmm_object_id);
2228 __swab64s(&lmm->lmm_object_gr);
2229 __swab32s(&lmm->lmm_stripe_size);
2230 __swab32s(&lmm->lmm_stripe_count);
2236 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2240 for (i = 0; i < RES_NAME_SIZE; i++)
2241 __swab64s (&id->name[i]);
2244 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2246 /* the lock data is a union and the first two fields are always an
2247 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2248 * data the same way. */
2249 __swab64s(&d->l_extent.start);
2250 __swab64s(&d->l_extent.end);
2251 __swab64s(&d->l_extent.gid);
2252 __swab32s(&d->l_flock.pid);
2255 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2257 __swab64s (&i->opc);
2260 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2262 __swab32s (&r->lr_type);
2263 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2264 lustre_swab_ldlm_res_id (&r->lr_name);
2267 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2269 lustre_swab_ldlm_resource_desc (&l->l_resource);
2270 __swab32s (&l->l_req_mode);
2271 __swab32s (&l->l_granted_mode);
2272 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2275 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2277 __swab32s (&rq->lock_flags);
2278 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2279 __swab32s (&rq->lock_count);
2280 /* lock_handle[] opaque */
2283 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2285 __swab32s (&r->lock_flags);
2286 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2287 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2288 /* lock_handle opaque */
2289 __swab64s (&r->lock_policy_res1);
2290 __swab64s (&r->lock_policy_res2);
2293 /* no one calls this */
2294 int llog_log_swabbed(struct llog_log_hdr *hdr)
2296 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2298 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2303 void lustre_swab_qdata(struct qunit_data *d)
2305 __swab32s (&d->qd_id);
2306 __swab32s (&d->qd_flags);
2307 __swab64s (&d->qd_count);
2310 void lustre_swab_qdata_old(struct qunit_data_old *d)
2312 __swab32s (&d->qd_id);
2313 __swab32s (&d->qd_type);
2314 __swab32s (&d->qd_count);
2315 __swab32s (&d->qd_isblk);
2319 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2321 struct qunit_data_old tmp;
2322 struct qunit_data *ret;
2329 ret = (struct qunit_data *)d;
2330 ret->qd_id = tmp.qd_id;
2331 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2332 ret->qd_count = tmp.qd_count;
2336 EXPORT_SYMBOL(lustre_quota_old_to_new);
2338 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2340 struct qunit_data tmp;
2341 struct qunit_data_old *ret;
2348 ret = (struct qunit_data_old *)d;
2349 ret->qd_id = tmp.qd_id;
2350 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2351 ret->qd_count = (__u32)tmp.qd_count;
2352 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2355 EXPORT_SYMBOL(lustre_quota_new_to_old);
2356 #endif /* __KERNEL__ */
2358 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2360 LASSERT(req->rq_reqmsg);
2362 switch (req->rq_reqmsg->lm_magic) {
2363 case LUSTRE_MSG_MAGIC_V1:
2364 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2366 case LUSTRE_MSG_MAGIC_V2:
2367 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2368 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2370 CERROR("bad lustre msg magic: %#08X\n",
2371 req->rq_reqmsg->lm_magic);
2376 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2378 LASSERT(req->rq_repmsg);
2380 switch (req->rq_repmsg->lm_magic) {
2381 case LUSTRE_MSG_MAGIC_V1:
2382 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2384 case LUSTRE_MSG_MAGIC_V2:
2385 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2386 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2388 /* uninitialized yet */
2393 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2394 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2398 va_start(args, fmt);
2399 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2400 data->msg_fn, data->msg_line, fmt, args,
2401 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d lens"
2402 " %d/%d ref %d fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2403 req, req->rq_xid, req->rq_transno,
2404 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2405 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2406 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2408 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2410 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2412 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2413 (req->rq_import && req->rq_import->imp_client) ?
2414 req->rq_import->imp_client->cli_request_portal : -1,
2415 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2416 DEBUG_REQ_FLAGS(req),
2417 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2418 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2419 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2420 lustre_msg_get_flags(req->rq_repmsg) : -1,
2422 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2423 lustre_msg_get_status(req->rq_repmsg) : -1);
2425 EXPORT_SYMBOL(_debug_req);
2427 void lustre_swab_lustre_capa(struct lustre_capa *c)
2429 lustre_swab_lu_fid(&c->lc_fid);
2430 __swab64s (&c->lc_opc);
2431 __swab32s (&c->lc_uid);
2432 __swab32s (&c->lc_flags);
2433 __swab32s (&c->lc_keyid);
2434 __swab32s (&c->lc_timeout);
2435 __swab64s (&c->lc_expiry);
2438 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2440 __swab64s (&k->lk_mdsid);
2441 __swab32s (&k->lk_keyid);
2442 __swab32s (&k->lk_padding);