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 static inline int lustre_msg_size_v1(int count, int *lengths)
92 size = lustre_msg_hdr_size_v1(count);
93 for (i = 0; i < count; i++)
94 size += size_round(lengths[i]);
99 static inline int lustre_msg_size_v2(int count, int *lengths)
104 size = lustre_msg_hdr_size_v2(count);
105 for (i = 0; i < count; i++)
106 size += size_round(lengths[i]);
111 /* This returns the size of the buffer that is required to hold a lustre_msg
112 * with the given sub-buffer lengths. */
113 int lustre_msg_size(__u32 magic, int count, int *lens)
115 int size[] = { sizeof(struct ptlrpc_body) };
123 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
126 case LUSTRE_MSG_MAGIC_V1:
127 return lustre_msg_size_v1(count - 1, lens + 1);
128 case LUSTRE_MSG_MAGIC_V2:
129 return lustre_msg_size_v2(count, lens);
131 CERROR("incorrect message magic: %08x\n", magic);
137 lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
139 struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)m;
144 msg->lm_magic = LUSTRE_MSG_MAGIC_V1;
145 msg->lm_version = PTLRPC_MSG_VERSION;
146 msg->lm_bufcount = count;
148 for (i = 0; i < count; i++)
149 msg->lm_buflens[i] = lens[i];
154 ptr = (char *)msg + lustre_msg_hdr_size_v1(count);
155 for (i = 0; i < count; i++) {
157 LOGL(tmp, lens[i], ptr);
162 lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens, char **bufs)
167 msg->lm_bufcount = count;
168 /* XXX: lm_secflvr uninitialized here */
169 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
171 for (i = 0; i < count; i++)
172 msg->lm_buflens[i] = lens[i];
177 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
178 for (i = 0; i < count; i++) {
180 LOGL(tmp, lens[i], ptr);
184 static int lustre_pack_request_v1(struct ptlrpc_request *req,
185 int count, int *lens, char **bufs)
189 reqlen = lustre_msg_size_v1(count, lens);
191 /* See if we got it from prealloc pool */
192 if (req->rq_reqmsg) {
193 /* Cannot return error here, that would create
194 infinite loop in ptlrpc_prep_req_pool */
195 /* In this case ptlrpc_prep_req_from_pool sets req->rq_reqlen
196 to maximum size that would fit into this preallocated
198 LASSERTF(req->rq_reqlen >= reqlen, "req->rq_reqlen %d, "
199 "reqlen %d\n",req->rq_reqlen,
201 memset(req->rq_reqmsg, 0, reqlen);
203 OBD_ALLOC(req->rq_reqmsg, reqlen);
204 if (req->rq_reqmsg == NULL) {
205 CERROR("alloc reqmsg (len %d) failed\n", reqlen);
210 req->rq_reqlen = reqlen;
212 lustre_init_msg_v1(req->rq_reqmsg, count, lens, bufs);
216 static int lustre_pack_request_v2(struct ptlrpc_request *req,
217 int count, int *lens, char **bufs)
221 reqlen = lustre_msg_size_v2(count, lens);
223 /* See if we got it from prealloc pool */
224 if (req->rq_reqmsg) {
225 /* Cannot return error here, that would create
226 infinite loop in ptlrpc_prep_req_pool */
227 /* In this case ptlrpc_prep_req_from_pool sets req->rq_reqlen
228 to maximum size that would fit into this preallocated
230 LASSERTF(req->rq_reqlen >= reqlen, "req->rq_reqlen %d, "
231 "reqlen %d\n",req->rq_reqlen,
233 memset(req->rq_reqmsg, 0, reqlen);
235 OBD_ALLOC(req->rq_reqmsg, reqlen);
236 if (req->rq_reqmsg == NULL) {
237 CERROR("alloc reqmsg (len %d) failed\n", reqlen);
242 req->rq_reqlen = reqlen;
244 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
245 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
246 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
250 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
251 int *lens, char **bufs)
253 int size[] = { sizeof(struct ptlrpc_body) };
261 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
264 case LUSTRE_MSG_MAGIC_V1:
265 return lustre_pack_request_v1(req, count - 1, lens + 1,
266 bufs ? bufs + 1 : NULL);
267 case LUSTRE_MSG_MAGIC_V2:
268 return lustre_pack_request_v2(req, count, lens, bufs);
270 LASSERTF(0, "incorrect message magic: %08x\n", magic);
276 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
277 spinlock_t ptlrpc_rs_debug_lock;
279 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
281 spin_lock(&ptlrpc_rs_debug_lock); \
282 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
283 spin_unlock(&ptlrpc_rs_debug_lock); \
286 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
288 spin_lock(&ptlrpc_rs_debug_lock); \
289 list_del(&(rs)->rs_debug_list); \
290 spin_unlock(&ptlrpc_rs_debug_lock); \
293 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
294 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
297 static struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc,
300 struct ptlrpc_reply_state *rs = NULL;
302 spin_lock(&svc->srv_lock);
303 /* See if we have anything in a pool, and wait if nothing */
304 while (list_empty(&svc->srv_free_rs_list)) {
305 struct l_wait_info lwi;
307 spin_unlock(&svc->srv_lock);
308 /* If we cannot get anything for some long time, we better
309 bail out instead of waiting infinitely */
310 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
311 rc = l_wait_event(svc->srv_free_rs_waitq,
312 !list_empty(&svc->srv_free_rs_list), &lwi);
315 spin_lock(&svc->srv_lock);
318 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
320 list_del(&rs->rs_list);
321 spin_unlock(&svc->srv_lock);
323 LASSERTF(svc->srv_max_reply_size > size, "Want %d, prealloc %d\n", size,
324 svc->srv_max_reply_size);
331 static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count,
332 int *lens, char **bufs)
334 struct ptlrpc_reply_state *rs;
339 LASSERT (req->rq_reply_state == NULL);
341 msg_len = lustre_msg_size_v1(count, lens);
342 size = sizeof(struct ptlrpc_reply_state) + msg_len;
344 if (unlikely(rs == NULL)) {
345 rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_service, size);
349 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
350 rs->rs_cb_id.cbid_fn = reply_out_callback;
351 rs->rs_cb_id.cbid_arg = rs;
352 rs->rs_service = req->rq_rqbd->rqbd_service;
354 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
355 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
356 rs->rs_msg = (struct lustre_msg *)(rs + 1);
358 req->rq_replen = msg_len;
359 req->rq_reply_state = rs;
360 req->rq_repmsg = rs->rs_msg;
361 lustre_init_msg_v1(rs->rs_msg, count, lens, bufs);
363 PTLRPC_RS_DEBUG_LRU_ADD(rs);
368 static int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
369 int *lens, char **bufs)
371 struct ptlrpc_reply_state *rs;
376 LASSERT(req->rq_reply_state == NULL);
378 msg_len = lustre_msg_size_v2(count, lens);
379 size = sizeof(struct ptlrpc_reply_state) + msg_len;
381 if (unlikely(rs == NULL)) {
382 rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_service, size);
386 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
387 rs->rs_cb_id.cbid_fn = reply_out_callback;
388 rs->rs_cb_id.cbid_arg = rs;
389 rs->rs_service = req->rq_rqbd->rqbd_service;
391 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
392 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
393 rs->rs_msg = (struct lustre_msg *)(rs + 1);
395 req->rq_replen = msg_len;
396 req->rq_reply_state = rs;
397 req->rq_repmsg = rs->rs_msg;
398 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
399 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
400 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
402 PTLRPC_RS_DEBUG_LRU_ADD(rs);
407 int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
410 int size[] = { sizeof(struct ptlrpc_body) };
418 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
420 switch (req->rq_reqmsg->lm_magic) {
421 case LUSTRE_MSG_MAGIC_V1:
422 case LUSTRE_MSG_MAGIC_V1_SWABBED:
423 return lustre_pack_reply_v1(req, count - 1, lens + 1,
424 bufs ? bufs + 1 : NULL);
425 case LUSTRE_MSG_MAGIC_V2:
426 case LUSTRE_MSG_MAGIC_V2_SWABBED:
427 return lustre_pack_reply_v2(req, count, lens, bufs);
429 LASSERTF(0, "incorrect message magic: %08x\n",
430 req->rq_reqmsg->lm_magic);
435 void *lustre_msg_buf_v1(void *msg, int n, int min_size)
437 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
438 int i, offset, buflen, bufcount;
443 bufcount = m->lm_bufcount;
445 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
450 buflen = m->lm_buflens[n];
451 if (buflen < min_size) {
452 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
453 m, n, buflen, min_size);
458 offset = lustre_msg_hdr_size_v1(bufcount);
459 for (i = 0; i < n; i++)
460 offset += size_round(m->lm_buflens[i]);
462 return (char *)m + offset;
465 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
467 int i, offset, buflen, bufcount;
472 bufcount = m->lm_bufcount;
474 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
479 buflen = m->lm_buflens[n];
480 if (buflen < min_size) {
481 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
482 m, n, buflen, min_size);
486 offset = lustre_msg_hdr_size_v2(bufcount);
487 for (i = 0; i < n; i++)
488 offset += size_round(m->lm_buflens[i]);
490 return (char *)m + offset;
493 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
495 switch (m->lm_magic) {
496 case LUSTRE_MSG_MAGIC_V1:
497 case LUSTRE_MSG_MAGIC_V1_SWABBED:
498 return lustre_msg_buf_v1(m, n - 1, min_size);
499 case LUSTRE_MSG_MAGIC_V2:
500 case LUSTRE_MSG_MAGIC_V2_SWABBED:
501 return lustre_msg_buf_v2(m, n, min_size);
503 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
508 void lustre_shrink_reply_v1(struct ptlrpc_request *req, int segment,
509 unsigned int newlen, int move_data)
511 struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)req->rq_repmsg;
512 char *tail = NULL, *newpos;
515 LASSERT(req->rq_reply_state);
517 LASSERT(segment >= 0);
518 LASSERT(msg->lm_bufcount > segment);
519 LASSERT(msg->lm_buflens[segment] >= newlen);
521 if (msg->lm_buflens[segment] == newlen)
524 if (move_data && msg->lm_bufcount > segment + 1) {
525 tail = lustre_msg_buf_v1(msg, segment + 1, 0);
526 for (n = segment + 1; n < msg->lm_bufcount; n++)
527 tail_len += size_round(msg->lm_buflens[n]);
530 msg->lm_buflens[segment] = newlen;
532 if (tail && tail_len) {
533 newpos = lustre_msg_buf_v1(msg, segment + 1, 0);
534 LASSERT(newpos <= tail);
536 memcpy(newpos, tail, tail_len);
539 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
540 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
541 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
542 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
545 req->rq_replen = lustre_msg_size_v1(msg->lm_bufcount, msg->lm_buflens);
548 void lustre_shrink_reply_v2(struct ptlrpc_request *req, int segment,
549 unsigned int newlen, int move_data)
551 struct lustre_msg_v2 *msg = req->rq_repmsg;
552 char *tail = NULL, *newpos;
555 LASSERT(req->rq_reply_state);
557 LASSERT(msg->lm_bufcount > segment);
558 LASSERT(msg->lm_buflens[segment] >= newlen);
560 if (msg->lm_buflens[segment] == newlen)
563 if (move_data && msg->lm_bufcount > segment + 1) {
564 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
565 for (n = segment + 1; n < msg->lm_bufcount; n++)
566 tail_len += size_round(msg->lm_buflens[n]);
569 msg->lm_buflens[segment] = newlen;
571 if (tail && tail_len) {
572 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
573 LASSERT(newpos <= tail);
575 memcpy(newpos, tail, tail_len);
578 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
579 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
580 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
581 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
584 req->rq_replen = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
588 * shrink @segment to size @newlen. if @move_data is non-zero, we also move
589 * data forward from @segment + 1.
591 * if @newlen == 0, we remove the segment completely, but we still keep the
592 * totally bufcount the same to save possible data moving. this will leave a
593 * unused segment with size 0 at the tail, but that's ok.
596 * + if any buffers higher than @segment has been filled in, must call shrink
597 * with non-zero @move_data.
598 * + caller should NOT keep pointers to msg buffers which higher than @segment
601 void lustre_shrink_reply(struct ptlrpc_request *req, int segment,
602 unsigned int newlen, int move_data)
604 switch (req->rq_repmsg->lm_magic) {
605 case LUSTRE_MSG_MAGIC_V1:
606 lustre_shrink_reply_v1(req, segment - 1, newlen, move_data);
608 case LUSTRE_MSG_MAGIC_V2:
609 lustre_shrink_reply_v2(req, segment, newlen, move_data);
612 LASSERTF(0, "incorrect message magic: %08x\n",
613 req->rq_repmsg->lm_magic);
617 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
619 PTLRPC_RS_DEBUG_LRU_DEL(rs);
621 LASSERT (atomic_read(&rs->rs_refcount) == 0);
622 LASSERT (!rs->rs_difficult || rs->rs_handled);
623 LASSERT (!rs->rs_on_net);
624 LASSERT (!rs->rs_scheduled);
625 LASSERT (rs->rs_export == NULL);
626 LASSERT (rs->rs_nlocks == 0);
627 LASSERT (list_empty(&rs->rs_exp_list));
628 LASSERT (list_empty(&rs->rs_obd_list));
630 if (unlikely(rs->rs_prealloc)) {
631 struct ptlrpc_service *svc = rs->rs_service;
633 spin_lock(&svc->srv_lock);
634 list_add(&rs->rs_list,
635 &svc->srv_free_rs_list);
636 spin_unlock(&svc->srv_lock);
637 cfs_waitq_signal(&svc->srv_free_rs_waitq);
639 OBD_FREE(rs, rs->rs_size);
643 int lustre_unpack_msg_v1(void *msg, int len)
645 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
646 int flipped, required_len, i;
649 /* Now we know the sender speaks my language. */
650 required_len = lustre_msg_hdr_size_v1(0);
651 if (len < required_len) {
652 /* can't even look inside the message */
653 CERROR("message length %d too small for lustre_msg\n", len);
657 flipped = lustre_msg_swabbed((struct lustre_msg *)m);
660 __swab32s(&m->lm_type);
661 __swab32s(&m->lm_version);
662 __swab32s(&m->lm_opc);
663 __swab64s(&m->lm_last_xid);
664 __swab64s(&m->lm_last_committed);
665 __swab64s(&m->lm_transno);
666 __swab32s(&m->lm_status);
667 __swab32s(&m->lm_flags);
668 __swab32s(&m->lm_conn_cnt);
669 __swab32s(&m->lm_bufcount);
672 if (m->lm_version != PTLRPC_MSG_VERSION) {
673 CERROR("wrong lustre_msg version %08x\n", m->lm_version);
677 required_len = lustre_msg_hdr_size_v1(m->lm_bufcount);
678 if (len < required_len) {
679 /* didn't receive all the buffer lengths */
680 CERROR("message length %d too small for %d buflens\n",
681 len, m->lm_bufcount);
685 for (i = 0; i < m->lm_bufcount; i++) {
687 __swab32s (&m->lm_buflens[i]);
688 required_len += size_round(m->lm_buflens[i]);
691 if (len < required_len) {
692 CERROR("len: %d, required_len %d\n", len, required_len);
693 CERROR("bufcount: %d\n", m->lm_bufcount);
694 for (i = 0; i < m->lm_bufcount; i++)
695 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
702 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
704 int flipped, required_len, i;
706 /* Now we know the sender speaks my language. */
707 required_len = lustre_msg_hdr_size_v2(0);
708 if (len < required_len) {
709 /* can't even look inside the message */
710 CERROR("message length %d too small for lustre_msg\n", len);
714 flipped = lustre_msg_swabbed(m);
717 __swab32s(&m->lm_bufcount);
718 __swab32s(&m->lm_secflvr);
719 __swab32s(&m->lm_repsize);
720 __swab32s(&m->lm_timeout);
721 CLASSERT(offsetof(typeof(*m), lm_padding_1) != 0);
722 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
723 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
726 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
727 if (len < required_len) {
728 /* didn't receive all the buffer lengths */
729 CERROR ("message length %d too small for %d buflens\n",
730 len, m->lm_bufcount);
734 for (i = 0; i < m->lm_bufcount; i++) {
736 __swab32s(&m->lm_buflens[i]);
737 required_len += size_round(m->lm_buflens[i]);
740 if (len < required_len) {
741 CERROR("len: %d, required_len %d\n", len, required_len);
742 CERROR("bufcount: %d\n", m->lm_bufcount);
743 for (i = 0; i < m->lm_bufcount; i++)
744 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
751 int lustre_unpack_msg(struct lustre_msg *m, int len)
753 int required_len, rc;
756 /* We can provide a slightly better error log, if we check the
757 * message magic and version first. In the future, struct
758 * lustre_msg may grow, and we'd like to log a version mismatch,
759 * rather than a short message.
762 required_len = offsetof(struct lustre_msg, lm_magic) +
764 if (len < required_len) {
765 /* can't even look inside the message */
766 CERROR("message length %d too small for magic/version check\n",
771 switch (m->lm_magic) {
772 case LUSTRE_MSG_MAGIC_V1:
773 case LUSTRE_MSG_MAGIC_V1_SWABBED:
774 rc = lustre_unpack_msg_v1(m, len);
776 case LUSTRE_MSG_MAGIC_V2:
777 case LUSTRE_MSG_MAGIC_V2_SWABBED:
778 rc = lustre_unpack_msg_v2(m, len);
781 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
788 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
791 struct ptlrpc_body *pb;
793 pb = lustre_swab_buf(m, offset, sizeof(*pb), lustre_swab_ptlrpc_body);
795 CERROR("error unpacking ptlrpc body");
799 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
800 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
807 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
809 switch (req->rq_reqmsg->lm_magic) {
810 case LUSTRE_MSG_MAGIC_V1:
811 case LUSTRE_MSG_MAGIC_V1_SWABBED:
813 case LUSTRE_MSG_MAGIC_V2:
814 case LUSTRE_MSG_MAGIC_V2_SWABBED:
815 lustre_set_req_swabbed(req, offset);
816 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
818 CERROR("bad lustre msg magic: %#08X\n",
819 req->rq_reqmsg->lm_magic);
824 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
826 switch (req->rq_repmsg->lm_magic) {
827 case LUSTRE_MSG_MAGIC_V1:
828 case LUSTRE_MSG_MAGIC_V1_SWABBED:
830 case LUSTRE_MSG_MAGIC_V2:
831 case LUSTRE_MSG_MAGIC_V2_SWABBED:
832 lustre_set_rep_swabbed(req, offset);
833 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
835 CERROR("bad lustre msg magic: %#08X\n",
836 req->rq_repmsg->lm_magic);
841 static inline int lustre_msg_buflen_v1(void *msg, int n)
843 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
846 if (n >= m->lm_bufcount)
849 return m->lm_buflens[n];
852 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
854 if (n >= m->lm_bufcount)
857 return m->lm_buflens[n];
861 * lustre_msg_buflen - return the length of buffer @n in message @m
862 * @m - lustre_msg (request or reply) to look at
863 * @n - message index (base 0)
865 * returns zero for non-existent message indices
867 int lustre_msg_buflen(struct lustre_msg *m, int n)
869 switch (m->lm_magic) {
870 case LUSTRE_MSG_MAGIC_V1:
871 case LUSTRE_MSG_MAGIC_V1_SWABBED:
872 return lustre_msg_buflen_v1(m, n - 1);
873 case LUSTRE_MSG_MAGIC_V2:
874 case LUSTRE_MSG_MAGIC_V2_SWABBED:
875 return lustre_msg_buflen_v2(m, n);
877 CERROR("incorrect message magic: %08x\n", m->lm_magic);
881 EXPORT_SYMBOL(lustre_msg_buflen);
883 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
885 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
888 if (n >= m->lm_bufcount)
891 m->lm_buflens[n] = len;
895 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
897 if (n >= m->lm_bufcount)
900 m->lm_buflens[n] = len;
903 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
905 switch (m->lm_magic) {
906 case LUSTRE_MSG_MAGIC_V1:
907 lustre_msg_set_buflen_v1(m, n - 1, len);
909 case LUSTRE_MSG_MAGIC_V2:
910 lustre_msg_set_buflen_v2(m, n, len);
913 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
917 EXPORT_SYMBOL(lustre_msg_set_buflen);
919 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
920 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
921 int lustre_msg_bufcount(struct lustre_msg *m)
923 switch (m->lm_magic) {
924 case LUSTRE_MSG_MAGIC_V1:
925 case LUSTRE_MSG_MAGIC_V1_SWABBED:
926 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
927 case LUSTRE_MSG_MAGIC_V2:
928 case LUSTRE_MSG_MAGIC_V2_SWABBED:
929 return m->lm_bufcount;
931 CERROR("incorrect message magic: %08x\n", m->lm_magic);
935 EXPORT_SYMBOL(lustre_msg_bufcount);
937 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
939 /* max_len == 0 means the string should fill the buffer */
943 switch (m->lm_magic) {
944 case LUSTRE_MSG_MAGIC_V1:
945 case LUSTRE_MSG_MAGIC_V1_SWABBED:
946 str = lustre_msg_buf_v1(m, index - 1, 0);
947 blen = lustre_msg_buflen_v1(m, index - 1);
949 case LUSTRE_MSG_MAGIC_V2:
950 case LUSTRE_MSG_MAGIC_V2_SWABBED:
951 str = lustre_msg_buf_v2(m, index, 0);
952 blen = lustre_msg_buflen_v2(m, index);
955 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
959 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
963 slen = strnlen(str, blen);
965 if (slen == blen) { /* not NULL terminated */
966 CERROR("can't unpack non-NULL terminated string in "
967 "msg %p buffer[%d] len %d\n", m, index, blen);
972 if (slen != blen - 1) {
973 CERROR("can't unpack short string in msg %p "
974 "buffer[%d] len %d: strlen %d\n",
975 m, index, blen, slen);
978 } else if (slen > max_len) {
979 CERROR("can't unpack oversized string in msg %p "
980 "buffer[%d] len %d strlen %d: max %d expected\n",
981 m, index, blen, slen, max_len);
988 /* Wrap up the normal fixed length cases */
989 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
994 switch (msg->lm_magic) {
995 case LUSTRE_MSG_MAGIC_V1:
996 case LUSTRE_MSG_MAGIC_V1_SWABBED:
997 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
999 case LUSTRE_MSG_MAGIC_V2:
1000 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1001 ptr = lustre_msg_buf_v2(msg, index, min_size);
1004 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1009 if (swabber != NULL && lustre_msg_swabbed(msg))
1010 ((void (*)(void *))swabber)(ptr);
1015 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
1018 LASSERT_REQSWAB(req, index);
1019 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
1022 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
1025 LASSERT_REPSWAB(req, index);
1026 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
1029 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
1031 switch (msg->lm_magic) {
1032 case LUSTRE_MSG_MAGIC_V1:
1033 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1034 return ((struct lustre_msg_v1 *)msg)->lm_flags &
1036 case LUSTRE_MSG_MAGIC_V2:
1037 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1038 struct ptlrpc_body *pb;
1040 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1042 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1045 return pb->pb_flags;
1048 /* flags might be printed in debug code while message
1054 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
1056 switch (msg->lm_magic) {
1057 case LUSTRE_MSG_MAGIC_V1:
1058 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1059 MSG_GEN_FLAG_MASK & flags;
1061 case LUSTRE_MSG_MAGIC_V2: {
1062 struct ptlrpc_body *pb;
1064 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1065 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1066 pb->pb_flags |= flags;
1070 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1074 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
1076 switch (msg->lm_magic) {
1077 case LUSTRE_MSG_MAGIC_V1:
1078 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK;
1079 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1080 MSG_GEN_FLAG_MASK & flags;
1082 case LUSTRE_MSG_MAGIC_V2: {
1083 struct ptlrpc_body *pb;
1085 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1086 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1087 pb->pb_flags = flags;
1091 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1095 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1097 switch (msg->lm_magic) {
1098 case LUSTRE_MSG_MAGIC_V1:
1099 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1100 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1101 ~(MSG_GEN_FLAG_MASK & flags);
1103 case LUSTRE_MSG_MAGIC_V2:
1104 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1105 struct ptlrpc_body *pb;
1107 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1108 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1109 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
1113 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1117 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1119 switch (msg->lm_magic) {
1120 case LUSTRE_MSG_MAGIC_V1:
1121 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1122 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1124 case LUSTRE_MSG_MAGIC_V2:
1125 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1126 struct ptlrpc_body *pb;
1128 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1130 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1133 return pb->pb_op_flags;
1140 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1142 switch (msg->lm_magic) {
1143 case LUSTRE_MSG_MAGIC_V1:
1144 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1145 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1147 case LUSTRE_MSG_MAGIC_V2: {
1148 struct ptlrpc_body *pb;
1150 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1151 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1152 pb->pb_op_flags |= flags;
1156 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1160 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
1162 switch (msg->lm_magic) {
1163 case LUSTRE_MSG_MAGIC_V1:
1164 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK;
1165 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1166 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1168 case LUSTRE_MSG_MAGIC_V2: {
1169 struct ptlrpc_body *pb;
1171 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1172 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1173 pb->pb_op_flags |= flags;
1177 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1181 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1183 switch (msg->lm_magic) {
1184 case LUSTRE_MSG_MAGIC_V1:
1185 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1186 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1187 case LUSTRE_MSG_MAGIC_V2:
1188 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1189 struct ptlrpc_body *pb;
1191 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1193 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1196 return &pb->pb_handle;
1199 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1204 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1206 switch (msg->lm_magic) {
1207 case LUSTRE_MSG_MAGIC_V1:
1208 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1209 return ((struct lustre_msg_v1 *)msg)->lm_type;
1210 case LUSTRE_MSG_MAGIC_V2:
1211 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1212 struct ptlrpc_body *pb;
1214 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1216 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1217 return PTL_RPC_MSG_ERR;
1222 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1223 return PTL_RPC_MSG_ERR;
1227 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1229 switch (msg->lm_magic) {
1230 case LUSTRE_MSG_MAGIC_V1:
1231 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1232 return ((struct lustre_msg_v1 *)msg)->lm_version;
1233 case LUSTRE_MSG_MAGIC_V2:
1234 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1235 struct ptlrpc_body *pb;
1237 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1239 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1242 return pb->pb_version;
1245 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1250 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1252 switch (msg->lm_magic) {
1253 case LUSTRE_MSG_MAGIC_V1:
1254 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1256 case LUSTRE_MSG_MAGIC_V2:
1257 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1258 struct ptlrpc_body *pb;
1260 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1261 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1262 pb->pb_version |= version;
1266 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1270 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1272 switch (msg->lm_magic) {
1273 case LUSTRE_MSG_MAGIC_V1:
1274 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1275 return ((struct lustre_msg_v1 *)msg)->lm_opc;
1276 case LUSTRE_MSG_MAGIC_V2:
1277 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1278 struct ptlrpc_body *pb;
1280 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1282 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1288 CERROR( "incorrect message magic: %08x\n", msg->lm_magic);
1293 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1295 switch (msg->lm_magic) {
1296 case LUSTRE_MSG_MAGIC_V1:
1297 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1298 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1299 case LUSTRE_MSG_MAGIC_V2:
1300 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1301 struct ptlrpc_body *pb;
1303 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1305 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1308 return pb->pb_last_xid;
1311 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1316 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1318 switch (msg->lm_magic) {
1319 case LUSTRE_MSG_MAGIC_V1:
1320 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1321 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1322 case LUSTRE_MSG_MAGIC_V2:
1323 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1324 struct ptlrpc_body *pb;
1326 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1328 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1331 return pb->pb_last_committed;
1334 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1339 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1341 switch (msg->lm_magic) {
1342 case LUSTRE_MSG_MAGIC_V1:
1343 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1344 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1345 case LUSTRE_MSG_MAGIC_V2:
1346 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1347 struct ptlrpc_body *pb;
1349 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1351 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1354 return pb->pb_transno;
1357 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1362 int lustre_msg_get_status(struct lustre_msg *msg)
1364 switch (msg->lm_magic) {
1365 case LUSTRE_MSG_MAGIC_V1:
1366 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1367 return ((struct lustre_msg_v1 *)msg)->lm_status;
1368 case LUSTRE_MSG_MAGIC_V2:
1369 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1370 struct ptlrpc_body *pb;
1372 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1374 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1377 return pb->pb_status;
1380 /* status might be printed in debug code while message
1386 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1388 switch (msg->lm_magic) {
1389 case LUSTRE_MSG_MAGIC_V1:
1390 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1391 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1392 case LUSTRE_MSG_MAGIC_V2:
1393 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1394 struct ptlrpc_body *pb;
1396 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1398 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1401 return pb->pb_conn_cnt;
1404 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1409 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1411 switch (msg->lm_magic) {
1412 case LUSTRE_MSG_MAGIC_V1:
1413 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1414 case LUSTRE_MSG_MAGIC_V2:
1415 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1416 return msg->lm_magic;
1418 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1423 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1425 switch (msg->lm_magic) {
1426 case LUSTRE_MSG_MAGIC_V1:
1427 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
1429 case LUSTRE_MSG_MAGIC_V2: {
1430 struct ptlrpc_body *pb;
1432 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1433 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1434 pb->pb_handle = *handle;
1438 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1442 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1444 switch (msg->lm_magic) {
1445 case LUSTRE_MSG_MAGIC_V1:
1446 ((struct lustre_msg_v1 *)msg)->lm_type = type;
1448 case LUSTRE_MSG_MAGIC_V2: {
1449 struct ptlrpc_body *pb;
1451 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1452 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1457 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1461 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1463 switch (msg->lm_magic) {
1464 case LUSTRE_MSG_MAGIC_V1:
1465 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
1467 case LUSTRE_MSG_MAGIC_V2: {
1468 struct ptlrpc_body *pb;
1470 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1471 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1476 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1480 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1482 switch (msg->lm_magic) {
1483 case LUSTRE_MSG_MAGIC_V1:
1484 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1486 case LUSTRE_MSG_MAGIC_V2: {
1487 struct ptlrpc_body *pb;
1489 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1490 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1491 pb->pb_last_xid = last_xid;
1495 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1499 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1501 switch (msg->lm_magic) {
1502 case LUSTRE_MSG_MAGIC_V1:
1503 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1505 case LUSTRE_MSG_MAGIC_V2: {
1506 struct ptlrpc_body *pb;
1508 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1509 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1510 pb->pb_last_committed = last_committed;
1514 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1518 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1520 switch (msg->lm_magic) {
1521 case LUSTRE_MSG_MAGIC_V1:
1522 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1524 case LUSTRE_MSG_MAGIC_V2: {
1525 struct ptlrpc_body *pb;
1527 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1528 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1529 pb->pb_transno = transno;
1533 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1537 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1539 switch (msg->lm_magic) {
1540 case LUSTRE_MSG_MAGIC_V1:
1541 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1543 case LUSTRE_MSG_MAGIC_V2: {
1544 struct ptlrpc_body *pb;
1546 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1547 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1548 pb->pb_status = status;
1552 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1556 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1558 switch (msg->lm_magic) {
1559 case LUSTRE_MSG_MAGIC_V1:
1560 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1562 case LUSTRE_MSG_MAGIC_V2: {
1563 struct ptlrpc_body *pb;
1565 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1566 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1567 pb->pb_conn_cnt = conn_cnt;
1571 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1575 /* byte flipping routines for all wire types declared in
1576 * lustre_idl.h implemented here.
1578 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1580 __swab32s (&b->pb_type);
1581 __swab32s (&b->pb_version);
1582 __swab32s (&b->pb_opc);
1583 __swab32s (&b->pb_status);
1584 __swab64s (&b->pb_last_xid);
1585 __swab64s (&b->pb_last_seen);
1586 __swab64s (&b->pb_last_committed);
1587 __swab64s (&b->pb_transno);
1588 __swab32s (&b->pb_flags);
1589 __swab32s (&b->pb_op_flags);
1590 __swab32s (&b->pb_conn_cnt);
1591 CLASSERT(offsetof(typeof(*b), pb_padding_1) != 0);
1592 CLASSERT(offsetof(typeof(*b), pb_padding_2) != 0);
1593 CLASSERT(offsetof(typeof(*b), pb_padding_3) != 0);
1594 CLASSERT(offsetof(typeof(*b), pb_padding_4) != 0);
1595 CLASSERT(offsetof(typeof(*b), pb_padding_5) != 0);
1598 void lustre_swab_connect(struct obd_connect_data *ocd)
1600 __swab64s(&ocd->ocd_connect_flags);
1601 __swab32s(&ocd->ocd_version);
1602 __swab32s(&ocd->ocd_grant);
1603 __swab32s(&ocd->ocd_index);
1604 __swab32s(&ocd->ocd_brw_size);
1605 __swab64s(&ocd->ocd_ibits_known);
1606 __swab32s(&ocd->ocd_nllu);
1607 __swab32s(&ocd->ocd_nllg);
1608 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1609 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1610 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1611 CLASSERT(offsetof(typeof(*ocd), padding4) != 0);
1614 void lustre_swab_obdo (struct obdo *o)
1616 __swab64s (&o->o_valid);
1617 __swab64s (&o->o_id);
1618 __swab64s (&o->o_gr);
1619 __swab64s (&o->o_fid);
1620 __swab64s (&o->o_size);
1621 __swab64s (&o->o_mtime);
1622 __swab64s (&o->o_atime);
1623 __swab64s (&o->o_ctime);
1624 __swab64s (&o->o_blocks);
1625 __swab64s (&o->o_grant);
1626 __swab32s (&o->o_blksize);
1627 __swab32s (&o->o_mode);
1628 __swab32s (&o->o_uid);
1629 __swab32s (&o->o_gid);
1630 __swab32s (&o->o_flags);
1631 __swab32s (&o->o_nlink);
1632 __swab32s (&o->o_generation);
1633 __swab32s (&o->o_misc);
1634 __swab32s (&o->o_easize);
1635 __swab32s (&o->o_mds);
1636 __swab32s (&o->o_stripe_idx);
1637 __swab32s (&o->o_padding_1);
1638 /* o_inline is opaque */
1641 void lustre_swab_obd_statfs (struct obd_statfs *os)
1643 __swab64s (&os->os_type);
1644 __swab64s (&os->os_blocks);
1645 __swab64s (&os->os_bfree);
1646 __swab64s (&os->os_bavail);
1647 __swab64s (&os->os_files);
1648 __swab64s (&os->os_ffree);
1649 /* no need to swab os_fsid */
1650 __swab32s (&os->os_bsize);
1651 __swab32s (&os->os_namelen);
1652 __swab64s (&os->os_maxbytes);
1653 __swab32s (&os->os_state);
1654 /* no need to swap os_spare */
1657 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1659 __swab64s (&ioo->ioo_id);
1660 __swab64s (&ioo->ioo_gr);
1661 __swab32s (&ioo->ioo_type);
1662 __swab32s (&ioo->ioo_bufcnt);
1665 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1667 __swab64s (&nbr->offset);
1668 __swab32s (&nbr->len);
1669 __swab32s (&nbr->flags);
1672 void lustre_swab_ost_body (struct ost_body *b)
1674 lustre_swab_obdo (&b->oa);
1677 void lustre_swab_ost_last_id(obd_id *id)
1682 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1684 __swab64s(&lvb->lvb_size);
1685 __swab64s(&lvb->lvb_mtime);
1686 __swab64s(&lvb->lvb_atime);
1687 __swab64s(&lvb->lvb_ctime);
1688 __swab64s(&lvb->lvb_blocks);
1691 void lustre_swab_mds_status_req (struct mds_status_req *r)
1693 __swab32s (&r->flags);
1694 __swab32s (&r->repbuf);
1697 void lustre_swab_mds_body (struct mds_body *b)
1699 lustre_swab_ll_fid (&b->fid1);
1700 lustre_swab_ll_fid (&b->fid2);
1701 /* handle is opaque */
1702 __swab64s (&b->valid);
1703 __swab64s (&b->size);
1704 __swab64s (&b->mtime);
1705 __swab64s (&b->atime);
1706 __swab64s (&b->ctime);
1707 __swab64s (&b->blocks);
1708 __swab64s (&b->io_epoch);
1709 __swab64s (&b->ino);
1710 __swab32s (&b->fsuid);
1711 __swab32s (&b->fsgid);
1712 __swab32s (&b->capability);
1713 __swab32s (&b->mode);
1714 __swab32s (&b->uid);
1715 __swab32s (&b->gid);
1716 __swab32s (&b->flags);
1717 __swab32s (&b->rdev);
1718 __swab32s (&b->nlink);
1719 __swab32s (&b->generation);
1720 __swab32s (&b->suppgid);
1721 __swab32s (&b->eadatasize);
1722 __swab32s (&b->aclsize);
1723 __swab32s (&b->max_mdsize);
1724 __swab32s (&b->max_cookiesize);
1725 __swab32s (&b->padding_4);
1728 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1731 __swab32s(&mti->mti_lustre_ver);
1732 __swab32s(&mti->mti_stripe_index);
1733 __swab32s(&mti->mti_config_ver);
1734 __swab32s(&mti->mti_flags);
1735 __swab32s(&mti->mti_nid_count);
1736 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1737 for (i = 0; i < MTI_NIDS_MAX; i++)
1738 __swab64s(&mti->mti_nids[i]);
1741 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1743 __swab64s (&i->dqi_bgrace);
1744 __swab64s (&i->dqi_igrace);
1745 __swab32s (&i->dqi_flags);
1746 __swab32s (&i->dqi_valid);
1749 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1751 __swab64s (&b->dqb_ihardlimit);
1752 __swab64s (&b->dqb_isoftlimit);
1753 __swab64s (&b->dqb_curinodes);
1754 __swab64s (&b->dqb_bhardlimit);
1755 __swab64s (&b->dqb_bsoftlimit);
1756 __swab64s (&b->dqb_curspace);
1757 __swab64s (&b->dqb_btime);
1758 __swab64s (&b->dqb_itime);
1759 __swab32s (&b->dqb_valid);
1760 CLASSERT(offsetof(typeof(*b), padding) != 0);
1763 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1765 __swab32s (&q->qc_cmd);
1766 __swab32s (&q->qc_type);
1767 __swab32s (&q->qc_id);
1768 __swab32s (&q->qc_stat);
1769 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1770 lustre_swab_obd_dqblk (&q->qc_dqblk);
1773 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1775 __swab32s (&sa->sa_opcode);
1776 __swab32s (&sa->sa_fsuid);
1777 __swab32s (&sa->sa_fsgid);
1778 __swab32s (&sa->sa_cap);
1779 __swab32s (&sa->sa_suppgid);
1780 __swab32s (&sa->sa_mode);
1781 lustre_swab_ll_fid (&sa->sa_fid);
1782 __swab64s (&sa->sa_valid);
1783 __swab64s (&sa->sa_size);
1784 __swab64s (&sa->sa_mtime);
1785 __swab64s (&sa->sa_atime);
1786 __swab64s (&sa->sa_ctime);
1787 __swab32s (&sa->sa_uid);
1788 __swab32s (&sa->sa_gid);
1789 __swab32s (&sa->sa_attr_flags);
1790 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1793 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1795 __swab64s(&jr->jr_headsize);
1796 lustre_swab_ll_fid(&jr->jr_fid);
1799 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1801 __swab32s (&cr->cr_opcode);
1802 __swab32s (&cr->cr_fsuid);
1803 __swab32s (&cr->cr_fsgid);
1804 __swab32s (&cr->cr_cap);
1805 __swab32s (&cr->cr_flags); /* for use with open */
1806 __swab32s (&cr->cr_mode);
1807 lustre_swab_ll_fid (&cr->cr_fid);
1808 lustre_swab_ll_fid (&cr->cr_replayfid);
1809 __swab64s (&cr->cr_time);
1810 __swab64s (&cr->cr_rdev);
1811 __swab32s (&cr->cr_suppgid);
1812 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1813 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1814 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1815 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1816 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1819 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1821 __swab32s (&lk->lk_opcode);
1822 __swab32s (&lk->lk_fsuid);
1823 __swab32s (&lk->lk_fsgid);
1824 __swab32s (&lk->lk_cap);
1825 __swab32s (&lk->lk_suppgid1);
1826 __swab32s (&lk->lk_suppgid2);
1827 lustre_swab_ll_fid (&lk->lk_fid1);
1828 lustre_swab_ll_fid (&lk->lk_fid2);
1829 __swab64s (&lk->lk_time);
1830 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1831 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1832 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1833 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1836 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1838 __swab32s (&ul->ul_opcode);
1839 __swab32s (&ul->ul_fsuid);
1840 __swab32s (&ul->ul_fsgid);
1841 __swab32s (&ul->ul_cap);
1842 __swab32s (&ul->ul_suppgid);
1843 __swab32s (&ul->ul_mode);
1844 lustre_swab_ll_fid (&ul->ul_fid1);
1845 lustre_swab_ll_fid (&ul->ul_fid2);
1846 __swab64s (&ul->ul_time);
1847 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1848 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1849 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1850 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1853 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1855 __swab32s (&rn->rn_opcode);
1856 __swab32s (&rn->rn_fsuid);
1857 __swab32s (&rn->rn_fsgid);
1858 __swab32s (&rn->rn_cap);
1859 __swab32s (&rn->rn_suppgid1);
1860 __swab32s (&rn->rn_suppgid2);
1861 lustre_swab_ll_fid (&rn->rn_fid1);
1862 lustre_swab_ll_fid (&rn->rn_fid2);
1863 __swab64s (&rn->rn_time);
1864 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1865 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1866 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1867 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1870 void lustre_swab_lov_desc (struct lov_desc *ld)
1872 __swab32s (&ld->ld_tgt_count);
1873 __swab32s (&ld->ld_active_tgt_count);
1874 __swab32s (&ld->ld_default_stripe_count);
1875 __swab64s (&ld->ld_default_stripe_size);
1876 __swab64s (&ld->ld_default_stripe_offset);
1877 __swab32s (&ld->ld_pattern);
1878 __swab32s (&ld->ld_qos_maxage);
1879 /* uuid endian insensitive */
1882 static void print_lum (struct lov_user_md *lum)
1884 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1885 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1886 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1887 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1888 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
1889 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1890 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1891 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1894 void lustre_swab_lov_user_md(struct lov_user_md *lum)
1897 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
1898 __swab32s(&lum->lmm_magic);
1899 __swab32s(&lum->lmm_pattern);
1900 __swab64s(&lum->lmm_object_id);
1901 __swab64s(&lum->lmm_object_gr);
1902 __swab32s(&lum->lmm_stripe_size);
1903 __swab16s(&lum->lmm_stripe_count);
1904 __swab16s(&lum->lmm_stripe_offset);
1909 static void print_lumj (struct lov_user_md_join *lumj)
1911 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
1912 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
1913 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
1914 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
1915 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
1916 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
1917 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
1918 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
1921 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
1924 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
1925 __swab32s(&lumj->lmm_magic);
1926 __swab32s(&lumj->lmm_pattern);
1927 __swab64s(&lumj->lmm_object_id);
1928 __swab64s(&lumj->lmm_object_gr);
1929 __swab32s(&lumj->lmm_stripe_size);
1930 __swab32s(&lumj->lmm_stripe_count);
1931 __swab32s(&lumj->lmm_extent_count);
1936 static void print_lum_objs(struct lov_user_md *lum)
1938 struct lov_user_ost_data *lod;
1941 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
1943 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
1944 for (i = 0; i < lum->lmm_stripe_count; i++) {
1945 lod = &lum->lmm_objects[i];
1946 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
1947 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
1948 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
1949 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
1954 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
1956 struct lov_user_ost_data *lod;
1959 for (i = 0; i < lum->lmm_stripe_count; i++) {
1960 lod = &lum->lmm_objects[i];
1961 __swab64s(&lod->l_object_id);
1962 __swab64s(&lod->l_object_gr);
1963 __swab32s(&lod->l_ost_gen);
1964 __swab32s(&lod->l_ost_idx);
1966 print_lum_objs(lum);
1970 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
1974 for (i = 0; i < RES_NAME_SIZE; i++)
1975 __swab64s (&id->name[i]);
1978 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
1980 /* the lock data is a union and the first two fields are always an
1981 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
1982 * data the same way. */
1983 __swab64s(&d->l_extent.start);
1984 __swab64s(&d->l_extent.end);
1985 __swab64s(&d->l_extent.gid);
1986 __swab32s(&d->l_flock.pid);
1989 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
1991 __swab64s (&i->opc);
1994 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
1996 __swab32s (&r->lr_type);
1997 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
1998 lustre_swab_ldlm_res_id (&r->lr_name);
2001 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2003 lustre_swab_ldlm_resource_desc (&l->l_resource);
2004 __swab32s (&l->l_req_mode);
2005 __swab32s (&l->l_granted_mode);
2006 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2009 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2011 __swab32s (&rq->lock_flags);
2012 CLASSERT(offsetof(typeof(*rq), lock_padding) != 0);
2013 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2014 /* lock_handle1 opaque */
2015 /* lock_handle2 opaque */
2018 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2020 __swab32s (&r->lock_flags);
2021 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2022 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2023 /* lock_handle opaque */
2024 __swab64s (&r->lock_policy_res1);
2025 __swab64s (&r->lock_policy_res2);
2028 /* no one calls this */
2029 int llog_log_swabbed(struct llog_log_hdr *hdr)
2031 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2033 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2038 void lustre_swab_qdata(struct qunit_data *d)
2040 __swab32s (&d->qd_id);
2041 __swab32s (&d->qd_flags);
2042 __swab64s (&d->qd_count);
2045 void lustre_swab_qdata_old(struct qunit_data_old *d)
2047 __swab32s (&d->qd_id);
2048 __swab32s (&d->qd_type);
2049 __swab32s (&d->qd_count);
2050 __swab32s (&d->qd_isblk);
2054 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2056 struct qunit_data_old tmp;
2057 struct qunit_data *ret;
2064 ret = (struct qunit_data *)d;
2065 ret->qd_id = tmp.qd_id;
2066 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2067 ret->qd_count = tmp.qd_count;
2071 EXPORT_SYMBOL(lustre_quota_old_to_new);
2073 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2075 struct qunit_data tmp;
2076 struct qunit_data_old *ret;
2082 LASSERT(d->qd_count <= MAX_QUOTA_COUNT32);
2084 ret = (struct qunit_data_old *)d;
2085 ret->qd_id = tmp.qd_id;
2086 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2087 ret->qd_count = (__u32)tmp.qd_count;
2088 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2091 EXPORT_SYMBOL(lustre_quota_new_to_old);
2092 #endif /* __KERNEL__ */
2094 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2096 LASSERT(req->rq_reqmsg);
2098 switch (req->rq_reqmsg->lm_magic) {
2099 case LUSTRE_MSG_MAGIC_V1:
2100 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2102 case LUSTRE_MSG_MAGIC_V2:
2103 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2104 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2106 CERROR("bad lustre msg magic: %#08X\n",
2107 req->rq_reqmsg->lm_magic);
2112 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2114 LASSERT(req->rq_repmsg);
2116 switch (req->rq_repmsg->lm_magic) {
2117 case LUSTRE_MSG_MAGIC_V1:
2118 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2120 case LUSTRE_MSG_MAGIC_V2:
2121 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2122 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2124 /* uninitialized yet */
2129 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2130 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2135 va_start(args, fmt);
2136 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2137 data->msg_fn, data->msg_line, fmt, args,
2138 " req@%p x"LPD64"/t"LPD64" o%d->%s@%s:%d lens %d/%d ref %d fl "
2139 REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2140 req, req->rq_xid, req->rq_transno,
2141 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2142 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2144 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2146 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2148 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2149 (req->rq_import && req->rq_import->imp_client) ?
2150 req->rq_import->imp_client->cli_request_portal : -1,
2151 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2152 DEBUG_REQ_FLAGS(req),
2153 req->rq_reqmsg ? lustre_msg_get_flags(req->rq_reqmsg) : 0,
2154 req->rq_repmsg ? lustre_msg_get_flags(req->rq_repmsg) : 0,
2156 req->rq_repmsg ? lustre_msg_get_status(req->rq_repmsg) : 0);
2160 EXPORT_SYMBOL(_debug_req);