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 <obd_support.h>
37 #include <obd_class.h>
38 #include <lustre_net.h>
40 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2,0,0,0)
41 #error "lustre_msg_v1 has been deprecated since 1.6.0, please remove it"
42 #elif LUSTRE_VERSION_CODE > OBD_OCD_VERSION(1,6,7,0)
43 #warning "lustre_msg_v1 has been deprecated since 1.6.0, consider removing it"
46 static inline int lustre_msg_hdr_size_v1(int count)
48 return size_round(offsetof(struct lustre_msg_v1, lm_buflens[count]));
51 static inline int lustre_msg_hdr_size_v2(int count)
53 return size_round(offsetof(struct lustre_msg_v2, lm_buflens[count]));
56 int lustre_msg_swabbed(struct lustre_msg *msg)
58 return (msg->lm_magic == LUSTRE_MSG_MAGIC_V1_SWABBED) ||
59 (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
63 lustre_msg_check_version_v2(struct lustre_msg_v2 *msg, __u32 version)
65 __u32 ver = lustre_msg_get_version(msg);
67 if (lustre_msg_swabbed(msg))
68 return (__swab32(ver) & LUSTRE_VERSION_MASK) != version;
70 return (ver & LUSTRE_VERSION_MASK) != version;
73 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
75 switch (msg->lm_magic) {
76 case LUSTRE_MSG_MAGIC_V1:
77 case LUSTRE_MSG_MAGIC_V1_SWABBED:
79 case LUSTRE_MSG_MAGIC_V2:
80 case LUSTRE_MSG_MAGIC_V2_SWABBED:
81 return lustre_msg_check_version_v2(msg, version);
83 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
88 static inline int lustre_msg_size_v1(int count, int *lengths)
94 size = lustre_msg_hdr_size_v1(count);
95 for (i = 0; i < count; i++)
96 size += size_round(lengths[i]);
101 int lustre_msg_size_v2(int count, int *lengths)
106 size = lustre_msg_hdr_size_v2(count);
107 for (i = 0; i < count; i++)
108 size += size_round(lengths[i]);
112 EXPORT_SYMBOL(lustre_msg_size_v2);
114 /* This returns the size of the buffer that is required to hold a lustre_msg
115 * with the given sub-buffer lengths. */
116 int lustre_msg_size(__u32 magic, int count, int *lens)
118 int size[] = { sizeof(struct ptlrpc_body) };
126 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
129 case LUSTRE_MSG_MAGIC_V1:
130 return lustre_msg_size_v1(count - 1, lens + 1);
131 case LUSTRE_MSG_MAGIC_V2:
132 return lustre_msg_size_v2(count, lens);
134 LASSERTF(0, "incorrect message magic: %08x\n", magic);
140 void lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
142 struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)m;
147 msg->lm_magic = LUSTRE_MSG_MAGIC_V1;
148 msg->lm_version = PTLRPC_MSG_VERSION;
149 msg->lm_bufcount = count;
151 for (i = 0; i < count; i++)
152 msg->lm_buflens[i] = lens[i];
157 ptr = (char *)msg + lustre_msg_hdr_size_v1(count);
158 for (i = 0; i < count; i++) {
160 LOGL(tmp, lens[i], ptr);
164 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
170 msg->lm_bufcount = count;
171 /* XXX: lm_secflvr uninitialized here */
172 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
174 for (i = 0; i < count; i++)
175 msg->lm_buflens[i] = lens[i];
180 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
181 for (i = 0; i < count; i++) {
183 LOGL(tmp, lens[i], ptr);
186 EXPORT_SYMBOL(lustre_init_msg_v2);
188 static int lustre_pack_request_v1(struct ptlrpc_request *req,
189 int count, int *lens, char **bufs)
193 reqlen = lustre_msg_size_v1(count, lens);
195 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
199 req->rq_reqlen = reqlen;
201 lustre_init_msg_v1(req->rq_reqmsg, count, lens, bufs);
205 static int lustre_pack_request_v2(struct ptlrpc_request *req,
206 int count, int *lens, char **bufs)
210 reqlen = lustre_msg_size_v2(count, lens);
212 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
216 req->rq_reqlen = reqlen;
218 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
219 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
223 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
224 int *lens, char **bufs)
226 int size[] = { sizeof(struct ptlrpc_body) };
234 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
236 /* if we choose policy other than null, we have also choosed
237 * to use new message format.
239 if (magic == LUSTRE_MSG_MAGIC_V1 &&
240 req->rq_sec_flavor != SPTLRPC_FLVR_NULL)
241 magic = LUSTRE_MSG_MAGIC_V2;
244 case LUSTRE_MSG_MAGIC_V1:
245 return lustre_pack_request_v1(req, count - 1, lens + 1,
246 bufs ? bufs + 1 : NULL);
247 case LUSTRE_MSG_MAGIC_V2:
248 return lustre_pack_request_v2(req, count, lens, bufs);
250 LASSERTF(0, "incorrect message magic: %08x\n", magic);
256 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
257 spinlock_t ptlrpc_rs_debug_lock;
259 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
261 spin_lock(&ptlrpc_rs_debug_lock); \
262 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
263 spin_unlock(&ptlrpc_rs_debug_lock); \
266 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
268 spin_lock(&ptlrpc_rs_debug_lock); \
269 list_del(&(rs)->rs_debug_list); \
270 spin_unlock(&ptlrpc_rs_debug_lock); \
273 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
274 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
277 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
279 struct ptlrpc_reply_state *rs = NULL;
281 spin_lock(&svc->srv_lock);
282 /* See if we have anything in a pool, and wait if nothing */
283 while (list_empty(&svc->srv_free_rs_list)) {
284 struct l_wait_info lwi;
286 spin_unlock(&svc->srv_lock);
287 /* If we cannot get anything for some long time, we better
288 bail out instead of waiting infinitely */
289 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
290 rc = l_wait_event(svc->srv_free_rs_waitq,
291 !list_empty(&svc->srv_free_rs_list), &lwi);
294 spin_lock(&svc->srv_lock);
297 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
299 list_del(&rs->rs_list);
300 spin_unlock(&svc->srv_lock);
302 memset(rs, 0, svc->srv_max_reply_size);
303 rs->rs_service = svc;
309 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
311 struct ptlrpc_service *svc = rs->rs_service;
315 spin_lock(&svc->srv_lock);
316 list_add(&rs->rs_list, &svc->srv_free_rs_list);
317 spin_unlock(&svc->srv_lock);
318 cfs_waitq_signal(&svc->srv_free_rs_waitq);
321 static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count,
322 int *lens, char **bufs)
324 struct ptlrpc_reply_state *rs;
328 LASSERT (req->rq_reply_state == NULL);
330 msg_len = lustre_msg_size_v1(count, lens);
331 rc = sptlrpc_svc_alloc_rs(req, msg_len);
335 rs = req->rq_reply_state;
336 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
337 rs->rs_cb_id.cbid_fn = reply_out_callback;
338 rs->rs_cb_id.cbid_arg = rs;
339 rs->rs_service = req->rq_rqbd->rqbd_service;
340 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
341 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
343 req->rq_replen = msg_len;
344 req->rq_reply_state = rs;
345 req->rq_repmsg = rs->rs_msg;
346 lustre_init_msg_v1(rs->rs_msg, count, lens, bufs);
348 PTLRPC_RS_DEBUG_LRU_ADD(rs);
353 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
354 int *lens, char **bufs)
356 struct ptlrpc_reply_state *rs;
360 LASSERT(req->rq_reply_state == NULL);
362 msg_len = lustre_msg_size_v2(count, lens);
363 rc = sptlrpc_svc_alloc_rs(req, msg_len);
367 rs = req->rq_reply_state;
368 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
369 rs->rs_cb_id.cbid_fn = reply_out_callback;
370 rs->rs_cb_id.cbid_arg = rs;
371 rs->rs_service = req->rq_rqbd->rqbd_service;
372 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
373 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
375 req->rq_replen = msg_len;
376 req->rq_reply_state = rs;
377 req->rq_repmsg = rs->rs_msg;
378 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
379 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
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;
425 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
430 buflen = m->lm_buflens[n];
431 if (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;
454 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
459 buflen = m->lm_buflens[n];
460 if (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 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
675 if (len < required_len) {
676 /* didn't receive all the buffer lengths */
677 CERROR ("message length %d too small for %d buflens\n",
678 len, m->lm_bufcount);
682 flipped = lustre_msg_swabbed(m);
685 __swab32s(&m->lm_bufcount);
686 __swab32s(&m->lm_secflvr);
687 __swab32s(&m->lm_repsize);
690 for (i = 0; i < m->lm_bufcount; i++) {
692 __swab32s(&m->lm_buflens[i]);
693 required_len += size_round(m->lm_buflens[i]);
696 if (len < required_len) {
697 CERROR("len: %d, required_len %d\n", len, required_len);
698 CERROR("bufcount: %d\n", m->lm_bufcount);
699 for (i = 0; i < m->lm_bufcount; i++)
700 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
707 int lustre_unpack_msg(struct lustre_msg *m, int len)
709 int required_len, rc;
712 /* We can provide a slightly better error log, if we check the
713 * message magic and version first. In the future, struct
714 * lustre_msg may grow, and we'd like to log a version mismatch,
715 * rather than a short message.
718 required_len = offsetof(struct lustre_msg, lm_magic) +
720 if (len < required_len) {
721 /* can't even look inside the message */
722 CERROR("message length %d too small for magic/version check\n",
727 switch (m->lm_magic) {
728 case LUSTRE_MSG_MAGIC_V1:
729 case LUSTRE_MSG_MAGIC_V1_SWABBED:
730 rc = lustre_unpack_msg_v1(m, len);
732 case LUSTRE_MSG_MAGIC_V2:
733 case LUSTRE_MSG_MAGIC_V2_SWABBED:
734 rc = lustre_unpack_msg_v2(m, len);
737 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
744 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m)
746 struct ptlrpc_body *pb;
748 pb = lustre_swab_buf(m, MSG_PTLRPC_BODY_OFF, sizeof(*pb),
749 lustre_swab_ptlrpc_body);
751 CERROR("error unpacking ptlrpc body");
755 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
756 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
763 int lustre_unpack_ptlrpc_body(struct lustre_msg *m)
765 switch (m->lm_magic) {
766 case LUSTRE_MSG_MAGIC_V1:
767 case LUSTRE_MSG_MAGIC_V1_SWABBED:
769 case LUSTRE_MSG_MAGIC_V2:
770 case LUSTRE_MSG_MAGIC_V2_SWABBED:
771 return lustre_unpack_ptlrpc_body_v2(m);
773 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
778 static inline int lustre_msg_buflen_v1(void *msg, int n)
780 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
783 if (n >= m->lm_bufcount)
786 return m->lm_buflens[n];
789 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
791 if (n >= m->lm_bufcount)
794 return m->lm_buflens[n];
798 * lustre_msg_buflen - return the length of buffer @n in message @m
799 * @m - lustre_msg (request or reply) to look at
800 * @n - message index (base 0)
802 * returns zero for non-existent message indices
804 int lustre_msg_buflen(struct lustre_msg *m, int n)
806 switch (m->lm_magic) {
807 case LUSTRE_MSG_MAGIC_V1:
808 case LUSTRE_MSG_MAGIC_V1_SWABBED:
809 return lustre_msg_buflen_v1(m, n - 1);
810 case LUSTRE_MSG_MAGIC_V2:
811 case LUSTRE_MSG_MAGIC_V2_SWABBED:
812 return lustre_msg_buflen_v2(m, n);
814 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
818 EXPORT_SYMBOL(lustre_msg_buflen);
820 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
822 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
825 if (n >= m->lm_bufcount)
828 m->lm_buflens[n] = len;
832 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
834 if (n >= m->lm_bufcount)
837 m->lm_buflens[n] = len;
840 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
842 switch (m->lm_magic) {
843 case LUSTRE_MSG_MAGIC_V1:
844 case LUSTRE_MSG_MAGIC_V1_SWABBED:
845 lustre_msg_set_buflen_v1(m, n - 1, len);
847 case LUSTRE_MSG_MAGIC_V2:
848 case LUSTRE_MSG_MAGIC_V2_SWABBED:
849 lustre_msg_set_buflen_v2(m, n, len);
852 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
856 EXPORT_SYMBOL(lustre_msg_set_buflen);
858 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
859 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
860 int lustre_msg_bufcount(struct lustre_msg *m)
862 switch (m->lm_magic) {
863 case LUSTRE_MSG_MAGIC_V1:
864 case LUSTRE_MSG_MAGIC_V1_SWABBED:
865 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
866 case LUSTRE_MSG_MAGIC_V2:
867 case LUSTRE_MSG_MAGIC_V2_SWABBED:
868 return m->lm_bufcount;
870 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
874 EXPORT_SYMBOL(lustre_msg_bufcount);
876 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
878 /* max_len == 0 means the string should fill the buffer */
882 switch (m->lm_magic) {
883 case LUSTRE_MSG_MAGIC_V1:
884 case LUSTRE_MSG_MAGIC_V1_SWABBED:
885 str = lustre_msg_buf_v1(m, index - 1, 0);
886 blen = lustre_msg_buflen_v1(m, index - 1);
888 case LUSTRE_MSG_MAGIC_V2:
889 case LUSTRE_MSG_MAGIC_V2_SWABBED:
890 str = lustre_msg_buf_v2(m, index, 0);
891 blen = lustre_msg_buflen_v2(m, index);
894 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
898 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
902 slen = strnlen(str, blen);
904 if (slen == blen) { /* not NULL terminated */
905 CERROR("can't unpack non-NULL terminated string in "
906 "msg %p buffer[%d] len %d\n", m, index, blen);
911 if (slen != blen - 1) {
912 CERROR("can't unpack short string in msg %p "
913 "buffer[%d] len %d: strlen %d\n",
914 m, index, blen, slen);
917 } else if (slen > max_len) {
918 CERROR("can't unpack oversized string in msg %p "
919 "buffer[%d] len %d strlen %d: max %d expected\n",
920 m, index, blen, slen, max_len);
927 /* Wrap up the normal fixed length cases */
928 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
933 switch (msg->lm_magic) {
934 case LUSTRE_MSG_MAGIC_V1:
935 case LUSTRE_MSG_MAGIC_V1_SWABBED:
936 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
938 case LUSTRE_MSG_MAGIC_V2:
939 case LUSTRE_MSG_MAGIC_V2_SWABBED:
940 ptr = lustre_msg_buf_v2(msg, index, min_size);
943 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
948 if (swabber != NULL && lustre_msg_swabbed(msg))
949 ((void (*)(void *))swabber)(ptr);
954 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
957 LASSERT_REQSWAB(req, index);
958 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
961 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
964 LASSERT_REPSWAB(req, index);
965 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
968 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
970 switch (msg->lm_magic) {
971 case LUSTRE_MSG_MAGIC_V1:
972 case LUSTRE_MSG_MAGIC_V1_SWABBED:
973 return ((struct lustre_msg_v1 *)msg)->lm_flags &
975 case LUSTRE_MSG_MAGIC_V2:
976 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
977 struct ptlrpc_body *pb;
979 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
980 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
984 /* flags might be printed in debug code while message
990 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
992 switch (msg->lm_magic) {
993 case LUSTRE_MSG_MAGIC_V1:
994 ((struct lustre_msg_v1 *)msg)->lm_flags |=
995 MSG_GEN_FLAG_MASK & flags;
997 case LUSTRE_MSG_MAGIC_V2: {
998 struct ptlrpc_body *pb;
1000 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1001 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1002 pb->pb_flags |= flags;
1006 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1010 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
1012 switch (msg->lm_magic) {
1013 case LUSTRE_MSG_MAGIC_V1:
1014 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK;
1015 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1016 MSG_GEN_FLAG_MASK & flags;
1018 case LUSTRE_MSG_MAGIC_V2: {
1019 struct ptlrpc_body *pb;
1021 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1022 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1023 pb->pb_flags = flags;
1027 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1031 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1033 switch (msg->lm_magic) {
1034 case LUSTRE_MSG_MAGIC_V1:
1035 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1036 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1037 ~(MSG_GEN_FLAG_MASK & flags);
1039 case LUSTRE_MSG_MAGIC_V2:
1040 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1041 struct ptlrpc_body *pb;
1043 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1044 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1049 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1053 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1055 switch (msg->lm_magic) {
1056 case LUSTRE_MSG_MAGIC_V1:
1057 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1058 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1060 case LUSTRE_MSG_MAGIC_V2:
1061 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1062 struct ptlrpc_body *pb;
1064 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1065 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1066 return pb->pb_op_flags;
1073 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1075 switch (msg->lm_magic) {
1076 case LUSTRE_MSG_MAGIC_V1:
1077 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1078 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1080 case LUSTRE_MSG_MAGIC_V2: {
1081 struct ptlrpc_body *pb;
1083 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1084 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1085 pb->pb_op_flags |= flags;
1089 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1093 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
1095 switch (msg->lm_magic) {
1096 case LUSTRE_MSG_MAGIC_V1:
1097 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK;
1098 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1099 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1101 case LUSTRE_MSG_MAGIC_V2: {
1102 struct ptlrpc_body *pb;
1104 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1105 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1106 pb->pb_op_flags |= flags;
1110 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1114 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1116 switch (msg->lm_magic) {
1117 case LUSTRE_MSG_MAGIC_V1:
1118 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1119 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1120 case LUSTRE_MSG_MAGIC_V2:
1121 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1122 struct ptlrpc_body *pb;
1124 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1125 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1126 return &pb->pb_handle;
1129 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1134 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1136 switch (msg->lm_magic) {
1137 case LUSTRE_MSG_MAGIC_V1:
1138 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1139 return ((struct lustre_msg_v1 *)msg)->lm_type;
1140 case LUSTRE_MSG_MAGIC_V2:
1141 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1142 struct ptlrpc_body *pb;
1144 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1145 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1149 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1154 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1156 switch (msg->lm_magic) {
1157 case LUSTRE_MSG_MAGIC_V1:
1158 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1159 return ((struct lustre_msg_v1 *)msg)->lm_version;
1160 case LUSTRE_MSG_MAGIC_V2:
1161 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1162 struct ptlrpc_body *pb;
1164 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1165 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1166 return pb->pb_version;
1169 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1174 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1176 switch (msg->lm_magic) {
1177 case LUSTRE_MSG_MAGIC_V1:
1178 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1180 case LUSTRE_MSG_MAGIC_V2:
1181 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1182 struct ptlrpc_body *pb;
1184 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1185 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1186 pb->pb_version |= version;
1190 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1194 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1196 switch (msg->lm_magic) {
1197 case LUSTRE_MSG_MAGIC_V1:
1198 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1199 return ((struct lustre_msg_v1 *)msg)->lm_opc;
1200 case LUSTRE_MSG_MAGIC_V2:
1201 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1202 struct ptlrpc_body *pb;
1204 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1205 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1209 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1214 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1216 switch (msg->lm_magic) {
1217 case LUSTRE_MSG_MAGIC_V1:
1218 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1219 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1220 case LUSTRE_MSG_MAGIC_V2:
1221 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1222 struct ptlrpc_body *pb;
1224 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1225 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1226 return pb->pb_last_xid;
1229 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1234 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1236 switch (msg->lm_magic) {
1237 case LUSTRE_MSG_MAGIC_V1:
1238 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1239 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1240 case LUSTRE_MSG_MAGIC_V2:
1241 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1242 struct ptlrpc_body *pb;
1244 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1245 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1246 return pb->pb_last_committed;
1249 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1254 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1256 switch (msg->lm_magic) {
1257 case LUSTRE_MSG_MAGIC_V1:
1258 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1259 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1260 case LUSTRE_MSG_MAGIC_V2:
1261 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1262 struct ptlrpc_body *pb;
1264 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1265 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1266 return pb->pb_transno;
1269 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1274 __u32 lustre_msg_get_status(struct lustre_msg *msg)
1276 switch (msg->lm_magic) {
1277 case LUSTRE_MSG_MAGIC_V1:
1278 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1279 return ((struct lustre_msg_v1 *)msg)->lm_status;
1280 case LUSTRE_MSG_MAGIC_V2:
1281 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1282 struct ptlrpc_body *pb;
1284 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1285 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1286 return pb->pb_status;
1289 /* status might be printed in debug code while message
1295 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1297 switch (msg->lm_magic) {
1298 case LUSTRE_MSG_MAGIC_V1:
1299 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1300 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1301 case LUSTRE_MSG_MAGIC_V2:
1302 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1303 struct ptlrpc_body *pb;
1305 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1306 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1307 return pb->pb_conn_cnt;
1310 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1315 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1317 switch (msg->lm_magic) {
1318 case LUSTRE_MSG_MAGIC_V1:
1319 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1320 case LUSTRE_MSG_MAGIC_V2:
1321 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1322 return msg->lm_magic;
1324 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1329 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1331 switch (msg->lm_magic) {
1332 case LUSTRE_MSG_MAGIC_V1:
1333 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1335 case LUSTRE_MSG_MAGIC_V2: {
1336 struct ptlrpc_body *pb;
1338 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1339 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1340 pb->pb_handle = *handle;
1344 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1348 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1350 switch (msg->lm_magic) {
1351 case LUSTRE_MSG_MAGIC_V1:
1352 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1354 case LUSTRE_MSG_MAGIC_V2: {
1355 struct ptlrpc_body *pb;
1357 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1358 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1363 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1367 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1369 switch (msg->lm_magic) {
1370 case LUSTRE_MSG_MAGIC_V1:
1371 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1373 case LUSTRE_MSG_MAGIC_V2: {
1374 struct ptlrpc_body *pb;
1376 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1377 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1382 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1386 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1388 switch (msg->lm_magic) {
1389 case LUSTRE_MSG_MAGIC_V1:
1390 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1392 case LUSTRE_MSG_MAGIC_V2: {
1393 struct ptlrpc_body *pb;
1395 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1396 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1397 pb->pb_last_xid = last_xid;
1401 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1405 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1407 switch (msg->lm_magic) {
1408 case LUSTRE_MSG_MAGIC_V1:
1409 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1411 case LUSTRE_MSG_MAGIC_V2: {
1412 struct ptlrpc_body *pb;
1414 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1415 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1416 pb->pb_last_committed = last_committed;
1420 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1424 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1426 switch (msg->lm_magic) {
1427 case LUSTRE_MSG_MAGIC_V1:
1428 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1430 case LUSTRE_MSG_MAGIC_V2: {
1431 struct ptlrpc_body *pb;
1433 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1434 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1435 pb->pb_transno = transno;
1439 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1443 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1445 switch (msg->lm_magic) {
1446 case LUSTRE_MSG_MAGIC_V1:
1447 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1449 case LUSTRE_MSG_MAGIC_V2: {
1450 struct ptlrpc_body *pb;
1452 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1453 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1454 pb->pb_status = status;
1458 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1462 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1464 switch (msg->lm_magic) {
1465 case LUSTRE_MSG_MAGIC_V1:
1466 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1468 case LUSTRE_MSG_MAGIC_V2: {
1469 struct ptlrpc_body *pb;
1471 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1472 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1473 pb->pb_conn_cnt = conn_cnt;
1477 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1481 /* byte flipping routines for all wire types declared in
1482 * lustre_idl.h implemented here.
1484 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1486 __swab32s (&b->pb_type);
1487 __swab32s (&b->pb_version);
1488 __swab32s (&b->pb_opc);
1489 __swab32s (&b->pb_status);
1490 __swab64s (&b->pb_last_xid);
1491 __swab64s (&b->pb_last_committed);
1492 __swab64s (&b->pb_transno);
1493 __swab32s (&b->pb_flags);
1494 __swab32s (&b->pb_op_flags);
1495 __swab32s (&b->pb_conn_cnt);
1496 __swab32s (&b->pb_paddings[0]);
1497 __swab32s (&b->pb_paddings[1]);
1498 __swab32s (&b->pb_paddings[2]);
1501 void lustre_swab_connect(struct obd_connect_data *ocd)
1503 __swab64s(&ocd->ocd_connect_flags);
1504 __swab64s(&ocd->ocd_transno);
1505 __swab64s(&ocd->ocd_ibits_known);
1506 __swab32s(&ocd->ocd_version);
1507 __swab32s(&ocd->ocd_grant);
1508 __swab32s(&ocd->ocd_index);
1509 __swab32s(&ocd->ocd_brw_size);
1510 __swab32s(&ocd->ocd_nllu);
1511 __swab32s(&ocd->ocd_nllg);
1512 __swab32s(&ocd->ocd_group);
1513 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1514 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1515 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1518 void lustre_swab_obdo (struct obdo *o)
1520 __swab64s (&o->o_valid);
1521 __swab64s (&o->o_id);
1522 __swab64s (&o->o_gr);
1523 __swab64s (&o->o_fid);
1524 __swab64s (&o->o_size);
1525 __swab64s (&o->o_mtime);
1526 __swab64s (&o->o_atime);
1527 __swab64s (&o->o_ctime);
1528 __swab64s (&o->o_blocks);
1529 __swab64s (&o->o_grant);
1530 __swab32s (&o->o_blksize);
1531 __swab32s (&o->o_mode);
1532 __swab32s (&o->o_uid);
1533 __swab32s (&o->o_gid);
1534 __swab32s (&o->o_flags);
1535 __swab32s (&o->o_nlink);
1536 __swab32s (&o->o_generation);
1537 __swab32s (&o->o_misc);
1538 __swab32s (&o->o_easize);
1539 __swab32s (&o->o_mds);
1540 __swab32s (&o->o_stripe_idx);
1541 __swab32s (&o->o_padding_1);
1542 /* o_inline is opaque */
1545 void lustre_swab_obd_statfs (struct obd_statfs *os)
1547 __swab64s (&os->os_type);
1548 __swab64s (&os->os_blocks);
1549 __swab64s (&os->os_bfree);
1550 __swab64s (&os->os_bavail);
1551 __swab64s (&os->os_files);
1552 __swab64s (&os->os_ffree);
1553 /* no need to swab os_fsid */
1554 __swab32s (&os->os_bsize);
1555 __swab32s (&os->os_namelen);
1556 __swab64s (&os->os_maxbytes);
1557 __swab32s (&os->os_state);
1558 /* no need to swap os_spare */
1561 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1563 __swab64s (&ioo->ioo_id);
1564 __swab64s (&ioo->ioo_gr);
1565 __swab32s (&ioo->ioo_type);
1566 __swab32s (&ioo->ioo_bufcnt);
1569 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1571 __swab64s (&nbr->offset);
1572 __swab32s (&nbr->len);
1573 __swab32s (&nbr->flags);
1576 void lustre_swab_ost_body (struct ost_body *b)
1578 lustre_swab_obdo (&b->oa);
1581 void lustre_swab_ost_last_id(obd_id *id)
1586 void lustre_swab_generic_32s(__u32 *val)
1591 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1593 __swab64s(&lvb->lvb_size);
1594 __swab64s(&lvb->lvb_mtime);
1595 __swab64s(&lvb->lvb_atime);
1596 __swab64s(&lvb->lvb_ctime);
1597 __swab64s(&lvb->lvb_blocks);
1600 void lustre_swab_mds_status_req (struct mds_status_req *r)
1602 __swab32s (&r->flags);
1603 __swab32s (&r->repbuf);
1606 void lustre_swab_mds_body (struct mds_body *b)
1608 lustre_swab_ll_fid (&b->fid1);
1609 lustre_swab_ll_fid (&b->fid2);
1610 /* handle is opaque */
1611 __swab64s (&b->valid);
1612 __swab64s (&b->size);
1613 __swab64s (&b->mtime);
1614 __swab64s (&b->atime);
1615 __swab64s (&b->ctime);
1616 __swab64s (&b->blocks);
1617 __swab64s (&b->io_epoch);
1618 __swab64s (&b->ino);
1619 __swab32s (&b->fsuid);
1620 __swab32s (&b->fsgid);
1621 __swab32s (&b->capability);
1622 __swab32s (&b->mode);
1623 __swab32s (&b->uid);
1624 __swab32s (&b->gid);
1625 __swab32s (&b->flags);
1626 __swab32s (&b->rdev);
1627 __swab32s (&b->nlink);
1628 __swab32s (&b->generation);
1629 __swab32s (&b->suppgid);
1630 __swab32s (&b->eadatasize);
1631 __swab32s (&b->aclsize);
1632 __swab32s (&b->max_mdsize);
1633 __swab32s (&b->max_cookiesize);
1634 __swab32s (&b->padding_4);
1637 void lustre_swab_mdt_body (struct mdt_body *b)
1639 lustre_swab_lu_fid (&b->fid1);
1640 lustre_swab_lu_fid (&b->fid2);
1641 /* handle is opaque */
1642 __swab64s (&b->valid);
1643 __swab64s (&b->size);
1644 __swab64s (&b->mtime);
1645 __swab64s (&b->atime);
1646 __swab64s (&b->ctime);
1647 __swab64s (&b->blocks);
1648 __swab64s (&b->ioepoch);
1649 __swab32s (&b->fsuid);
1650 __swab32s (&b->fsgid);
1651 __swab32s (&b->capability);
1652 __swab32s (&b->mode);
1653 __swab32s (&b->uid);
1654 __swab32s (&b->gid);
1655 __swab32s (&b->flags);
1656 __swab32s (&b->rdev);
1657 __swab32s (&b->nlink);
1658 __swab32s (&b->suppgid);
1659 __swab32s (&b->eadatasize);
1660 __swab32s (&b->aclsize);
1661 __swab32s (&b->max_mdsize);
1662 __swab32s (&b->max_cookiesize);
1665 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1667 /* handle is opaque */
1668 __swab64s (&b->ioepoch);
1669 __swab32s (&b->flags);
1672 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1675 __swab32s(&mti->mti_lustre_ver);
1676 __swab32s(&mti->mti_stripe_index);
1677 __swab32s(&mti->mti_config_ver);
1678 __swab32s(&mti->mti_flags);
1679 __swab32s(&mti->mti_nid_count);
1680 LASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1681 for (i = 0; i < MTI_NIDS_MAX; i++)
1682 __swab64s(&mti->mti_nids[i]);
1685 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1687 __swab64s (&i->dqi_bgrace);
1688 __swab64s (&i->dqi_igrace);
1689 __swab32s (&i->dqi_flags);
1690 __swab32s (&i->dqi_valid);
1693 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1695 __swab64s (&b->dqb_ihardlimit);
1696 __swab64s (&b->dqb_isoftlimit);
1697 __swab64s (&b->dqb_curinodes);
1698 __swab64s (&b->dqb_bhardlimit);
1699 __swab64s (&b->dqb_bsoftlimit);
1700 __swab64s (&b->dqb_curspace);
1701 __swab64s (&b->dqb_btime);
1702 __swab64s (&b->dqb_itime);
1703 __swab32s (&b->dqb_valid);
1704 CLASSERT(offsetof(typeof(*b), padding) != 0);
1707 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1709 __swab32s (&q->qc_cmd);
1710 __swab32s (&q->qc_type);
1711 __swab32s (&q->qc_id);
1712 __swab32s (&q->qc_stat);
1713 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1714 lustre_swab_obd_dqblk (&q->qc_dqblk);
1717 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1719 __swab32s (&p->rp_uid);
1720 __swab32s (&p->rp_gid);
1721 __swab32s (&p->rp_fsuid);
1722 __swab32s (&p->rp_fsgid);
1723 __swab32s (&p->rp_access_perm);
1726 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1728 __swab32s (&p->rp_uid);
1729 __swab32s (&p->rp_gid);
1730 __swab32s (&p->rp_fsuid);
1731 __swab32s (&p->rp_fsgid);
1732 __swab32s (&p->rp_access_perm);
1735 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1737 __swab32s (&sa->sa_opcode);
1738 __swab32s (&sa->sa_fsuid);
1739 __swab32s (&sa->sa_fsgid);
1740 __swab32s (&sa->sa_cap);
1741 __swab32s (&sa->sa_suppgid);
1742 __swab32s (&sa->sa_mode);
1743 lustre_swab_ll_fid (&sa->sa_fid);
1744 __swab64s (&sa->sa_valid);
1745 __swab64s (&sa->sa_size);
1746 __swab64s (&sa->sa_mtime);
1747 __swab64s (&sa->sa_atime);
1748 __swab64s (&sa->sa_ctime);
1749 __swab32s (&sa->sa_uid);
1750 __swab32s (&sa->sa_gid);
1751 __swab32s (&sa->sa_attr_flags);
1752 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1755 void lustre_swab_mdt_rec_setattr (struct mdt_rec_setattr *sa)
1757 __swab32s (&sa->sa_opcode);
1758 __swab32s (&sa->sa_fsuid);
1759 __swab32s (&sa->sa_fsgid);
1760 __swab32s (&sa->sa_cap);
1761 __swab32s (&sa->sa_suppgid);
1762 __swab32s (&sa->sa_mode);
1763 lustre_swab_lu_fid (&sa->sa_fid);
1764 __swab64s (&sa->sa_valid);
1765 __swab64s (&sa->sa_size);
1766 __swab64s (&sa->sa_blocks);
1767 __swab64s (&sa->sa_mtime);
1768 __swab64s (&sa->sa_atime);
1769 __swab64s (&sa->sa_ctime);
1770 __swab32s (&sa->sa_uid);
1771 __swab32s (&sa->sa_gid);
1772 __swab32s (&sa->sa_attr_flags);
1773 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1776 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1778 __swab64s(&jr->jr_headsize);
1779 lustre_swab_ll_fid(&jr->jr_fid);
1782 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1784 __swab64s(&jr->jr_headsize);
1785 lustre_swab_lu_fid(&jr->jr_fid);
1788 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1790 __swab32s (&cr->cr_opcode);
1791 __swab32s (&cr->cr_fsuid);
1792 __swab32s (&cr->cr_fsgid);
1793 __swab32s (&cr->cr_cap);
1794 __swab32s (&cr->cr_flags); /* for use with open */
1795 __swab32s (&cr->cr_mode);
1796 lustre_swab_ll_fid (&cr->cr_fid);
1797 lustre_swab_ll_fid (&cr->cr_replayfid);
1798 __swab64s (&cr->cr_time);
1799 __swab64s (&cr->cr_rdev);
1800 __swab32s (&cr->cr_suppgid);
1801 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1802 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1803 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1804 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1805 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1808 void lustre_swab_mdt_rec_create (struct mdt_rec_create *cr)
1810 __swab32s (&cr->cr_opcode);
1811 __swab32s (&cr->cr_fsuid);
1812 __swab32s (&cr->cr_fsgid);
1813 __swab32s (&cr->cr_cap);
1814 __swab32s (&cr->cr_flags); /* for use with open */
1815 __swab32s (&cr->cr_mode);
1816 lustre_swab_lu_fid (&cr->cr_fid1);
1817 lustre_swab_lu_fid (&cr->cr_fid2);
1818 __swab64s (&cr->cr_time);
1819 __swab64s (&cr->cr_rdev);
1820 __swab64s (&cr->cr_ioepoch);
1821 __swab32s (&cr->cr_suppgid);
1822 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1823 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1824 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1827 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1829 __swab32s (&lk->lk_opcode);
1830 __swab32s (&lk->lk_fsuid);
1831 __swab32s (&lk->lk_fsgid);
1832 __swab32s (&lk->lk_cap);
1833 __swab32s (&lk->lk_suppgid1);
1834 __swab32s (&lk->lk_suppgid2);
1835 lustre_swab_ll_fid (&lk->lk_fid1);
1836 lustre_swab_ll_fid (&lk->lk_fid2);
1837 __swab64s (&lk->lk_time);
1838 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1839 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1840 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1841 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1844 void lustre_swab_mdt_rec_link (struct mdt_rec_link *lk)
1846 __swab32s (&lk->lk_opcode);
1847 __swab32s (&lk->lk_fsuid);
1848 __swab32s (&lk->lk_fsgid);
1849 __swab32s (&lk->lk_cap);
1850 __swab32s (&lk->lk_suppgid1);
1851 __swab32s (&lk->lk_suppgid2);
1852 lustre_swab_lu_fid (&lk->lk_fid1);
1853 lustre_swab_lu_fid (&lk->lk_fid2);
1854 __swab64s (&lk->lk_time);
1855 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1856 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1857 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1858 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1861 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1863 __swab32s (&ul->ul_opcode);
1864 __swab32s (&ul->ul_fsuid);
1865 __swab32s (&ul->ul_fsgid);
1866 __swab32s (&ul->ul_cap);
1867 __swab32s (&ul->ul_suppgid);
1868 __swab32s (&ul->ul_mode);
1869 lustre_swab_ll_fid (&ul->ul_fid1);
1870 lustre_swab_ll_fid (&ul->ul_fid2);
1871 __swab64s (&ul->ul_time);
1872 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1873 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1874 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1875 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1878 void lustre_swab_mdt_rec_unlink (struct mdt_rec_unlink *ul)
1880 __swab32s (&ul->ul_opcode);
1881 __swab32s (&ul->ul_fsuid);
1882 __swab32s (&ul->ul_fsgid);
1883 __swab32s (&ul->ul_cap);
1884 __swab32s (&ul->ul_suppgid);
1885 __swab32s (&ul->ul_mode);
1886 lustre_swab_lu_fid (&ul->ul_fid1);
1887 lustre_swab_lu_fid (&ul->ul_fid2);
1888 __swab64s (&ul->ul_time);
1889 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1890 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1891 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1892 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1895 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1897 __swab32s (&rn->rn_opcode);
1898 __swab32s (&rn->rn_fsuid);
1899 __swab32s (&rn->rn_fsgid);
1900 __swab32s (&rn->rn_cap);
1901 __swab32s (&rn->rn_suppgid1);
1902 __swab32s (&rn->rn_suppgid2);
1903 lustre_swab_ll_fid (&rn->rn_fid1);
1904 lustre_swab_ll_fid (&rn->rn_fid2);
1905 __swab64s (&rn->rn_time);
1906 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1907 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1908 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1909 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1912 void lustre_swab_mdt_rec_rename (struct mdt_rec_rename *rn)
1914 __swab32s (&rn->rn_opcode);
1915 __swab32s (&rn->rn_fsuid);
1916 __swab32s (&rn->rn_fsgid);
1917 __swab32s (&rn->rn_cap);
1918 __swab32s (&rn->rn_suppgid1);
1919 __swab32s (&rn->rn_suppgid2);
1920 lustre_swab_lu_fid (&rn->rn_fid1);
1921 lustre_swab_lu_fid (&rn->rn_fid2);
1922 __swab64s (&rn->rn_time);
1923 __swab32s (&rn->rn_mode);
1924 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1925 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1926 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1929 void lustre_swab_lov_desc (struct lov_desc *ld)
1931 __swab32s (&ld->ld_tgt_count);
1932 __swab32s (&ld->ld_active_tgt_count);
1933 __swab32s (&ld->ld_default_stripe_count);
1934 __swab64s (&ld->ld_default_stripe_size);
1935 __swab64s (&ld->ld_default_stripe_offset);
1936 __swab32s (&ld->ld_pattern);
1937 __swab32s (&ld->ld_qos_maxage);
1938 /* uuid endian insensitive */
1941 /*begin adding MDT by huanghua@clusterfs.com*/
1942 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1944 __swab32s (&ld->ld_tgt_count);
1945 __swab32s (&ld->ld_active_tgt_count);
1946 /* uuid endian insensitive */
1948 /*end adding MDT by huanghua@clusterfs.com*/
1949 void lustre_swab_md_fld (struct md_fld *mf)
1951 __swab64s(&mf->mf_seq);
1952 __swab64s(&mf->mf_mds);
1955 static void print_lum (struct lov_user_md *lum)
1957 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1958 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1959 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1960 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1961 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
1962 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1963 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1964 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1967 void lustre_swab_lov_user_md(struct lov_user_md *lum)
1970 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
1971 __swab32s(&lum->lmm_magic);
1972 __swab32s(&lum->lmm_pattern);
1973 __swab64s(&lum->lmm_object_id);
1974 __swab64s(&lum->lmm_object_gr);
1975 __swab32s(&lum->lmm_stripe_size);
1976 __swab16s(&lum->lmm_stripe_count);
1977 __swab16s(&lum->lmm_stripe_offset);
1982 static void print_lumj (struct lov_user_md_join *lumj)
1984 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
1985 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
1986 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
1987 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
1988 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
1989 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
1990 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
1991 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
1994 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
1997 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
1998 __swab32s(&lumj->lmm_magic);
1999 __swab32s(&lumj->lmm_pattern);
2000 __swab64s(&lumj->lmm_object_id);
2001 __swab64s(&lumj->lmm_object_gr);
2002 __swab32s(&lumj->lmm_stripe_size);
2003 __swab32s(&lumj->lmm_stripe_count);
2004 __swab32s(&lumj->lmm_extent_count);
2009 static void print_lum_objs(struct lov_user_md *lum)
2011 struct lov_user_ost_data *lod;
2014 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2016 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2017 for (i = 0; i < lum->lmm_stripe_count; i++) {
2018 lod = &lum->lmm_objects[i];
2019 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2020 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2021 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2022 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2027 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2029 struct lov_user_ost_data *lod;
2032 for (i = 0; i < lum->lmm_stripe_count; i++) {
2033 lod = &lum->lmm_objects[i];
2034 __swab64s(&lod->l_object_id);
2035 __swab64s(&lod->l_object_gr);
2036 __swab32s(&lod->l_ost_gen);
2037 __swab32s(&lod->l_ost_idx);
2039 print_lum_objs(lum);
2044 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2046 struct lov_ost_data *lod;
2049 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2050 lod = &lmm->lmm_objects[i];
2051 __swab64s(&lod->l_object_id);
2052 __swab64s(&lod->l_object_gr);
2053 __swab32s(&lod->l_ost_gen);
2054 __swab32s(&lod->l_ost_idx);
2056 __swab32s(&lmm->lmm_magic);
2057 __swab32s(&lmm->lmm_pattern);
2058 __swab64s(&lmm->lmm_object_id);
2059 __swab64s(&lmm->lmm_object_gr);
2060 __swab32s(&lmm->lmm_stripe_size);
2061 __swab32s(&lmm->lmm_stripe_count);
2067 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2071 for (i = 0; i < RES_NAME_SIZE; i++)
2072 __swab64s (&id->name[i]);
2075 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2077 /* the lock data is a union and the first two fields are always an
2078 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2079 * data the same way. */
2080 __swab64s(&d->l_extent.start);
2081 __swab64s(&d->l_extent.end);
2082 __swab64s(&d->l_extent.gid);
2083 __swab32s(&d->l_flock.pid);
2086 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2088 __swab64s (&i->opc);
2091 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2093 __swab32s (&r->lr_type);
2094 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2095 lustre_swab_ldlm_res_id (&r->lr_name);
2098 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2100 lustre_swab_ldlm_resource_desc (&l->l_resource);
2101 __swab32s (&l->l_req_mode);
2102 __swab32s (&l->l_granted_mode);
2103 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2106 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2108 __swab32s (&rq->lock_flags);
2109 CLASSERT(offsetof(typeof(*rq), lock_padding) != 0);
2110 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2111 /* lock_handle1 opaque */
2112 /* lock_handle2 opaque */
2115 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2117 __swab32s (&r->lock_flags);
2118 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2119 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2120 /* lock_handle opaque */
2121 __swab64s (&r->lock_policy_res1);
2122 __swab64s (&r->lock_policy_res2);
2125 /* no one calls this */
2126 int llog_log_swabbed(struct llog_log_hdr *hdr)
2128 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2130 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2135 void lustre_swab_qdata(struct qunit_data *d)
2137 __swab32s (&d->qd_id);
2138 __swab32s (&d->qd_flags);
2139 __swab64s (&d->qd_count);
2142 void lustre_swab_qdata_old(struct qunit_data_old *d)
2144 __swab32s (&d->qd_id);
2145 __swab32s (&d->qd_type);
2146 __swab32s (&d->qd_count);
2147 __swab32s (&d->qd_isblk);
2151 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2153 struct qunit_data_old tmp;
2154 struct qunit_data *ret;
2161 ret = (struct qunit_data *)d;
2162 ret->qd_id = tmp.qd_id;
2163 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2164 ret->qd_count = tmp.qd_count;
2168 EXPORT_SYMBOL(lustre_quota_old_to_new);
2170 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2172 struct qunit_data tmp;
2173 struct qunit_data_old *ret;
2179 LASSERT(d->qd_count <= MAX_QUOTA_COUNT32);
2181 ret = (struct qunit_data_old *)d;
2182 ret->qd_id = tmp.qd_id;
2183 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2184 ret->qd_count = (__u32)tmp.qd_count;
2185 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2188 EXPORT_SYMBOL(lustre_quota_new_to_old);
2189 #endif /* __KERNEL__ */
2192 void cdebug_va(cfs_debug_limit_state_t *cdls, __u32 mask,
2193 const char *file, const char *func, const int line,
2194 const char *fmt, va_list args);
2195 void cdebug(cfs_debug_limit_state_t *cdls, __u32 mask,
2196 const char *file, const char *func, const int line,
2197 const char *fmt, ...);
2199 void debug_req(cfs_debug_limit_state_t *cdls,
2200 __u32 level, struct ptlrpc_request *req,
2201 const char *file, const char *func, const int line,
2202 const char *fmt, ...)
2206 va_start(args, fmt);
2207 cdebug_va(cdls, level, file, func, line, fmt, args);
2210 cdebug(cdls, level, file, func, line,
2211 " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d lens %d/%d ref %d fl "
2212 REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2213 req, req->rq_xid, req->rq_transno,
2214 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2215 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2217 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2219 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2221 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2222 (req->rq_import && req->rq_import->imp_client) ?
2223 req->rq_import->imp_client->cli_request_portal : -1,
2224 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2225 DEBUG_REQ_FLAGS(req),
2226 req->rq_reqmsg ? lustre_msg_get_flags(req->rq_reqmsg) : 0,
2227 req->rq_repmsg ? lustre_msg_get_flags(req->rq_repmsg) : 0,
2229 req->rq_repmsg ? lustre_msg_get_status(req->rq_repmsg) : 0);
2231 EXPORT_SYMBOL(debug_req);
2233 void lustre_swab_lustre_capa(struct lustre_capa *c)
2235 lustre_swab_lu_fid(&c->lc_fid);
2236 __swab64s (&c->lc_opc);
2237 __swab32s (&c->lc_flags);
2238 __swab32s (&c->lc_keyid);
2239 __swab64s (&c->lc_expiry);
2242 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2244 __swab64s (&k->lk_mdsid);
2245 __swab32s (&k->lk_keyid);
2246 __swab32s (&k->lk_padding);