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 LASSERT_REQSWAB(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 LASSERT_REPSWAB(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 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1356 switch (msg->lm_magic) {
1357 case LUSTRE_MSG_MAGIC_V1:
1358 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1359 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
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);
1369 return pb->pb_conn_cnt;
1372 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1377 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1379 switch (msg->lm_magic) {
1380 case LUSTRE_MSG_MAGIC_V1:
1381 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1382 case LUSTRE_MSG_MAGIC_V2:
1383 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1384 return msg->lm_magic;
1386 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1391 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1393 switch (msg->lm_magic) {
1394 case LUSTRE_MSG_MAGIC_V1:
1395 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1397 case LUSTRE_MSG_MAGIC_V2: {
1398 struct ptlrpc_body *pb;
1400 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1401 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1402 pb->pb_handle = *handle;
1406 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1410 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1412 switch (msg->lm_magic) {
1413 case LUSTRE_MSG_MAGIC_V1:
1414 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1416 case LUSTRE_MSG_MAGIC_V2: {
1417 struct ptlrpc_body *pb;
1419 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1420 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1425 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1429 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1431 switch (msg->lm_magic) {
1432 case LUSTRE_MSG_MAGIC_V1:
1433 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1435 case LUSTRE_MSG_MAGIC_V2: {
1436 struct ptlrpc_body *pb;
1438 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1439 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1444 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1448 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1450 switch (msg->lm_magic) {
1451 case LUSTRE_MSG_MAGIC_V1:
1452 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1454 case LUSTRE_MSG_MAGIC_V2: {
1455 struct ptlrpc_body *pb;
1457 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1458 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1459 pb->pb_last_xid = last_xid;
1463 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1467 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1469 switch (msg->lm_magic) {
1470 case LUSTRE_MSG_MAGIC_V1:
1471 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1473 case LUSTRE_MSG_MAGIC_V2: {
1474 struct ptlrpc_body *pb;
1476 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1477 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1478 pb->pb_last_committed = last_committed;
1482 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1486 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1488 switch (msg->lm_magic) {
1489 case LUSTRE_MSG_MAGIC_V1:
1490 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1492 case LUSTRE_MSG_MAGIC_V2: {
1493 struct ptlrpc_body *pb;
1495 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1496 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1497 pb->pb_transno = transno;
1501 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1505 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1507 switch (msg->lm_magic) {
1508 case LUSTRE_MSG_MAGIC_V1:
1509 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1511 case LUSTRE_MSG_MAGIC_V2: {
1512 struct ptlrpc_body *pb;
1514 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1515 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1516 pb->pb_status = status;
1520 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1524 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1526 switch (msg->lm_magic) {
1527 case LUSTRE_MSG_MAGIC_V1:
1528 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1530 case LUSTRE_MSG_MAGIC_V2: {
1531 struct ptlrpc_body *pb;
1533 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1534 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1535 pb->pb_conn_cnt = conn_cnt;
1539 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1543 /* byte flipping routines for all wire types declared in
1544 * lustre_idl.h implemented here.
1546 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1548 __swab32s (&b->pb_type);
1549 __swab32s (&b->pb_version);
1550 __swab32s (&b->pb_opc);
1551 __swab32s (&b->pb_status);
1552 __swab64s (&b->pb_last_xid);
1553 __swab64s (&b->pb_last_seen);
1554 __swab64s (&b->pb_last_committed);
1555 __swab64s (&b->pb_transno);
1556 __swab32s (&b->pb_flags);
1557 __swab32s (&b->pb_op_flags);
1558 __swab32s (&b->pb_conn_cnt);
1559 CLASSERT(offsetof(typeof(*b), pb_padding_1) != 0);
1560 CLASSERT(offsetof(typeof(*b), pb_padding_2) != 0);
1561 CLASSERT(offsetof(typeof(*b), pb_padding_3) != 0);
1562 CLASSERT(offsetof(typeof(*b), pb_padding_4) != 0);
1563 CLASSERT(offsetof(typeof(*b), pb_padding_5) != 0);
1566 void lustre_swab_connect(struct obd_connect_data *ocd)
1568 __swab64s(&ocd->ocd_connect_flags);
1569 __swab32s(&ocd->ocd_version);
1570 __swab32s(&ocd->ocd_grant);
1571 __swab64s(&ocd->ocd_ibits_known);
1572 __swab32s(&ocd->ocd_index);
1573 __swab32s(&ocd->ocd_brw_size);
1574 __swab32s(&ocd->ocd_nllu);
1575 __swab32s(&ocd->ocd_nllg);
1576 __swab64s(&ocd->ocd_transno);
1577 __swab32s(&ocd->ocd_group);
1578 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1579 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1580 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1583 void lustre_swab_obdo (struct obdo *o)
1585 __swab64s (&o->o_valid);
1586 __swab64s (&o->o_id);
1587 __swab64s (&o->o_gr);
1588 __swab64s (&o->o_fid);
1589 __swab64s (&o->o_size);
1590 __swab64s (&o->o_mtime);
1591 __swab64s (&o->o_atime);
1592 __swab64s (&o->o_ctime);
1593 __swab64s (&o->o_blocks);
1594 __swab64s (&o->o_grant);
1595 __swab32s (&o->o_blksize);
1596 __swab32s (&o->o_mode);
1597 __swab32s (&o->o_uid);
1598 __swab32s (&o->o_gid);
1599 __swab32s (&o->o_flags);
1600 __swab32s (&o->o_nlink);
1601 __swab32s (&o->o_generation);
1602 __swab32s (&o->o_misc);
1603 __swab32s (&o->o_easize);
1604 __swab32s (&o->o_mds);
1605 __swab32s (&o->o_stripe_idx);
1606 __swab32s (&o->o_padding_1);
1607 /* o_inline is opaque */
1610 void lustre_swab_obd_statfs (struct obd_statfs *os)
1612 __swab64s (&os->os_type);
1613 __swab64s (&os->os_blocks);
1614 __swab64s (&os->os_bfree);
1615 __swab64s (&os->os_bavail);
1616 __swab64s (&os->os_files);
1617 __swab64s (&os->os_ffree);
1618 /* no need to swab os_fsid */
1619 __swab32s (&os->os_bsize);
1620 __swab32s (&os->os_namelen);
1621 __swab64s (&os->os_maxbytes);
1622 __swab32s (&os->os_state);
1623 /* no need to swap os_spare */
1626 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1628 __swab64s (&ioo->ioo_id);
1629 __swab64s (&ioo->ioo_gr);
1630 __swab32s (&ioo->ioo_type);
1631 __swab32s (&ioo->ioo_bufcnt);
1634 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1636 __swab64s (&nbr->offset);
1637 __swab32s (&nbr->len);
1638 __swab32s (&nbr->flags);
1641 void lustre_swab_ost_body (struct ost_body *b)
1643 lustre_swab_obdo (&b->oa);
1646 void lustre_swab_ost_last_id(obd_id *id)
1651 void lustre_swab_generic_32s(__u32 *val)
1656 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1658 __swab64s(&lvb->lvb_size);
1659 __swab64s(&lvb->lvb_mtime);
1660 __swab64s(&lvb->lvb_atime);
1661 __swab64s(&lvb->lvb_ctime);
1662 __swab64s(&lvb->lvb_blocks);
1665 void lustre_swab_mds_status_req (struct mds_status_req *r)
1667 __swab32s (&r->flags);
1668 __swab32s (&r->repbuf);
1671 void lustre_swab_mds_body (struct mds_body *b)
1673 lustre_swab_ll_fid (&b->fid1);
1674 lustre_swab_ll_fid (&b->fid2);
1675 /* handle is opaque */
1676 __swab64s (&b->valid);
1677 __swab64s (&b->size);
1678 __swab64s (&b->mtime);
1679 __swab64s (&b->atime);
1680 __swab64s (&b->ctime);
1681 __swab64s (&b->blocks);
1682 __swab64s (&b->io_epoch);
1683 __swab64s (&b->ino);
1684 __swab32s (&b->fsuid);
1685 __swab32s (&b->fsgid);
1686 __swab32s (&b->capability);
1687 __swab32s (&b->mode);
1688 __swab32s (&b->uid);
1689 __swab32s (&b->gid);
1690 __swab32s (&b->flags);
1691 __swab32s (&b->rdev);
1692 __swab32s (&b->nlink);
1693 __swab32s (&b->generation);
1694 __swab32s (&b->suppgid);
1695 __swab32s (&b->eadatasize);
1696 __swab32s (&b->aclsize);
1697 __swab32s (&b->max_mdsize);
1698 __swab32s (&b->max_cookiesize);
1699 __swab32s (&b->padding_4);
1702 void lustre_swab_mdt_body (struct mdt_body *b)
1704 lustre_swab_lu_fid (&b->fid1);
1705 lustre_swab_lu_fid (&b->fid2);
1706 /* handle is opaque */
1707 __swab64s (&b->valid);
1708 __swab64s (&b->size);
1709 __swab64s (&b->mtime);
1710 __swab64s (&b->atime);
1711 __swab64s (&b->ctime);
1712 __swab64s (&b->blocks);
1713 __swab64s (&b->ioepoch);
1714 __swab32s (&b->fsuid);
1715 __swab32s (&b->fsgid);
1716 __swab32s (&b->capability);
1717 __swab32s (&b->mode);
1718 __swab32s (&b->uid);
1719 __swab32s (&b->gid);
1720 __swab32s (&b->flags);
1721 __swab32s (&b->rdev);
1722 __swab32s (&b->nlink);
1723 __swab32s (&b->suppgid);
1724 __swab32s (&b->eadatasize);
1725 __swab32s (&b->aclsize);
1726 __swab32s (&b->max_mdsize);
1727 __swab32s (&b->max_cookiesize);
1730 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1732 /* handle is opaque */
1733 __swab64s (&b->ioepoch);
1734 __swab32s (&b->flags);
1735 CLASSERT(offsetof(typeof(*b), padding) != 0);
1738 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1741 __swab32s(&mti->mti_lustre_ver);
1742 __swab32s(&mti->mti_stripe_index);
1743 __swab32s(&mti->mti_config_ver);
1744 __swab32s(&mti->mti_flags);
1745 __swab32s(&mti->mti_nid_count);
1746 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1747 for (i = 0; i < MTI_NIDS_MAX; i++)
1748 __swab64s(&mti->mti_nids[i]);
1751 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1753 __swab64s (&i->dqi_bgrace);
1754 __swab64s (&i->dqi_igrace);
1755 __swab32s (&i->dqi_flags);
1756 __swab32s (&i->dqi_valid);
1759 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1761 __swab64s (&b->dqb_ihardlimit);
1762 __swab64s (&b->dqb_isoftlimit);
1763 __swab64s (&b->dqb_curinodes);
1764 __swab64s (&b->dqb_bhardlimit);
1765 __swab64s (&b->dqb_bsoftlimit);
1766 __swab64s (&b->dqb_curspace);
1767 __swab64s (&b->dqb_btime);
1768 __swab64s (&b->dqb_itime);
1769 __swab32s (&b->dqb_valid);
1770 CLASSERT(offsetof(typeof(*b), padding) != 0);
1773 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1775 __swab32s (&q->qc_cmd);
1776 __swab32s (&q->qc_type);
1777 __swab32s (&q->qc_id);
1778 __swab32s (&q->qc_stat);
1779 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1780 lustre_swab_obd_dqblk (&q->qc_dqblk);
1783 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1785 __swab32s (&p->rp_uid);
1786 __swab32s (&p->rp_gid);
1787 __swab32s (&p->rp_fsuid);
1788 __swab32s (&p->rp_fsgid);
1789 __swab32s (&p->rp_access_perm);
1792 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1794 __swab32s (&p->rp_uid);
1795 __swab32s (&p->rp_gid);
1796 __swab32s (&p->rp_fsuid);
1797 __swab32s (&p->rp_fsgid);
1798 __swab32s (&p->rp_access_perm);
1801 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1803 __swab32s (&sa->sa_opcode);
1804 __swab32s (&sa->sa_fsuid);
1805 __swab32s (&sa->sa_fsgid);
1806 __swab32s (&sa->sa_cap);
1807 __swab32s (&sa->sa_suppgid);
1808 __swab32s (&sa->sa_mode);
1809 lustre_swab_ll_fid (&sa->sa_fid);
1810 __swab64s (&sa->sa_valid);
1811 __swab64s (&sa->sa_size);
1812 __swab64s (&sa->sa_mtime);
1813 __swab64s (&sa->sa_atime);
1814 __swab64s (&sa->sa_ctime);
1815 __swab32s (&sa->sa_uid);
1816 __swab32s (&sa->sa_gid);
1817 __swab32s (&sa->sa_attr_flags);
1818 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1821 void lustre_swab_mdt_rec_setattr (struct mdt_rec_setattr *sa)
1823 __swab32s (&sa->sa_opcode);
1824 __swab32s (&sa->sa_fsuid);
1825 __swab32s (&sa->sa_fsgid);
1826 __swab32s (&sa->sa_cap);
1827 __swab32s (&sa->sa_suppgid);
1828 __swab32s (&sa->sa_mode);
1829 lustre_swab_lu_fid (&sa->sa_fid);
1830 __swab64s (&sa->sa_valid);
1831 __swab64s (&sa->sa_size);
1832 __swab64s (&sa->sa_blocks);
1833 __swab64s (&sa->sa_mtime);
1834 __swab64s (&sa->sa_atime);
1835 __swab64s (&sa->sa_ctime);
1836 __swab32s (&sa->sa_uid);
1837 __swab32s (&sa->sa_gid);
1838 __swab32s (&sa->sa_attr_flags);
1839 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1842 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1844 __swab64s(&jr->jr_headsize);
1845 lustre_swab_ll_fid(&jr->jr_fid);
1848 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1850 __swab64s(&jr->jr_headsize);
1851 lustre_swab_lu_fid(&jr->jr_fid);
1854 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1856 __swab32s (&cr->cr_opcode);
1857 __swab32s (&cr->cr_fsuid);
1858 __swab32s (&cr->cr_fsgid);
1859 __swab32s (&cr->cr_cap);
1860 __swab32s (&cr->cr_flags); /* for use with open */
1861 __swab32s (&cr->cr_mode);
1862 lustre_swab_ll_fid (&cr->cr_fid);
1863 lustre_swab_ll_fid (&cr->cr_replayfid);
1864 __swab64s (&cr->cr_time);
1865 __swab64s (&cr->cr_rdev);
1866 __swab32s (&cr->cr_suppgid);
1867 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1868 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1869 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1870 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1871 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1874 void lustre_swab_mdt_rec_create (struct mdt_rec_create *cr)
1876 __swab32s (&cr->cr_opcode);
1877 __swab32s (&cr->cr_fsuid);
1878 __swab32s (&cr->cr_fsgid);
1879 __swab32s (&cr->cr_cap);
1880 __swab32s (&cr->cr_flags); /* for use with open */
1881 __swab32s (&cr->cr_mode);
1882 /* handle is opaque */
1883 lustre_swab_lu_fid (&cr->cr_fid1);
1884 lustre_swab_lu_fid (&cr->cr_fid2);
1885 __swab64s (&cr->cr_time);
1886 __swab64s (&cr->cr_rdev);
1887 __swab64s (&cr->cr_ioepoch);
1888 __swab32s (&cr->cr_suppgid1);
1889 __swab32s (&cr->cr_suppgid2);
1890 __swab32s (&cr->cr_bias);
1891 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1894 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1896 __swab32s (&lk->lk_opcode);
1897 __swab32s (&lk->lk_fsuid);
1898 __swab32s (&lk->lk_fsgid);
1899 __swab32s (&lk->lk_cap);
1900 __swab32s (&lk->lk_suppgid1);
1901 __swab32s (&lk->lk_suppgid2);
1902 lustre_swab_ll_fid (&lk->lk_fid1);
1903 lustre_swab_ll_fid (&lk->lk_fid2);
1904 __swab64s (&lk->lk_time);
1905 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1906 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1907 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1908 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1911 void lustre_swab_mdt_rec_link (struct mdt_rec_link *lk)
1913 __swab32s (&lk->lk_opcode);
1914 __swab32s (&lk->lk_fsuid);
1915 __swab32s (&lk->lk_fsgid);
1916 __swab32s (&lk->lk_cap);
1917 __swab32s (&lk->lk_suppgid1);
1918 __swab32s (&lk->lk_suppgid2);
1919 lustre_swab_lu_fid (&lk->lk_fid1);
1920 lustre_swab_lu_fid (&lk->lk_fid2);
1921 __swab64s (&lk->lk_time);
1922 __swab32s (&lk->lk_bias);
1923 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1924 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1925 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1928 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1930 __swab32s (&ul->ul_opcode);
1931 __swab32s (&ul->ul_fsuid);
1932 __swab32s (&ul->ul_fsgid);
1933 __swab32s (&ul->ul_cap);
1934 __swab32s (&ul->ul_suppgid);
1935 __swab32s (&ul->ul_mode);
1936 lustre_swab_ll_fid (&ul->ul_fid1);
1937 lustre_swab_ll_fid (&ul->ul_fid2);
1938 __swab64s (&ul->ul_time);
1939 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1940 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1941 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1942 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1945 void lustre_swab_mdt_rec_unlink (struct mdt_rec_unlink *ul)
1947 __swab32s (&ul->ul_opcode);
1948 __swab32s (&ul->ul_fsuid);
1949 __swab32s (&ul->ul_fsgid);
1950 __swab32s (&ul->ul_cap);
1951 __swab32s (&ul->ul_suppgid);
1952 __swab32s (&ul->ul_mode);
1953 lustre_swab_lu_fid (&ul->ul_fid1);
1954 lustre_swab_lu_fid (&ul->ul_fid2);
1955 __swab64s (&ul->ul_time);
1956 __swab32s (&ul->ul_bias);
1957 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1958 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1959 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1962 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1964 __swab32s (&rn->rn_opcode);
1965 __swab32s (&rn->rn_fsuid);
1966 __swab32s (&rn->rn_fsgid);
1967 __swab32s (&rn->rn_cap);
1968 __swab32s (&rn->rn_suppgid1);
1969 __swab32s (&rn->rn_suppgid2);
1970 lustre_swab_ll_fid (&rn->rn_fid1);
1971 lustre_swab_ll_fid (&rn->rn_fid2);
1972 __swab64s (&rn->rn_time);
1973 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1974 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1975 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1976 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1979 void lustre_swab_mdt_rec_rename (struct mdt_rec_rename *rn)
1981 __swab32s (&rn->rn_opcode);
1982 __swab32s (&rn->rn_fsuid);
1983 __swab32s (&rn->rn_fsgid);
1984 __swab32s (&rn->rn_cap);
1985 __swab32s (&rn->rn_suppgid1);
1986 __swab32s (&rn->rn_suppgid2);
1987 lustre_swab_lu_fid (&rn->rn_fid1);
1988 lustre_swab_lu_fid (&rn->rn_fid2);
1989 __swab64s (&rn->rn_time);
1990 __swab32s (&rn->rn_mode);
1991 __swab32s (&rn->rn_bias);
1992 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1993 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1996 void lustre_swab_lov_desc (struct lov_desc *ld)
1998 __swab32s (&ld->ld_tgt_count);
1999 __swab32s (&ld->ld_active_tgt_count);
2000 __swab32s (&ld->ld_default_stripe_count);
2001 __swab64s (&ld->ld_default_stripe_size);
2002 __swab64s (&ld->ld_default_stripe_offset);
2003 __swab32s (&ld->ld_pattern);
2004 __swab32s (&ld->ld_qos_maxage);
2005 /* uuid endian insensitive */
2008 /*begin adding MDT by huanghua@clusterfs.com*/
2009 void lustre_swab_lmv_desc (struct lmv_desc *ld)
2011 __swab32s (&ld->ld_tgt_count);
2012 __swab32s (&ld->ld_active_tgt_count);
2013 /* uuid endian insensitive */
2015 /*end adding MDT by huanghua@clusterfs.com*/
2016 void lustre_swab_md_fld (struct md_fld *mf)
2018 __swab64s(&mf->mf_seq);
2019 __swab64s(&mf->mf_mds);
2022 static void print_lum (struct lov_user_md *lum)
2024 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
2025 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
2026 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2027 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
2028 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
2029 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2030 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2031 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
2034 void lustre_swab_lov_user_md(struct lov_user_md *lum)
2037 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2038 __swab32s(&lum->lmm_magic);
2039 __swab32s(&lum->lmm_pattern);
2040 __swab64s(&lum->lmm_object_id);
2041 __swab64s(&lum->lmm_object_gr);
2042 __swab32s(&lum->lmm_stripe_size);
2043 __swab16s(&lum->lmm_stripe_count);
2044 __swab16s(&lum->lmm_stripe_offset);
2049 static void print_lumj (struct lov_user_md_join *lumj)
2051 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2052 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2053 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2054 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2055 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2056 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2057 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2058 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2061 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2064 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2065 __swab32s(&lumj->lmm_magic);
2066 __swab32s(&lumj->lmm_pattern);
2067 __swab64s(&lumj->lmm_object_id);
2068 __swab64s(&lumj->lmm_object_gr);
2069 __swab32s(&lumj->lmm_stripe_size);
2070 __swab32s(&lumj->lmm_stripe_count);
2071 __swab32s(&lumj->lmm_extent_count);
2076 static void print_lum_objs(struct lov_user_md *lum)
2078 struct lov_user_ost_data *lod;
2081 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2083 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2084 for (i = 0; i < lum->lmm_stripe_count; i++) {
2085 lod = &lum->lmm_objects[i];
2086 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2087 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2088 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2089 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2094 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2096 struct lov_user_ost_data *lod;
2099 for (i = 0; i < lum->lmm_stripe_count; i++) {
2100 lod = &lum->lmm_objects[i];
2101 __swab64s(&lod->l_object_id);
2102 __swab64s(&lod->l_object_gr);
2103 __swab32s(&lod->l_ost_gen);
2104 __swab32s(&lod->l_ost_idx);
2106 print_lum_objs(lum);
2111 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2113 struct lov_ost_data *lod;
2116 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2117 lod = &lmm->lmm_objects[i];
2118 __swab64s(&lod->l_object_id);
2119 __swab64s(&lod->l_object_gr);
2120 __swab32s(&lod->l_ost_gen);
2121 __swab32s(&lod->l_ost_idx);
2123 __swab32s(&lmm->lmm_magic);
2124 __swab32s(&lmm->lmm_pattern);
2125 __swab64s(&lmm->lmm_object_id);
2126 __swab64s(&lmm->lmm_object_gr);
2127 __swab32s(&lmm->lmm_stripe_size);
2128 __swab32s(&lmm->lmm_stripe_count);
2134 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2138 for (i = 0; i < RES_NAME_SIZE; i++)
2139 __swab64s (&id->name[i]);
2142 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2144 /* the lock data is a union and the first two fields are always an
2145 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2146 * data the same way. */
2147 __swab64s(&d->l_extent.start);
2148 __swab64s(&d->l_extent.end);
2149 __swab64s(&d->l_extent.gid);
2150 __swab32s(&d->l_flock.pid);
2153 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2155 __swab64s (&i->opc);
2158 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2160 __swab32s (&r->lr_type);
2161 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2162 lustre_swab_ldlm_res_id (&r->lr_name);
2165 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2167 lustre_swab_ldlm_resource_desc (&l->l_resource);
2168 __swab32s (&l->l_req_mode);
2169 __swab32s (&l->l_granted_mode);
2170 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2173 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2175 __swab32s (&rq->lock_flags);
2176 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2177 __swab32s (&rq->lock_count);
2178 /* lock_handle[] opaque */
2181 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2183 __swab32s (&r->lock_flags);
2184 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2185 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2186 /* lock_handle opaque */
2187 __swab64s (&r->lock_policy_res1);
2188 __swab64s (&r->lock_policy_res2);
2191 /* no one calls this */
2192 int llog_log_swabbed(struct llog_log_hdr *hdr)
2194 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2196 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2201 void lustre_swab_qdata(struct qunit_data *d)
2203 __swab32s (&d->qd_id);
2204 __swab32s (&d->qd_flags);
2205 __swab64s (&d->qd_count);
2208 void lustre_swab_qdata_old(struct qunit_data_old *d)
2210 __swab32s (&d->qd_id);
2211 __swab32s (&d->qd_type);
2212 __swab32s (&d->qd_count);
2213 __swab32s (&d->qd_isblk);
2217 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2219 struct qunit_data_old tmp;
2220 struct qunit_data *ret;
2227 ret = (struct qunit_data *)d;
2228 ret->qd_id = tmp.qd_id;
2229 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2230 ret->qd_count = tmp.qd_count;
2234 EXPORT_SYMBOL(lustre_quota_old_to_new);
2236 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2238 struct qunit_data tmp;
2239 struct qunit_data_old *ret;
2246 ret = (struct qunit_data_old *)d;
2247 ret->qd_id = tmp.qd_id;
2248 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2249 ret->qd_count = (__u32)tmp.qd_count;
2250 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2253 EXPORT_SYMBOL(lustre_quota_new_to_old);
2254 #endif /* __KERNEL__ */
2256 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2258 LASSERT(req->rq_reqmsg);
2260 switch (req->rq_reqmsg->lm_magic) {
2261 case LUSTRE_MSG_MAGIC_V1:
2262 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2264 case LUSTRE_MSG_MAGIC_V2:
2265 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2266 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2268 CERROR("bad lustre msg magic: %#08X\n",
2269 req->rq_reqmsg->lm_magic);
2274 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2276 LASSERT(req->rq_repmsg);
2278 switch (req->rq_repmsg->lm_magic) {
2279 case LUSTRE_MSG_MAGIC_V1:
2280 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2282 case LUSTRE_MSG_MAGIC_V2:
2283 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2284 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2286 /* uninitialized yet */
2291 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2292 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2296 va_start(args, fmt);
2297 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2298 data->msg_fn, data->msg_line, fmt, args,
2299 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d lens"
2300 " %d/%d ref %d fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2301 req, req->rq_xid, req->rq_transno,
2302 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2303 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2304 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2306 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2308 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2310 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2311 (req->rq_import && req->rq_import->imp_client) ?
2312 req->rq_import->imp_client->cli_request_portal : -1,
2313 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2314 DEBUG_REQ_FLAGS(req),
2315 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2316 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2317 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2318 lustre_msg_get_flags(req->rq_repmsg) : -1,
2320 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2321 lustre_msg_get_status(req->rq_repmsg) : -1);
2323 EXPORT_SYMBOL(_debug_req);
2325 void lustre_swab_lustre_capa(struct lustre_capa *c)
2327 lustre_swab_lu_fid(&c->lc_fid);
2328 __swab64s (&c->lc_opc);
2329 __swab32s (&c->lc_uid);
2330 __swab32s (&c->lc_flags);
2331 __swab32s (&c->lc_keyid);
2332 __swab32s (&c->lc_timeout);
2333 __swab64s (&c->lc_expiry);
2336 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2338 __swab64s (&k->lk_mdsid);
2339 __swab32s (&k->lk_keyid);
2340 __swab32s (&k->lk_padding);