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 static inline int lustre_msg_hdr_size_v2(int count)
44 return size_round(offsetof(struct lustre_msg_v2, lm_buflens[count]));
47 int lustre_msg_hdr_size(__u32 magic, int count)
50 case LUSTRE_MSG_MAGIC_V2:
51 return lustre_msg_hdr_size_v2(count);
53 LASSERTF(0, "incorrect message magic: %08x\n", magic);
57 EXPORT_SYMBOL(lustre_msg_hdr_size);
59 int lustre_msg_swabbed(struct lustre_msg *msg)
61 return (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:
76 CERROR("msg v1 not supported - please upgrade you system\n");
78 case LUSTRE_MSG_MAGIC_V2:
79 case LUSTRE_MSG_MAGIC_V2_SWABBED:
80 return lustre_msg_check_version_v2(msg, version);
82 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
87 int lustre_msg_size_v2(int count, int *lengths)
92 size = lustre_msg_hdr_size_v2(count);
93 for (i = 0; i < count; i++)
94 size += size_round(lengths[i]);
98 EXPORT_SYMBOL(lustre_msg_size_v2);
100 /* This returns the size of the buffer that is required to hold a lustre_msg
101 * with the given sub-buffer lengths.
102 * NOTE: this should only be used for NEW requests, and should always be
103 * in the form of a v2 request. If this is a connection to a v1
104 * target then the first buffer will be stripped because the ptlrpc
105 * data is part of the lustre_msg_v1 header. b=14043 */
106 int lustre_msg_size(__u32 magic, int count, int *lens)
108 int size[] = { sizeof(struct ptlrpc_body) };
116 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
119 case LUSTRE_MSG_MAGIC_V2:
120 return lustre_msg_size_v2(count, lens);
122 LASSERTF(0, "incorrect message magic: %08x\n", magic);
127 /* This is used to determine the size of a buffer that was already packed
128 * and will correctly handle the different message formats. */
129 int lustre_packed_msg_size(struct lustre_msg *msg)
131 switch (msg->lm_magic) {
132 case LUSTRE_MSG_MAGIC_V2:
133 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
135 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
140 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
146 msg->lm_bufcount = count;
147 /* XXX: lm_secflvr uninitialized here */
148 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
150 for (i = 0; i < count; i++)
151 msg->lm_buflens[i] = lens[i];
156 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
157 for (i = 0; i < count; i++) {
159 LOGL(tmp, lens[i], ptr);
162 EXPORT_SYMBOL(lustre_init_msg_v2);
164 static int lustre_pack_request_v2(struct ptlrpc_request *req,
165 int count, int *lens, char **bufs)
169 reqlen = lustre_msg_size_v2(count, lens);
171 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
175 req->rq_reqlen = reqlen;
177 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
178 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
179 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
183 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
184 int *lens, char **bufs)
186 int size[] = { sizeof(struct ptlrpc_body) };
194 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
196 /* only use new format, we don't need to be compatible with 1.4 */
197 magic = LUSTRE_MSG_MAGIC_V2;
200 case LUSTRE_MSG_MAGIC_V2:
201 return lustre_pack_request_v2(req, count, lens, bufs);
203 LASSERTF(0, "incorrect message magic: %08x\n", magic);
209 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
210 spinlock_t ptlrpc_rs_debug_lock;
212 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
214 spin_lock(&ptlrpc_rs_debug_lock); \
215 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
216 spin_unlock(&ptlrpc_rs_debug_lock); \
219 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
221 spin_lock(&ptlrpc_rs_debug_lock); \
222 list_del(&(rs)->rs_debug_list); \
223 spin_unlock(&ptlrpc_rs_debug_lock); \
226 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
227 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
230 struct ptlrpc_reply_state *lustre_get_emerg_rs(struct ptlrpc_service *svc)
232 struct ptlrpc_reply_state *rs = NULL;
234 spin_lock(&svc->srv_lock);
235 /* See if we have anything in a pool, and wait if nothing */
236 while (list_empty(&svc->srv_free_rs_list)) {
237 struct l_wait_info lwi;
239 spin_unlock(&svc->srv_lock);
240 /* If we cannot get anything for some long time, we better
241 bail out instead of waiting infinitely */
242 lwi = LWI_TIMEOUT(cfs_time_seconds(10), NULL, NULL);
243 rc = l_wait_event(svc->srv_free_rs_waitq,
244 !list_empty(&svc->srv_free_rs_list), &lwi);
247 spin_lock(&svc->srv_lock);
250 rs = list_entry(svc->srv_free_rs_list.next, struct ptlrpc_reply_state,
252 list_del(&rs->rs_list);
253 spin_unlock(&svc->srv_lock);
255 memset(rs, 0, svc->srv_max_reply_size);
256 rs->rs_service = svc;
262 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
264 struct ptlrpc_service *svc = rs->rs_service;
268 spin_lock(&svc->srv_lock);
269 list_add(&rs->rs_list, &svc->srv_free_rs_list);
270 spin_unlock(&svc->srv_lock);
271 cfs_waitq_signal(&svc->srv_free_rs_waitq);
274 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
275 int *lens, char **bufs)
277 struct ptlrpc_reply_state *rs;
281 LASSERT(req->rq_reply_state == NULL);
283 msg_len = lustre_msg_size_v2(count, lens);
284 rc = sptlrpc_svc_alloc_rs(req, msg_len);
288 rs = req->rq_reply_state;
289 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
290 rs->rs_cb_id.cbid_fn = reply_out_callback;
291 rs->rs_cb_id.cbid_arg = rs;
292 rs->rs_service = req->rq_rqbd->rqbd_service;
293 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
294 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
296 req->rq_replen = msg_len;
297 req->rq_reply_state = rs;
298 req->rq_repmsg = rs->rs_msg;
299 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
300 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
301 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
303 PTLRPC_RS_DEBUG_LRU_ADD(rs);
307 EXPORT_SYMBOL(lustre_pack_reply_v2);
309 int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
313 int size[] = { sizeof(struct ptlrpc_body) };
321 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
323 switch (req->rq_reqmsg->lm_magic) {
324 case LUSTRE_MSG_MAGIC_V2:
325 case LUSTRE_MSG_MAGIC_V2_SWABBED:
326 rc = lustre_pack_reply_v2(req, count, lens, bufs);
329 LASSERTF(0, "incorrect message magic: %08x\n",
330 req->rq_reqmsg->lm_magic);
334 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
335 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
339 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
341 int i, offset, buflen, bufcount;
346 bufcount = m->lm_bufcount;
347 if (unlikely(n >= bufcount)) {
348 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
353 buflen = m->lm_buflens[n];
354 if (unlikely(buflen < min_size)) {
355 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
356 m, n, buflen, min_size);
360 offset = lustre_msg_hdr_size_v2(bufcount);
361 for (i = 0; i < n; i++)
362 offset += size_round(m->lm_buflens[i]);
364 return (char *)m + offset;
367 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
369 switch (m->lm_magic) {
370 case LUSTRE_MSG_MAGIC_V2:
371 case LUSTRE_MSG_MAGIC_V2_SWABBED:
372 return lustre_msg_buf_v2(m, n, min_size);
374 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
379 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
380 unsigned int newlen, int move_data)
382 char *tail = NULL, *newpos;
386 LASSERT(msg->lm_bufcount > segment);
387 LASSERT(msg->lm_buflens[segment] >= newlen);
389 if (msg->lm_buflens[segment] == newlen)
392 if (move_data && msg->lm_bufcount > segment + 1) {
393 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
394 for (n = segment + 1; n < msg->lm_bufcount; n++)
395 tail_len += size_round(msg->lm_buflens[n]);
398 msg->lm_buflens[segment] = newlen;
400 if (tail && tail_len) {
401 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
402 LASSERT(newpos <= tail);
404 memcpy(newpos, tail, tail_len);
407 return lustre_msg_size_v2(msg->lm_bufcount, (int *)msg->lm_buflens);
411 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
412 * we also move data forward from @segment + 1.
414 * if @newlen == 0, we remove the segment completely, but we still keep the
415 * totally bufcount the same to save possible data moving. this will leave a
416 * unused segment with size 0 at the tail, but that's ok.
418 * return new msg size after shrinking.
421 * + if any buffers higher than @segment has been filled in, must call shrink
422 * with non-zero @move_data.
423 * + caller should NOT keep pointers to msg buffers which higher than @segment
426 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
427 unsigned int newlen, int move_data)
429 switch (msg->lm_magic) {
430 case LUSTRE_MSG_MAGIC_V2:
431 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
433 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
437 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
439 PTLRPC_RS_DEBUG_LRU_DEL(rs);
441 LASSERT (atomic_read(&rs->rs_refcount) == 0);
442 LASSERT (!rs->rs_difficult || rs->rs_handled);
443 LASSERT (!rs->rs_on_net);
444 LASSERT (!rs->rs_scheduled);
445 LASSERT (rs->rs_export == NULL);
446 LASSERT (rs->rs_nlocks == 0);
447 LASSERT (list_empty(&rs->rs_exp_list));
448 LASSERT (list_empty(&rs->rs_obd_list));
450 sptlrpc_svc_free_rs(rs);
453 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
455 int flipped, required_len, i;
457 /* Now we know the sender speaks my language. */
458 required_len = lustre_msg_hdr_size_v2(0);
459 if (len < required_len) {
460 /* can't even look inside the message */
461 CERROR("message length %d too small for lustre_msg\n", len);
465 flipped = lustre_msg_swabbed(m);
468 __swab32s(&m->lm_bufcount);
469 __swab32s(&m->lm_secflvr);
470 __swab32s(&m->lm_repsize);
471 __swab32s(&m->lm_timeout);
472 CLASSERT(offsetof(typeof(*m), lm_padding_1) != 0);
473 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
474 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
477 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
478 if (len < required_len) {
479 /* didn't receive all the buffer lengths */
480 CERROR ("message length %d too small for %d buflens\n",
481 len, m->lm_bufcount);
485 for (i = 0; i < m->lm_bufcount; i++) {
487 __swab32s(&m->lm_buflens[i]);
488 required_len += size_round(m->lm_buflens[i]);
491 if (len < required_len) {
492 CERROR("len: %d, required_len %d\n", len, required_len);
493 CERROR("bufcount: %d\n", m->lm_bufcount);
494 for (i = 0; i < m->lm_bufcount; i++)
495 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
502 int lustre_unpack_msg(struct lustre_msg *m, int len)
504 int required_len, rc;
507 /* We can provide a slightly better error log, if we check the
508 * message magic and version first. In the future, struct
509 * lustre_msg may grow, and we'd like to log a version mismatch,
510 * rather than a short message.
513 required_len = offsetof(struct lustre_msg, lm_magic) +
515 if (len < required_len) {
516 /* can't even look inside the message */
517 CERROR("message length %d too small for magic/version check\n",
522 switch (m->lm_magic) {
523 case LUSTRE_MSG_MAGIC_V2:
524 case LUSTRE_MSG_MAGIC_V2_SWABBED:
525 rc = lustre_unpack_msg_v2(m, len);
528 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
535 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
538 struct ptlrpc_body *pb;
540 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
542 CERROR("error unpacking ptlrpc body\n");
545 if (lustre_msg_swabbed(m))
546 lustre_swab_ptlrpc_body(pb);
548 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
549 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
556 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
558 switch (req->rq_reqmsg->lm_magic) {
559 case LUSTRE_MSG_MAGIC_V2:
560 case LUSTRE_MSG_MAGIC_V2_SWABBED:
561 lustre_set_req_swabbed(req, offset);
562 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
564 CERROR("bad lustre msg magic: %#08X\n",
565 req->rq_reqmsg->lm_magic);
570 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
572 switch (req->rq_repmsg->lm_magic) {
573 case LUSTRE_MSG_MAGIC_V2:
574 case LUSTRE_MSG_MAGIC_V2_SWABBED:
575 lustre_set_rep_swabbed(req, offset);
576 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
578 CERROR("bad lustre msg magic: %#08X\n",
579 req->rq_repmsg->lm_magic);
584 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
586 if (n >= m->lm_bufcount)
589 return m->lm_buflens[n];
593 * lustre_msg_buflen - return the length of buffer @n in message @m
594 * @m - lustre_msg (request or reply) to look at
595 * @n - message index (base 0)
597 * returns zero for non-existent message indices
599 int lustre_msg_buflen(struct lustre_msg *m, int n)
601 switch (m->lm_magic) {
602 case LUSTRE_MSG_MAGIC_V2:
603 case LUSTRE_MSG_MAGIC_V2_SWABBED:
604 return lustre_msg_buflen_v2(m, n);
606 CERROR("incorrect message magic: %08x\n", m->lm_magic);
610 EXPORT_SYMBOL(lustre_msg_buflen);
613 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
615 if (n >= m->lm_bufcount)
618 m->lm_buflens[n] = len;
621 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
623 switch (m->lm_magic) {
624 case LUSTRE_MSG_MAGIC_V2:
625 lustre_msg_set_buflen_v2(m, n, len);
628 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
632 EXPORT_SYMBOL(lustre_msg_set_buflen);
634 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
635 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
636 int lustre_msg_bufcount(struct lustre_msg *m)
638 switch (m->lm_magic) {
639 case LUSTRE_MSG_MAGIC_V2:
640 case LUSTRE_MSG_MAGIC_V2_SWABBED:
641 return m->lm_bufcount;
643 CERROR("incorrect message magic: %08x\n", m->lm_magic);
647 EXPORT_SYMBOL(lustre_msg_bufcount);
649 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
651 /* max_len == 0 means the string should fill the buffer */
655 switch (m->lm_magic) {
656 case LUSTRE_MSG_MAGIC_V2:
657 case LUSTRE_MSG_MAGIC_V2_SWABBED:
658 str = lustre_msg_buf_v2(m, index, 0);
659 blen = lustre_msg_buflen_v2(m, index);
662 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
666 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
670 slen = strnlen(str, blen);
672 if (slen == blen) { /* not NULL terminated */
673 CERROR("can't unpack non-NULL terminated string in "
674 "msg %p buffer[%d] len %d\n", m, index, blen);
679 if (slen != blen - 1) {
680 CERROR("can't unpack short string in msg %p "
681 "buffer[%d] len %d: strlen %d\n",
682 m, index, blen, slen);
685 } else if (slen > max_len) {
686 CERROR("can't unpack oversized string in msg %p "
687 "buffer[%d] len %d strlen %d: max %d expected\n",
688 m, index, blen, slen, max_len);
695 /* Wrap up the normal fixed length cases */
696 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
701 switch (msg->lm_magic) {
702 case LUSTRE_MSG_MAGIC_V2:
703 case LUSTRE_MSG_MAGIC_V2_SWABBED:
704 ptr = lustre_msg_buf_v2(msg, index, min_size);
707 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
712 if (swabber != NULL && lustre_msg_swabbed(msg))
713 ((void (*)(void *))swabber)(ptr);
718 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
721 lustre_set_req_swabbed(req, index);
722 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
725 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
728 lustre_set_rep_swabbed(req, index);
729 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
732 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
734 switch (msg->lm_magic) {
735 case LUSTRE_MSG_MAGIC_V2:
736 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
737 struct ptlrpc_body *pb;
739 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
741 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
747 /* flags might be printed in debug code while message
753 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
755 switch (msg->lm_magic) {
756 case LUSTRE_MSG_MAGIC_V2: {
757 struct ptlrpc_body *pb;
759 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
760 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
761 pb->pb_flags |= flags;
765 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
769 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
771 switch (msg->lm_magic) {
772 case LUSTRE_MSG_MAGIC_V2: {
773 struct ptlrpc_body *pb;
775 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
776 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
777 pb->pb_flags = flags;
781 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
785 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
787 switch (msg->lm_magic) {
788 case LUSTRE_MSG_MAGIC_V2:
789 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
790 struct ptlrpc_body *pb;
792 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
793 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
794 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
798 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
802 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
804 switch (msg->lm_magic) {
805 case LUSTRE_MSG_MAGIC_V2:
806 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
807 struct ptlrpc_body *pb;
809 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
811 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
814 return pb->pb_op_flags;
821 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
823 switch (msg->lm_magic) {
824 case LUSTRE_MSG_MAGIC_V2: {
825 struct ptlrpc_body *pb;
827 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
828 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
829 pb->pb_op_flags |= flags;
833 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
837 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
839 switch (msg->lm_magic) {
840 case LUSTRE_MSG_MAGIC_V2: {
841 struct ptlrpc_body *pb;
843 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
844 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
845 pb->pb_op_flags |= flags;
849 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
853 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
855 switch (msg->lm_magic) {
856 case LUSTRE_MSG_MAGIC_V2:
857 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
858 struct ptlrpc_body *pb;
860 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
862 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
865 return &pb->pb_handle;
868 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
873 __u32 lustre_msg_get_type(struct lustre_msg *msg)
875 switch (msg->lm_magic) {
876 case LUSTRE_MSG_MAGIC_V2:
877 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
878 struct ptlrpc_body *pb;
880 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
882 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
883 return PTL_RPC_MSG_ERR;
888 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
889 return PTL_RPC_MSG_ERR;
893 __u32 lustre_msg_get_version(struct lustre_msg *msg)
895 switch (msg->lm_magic) {
896 case LUSTRE_MSG_MAGIC_V2:
897 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
898 struct ptlrpc_body *pb;
900 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
902 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
905 return pb->pb_version;
908 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
913 void lustre_msg_add_version(struct lustre_msg *msg, int version)
915 switch (msg->lm_magic) {
916 case LUSTRE_MSG_MAGIC_V2:
917 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
918 struct ptlrpc_body *pb;
920 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
921 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
922 pb->pb_version |= version;
926 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
930 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
932 switch (msg->lm_magic) {
933 case LUSTRE_MSG_MAGIC_V2:
934 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
935 struct ptlrpc_body *pb;
937 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
939 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
945 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
950 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
952 switch (msg->lm_magic) {
953 case LUSTRE_MSG_MAGIC_V2:
954 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
955 struct ptlrpc_body *pb;
957 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
959 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
962 return pb->pb_last_xid;
965 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
970 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
972 switch (msg->lm_magic) {
973 case LUSTRE_MSG_MAGIC_V2:
974 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
975 struct ptlrpc_body *pb;
977 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
979 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
982 return pb->pb_last_committed;
985 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
990 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
992 switch (msg->lm_magic) {
993 case LUSTRE_MSG_MAGIC_V2:
994 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
995 struct ptlrpc_body *pb;
997 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
999 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1002 return pb->pb_transno;
1005 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1010 int lustre_msg_get_status(struct lustre_msg *msg)
1012 switch (msg->lm_magic) {
1013 case LUSTRE_MSG_MAGIC_V2:
1014 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1015 struct ptlrpc_body *pb;
1017 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1019 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1022 return pb->pb_status;
1025 /* status might be printed in debug code while message
1031 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1033 switch (msg->lm_magic) {
1034 case LUSTRE_MSG_MAGIC_V2:
1035 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1036 struct ptlrpc_body *pb;
1038 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1040 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1046 CERROR("invalid msg magic %x\n", msg->lm_magic);
1052 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1054 switch (msg->lm_magic) {
1055 case LUSTRE_MSG_MAGIC_V2:
1056 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1057 struct ptlrpc_body *pb;
1059 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1061 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1068 CERROR("invalid msg magic %x\n", msg->lm_magic);
1073 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1075 switch (msg->lm_magic) {
1076 case LUSTRE_MSG_MAGIC_V2:
1077 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1078 struct ptlrpc_body *pb;
1080 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1082 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1085 return pb->pb_limit;
1088 CERROR("invalid msg magic %x\n", msg->lm_magic);
1094 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1096 switch (msg->lm_magic) {
1097 case LUSTRE_MSG_MAGIC_V2:
1098 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1099 struct ptlrpc_body *pb;
1101 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1103 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1106 pb->pb_limit = limit;
1110 CERROR("invalid msg magic %x\n", msg->lm_magic);
1115 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1117 switch (msg->lm_magic) {
1118 case LUSTRE_MSG_MAGIC_V2:
1119 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1120 struct ptlrpc_body *pb;
1122 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1124 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1127 return pb->pb_conn_cnt;
1130 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1135 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1137 switch (msg->lm_magic) {
1138 case LUSTRE_MSG_MAGIC_V2:
1139 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1140 return msg->lm_magic;
1142 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1147 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1149 switch (msg->lm_magic) {
1150 case LUSTRE_MSG_MAGIC_V2: {
1151 struct ptlrpc_body *pb;
1153 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1154 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1155 pb->pb_handle = *handle;
1159 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1163 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1165 switch (msg->lm_magic) {
1166 case LUSTRE_MSG_MAGIC_V2: {
1167 struct ptlrpc_body *pb;
1169 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1170 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1175 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1179 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1181 switch (msg->lm_magic) {
1182 case LUSTRE_MSG_MAGIC_V2: {
1183 struct ptlrpc_body *pb;
1185 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1186 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1191 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1195 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1197 switch (msg->lm_magic) {
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_last_xid = last_xid;
1207 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1211 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1213 switch (msg->lm_magic) {
1214 case LUSTRE_MSG_MAGIC_V2: {
1215 struct ptlrpc_body *pb;
1217 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1218 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1219 pb->pb_last_committed = last_committed;
1223 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1227 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1229 switch (msg->lm_magic) {
1230 case LUSTRE_MSG_MAGIC_V2: {
1231 struct ptlrpc_body *pb;
1233 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1234 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1235 pb->pb_transno = transno;
1239 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1243 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1245 switch (msg->lm_magic) {
1246 case LUSTRE_MSG_MAGIC_V2: {
1247 struct ptlrpc_body *pb;
1249 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1250 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1251 pb->pb_status = status;
1255 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1259 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1261 switch (msg->lm_magic) {
1262 case LUSTRE_MSG_MAGIC_V2: {
1263 struct ptlrpc_body *pb;
1265 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1266 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1267 pb->pb_conn_cnt = conn_cnt;
1271 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1275 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
1277 int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
1279 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count,
1280 req->rq_pill.rc_area[RCL_SERVER]);
1281 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1282 req->rq_reqmsg->lm_repsize = req->rq_replen;
1285 void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, int *lens)
1287 req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
1288 if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
1289 req->rq_reqmsg->lm_repsize = req->rq_replen;
1292 /* byte flipping routines for all wire types declared in
1293 * lustre_idl.h implemented here.
1295 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1297 __swab32s (&b->pb_type);
1298 __swab32s (&b->pb_version);
1299 __swab32s (&b->pb_opc);
1300 __swab32s (&b->pb_status);
1301 __swab64s (&b->pb_last_xid);
1302 __swab64s (&b->pb_last_seen);
1303 __swab64s (&b->pb_last_committed);
1304 __swab64s (&b->pb_transno);
1305 __swab32s (&b->pb_flags);
1306 __swab32s (&b->pb_op_flags);
1307 __swab32s (&b->pb_conn_cnt);
1308 CLASSERT(offsetof(typeof(*b), pb_padding_1) != 0);
1309 CLASSERT(offsetof(typeof(*b), pb_padding_2) != 0);
1310 __swab32s (&b->pb_limit);
1311 __swab64s (&b->pb_slv);
1314 void lustre_swab_connect(struct obd_connect_data *ocd)
1316 __swab64s(&ocd->ocd_connect_flags);
1317 __swab32s(&ocd->ocd_version);
1318 __swab32s(&ocd->ocd_grant);
1319 __swab64s(&ocd->ocd_ibits_known);
1320 __swab32s(&ocd->ocd_index);
1321 __swab32s(&ocd->ocd_brw_size);
1322 __swab32s(&ocd->ocd_nllu);
1323 __swab32s(&ocd->ocd_nllg);
1324 __swab64s(&ocd->ocd_transno);
1325 __swab32s(&ocd->ocd_group);
1326 __swab32s(&ocd->ocd_cksum_types);
1327 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1328 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1331 void lustre_swab_obdo (struct obdo *o)
1333 __swab64s (&o->o_valid);
1334 __swab64s (&o->o_id);
1335 __swab64s (&o->o_gr);
1336 __swab64s (&o->o_fid);
1337 __swab64s (&o->o_size);
1338 __swab64s (&o->o_mtime);
1339 __swab64s (&o->o_atime);
1340 __swab64s (&o->o_ctime);
1341 __swab64s (&o->o_blocks);
1342 __swab64s (&o->o_grant);
1343 __swab32s (&o->o_blksize);
1344 __swab32s (&o->o_mode);
1345 __swab32s (&o->o_uid);
1346 __swab32s (&o->o_gid);
1347 __swab32s (&o->o_flags);
1348 __swab32s (&o->o_nlink);
1349 __swab32s (&o->o_generation);
1350 __swab32s (&o->o_misc);
1351 __swab32s (&o->o_easize);
1352 __swab32s (&o->o_mds);
1353 __swab32s (&o->o_stripe_idx);
1354 __swab32s (&o->o_padding_1);
1355 /* o_inline is opaque */
1358 void lustre_swab_obd_statfs (struct obd_statfs *os)
1360 __swab64s (&os->os_type);
1361 __swab64s (&os->os_blocks);
1362 __swab64s (&os->os_bfree);
1363 __swab64s (&os->os_bavail);
1364 __swab64s (&os->os_files);
1365 __swab64s (&os->os_ffree);
1366 /* no need to swab os_fsid */
1367 __swab32s (&os->os_bsize);
1368 __swab32s (&os->os_namelen);
1369 __swab64s (&os->os_maxbytes);
1370 __swab32s (&os->os_state);
1371 /* no need to swap os_spare */
1374 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1376 __swab64s (&ioo->ioo_id);
1377 __swab64s (&ioo->ioo_gr);
1378 __swab32s (&ioo->ioo_type);
1379 __swab32s (&ioo->ioo_bufcnt);
1382 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1384 __swab64s (&nbr->offset);
1385 __swab32s (&nbr->len);
1386 __swab32s (&nbr->flags);
1389 void lustre_swab_ost_body (struct ost_body *b)
1391 lustre_swab_obdo (&b->oa);
1394 void lustre_swab_ost_last_id(obd_id *id)
1399 void lustre_swab_generic_32s(__u32 *val)
1404 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1406 __swab64s(&lvb->lvb_size);
1407 __swab64s(&lvb->lvb_mtime);
1408 __swab64s(&lvb->lvb_atime);
1409 __swab64s(&lvb->lvb_ctime);
1410 __swab64s(&lvb->lvb_blocks);
1413 void lustre_swab_mds_status_req (struct mds_status_req *r)
1415 __swab32s (&r->flags);
1416 __swab32s (&r->repbuf);
1419 void lustre_swab_mds_body (struct mds_body *b)
1421 lustre_swab_ll_fid (&b->fid1);
1422 lustre_swab_ll_fid (&b->fid2);
1423 /* handle is opaque */
1424 __swab64s (&b->valid);
1425 __swab64s (&b->size);
1426 __swab64s (&b->mtime);
1427 __swab64s (&b->atime);
1428 __swab64s (&b->ctime);
1429 __swab64s (&b->blocks);
1430 __swab64s (&b->io_epoch);
1431 __swab64s (&b->ino);
1432 __swab32s (&b->fsuid);
1433 __swab32s (&b->fsgid);
1434 __swab32s (&b->capability);
1435 __swab32s (&b->mode);
1436 __swab32s (&b->uid);
1437 __swab32s (&b->gid);
1438 __swab32s (&b->flags);
1439 __swab32s (&b->rdev);
1440 __swab32s (&b->nlink);
1441 __swab32s (&b->generation);
1442 __swab32s (&b->suppgid);
1443 __swab32s (&b->eadatasize);
1444 __swab32s (&b->aclsize);
1445 __swab32s (&b->max_mdsize);
1446 __swab32s (&b->max_cookiesize);
1447 __swab32s (&b->padding_4);
1450 void lustre_swab_mdt_body (struct mdt_body *b)
1452 lustre_swab_lu_fid (&b->fid1);
1453 lustre_swab_lu_fid (&b->fid2);
1454 /* handle is opaque */
1455 __swab64s (&b->valid);
1456 __swab64s (&b->size);
1457 __swab64s (&b->mtime);
1458 __swab64s (&b->atime);
1459 __swab64s (&b->ctime);
1460 __swab64s (&b->blocks);
1461 __swab64s (&b->ioepoch);
1462 __swab64s (&b->ino);
1463 __swab32s (&b->fsuid);
1464 __swab32s (&b->fsgid);
1465 __swab32s (&b->capability);
1466 __swab32s (&b->mode);
1467 __swab32s (&b->uid);
1468 __swab32s (&b->gid);
1469 __swab32s (&b->flags);
1470 __swab32s (&b->rdev);
1471 __swab32s (&b->nlink);
1472 __swab32s (&b->generation);
1473 __swab32s (&b->suppgid);
1474 __swab32s (&b->eadatasize);
1475 __swab32s (&b->aclsize);
1476 __swab32s (&b->max_mdsize);
1477 __swab32s (&b->max_cookiesize);
1478 __swab32s (&b->padding_4);
1481 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1483 /* handle is opaque */
1484 __swab64s (&b->ioepoch);
1485 __swab32s (&b->flags);
1486 CLASSERT(offsetof(typeof(*b), padding) != 0);
1489 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1492 __swab32s(&mti->mti_lustre_ver);
1493 __swab32s(&mti->mti_stripe_index);
1494 __swab32s(&mti->mti_config_ver);
1495 __swab32s(&mti->mti_flags);
1496 __swab32s(&mti->mti_nid_count);
1497 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1498 for (i = 0; i < MTI_NIDS_MAX; i++)
1499 __swab64s(&mti->mti_nids[i]);
1502 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1504 __swab64s (&i->dqi_bgrace);
1505 __swab64s (&i->dqi_igrace);
1506 __swab32s (&i->dqi_flags);
1507 __swab32s (&i->dqi_valid);
1510 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1512 __swab64s (&b->dqb_ihardlimit);
1513 __swab64s (&b->dqb_isoftlimit);
1514 __swab64s (&b->dqb_curinodes);
1515 __swab64s (&b->dqb_bhardlimit);
1516 __swab64s (&b->dqb_bsoftlimit);
1517 __swab64s (&b->dqb_curspace);
1518 __swab64s (&b->dqb_btime);
1519 __swab64s (&b->dqb_itime);
1520 __swab32s (&b->dqb_valid);
1521 CLASSERT(offsetof(typeof(*b), padding) != 0);
1524 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1526 __swab32s (&q->qc_cmd);
1527 __swab32s (&q->qc_type);
1528 __swab32s (&q->qc_id);
1529 __swab32s (&q->qc_stat);
1530 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1531 lustre_swab_obd_dqblk (&q->qc_dqblk);
1534 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1536 __swab32s (&p->rp_uid);
1537 __swab32s (&p->rp_gid);
1538 __swab32s (&p->rp_fsuid);
1539 __swab32s (&p->rp_fsgid);
1540 __swab32s (&p->rp_access_perm);
1543 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1545 __swab32s (&p->rp_uid);
1546 __swab32s (&p->rp_gid);
1547 __swab32s (&p->rp_fsuid);
1548 __swab32s (&p->rp_fsgid);
1549 __swab32s (&p->rp_access_perm);
1552 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1554 __swab32s (&sa->sa_opcode);
1555 __swab32s (&sa->sa_fsuid);
1556 __swab32s (&sa->sa_fsgid);
1557 __swab32s (&sa->sa_cap);
1558 __swab32s (&sa->sa_suppgid);
1559 __swab32s (&sa->sa_mode);
1560 lustre_swab_ll_fid (&sa->sa_fid);
1561 __swab64s (&sa->sa_valid);
1562 __swab64s (&sa->sa_size);
1563 __swab64s (&sa->sa_mtime);
1564 __swab64s (&sa->sa_atime);
1565 __swab64s (&sa->sa_ctime);
1566 __swab32s (&sa->sa_uid);
1567 __swab32s (&sa->sa_gid);
1568 __swab32s (&sa->sa_attr_flags);
1569 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1572 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1574 __swab64s(&jr->jr_headsize);
1575 lustre_swab_ll_fid(&jr->jr_fid);
1578 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1580 __swab64s(&jr->jr_headsize);
1581 lustre_swab_lu_fid(&jr->jr_fid);
1584 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1586 __swab32s (&cr->cr_opcode);
1587 __swab32s (&cr->cr_fsuid);
1588 __swab32s (&cr->cr_fsgid);
1589 __swab32s (&cr->cr_cap);
1590 __swab32s (&cr->cr_flags); /* for use with open */
1591 __swab32s (&cr->cr_mode);
1592 lustre_swab_ll_fid (&cr->cr_fid);
1593 lustre_swab_ll_fid (&cr->cr_replayfid);
1594 __swab64s (&cr->cr_time);
1595 __swab64s (&cr->cr_rdev);
1596 __swab32s (&cr->cr_suppgid);
1597 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1598 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1599 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1600 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1601 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
1604 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
1606 __swab32s (&lk->lk_opcode);
1607 __swab32s (&lk->lk_fsuid);
1608 __swab32s (&lk->lk_fsgid);
1609 __swab32s (&lk->lk_cap);
1610 __swab32s (&lk->lk_suppgid1);
1611 __swab32s (&lk->lk_suppgid2);
1612 lustre_swab_ll_fid (&lk->lk_fid1);
1613 lustre_swab_ll_fid (&lk->lk_fid2);
1614 __swab64s (&lk->lk_time);
1615 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
1616 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
1617 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
1618 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
1621 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
1623 __swab32s (&ul->ul_opcode);
1624 __swab32s (&ul->ul_fsuid);
1625 __swab32s (&ul->ul_fsgid);
1626 __swab32s (&ul->ul_cap);
1627 __swab32s (&ul->ul_suppgid);
1628 __swab32s (&ul->ul_mode);
1629 lustre_swab_ll_fid (&ul->ul_fid1);
1630 lustre_swab_ll_fid (&ul->ul_fid2);
1631 __swab64s (&ul->ul_time);
1632 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
1633 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
1634 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
1635 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
1638 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
1640 __swab32s (&rn->rn_opcode);
1641 __swab32s (&rn->rn_fsuid);
1642 __swab32s (&rn->rn_fsgid);
1643 __swab32s (&rn->rn_cap);
1644 __swab32s (&rn->rn_suppgid1);
1645 __swab32s (&rn->rn_suppgid2);
1646 lustre_swab_ll_fid (&rn->rn_fid1);
1647 lustre_swab_ll_fid (&rn->rn_fid2);
1648 __swab64s (&rn->rn_time);
1649 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
1650 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
1651 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
1652 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
1655 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
1657 __swab32s (&rr->rr_opcode);
1658 __swab32s (&rr->rr_fsuid);
1659 __swab32s (&rr->rr_fsgid);
1660 __swab32s (&rr->rr_cap);
1661 __swab32s (&rr->rr_suppgid1);
1662 __swab32s (&rr->rr_suppgid2);
1663 /* handle is opaque */
1664 lustre_swab_lu_fid (&rr->rr_fid1);
1665 lustre_swab_lu_fid (&rr->rr_fid2);
1666 __swab64s (&rr->rr_mtime);
1667 __swab64s (&rr->rr_atime);
1668 __swab64s (&rr->rr_ctime);
1669 __swab64s (&rr->rr_size);
1670 __swab64s (&rr->rr_blocks);
1671 __swab32s (&rr->rr_bias);
1672 __swab32s (&rr->rr_mode);
1673 __swab32s (&rr->rr_padding_1);
1674 __swab32s (&rr->rr_padding_2);
1675 __swab32s (&rr->rr_padding_3);
1676 __swab32s (&rr->rr_padding_4);
1678 CLASSERT(offsetof(typeof(*rr), rr_padding_1) != 0);
1679 CLASSERT(offsetof(typeof(*rr), rr_padding_2) != 0);
1680 CLASSERT(offsetof(typeof(*rr), rr_padding_3) != 0);
1681 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0);
1684 void lustre_swab_lov_desc (struct lov_desc *ld)
1686 __swab32s (&ld->ld_tgt_count);
1687 __swab32s (&ld->ld_active_tgt_count);
1688 __swab32s (&ld->ld_default_stripe_count);
1689 __swab64s (&ld->ld_default_stripe_size);
1690 __swab64s (&ld->ld_default_stripe_offset);
1691 __swab32s (&ld->ld_pattern);
1692 __swab32s (&ld->ld_qos_maxage);
1693 /* uuid endian insensitive */
1696 /*begin adding MDT by huanghua@clusterfs.com*/
1697 void lustre_swab_lmv_desc (struct lmv_desc *ld)
1699 __swab32s (&ld->ld_tgt_count);
1700 __swab32s (&ld->ld_active_tgt_count);
1701 /* uuid endian insensitive */
1703 /*end adding MDT by huanghua@clusterfs.com*/
1704 void lustre_swab_md_fld (struct md_fld *mf)
1706 __swab64s(&mf->mf_seq);
1707 __swab64s(&mf->mf_mds);
1710 static void print_lum (struct lov_user_md *lum)
1712 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
1713 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
1714 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
1715 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
1716 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
1717 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
1718 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
1719 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
1722 void lustre_swab_lov_user_md(struct lov_user_md *lum)
1725 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
1726 __swab32s(&lum->lmm_magic);
1727 __swab32s(&lum->lmm_pattern);
1728 __swab64s(&lum->lmm_object_id);
1729 __swab64s(&lum->lmm_object_gr);
1730 __swab32s(&lum->lmm_stripe_size);
1731 __swab16s(&lum->lmm_stripe_count);
1732 __swab16s(&lum->lmm_stripe_offset);
1737 static void print_lumj (struct lov_user_md_join *lumj)
1739 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
1740 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
1741 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
1742 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
1743 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
1744 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
1745 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
1746 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
1749 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
1752 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
1753 __swab32s(&lumj->lmm_magic);
1754 __swab32s(&lumj->lmm_pattern);
1755 __swab64s(&lumj->lmm_object_id);
1756 __swab64s(&lumj->lmm_object_gr);
1757 __swab32s(&lumj->lmm_stripe_size);
1758 __swab32s(&lumj->lmm_stripe_count);
1759 __swab32s(&lumj->lmm_extent_count);
1764 static void print_lum_objs(struct lov_user_md *lum)
1766 struct lov_user_ost_data *lod;
1769 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
1771 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
1772 for (i = 0; i < lum->lmm_stripe_count; i++) {
1773 lod = &lum->lmm_objects[i];
1774 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
1775 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
1776 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
1777 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
1782 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
1784 struct lov_user_ost_data *lod;
1787 for (i = 0; i < lum->lmm_stripe_count; i++) {
1788 lod = &lum->lmm_objects[i];
1789 __swab64s(&lod->l_object_id);
1790 __swab64s(&lod->l_object_gr);
1791 __swab32s(&lod->l_ost_gen);
1792 __swab32s(&lod->l_ost_idx);
1794 print_lum_objs(lum);
1799 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
1801 struct lov_ost_data *lod;
1804 for (i = 0; i < lmm->lmm_stripe_count; i++) {
1805 lod = &lmm->lmm_objects[i];
1806 __swab64s(&lod->l_object_id);
1807 __swab64s(&lod->l_object_gr);
1808 __swab32s(&lod->l_ost_gen);
1809 __swab32s(&lod->l_ost_idx);
1811 __swab32s(&lmm->lmm_magic);
1812 __swab32s(&lmm->lmm_pattern);
1813 __swab64s(&lmm->lmm_object_id);
1814 __swab64s(&lmm->lmm_object_gr);
1815 __swab32s(&lmm->lmm_stripe_size);
1816 __swab32s(&lmm->lmm_stripe_count);
1822 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
1826 for (i = 0; i < RES_NAME_SIZE; i++)
1827 __swab64s (&id->name[i]);
1830 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
1832 /* the lock data is a union and the first two fields are always an
1833 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
1834 * data the same way. */
1835 __swab64s(&d->l_extent.start);
1836 __swab64s(&d->l_extent.end);
1837 __swab64s(&d->l_extent.gid);
1838 __swab32s(&d->l_flock.pid);
1841 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
1843 __swab64s (&i->opc);
1846 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
1848 __swab32s (&r->lr_type);
1849 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
1850 lustre_swab_ldlm_res_id (&r->lr_name);
1853 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
1855 lustre_swab_ldlm_resource_desc (&l->l_resource);
1856 __swab32s (&l->l_req_mode);
1857 __swab32s (&l->l_granted_mode);
1858 lustre_swab_ldlm_policy_data (&l->l_policy_data);
1861 void lustre_swab_ldlm_request (struct ldlm_request *rq)
1863 __swab32s (&rq->lock_flags);
1864 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
1865 __swab32s (&rq->lock_count);
1866 /* lock_handle[] opaque */
1869 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
1871 __swab32s (&r->lock_flags);
1872 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
1873 lustre_swab_ldlm_lock_desc (&r->lock_desc);
1874 /* lock_handle opaque */
1875 __swab64s (&r->lock_policy_res1);
1876 __swab64s (&r->lock_policy_res2);
1879 /* no one calls this */
1880 int llog_log_swabbed(struct llog_log_hdr *hdr)
1882 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
1884 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
1889 void lustre_swab_qdata(struct qunit_data *d)
1891 __swab32s (&d->qd_id);
1892 __swab32s (&d->qd_flags);
1893 __swab64s (&d->qd_count);
1896 void lustre_swab_qdata_old(struct qunit_data_old *d)
1898 __swab32s (&d->qd_id);
1899 __swab32s (&d->qd_type);
1900 __swab32s (&d->qd_count);
1901 __swab32s (&d->qd_isblk);
1905 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
1907 struct qunit_data_old tmp;
1908 struct qunit_data *ret;
1915 ret = (struct qunit_data *)d;
1916 ret->qd_id = tmp.qd_id;
1917 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
1918 ret->qd_count = tmp.qd_count;
1922 EXPORT_SYMBOL(lustre_quota_old_to_new);
1924 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
1926 struct qunit_data tmp;
1927 struct qunit_data_old *ret;
1934 ret = (struct qunit_data_old *)d;
1935 ret->qd_id = tmp.qd_id;
1936 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
1937 ret->qd_count = (__u32)tmp.qd_count;
1938 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
1941 EXPORT_SYMBOL(lustre_quota_new_to_old);
1942 #endif /* __KERNEL__ */
1944 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
1946 LASSERT(req->rq_reqmsg);
1948 switch (req->rq_reqmsg->lm_magic) {
1949 case LUSTRE_MSG_MAGIC_V2:
1950 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1951 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
1953 CERROR("bad lustre msg magic: %#08X\n",
1954 req->rq_reqmsg->lm_magic);
1959 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
1961 LASSERT(req->rq_repmsg);
1963 switch (req->rq_repmsg->lm_magic) {
1964 case LUSTRE_MSG_MAGIC_V2:
1965 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1966 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
1968 /* uninitialized yet */
1973 void _debug_req(struct ptlrpc_request *req, __u32 mask,
1974 struct libcfs_debug_msg_data *data, const char *fmt, ... )
1978 va_start(args, fmt);
1979 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
1980 data->msg_fn, data->msg_line, fmt, args,
1981 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d lens"
1982 " %d/%d ref %d fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
1983 req, req->rq_xid, req->rq_transno,
1984 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
1985 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
1986 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
1988 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
1990 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
1992 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
1993 (req->rq_import && req->rq_import->imp_client) ?
1994 req->rq_import->imp_client->cli_request_portal : -1,
1995 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
1996 DEBUG_REQ_FLAGS(req),
1997 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
1998 lustre_msg_get_flags(req->rq_reqmsg) : -1,
1999 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2000 lustre_msg_get_flags(req->rq_repmsg) : -1,
2002 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2003 lustre_msg_get_status(req->rq_repmsg) : -1);
2005 EXPORT_SYMBOL(_debug_req);
2007 void lustre_swab_lustre_capa(struct lustre_capa *c)
2009 lustre_swab_lu_fid(&c->lc_fid);
2010 __swab64s (&c->lc_opc);
2011 __swab32s (&c->lc_uid);
2012 __swab32s (&c->lc_flags);
2013 __swab32s (&c->lc_keyid);
2014 __swab32s (&c->lc_timeout);
2015 __swab64s (&c->lc_expiry);
2018 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2020 __swab64s (&k->lk_mdsid);
2021 __swab32s (&k->lk_keyid);
2022 __swab32s (&k->lk_padding);