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,
390 int size[] = { sizeof(struct ptlrpc_body) };
398 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
400 switch (req->rq_reqmsg->lm_magic) {
401 case LUSTRE_MSG_MAGIC_V1:
402 case LUSTRE_MSG_MAGIC_V1_SWABBED:
403 return lustre_pack_reply_v1(req, count - 1, lens + 1,
404 bufs ? bufs + 1 : NULL);
405 case LUSTRE_MSG_MAGIC_V2:
406 case LUSTRE_MSG_MAGIC_V2_SWABBED:
407 return lustre_pack_reply_v2(req, count, lens, bufs);
409 LASSERTF(0, "incorrect message magic: %08x\n",
410 req->rq_reqmsg->lm_magic);
415 void *lustre_msg_buf_v1(void *msg, int n, int min_size)
417 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
418 int i, offset, buflen, bufcount;
423 bufcount = m->lm_bufcount;
424 if (unlikely(n >= bufcount)) {
425 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
430 buflen = m->lm_buflens[n];
431 if (unlikely(buflen < min_size)) {
432 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
433 m, n, buflen, min_size);
438 offset = lustre_msg_hdr_size_v1(bufcount);
439 for (i = 0; i < n; i++)
440 offset += size_round(m->lm_buflens[i]);
442 return (char *)m + offset;
445 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
447 int i, offset, buflen, bufcount;
452 bufcount = m->lm_bufcount;
453 if (unlikely(n >= bufcount)) {
454 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
459 buflen = m->lm_buflens[n];
460 if (unlikely(buflen < min_size)) {
461 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
462 m, n, buflen, min_size);
466 offset = lustre_msg_hdr_size_v2(bufcount);
467 for (i = 0; i < n; i++)
468 offset += size_round(m->lm_buflens[i]);
470 return (char *)m + offset;
473 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
475 switch (m->lm_magic) {
476 case LUSTRE_MSG_MAGIC_V1:
477 case LUSTRE_MSG_MAGIC_V1_SWABBED:
478 return lustre_msg_buf_v1(m, n - 1, min_size);
479 case LUSTRE_MSG_MAGIC_V2:
480 case LUSTRE_MSG_MAGIC_V2_SWABBED:
481 return lustre_msg_buf_v2(m, n, min_size);
483 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
488 int lustre_shrink_msg_v1(struct lustre_msg_v1 *msg, int segment,
489 unsigned int newlen, int move_data)
491 char *tail = NULL, *newpos;
495 LASSERT(segment >= 0);
496 LASSERT(msg->lm_bufcount > segment);
497 LASSERT(msg->lm_buflens[segment] >= newlen);
499 if (msg->lm_buflens[segment] == newlen)
502 if (move_data && msg->lm_bufcount > segment + 1) {
503 tail = lustre_msg_buf_v1(msg, segment + 1, 0);
504 for (n = segment + 1; n < msg->lm_bufcount; n++)
505 tail_len += size_round(msg->lm_buflens[n]);
508 msg->lm_buflens[segment] = newlen;
510 if (tail && tail_len) {
511 newpos = lustre_msg_buf_v1(msg, segment + 1, 0);
512 LASSERT(newpos <= tail);
514 memcpy(newpos, tail, tail_len);
517 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
518 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
519 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
520 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
524 return lustre_msg_size_v1(msg->lm_bufcount, msg->lm_buflens);
527 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
528 unsigned int newlen, int move_data)
530 char *tail = NULL, *newpos;
534 LASSERT(msg->lm_bufcount > segment);
535 LASSERT(msg->lm_buflens[segment] >= newlen);
537 if (msg->lm_buflens[segment] == newlen)
540 if (move_data && msg->lm_bufcount > segment + 1) {
541 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
542 for (n = segment + 1; n < msg->lm_bufcount; n++)
543 tail_len += size_round(msg->lm_buflens[n]);
546 msg->lm_buflens[segment] = newlen;
548 if (tail && tail_len) {
549 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
550 LASSERT(newpos <= tail);
552 memcpy(newpos, tail, tail_len);
555 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
556 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
557 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
558 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
562 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
566 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
567 * we also move data forward from @segment + 1.
569 * if @newlen == 0, we remove the segment completely, but we still keep the
570 * totally bufcount the same to save possible data moving. this will leave a
571 * unused segment with size 0 at the tail, but that's ok.
573 * return new msg size after shrinking.
576 * + if any buffers higher than @segment has been filled in, must call shrink
577 * with non-zero @move_data.
578 * + caller should NOT keep pointers to msg buffers which higher than @segment
581 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
582 unsigned int newlen, int move_data)
584 switch (msg->lm_magic) {
585 case LUSTRE_MSG_MAGIC_V1:
586 return lustre_shrink_msg_v1((struct lustre_msg_v1 *) msg,
587 segment - 1, newlen, move_data);
588 case LUSTRE_MSG_MAGIC_V2:
589 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
591 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
595 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
597 PTLRPC_RS_DEBUG_LRU_DEL(rs);
599 LASSERT (atomic_read(&rs->rs_refcount) == 0);
600 LASSERT (!rs->rs_difficult || rs->rs_handled);
601 LASSERT (!rs->rs_on_net);
602 LASSERT (!rs->rs_scheduled);
603 LASSERT (rs->rs_export == NULL);
604 LASSERT (rs->rs_nlocks == 0);
605 LASSERT (list_empty(&rs->rs_exp_list));
606 LASSERT (list_empty(&rs->rs_obd_list));
608 sptlrpc_svc_free_rs(rs);
611 int lustre_unpack_msg_v1(void *msg, int len)
613 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
614 int flipped, required_len, i;
617 /* Now we know the sender speaks my language. */
618 required_len = lustre_msg_hdr_size_v1(0);
619 if (len < required_len) {
620 /* can't even look inside the message */
621 CERROR("message length %d too small for lustre_msg\n", len);
625 flipped = lustre_msg_swabbed((struct lustre_msg *)m);
628 __swab32s(&m->lm_type);
629 __swab32s(&m->lm_version);
630 __swab32s(&m->lm_opc);
631 __swab64s(&m->lm_last_xid);
632 __swab64s(&m->lm_last_committed);
633 __swab64s(&m->lm_transno);
634 __swab32s(&m->lm_status);
635 __swab32s(&m->lm_flags);
636 __swab32s(&m->lm_conn_cnt);
637 __swab32s(&m->lm_bufcount);
640 if (m->lm_version != PTLRPC_MSG_VERSION) {
641 CERROR("wrong lustre_msg version %08x\n", m->lm_version);
645 required_len = lustre_msg_hdr_size_v1(m->lm_bufcount);
646 if (len < required_len) {
647 /* didn't receive all the buffer lengths */
648 CERROR("message length %d too small for %d buflens\n",
649 len, m->lm_bufcount);
653 for (i = 0; i < m->lm_bufcount; i++) {
655 __swab32s (&m->lm_buflens[i]);
656 required_len += size_round(m->lm_buflens[i]);
659 if (len < required_len) {
660 CERROR("len: %d, required_len %d\n", len, required_len);
661 CERROR("bufcount: %d\n", m->lm_bufcount);
662 for (i = 0; i < m->lm_bufcount; i++)
663 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
670 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
672 int flipped, required_len, i;
674 /* Now we know the sender speaks my language. */
675 required_len = lustre_msg_hdr_size_v2(0);
676 if (len < required_len) {
677 /* can't even look inside the message */
678 CERROR("message length %d too small for lustre_msg\n", len);
682 flipped = lustre_msg_swabbed(m);
685 __swab32s(&m->lm_bufcount);
686 __swab32s(&m->lm_secflvr);
687 __swab32s(&m->lm_repsize);
688 __swab32s(&m->lm_timeout);
689 CLASSERT(offsetof(typeof(*m), lm_padding_1) != 0);
690 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
691 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
694 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
695 if (len < required_len) {
696 /* didn't receive all the buffer lengths */
697 CERROR ("message length %d too small for %d buflens\n",
698 len, m->lm_bufcount);
702 for (i = 0; i < m->lm_bufcount; i++) {
704 __swab32s(&m->lm_buflens[i]);
705 required_len += size_round(m->lm_buflens[i]);
708 if (len < required_len) {
709 CERROR("len: %d, required_len %d\n", len, required_len);
710 CERROR("bufcount: %d\n", m->lm_bufcount);
711 for (i = 0; i < m->lm_bufcount; i++)
712 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
719 int lustre_unpack_msg(struct lustre_msg *m, int len)
721 int required_len, rc;
724 /* We can provide a slightly better error log, if we check the
725 * message magic and version first. In the future, struct
726 * lustre_msg may grow, and we'd like to log a version mismatch,
727 * rather than a short message.
730 required_len = offsetof(struct lustre_msg, lm_magic) +
732 if (len < required_len) {
733 /* can't even look inside the message */
734 CERROR("message length %d too small for magic/version check\n",
739 switch (m->lm_magic) {
740 case LUSTRE_MSG_MAGIC_V1:
741 case LUSTRE_MSG_MAGIC_V1_SWABBED:
742 rc = lustre_unpack_msg_v1(m, len);
744 case LUSTRE_MSG_MAGIC_V2:
745 case LUSTRE_MSG_MAGIC_V2_SWABBED:
746 rc = lustre_unpack_msg_v2(m, len);
749 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
756 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
759 struct ptlrpc_body *pb;
761 pb = lustre_swab_buf(m, offset, sizeof(*pb), lustre_swab_ptlrpc_body);
763 CERROR("error unpacking ptlrpc body");
767 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
768 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
775 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
777 switch (req->rq_reqmsg->lm_magic) {
778 case LUSTRE_MSG_MAGIC_V1:
779 case LUSTRE_MSG_MAGIC_V1_SWABBED:
781 case LUSTRE_MSG_MAGIC_V2:
782 case LUSTRE_MSG_MAGIC_V2_SWABBED:
783 lustre_set_req_swabbed(req, offset);
784 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
786 CERROR("bad lustre msg magic: %#08X\n",
787 req->rq_reqmsg->lm_magic);
792 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
794 switch (req->rq_repmsg->lm_magic) {
795 case LUSTRE_MSG_MAGIC_V1:
796 case LUSTRE_MSG_MAGIC_V1_SWABBED:
798 case LUSTRE_MSG_MAGIC_V2:
799 case LUSTRE_MSG_MAGIC_V2_SWABBED:
800 lustre_set_rep_swabbed(req, offset);
801 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
803 CERROR("bad lustre msg magic: %#08X\n",
804 req->rq_repmsg->lm_magic);
809 static inline int lustre_msg_buflen_v1(void *msg, int n)
811 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
814 if (n >= m->lm_bufcount)
817 return m->lm_buflens[n];
820 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
822 if (n >= m->lm_bufcount)
825 return m->lm_buflens[n];
829 * lustre_msg_buflen - return the length of buffer @n in message @m
830 * @m - lustre_msg (request or reply) to look at
831 * @n - message index (base 0)
833 * returns zero for non-existent message indices
835 int lustre_msg_buflen(struct lustre_msg *m, int n)
837 switch (m->lm_magic) {
838 case LUSTRE_MSG_MAGIC_V1:
839 case LUSTRE_MSG_MAGIC_V1_SWABBED:
840 return lustre_msg_buflen_v1(m, n - 1);
841 case LUSTRE_MSG_MAGIC_V2:
842 case LUSTRE_MSG_MAGIC_V2_SWABBED:
843 return lustre_msg_buflen_v2(m, n);
845 CERROR("incorrect message magic: %08x\n", m->lm_magic);
849 EXPORT_SYMBOL(lustre_msg_buflen);
851 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
853 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
856 if (n >= m->lm_bufcount)
859 m->lm_buflens[n] = len;
863 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
865 if (n >= m->lm_bufcount)
868 m->lm_buflens[n] = len;
871 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
873 switch (m->lm_magic) {
874 case LUSTRE_MSG_MAGIC_V1:
875 lustre_msg_set_buflen_v1(m, n - 1, len);
877 case LUSTRE_MSG_MAGIC_V2:
878 lustre_msg_set_buflen_v2(m, n, len);
881 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
885 EXPORT_SYMBOL(lustre_msg_set_buflen);
887 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
888 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
889 int lustre_msg_bufcount(struct lustre_msg *m)
891 switch (m->lm_magic) {
892 case LUSTRE_MSG_MAGIC_V1:
893 case LUSTRE_MSG_MAGIC_V1_SWABBED:
894 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
895 case LUSTRE_MSG_MAGIC_V2:
896 case LUSTRE_MSG_MAGIC_V2_SWABBED:
897 return m->lm_bufcount;
899 CERROR("incorrect message magic: %08x\n", m->lm_magic);
903 EXPORT_SYMBOL(lustre_msg_bufcount);
905 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
907 /* max_len == 0 means the string should fill the buffer */
911 switch (m->lm_magic) {
912 case LUSTRE_MSG_MAGIC_V1:
913 case LUSTRE_MSG_MAGIC_V1_SWABBED:
914 str = lustre_msg_buf_v1(m, index - 1, 0);
915 blen = lustre_msg_buflen_v1(m, index - 1);
917 case LUSTRE_MSG_MAGIC_V2:
918 case LUSTRE_MSG_MAGIC_V2_SWABBED:
919 str = lustre_msg_buf_v2(m, index, 0);
920 blen = lustre_msg_buflen_v2(m, index);
923 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
927 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
931 slen = strnlen(str, blen);
933 if (slen == blen) { /* not NULL terminated */
934 CERROR("can't unpack non-NULL terminated string in "
935 "msg %p buffer[%d] len %d\n", m, index, blen);
940 if (slen != blen - 1) {
941 CERROR("can't unpack short string in msg %p "
942 "buffer[%d] len %d: strlen %d\n",
943 m, index, blen, slen);
946 } else if (slen > max_len) {
947 CERROR("can't unpack oversized string in msg %p "
948 "buffer[%d] len %d strlen %d: max %d expected\n",
949 m, index, blen, slen, max_len);
956 /* Wrap up the normal fixed length cases */
957 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
962 switch (msg->lm_magic) {
963 case LUSTRE_MSG_MAGIC_V1:
964 case LUSTRE_MSG_MAGIC_V1_SWABBED:
965 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
967 case LUSTRE_MSG_MAGIC_V2:
968 case LUSTRE_MSG_MAGIC_V2_SWABBED:
969 ptr = lustre_msg_buf_v2(msg, index, min_size);
972 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
977 if (swabber != NULL && lustre_msg_swabbed(msg))
978 ((void (*)(void *))swabber)(ptr);
983 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
986 lustre_set_req_swabbed(req, index);
987 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
990 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
993 lustre_set_rep_swabbed(req, index);
994 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
997 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
999 switch (msg->lm_magic) {
1000 case LUSTRE_MSG_MAGIC_V1:
1001 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1002 return ((struct lustre_msg_v1 *)msg)->lm_flags &
1004 case LUSTRE_MSG_MAGIC_V2:
1005 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1006 struct ptlrpc_body *pb;
1008 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1010 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1013 return pb->pb_flags;
1016 /* flags might be printed in debug code while message
1022 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
1024 switch (msg->lm_magic) {
1025 case LUSTRE_MSG_MAGIC_V1:
1026 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1027 MSG_GEN_FLAG_MASK & flags;
1029 case LUSTRE_MSG_MAGIC_V2: {
1030 struct ptlrpc_body *pb;
1032 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1033 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1034 pb->pb_flags |= flags;
1038 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1042 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
1044 switch (msg->lm_magic) {
1045 case LUSTRE_MSG_MAGIC_V1:
1046 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK;
1047 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1048 MSG_GEN_FLAG_MASK & flags;
1050 case LUSTRE_MSG_MAGIC_V2: {
1051 struct ptlrpc_body *pb;
1053 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1054 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1055 pb->pb_flags = flags;
1059 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1063 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1065 switch (msg->lm_magic) {
1066 case LUSTRE_MSG_MAGIC_V1:
1067 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1068 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1069 ~(MSG_GEN_FLAG_MASK & flags);
1071 case LUSTRE_MSG_MAGIC_V2:
1072 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1073 struct ptlrpc_body *pb;
1075 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1076 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1077 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
1081 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1085 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1087 switch (msg->lm_magic) {
1088 case LUSTRE_MSG_MAGIC_V1:
1089 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1090 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1092 case LUSTRE_MSG_MAGIC_V2:
1093 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1094 struct ptlrpc_body *pb;
1096 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1098 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1101 return pb->pb_op_flags;
1108 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1110 switch (msg->lm_magic) {
1111 case LUSTRE_MSG_MAGIC_V1:
1112 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1113 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1115 case LUSTRE_MSG_MAGIC_V2: {
1116 struct ptlrpc_body *pb;
1118 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1119 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1120 pb->pb_op_flags |= flags;
1124 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1128 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
1130 switch (msg->lm_magic) {
1131 case LUSTRE_MSG_MAGIC_V1:
1132 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK;
1133 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1134 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1136 case LUSTRE_MSG_MAGIC_V2: {
1137 struct ptlrpc_body *pb;
1139 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1140 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1141 pb->pb_op_flags |= flags;
1145 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1149 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1151 switch (msg->lm_magic) {
1152 case LUSTRE_MSG_MAGIC_V1:
1153 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1154 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1155 case LUSTRE_MSG_MAGIC_V2:
1156 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1157 struct ptlrpc_body *pb;
1159 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1161 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1164 return &pb->pb_handle;
1167 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1172 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1174 switch (msg->lm_magic) {
1175 case LUSTRE_MSG_MAGIC_V1:
1176 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1177 return ((struct lustre_msg_v1 *)msg)->lm_type;
1178 case LUSTRE_MSG_MAGIC_V2:
1179 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1180 struct ptlrpc_body *pb;
1182 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1184 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1185 return PTL_RPC_MSG_ERR;
1190 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1191 return PTL_RPC_MSG_ERR;
1195 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1197 switch (msg->lm_magic) {
1198 case LUSTRE_MSG_MAGIC_V1:
1199 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1200 return ((struct lustre_msg_v1 *)msg)->lm_version;
1201 case LUSTRE_MSG_MAGIC_V2:
1202 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1203 struct ptlrpc_body *pb;
1205 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1207 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1210 return pb->pb_version;
1213 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1218 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1220 switch (msg->lm_magic) {
1221 case LUSTRE_MSG_MAGIC_V1:
1222 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1224 case LUSTRE_MSG_MAGIC_V2:
1225 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1226 struct ptlrpc_body *pb;
1228 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1229 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1230 pb->pb_version |= version;
1234 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1238 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1240 switch (msg->lm_magic) {
1241 case LUSTRE_MSG_MAGIC_V1:
1242 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1243 return ((struct lustre_msg_v1 *)msg)->lm_opc;
1244 case LUSTRE_MSG_MAGIC_V2:
1245 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1246 struct ptlrpc_body *pb;
1248 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1250 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1256 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1261 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1263 switch (msg->lm_magic) {
1264 case LUSTRE_MSG_MAGIC_V1:
1265 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1266 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1267 case LUSTRE_MSG_MAGIC_V2:
1268 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1269 struct ptlrpc_body *pb;
1271 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1273 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1276 return pb->pb_last_xid;
1279 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1284 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1286 switch (msg->lm_magic) {
1287 case LUSTRE_MSG_MAGIC_V1:
1288 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1289 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1290 case LUSTRE_MSG_MAGIC_V2:
1291 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1292 struct ptlrpc_body *pb;
1294 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1296 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1299 return pb->pb_last_committed;
1302 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1307 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1309 switch (msg->lm_magic) {
1310 case LUSTRE_MSG_MAGIC_V1:
1311 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1312 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1313 case LUSTRE_MSG_MAGIC_V2:
1314 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1315 struct ptlrpc_body *pb;
1317 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1319 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1322 return pb->pb_transno;
1325 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1330 int lustre_msg_get_status(struct lustre_msg *msg)
1332 switch (msg->lm_magic) {
1333 case LUSTRE_MSG_MAGIC_V1:
1334 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1335 return ((struct lustre_msg_v1 *)msg)->lm_status;
1336 case LUSTRE_MSG_MAGIC_V2:
1337 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1338 struct ptlrpc_body *pb;
1340 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1342 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1345 return pb->pb_status;
1348 /* status might be printed in debug code while message
1354 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1356 switch (msg->lm_magic) {
1357 case LUSTRE_MSG_MAGIC_V1:
1358 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1360 case LUSTRE_MSG_MAGIC_V2:
1361 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1362 struct ptlrpc_body *pb;
1364 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1366 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1372 CERROR("invalid msg magic %x\n", msg->lm_magic);
1378 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1380 switch (msg->lm_magic) {
1381 case LUSTRE_MSG_MAGIC_V1:
1382 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1384 case LUSTRE_MSG_MAGIC_V2:
1385 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1386 struct ptlrpc_body *pb;
1388 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1390 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1397 CERROR("invalid msg magic %x\n", msg->lm_magic);
1402 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1404 switch (msg->lm_magic) {
1405 case LUSTRE_MSG_MAGIC_V1:
1406 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1408 case LUSTRE_MSG_MAGIC_V2:
1409 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1410 struct ptlrpc_body *pb;
1412 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1414 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1417 return pb->pb_limit;
1420 CERROR("invalid msg magic %x\n", msg->lm_magic);
1426 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1428 switch (msg->lm_magic) {
1429 case LUSTRE_MSG_MAGIC_V1:
1430 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1432 case LUSTRE_MSG_MAGIC_V2:
1433 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1434 struct ptlrpc_body *pb;
1436 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1438 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1441 pb->pb_limit = limit;
1445 CERROR("invalid msg magic %x\n", msg->lm_magic);
1450 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1452 switch (msg->lm_magic) {
1453 case LUSTRE_MSG_MAGIC_V1:
1454 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1455 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1456 case LUSTRE_MSG_MAGIC_V2:
1457 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1458 struct ptlrpc_body *pb;
1460 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1462 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1465 return pb->pb_conn_cnt;
1468 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1473 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1475 switch (msg->lm_magic) {
1476 case LUSTRE_MSG_MAGIC_V1:
1477 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1478 case LUSTRE_MSG_MAGIC_V2:
1479 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1480 return msg->lm_magic;
1482 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1487 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1489 switch (msg->lm_magic) {
1490 case LUSTRE_MSG_MAGIC_V1:
1491 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1493 case LUSTRE_MSG_MAGIC_V2: {
1494 struct ptlrpc_body *pb;
1496 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1497 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1498 pb->pb_handle = *handle;
1502 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1506 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1508 switch (msg->lm_magic) {
1509 case LUSTRE_MSG_MAGIC_V1:
1510 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1512 case LUSTRE_MSG_MAGIC_V2: {
1513 struct ptlrpc_body *pb;
1515 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1516 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1521 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1525 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1527 switch (msg->lm_magic) {
1528 case LUSTRE_MSG_MAGIC_V1:
1529 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1531 case LUSTRE_MSG_MAGIC_V2: {
1532 struct ptlrpc_body *pb;
1534 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1535 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1540 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1544 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1546 switch (msg->lm_magic) {
1547 case LUSTRE_MSG_MAGIC_V1:
1548 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1550 case LUSTRE_MSG_MAGIC_V2: {
1551 struct ptlrpc_body *pb;
1553 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1554 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1555 pb->pb_last_xid = last_xid;
1559 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1563 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1565 switch (msg->lm_magic) {
1566 case LUSTRE_MSG_MAGIC_V1:
1567 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1569 case LUSTRE_MSG_MAGIC_V2: {
1570 struct ptlrpc_body *pb;
1572 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1573 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1574 pb->pb_last_committed = last_committed;
1578 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1582 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1584 switch (msg->lm_magic) {
1585 case LUSTRE_MSG_MAGIC_V1:
1586 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1588 case LUSTRE_MSG_MAGIC_V2: {
1589 struct ptlrpc_body *pb;
1591 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1592 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1593 pb->pb_transno = transno;
1597 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1601 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1603 switch (msg->lm_magic) {
1604 case LUSTRE_MSG_MAGIC_V1:
1605 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1607 case LUSTRE_MSG_MAGIC_V2: {
1608 struct ptlrpc_body *pb;
1610 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1611 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1612 pb->pb_status = status;
1616 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1620 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1622 switch (msg->lm_magic) {
1623 case LUSTRE_MSG_MAGIC_V1:
1624 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1626 case LUSTRE_MSG_MAGIC_V2: {
1627 struct ptlrpc_body *pb;
1629 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1630 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1631 pb->pb_conn_cnt = conn_cnt;
1635 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1639 /* byte flipping routines for all wire types declared in
1640 * lustre_idl.h implemented here.
1642 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1644 __swab32s (&b->pb_type);
1645 __swab32s (&b->pb_version);
1646 __swab32s (&b->pb_opc);
1647 __swab32s (&b->pb_status);
1648 __swab64s (&b->pb_last_xid);
1649 __swab64s (&b->pb_last_seen);
1650 __swab64s (&b->pb_last_committed);
1651 __swab64s (&b->pb_transno);
1652 __swab32s (&b->pb_flags);
1653 __swab32s (&b->pb_op_flags);
1654 __swab32s (&b->pb_conn_cnt);
1655 CLASSERT(offsetof(typeof(*b), pb_padding_1) != 0);
1656 CLASSERT(offsetof(typeof(*b), pb_padding_2) != 0);
1657 __swab32s (&b->pb_limit);
1658 __swab64s (&b->pb_slv);
1661 void lustre_swab_connect(struct obd_connect_data *ocd)
1663 __swab64s(&ocd->ocd_connect_flags);
1664 __swab32s(&ocd->ocd_version);
1665 __swab32s(&ocd->ocd_grant);
1666 __swab64s(&ocd->ocd_ibits_known);
1667 __swab32s(&ocd->ocd_index);
1668 __swab32s(&ocd->ocd_brw_size);
1669 __swab32s(&ocd->ocd_nllu);
1670 __swab32s(&ocd->ocd_nllg);
1671 __swab64s(&ocd->ocd_transno);
1672 __swab32s(&ocd->ocd_group);
1673 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1674 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1675 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1678 void lustre_swab_obdo (struct obdo *o)
1680 __swab64s (&o->o_valid);
1681 __swab64s (&o->o_id);
1682 __swab64s (&o->o_gr);
1683 __swab64s (&o->o_fid);
1684 __swab64s (&o->o_size);
1685 __swab64s (&o->o_mtime);
1686 __swab64s (&o->o_atime);
1687 __swab64s (&o->o_ctime);
1688 __swab64s (&o->o_blocks);
1689 __swab64s (&o->o_grant);
1690 __swab32s (&o->o_blksize);
1691 __swab32s (&o->o_mode);
1692 __swab32s (&o->o_uid);
1693 __swab32s (&o->o_gid);
1694 __swab32s (&o->o_flags);
1695 __swab32s (&o->o_nlink);
1696 __swab32s (&o->o_generation);
1697 __swab32s (&o->o_misc);
1698 __swab32s (&o->o_easize);
1699 __swab32s (&o->o_mds);
1700 __swab32s (&o->o_stripe_idx);
1701 __swab32s (&o->o_padding_1);
1702 /* o_inline is opaque */
1705 void lustre_swab_obd_statfs (struct obd_statfs *os)
1707 __swab64s (&os->os_type);
1708 __swab64s (&os->os_blocks);
1709 __swab64s (&os->os_bfree);
1710 __swab64s (&os->os_bavail);
1711 __swab64s (&os->os_files);
1712 __swab64s (&os->os_ffree);
1713 /* no need to swab os_fsid */
1714 __swab32s (&os->os_bsize);
1715 __swab32s (&os->os_namelen);
1716 __swab64s (&os->os_maxbytes);
1717 __swab32s (&os->os_state);
1718 /* no need to swap os_spare */
1721 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1723 __swab64s (&ioo->ioo_id);
1724 __swab64s (&ioo->ioo_gr);
1725 __swab32s (&ioo->ioo_type);
1726 __swab32s (&ioo->ioo_bufcnt);
1729 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1731 __swab64s (&nbr->offset);
1732 __swab32s (&nbr->len);
1733 __swab32s (&nbr->flags);
1736 void lustre_swab_ost_body (struct ost_body *b)
1738 lustre_swab_obdo (&b->oa);
1741 void lustre_swab_ost_last_id(obd_id *id)
1746 void lustre_swab_generic_32s(__u32 *val)
1751 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1753 __swab64s(&lvb->lvb_size);
1754 __swab64s(&lvb->lvb_mtime);
1755 __swab64s(&lvb->lvb_atime);
1756 __swab64s(&lvb->lvb_ctime);
1757 __swab64s(&lvb->lvb_blocks);
1760 void lustre_swab_mds_status_req (struct mds_status_req *r)
1762 __swab32s (&r->flags);
1763 __swab32s (&r->repbuf);
1766 void lustre_swab_mds_body (struct mds_body *b)
1768 lustre_swab_ll_fid (&b->fid1);
1769 lustre_swab_ll_fid (&b->fid2);
1770 /* handle is opaque */
1771 __swab64s (&b->valid);
1772 __swab64s (&b->size);
1773 __swab64s (&b->mtime);
1774 __swab64s (&b->atime);
1775 __swab64s (&b->ctime);
1776 __swab64s (&b->blocks);
1777 __swab64s (&b->io_epoch);
1778 __swab64s (&b->ino);
1779 __swab32s (&b->fsuid);
1780 __swab32s (&b->fsgid);
1781 __swab32s (&b->capability);
1782 __swab32s (&b->mode);
1783 __swab32s (&b->uid);
1784 __swab32s (&b->gid);
1785 __swab32s (&b->flags);
1786 __swab32s (&b->rdev);
1787 __swab32s (&b->nlink);
1788 __swab32s (&b->generation);
1789 __swab32s (&b->suppgid);
1790 __swab32s (&b->eadatasize);
1791 __swab32s (&b->aclsize);
1792 __swab32s (&b->max_mdsize);
1793 __swab32s (&b->max_cookiesize);
1794 __swab32s (&b->padding_4);
1797 void lustre_swab_mdt_body (struct mdt_body *b)
1799 lustre_swab_lu_fid (&b->fid1);
1800 lustre_swab_lu_fid (&b->fid2);
1801 /* handle is opaque */
1802 __swab64s (&b->valid);
1803 __swab64s (&b->size);
1804 __swab64s (&b->mtime);
1805 __swab64s (&b->atime);
1806 __swab64s (&b->ctime);
1807 __swab64s (&b->blocks);
1808 __swab64s (&b->ioepoch);
1809 __swab32s (&b->fsuid);
1810 __swab32s (&b->fsgid);
1811 __swab32s (&b->capability);
1812 __swab32s (&b->mode);
1813 __swab32s (&b->uid);
1814 __swab32s (&b->gid);
1815 __swab32s (&b->flags);
1816 __swab32s (&b->rdev);
1817 __swab32s (&b->nlink);
1818 __swab32s (&b->suppgid);
1819 __swab32s (&b->eadatasize);
1820 __swab32s (&b->aclsize);
1821 __swab32s (&b->max_mdsize);
1822 __swab32s (&b->max_cookiesize);
1825 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1827 /* handle is opaque */
1828 __swab64s (&b->ioepoch);
1829 __swab32s (&b->flags);
1830 CLASSERT(offsetof(typeof(*b), padding) != 0);
1833 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1836 __swab32s(&mti->mti_lustre_ver);
1837 __swab32s(&mti->mti_stripe_index);
1838 __swab32s(&mti->mti_config_ver);
1839 __swab32s(&mti->mti_flags);
1840 __swab32s(&mti->mti_nid_count);
1841 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1842 for (i = 0; i < MTI_NIDS_MAX; i++)
1843 __swab64s(&mti->mti_nids[i]);
1846 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1848 __swab64s (&i->dqi_bgrace);
1849 __swab64s (&i->dqi_igrace);
1850 __swab32s (&i->dqi_flags);
1851 __swab32s (&i->dqi_valid);
1854 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1856 __swab64s (&b->dqb_ihardlimit);
1857 __swab64s (&b->dqb_isoftlimit);
1858 __swab64s (&b->dqb_curinodes);
1859 __swab64s (&b->dqb_bhardlimit);
1860 __swab64s (&b->dqb_bsoftlimit);
1861 __swab64s (&b->dqb_curspace);
1862 __swab64s (&b->dqb_btime);
1863 __swab64s (&b->dqb_itime);
1864 __swab32s (&b->dqb_valid);
1865 CLASSERT(offsetof(typeof(*b), padding) != 0);
1868 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1870 __swab32s (&q->qc_cmd);
1871 __swab32s (&q->qc_type);
1872 __swab32s (&q->qc_id);
1873 __swab32s (&q->qc_stat);
1874 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1875 lustre_swab_obd_dqblk (&q->qc_dqblk);
1878 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1880 __swab32s (&p->rp_uid);
1881 __swab32s (&p->rp_gid);
1882 __swab32s (&p->rp_fsuid);
1883 __swab32s (&p->rp_fsgid);
1884 __swab32s (&p->rp_access_perm);
1887 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1889 __swab32s (&p->rp_uid);
1890 __swab32s (&p->rp_gid);
1891 __swab32s (&p->rp_fsuid);
1892 __swab32s (&p->rp_fsgid);
1893 __swab32s (&p->rp_access_perm);
1896 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1898 __swab32s (&sa->sa_opcode);
1899 __swab32s (&sa->sa_fsuid);
1900 __swab32s (&sa->sa_fsgid);
1901 __swab32s (&sa->sa_cap);
1902 __swab32s (&sa->sa_suppgid);
1903 __swab32s (&sa->sa_mode);
1904 lustre_swab_ll_fid (&sa->sa_fid);
1905 __swab64s (&sa->sa_valid);
1906 __swab64s (&sa->sa_size);
1907 __swab64s (&sa->sa_mtime);
1908 __swab64s (&sa->sa_atime);
1909 __swab64s (&sa->sa_ctime);
1910 __swab32s (&sa->sa_uid);
1911 __swab32s (&sa->sa_gid);
1912 __swab32s (&sa->sa_attr_flags);
1913 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1916 void lustre_swab_mdt_rec_setattr (struct mdt_rec_setattr *sa)
1918 __swab32s (&sa->sa_opcode);
1919 __swab32s (&sa->sa_fsuid);
1920 __swab32s (&sa->sa_fsgid);
1921 __swab32s (&sa->sa_cap);
1922 __swab32s (&sa->sa_suppgid);
1923 __swab32s (&sa->sa_mode);
1924 lustre_swab_lu_fid (&sa->sa_fid);
1925 __swab64s (&sa->sa_valid);
1926 __swab64s (&sa->sa_size);
1927 __swab64s (&sa->sa_blocks);
1928 __swab64s (&sa->sa_mtime);
1929 __swab64s (&sa->sa_atime);
1930 __swab64s (&sa->sa_ctime);
1931 __swab32s (&sa->sa_uid);
1932 __swab32s (&sa->sa_gid);
1933 __swab32s (&sa->sa_attr_flags);
1934 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1937 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1939 __swab64s(&jr->jr_headsize);
1940 lustre_swab_ll_fid(&jr->jr_fid);
1943 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1945 __swab64s(&jr->jr_headsize);
1946 lustre_swab_lu_fid(&jr->jr_fid);
1949 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1951 __swab32s (&cr->cr_opcode);
1952 __swab32s (&cr->cr_fsuid);
1953 __swab32s (&cr->cr_fsgid);
1954 __swab32s (&cr->cr_cap);
1955 __swab32s (&cr->cr_flags); /* for use with open */
1956 __swab32s (&cr->cr_mode);
1957 lustre_swab_ll_fid (&cr->cr_fid);
1958 lustre_swab_ll_fid (&cr->cr_replayfid);
1959 __swab64s (&cr->cr_time);
1960 __swab64s (&cr->cr_rdev);
1961 __swab32s (&cr->cr_suppgid);
1962 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1963 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1964 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1965 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1966 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1969 void lustre_swab_mdt_rec_create (struct mdt_rec_create *cr)
1971 __swab32s (&cr->cr_opcode);
1972 __swab32s (&cr->cr_fsuid);
1973 __swab32s (&cr->cr_fsgid);
1974 __swab32s (&cr->cr_cap);
1975 __swab32s (&cr->cr_flags); /* for use with open */
1976 __swab32s (&cr->cr_mode);
1977 /* handle is opaque */
1978 lustre_swab_lu_fid (&cr->cr_fid1);
1979 lustre_swab_lu_fid (&cr->cr_fid2);
1980 __swab64s (&cr->cr_time);
1981 __swab64s (&cr->cr_rdev);
1982 __swab64s (&cr->cr_ioepoch);
1983 __swab32s (&cr->cr_suppgid1);
1984 __swab32s (&cr->cr_suppgid2);
1985 __swab32s (&cr->cr_bias);
1986 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1989 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1991 __swab32s (&lk->lk_opcode);
1992 __swab32s (&lk->lk_fsuid);
1993 __swab32s (&lk->lk_fsgid);
1994 __swab32s (&lk->lk_cap);
1995 __swab32s (&lk->lk_suppgid1);
1996 __swab32s (&lk->lk_suppgid2);
1997 lustre_swab_ll_fid (&lk->lk_fid1);
1998 lustre_swab_ll_fid (&lk->lk_fid2);
1999 __swab64s (&lk->lk_time);
2000 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
2001 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2002 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2003 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2006 void lustre_swab_mdt_rec_link (struct mdt_rec_link *lk)
2008 __swab32s (&lk->lk_opcode);
2009 __swab32s (&lk->lk_fsuid);
2010 __swab32s (&lk->lk_fsgid);
2011 __swab32s (&lk->lk_cap);
2012 __swab32s (&lk->lk_suppgid1);
2013 __swab32s (&lk->lk_suppgid2);
2014 lustre_swab_lu_fid (&lk->lk_fid1);
2015 lustre_swab_lu_fid (&lk->lk_fid2);
2016 __swab64s (&lk->lk_time);
2017 __swab32s (&lk->lk_bias);
2018 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2019 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2020 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2023 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
2025 __swab32s (&ul->ul_opcode);
2026 __swab32s (&ul->ul_fsuid);
2027 __swab32s (&ul->ul_fsgid);
2028 __swab32s (&ul->ul_cap);
2029 __swab32s (&ul->ul_suppgid);
2030 __swab32s (&ul->ul_mode);
2031 lustre_swab_ll_fid (&ul->ul_fid1);
2032 lustre_swab_ll_fid (&ul->ul_fid2);
2033 __swab64s (&ul->ul_time);
2034 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
2035 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2036 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2037 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2040 void lustre_swab_mdt_rec_unlink (struct mdt_rec_unlink *ul)
2042 __swab32s (&ul->ul_opcode);
2043 __swab32s (&ul->ul_fsuid);
2044 __swab32s (&ul->ul_fsgid);
2045 __swab32s (&ul->ul_cap);
2046 __swab32s (&ul->ul_suppgid);
2047 __swab32s (&ul->ul_mode);
2048 lustre_swab_lu_fid (&ul->ul_fid1);
2049 lustre_swab_lu_fid (&ul->ul_fid2);
2050 __swab64s (&ul->ul_time);
2051 __swab32s (&ul->ul_bias);
2052 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2053 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2054 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2057 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
2059 __swab32s (&rn->rn_opcode);
2060 __swab32s (&rn->rn_fsuid);
2061 __swab32s (&rn->rn_fsgid);
2062 __swab32s (&rn->rn_cap);
2063 __swab32s (&rn->rn_suppgid1);
2064 __swab32s (&rn->rn_suppgid2);
2065 lustre_swab_ll_fid (&rn->rn_fid1);
2066 lustre_swab_ll_fid (&rn->rn_fid2);
2067 __swab64s (&rn->rn_time);
2068 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
2069 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
2070 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2071 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2074 void lustre_swab_mdt_rec_rename (struct mdt_rec_rename *rn)
2076 __swab32s (&rn->rn_opcode);
2077 __swab32s (&rn->rn_fsuid);
2078 __swab32s (&rn->rn_fsgid);
2079 __swab32s (&rn->rn_cap);
2080 __swab32s (&rn->rn_suppgid1);
2081 __swab32s (&rn->rn_suppgid2);
2082 lustre_swab_lu_fid (&rn->rn_fid1);
2083 lustre_swab_lu_fid (&rn->rn_fid2);
2084 __swab64s (&rn->rn_time);
2085 __swab32s (&rn->rn_mode);
2086 __swab32s (&rn->rn_bias);
2087 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2088 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2091 void lustre_swab_lov_desc (struct lov_desc *ld)
2093 __swab32s (&ld->ld_tgt_count);
2094 __swab32s (&ld->ld_active_tgt_count);
2095 __swab32s (&ld->ld_default_stripe_count);
2096 __swab64s (&ld->ld_default_stripe_size);
2097 __swab64s (&ld->ld_default_stripe_offset);
2098 __swab32s (&ld->ld_pattern);
2099 __swab32s (&ld->ld_qos_maxage);
2100 /* uuid endian insensitive */
2103 /*begin adding MDT by huanghua@clusterfs.com*/
2104 void lustre_swab_lmv_desc (struct lmv_desc *ld)
2106 __swab32s (&ld->ld_tgt_count);
2107 __swab32s (&ld->ld_active_tgt_count);
2108 /* uuid endian insensitive */
2110 /*end adding MDT by huanghua@clusterfs.com*/
2111 void lustre_swab_md_fld (struct md_fld *mf)
2113 __swab64s(&mf->mf_seq);
2114 __swab64s(&mf->mf_mds);
2117 static void print_lum (struct lov_user_md *lum)
2119 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
2120 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
2121 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2122 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
2123 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
2124 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2125 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2126 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
2129 void lustre_swab_lov_user_md(struct lov_user_md *lum)
2132 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2133 __swab32s(&lum->lmm_magic);
2134 __swab32s(&lum->lmm_pattern);
2135 __swab64s(&lum->lmm_object_id);
2136 __swab64s(&lum->lmm_object_gr);
2137 __swab32s(&lum->lmm_stripe_size);
2138 __swab16s(&lum->lmm_stripe_count);
2139 __swab16s(&lum->lmm_stripe_offset);
2144 static void print_lumj (struct lov_user_md_join *lumj)
2146 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2147 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2148 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2149 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2150 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2151 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2152 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2153 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2156 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2159 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2160 __swab32s(&lumj->lmm_magic);
2161 __swab32s(&lumj->lmm_pattern);
2162 __swab64s(&lumj->lmm_object_id);
2163 __swab64s(&lumj->lmm_object_gr);
2164 __swab32s(&lumj->lmm_stripe_size);
2165 __swab32s(&lumj->lmm_stripe_count);
2166 __swab32s(&lumj->lmm_extent_count);
2171 static void print_lum_objs(struct lov_user_md *lum)
2173 struct lov_user_ost_data *lod;
2176 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2178 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2179 for (i = 0; i < lum->lmm_stripe_count; i++) {
2180 lod = &lum->lmm_objects[i];
2181 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2182 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2183 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2184 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2189 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2191 struct lov_user_ost_data *lod;
2194 for (i = 0; i < lum->lmm_stripe_count; i++) {
2195 lod = &lum->lmm_objects[i];
2196 __swab64s(&lod->l_object_id);
2197 __swab64s(&lod->l_object_gr);
2198 __swab32s(&lod->l_ost_gen);
2199 __swab32s(&lod->l_ost_idx);
2201 print_lum_objs(lum);
2206 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2208 struct lov_ost_data *lod;
2211 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2212 lod = &lmm->lmm_objects[i];
2213 __swab64s(&lod->l_object_id);
2214 __swab64s(&lod->l_object_gr);
2215 __swab32s(&lod->l_ost_gen);
2216 __swab32s(&lod->l_ost_idx);
2218 __swab32s(&lmm->lmm_magic);
2219 __swab32s(&lmm->lmm_pattern);
2220 __swab64s(&lmm->lmm_object_id);
2221 __swab64s(&lmm->lmm_object_gr);
2222 __swab32s(&lmm->lmm_stripe_size);
2223 __swab32s(&lmm->lmm_stripe_count);
2229 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2233 for (i = 0; i < RES_NAME_SIZE; i++)
2234 __swab64s (&id->name[i]);
2237 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2239 /* the lock data is a union and the first two fields are always an
2240 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2241 * data the same way. */
2242 __swab64s(&d->l_extent.start);
2243 __swab64s(&d->l_extent.end);
2244 __swab64s(&d->l_extent.gid);
2245 __swab32s(&d->l_flock.pid);
2248 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2250 __swab64s (&i->opc);
2253 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2255 __swab32s (&r->lr_type);
2256 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2257 lustre_swab_ldlm_res_id (&r->lr_name);
2260 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2262 lustre_swab_ldlm_resource_desc (&l->l_resource);
2263 __swab32s (&l->l_req_mode);
2264 __swab32s (&l->l_granted_mode);
2265 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2268 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2270 __swab32s (&rq->lock_flags);
2271 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2272 __swab32s (&rq->lock_count);
2273 /* lock_handle[] opaque */
2276 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2278 __swab32s (&r->lock_flags);
2279 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2280 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2281 /* lock_handle opaque */
2282 __swab64s (&r->lock_policy_res1);
2283 __swab64s (&r->lock_policy_res2);
2286 /* no one calls this */
2287 int llog_log_swabbed(struct llog_log_hdr *hdr)
2289 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2291 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2296 void lustre_swab_qdata(struct qunit_data *d)
2298 __swab32s (&d->qd_id);
2299 __swab32s (&d->qd_flags);
2300 __swab64s (&d->qd_count);
2303 void lustre_swab_qdata_old(struct qunit_data_old *d)
2305 __swab32s (&d->qd_id);
2306 __swab32s (&d->qd_type);
2307 __swab32s (&d->qd_count);
2308 __swab32s (&d->qd_isblk);
2312 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2314 struct qunit_data_old tmp;
2315 struct qunit_data *ret;
2322 ret = (struct qunit_data *)d;
2323 ret->qd_id = tmp.qd_id;
2324 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2325 ret->qd_count = tmp.qd_count;
2329 EXPORT_SYMBOL(lustre_quota_old_to_new);
2331 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2333 struct qunit_data tmp;
2334 struct qunit_data_old *ret;
2341 ret = (struct qunit_data_old *)d;
2342 ret->qd_id = tmp.qd_id;
2343 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2344 ret->qd_count = (__u32)tmp.qd_count;
2345 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2348 EXPORT_SYMBOL(lustre_quota_new_to_old);
2349 #endif /* __KERNEL__ */
2351 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2353 LASSERT(req->rq_reqmsg);
2355 switch (req->rq_reqmsg->lm_magic) {
2356 case LUSTRE_MSG_MAGIC_V1:
2357 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2359 case LUSTRE_MSG_MAGIC_V2:
2360 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2361 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2363 CERROR("bad lustre msg magic: %#08X\n",
2364 req->rq_reqmsg->lm_magic);
2369 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2371 LASSERT(req->rq_repmsg);
2373 switch (req->rq_repmsg->lm_magic) {
2374 case LUSTRE_MSG_MAGIC_V1:
2375 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2377 case LUSTRE_MSG_MAGIC_V2:
2378 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2379 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2381 /* uninitialized yet */
2386 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2387 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2391 va_start(args, fmt);
2392 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2393 data->msg_fn, data->msg_line, fmt, args,
2394 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d lens"
2395 " %d/%d ref %d fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2396 req, req->rq_xid, req->rq_transno,
2397 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2398 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2399 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2401 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2403 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2405 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2406 (req->rq_import && req->rq_import->imp_client) ?
2407 req->rq_import->imp_client->cli_request_portal : -1,
2408 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2409 DEBUG_REQ_FLAGS(req),
2410 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2411 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2412 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2413 lustre_msg_get_flags(req->rq_repmsg) : -1,
2415 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2416 lustre_msg_get_status(req->rq_repmsg) : -1);
2418 EXPORT_SYMBOL(_debug_req);
2420 void lustre_swab_lustre_capa(struct lustre_capa *c)
2422 lustre_swab_lu_fid(&c->lc_fid);
2423 __swab64s (&c->lc_opc);
2424 __swab32s (&c->lc_uid);
2425 __swab32s (&c->lc_flags);
2426 __swab32s (&c->lc_keyid);
2427 __swab32s (&c->lc_timeout);
2428 __swab64s (&c->lc_expiry);
2431 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2433 __swab64s (&k->lk_mdsid);
2434 __swab32s (&k->lk_keyid);
2435 __swab32s (&k->lk_padding);