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;
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);
690 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
691 if (len < required_len) {
692 /* didn't receive all the buffer lengths */
693 CERROR ("message length %d too small for %d buflens\n",
694 len, m->lm_bufcount);
698 for (i = 0; i < m->lm_bufcount; i++) {
700 __swab32s(&m->lm_buflens[i]);
701 required_len += size_round(m->lm_buflens[i]);
704 if (len < required_len) {
705 CERROR("len: %d, required_len %d\n", len, required_len);
706 CERROR("bufcount: %d\n", m->lm_bufcount);
707 for (i = 0; i < m->lm_bufcount; i++)
708 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
715 int lustre_unpack_msg(struct lustre_msg *m, int len)
717 int required_len, rc;
720 /* We can provide a slightly better error log, if we check the
721 * message magic and version first. In the future, struct
722 * lustre_msg may grow, and we'd like to log a version mismatch,
723 * rather than a short message.
726 required_len = offsetof(struct lustre_msg, lm_magic) +
728 if (len < required_len) {
729 /* can't even look inside the message */
730 CERROR("message length %d too small for magic/version check\n",
735 switch (m->lm_magic) {
736 case LUSTRE_MSG_MAGIC_V1:
737 case LUSTRE_MSG_MAGIC_V1_SWABBED:
738 rc = lustre_unpack_msg_v1(m, len);
740 case LUSTRE_MSG_MAGIC_V2:
741 case LUSTRE_MSG_MAGIC_V2_SWABBED:
742 rc = lustre_unpack_msg_v2(m, len);
745 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
752 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m)
754 struct ptlrpc_body *pb;
756 pb = lustre_swab_buf(m, MSG_PTLRPC_BODY_OFF, sizeof(*pb),
757 lustre_swab_ptlrpc_body);
759 CERROR("error unpacking ptlrpc body");
763 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
764 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
771 int lustre_unpack_ptlrpc_body(struct lustre_msg *m)
773 switch (m->lm_magic) {
774 case LUSTRE_MSG_MAGIC_V1:
775 case LUSTRE_MSG_MAGIC_V1_SWABBED:
777 case LUSTRE_MSG_MAGIC_V2:
778 case LUSTRE_MSG_MAGIC_V2_SWABBED:
779 return lustre_unpack_ptlrpc_body_v2(m);
781 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
786 static inline int lustre_msg_buflen_v1(void *msg, int n)
788 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
791 if (n >= m->lm_bufcount)
794 return m->lm_buflens[n];
797 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
799 if (n >= m->lm_bufcount)
802 return m->lm_buflens[n];
806 * lustre_msg_buflen - return the length of buffer @n in message @m
807 * @m - lustre_msg (request or reply) to look at
808 * @n - message index (base 0)
810 * returns zero for non-existent message indices
812 int lustre_msg_buflen(struct lustre_msg *m, int n)
814 switch (m->lm_magic) {
815 case LUSTRE_MSG_MAGIC_V1:
816 case LUSTRE_MSG_MAGIC_V1_SWABBED:
817 return lustre_msg_buflen_v1(m, n - 1);
818 case LUSTRE_MSG_MAGIC_V2:
819 case LUSTRE_MSG_MAGIC_V2_SWABBED:
820 return lustre_msg_buflen_v2(m, n);
822 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
826 EXPORT_SYMBOL(lustre_msg_buflen);
828 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
830 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
833 if (n >= m->lm_bufcount)
836 m->lm_buflens[n] = len;
840 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
842 if (n >= m->lm_bufcount)
845 m->lm_buflens[n] = len;
848 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
850 switch (m->lm_magic) {
851 case LUSTRE_MSG_MAGIC_V1:
852 case LUSTRE_MSG_MAGIC_V1_SWABBED:
853 lustre_msg_set_buflen_v1(m, n - 1, len);
855 case LUSTRE_MSG_MAGIC_V2:
856 case LUSTRE_MSG_MAGIC_V2_SWABBED:
857 lustre_msg_set_buflen_v2(m, n, len);
860 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
864 EXPORT_SYMBOL(lustre_msg_set_buflen);
866 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
867 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
868 int lustre_msg_bufcount(struct lustre_msg *m)
870 switch (m->lm_magic) {
871 case LUSTRE_MSG_MAGIC_V1:
872 case LUSTRE_MSG_MAGIC_V1_SWABBED:
873 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
874 case LUSTRE_MSG_MAGIC_V2:
875 case LUSTRE_MSG_MAGIC_V2_SWABBED:
876 return m->lm_bufcount;
878 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
882 EXPORT_SYMBOL(lustre_msg_bufcount);
884 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
886 /* max_len == 0 means the string should fill the buffer */
890 switch (m->lm_magic) {
891 case LUSTRE_MSG_MAGIC_V1:
892 case LUSTRE_MSG_MAGIC_V1_SWABBED:
893 str = lustre_msg_buf_v1(m, index - 1, 0);
894 blen = lustre_msg_buflen_v1(m, index - 1);
896 case LUSTRE_MSG_MAGIC_V2:
897 case LUSTRE_MSG_MAGIC_V2_SWABBED:
898 str = lustre_msg_buf_v2(m, index, 0);
899 blen = lustre_msg_buflen_v2(m, index);
902 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
906 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
910 slen = strnlen(str, blen);
912 if (slen == blen) { /* not NULL terminated */
913 CERROR("can't unpack non-NULL terminated string in "
914 "msg %p buffer[%d] len %d\n", m, index, blen);
919 if (slen != blen - 1) {
920 CERROR("can't unpack short string in msg %p "
921 "buffer[%d] len %d: strlen %d\n",
922 m, index, blen, slen);
925 } else if (slen > max_len) {
926 CERROR("can't unpack oversized string in msg %p "
927 "buffer[%d] len %d strlen %d: max %d expected\n",
928 m, index, blen, slen, max_len);
935 /* Wrap up the normal fixed length cases */
936 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
941 switch (msg->lm_magic) {
942 case LUSTRE_MSG_MAGIC_V1:
943 case LUSTRE_MSG_MAGIC_V1_SWABBED:
944 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
946 case LUSTRE_MSG_MAGIC_V2:
947 case LUSTRE_MSG_MAGIC_V2_SWABBED:
948 ptr = lustre_msg_buf_v2(msg, index, min_size);
951 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
956 if (swabber != NULL && lustre_msg_swabbed(msg))
957 ((void (*)(void *))swabber)(ptr);
962 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
965 LASSERT_REQSWAB(req, index);
966 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
969 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
972 LASSERT_REPSWAB(req, index);
973 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
976 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
978 switch (msg->lm_magic) {
979 case LUSTRE_MSG_MAGIC_V1:
980 case LUSTRE_MSG_MAGIC_V1_SWABBED:
981 return ((struct lustre_msg_v1 *)msg)->lm_flags &
983 case LUSTRE_MSG_MAGIC_V2:
984 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
985 struct ptlrpc_body *pb;
987 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
988 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
992 /* flags might be printed in debug code while message
998 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
1000 switch (msg->lm_magic) {
1001 case LUSTRE_MSG_MAGIC_V1:
1002 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1003 MSG_GEN_FLAG_MASK & flags;
1005 case LUSTRE_MSG_MAGIC_V2: {
1006 struct ptlrpc_body *pb;
1008 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1009 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1010 pb->pb_flags |= flags;
1014 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1018 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
1020 switch (msg->lm_magic) {
1021 case LUSTRE_MSG_MAGIC_V1:
1022 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK;
1023 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1024 MSG_GEN_FLAG_MASK & flags;
1026 case LUSTRE_MSG_MAGIC_V2: {
1027 struct ptlrpc_body *pb;
1029 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1030 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1031 pb->pb_flags = flags;
1035 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1039 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1041 switch (msg->lm_magic) {
1042 case LUSTRE_MSG_MAGIC_V1:
1043 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1044 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1045 ~(MSG_GEN_FLAG_MASK & flags);
1047 case LUSTRE_MSG_MAGIC_V2:
1048 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1049 struct ptlrpc_body *pb;
1051 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1052 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1057 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1061 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1063 switch (msg->lm_magic) {
1064 case LUSTRE_MSG_MAGIC_V1:
1065 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1066 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1068 case LUSTRE_MSG_MAGIC_V2:
1069 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1070 struct ptlrpc_body *pb;
1072 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1073 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1074 return pb->pb_op_flags;
1081 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1083 switch (msg->lm_magic) {
1084 case LUSTRE_MSG_MAGIC_V1:
1085 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1086 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1088 case LUSTRE_MSG_MAGIC_V2: {
1089 struct ptlrpc_body *pb;
1091 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1092 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1093 pb->pb_op_flags |= flags;
1097 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1101 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
1103 switch (msg->lm_magic) {
1104 case LUSTRE_MSG_MAGIC_V1:
1105 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK;
1106 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1107 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1109 case LUSTRE_MSG_MAGIC_V2: {
1110 struct ptlrpc_body *pb;
1112 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1113 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1114 pb->pb_op_flags |= flags;
1118 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1122 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1124 switch (msg->lm_magic) {
1125 case LUSTRE_MSG_MAGIC_V1:
1126 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1127 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1128 case LUSTRE_MSG_MAGIC_V2:
1129 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1130 struct ptlrpc_body *pb;
1132 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1133 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1134 return &pb->pb_handle;
1137 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1142 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1144 switch (msg->lm_magic) {
1145 case LUSTRE_MSG_MAGIC_V1:
1146 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1147 return ((struct lustre_msg_v1 *)msg)->lm_type;
1148 case LUSTRE_MSG_MAGIC_V2:
1149 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1150 struct ptlrpc_body *pb;
1152 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1153 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1157 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1162 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1164 switch (msg->lm_magic) {
1165 case LUSTRE_MSG_MAGIC_V1:
1166 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1167 return ((struct lustre_msg_v1 *)msg)->lm_version;
1168 case LUSTRE_MSG_MAGIC_V2:
1169 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1170 struct ptlrpc_body *pb;
1172 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1173 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1174 return pb->pb_version;
1177 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1182 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1184 switch (msg->lm_magic) {
1185 case LUSTRE_MSG_MAGIC_V1:
1186 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1188 case LUSTRE_MSG_MAGIC_V2:
1189 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1190 struct ptlrpc_body *pb;
1192 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1193 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1194 pb->pb_version |= version;
1198 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1202 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1204 switch (msg->lm_magic) {
1205 case LUSTRE_MSG_MAGIC_V1:
1206 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1207 return ((struct lustre_msg_v1 *)msg)->lm_opc;
1208 case LUSTRE_MSG_MAGIC_V2:
1209 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1210 struct ptlrpc_body *pb;
1212 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1213 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1217 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1222 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1224 switch (msg->lm_magic) {
1225 case LUSTRE_MSG_MAGIC_V1:
1226 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1227 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1228 case LUSTRE_MSG_MAGIC_V2:
1229 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1230 struct ptlrpc_body *pb;
1232 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1233 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1234 return pb->pb_last_xid;
1237 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1242 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1244 switch (msg->lm_magic) {
1245 case LUSTRE_MSG_MAGIC_V1:
1246 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1247 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1248 case LUSTRE_MSG_MAGIC_V2:
1249 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1250 struct ptlrpc_body *pb;
1252 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1253 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1254 return pb->pb_last_committed;
1257 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1262 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1264 switch (msg->lm_magic) {
1265 case LUSTRE_MSG_MAGIC_V1:
1266 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1267 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1268 case LUSTRE_MSG_MAGIC_V2:
1269 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1270 struct ptlrpc_body *pb;
1272 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1273 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1274 return pb->pb_transno;
1277 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1282 __u32 lustre_msg_get_status(struct lustre_msg *msg)
1284 switch (msg->lm_magic) {
1285 case LUSTRE_MSG_MAGIC_V1:
1286 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1287 return ((struct lustre_msg_v1 *)msg)->lm_status;
1288 case LUSTRE_MSG_MAGIC_V2:
1289 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1290 struct ptlrpc_body *pb;
1292 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1293 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1294 return pb->pb_status;
1297 /* status might be printed in debug code while message
1303 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1305 switch (msg->lm_magic) {
1306 case LUSTRE_MSG_MAGIC_V1:
1307 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1308 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1309 case LUSTRE_MSG_MAGIC_V2:
1310 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1311 struct ptlrpc_body *pb;
1313 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1314 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1315 return pb->pb_conn_cnt;
1318 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1323 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1325 switch (msg->lm_magic) {
1326 case LUSTRE_MSG_MAGIC_V1:
1327 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1328 case LUSTRE_MSG_MAGIC_V2:
1329 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1330 return msg->lm_magic;
1332 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1337 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1339 switch (msg->lm_magic) {
1340 case LUSTRE_MSG_MAGIC_V1:
1341 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1343 case LUSTRE_MSG_MAGIC_V2: {
1344 struct ptlrpc_body *pb;
1346 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1347 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1348 pb->pb_handle = *handle;
1352 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1356 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1358 switch (msg->lm_magic) {
1359 case LUSTRE_MSG_MAGIC_V1:
1360 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1362 case LUSTRE_MSG_MAGIC_V2: {
1363 struct ptlrpc_body *pb;
1365 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1366 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1371 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1375 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1377 switch (msg->lm_magic) {
1378 case LUSTRE_MSG_MAGIC_V1:
1379 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1381 case LUSTRE_MSG_MAGIC_V2: {
1382 struct ptlrpc_body *pb;
1384 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1385 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1390 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1394 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1396 switch (msg->lm_magic) {
1397 case LUSTRE_MSG_MAGIC_V1:
1398 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1400 case LUSTRE_MSG_MAGIC_V2: {
1401 struct ptlrpc_body *pb;
1403 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1404 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1405 pb->pb_last_xid = last_xid;
1409 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1413 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1415 switch (msg->lm_magic) {
1416 case LUSTRE_MSG_MAGIC_V1:
1417 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1419 case LUSTRE_MSG_MAGIC_V2: {
1420 struct ptlrpc_body *pb;
1422 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1423 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1424 pb->pb_last_committed = last_committed;
1428 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1432 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1434 switch (msg->lm_magic) {
1435 case LUSTRE_MSG_MAGIC_V1:
1436 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1438 case LUSTRE_MSG_MAGIC_V2: {
1439 struct ptlrpc_body *pb;
1441 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1442 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1443 pb->pb_transno = transno;
1447 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1451 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1453 switch (msg->lm_magic) {
1454 case LUSTRE_MSG_MAGIC_V1:
1455 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1457 case LUSTRE_MSG_MAGIC_V2: {
1458 struct ptlrpc_body *pb;
1460 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1461 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1462 pb->pb_status = status;
1466 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1470 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1472 switch (msg->lm_magic) {
1473 case LUSTRE_MSG_MAGIC_V1:
1474 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1476 case LUSTRE_MSG_MAGIC_V2: {
1477 struct ptlrpc_body *pb;
1479 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1480 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1481 pb->pb_conn_cnt = conn_cnt;
1485 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1489 /* byte flipping routines for all wire types declared in
1490 * lustre_idl.h implemented here.
1492 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1494 __swab32s (&b->pb_type);
1495 __swab32s (&b->pb_version);
1496 __swab32s (&b->pb_opc);
1497 __swab32s (&b->pb_status);
1498 __swab64s (&b->pb_last_xid);
1499 __swab64s (&b->pb_last_committed);
1500 __swab64s (&b->pb_transno);
1501 __swab32s (&b->pb_flags);
1502 __swab32s (&b->pb_op_flags);
1503 __swab32s (&b->pb_conn_cnt);
1504 __swab32s (&b->pb_paddings[0]);
1505 __swab32s (&b->pb_paddings[1]);
1506 __swab32s (&b->pb_paddings[2]);
1509 void lustre_swab_connect(struct obd_connect_data *ocd)
1511 __swab64s(&ocd->ocd_connect_flags);
1512 __swab64s(&ocd->ocd_transno);
1513 __swab64s(&ocd->ocd_ibits_known);
1514 __swab32s(&ocd->ocd_version);
1515 __swab32s(&ocd->ocd_grant);
1516 __swab32s(&ocd->ocd_index);
1517 __swab32s(&ocd->ocd_brw_size);
1518 __swab32s(&ocd->ocd_nllu);
1519 __swab32s(&ocd->ocd_nllg);
1520 __swab32s(&ocd->ocd_group);
1521 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1522 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1523 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1526 void lustre_swab_obdo (struct obdo *o)
1528 __swab64s (&o->o_valid);
1529 __swab64s (&o->o_id);
1530 __swab64s (&o->o_gr);
1531 __swab64s (&o->o_fid);
1532 __swab64s (&o->o_size);
1533 __swab64s (&o->o_mtime);
1534 __swab64s (&o->o_atime);
1535 __swab64s (&o->o_ctime);
1536 __swab64s (&o->o_blocks);
1537 __swab64s (&o->o_grant);
1538 __swab32s (&o->o_blksize);
1539 __swab32s (&o->o_mode);
1540 __swab32s (&o->o_uid);
1541 __swab32s (&o->o_gid);
1542 __swab32s (&o->o_flags);
1543 __swab32s (&o->o_nlink);
1544 __swab32s (&o->o_generation);
1545 __swab32s (&o->o_misc);
1546 __swab32s (&o->o_easize);
1547 __swab32s (&o->o_mds);
1548 __swab32s (&o->o_stripe_idx);
1549 __swab32s (&o->o_padding_1);
1550 /* o_inline is opaque */
1553 void lustre_swab_obd_statfs (struct obd_statfs *os)
1555 __swab64s (&os->os_type);
1556 __swab64s (&os->os_blocks);
1557 __swab64s (&os->os_bfree);
1558 __swab64s (&os->os_bavail);
1559 __swab64s (&os->os_files);
1560 __swab64s (&os->os_ffree);
1561 /* no need to swab os_fsid */
1562 __swab32s (&os->os_bsize);
1563 __swab32s (&os->os_namelen);
1564 __swab64s (&os->os_maxbytes);
1565 __swab32s (&os->os_state);
1566 /* no need to swap os_spare */
1569 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1571 __swab64s (&ioo->ioo_id);
1572 __swab64s (&ioo->ioo_gr);
1573 __swab32s (&ioo->ioo_type);
1574 __swab32s (&ioo->ioo_bufcnt);
1577 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1579 __swab64s (&nbr->offset);
1580 __swab32s (&nbr->len);
1581 __swab32s (&nbr->flags);
1584 void lustre_swab_ost_body (struct ost_body *b)
1586 lustre_swab_obdo (&b->oa);
1589 void lustre_swab_ost_last_id(obd_id *id)
1594 void lustre_swab_generic_32s(__u32 *val)
1599 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1601 __swab64s(&lvb->lvb_size);
1602 __swab64s(&lvb->lvb_mtime);
1603 __swab64s(&lvb->lvb_atime);
1604 __swab64s(&lvb->lvb_ctime);
1605 __swab64s(&lvb->lvb_blocks);
1608 void lustre_swab_mds_status_req (struct mds_status_req *r)
1610 __swab32s (&r->flags);
1611 __swab32s (&r->repbuf);
1614 void lustre_swab_mds_body (struct mds_body *b)
1616 lustre_swab_ll_fid (&b->fid1);
1617 lustre_swab_ll_fid (&b->fid2);
1618 /* handle is opaque */
1619 __swab64s (&b->valid);
1620 __swab64s (&b->size);
1621 __swab64s (&b->mtime);
1622 __swab64s (&b->atime);
1623 __swab64s (&b->ctime);
1624 __swab64s (&b->blocks);
1625 __swab64s (&b->io_epoch);
1626 __swab64s (&b->ino);
1627 __swab32s (&b->fsuid);
1628 __swab32s (&b->fsgid);
1629 __swab32s (&b->capability);
1630 __swab32s (&b->mode);
1631 __swab32s (&b->uid);
1632 __swab32s (&b->gid);
1633 __swab32s (&b->flags);
1634 __swab32s (&b->rdev);
1635 __swab32s (&b->nlink);
1636 __swab32s (&b->generation);
1637 __swab32s (&b->suppgid);
1638 __swab32s (&b->eadatasize);
1639 __swab32s (&b->aclsize);
1640 __swab32s (&b->max_mdsize);
1641 __swab32s (&b->max_cookiesize);
1642 __swab32s (&b->padding_4);
1645 void lustre_swab_mdt_body (struct mdt_body *b)
1647 lustre_swab_lu_fid (&b->fid1);
1648 lustre_swab_lu_fid (&b->fid2);
1649 /* handle is opaque */
1650 __swab64s (&b->valid);
1651 __swab64s (&b->size);
1652 __swab64s (&b->mtime);
1653 __swab64s (&b->atime);
1654 __swab64s (&b->ctime);
1655 __swab64s (&b->blocks);
1656 __swab64s (&b->ioepoch);
1657 __swab32s (&b->fsuid);
1658 __swab32s (&b->fsgid);
1659 __swab32s (&b->capability);
1660 __swab32s (&b->mode);
1661 __swab32s (&b->uid);
1662 __swab32s (&b->gid);
1663 __swab32s (&b->flags);
1664 __swab32s (&b->rdev);
1665 __swab32s (&b->nlink);
1666 __swab32s (&b->suppgid);
1667 __swab32s (&b->eadatasize);
1668 __swab32s (&b->aclsize);
1669 __swab32s (&b->max_mdsize);
1670 __swab32s (&b->max_cookiesize);
1673 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1675 /* handle is opaque */
1676 __swab64s (&b->ioepoch);
1677 __swab32s (&b->flags);
1680 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1683 __swab32s(&mti->mti_lustre_ver);
1684 __swab32s(&mti->mti_stripe_index);
1685 __swab32s(&mti->mti_config_ver);
1686 __swab32s(&mti->mti_flags);
1687 __swab32s(&mti->mti_nid_count);
1688 LASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1689 for (i = 0; i < MTI_NIDS_MAX; i++)
1690 __swab64s(&mti->mti_nids[i]);
1693 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1695 __swab64s (&i->dqi_bgrace);
1696 __swab64s (&i->dqi_igrace);
1697 __swab32s (&i->dqi_flags);
1698 __swab32s (&i->dqi_valid);
1701 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1703 __swab64s (&b->dqb_ihardlimit);
1704 __swab64s (&b->dqb_isoftlimit);
1705 __swab64s (&b->dqb_curinodes);
1706 __swab64s (&b->dqb_bhardlimit);
1707 __swab64s (&b->dqb_bsoftlimit);
1708 __swab64s (&b->dqb_curspace);
1709 __swab64s (&b->dqb_btime);
1710 __swab64s (&b->dqb_itime);
1711 __swab32s (&b->dqb_valid);
1712 CLASSERT(offsetof(typeof(*b), padding) != 0);
1715 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1717 __swab32s (&q->qc_cmd);
1718 __swab32s (&q->qc_type);
1719 __swab32s (&q->qc_id);
1720 __swab32s (&q->qc_stat);
1721 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1722 lustre_swab_obd_dqblk (&q->qc_dqblk);
1725 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1727 __swab32s (&p->rp_uid);
1728 __swab32s (&p->rp_gid);
1729 __swab32s (&p->rp_fsuid);
1730 __swab32s (&p->rp_fsgid);
1731 __swab32s (&p->rp_access_perm);
1734 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1736 __swab32s (&p->rp_uid);
1737 __swab32s (&p->rp_gid);
1738 __swab32s (&p->rp_fsuid);
1739 __swab32s (&p->rp_fsgid);
1740 __swab32s (&p->rp_access_perm);
1743 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1745 __swab32s (&sa->sa_opcode);
1746 __swab32s (&sa->sa_fsuid);
1747 __swab32s (&sa->sa_fsgid);
1748 __swab32s (&sa->sa_cap);
1749 __swab32s (&sa->sa_suppgid);
1750 __swab32s (&sa->sa_mode);
1751 lustre_swab_ll_fid (&sa->sa_fid);
1752 __swab64s (&sa->sa_valid);
1753 __swab64s (&sa->sa_size);
1754 __swab64s (&sa->sa_mtime);
1755 __swab64s (&sa->sa_atime);
1756 __swab64s (&sa->sa_ctime);
1757 __swab32s (&sa->sa_uid);
1758 __swab32s (&sa->sa_gid);
1759 __swab32s (&sa->sa_attr_flags);
1760 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1763 void lustre_swab_mdt_rec_setattr (struct mdt_rec_setattr *sa)
1765 __swab32s (&sa->sa_opcode);
1766 __swab32s (&sa->sa_fsuid);
1767 __swab32s (&sa->sa_fsgid);
1768 __swab32s (&sa->sa_cap);
1769 __swab32s (&sa->sa_suppgid);
1770 __swab32s (&sa->sa_mode);
1771 lustre_swab_lu_fid (&sa->sa_fid);
1772 __swab64s (&sa->sa_valid);
1773 __swab64s (&sa->sa_size);
1774 __swab64s (&sa->sa_blocks);
1775 __swab64s (&sa->sa_mtime);
1776 __swab64s (&sa->sa_atime);
1777 __swab64s (&sa->sa_ctime);
1778 __swab32s (&sa->sa_uid);
1779 __swab32s (&sa->sa_gid);
1780 __swab32s (&sa->sa_attr_flags);
1781 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1784 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1786 __swab64s(&jr->jr_headsize);
1787 lustre_swab_ll_fid(&jr->jr_fid);
1790 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1792 __swab64s(&jr->jr_headsize);
1793 lustre_swab_lu_fid(&jr->jr_fid);
1796 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1798 __swab32s (&cr->cr_opcode);
1799 __swab32s (&cr->cr_fsuid);
1800 __swab32s (&cr->cr_fsgid);
1801 __swab32s (&cr->cr_cap);
1802 __swab32s (&cr->cr_flags); /* for use with open */
1803 __swab32s (&cr->cr_mode);
1804 lustre_swab_ll_fid (&cr->cr_fid);
1805 lustre_swab_ll_fid (&cr->cr_replayfid);
1806 __swab64s (&cr->cr_time);
1807 __swab64s (&cr->cr_rdev);
1808 __swab32s (&cr->cr_suppgid);
1809 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1810 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1811 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1812 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1813 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1816 void lustre_swab_mdt_rec_create (struct mdt_rec_create *cr)
1818 __swab32s (&cr->cr_opcode);
1819 __swab32s (&cr->cr_fsuid);
1820 __swab32s (&cr->cr_fsgid);
1821 __swab32s (&cr->cr_cap);
1822 __swab32s (&cr->cr_flags); /* for use with open */
1823 __swab32s (&cr->cr_mode);
1824 /* handle is opaque */
1825 lustre_swab_lu_fid (&cr->cr_fid1);
1826 lustre_swab_lu_fid (&cr->cr_fid2);
1827 __swab64s (&cr->cr_time);
1828 __swab64s (&cr->cr_rdev);
1829 __swab64s (&cr->cr_ioepoch);
1830 __swab32s (&cr->cr_suppgid);
1831 __swab32s (&cr->cr_bias);
1834 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1836 __swab32s (&lk->lk_opcode);
1837 __swab32s (&lk->lk_fsuid);
1838 __swab32s (&lk->lk_fsgid);
1839 __swab32s (&lk->lk_cap);
1840 __swab32s (&lk->lk_suppgid1);
1841 __swab32s (&lk->lk_suppgid2);
1842 lustre_swab_ll_fid (&lk->lk_fid1);
1843 lustre_swab_ll_fid (&lk->lk_fid2);
1844 __swab64s (&lk->lk_time);
1845 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1846 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1847 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1848 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1851 void lustre_swab_mdt_rec_link (struct mdt_rec_link *lk)
1853 __swab32s (&lk->lk_opcode);
1854 __swab32s (&lk->lk_fsuid);
1855 __swab32s (&lk->lk_fsgid);
1856 __swab32s (&lk->lk_cap);
1857 __swab32s (&lk->lk_suppgid1);
1858 __swab32s (&lk->lk_suppgid2);
1859 lustre_swab_lu_fid (&lk->lk_fid1);
1860 lustre_swab_lu_fid (&lk->lk_fid2);
1861 __swab64s (&lk->lk_time);
1862 __swab32s (&lk->lk_bias);
1863 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1864 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1865 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1868 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1870 __swab32s (&ul->ul_opcode);
1871 __swab32s (&ul->ul_fsuid);
1872 __swab32s (&ul->ul_fsgid);
1873 __swab32s (&ul->ul_cap);
1874 __swab32s (&ul->ul_suppgid);
1875 __swab32s (&ul->ul_mode);
1876 lustre_swab_ll_fid (&ul->ul_fid1);
1877 lustre_swab_ll_fid (&ul->ul_fid2);
1878 __swab64s (&ul->ul_time);
1879 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1880 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1881 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1882 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1885 void lustre_swab_mdt_rec_unlink (struct mdt_rec_unlink *ul)
1887 __swab32s (&ul->ul_opcode);
1888 __swab32s (&ul->ul_fsuid);
1889 __swab32s (&ul->ul_fsgid);
1890 __swab32s (&ul->ul_cap);
1891 __swab32s (&ul->ul_suppgid);
1892 __swab32s (&ul->ul_mode);
1893 lustre_swab_lu_fid (&ul->ul_fid1);
1894 lustre_swab_lu_fid (&ul->ul_fid2);
1895 __swab64s (&ul->ul_time);
1896 __swab32s (&ul->ul_bias);
1897 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1898 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1899 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1902 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1904 __swab32s (&rn->rn_opcode);
1905 __swab32s (&rn->rn_fsuid);
1906 __swab32s (&rn->rn_fsgid);
1907 __swab32s (&rn->rn_cap);
1908 __swab32s (&rn->rn_suppgid1);
1909 __swab32s (&rn->rn_suppgid2);
1910 lustre_swab_ll_fid (&rn->rn_fid1);
1911 lustre_swab_ll_fid (&rn->rn_fid2);
1912 __swab64s (&rn->rn_time);
1913 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1914 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1915 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1916 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1919 void lustre_swab_mdt_rec_rename (struct mdt_rec_rename *rn)
1921 __swab32s (&rn->rn_opcode);
1922 __swab32s (&rn->rn_fsuid);
1923 __swab32s (&rn->rn_fsgid);
1924 __swab32s (&rn->rn_cap);
1925 __swab32s (&rn->rn_suppgid1);
1926 __swab32s (&rn->rn_suppgid2);
1927 lustre_swab_lu_fid (&rn->rn_fid1);
1928 lustre_swab_lu_fid (&rn->rn_fid2);
1929 __swab64s (&rn->rn_time);
1930 __swab32s (&rn->rn_mode);
1931 __swab32s (&rn->rn_bias);
1932 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1933 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1936 void lustre_swab_lov_desc (struct lov_desc *ld)
1938 __swab32s (&ld->ld_tgt_count);
1939 __swab32s (&ld->ld_active_tgt_count);
1940 __swab32s (&ld->ld_default_stripe_count);
1941 __swab64s (&ld->ld_default_stripe_size);
1942 __swab64s (&ld->ld_default_stripe_offset);
1943 __swab32s (&ld->ld_pattern);
1944 __swab32s (&ld->ld_qos_maxage);
1945 /* uuid endian insensitive */
1948 /*begin adding MDT by huanghua@clusterfs.com*/
1949 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1951 __swab32s (&ld->ld_tgt_count);
1952 __swab32s (&ld->ld_active_tgt_count);
1953 /* uuid endian insensitive */
1955 /*end adding MDT by huanghua@clusterfs.com*/
1956 void lustre_swab_md_fld (struct md_fld *mf)
1958 __swab64s(&mf->mf_seq);
1959 __swab64s(&mf->mf_mds);
1962 static void print_lum (struct lov_user_md *lum)
1964 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1965 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1966 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1967 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1968 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
1969 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1970 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1971 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1974 void lustre_swab_lov_user_md(struct lov_user_md *lum)
1977 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
1978 __swab32s(&lum->lmm_magic);
1979 __swab32s(&lum->lmm_pattern);
1980 __swab64s(&lum->lmm_object_id);
1981 __swab64s(&lum->lmm_object_gr);
1982 __swab32s(&lum->lmm_stripe_size);
1983 __swab16s(&lum->lmm_stripe_count);
1984 __swab16s(&lum->lmm_stripe_offset);
1989 static void print_lumj (struct lov_user_md_join *lumj)
1991 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
1992 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
1993 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
1994 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
1995 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
1996 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
1997 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
1998 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2001 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2004 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2005 __swab32s(&lumj->lmm_magic);
2006 __swab32s(&lumj->lmm_pattern);
2007 __swab64s(&lumj->lmm_object_id);
2008 __swab64s(&lumj->lmm_object_gr);
2009 __swab32s(&lumj->lmm_stripe_size);
2010 __swab32s(&lumj->lmm_stripe_count);
2011 __swab32s(&lumj->lmm_extent_count);
2016 static void print_lum_objs(struct lov_user_md *lum)
2018 struct lov_user_ost_data *lod;
2021 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2023 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2024 for (i = 0; i < lum->lmm_stripe_count; i++) {
2025 lod = &lum->lmm_objects[i];
2026 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2027 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2028 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2029 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2034 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2036 struct lov_user_ost_data *lod;
2039 for (i = 0; i < lum->lmm_stripe_count; i++) {
2040 lod = &lum->lmm_objects[i];
2041 __swab64s(&lod->l_object_id);
2042 __swab64s(&lod->l_object_gr);
2043 __swab32s(&lod->l_ost_gen);
2044 __swab32s(&lod->l_ost_idx);
2046 print_lum_objs(lum);
2051 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2053 struct lov_ost_data *lod;
2056 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2057 lod = &lmm->lmm_objects[i];
2058 __swab64s(&lod->l_object_id);
2059 __swab64s(&lod->l_object_gr);
2060 __swab32s(&lod->l_ost_gen);
2061 __swab32s(&lod->l_ost_idx);
2063 __swab32s(&lmm->lmm_magic);
2064 __swab32s(&lmm->lmm_pattern);
2065 __swab64s(&lmm->lmm_object_id);
2066 __swab64s(&lmm->lmm_object_gr);
2067 __swab32s(&lmm->lmm_stripe_size);
2068 __swab32s(&lmm->lmm_stripe_count);
2074 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2078 for (i = 0; i < RES_NAME_SIZE; i++)
2079 __swab64s (&id->name[i]);
2082 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2084 /* the lock data is a union and the first two fields are always an
2085 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2086 * data the same way. */
2087 __swab64s(&d->l_extent.start);
2088 __swab64s(&d->l_extent.end);
2089 __swab64s(&d->l_extent.gid);
2090 __swab32s(&d->l_flock.pid);
2093 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2095 __swab64s (&i->opc);
2098 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2100 __swab32s (&r->lr_type);
2101 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2102 lustre_swab_ldlm_res_id (&r->lr_name);
2105 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2107 lustre_swab_ldlm_resource_desc (&l->l_resource);
2108 __swab32s (&l->l_req_mode);
2109 __swab32s (&l->l_granted_mode);
2110 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2113 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2115 __swab32s (&rq->lock_flags);
2116 CLASSERT(offsetof(typeof(*rq), lock_padding) != 0);
2117 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2118 /* lock_handle1 opaque */
2119 /* lock_handle2 opaque */
2122 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2124 __swab32s (&r->lock_flags);
2125 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2126 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2127 /* lock_handle opaque */
2128 __swab64s (&r->lock_policy_res1);
2129 __swab64s (&r->lock_policy_res2);
2132 /* no one calls this */
2133 int llog_log_swabbed(struct llog_log_hdr *hdr)
2135 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2137 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2142 void lustre_swab_qdata(struct qunit_data *d)
2144 __swab32s (&d->qd_id);
2145 __swab32s (&d->qd_flags);
2146 __swab64s (&d->qd_count);
2149 void lustre_swab_qdata_old(struct qunit_data_old *d)
2151 __swab32s (&d->qd_id);
2152 __swab32s (&d->qd_type);
2153 __swab32s (&d->qd_count);
2154 __swab32s (&d->qd_isblk);
2158 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2160 struct qunit_data_old tmp;
2161 struct qunit_data *ret;
2168 ret = (struct qunit_data *)d;
2169 ret->qd_id = tmp.qd_id;
2170 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2171 ret->qd_count = tmp.qd_count;
2175 EXPORT_SYMBOL(lustre_quota_old_to_new);
2177 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2179 struct qunit_data tmp;
2180 struct qunit_data_old *ret;
2186 LASSERT(d->qd_count <= MAX_QUOTA_COUNT32);
2188 ret = (struct qunit_data_old *)d;
2189 ret->qd_id = tmp.qd_id;
2190 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2191 ret->qd_count = (__u32)tmp.qd_count;
2192 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2195 EXPORT_SYMBOL(lustre_quota_new_to_old);
2196 #endif /* __KERNEL__ */
2199 void cdebug_va(cfs_debug_limit_state_t *cdls, __u32 mask,
2200 const char *file, const char *func, const int line,
2201 const char *fmt, va_list args);
2202 void cdebug(cfs_debug_limit_state_t *cdls, __u32 mask,
2203 const char *file, const char *func, const int line,
2204 const char *fmt, ...);
2206 void debug_req(cfs_debug_limit_state_t *cdls,
2207 __u32 level, struct ptlrpc_request *req,
2208 const char *file, const char *func, const int line,
2209 const char *fmt, ...)
2213 va_start(args, fmt);
2214 cdebug_va(cdls, level, file, func, line, fmt, args);
2217 cdebug(cdls, level, file, func, line,
2218 " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d lens %d/%d ref %d fl "
2219 REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2220 req, req->rq_xid, req->rq_transno,
2221 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2222 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2224 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2226 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2228 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2229 (req->rq_import && req->rq_import->imp_client) ?
2230 req->rq_import->imp_client->cli_request_portal : -1,
2231 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2232 DEBUG_REQ_FLAGS(req),
2233 req->rq_reqmsg ? lustre_msg_get_flags(req->rq_reqmsg) : 0,
2234 req->rq_repmsg ? lustre_msg_get_flags(req->rq_repmsg) : 0,
2236 req->rq_repmsg ? lustre_msg_get_status(req->rq_repmsg) : 0);
2238 EXPORT_SYMBOL(debug_req);
2240 void lustre_swab_lustre_capa(struct lustre_capa *c)
2242 lustre_swab_lu_fid(&c->lc_fid);
2243 __swab64s (&c->lc_opc);
2244 __swab32s (&c->lc_flags);
2245 __swab32s (&c->lc_keyid);
2246 __swab64s (&c->lc_expiry);
2249 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2251 __swab64s (&k->lk_mdsid);
2252 __swab32s (&k->lk_keyid);
2253 __swab32s (&k->lk_padding);