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 CERROR("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 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]);
110 EXPORT_SYMBOL(lustre_msg_size_v2);
112 /* This returns the size of the buffer that is required to hold a lustre_msg
113 * with the given sub-buffer lengths.
114 * NOTE: this should only be used for NEW requests, and should always be
115 * in the form of a v2 request. If this is a connection to a v1
116 * target then the first buffer will be stripped because the ptlrpc
117 * data is part of the lustre_msg_v1 header. b=14043 */
118 int lustre_msg_size(__u32 magic, int count, int *lens)
120 int size[] = { sizeof(struct ptlrpc_body) };
128 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
131 case LUSTRE_MSG_MAGIC_V1:
132 return lustre_msg_size_v1(count - 1, lens + 1);
133 case LUSTRE_MSG_MAGIC_V2:
134 return lustre_msg_size_v2(count, lens);
136 LASSERTF(0, "incorrect message magic: %08x\n", magic);
141 /* This is used to determine the size of a buffer that was already packed
142 * and will correctly handle the different message formats. */
143 int lustre_packed_msg_size(struct lustre_msg *msg)
145 switch (msg->lm_magic) {
146 case LUSTRE_MSG_MAGIC_V1: {
147 struct lustre_msg_v1 *v1_msg = (struct lustre_msg_v1 *)msg;
148 return lustre_msg_size_v1(v1_msg->lm_bufcount,
151 case LUSTRE_MSG_MAGIC_V2:
152 return lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
154 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
160 void lustre_init_msg_v1(void *m, int count, int *lens, char **bufs)
162 struct lustre_msg_v1 *msg = (struct lustre_msg_v1 *)m;
167 msg->lm_magic = LUSTRE_MSG_MAGIC_V1;
168 msg->lm_version = PTLRPC_MSG_VERSION;
169 msg->lm_bufcount = count;
171 for (i = 0; i < count; i++)
172 msg->lm_buflens[i] = lens[i];
177 ptr = (char *)msg + lustre_msg_hdr_size_v1(count);
178 for (i = 0; i < count; i++) {
180 LOGL(tmp, lens[i], ptr);
184 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, int *lens,
190 msg->lm_bufcount = count;
191 /* XXX: lm_secflvr uninitialized here */
192 msg->lm_magic = LUSTRE_MSG_MAGIC_V2;
194 for (i = 0; i < count; i++)
195 msg->lm_buflens[i] = lens[i];
200 ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
201 for (i = 0; i < count; i++) {
203 LOGL(tmp, lens[i], ptr);
206 EXPORT_SYMBOL(lustre_init_msg_v2);
208 static int lustre_pack_request_v1(struct ptlrpc_request *req,
209 int count, int *lens, char **bufs)
213 reqlen = lustre_msg_size_v1(count, lens);
215 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
219 req->rq_reqlen = reqlen;
221 lustre_init_msg_v1(req->rq_reqmsg, count, lens, bufs);
225 static int lustre_pack_request_v2(struct ptlrpc_request *req,
226 int count, int *lens, char **bufs)
230 reqlen = lustre_msg_size_v2(count, lens);
232 rc = sptlrpc_cli_alloc_reqbuf(req, reqlen);
236 req->rq_reqlen = reqlen;
238 lustre_init_msg_v2(req->rq_reqmsg, count, lens, bufs);
239 lustre_msg_add_version(req->rq_reqmsg, PTLRPC_MSG_VERSION);
240 lustre_set_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
244 int lustre_pack_request(struct ptlrpc_request *req, __u32 magic, int count,
245 int *lens, char **bufs)
247 int size[] = { sizeof(struct ptlrpc_body) };
255 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
257 /* if we choose policy other than null, we have also choosed
258 * to use new message format.
260 if (magic == LUSTRE_MSG_MAGIC_V1 &&
261 req->rq_sec_flavor != SPTLRPC_FLVR_NULL)
262 magic = LUSTRE_MSG_MAGIC_V2;
265 case LUSTRE_MSG_MAGIC_V1:
266 return lustre_pack_request_v1(req, count - 1, lens + 1,
267 bufs ? bufs + 1 : NULL);
268 case LUSTRE_MSG_MAGIC_V2:
269 return lustre_pack_request_v2(req, count, lens, bufs);
271 LASSERTF(0, "incorrect message magic: %08x\n", magic);
277 CFS_LIST_HEAD(ptlrpc_rs_debug_lru);
278 spinlock_t ptlrpc_rs_debug_lock;
280 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
282 spin_lock(&ptlrpc_rs_debug_lock); \
283 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
284 spin_unlock(&ptlrpc_rs_debug_lock); \
287 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
289 spin_lock(&ptlrpc_rs_debug_lock); \
290 list_del(&(rs)->rs_debug_list); \
291 spin_unlock(&ptlrpc_rs_debug_lock); \
294 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
295 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
298 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 memset(rs, 0, svc->srv_max_reply_size);
324 rs->rs_service = svc;
330 void lustre_put_emerg_rs(struct ptlrpc_reply_state *rs)
332 struct ptlrpc_service *svc = rs->rs_service;
336 spin_lock(&svc->srv_lock);
337 list_add(&rs->rs_list, &svc->srv_free_rs_list);
338 spin_unlock(&svc->srv_lock);
339 cfs_waitq_signal(&svc->srv_free_rs_waitq);
342 static int lustre_pack_reply_v1(struct ptlrpc_request *req, int count,
343 int *lens, char **bufs)
345 struct ptlrpc_reply_state *rs;
349 LASSERT (req->rq_reply_state == NULL);
351 msg_len = lustre_msg_size_v1(count, lens);
352 rc = sptlrpc_svc_alloc_rs(req, msg_len);
356 rs = req->rq_reply_state;
357 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
358 rs->rs_cb_id.cbid_fn = reply_out_callback;
359 rs->rs_cb_id.cbid_arg = rs;
360 rs->rs_service = req->rq_rqbd->rqbd_service;
361 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
362 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
364 req->rq_replen = msg_len;
365 req->rq_reply_state = rs;
366 req->rq_repmsg = rs->rs_msg;
367 lustre_init_msg_v1(rs->rs_msg, count, lens, bufs);
369 PTLRPC_RS_DEBUG_LRU_ADD(rs);
374 int lustre_pack_reply_v2(struct ptlrpc_request *req, int count,
375 int *lens, char **bufs)
377 struct ptlrpc_reply_state *rs;
381 LASSERT(req->rq_reply_state == NULL);
383 msg_len = lustre_msg_size_v2(count, lens);
384 rc = sptlrpc_svc_alloc_rs(req, msg_len);
388 rs = req->rq_reply_state;
389 atomic_set(&rs->rs_refcount, 1); /* 1 ref for rq_reply_state */
390 rs->rs_cb_id.cbid_fn = reply_out_callback;
391 rs->rs_cb_id.cbid_arg = rs;
392 rs->rs_service = req->rq_rqbd->rqbd_service;
393 CFS_INIT_LIST_HEAD(&rs->rs_exp_list);
394 CFS_INIT_LIST_HEAD(&rs->rs_obd_list);
396 req->rq_replen = msg_len;
397 req->rq_reply_state = rs;
398 req->rq_repmsg = rs->rs_msg;
399 lustre_init_msg_v2(rs->rs_msg, count, lens, bufs);
400 lustre_msg_add_version(rs->rs_msg, PTLRPC_MSG_VERSION);
401 lustre_set_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
403 PTLRPC_RS_DEBUG_LRU_ADD(rs);
407 EXPORT_SYMBOL(lustre_pack_reply_v2);
409 int lustre_pack_reply(struct ptlrpc_request *req, int count, int *lens,
413 int size[] = { sizeof(struct ptlrpc_body) };
421 LASSERT(lens[MSG_PTLRPC_BODY_OFF] == sizeof(struct ptlrpc_body));
423 switch (req->rq_reqmsg->lm_magic) {
424 case LUSTRE_MSG_MAGIC_V1:
425 case LUSTRE_MSG_MAGIC_V1_SWABBED:
426 rc = lustre_pack_reply_v1(req, count - 1, lens + 1,
427 bufs ? bufs + 1 : NULL);
429 case LUSTRE_MSG_MAGIC_V2:
430 case LUSTRE_MSG_MAGIC_V2_SWABBED:
431 rc = lustre_pack_reply_v2(req, count, lens, bufs);
434 LASSERTF(0, "incorrect message magic: %08x\n",
435 req->rq_reqmsg->lm_magic);
439 CERROR("lustre_pack_reply failed: rc=%d size=%d\n", rc,
440 lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens));
444 void *lustre_msg_buf_v1(void *msg, int n, int min_size)
446 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
447 int i, offset, buflen, bufcount;
452 bufcount = m->lm_bufcount;
453 if (unlikely(n >= bufcount)) {
454 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
459 buflen = m->lm_buflens[n];
460 if (unlikely(buflen < min_size)) {
461 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
462 m, n, buflen, min_size);
467 offset = lustre_msg_hdr_size_v1(bufcount);
468 for (i = 0; i < n; i++)
469 offset += size_round(m->lm_buflens[i]);
471 return (char *)m + offset;
474 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
476 int i, offset, buflen, bufcount;
481 bufcount = m->lm_bufcount;
482 if (unlikely(n >= bufcount)) {
483 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
488 buflen = m->lm_buflens[n];
489 if (unlikely(buflen < min_size)) {
490 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
491 m, n, buflen, min_size);
495 offset = lustre_msg_hdr_size_v2(bufcount);
496 for (i = 0; i < n; i++)
497 offset += size_round(m->lm_buflens[i]);
499 return (char *)m + offset;
502 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
504 switch (m->lm_magic) {
505 case LUSTRE_MSG_MAGIC_V1:
506 case LUSTRE_MSG_MAGIC_V1_SWABBED:
507 return lustre_msg_buf_v1(m, n - 1, min_size);
508 case LUSTRE_MSG_MAGIC_V2:
509 case LUSTRE_MSG_MAGIC_V2_SWABBED:
510 return lustre_msg_buf_v2(m, n, min_size);
512 LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
517 int lustre_shrink_msg_v1(struct lustre_msg_v1 *msg, int segment,
518 unsigned int newlen, int move_data)
520 char *tail = NULL, *newpos;
524 LASSERT(segment >= 0);
525 LASSERT(msg->lm_bufcount > segment);
526 LASSERT(msg->lm_buflens[segment] >= newlen);
528 if (msg->lm_buflens[segment] == newlen)
531 if (move_data && msg->lm_bufcount > segment + 1) {
532 tail = lustre_msg_buf_v1(msg, segment + 1, 0);
533 for (n = segment + 1; n < msg->lm_bufcount; n++)
534 tail_len += size_round(msg->lm_buflens[n]);
537 msg->lm_buflens[segment] = newlen;
539 if (tail && tail_len) {
540 newpos = lustre_msg_buf_v1(msg, segment + 1, 0);
541 LASSERT(newpos <= tail);
543 memcpy(newpos, tail, tail_len);
546 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
547 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
548 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
549 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
553 return lustre_msg_size_v1(msg->lm_bufcount, (int *)msg->lm_buflens);
556 int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
557 unsigned int newlen, int move_data)
559 char *tail = NULL, *newpos;
563 LASSERT(msg->lm_bufcount > segment);
564 LASSERT(msg->lm_buflens[segment] >= newlen);
566 if (msg->lm_buflens[segment] == newlen)
569 if (move_data && msg->lm_bufcount > segment + 1) {
570 tail = lustre_msg_buf_v2(msg, segment + 1, 0);
571 for (n = segment + 1; n < msg->lm_bufcount; n++)
572 tail_len += size_round(msg->lm_buflens[n]);
575 msg->lm_buflens[segment] = newlen;
577 if (tail && tail_len) {
578 newpos = lustre_msg_buf_v2(msg, segment + 1, 0);
579 LASSERT(newpos <= tail);
581 memcpy(newpos, tail, tail_len);
584 if (newlen == 0 && msg->lm_bufcount > segment + 1) {
585 memmove(&msg->lm_buflens[segment], &msg->lm_buflens[segment + 1],
586 (msg->lm_bufcount - segment - 1) * sizeof(__u32));
587 msg->lm_buflens[msg->lm_bufcount - 1] = 0;
591 return lustre_msg_size_v2(msg->lm_bufcount, (int *)msg->lm_buflens);
595 * for @msg, shrink @segment to size @newlen. if @move_data is non-zero,
596 * we also move data forward from @segment + 1.
598 * if @newlen == 0, we remove the segment completely, but we still keep the
599 * totally bufcount the same to save possible data moving. this will leave a
600 * unused segment with size 0 at the tail, but that's ok.
602 * return new msg size after shrinking.
605 * + if any buffers higher than @segment has been filled in, must call shrink
606 * with non-zero @move_data.
607 * + caller should NOT keep pointers to msg buffers which higher than @segment
610 int lustre_shrink_msg(struct lustre_msg *msg, int segment,
611 unsigned int newlen, int move_data)
613 switch (msg->lm_magic) {
614 case LUSTRE_MSG_MAGIC_V1:
615 return lustre_shrink_msg_v1((struct lustre_msg_v1 *) msg,
616 segment - 1, newlen, move_data);
617 case LUSTRE_MSG_MAGIC_V2:
618 return lustre_shrink_msg_v2(msg, segment, newlen, move_data);
620 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
624 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
626 PTLRPC_RS_DEBUG_LRU_DEL(rs);
628 LASSERT (atomic_read(&rs->rs_refcount) == 0);
629 LASSERT (!rs->rs_difficult || rs->rs_handled);
630 LASSERT (!rs->rs_on_net);
631 LASSERT (!rs->rs_scheduled);
632 LASSERT (rs->rs_export == NULL);
633 LASSERT (rs->rs_nlocks == 0);
634 LASSERT (list_empty(&rs->rs_exp_list));
635 LASSERT (list_empty(&rs->rs_obd_list));
637 sptlrpc_svc_free_rs(rs);
640 int lustre_unpack_msg_v1(void *msg, int len)
642 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
643 int flipped, required_len, i;
646 /* Now we know the sender speaks my language. */
647 required_len = lustre_msg_hdr_size_v1(0);
648 if (len < required_len) {
649 /* can't even look inside the message */
650 CERROR("message length %d too small for lustre_msg\n", len);
654 flipped = lustre_msg_swabbed((struct lustre_msg *)m);
657 __swab32s(&m->lm_type);
658 __swab32s(&m->lm_version);
659 __swab32s(&m->lm_opc);
660 __swab64s(&m->lm_last_xid);
661 __swab64s(&m->lm_last_committed);
662 __swab64s(&m->lm_transno);
663 __swab32s(&m->lm_status);
664 __swab32s(&m->lm_flags);
665 __swab32s(&m->lm_conn_cnt);
666 __swab32s(&m->lm_bufcount);
669 if (m->lm_version != PTLRPC_MSG_VERSION) {
670 CERROR("wrong lustre_msg version %08x\n", m->lm_version);
674 required_len = lustre_msg_hdr_size_v1(m->lm_bufcount);
675 if (len < required_len) {
676 /* didn't receive all the buffer lengths */
677 CERROR("message length %d too small for %d buflens\n",
678 len, m->lm_bufcount);
682 for (i = 0; i < m->lm_bufcount; i++) {
684 __swab32s (&m->lm_buflens[i]);
685 required_len += size_round(m->lm_buflens[i]);
688 if (len < required_len) {
689 CERROR("len: %d, required_len %d\n", len, required_len);
690 CERROR("bufcount: %d\n", m->lm_bufcount);
691 for (i = 0; i < m->lm_bufcount; i++)
692 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
699 static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
701 int flipped, required_len, i;
703 /* Now we know the sender speaks my language. */
704 required_len = lustre_msg_hdr_size_v2(0);
705 if (len < required_len) {
706 /* can't even look inside the message */
707 CERROR("message length %d too small for lustre_msg\n", len);
711 flipped = lustre_msg_swabbed(m);
714 __swab32s(&m->lm_bufcount);
715 __swab32s(&m->lm_secflvr);
716 __swab32s(&m->lm_repsize);
717 __swab32s(&m->lm_timeout);
718 CLASSERT(offsetof(typeof(*m), lm_padding_1) != 0);
719 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0);
720 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0);
723 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
724 if (len < required_len) {
725 /* didn't receive all the buffer lengths */
726 CERROR ("message length %d too small for %d buflens\n",
727 len, m->lm_bufcount);
731 for (i = 0; i < m->lm_bufcount; i++) {
733 __swab32s(&m->lm_buflens[i]);
734 required_len += size_round(m->lm_buflens[i]);
737 if (len < required_len) {
738 CERROR("len: %d, required_len %d\n", len, required_len);
739 CERROR("bufcount: %d\n", m->lm_bufcount);
740 for (i = 0; i < m->lm_bufcount; i++)
741 CERROR("buffer %d length %d\n", i, m->lm_buflens[i]);
748 int lustre_unpack_msg(struct lustre_msg *m, int len)
750 int required_len, rc;
753 /* We can provide a slightly better error log, if we check the
754 * message magic and version first. In the future, struct
755 * lustre_msg may grow, and we'd like to log a version mismatch,
756 * rather than a short message.
759 required_len = offsetof(struct lustre_msg, lm_magic) +
761 if (len < required_len) {
762 /* can't even look inside the message */
763 CERROR("message length %d too small for magic/version check\n",
768 switch (m->lm_magic) {
769 case LUSTRE_MSG_MAGIC_V1:
770 case LUSTRE_MSG_MAGIC_V1_SWABBED:
771 rc = lustre_unpack_msg_v1(m, len);
773 case LUSTRE_MSG_MAGIC_V2:
774 case LUSTRE_MSG_MAGIC_V2_SWABBED:
775 rc = lustre_unpack_msg_v2(m, len);
778 CERROR("bad lustre msg magic: %#08X\n", m->lm_magic);
785 static inline int lustre_unpack_ptlrpc_body_v2(struct lustre_msg_v2 *m,
788 struct ptlrpc_body *pb;
790 pb = lustre_msg_buf_v2(m, offset, sizeof(*pb));
792 CERROR("error unpacking ptlrpc body");
795 if (lustre_msg_swabbed(m))
796 lustre_swab_ptlrpc_body(pb);
798 if ((pb->pb_version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
799 CERROR("wrong lustre_msg version %08x\n", pb->pb_version);
806 int lustre_unpack_req_ptlrpc_body(struct ptlrpc_request *req, int offset)
808 switch (req->rq_reqmsg->lm_magic) {
809 case LUSTRE_MSG_MAGIC_V1:
810 case LUSTRE_MSG_MAGIC_V1_SWABBED:
812 case LUSTRE_MSG_MAGIC_V2:
813 case LUSTRE_MSG_MAGIC_V2_SWABBED:
814 lustre_set_req_swabbed(req, offset);
815 return lustre_unpack_ptlrpc_body_v2(req->rq_reqmsg, offset);
817 CERROR("bad lustre msg magic: %#08X\n",
818 req->rq_reqmsg->lm_magic);
823 int lustre_unpack_rep_ptlrpc_body(struct ptlrpc_request *req, int offset)
825 switch (req->rq_repmsg->lm_magic) {
826 case LUSTRE_MSG_MAGIC_V1:
827 case LUSTRE_MSG_MAGIC_V1_SWABBED:
829 case LUSTRE_MSG_MAGIC_V2:
830 case LUSTRE_MSG_MAGIC_V2_SWABBED:
831 lustre_set_rep_swabbed(req, offset);
832 return lustre_unpack_ptlrpc_body_v2(req->rq_repmsg, offset);
834 CERROR("bad lustre msg magic: %#08X\n",
835 req->rq_repmsg->lm_magic);
840 static inline int lustre_msg_buflen_v1(void *msg, int n)
842 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
845 if (n >= m->lm_bufcount)
848 return m->lm_buflens[n];
851 static inline int lustre_msg_buflen_v2(struct lustre_msg_v2 *m, int n)
853 if (n >= m->lm_bufcount)
856 return m->lm_buflens[n];
860 * lustre_msg_buflen - return the length of buffer @n in message @m
861 * @m - lustre_msg (request or reply) to look at
862 * @n - message index (base 0)
864 * returns zero for non-existent message indices
866 int lustre_msg_buflen(struct lustre_msg *m, int n)
868 switch (m->lm_magic) {
869 case LUSTRE_MSG_MAGIC_V1:
870 case LUSTRE_MSG_MAGIC_V1_SWABBED:
871 return lustre_msg_buflen_v1(m, n - 1);
872 case LUSTRE_MSG_MAGIC_V2:
873 case LUSTRE_MSG_MAGIC_V2_SWABBED:
874 return lustre_msg_buflen_v2(m, n);
876 CERROR("incorrect message magic: %08x\n", m->lm_magic);
880 EXPORT_SYMBOL(lustre_msg_buflen);
882 static inline void lustre_msg_set_buflen_v1(void *msg, int n, int len)
884 struct lustre_msg_v1 *m = (struct lustre_msg_v1 *)msg;
887 if (n >= m->lm_bufcount)
890 m->lm_buflens[n] = len;
894 lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
896 if (n >= m->lm_bufcount)
899 m->lm_buflens[n] = len;
902 void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
904 switch (m->lm_magic) {
905 case LUSTRE_MSG_MAGIC_V1:
906 lustre_msg_set_buflen_v1(m, n - 1, len);
908 case LUSTRE_MSG_MAGIC_V2:
909 lustre_msg_set_buflen_v2(m, n, len);
912 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
916 EXPORT_SYMBOL(lustre_msg_set_buflen);
918 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
919 * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
920 int lustre_msg_bufcount(struct lustre_msg *m)
922 switch (m->lm_magic) {
923 case LUSTRE_MSG_MAGIC_V1:
924 case LUSTRE_MSG_MAGIC_V1_SWABBED:
925 return ((struct lustre_msg_v1 *)m)->lm_bufcount + 1;
926 case LUSTRE_MSG_MAGIC_V2:
927 case LUSTRE_MSG_MAGIC_V2_SWABBED:
928 return m->lm_bufcount;
930 CERROR("incorrect message magic: %08x\n", m->lm_magic);
934 EXPORT_SYMBOL(lustre_msg_bufcount);
936 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
938 /* max_len == 0 means the string should fill the buffer */
942 switch (m->lm_magic) {
943 case LUSTRE_MSG_MAGIC_V1:
944 case LUSTRE_MSG_MAGIC_V1_SWABBED:
945 str = lustre_msg_buf_v1(m, index - 1, 0);
946 blen = lustre_msg_buflen_v1(m, index - 1);
948 case LUSTRE_MSG_MAGIC_V2:
949 case LUSTRE_MSG_MAGIC_V2_SWABBED:
950 str = lustre_msg_buf_v2(m, index, 0);
951 blen = lustre_msg_buflen_v2(m, index);
954 LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
958 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
962 slen = strnlen(str, blen);
964 if (slen == blen) { /* not NULL terminated */
965 CERROR("can't unpack non-NULL terminated string in "
966 "msg %p buffer[%d] len %d\n", m, index, blen);
971 if (slen != blen - 1) {
972 CERROR("can't unpack short string in msg %p "
973 "buffer[%d] len %d: strlen %d\n",
974 m, index, blen, slen);
977 } else if (slen > max_len) {
978 CERROR("can't unpack oversized string in msg %p "
979 "buffer[%d] len %d strlen %d: max %d expected\n",
980 m, index, blen, slen, max_len);
987 /* Wrap up the normal fixed length cases */
988 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
993 switch (msg->lm_magic) {
994 case LUSTRE_MSG_MAGIC_V1:
995 case LUSTRE_MSG_MAGIC_V1_SWABBED:
996 ptr = lustre_msg_buf_v1(msg, index - 1, min_size);
998 case LUSTRE_MSG_MAGIC_V2:
999 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1000 ptr = lustre_msg_buf_v2(msg, index, min_size);
1003 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1008 if (swabber != NULL && lustre_msg_swabbed(msg))
1009 ((void (*)(void *))swabber)(ptr);
1014 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
1017 lustre_set_req_swabbed(req, index);
1018 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
1021 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
1024 lustre_set_rep_swabbed(req, index);
1025 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
1028 __u32 lustre_msg_get_flags(struct lustre_msg *msg)
1030 switch (msg->lm_magic) {
1031 case LUSTRE_MSG_MAGIC_V1:
1032 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1033 return ((struct lustre_msg_v1 *)msg)->lm_flags &
1035 case LUSTRE_MSG_MAGIC_V2:
1036 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1037 struct ptlrpc_body *pb;
1039 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1041 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1044 return pb->pb_flags;
1047 /* flags might be printed in debug code while message
1053 void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
1055 switch (msg->lm_magic) {
1056 case LUSTRE_MSG_MAGIC_V1:
1057 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1058 MSG_GEN_FLAG_MASK & flags;
1060 case LUSTRE_MSG_MAGIC_V2: {
1061 struct ptlrpc_body *pb;
1063 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1064 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1065 pb->pb_flags |= flags;
1069 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1073 void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
1075 switch (msg->lm_magic) {
1076 case LUSTRE_MSG_MAGIC_V1:
1077 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_GEN_FLAG_MASK;
1078 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1079 MSG_GEN_FLAG_MASK & flags;
1081 case LUSTRE_MSG_MAGIC_V2: {
1082 struct ptlrpc_body *pb;
1084 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1085 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1086 pb->pb_flags = flags;
1090 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1094 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
1096 switch (msg->lm_magic) {
1097 case LUSTRE_MSG_MAGIC_V1:
1098 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1099 ((struct lustre_msg_v1 *)msg)->lm_flags &=
1100 ~(MSG_GEN_FLAG_MASK & flags);
1102 case LUSTRE_MSG_MAGIC_V2:
1103 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1104 struct ptlrpc_body *pb;
1106 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1107 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1108 pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
1112 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1116 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
1118 switch (msg->lm_magic) {
1119 case LUSTRE_MSG_MAGIC_V1:
1120 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1121 return ((struct lustre_msg_v1 *)msg)->lm_flags >>
1123 case LUSTRE_MSG_MAGIC_V2:
1124 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1125 struct ptlrpc_body *pb;
1127 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1129 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1132 return pb->pb_op_flags;
1139 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
1141 switch (msg->lm_magic) {
1142 case LUSTRE_MSG_MAGIC_V1:
1143 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1144 (flags & MSG_GEN_FLAG_MASK) << MSG_OP_FLAG_SHIFT;
1146 case LUSTRE_MSG_MAGIC_V2: {
1147 struct ptlrpc_body *pb;
1149 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1150 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1151 pb->pb_op_flags |= flags;
1155 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1159 void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
1161 switch (msg->lm_magic) {
1162 case LUSTRE_MSG_MAGIC_V1:
1163 ((struct lustre_msg_v1 *)msg)->lm_flags &= ~MSG_OP_FLAG_MASK;
1164 ((struct lustre_msg_v1 *)msg)->lm_flags |=
1165 ((flags & MSG_GEN_FLAG_MASK) <<MSG_OP_FLAG_SHIFT);
1167 case LUSTRE_MSG_MAGIC_V2: {
1168 struct ptlrpc_body *pb;
1170 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1171 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1172 pb->pb_op_flags |= flags;
1176 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1180 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
1182 switch (msg->lm_magic) {
1183 case LUSTRE_MSG_MAGIC_V1:
1184 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1185 return &((struct lustre_msg_v1 *)msg)->lm_handle;
1186 case LUSTRE_MSG_MAGIC_V2:
1187 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1188 struct ptlrpc_body *pb;
1190 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1192 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1195 return &pb->pb_handle;
1198 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1203 __u32 lustre_msg_get_type(struct lustre_msg *msg)
1205 switch (msg->lm_magic) {
1206 case LUSTRE_MSG_MAGIC_V1:
1207 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1208 return ((struct lustre_msg_v1 *)msg)->lm_type;
1209 case LUSTRE_MSG_MAGIC_V2:
1210 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1211 struct ptlrpc_body *pb;
1213 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1215 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1216 return PTL_RPC_MSG_ERR;
1221 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1222 return PTL_RPC_MSG_ERR;
1226 __u32 lustre_msg_get_version(struct lustre_msg *msg)
1228 switch (msg->lm_magic) {
1229 case LUSTRE_MSG_MAGIC_V1:
1230 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1231 return ((struct lustre_msg_v1 *)msg)->lm_version;
1232 case LUSTRE_MSG_MAGIC_V2:
1233 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1234 struct ptlrpc_body *pb;
1236 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1238 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1241 return pb->pb_version;
1244 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1249 void lustre_msg_add_version(struct lustre_msg *msg, int version)
1251 switch (msg->lm_magic) {
1252 case LUSTRE_MSG_MAGIC_V1:
1253 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1255 case LUSTRE_MSG_MAGIC_V2:
1256 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1257 struct ptlrpc_body *pb;
1259 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1260 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1261 pb->pb_version |= version;
1265 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1269 __u32 lustre_msg_get_opc(struct lustre_msg *msg)
1271 switch (msg->lm_magic) {
1272 case LUSTRE_MSG_MAGIC_V1:
1273 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1274 return ((struct lustre_msg_v1 *)msg)->lm_opc;
1275 case LUSTRE_MSG_MAGIC_V2:
1276 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1277 struct ptlrpc_body *pb;
1279 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1281 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1287 CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
1292 __u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
1294 switch (msg->lm_magic) {
1295 case LUSTRE_MSG_MAGIC_V1:
1296 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1297 return ((struct lustre_msg_v1 *)msg)->lm_last_xid;
1298 case LUSTRE_MSG_MAGIC_V2:
1299 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1300 struct ptlrpc_body *pb;
1302 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1304 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1307 return pb->pb_last_xid;
1310 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1315 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
1317 switch (msg->lm_magic) {
1318 case LUSTRE_MSG_MAGIC_V1:
1319 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1320 return ((struct lustre_msg_v1 *)msg)->lm_last_committed;
1321 case LUSTRE_MSG_MAGIC_V2:
1322 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1323 struct ptlrpc_body *pb;
1325 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1327 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1330 return pb->pb_last_committed;
1333 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1338 __u64 lustre_msg_get_transno(struct lustre_msg *msg)
1340 switch (msg->lm_magic) {
1341 case LUSTRE_MSG_MAGIC_V1:
1342 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1343 return ((struct lustre_msg_v1 *)msg)->lm_transno;
1344 case LUSTRE_MSG_MAGIC_V2:
1345 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1346 struct ptlrpc_body *pb;
1348 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1350 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1353 return pb->pb_transno;
1356 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1361 int lustre_msg_get_status(struct lustre_msg *msg)
1363 switch (msg->lm_magic) {
1364 case LUSTRE_MSG_MAGIC_V1:
1365 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1366 return ((struct lustre_msg_v1 *)msg)->lm_status;
1367 case LUSTRE_MSG_MAGIC_V2:
1368 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1369 struct ptlrpc_body *pb;
1371 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1373 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1376 return pb->pb_status;
1379 /* status might be printed in debug code while message
1385 __u64 lustre_msg_get_slv(struct lustre_msg *msg)
1387 switch (msg->lm_magic) {
1388 case LUSTRE_MSG_MAGIC_V1:
1389 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1391 case LUSTRE_MSG_MAGIC_V2:
1392 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1393 struct ptlrpc_body *pb;
1395 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1397 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1403 CERROR("invalid msg magic %x\n", msg->lm_magic);
1409 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
1411 switch (msg->lm_magic) {
1412 case LUSTRE_MSG_MAGIC_V1:
1413 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1415 case LUSTRE_MSG_MAGIC_V2:
1416 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1417 struct ptlrpc_body *pb;
1419 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1421 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1428 CERROR("invalid msg magic %x\n", msg->lm_magic);
1433 __u32 lustre_msg_get_limit(struct lustre_msg *msg)
1435 switch (msg->lm_magic) {
1436 case LUSTRE_MSG_MAGIC_V1:
1437 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1439 case LUSTRE_MSG_MAGIC_V2:
1440 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1441 struct ptlrpc_body *pb;
1443 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1445 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1448 return pb->pb_limit;
1451 CERROR("invalid msg magic %x\n", msg->lm_magic);
1457 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
1459 switch (msg->lm_magic) {
1460 case LUSTRE_MSG_MAGIC_V1:
1461 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1463 case LUSTRE_MSG_MAGIC_V2:
1464 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1465 struct ptlrpc_body *pb;
1467 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1469 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1472 pb->pb_limit = limit;
1476 CERROR("invalid msg magic %x\n", msg->lm_magic);
1481 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
1483 switch (msg->lm_magic) {
1484 case LUSTRE_MSG_MAGIC_V1:
1485 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1486 return ((struct lustre_msg_v1 *)msg)->lm_conn_cnt;
1487 case LUSTRE_MSG_MAGIC_V2:
1488 case LUSTRE_MSG_MAGIC_V2_SWABBED: {
1489 struct ptlrpc_body *pb;
1491 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1493 CERROR("invalid msg %p: no ptlrpc body!\n", msg);
1496 return pb->pb_conn_cnt;
1499 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1504 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
1506 switch (msg->lm_magic) {
1507 case LUSTRE_MSG_MAGIC_V1:
1508 case LUSTRE_MSG_MAGIC_V1_SWABBED:
1509 case LUSTRE_MSG_MAGIC_V2:
1510 case LUSTRE_MSG_MAGIC_V2_SWABBED:
1511 return msg->lm_magic;
1513 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
1518 void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
1520 switch (msg->lm_magic) {
1521 case LUSTRE_MSG_MAGIC_V1:
1522 ((struct lustre_msg_v1 *)msg)->lm_handle = *handle;
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_handle = *handle;
1533 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1537 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
1539 switch (msg->lm_magic) {
1540 case LUSTRE_MSG_MAGIC_V1:
1541 ((struct lustre_msg_v1 *)msg)->lm_type = type;
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);
1552 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1556 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
1558 switch (msg->lm_magic) {
1559 case LUSTRE_MSG_MAGIC_V1:
1560 ((struct lustre_msg_v1 *)msg)->lm_opc = opc;
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);
1571 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1575 void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
1577 switch (msg->lm_magic) {
1578 case LUSTRE_MSG_MAGIC_V1:
1579 ((struct lustre_msg_v1 *)msg)->lm_last_xid = last_xid;
1581 case LUSTRE_MSG_MAGIC_V2: {
1582 struct ptlrpc_body *pb;
1584 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1585 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1586 pb->pb_last_xid = last_xid;
1590 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1594 void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
1596 switch (msg->lm_magic) {
1597 case LUSTRE_MSG_MAGIC_V1:
1598 ((struct lustre_msg_v1 *)msg)->lm_last_committed=last_committed;
1600 case LUSTRE_MSG_MAGIC_V2: {
1601 struct ptlrpc_body *pb;
1603 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1604 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1605 pb->pb_last_committed = last_committed;
1609 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1613 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
1615 switch (msg->lm_magic) {
1616 case LUSTRE_MSG_MAGIC_V1:
1617 ((struct lustre_msg_v1 *)msg)->lm_transno = transno;
1619 case LUSTRE_MSG_MAGIC_V2: {
1620 struct ptlrpc_body *pb;
1622 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1623 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1624 pb->pb_transno = transno;
1628 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1632 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
1634 switch (msg->lm_magic) {
1635 case LUSTRE_MSG_MAGIC_V1:
1636 ((struct lustre_msg_v1 *)msg)->lm_status = status;
1638 case LUSTRE_MSG_MAGIC_V2: {
1639 struct ptlrpc_body *pb;
1641 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1642 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1643 pb->pb_status = status;
1647 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1651 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
1653 switch (msg->lm_magic) {
1654 case LUSTRE_MSG_MAGIC_V1:
1655 ((struct lustre_msg_v1 *)msg)->lm_conn_cnt = conn_cnt;
1657 case LUSTRE_MSG_MAGIC_V2: {
1658 struct ptlrpc_body *pb;
1660 pb = lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF, sizeof(*pb));
1661 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1662 pb->pb_conn_cnt = conn_cnt;
1666 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
1670 /* byte flipping routines for all wire types declared in
1671 * lustre_idl.h implemented here.
1673 void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1675 __swab32s (&b->pb_type);
1676 __swab32s (&b->pb_version);
1677 __swab32s (&b->pb_opc);
1678 __swab32s (&b->pb_status);
1679 __swab64s (&b->pb_last_xid);
1680 __swab64s (&b->pb_last_seen);
1681 __swab64s (&b->pb_last_committed);
1682 __swab64s (&b->pb_transno);
1683 __swab32s (&b->pb_flags);
1684 __swab32s (&b->pb_op_flags);
1685 __swab32s (&b->pb_conn_cnt);
1686 CLASSERT(offsetof(typeof(*b), pb_padding_1) != 0);
1687 CLASSERT(offsetof(typeof(*b), pb_padding_2) != 0);
1688 __swab32s (&b->pb_limit);
1689 __swab64s (&b->pb_slv);
1692 void lustre_swab_connect(struct obd_connect_data *ocd)
1694 __swab64s(&ocd->ocd_connect_flags);
1695 __swab32s(&ocd->ocd_version);
1696 __swab32s(&ocd->ocd_grant);
1697 __swab64s(&ocd->ocd_ibits_known);
1698 __swab32s(&ocd->ocd_index);
1699 __swab32s(&ocd->ocd_brw_size);
1700 __swab32s(&ocd->ocd_nllu);
1701 __swab32s(&ocd->ocd_nllg);
1702 __swab64s(&ocd->ocd_transno);
1703 __swab32s(&ocd->ocd_group);
1704 CLASSERT(offsetof(typeof(*ocd), padding1) != 0);
1705 CLASSERT(offsetof(typeof(*ocd), padding2) != 0);
1706 CLASSERT(offsetof(typeof(*ocd), padding3) != 0);
1709 void lustre_swab_obdo (struct obdo *o)
1711 __swab64s (&o->o_valid);
1712 __swab64s (&o->o_id);
1713 __swab64s (&o->o_gr);
1714 __swab64s (&o->o_fid);
1715 __swab64s (&o->o_size);
1716 __swab64s (&o->o_mtime);
1717 __swab64s (&o->o_atime);
1718 __swab64s (&o->o_ctime);
1719 __swab64s (&o->o_blocks);
1720 __swab64s (&o->o_grant);
1721 __swab32s (&o->o_blksize);
1722 __swab32s (&o->o_mode);
1723 __swab32s (&o->o_uid);
1724 __swab32s (&o->o_gid);
1725 __swab32s (&o->o_flags);
1726 __swab32s (&o->o_nlink);
1727 __swab32s (&o->o_generation);
1728 __swab32s (&o->o_misc);
1729 __swab32s (&o->o_easize);
1730 __swab32s (&o->o_mds);
1731 __swab32s (&o->o_stripe_idx);
1732 __swab32s (&o->o_padding_1);
1733 /* o_inline is opaque */
1736 void lustre_swab_obd_statfs (struct obd_statfs *os)
1738 __swab64s (&os->os_type);
1739 __swab64s (&os->os_blocks);
1740 __swab64s (&os->os_bfree);
1741 __swab64s (&os->os_bavail);
1742 __swab64s (&os->os_files);
1743 __swab64s (&os->os_ffree);
1744 /* no need to swab os_fsid */
1745 __swab32s (&os->os_bsize);
1746 __swab32s (&os->os_namelen);
1747 __swab64s (&os->os_maxbytes);
1748 __swab32s (&os->os_state);
1749 /* no need to swap os_spare */
1752 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
1754 __swab64s (&ioo->ioo_id);
1755 __swab64s (&ioo->ioo_gr);
1756 __swab32s (&ioo->ioo_type);
1757 __swab32s (&ioo->ioo_bufcnt);
1760 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
1762 __swab64s (&nbr->offset);
1763 __swab32s (&nbr->len);
1764 __swab32s (&nbr->flags);
1767 void lustre_swab_ost_body (struct ost_body *b)
1769 lustre_swab_obdo (&b->oa);
1772 void lustre_swab_ost_last_id(obd_id *id)
1777 void lustre_swab_generic_32s(__u32 *val)
1782 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
1784 __swab64s(&lvb->lvb_size);
1785 __swab64s(&lvb->lvb_mtime);
1786 __swab64s(&lvb->lvb_atime);
1787 __swab64s(&lvb->lvb_ctime);
1788 __swab64s(&lvb->lvb_blocks);
1791 void lustre_swab_mds_status_req (struct mds_status_req *r)
1793 __swab32s (&r->flags);
1794 __swab32s (&r->repbuf);
1797 void lustre_swab_mds_body (struct mds_body *b)
1799 lustre_swab_ll_fid (&b->fid1);
1800 lustre_swab_ll_fid (&b->fid2);
1801 /* handle is opaque */
1802 __swab64s (&b->valid);
1803 __swab64s (&b->size);
1804 __swab64s (&b->mtime);
1805 __swab64s (&b->atime);
1806 __swab64s (&b->ctime);
1807 __swab64s (&b->blocks);
1808 __swab64s (&b->io_epoch);
1809 __swab64s (&b->ino);
1810 __swab32s (&b->fsuid);
1811 __swab32s (&b->fsgid);
1812 __swab32s (&b->capability);
1813 __swab32s (&b->mode);
1814 __swab32s (&b->uid);
1815 __swab32s (&b->gid);
1816 __swab32s (&b->flags);
1817 __swab32s (&b->rdev);
1818 __swab32s (&b->nlink);
1819 __swab32s (&b->generation);
1820 __swab32s (&b->suppgid);
1821 __swab32s (&b->eadatasize);
1822 __swab32s (&b->aclsize);
1823 __swab32s (&b->max_mdsize);
1824 __swab32s (&b->max_cookiesize);
1825 __swab32s (&b->padding_4);
1828 void lustre_swab_mdt_body (struct mdt_body *b)
1830 lustre_swab_lu_fid (&b->fid1);
1831 lustre_swab_lu_fid (&b->fid2);
1832 /* handle is opaque */
1833 __swab64s (&b->valid);
1834 __swab64s (&b->size);
1835 __swab64s (&b->mtime);
1836 __swab64s (&b->atime);
1837 __swab64s (&b->ctime);
1838 __swab64s (&b->blocks);
1839 __swab64s (&b->ioepoch);
1840 __swab32s (&b->fsuid);
1841 __swab32s (&b->fsgid);
1842 __swab32s (&b->capability);
1843 __swab32s (&b->mode);
1844 __swab32s (&b->uid);
1845 __swab32s (&b->gid);
1846 __swab32s (&b->flags);
1847 __swab32s (&b->rdev);
1848 __swab32s (&b->nlink);
1849 __swab32s (&b->suppgid);
1850 __swab32s (&b->eadatasize);
1851 __swab32s (&b->aclsize);
1852 __swab32s (&b->max_mdsize);
1853 __swab32s (&b->max_cookiesize);
1856 void lustre_swab_mdt_epoch (struct mdt_epoch *b)
1858 /* handle is opaque */
1859 __swab64s (&b->ioepoch);
1860 __swab32s (&b->flags);
1861 CLASSERT(offsetof(typeof(*b), padding) != 0);
1864 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1867 __swab32s(&mti->mti_lustre_ver);
1868 __swab32s(&mti->mti_stripe_index);
1869 __swab32s(&mti->mti_config_ver);
1870 __swab32s(&mti->mti_flags);
1871 __swab32s(&mti->mti_nid_count);
1872 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64));
1873 for (i = 0; i < MTI_NIDS_MAX; i++)
1874 __swab64s(&mti->mti_nids[i]);
1877 static void lustre_swab_obd_dqinfo (struct obd_dqinfo *i)
1879 __swab64s (&i->dqi_bgrace);
1880 __swab64s (&i->dqi_igrace);
1881 __swab32s (&i->dqi_flags);
1882 __swab32s (&i->dqi_valid);
1885 static void lustre_swab_obd_dqblk (struct obd_dqblk *b)
1887 __swab64s (&b->dqb_ihardlimit);
1888 __swab64s (&b->dqb_isoftlimit);
1889 __swab64s (&b->dqb_curinodes);
1890 __swab64s (&b->dqb_bhardlimit);
1891 __swab64s (&b->dqb_bsoftlimit);
1892 __swab64s (&b->dqb_curspace);
1893 __swab64s (&b->dqb_btime);
1894 __swab64s (&b->dqb_itime);
1895 __swab32s (&b->dqb_valid);
1896 CLASSERT(offsetof(typeof(*b), padding) != 0);
1899 void lustre_swab_obd_quotactl (struct obd_quotactl *q)
1901 __swab32s (&q->qc_cmd);
1902 __swab32s (&q->qc_type);
1903 __swab32s (&q->qc_id);
1904 __swab32s (&q->qc_stat);
1905 lustre_swab_obd_dqinfo (&q->qc_dqinfo);
1906 lustre_swab_obd_dqblk (&q->qc_dqblk);
1909 void lustre_swab_mds_remote_perm (struct mds_remote_perm *p)
1911 __swab32s (&p->rp_uid);
1912 __swab32s (&p->rp_gid);
1913 __swab32s (&p->rp_fsuid);
1914 __swab32s (&p->rp_fsgid);
1915 __swab32s (&p->rp_access_perm);
1918 void lustre_swab_mdt_remote_perm (struct mdt_remote_perm *p)
1920 __swab32s (&p->rp_uid);
1921 __swab32s (&p->rp_gid);
1922 __swab32s (&p->rp_fsuid);
1923 __swab32s (&p->rp_fsgid);
1924 __swab32s (&p->rp_access_perm);
1927 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
1929 __swab32s (&sa->sa_opcode);
1930 __swab32s (&sa->sa_fsuid);
1931 __swab32s (&sa->sa_fsgid);
1932 __swab32s (&sa->sa_cap);
1933 __swab32s (&sa->sa_suppgid);
1934 __swab32s (&sa->sa_mode);
1935 lustre_swab_ll_fid (&sa->sa_fid);
1936 __swab64s (&sa->sa_valid);
1937 __swab64s (&sa->sa_size);
1938 __swab64s (&sa->sa_mtime);
1939 __swab64s (&sa->sa_atime);
1940 __swab64s (&sa->sa_ctime);
1941 __swab32s (&sa->sa_uid);
1942 __swab32s (&sa->sa_gid);
1943 __swab32s (&sa->sa_attr_flags);
1944 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1947 void lustre_swab_mdt_rec_setattr (struct mdt_rec_setattr *sa)
1949 __swab32s (&sa->sa_opcode);
1950 __swab32s (&sa->sa_fsuid);
1951 __swab32s (&sa->sa_fsgid);
1952 __swab32s (&sa->sa_cap);
1953 __swab32s (&sa->sa_suppgid);
1954 __swab32s (&sa->sa_mode);
1955 lustre_swab_lu_fid (&sa->sa_fid);
1956 __swab64s (&sa->sa_valid);
1957 __swab64s (&sa->sa_size);
1958 __swab64s (&sa->sa_blocks);
1959 __swab64s (&sa->sa_mtime);
1960 __swab64s (&sa->sa_atime);
1961 __swab64s (&sa->sa_ctime);
1962 __swab32s (&sa->sa_uid);
1963 __swab32s (&sa->sa_gid);
1964 __swab32s (&sa->sa_attr_flags);
1965 CLASSERT(offsetof(typeof(*sa), sa_padding) != 0);
1968 void lustre_swab_mds_rec_join (struct mds_rec_join *jr)
1970 __swab64s(&jr->jr_headsize);
1971 lustre_swab_ll_fid(&jr->jr_fid);
1974 void lustre_swab_mdt_rec_join (struct mdt_rec_join *jr)
1976 __swab64s(&jr->jr_headsize);
1977 lustre_swab_lu_fid(&jr->jr_fid);
1980 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
1982 __swab32s (&cr->cr_opcode);
1983 __swab32s (&cr->cr_fsuid);
1984 __swab32s (&cr->cr_fsgid);
1985 __swab32s (&cr->cr_cap);
1986 __swab32s (&cr->cr_flags); /* for use with open */
1987 __swab32s (&cr->cr_mode);
1988 lustre_swab_ll_fid (&cr->cr_fid);
1989 lustre_swab_ll_fid (&cr->cr_replayfid);
1990 __swab64s (&cr->cr_time);
1991 __swab64s (&cr->cr_rdev);
1992 __swab32s (&cr->cr_suppgid);
1993 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
1994 CLASSERT(offsetof(typeof(*cr), cr_padding_2) != 0);
1995 CLASSERT(offsetof(typeof(*cr), cr_padding_3) != 0);
1996 CLASSERT(offsetof(typeof(*cr), cr_padding_4) != 0);
1997 CLASSERT(offsetof(typeof(*cr), cr_padding_5) != 0);
2000 void lustre_swab_mdt_rec_create (struct mdt_rec_create *cr)
2002 __swab32s (&cr->cr_opcode);
2003 __swab32s (&cr->cr_fsuid);
2004 __swab32s (&cr->cr_fsgid);
2005 __swab32s (&cr->cr_cap);
2006 __swab32s (&cr->cr_flags); /* for use with open */
2007 __swab32s (&cr->cr_mode);
2008 /* handle is opaque */
2009 lustre_swab_lu_fid (&cr->cr_fid1);
2010 lustre_swab_lu_fid (&cr->cr_fid2);
2011 __swab64s (&cr->cr_time);
2012 __swab64s (&cr->cr_rdev);
2013 __swab64s (&cr->cr_ioepoch);
2014 __swab32s (&cr->cr_suppgid1);
2015 __swab32s (&cr->cr_suppgid2);
2016 __swab32s (&cr->cr_bias);
2017 CLASSERT(offsetof(typeof(*cr), cr_padding_1) != 0);
2020 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
2022 __swab32s (&lk->lk_opcode);
2023 __swab32s (&lk->lk_fsuid);
2024 __swab32s (&lk->lk_fsgid);
2025 __swab32s (&lk->lk_cap);
2026 __swab32s (&lk->lk_suppgid1);
2027 __swab32s (&lk->lk_suppgid2);
2028 lustre_swab_ll_fid (&lk->lk_fid1);
2029 lustre_swab_ll_fid (&lk->lk_fid2);
2030 __swab64s (&lk->lk_time);
2031 CLASSERT(offsetof(typeof(*lk), lk_padding_1) != 0);
2032 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2033 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2034 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2037 void lustre_swab_mdt_rec_link (struct mdt_rec_link *lk)
2039 __swab32s (&lk->lk_opcode);
2040 __swab32s (&lk->lk_fsuid);
2041 __swab32s (&lk->lk_fsgid);
2042 __swab32s (&lk->lk_cap);
2043 __swab32s (&lk->lk_suppgid1);
2044 __swab32s (&lk->lk_suppgid2);
2045 lustre_swab_lu_fid (&lk->lk_fid1);
2046 lustre_swab_lu_fid (&lk->lk_fid2);
2047 __swab64s (&lk->lk_time);
2048 __swab32s (&lk->lk_bias);
2049 CLASSERT(offsetof(typeof(*lk), lk_padding_2) != 0);
2050 CLASSERT(offsetof(typeof(*lk), lk_padding_3) != 0);
2051 CLASSERT(offsetof(typeof(*lk), lk_padding_4) != 0);
2054 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
2056 __swab32s (&ul->ul_opcode);
2057 __swab32s (&ul->ul_fsuid);
2058 __swab32s (&ul->ul_fsgid);
2059 __swab32s (&ul->ul_cap);
2060 __swab32s (&ul->ul_suppgid);
2061 __swab32s (&ul->ul_mode);
2062 lustre_swab_ll_fid (&ul->ul_fid1);
2063 lustre_swab_ll_fid (&ul->ul_fid2);
2064 __swab64s (&ul->ul_time);
2065 CLASSERT(offsetof(typeof(*ul), ul_padding_1) != 0);
2066 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2067 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2068 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2071 void lustre_swab_mdt_rec_unlink (struct mdt_rec_unlink *ul)
2073 __swab32s (&ul->ul_opcode);
2074 __swab32s (&ul->ul_fsuid);
2075 __swab32s (&ul->ul_fsgid);
2076 __swab32s (&ul->ul_cap);
2077 __swab32s (&ul->ul_suppgid);
2078 __swab32s (&ul->ul_mode);
2079 lustre_swab_lu_fid (&ul->ul_fid1);
2080 lustre_swab_lu_fid (&ul->ul_fid2);
2081 __swab64s (&ul->ul_time);
2082 __swab32s (&ul->ul_bias);
2083 CLASSERT(offsetof(typeof(*ul), ul_padding_2) != 0);
2084 CLASSERT(offsetof(typeof(*ul), ul_padding_3) != 0);
2085 CLASSERT(offsetof(typeof(*ul), ul_padding_4) != 0);
2088 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
2090 __swab32s (&rn->rn_opcode);
2091 __swab32s (&rn->rn_fsuid);
2092 __swab32s (&rn->rn_fsgid);
2093 __swab32s (&rn->rn_cap);
2094 __swab32s (&rn->rn_suppgid1);
2095 __swab32s (&rn->rn_suppgid2);
2096 lustre_swab_ll_fid (&rn->rn_fid1);
2097 lustre_swab_ll_fid (&rn->rn_fid2);
2098 __swab64s (&rn->rn_time);
2099 CLASSERT(offsetof(typeof(*rn), rn_padding_1) != 0);
2100 CLASSERT(offsetof(typeof(*rn), rn_padding_2) != 0);
2101 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2102 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2105 void lustre_swab_mdt_rec_rename (struct mdt_rec_rename *rn)
2107 __swab32s (&rn->rn_opcode);
2108 __swab32s (&rn->rn_fsuid);
2109 __swab32s (&rn->rn_fsgid);
2110 __swab32s (&rn->rn_cap);
2111 __swab32s (&rn->rn_suppgid1);
2112 __swab32s (&rn->rn_suppgid2);
2113 lustre_swab_lu_fid (&rn->rn_fid1);
2114 lustre_swab_lu_fid (&rn->rn_fid2);
2115 __swab64s (&rn->rn_time);
2116 __swab32s (&rn->rn_mode);
2117 __swab32s (&rn->rn_bias);
2118 CLASSERT(offsetof(typeof(*rn), rn_padding_3) != 0);
2119 CLASSERT(offsetof(typeof(*rn), rn_padding_4) != 0);
2122 void lustre_swab_lov_desc (struct lov_desc *ld)
2124 __swab32s (&ld->ld_tgt_count);
2125 __swab32s (&ld->ld_active_tgt_count);
2126 __swab32s (&ld->ld_default_stripe_count);
2127 __swab64s (&ld->ld_default_stripe_size);
2128 __swab64s (&ld->ld_default_stripe_offset);
2129 __swab32s (&ld->ld_pattern);
2130 __swab32s (&ld->ld_qos_maxage);
2131 /* uuid endian insensitive */
2134 /*begin adding MDT by huanghua@clusterfs.com*/
2135 void lustre_swab_lmv_desc (struct lmv_desc *ld)
2137 __swab32s (&ld->ld_tgt_count);
2138 __swab32s (&ld->ld_active_tgt_count);
2139 /* uuid endian insensitive */
2141 /*end adding MDT by huanghua@clusterfs.com*/
2142 void lustre_swab_md_fld (struct md_fld *mf)
2144 __swab64s(&mf->mf_seq);
2145 __swab64s(&mf->mf_mds);
2148 static void print_lum (struct lov_user_md *lum)
2150 CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
2151 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
2152 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
2153 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
2154 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_gr);
2155 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
2156 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
2157 CDEBUG(D_OTHER, "\tlmm_stripe_offset: %#x\n", lum->lmm_stripe_offset);
2160 void lustre_swab_lov_user_md(struct lov_user_md *lum)
2163 CDEBUG(D_IOCTL, "swabbing lov_user_md\n");
2164 __swab32s(&lum->lmm_magic);
2165 __swab32s(&lum->lmm_pattern);
2166 __swab64s(&lum->lmm_object_id);
2167 __swab64s(&lum->lmm_object_gr);
2168 __swab32s(&lum->lmm_stripe_size);
2169 __swab16s(&lum->lmm_stripe_count);
2170 __swab16s(&lum->lmm_stripe_offset);
2175 static void print_lumj (struct lov_user_md_join *lumj)
2177 CDEBUG(D_OTHER, "lov_user_md %p:\n", lumj);
2178 CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lumj->lmm_magic);
2179 CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lumj->lmm_pattern);
2180 CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lumj->lmm_object_id);
2181 CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lumj->lmm_object_gr);
2182 CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lumj->lmm_stripe_size);
2183 CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lumj->lmm_stripe_count);
2184 CDEBUG(D_OTHER, "\tlmm_extent_count: %#x\n", lumj->lmm_extent_count);
2187 void lustre_swab_lov_user_md_join(struct lov_user_md_join *lumj)
2190 CDEBUG(D_IOCTL, "swabbing lov_user_md_join\n");
2191 __swab32s(&lumj->lmm_magic);
2192 __swab32s(&lumj->lmm_pattern);
2193 __swab64s(&lumj->lmm_object_id);
2194 __swab64s(&lumj->lmm_object_gr);
2195 __swab32s(&lumj->lmm_stripe_size);
2196 __swab32s(&lumj->lmm_stripe_count);
2197 __swab32s(&lumj->lmm_extent_count);
2202 static void print_lum_objs(struct lov_user_md *lum)
2204 struct lov_user_ost_data *lod;
2207 if (!(libcfs_debug & D_OTHER)) /* don't loop on nothing */
2209 CDEBUG(D_OTHER, "lov_user_md_objects: %p\n", lum);
2210 for (i = 0; i < lum->lmm_stripe_count; i++) {
2211 lod = &lum->lmm_objects[i];
2212 CDEBUG(D_OTHER, "(%i) lod->l_object_id: "LPX64"\n", i, lod->l_object_id);
2213 CDEBUG(D_OTHER, "(%i) lod->l_object_gr: "LPX64"\n", i, lod->l_object_gr);
2214 CDEBUG(D_OTHER, "(%i) lod->l_ost_gen: %#x\n", i, lod->l_ost_gen);
2215 CDEBUG(D_OTHER, "(%i) lod->l_ost_idx: %#x\n", i, lod->l_ost_idx);
2220 void lustre_swab_lov_user_md_objects(struct lov_user_md *lum)
2222 struct lov_user_ost_data *lod;
2225 for (i = 0; i < lum->lmm_stripe_count; i++) {
2226 lod = &lum->lmm_objects[i];
2227 __swab64s(&lod->l_object_id);
2228 __swab64s(&lod->l_object_gr);
2229 __swab32s(&lod->l_ost_gen);
2230 __swab32s(&lod->l_ost_idx);
2232 print_lum_objs(lum);
2237 void lustre_swab_lov_mds_md(struct lov_mds_md *lmm)
2239 struct lov_ost_data *lod;
2242 for (i = 0; i < lmm->lmm_stripe_count; i++) {
2243 lod = &lmm->lmm_objects[i];
2244 __swab64s(&lod->l_object_id);
2245 __swab64s(&lod->l_object_gr);
2246 __swab32s(&lod->l_ost_gen);
2247 __swab32s(&lod->l_ost_idx);
2249 __swab32s(&lmm->lmm_magic);
2250 __swab32s(&lmm->lmm_pattern);
2251 __swab64s(&lmm->lmm_object_id);
2252 __swab64s(&lmm->lmm_object_gr);
2253 __swab32s(&lmm->lmm_stripe_size);
2254 __swab32s(&lmm->lmm_stripe_count);
2260 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
2264 for (i = 0; i < RES_NAME_SIZE; i++)
2265 __swab64s (&id->name[i]);
2268 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
2270 /* the lock data is a union and the first two fields are always an
2271 * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
2272 * data the same way. */
2273 __swab64s(&d->l_extent.start);
2274 __swab64s(&d->l_extent.end);
2275 __swab64s(&d->l_extent.gid);
2276 __swab32s(&d->l_flock.pid);
2279 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
2281 __swab64s (&i->opc);
2284 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
2286 __swab32s (&r->lr_type);
2287 CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
2288 lustre_swab_ldlm_res_id (&r->lr_name);
2291 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
2293 lustre_swab_ldlm_resource_desc (&l->l_resource);
2294 __swab32s (&l->l_req_mode);
2295 __swab32s (&l->l_granted_mode);
2296 lustre_swab_ldlm_policy_data (&l->l_policy_data);
2299 void lustre_swab_ldlm_request (struct ldlm_request *rq)
2301 __swab32s (&rq->lock_flags);
2302 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
2303 __swab32s (&rq->lock_count);
2304 /* lock_handle[] opaque */
2307 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
2309 __swab32s (&r->lock_flags);
2310 CLASSERT(offsetof(typeof(*r), lock_padding) != 0);
2311 lustre_swab_ldlm_lock_desc (&r->lock_desc);
2312 /* lock_handle opaque */
2313 __swab64s (&r->lock_policy_res1);
2314 __swab64s (&r->lock_policy_res2);
2317 /* no one calls this */
2318 int llog_log_swabbed(struct llog_log_hdr *hdr)
2320 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
2322 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
2327 void lustre_swab_qdata(struct qunit_data *d)
2329 __swab32s (&d->qd_id);
2330 __swab32s (&d->qd_flags);
2331 __swab64s (&d->qd_count);
2334 void lustre_swab_qdata_old(struct qunit_data_old *d)
2336 __swab32s (&d->qd_id);
2337 __swab32s (&d->qd_type);
2338 __swab32s (&d->qd_count);
2339 __swab32s (&d->qd_isblk);
2343 struct qunit_data *lustre_quota_old_to_new(struct qunit_data_old *d)
2345 struct qunit_data_old tmp;
2346 struct qunit_data *ret;
2353 ret = (struct qunit_data *)d;
2354 ret->qd_id = tmp.qd_id;
2355 ret->qd_flags = (tmp.qd_type ? QUOTA_IS_GRP : 0) | (tmp.qd_isblk ? QUOTA_IS_BLOCK : 0);
2356 ret->qd_count = tmp.qd_count;
2360 EXPORT_SYMBOL(lustre_quota_old_to_new);
2362 struct qunit_data_old *lustre_quota_new_to_old(struct qunit_data *d)
2364 struct qunit_data tmp;
2365 struct qunit_data_old *ret;
2372 ret = (struct qunit_data_old *)d;
2373 ret->qd_id = tmp.qd_id;
2374 ret->qd_type = ((tmp.qd_flags & QUOTA_IS_GRP) ? GRPQUOTA : USRQUOTA);
2375 ret->qd_count = (__u32)tmp.qd_count;
2376 ret->qd_isblk = ((tmp.qd_flags & QUOTA_IS_BLOCK) ? 1 : 0);
2379 EXPORT_SYMBOL(lustre_quota_new_to_old);
2380 #endif /* __KERNEL__ */
2382 static inline int req_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2384 LASSERT(req->rq_reqmsg);
2386 switch (req->rq_reqmsg->lm_magic) {
2387 case LUSTRE_MSG_MAGIC_V1:
2388 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2390 case LUSTRE_MSG_MAGIC_V2:
2391 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2392 return lustre_req_swabbed(req, MSG_PTLRPC_BODY_OFF);
2394 CERROR("bad lustre msg magic: %#08X\n",
2395 req->rq_reqmsg->lm_magic);
2400 static inline int rep_ptlrpc_body_swabbed(struct ptlrpc_request *req)
2402 LASSERT(req->rq_repmsg);
2404 switch (req->rq_repmsg->lm_magic) {
2405 case LUSTRE_MSG_MAGIC_V1:
2406 case LUSTRE_MSG_MAGIC_V1_SWABBED:
2408 case LUSTRE_MSG_MAGIC_V2:
2409 case LUSTRE_MSG_MAGIC_V2_SWABBED:
2410 return lustre_rep_swabbed(req, MSG_PTLRPC_BODY_OFF);
2412 /* uninitialized yet */
2417 void _debug_req(struct ptlrpc_request *req, __u32 mask,
2418 struct libcfs_debug_msg_data *data, const char *fmt, ... )
2422 va_start(args, fmt);
2423 libcfs_debug_vmsg2(data->msg_cdls, data->msg_subsys, mask, data->msg_file,
2424 data->msg_fn, data->msg_line, fmt, args,
2425 " req@%p x"LPD64"/t"LPD64"("LPD64") o%d->%s@%s:%d lens"
2426 " %d/%d ref %d fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2427 req, req->rq_xid, req->rq_transno,
2428 req->rq_reqmsg ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2429 req->rq_reqmsg ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2430 req->rq_import ? obd2cli_tgt(req->rq_import->imp_obd) :
2432 (char*)req->rq_export->exp_client_uuid.uuid : "<?>",
2434 (char *)req->rq_import->imp_connection->c_remote_uuid.uuid :
2436 (char *)req->rq_export->exp_connection->c_remote_uuid.uuid : "<?>",
2437 (req->rq_import && req->rq_import->imp_client) ?
2438 req->rq_import->imp_client->cli_request_portal : -1,
2439 req->rq_reqlen, req->rq_replen, atomic_read(&req->rq_refcount),
2440 DEBUG_REQ_FLAGS(req),
2441 req->rq_reqmsg && req_ptlrpc_body_swabbed(req) ?
2442 lustre_msg_get_flags(req->rq_reqmsg) : -1,
2443 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2444 lustre_msg_get_flags(req->rq_repmsg) : -1,
2446 req->rq_repmsg && rep_ptlrpc_body_swabbed(req) ?
2447 lustre_msg_get_status(req->rq_repmsg) : -1);
2449 EXPORT_SYMBOL(_debug_req);
2451 void lustre_swab_lustre_capa(struct lustre_capa *c)
2453 lustre_swab_lu_fid(&c->lc_fid);
2454 __swab64s (&c->lc_opc);
2455 __swab32s (&c->lc_uid);
2456 __swab32s (&c->lc_flags);
2457 __swab32s (&c->lc_keyid);
2458 __swab32s (&c->lc_timeout);
2459 __swab64s (&c->lc_expiry);
2462 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
2464 __swab64s (&k->lk_mdsid);
2465 __swab32s (&k->lk_keyid);
2466 __swab32s (&k->lk_padding);