1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author: Peter J. Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
7 * Author: Eric Barton <eeb@clusterfs.com>
9 * This file is part of the Lustre file system, http://www.lustre.org
10 * Lustre is a trademark of Cluster File Systems, Inc.
12 * You may have signed or agreed to another license before downloading
13 * this software. If so, you are bound by the terms and conditions
14 * of that agreement, and the following does not apply to you. See the
15 * LICENSE file included with this distribution for more information.
17 * If you did not agree to a different license, then this copy of Lustre
18 * is open source software; you can redistribute it and/or modify it
19 * under the terms of version 2 of the GNU General Public License as
20 * published by the Free Software Foundation.
22 * In either case, Lustre is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * license text for more details.
27 * (Un)packing of OST requests
31 #define DEBUG_SUBSYSTEM S_RPC
33 # include <liblustre.h>
36 #include <libcfs/libcfs.h>
38 #include <obd_support.h>
39 #include <obd_class.h>
40 #include <lustre_net.h>
42 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(1,8,0,0)
43 #error "lustre_msg_v1 has been deprecated since 1.6.0, please remove it"
44 #elif LUSTRE_VERSION_CODE > OBD_OCD_VERSION(1,6,50,0)
45 #warning "lustre_msg_v1 has been deprecated since 1.6.0, consider removing it"
48 static inline int lustre_msg_hdr_size_v1(int count)
50 return size_round(offsetof(struct lustre_msg_v1, lm_buflens[count]));
53 static inline int lustre_msg_hdr_size_v2(int count)
55 return size_round(offsetof(struct lustre_msg_v2, lm_buflens[count]));
58 int lustre_msg_swabbed(struct lustre_msg *msg)
60 return (msg->lm_magic == LUSTRE_MSG_MAGIC_V1_SWABBED) ||
61 (msg->lm_magic == LUSTRE_MSG_MAGIC_V2_SWABBED);
65 lustre_msg_check_version_v2(struct lustre_msg_v2 *msg, __u32 version)
67 __u32 ver = lustre_msg_get_version(msg);
68 return (ver & LUSTRE_VERSION_MASK) != version;
71 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
73 switch (msg->lm_magic) {
74 case LUSTRE_MSG_MAGIC_V1:
75 case LUSTRE_MSG_MAGIC_V1_SWABBED:
77 case LUSTRE_MSG_MAGIC_V2:
78 case LUSTRE_MSG_MAGIC_V2_SWABBED:
79 return lustre_msg_check_version_v2(msg, version);
81 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
86 /* early reply size */
87 int lustre_msg_early_size() {
90 size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, NULL);
93 EXPORT_SYMBOL(lustre_msg_early_size);
95 static inline int lustre_msg_size_v1(int count, int *lengths)
101 size = lustre_msg_hdr_size_v1(count);
102 for (i = 0; i < count; i++)
103 size += size_round(lengths[i]);
108 static inline int lustre_msg_size_v2(int count, int *lengths)
113 size = lustre_msg_hdr_size_v2(count);
114 for (i = 0; i < count; i++)
115 size += size_round(lengths[i]);
120 /* This returns the size of the buffer that is required to hold a lustre_msg
121 * with the given sub-buffer lengths. */
122 int lustre_msg_size(__u32 magic, int count, int *lens)
124 int size[] = { sizeof(struct ptlrpc_body) };
132 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
135 case LUSTRE_MSG_MAGIC_V1:
136 return lustre_msg_size_v1(count - 1, lens + 1);
137 case LUSTRE_MSG_MAGIC_V2:
138 return lustre_msg_size_v2(count, lens);
140 CERROR("incorrect message magic: %08x\n", magic);
146 lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
148 struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)m;
153 msg->lm_magic = LUSTRE_MSG_MAGIC_V1;
154 msg->lm_version = PTLRPC_MSG_VERSION;
155 msg->lm_bufcount = count;
157 for (i = 0; i < count; i++)
158 msg->lm_buflens[i] = lens[i];
163 ptr = (char *)msg + lustre_msg_hdr_size_v1(count);
164 for (i = 0; i < count; i++) {
166 LOGL(tmp, lens[i], ptr);
171 lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens, char **bufs)
176 msg->lm_bufcount = count;
177 /* XXX: lm_secflvr uninitialized here */
178 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
180 for (i = 0; i < count; i++)
181 msg->lm_buflens[i] = lens[i];
186 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
187 for (i = 0; i < count; i++) {
189 LOGL(tmp, lens[i], ptr);
193 static int lustre_pack_request_v1(struct ptlrpc_request *req,
194 int count, int *lens, char **bufs)
198 reqlen = lustre_msg_size_v1(count, lens);
200 /* See if we got it from prealloc pool */
201 if (req->rq_reqmsg) {
202 /* Cannot return error here, that would create
203 infinite loop in ptlrpc_prep_req_pool */
204 /* In this case ptlrpc_prep_req_from_pool sets req->rq_reqlen
205 to maximum size that would fit into this preallocated
207 LASSERTF(req->rq_reqlen >= reqlen, "req->rq_reqlen %d, "
208 "reqlen %d\n",req->rq_reqlen,
210 memset(req->rq_reqmsg, 0, reqlen);
212 OBD_ALLOC(req->rq_reqmsg, reqlen);
213 if (req->rq_reqmsg == NULL) {
214 CERROR("alloc reqmsg (len %d) failed\n", reqlen);
219 req->rq_reqlen = reqlen;
221 lustre_init_msg_v1(req->rq_reqmsg, count, lens, bufs);
225 static int lustre_pack_request_v2(struct ptlrpc_request *req,
226 int count, int *lens, char **bufs)
230 reqlen = lustre_msg_size_v2(count, lens);
232 /* See if we got it from prealloc pool */
233 if (req->rq_reqmsg) {
234 /* Cannot return error here, that would create
235 infinite loop in ptlrpc_prep_req_pool */
236 /* In this case ptlrpc_prep_req_from_pool sets req->rq_reqlen
237 to maximum size that would fit into this preallocated
239 LASSERTF(req->rq_reqlen >= reqlen, "req->rq_reqlen %d, "
240 "reqlen %d\n",req->rq_reqlen,
242 memset(req->rq_reqmsg, 0, reqlen);
244 OBD_ALLOC(req->rq_reqmsg, reqlen);
245 if (req->rq_reqmsg == NULL) {
246 CERROR("alloc reqmsg (len %d) failed\n", reqlen);
251 req->rq_reqlen = reqlen;
253 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
254 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
255 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
260 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
261 int *lens, char **bufs)
263 int size[] = { sizeof(struct ptlrpc_body) };
271 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
274 case LUSTRE_MSG_MAGIC_V1:
275 return lustre_pack_request_v1(req, count - 1, lens + 1,
276 bufs ? bufs + 1 : NULL);
277 case LUSTRE_MSG_MAGIC_V2:
278 return lustre_pack_request_v2(req, count, lens, bufs);
280 LASSERTF(0, "incorrect message magic: %08x\n", magic);
286 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
287 spinlock_t ptlrpc_rs_debug_lock;
289 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
291 spin_lock(&ptlrpc_rs_debug_lock); \
292 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
293 spin_unlock(&ptlrpc_rs_debug_lock); \
296 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
298 spin_lock(&ptlrpc_rs_debug_lock); \
299 list_del(&(rs)->rs_debug_list); \
300 spin_unlock(&ptlrpc_rs_debug_lock); \
303 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
304 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
307 static struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc,
310 struct ptlrpc_reply_state *rs = NULL;
312 spin_lock(&svc->srv_lock);
313 /* See if we have anything in a pool, and wait if nothing */
314 while (list_empty(&svc->srv_free_rs_list)) {
315 struct l_wait_info lwi;
317 spin_unlock(&svc->srv_lock);
318 /* If we cannot get anything for some long time, we better
319 bail out instead of waiting infinitely */
320 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
321 rc = l_wait_event(svc->srv_free_rs_waitq,
322 !list_empty(&svc->srv_free_rs_list), &lwi);
325 spin_lock(&svc->srv_lock);
328 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
330 list_del(&rs->rs_list);
331 spin_unlock(&svc->srv_lock);
333 LASSERTF(svc->srv_max_reply_size > size, "Want %d, prealloc %d\n", size,
334 svc->srv_max_reply_size);
341 static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count,
342 int *lens, char **bufs, int flags)
344 struct ptlrpc_reply_state *rs;
349 LASSERT(req->rq_reply_state == NULL);
351 if ((flags & LPRFL_EARLY_REPLY) == 0)
352 req->rq_packed_final = 1;
354 msg_len = lustre_msg_size_v1(count, lens);
355 size = sizeof(struct ptlrpc_reply_state) + msg_len;
357 if (unlikely(rs == NULL)) {
358 rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_service, size);
362 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
363 rs->rs_cb_id.cbid_fn = reply_out_callback;
364 rs->rs_cb_id.cbid_arg = rs;
365 rs->rs_service = req->rq_rqbd->rqbd_service;
367 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
368 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
369 rs->rs_msg = (struct lustre_msg *)(rs + 1);
371 req->rq_replen = msg_len;
372 req->rq_reply_state = rs;
373 req->rq_repmsg = rs->rs_msg;
375 lustre_init_msg_v1(rs->rs_msg, count, lens, bufs);
377 PTLRPC_RS_DEBUG_LRU_ADD(rs);
382 static int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
383 int *lens, char **bufs, int flags)
385 struct ptlrpc_reply_state *rs;
390 LASSERT(req->rq_reply_state == NULL);
392 if ((flags & LPRFL_EARLY_REPLY) == 0)
393 req->rq_packed_final = 1;
395 msg_len = lustre_msg_size_v2(count, lens);
396 size = sizeof(struct ptlrpc_reply_state) + msg_len;
398 if (unlikely(rs == NULL)) {
399 rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_service, size);
403 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
404 rs->rs_cb_id.cbid_fn = reply_out_callback;
405 rs->rs_cb_id.cbid_arg = rs;
406 rs->rs_service = req->rq_rqbd->rqbd_service;
408 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
409 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
410 rs->rs_msg = (struct lustre_msg *)(rs + 1);
412 req->rq_replen = msg_len;
413 req->rq_reply_state = rs;
414 req->rq_repmsg = rs->rs_msg;
416 /* server side, no rq_repbuf */
417 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
418 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
419 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
421 PTLRPC_RS_DEBUG_LRU_ADD(rs);
426 int lustre_pack_reply_flags(struct ptlrpc_request *req, int count, int *lens,
427 char **bufs, int flags)
429 int size[] = { sizeof(struct ptlrpc_body) };
437 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
439 switch (req->rq_reqmsg->lm_magic) {
440 case LUSTRE_MSG_MAGIC_V1:
441 case LUSTRE_MSG_MAGIC_V1_SWABBED:
442 return lustre_pack_reply_v1(req, count - 1, lens + 1,
443 bufs ? bufs + 1 : NULL, flags);
444 case LUSTRE_MSG_MAGIC_V2:
445 case LUSTRE_MSG_MAGIC_V2_SWABBED:
446 return lustre_pack_reply_v2(req, count, lens, bufs, flags);
448 LASSERTF(0, "incorrect message magic: %08x\n",
449 req->rq_reqmsg->lm_magic);
454 int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
457 int rc = lustre_pack_reply_flags(req, count, lens, bufs, 0);
459 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
460 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
465 void *lustre_msg_buf_v1(void *msg, int n, int min_size)
467 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
468 int i, offset, buflen, bufcount;
473 bufcount = m->lm_bufcount;
475 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
480 buflen = m->lm_buflens[n];
481 if (buflen < min_size) {
482 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
483 m, n, buflen, min_size);
488 offset = lustre_msg_hdr_size_v1(bufcount);
489 for (i = 0; i < n; i++)
490 offset += size_round(m->lm_buflens[i]);
492 return (char *)m + offset;
495 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
497 int i, offset, buflen, bufcount;
502 bufcount = m->lm_bufcount;
504 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
509 buflen = m->lm_buflens[n];
510 if (buflen < min_size) {
511 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
512 m, n, buflen, min_size);
516 offset = lustre_msg_hdr_size_v2(bufcount);
517 for (i = 0; i < n; i++)
518 offset += size_round(m->lm_buflens[i]);
520 return (char *)m + offset;
523 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
525 switch (m->lm_magic) {
526 case LUSTRE_MSG_MAGIC_V1:
527 case LUSTRE_MSG_MAGIC_V1_SWABBED:
528 return lustre_msg_buf_v1(m, n - 1, min_size);
529 case LUSTRE_MSG_MAGIC_V2:
530 case LUSTRE_MSG_MAGIC_V2_SWABBED:
531 return lustre_msg_buf_v2(m, n, min_size);
533 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
538 void lustre_shrink_reply_v1(struct ptlrpc_request *req, int segment,
539 unsigned int newlen, int move_data)
541 struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)req->rq_repmsg;
542 char *tail = NULL, *newpos;
545 LASSERT(req->rq_reply_state);
547 LASSERT(segment >= 0);
548 LASSERT(msg->lm_bufcount > segment);
549 LASSERT(msg->lm_buflens[segment] >= newlen);
551 if (msg->lm_buflens[segment] == newlen)
554 if (move_data && msg->lm_bufcount > segment + 1) {
555 tail = lustre_msg_buf_v1(msg, segment + 1, 0);
556 for (n = segment + 1; n < msg->lm_bufcount; n++)
557 tail_len += size_round(msg->lm_buflens[n]);
560 msg->lm_buflens[segment] = newlen;
562 if (tail && tail_len) {
563 newpos = lustre_msg_buf_v1(msg, segment + 1, 0);
564 LASSERT(newpos <= tail);
566 memcpy(newpos, tail, tail_len);
569 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
570 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
571 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
572 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
575 req->rq_replen = lustre_msg_size_v1(msg->lm_bufcount, msg->lm_buflens);
578 void lustre_shrink_reply_v2(struct ptlrpc_request *req, int segment,
579 unsigned int newlen, int move_data)
581 struct lustre_msg_v2 *msg = req->rq_repmsg;
582 char *tail = NULL, *newpos;
585 LASSERT(req->rq_reply_state);
587 LASSERT(msg->lm_bufcount > segment);
588 LASSERT(msg->lm_buflens[segment] >= newlen);
590 if (msg->lm_buflens[segment] == newlen)
593 if (move_data && msg->lm_bufcount > segment + 1) {
594 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
595 for (n = segment + 1; n < msg->lm_bufcount; n++)
596 tail_len += size_round(msg->lm_buflens[n]);
599 msg->lm_buflens[segment] = newlen;
601 if (tail && tail_len) {
602 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
603 LASSERT(newpos <= tail);
605 memcpy(newpos, tail, tail_len);
608 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
609 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
610 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
611 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
614 req->rq_replen = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
618 * shrink @segment to size @newlen. if @move_data is non-zero, we also move
619 * data forward from @segment + 1.
621 * if @newlen == 0, we remove the segment completely, but we still keep the
622 * totally bufcount the same to save possible data moving. this will leave a
623 * unused segment with size 0 at the tail, but that's ok.
626 * + if any buffers higher than @segment has been filled in, must call shrink
627 * with non-zero @move_data.
628 * + caller should NOT keep pointers to msg buffers which higher than @segment
631 void lustre_shrink_reply(struct ptlrpc_request *req, int segment,
632 unsigned int newlen, int move_data)
634 switch (req->rq_repmsg->lm_magic) {
635 case LUSTRE_MSG_MAGIC_V1:
636 lustre_shrink_reply_v1(req, segment - 1, newlen, move_data);
638 case LUSTRE_MSG_MAGIC_V2:
639 lustre_shrink_reply_v2(req, segment, newlen, move_data);
642 LASSERTF(0, "incorrect message magic: %08x\n",
643 req->rq_repmsg->lm_magic);
647 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
649 PTLRPC_RS_DEBUG_LRU_DEL(rs);
651 LASSERT (atomic_read(&rs->rs_refcount) == 0);
652 LASSERT (!rs->rs_difficult || rs->rs_handled);
653 LASSERT (!rs->rs_on_net);
654 LASSERT (!rs->rs_scheduled);
655 LASSERT (rs->rs_export == NULL);
656 LASSERT (rs->rs_nlocks == 0);
657 LASSERT (list_empty(&rs->rs_exp_list));
658 LASSERT (list_empty(&rs->rs_obd_list));
660 if (unlikely(rs->rs_prealloc)) {
661 struct ptlrpc_service *svc = rs->rs_service;
663 spin_lock(&svc->srv_lock);
664 list_add(&rs->rs_list,
665 &svc->srv_free_rs_list);
666 spin_unlock(&svc->srv_lock);
667 cfs_waitq_signal(&svc->srv_free_rs_waitq);
669 OBD_FREE(rs, rs->rs_size);
673 int lustre_unpack_msg_v1(void *msg, int len)
675 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
676 int flipped, required_len, i;
679 /* Now we know the sender speaks my language. */
680 required_len = lustre_msg_hdr_size_v1(0);
681 if (len < required_len) {
682 /* can't even look inside the message */
683 CERROR("message length %d too small for lustre_msg\n", len);
687 flipped = lustre_msg_swabbed((struct lustre_msg *)m);
690 __swab32s(&m->lm_type);
691 __swab32s(&m->lm_version);
692 __swab32s(&m->lm_opc);
693 __swab64s(&m->lm_last_xid);
694 __swab64s(&m->lm_last_committed);
695 __swab64s(&m->lm_transno);
696 __swab32s(&m->lm_status);
697 __swab32s(&m->lm_flags);
698 __swab32s(&m->lm_conn_cnt);
699 __swab32s(&m->lm_bufcount);
702 if (m->lm_version != PTLRPC_MSG_VERSION) {
703 CERROR("wrong lustre_msg version %08x\n", m->lm_version);
707 required_len = lustre_msg_hdr_size_v1(m->lm_bufcount);
708 if (len < required_len) {
709 /* didn't receive all the buffer lengths */
710 CERROR("message length %d too small for %d buflens\n",
711 len, m->lm_bufcount);
715 for (i = 0; i < m->lm_bufcount; i++) {
717 __swab32s (&m->lm_buflens[i]);
718 required_len += size_round(m->lm_buflens[i]);
721 if (len < required_len) {
722 CERROR("len: %d, required_len %d\n", len, required_len);
723 CERROR("bufcount: %d\n", m->lm_bufcount);
724 for (i = 0; i < m->lm_bufcount; i++)
725 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
732 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
734 int flipped, required_len, i;
736 /* Now we know the sender speaks my language. */
737 required_len = lustre_msg_hdr_size_v2(0);
738 if (len < required_len) {
739 /* can't even look inside the message */
740 CERROR("message length %d too small for lustre_msg\n", len);
744 flipped = lustre_msg_swabbed(m);
747 __swab32s(&m->lm_bufcount);
748 __swab32s(&m->lm_secflvr);
749 __swab32s(&m->lm_repsize);
750 __swab32s(&m->lm_cksum);
751 CLASSERT(offsetof(typeof(*m), lm_padding_1) != 0);
752 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
753 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
756 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
757 if (len < required_len) {
758 /* didn't receive all the buffer lengths */
759 CERROR ("message length %d too small for %d buflens\n",
760 len, m->lm_bufcount);
764 for (i = 0; i < m->lm_bufcount; i++) {
766 __swab32s(&m->lm_buflens[i]);
767 required_len += size_round(m->lm_buflens[i]);
770 if (len < required_len) {
771 CERROR("len: %d, required_len %d\n", len, required_len);
772 CERROR("bufcount: %d\n", m->lm_bufcount);
773 for (i = 0; i < m->lm_bufcount; i++)
774 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
781 int lustre_unpack_msg(struct lustre_msg *m, int len)
783 int required_len, rc;
786 /* We can provide a slightly better error log, if we check the
787 * message magic and version first. In the future, struct
788 * lustre_msg may grow, and we'd like to log a version mismatch,
789 * rather than a short message.
792 required_len = offsetof(struct lustre_msg, lm_magic) +
794 if (len < required_len) {
795 /* can't even look inside the message */
796 CERROR("message length %d too small for magic/version check\n",
801 switch (m->lm_magic) {
802 case LUSTRE_MSG_MAGIC_V1:
803 case LUSTRE_MSG_MAGIC_V1_SWABBED:
804 rc = lustre_unpack_msg_v1(m, len);
806 case LUSTRE_MSG_MAGIC_V2:
807 case LUSTRE_MSG_MAGIC_V2_SWABBED:
808 rc = lustre_unpack_msg_v2(m, len);
811 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
818 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
821 struct ptlrpc_body *pb;
823 pb = lustre_swab_buf(m, offset, sizeof(*pb), lustre_swab_ptlrpc_body);
825 CERROR("error unpacking ptlrpc body");
829 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
830 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
837 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
839 switch (req->rq_reqmsg->lm_magic) {
840 case LUSTRE_MSG_MAGIC_V1:
841 case LUSTRE_MSG_MAGIC_V1_SWABBED:
843 case LUSTRE_MSG_MAGIC_V2:
844 case LUSTRE_MSG_MAGIC_V2_SWABBED:
845 lustre_set_req_swabbed(req, offset);
846 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
848 CERROR("bad lustre msg magic: %#08X\n",
849 req->rq_reqmsg->lm_magic);
854 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
856 switch (req->rq_repmsg->lm_magic) {
857 case LUSTRE_MSG_MAGIC_V1:
858 case LUSTRE_MSG_MAGIC_V1_SWABBED:
860 case LUSTRE_MSG_MAGIC_V2:
861 case LUSTRE_MSG_MAGIC_V2_SWABBED:
862 lustre_set_rep_swabbed(req, offset);
863 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
865 CERROR("bad lustre msg magic: %#08X\n",
866 req->rq_repmsg->lm_magic);
871 static inline int lustre_msg_buflen_v1(void *msg, int n)
873 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
876 if (n >= m->lm_bufcount)
879 return m->lm_buflens[n];
882 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
884 if (n >= m->lm_bufcount)
887 return m->lm_buflens[n];
891 * lustre_msg_buflen - return the length of buffer @n in message @m
892 * @m - lustre_msg (request or reply) to look at
893 * @n - message index (base 0)
895 * returns zero for non-existent message indices
897 int lustre_msg_buflen(struct lustre_msg *m, int n)
899 switch (m->lm_magic) {
900 case LUSTRE_MSG_MAGIC_V1:
901 case LUSTRE_MSG_MAGIC_V1_SWABBED:
902 return lustre_msg_buflen_v1(m, n - 1);
903 case LUSTRE_MSG_MAGIC_V2:
904 case LUSTRE_MSG_MAGIC_V2_SWABBED:
905 return lustre_msg_buflen_v2(m, n);
907 CERROR("incorrect message magic: %08x\n", m->lm_magic);
911 EXPORT_SYMBOL(lustre_msg_buflen);
913 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
915 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
918 if (n >= m->lm_bufcount)
921 m->lm_buflens[n] = len;
925 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
927 if (n >= m->lm_bufcount)
930 m->lm_buflens[n] = len;
933 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
935 switch (m->lm_magic) {
936 case LUSTRE_MSG_MAGIC_V1:
937 lustre_msg_set_buflen_v1(m, n - 1, len);
939 case LUSTRE_MSG_MAGIC_V2:
940 lustre_msg_set_buflen_v2(m, n, len);
943 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
947 EXPORT_SYMBOL(lustre_msg_set_buflen);
949 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
950 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
951 int lustre_msg_bufcount(struct lustre_msg *m)
953 switch (m->lm_magic) {
954 case LUSTRE_MSG_MAGIC_V1:
955 case LUSTRE_MSG_MAGIC_V1_SWABBED:
956 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
957 case LUSTRE_MSG_MAGIC_V2:
958 case LUSTRE_MSG_MAGIC_V2_SWABBED:
959 return m->lm_bufcount;
961 CERROR("incorrect message magic: %08x\n", m->lm_magic);
965 EXPORT_SYMBOL(lustre_msg_bufcount);
967 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
969 /* max_len == 0 means the string should fill the buffer */
973 switch (m->lm_magic) {
974 case LUSTRE_MSG_MAGIC_V1:
975 case LUSTRE_MSG_MAGIC_V1_SWABBED:
976 str = lustre_msg_buf_v1(m, index - 1, 0);
977 blen = lustre_msg_buflen_v1(m, index - 1);
979 case LUSTRE_MSG_MAGIC_V2:
980 case LUSTRE_MSG_MAGIC_V2_SWABBED:
981 str = lustre_msg_buf_v2(m, index, 0);
982 blen = lustre_msg_buflen_v2(m, index);
985 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
989 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
993 slen = strnlen(str, blen);
995 if (slen == blen) { /* not NULL terminated */
996 CERROR("can't unpack non-NULL terminated string in "
997 "msg %p buffer[%d] len %d\n", m, index, blen);
1002 if (slen != blen - 1) {
1003 CERROR("can't unpack short string in msg %p "
1004 "buffer[%d] len %d: strlen %d\n",
1005 m, index, blen, slen);
1008 } else if (slen > max_len) {
1009 CERROR("can't unpack oversized string in msg %p "
1010 "buffer[%d] len %d strlen %d: max %d expected\n",
1011 m, index, blen, slen, max_len);
1018 /* Wrap up the normal fixed length cases */
1019 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
1024 switch (msg->lm_magic) {
1025 case LUSTRE_MSG_MAGIC_V1:
1026 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1027 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
1029 case LUSTRE_MSG_MAGIC_V2:
1030 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1031 ptr = lustre_msg_buf_v2(msg, index, min_size);
1034 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1039 if (swabber != NULL && lustre_msg_swabbed(msg))
1040 ((void (*)(void *))swabber)(ptr);
1045 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
1048 lustre_set_req_swabbed(req, index);
1049 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
1052 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
1055 lustre_set_rep_swabbed(req, index);
1056 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
1059 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
1061 switch (msg->lm_magic) {
1062 case LUSTRE_MSG_MAGIC_V1:
1063 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1064 return ((struct lustre_msg_v1 *)msg)->lm_flags &
1066 case LUSTRE_MSG_MAGIC_V2:
1067 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1068 struct ptlrpc_body *pb;
1070 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1072 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1075 return pb->pb_flags;
1078 /* flags might be printed in debug code while message
1084 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
1086 switch (msg->lm_magic) {
1087 case LUSTRE_MSG_MAGIC_V1:
1088 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1089 MSG_GEN_FLAG_MASK & flags;
1091 case LUSTRE_MSG_MAGIC_V2: {
1092 struct ptlrpc_body *pb;
1094 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1095 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1096 pb->pb_flags |= flags;
1100 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1104 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
1106 switch (msg->lm_magic) {
1107 case LUSTRE_MSG_MAGIC_V1:
1108 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK;
1109 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1110 MSG_GEN_FLAG_MASK & flags;
1112 case LUSTRE_MSG_MAGIC_V2: {
1113 struct ptlrpc_body *pb;
1115 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1116 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1117 pb->pb_flags = flags;
1121 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1125 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1127 switch (msg->lm_magic) {
1128 case LUSTRE_MSG_MAGIC_V1:
1129 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1130 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1131 ~(MSG_GEN_FLAG_MASK & flags);
1133 case LUSTRE_MSG_MAGIC_V2:
1134 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1135 struct ptlrpc_body *pb;
1137 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1138 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1139 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
1143 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1147 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1149 switch (msg->lm_magic) {
1150 case LUSTRE_MSG_MAGIC_V1:
1151 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1152 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1154 case LUSTRE_MSG_MAGIC_V2:
1155 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1156 struct ptlrpc_body *pb;
1158 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1160 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1163 return pb->pb_op_flags;
1170 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1172 switch (msg->lm_magic) {
1173 case LUSTRE_MSG_MAGIC_V1:
1174 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1175 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1177 case LUSTRE_MSG_MAGIC_V2: {
1178 struct ptlrpc_body *pb;
1180 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1181 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1182 pb->pb_op_flags |= flags;
1186 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1190 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
1192 switch (msg->lm_magic) {
1193 case LUSTRE_MSG_MAGIC_V1:
1194 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK;
1195 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1196 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1198 case LUSTRE_MSG_MAGIC_V2: {
1199 struct ptlrpc_body *pb;
1201 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1202 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1203 pb->pb_op_flags |= flags;
1207 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1211 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1213 switch (msg->lm_magic) {
1214 case LUSTRE_MSG_MAGIC_V1:
1215 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1216 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1217 case LUSTRE_MSG_MAGIC_V2:
1218 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1219 struct ptlrpc_body *pb;
1221 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1223 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1226 return &pb->pb_handle;
1229 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1234 __u32 lustre_msg_get_type(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_type;
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));
1246 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1247 return PTL_RPC_MSG_ERR;
1252 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1253 return PTL_RPC_MSG_ERR;
1257 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1259 switch (msg->lm_magic) {
1260 case LUSTRE_MSG_MAGIC_V1:
1261 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1262 return ((struct lustre_msg_v1 *)msg)->lm_version;
1263 case LUSTRE_MSG_MAGIC_V2:
1264 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1265 struct ptlrpc_body *pb;
1267 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1269 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1272 return pb->pb_version;
1275 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1280 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1282 switch (msg->lm_magic) {
1283 case LUSTRE_MSG_MAGIC_V1:
1284 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1286 case LUSTRE_MSG_MAGIC_V2:
1287 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1288 struct ptlrpc_body *pb;
1290 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1291 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1292 pb->pb_version |= version;
1296 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1300 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1302 switch (msg->lm_magic) {
1303 case LUSTRE_MSG_MAGIC_V1:
1304 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1305 return ((struct lustre_msg_v1 *)msg)->lm_opc;
1306 case LUSTRE_MSG_MAGIC_V2:
1307 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1308 struct ptlrpc_body *pb;
1310 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1312 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1318 CERROR( "incorrect message magic: %08x\n", msg->lm_magic);
1323 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1325 switch (msg->lm_magic) {
1326 case LUSTRE_MSG_MAGIC_V1:
1327 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1328 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1329 case LUSTRE_MSG_MAGIC_V2:
1330 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1331 struct ptlrpc_body *pb;
1333 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1335 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1338 return pb->pb_last_xid;
1341 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1346 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1348 switch (msg->lm_magic) {
1349 case LUSTRE_MSG_MAGIC_V1:
1350 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1351 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1352 case LUSTRE_MSG_MAGIC_V2:
1353 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1354 struct ptlrpc_body *pb;
1356 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1358 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1361 return pb->pb_last_committed;
1364 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1369 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1371 switch (msg->lm_magic) {
1372 case LUSTRE_MSG_MAGIC_V1:
1373 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1374 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1375 case LUSTRE_MSG_MAGIC_V2:
1376 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1377 struct ptlrpc_body *pb;
1379 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1381 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1384 return pb->pb_transno;
1387 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1392 int lustre_msg_get_status(struct lustre_msg *msg)
1394 switch (msg->lm_magic) {
1395 case LUSTRE_MSG_MAGIC_V1:
1396 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1397 return ((struct lustre_msg_v1 *)msg)->lm_status;
1398 case LUSTRE_MSG_MAGIC_V2:
1399 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1400 struct ptlrpc_body *pb;
1402 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1404 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1407 return pb->pb_status;
1410 /* status might be printed in debug code while message
1416 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1418 switch (msg->lm_magic) {
1419 case LUSTRE_MSG_MAGIC_V1:
1420 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1422 case LUSTRE_MSG_MAGIC_V2:
1423 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1424 struct ptlrpc_body *pb;
1426 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1428 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1434 CERROR("invalid msg magic %x\n", msg->lm_magic);
1440 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1442 switch (msg->lm_magic) {
1443 case LUSTRE_MSG_MAGIC_V1:
1444 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1446 case LUSTRE_MSG_MAGIC_V2:
1447 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1448 struct ptlrpc_body *pb;
1450 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1452 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1459 CERROR("invalid msg magic %x\n", msg->lm_magic);
1464 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1466 switch (msg->lm_magic) {
1467 case LUSTRE_MSG_MAGIC_V1:
1468 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1470 case LUSTRE_MSG_MAGIC_V2:
1471 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1472 struct ptlrpc_body *pb;
1474 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1476 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1479 return pb->pb_limit;
1482 CERROR("invalid msg magic %x\n", msg->lm_magic);
1488 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1490 switch (msg->lm_magic) {
1491 case LUSTRE_MSG_MAGIC_V1:
1492 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1494 case LUSTRE_MSG_MAGIC_V2:
1495 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1496 struct ptlrpc_body *pb;
1498 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1500 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1503 pb->pb_limit = limit;
1507 CERROR("invalid msg magic %x\n", msg->lm_magic);
1512 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1514 switch (msg->lm_magic) {
1515 case LUSTRE_MSG_MAGIC_V1:
1516 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1517 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1518 case LUSTRE_MSG_MAGIC_V2:
1519 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1520 struct ptlrpc_body *pb;
1522 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1524 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1527 return pb->pb_conn_cnt;
1530 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1535 int lustre_msg_is_v1(struct lustre_msg *msg)
1537 switch (msg->lm_magic) {
1538 case LUSTRE_MSG_MAGIC_V1:
1539 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1546 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1548 switch (msg->lm_magic) {
1549 case LUSTRE_MSG_MAGIC_V1:
1550 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1551 case LUSTRE_MSG_MAGIC_V2:
1552 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1553 return msg->lm_magic;
1555 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1560 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
1562 switch (msg->lm_magic) {
1563 case LUSTRE_MSG_MAGIC_V1:
1564 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1566 case LUSTRE_MSG_MAGIC_V2:
1567 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1568 struct ptlrpc_body *pb;
1570 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1572 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1576 return pb->pb_timeout;
1579 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1584 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
1586 switch (msg->lm_magic) {
1587 case LUSTRE_MSG_MAGIC_V1:
1588 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1590 case LUSTRE_MSG_MAGIC_V2:
1591 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1592 struct ptlrpc_body *pb;
1594 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1596 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1600 return pb->pb_service_time;
1603 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1608 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1610 switch (msg->lm_magic) {
1611 case LUSTRE_MSG_MAGIC_V1:
1612 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1614 case LUSTRE_MSG_MAGIC_V2:
1615 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1616 return msg->lm_cksum;
1618 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1623 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1625 switch (msg->lm_magic) {
1626 case LUSTRE_MSG_MAGIC_V1:
1627 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1629 case LUSTRE_MSG_MAGIC_V2:
1630 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1631 struct ptlrpc_body *pb;
1632 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1633 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1634 return crc32_le(~(__u32)0, (char *)pb, sizeof(*pb));
1637 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1642 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1644 switch (msg->lm_magic) {
1645 case LUSTRE_MSG_MAGIC_V1:
1646 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1648 case LUSTRE_MSG_MAGIC_V2: {
1649 struct ptlrpc_body *pb;
1651 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1652 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1653 pb->pb_handle = *handle;
1657 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1661 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1663 switch (msg->lm_magic) {
1664 case LUSTRE_MSG_MAGIC_V1:
1665 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1667 case LUSTRE_MSG_MAGIC_V2: {
1668 struct ptlrpc_body *pb;
1670 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1671 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1676 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1680 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1682 switch (msg->lm_magic) {
1683 case LUSTRE_MSG_MAGIC_V1:
1684 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1686 case LUSTRE_MSG_MAGIC_V2: {
1687 struct ptlrpc_body *pb;
1689 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1690 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1695 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1699 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1701 switch (msg->lm_magic) {
1702 case LUSTRE_MSG_MAGIC_V1:
1703 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1705 case LUSTRE_MSG_MAGIC_V2: {
1706 struct ptlrpc_body *pb;
1708 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1709 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1710 pb->pb_last_xid = last_xid;
1714 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1718 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1720 switch (msg->lm_magic) {
1721 case LUSTRE_MSG_MAGIC_V1:
1722 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1724 case LUSTRE_MSG_MAGIC_V2: {
1725 struct ptlrpc_body *pb;
1727 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1728 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1729 pb->pb_last_committed = last_committed;
1733 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1737 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1739 switch (msg->lm_magic) {
1740 case LUSTRE_MSG_MAGIC_V1:
1741 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1743 case LUSTRE_MSG_MAGIC_V2: {
1744 struct ptlrpc_body *pb;
1746 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1747 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1748 pb->pb_transno = transno;
1752 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1756 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1758 switch (msg->lm_magic) {
1759 case LUSTRE_MSG_MAGIC_V1:
1760 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1762 case LUSTRE_MSG_MAGIC_V2: {
1763 struct ptlrpc_body *pb;
1765 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1766 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1767 pb->pb_status = status;
1771 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1775 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1777 switch (msg->lm_magic) {
1778 case LUSTRE_MSG_MAGIC_V1:
1779 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1781 case LUSTRE_MSG_MAGIC_V2: {
1782 struct ptlrpc_body *pb;
1784 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1785 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1786 pb->pb_conn_cnt = conn_cnt;
1790 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1794 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
1796 switch (msg->lm_magic) {
1797 case LUSTRE_MSG_MAGIC_V1:
1799 case LUSTRE_MSG_MAGIC_V2: {
1800 struct ptlrpc_body *pb;
1802 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1803 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1804 pb->pb_timeout = timeout;
1808 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1812 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
1814 switch (msg->lm_magic) {
1815 case LUSTRE_MSG_MAGIC_V1:
1817 case LUSTRE_MSG_MAGIC_V2: {
1818 struct ptlrpc_body *pb;
1820 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1821 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1822 pb->pb_service_time = service_time;
1826 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1830 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
1832 switch (msg->lm_magic) {
1833 case LUSTRE_MSG_MAGIC_V1:
1835 case LUSTRE_MSG_MAGIC_V2:
1836 msg->lm_cksum = cksum;
1839 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1844 /* byte flipping routines for all wire types declared in
1845 * lustre_idl.h implemented here.
1847 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1849 __swab32s (&b->pb_type);
1850 __swab32s (&b->pb_version);
1851 __swab32s (&b->pb_opc);
1852 __swab32s (&b->pb_status);
1853 __swab64s (&b->pb_last_xid);
1854 __swab64s (&b->pb_last_seen);
1855 __swab64s (&b->pb_last_committed);
1856 __swab64s (&b->pb_transno);
1857 __swab32s (&b->pb_flags);
1858 __swab32s (&b->pb_op_flags);
1859 __swab32s (&b->pb_conn_cnt);
1860 __swab32s (&b->pb_timeout);
1861 __swab32s (&b->pb_service_time);
1862 __swab64s (&b->pb_slv);
1863 __swab32s (&b->pb_limit);
1866 void lustre_swab_connect(struct obd_connect_data *ocd)
1868 __swab64s(&ocd->ocd_connect_flags);
1869 __swab32s(&ocd->ocd_version);
1870 __swab32s(&ocd->ocd_grant);
1871 __swab32s(&ocd->ocd_index);
1872 __swab32s(&ocd->ocd_brw_size);
1873 __swab64s(&ocd->ocd_ibits_known);
1874 __swab32s(&ocd->ocd_nllu);
1875 __swab32s(&ocd->ocd_nllg);
1876 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1877 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1878 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1879 CLASSERT(offsetof(typeof(*ocd), padding4) != 0);
1882 void lustre_swab_obdo (struct obdo *o)
1884 __swab64s (&o->o_valid);
1885 __swab64s (&o->o_id);
1886 __swab64s (&o->o_gr);
1887 __swab64s (&o->o_fid);
1888 __swab64s (&o->o_size);
1889 __swab64s (&o->o_mtime);
1890 __swab64s (&o->o_atime);
1891 __swab64s (&o->o_ctime);
1892 __swab64s (&o->o_blocks);
1893 __swab64s (&o->o_grant);
1894 __swab32s (&o->o_blksize);
1895 __swab32s (&o->o_mode);
1896 __swab32s (&o->o_uid);
1897 __swab32s (&o->o_gid);
1898 __swab32s (&o->o_flags);
1899 __swab32s (&o->o_nlink);
1900 __swab32s (&o->o_generation);
1901 __swab32s (&o->o_misc);
1902 __swab32s (&o->o_easize);
1903 __swab32s (&o->o_mds);
1904 __swab32s (&o->o_stripe_idx);
1905 __swab32s (&o->o_padding_1);
1906 /* o_inline is opaque */
1909 void lustre_swab_obd_statfs (struct obd_statfs *os)
1911 __swab64s (&os->os_type);
1912 __swab64s (&os->os_blocks);
1913 __swab64s (&os->os_bfree);
1914 __swab64s (&os->os_bavail);
1915 __swab64s (&os->os_files);
1916 __swab64s (&os->os_ffree);
1917 /* no need to swab os_fsid */
1918 __swab32s (&os->os_bsize);
1919 __swab32s (&os->os_namelen);
1920 __swab64s (&os->os_maxbytes);
1921 __swab32s (&os->os_state);
1922 /* no need to swap os_spare */
1925 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1927 __swab64s (&ioo->ioo_id);
1928 __swab64s (&ioo->ioo_gr);
1929 __swab32s (&ioo->ioo_type);
1930 __swab32s (&ioo->ioo_bufcnt);
1933 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1935 __swab64s (&nbr->offset);
1936 __swab32s (&nbr->len);
1937 __swab32s (&nbr->flags);
1940 void lustre_swab_ost_body (struct ost_body *b)
1942 lustre_swab_obdo (&b->oa);
1945 void lustre_swab_ost_last_id(obd_id *id)
1950 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1952 __swab64s(&lvb->lvb_size);
1953 __swab64s(&lvb->lvb_mtime);
1954 __swab64s(&lvb->lvb_atime);
1955 __swab64s(&lvb->lvb_ctime);
1956 __swab64s(&lvb->lvb_blocks);
1959 void lustre_swab_mds_status_req (struct mds_status_req *r)
1961 __swab32s (&r->flags);
1962 __swab32s (&r->repbuf);
1965 void lustre_swab_mds_body (struct mds_body *b)
1967 lustre_swab_ll_fid (&b->fid1);
1968 lustre_swab_ll_fid (&b->fid2);
1969 /* handle is opaque */
1970 __swab64s (&b->valid);
1971 __swab64s (&b->size);
1972 __swab64s (&b->mtime);
1973 __swab64s (&b->atime);
1974 __swab64s (&b->ctime);
1975 __swab64s (&b->blocks);
1976 __swab64s (&b->io_epoch);
1977 __swab64s (&b->ino);
1978 __swab32s (&b->fsuid);
1979 __swab32s (&b->fsgid);
1980 __swab32s (&b->capability);
1981 __swab32s (&b->mode);
1982 __swab32s (&b->uid);
1983 __swab32s (&b->gid);
1984 __swab32s (&b->flags);
1985 __swab32s (&b->rdev);
1986 __swab32s (&b->nlink);
1987 __swab32s (&b->generation);
1988 __swab32s (&b->suppgid);
1989 __swab32s (&b->eadatasize);
1990 __swab32s (&b->aclsize);
1991 __swab32s (&b->max_mdsize);
1992 __swab32s (&b->max_cookiesize);
1993 __swab32s (&b->padding_4);
1996 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1999 __swab32s(&mti->mti_lustre_ver);
2000 __swab32s(&mti->mti_stripe_index);
2001 __swab32s(&mti->mti_config_ver);
2002 __swab32s(&mti->mti_flags);
2003 __swab32s(&mti->mti_nid_count);
2004 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
2005 for (i = 0; i < MTI_NIDS_MAX; i++)
2006 __swab64s(&mti->mti_nids[i]);
2009 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
2011 __swab64s (&i->dqi_bgrace);
2012 __swab64s (&i->dqi_igrace);
2013 __swab32s (&i->dqi_flags);
2014 __swab32s (&i->dqi_valid);
2017 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
2019 __swab64s (&b->dqb_ihardlimit);
2020 __swab64s (&b->dqb_isoftlimit);
2021 __swab64s (&b->dqb_curinodes);
2022 __swab64s (&b->dqb_bhardlimit);
2023 __swab64s (&b->dqb_bsoftlimit);
2024 __swab64s (&b->dqb_curspace);
2025 __swab64s (&b->dqb_btime);
2026 __swab64s (&b->dqb_itime);
2027 __swab32s (&b->dqb_valid);
2028 CLASSERT(offsetof(typeof(*b), padding) != 0);
2031 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
2033 __swab32s (&q->qc_cmd);
2034 __swab32s (&q->qc_type);
2035 __swab32s (&q->qc_id);
2036 __swab32s (&q->qc_stat);
2037 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
2038 lustre_swab_obd_dqblk (&q->qc_dqblk);
2041 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
2043 __swab32s (&sa->sa_opcode);
2044 __swab32s (&sa->sa_fsuid);
2045 __swab32s (&sa->sa_fsgid);
2046 __swab32s (&sa->sa_cap);
2047 __swab32s (&sa->sa_suppgid);
2048 __swab32s (&sa->sa_mode);
2049 lustre_swab_ll_fid (&sa->sa_fid);
2050 __swab64s (&sa->sa_valid);
2051 __swab64s (&sa->sa_size);
2052 __swab64s (&sa->sa_mtime);
2053 __swab64s (&sa->sa_atime);
2054 __swab64s (&sa->sa_ctime);
2055 __swab32s (&sa->sa_uid);
2056 __swab32s (&sa->sa_gid);
2057 __swab32s (&sa->sa_attr_flags);
2058 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
2061 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
2063 __swab64s(&jr->jr_headsize);
2064 lustre_swab_ll_fid(&jr->jr_fid);
2067 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
2069 __swab32s (&cr->cr_opcode);
2070 __swab32s (&cr->cr_fsuid);
2071 __swab32s (&cr->cr_fsgid);
2072 __swab32s (&cr->cr_cap);
2073 __swab32s (&cr->cr_flags); /* for use with open */
2074 __swab32s (&cr->cr_mode);
2075 lustre_swab_ll_fid (&cr->cr_fid);
2076 lustre_swab_ll_fid (&cr->cr_replayfid);
2077 __swab64s (&cr->cr_time);
2078 __swab64s (&cr->cr_rdev);
2079 __swab32s (&cr->cr_suppgid);
2080 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
2081 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
2082 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
2083 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
2084 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
2087 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
2089 __swab32s (&lk->lk_opcode);
2090 __swab32s (&lk->lk_fsuid);
2091 __swab32s (&lk->lk_fsgid);
2092 __swab32s (&lk->lk_cap);
2093 __swab32s (&lk->lk_suppgid1);
2094 __swab32s (&lk->lk_suppgid2);
2095 lustre_swab_ll_fid (&lk->lk_fid1);
2096 lustre_swab_ll_fid (&lk->lk_fid2);
2097 __swab64s (&lk->lk_time);
2098 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
2099 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2100 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2101 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2104 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
2106 __swab32s (&ul->ul_opcode);
2107 __swab32s (&ul->ul_fsuid);
2108 __swab32s (&ul->ul_fsgid);
2109 __swab32s (&ul->ul_cap);
2110 __swab32s (&ul->ul_suppgid);
2111 __swab32s (&ul->ul_mode);
2112 lustre_swab_ll_fid (&ul->ul_fid1);
2113 lustre_swab_ll_fid (&ul->ul_fid2);
2114 __swab64s (&ul->ul_time);
2115 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
2116 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2117 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2118 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2121 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
2123 __swab32s (&rn->rn_opcode);
2124 __swab32s (&rn->rn_fsuid);
2125 __swab32s (&rn->rn_fsgid);
2126 __swab32s (&rn->rn_cap);
2127 __swab32s (&rn->rn_suppgid1);
2128 __swab32s (&rn->rn_suppgid2);
2129 lustre_swab_ll_fid (&rn->rn_fid1);
2130 lustre_swab_ll_fid (&rn->rn_fid2);
2131 __swab64s (&rn->rn_time);
2132 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
2133 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
2134 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2135 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2138 void lustre_swab_lov_desc (struct lov_desc *ld)
2140 __swab32s (&ld->ld_tgt_count);
2141 __swab32s (&ld->ld_active_tgt_count);
2142 __swab32s (&ld->ld_default_stripe_count);
2143 __swab64s (&ld->ld_default_stripe_size);
2144 __swab64s (&ld->ld_default_stripe_offset);
2145 __swab32s (&ld->ld_pattern);
2146 __swab32s (&ld->ld_qos_maxage);
2147 /* uuid endian insensitive */
2150 static void print_lum (struct lov_user_md *lum)
2152 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
2153 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
2154 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2155 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
2156 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
2157 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2158 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2159 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
2162 void lustre_swab_lov_user_md(struct lov_user_md *lum)
2165 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2166 __swab32s(&lum->lmm_magic);
2167 __swab32s(&lum->lmm_pattern);
2168 __swab64s(&lum->lmm_object_id);
2169 __swab64s(&lum->lmm_object_gr);
2170 __swab32s(&lum->lmm_stripe_size);
2171 __swab16s(&lum->lmm_stripe_count);
2172 __swab16s(&lum->lmm_stripe_offset);
2177 static void print_lumj (struct lov_user_md_join *lumj)
2179 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2180 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2181 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2182 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2183 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2184 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2185 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2186 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2189 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2192 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2193 __swab32s(&lumj->lmm_magic);
2194 __swab32s(&lumj->lmm_pattern);
2195 __swab64s(&lumj->lmm_object_id);
2196 __swab64s(&lumj->lmm_object_gr);
2197 __swab32s(&lumj->lmm_stripe_size);
2198 __swab32s(&lumj->lmm_stripe_count);
2199 __swab32s(&lumj->lmm_extent_count);
2204 static void print_lum_objs(struct lov_user_md *lum)
2206 struct lov_user_ost_data *lod;
2209 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2211 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2212 for (i = 0; i < lum->lmm_stripe_count; i++) {
2213 lod = &lum->lmm_objects[i];
2214 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2215 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2216 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2217 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2222 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2224 struct lov_user_ost_data *lod;
2227 for (i = 0; i < lum->lmm_stripe_count; i++) {
2228 lod = &lum->lmm_objects[i];
2229 __swab64s(&lod->l_object_id);
2230 __swab64s(&lod->l_object_gr);
2231 __swab32s(&lod->l_ost_gen);
2232 __swab32s(&lod->l_ost_idx);
2234 print_lum_objs(lum);
2238 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2242 for (i = 0; i < RES_NAME_SIZE; i++)
2243 __swab64s (&id->name[i]);
2246 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2248 /* the lock data is a union and the first two fields are always an
2249 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2250 * data the same way. */
2251 __swab64s(&d->l_extent.start);
2252 __swab64s(&d->l_extent.end);
2253 __swab64s(&d->l_extent.gid);
2254 __swab32s(&d->l_flock.pid);
2257 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2259 __swab64s (&i->opc);
2262 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2264 __swab32s (&r->lr_type);
2265 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2266 lustre_swab_ldlm_res_id (&r->lr_name);
2269 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2271 lustre_swab_ldlm_resource_desc (&l->l_resource);
2272 __swab32s (&l->l_req_mode);
2273 __swab32s (&l->l_granted_mode);
2274 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2277 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2279 __swab32s (&rq->lock_flags);
2280 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2281 __swab32s (&rq->lock_count);
2282 /* lock_handle[] opaque */
2285 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2287 __swab32s (&r->lock_flags);
2288 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2289 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2290 /* lock_handle opaque */
2291 __swab64s (&r->lock_policy_res1);
2292 __swab64s (&r->lock_policy_res2);
2295 /* no one calls this */
2296 int llog_log_swabbed(struct llog_log_hdr *hdr)
2298 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2300 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2305 void lustre_swab_qdata(struct qunit_data *d)
2307 __swab32s (&d->qd_id);
2308 __swab32s (&d->qd_flags);
2309 __swab64s (&d->qd_count);
2312 void lustre_swab_qdata_old(struct qunit_data_old *d)
2314 __swab32s (&d->qd_id);
2315 __swab32s (&d->qd_type);
2316 __swab32s (&d->qd_count);
2317 __swab32s (&d->qd_isblk);
2321 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2323 struct qunit_data_old tmp;
2324 struct qunit_data *ret;
2331 ret = (struct qunit_data *)d;
2332 ret->qd_id = tmp.qd_id;
2333 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2334 ret->qd_count = tmp.qd_count;
2338 EXPORT_SYMBOL(lustre_quota_old_to_new);
2340 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2342 struct qunit_data tmp;
2343 struct qunit_data_old *ret;
2350 ret = (struct qunit_data_old *)d;
2351 ret->qd_id = tmp.qd_id;
2352 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2353 ret->qd_count = (__u32)tmp.qd_count;
2354 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2357 EXPORT_SYMBOL(lustre_quota_new_to_old);
2358 #endif /* __KERNEL__ */
2360 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2362 LASSERT(req->rq_reqmsg);
2364 switch (req->rq_reqmsg->lm_magic) {
2365 case LUSTRE_MSG_MAGIC_V1:
2366 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2368 case LUSTRE_MSG_MAGIC_V2:
2369 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2370 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2372 CERROR("bad lustre msg magic: %#08X\n",
2373 req->rq_reqmsg->lm_magic);
2378 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2380 LASSERT(req->rq_repmsg);
2382 switch (req->rq_repmsg->lm_magic) {
2383 case LUSTRE_MSG_MAGIC_V1:
2384 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2386 case LUSTRE_MSG_MAGIC_V2:
2387 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2388 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2390 /* uninitialized yet */
2395 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2396 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2401 va_start(args, fmt);
2402 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2403 data->msg_fn, data->msg_line, fmt, args,
2404 " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d/%d "
2405 "lens %d/%d e %d to %d dl %ld ref %d "
2406 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2407 req, req->rq_xid, req->rq_transno,
2408 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2409 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2411 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2413 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2415 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2416 req->rq_request_portal, req->rq_reply_portal,
2417 req->rq_reqlen, req->rq_replen,
2418 req->rq_early_count, req->rq_timeout, req->rq_deadline,
2419 atomic_read(&req->rq_refcount), DEBUG_REQ_FLAGS(req),
2420 req->rq_reqmsg ? lustre_msg_get_flags(req->rq_reqmsg) : 0,
2421 req->rq_repmsg ? lustre_msg_get_flags(req->rq_repmsg) : 0,
2423 req->rq_repmsg ? lustre_msg_get_status(req->rq_repmsg) : 0);
2427 EXPORT_SYMBOL(_debug_req);