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 Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * (Un)packing of OST requests
28 #define DEBUG_SUBSYSTEM S_RPC
30 # include <liblustre.h>
33 #include <linux/obd_support.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_net.h>
36 #include <linux/lustre_sec.h>
37 #include <linux/fcntl.h>
38 #include <linux/posix_acl.h>
41 #define HDR_SIZE(count) \
42 size_round(offsetof (struct lustre_msg, buflens[(count)]))
44 int lustre_msg_swabbed(struct lustre_msg *msg)
46 return (msg->magic == __swab32(PTLRPC_MSG_MAGIC));
49 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
51 if (!lustre_msg_swabbed(msg))
52 return (msg->version & LUSTRE_VERSION_MASK) != version;
54 return (__swab32(msg->version) & LUSTRE_VERSION_MASK) != version;
57 void lustre_init_msg(struct lustre_msg *msg, int count,
58 int *lens, char **bufs)
63 msg->magic = PTLRPC_MSG_MAGIC;
64 msg->version = PTLRPC_MSG_VERSION;
65 msg->bufcount = count;
66 for (i = 0; i < count; i++)
67 msg->buflens[i] = lens[i];
72 ptr = (char *)msg + HDR_SIZE(count);
73 for (i = 0; i < count; i++) {
75 LOGL(tmp, lens[i], ptr);
79 int lustre_secdesc_size(void)
82 int ngroups = current_ngroups;
84 if (ngroups > LUSTRE_MAX_GROUPS)
85 ngroups = LUSTRE_MAX_GROUPS;
87 return sizeof(struct mds_req_sec_desc) +
88 sizeof(__u32) * ngroups;
95 * because group info might have changed since last time we call
96 * secdesc_size(), so here we did more sanity check to prevent garbage gids
98 void lustre_pack_secdesc(struct ptlrpc_request *req, int size)
101 struct mds_req_sec_desc *rsd;
103 rsd = lustre_msg_buf(req->rq_reqmsg,
104 MDS_REQ_SECDESC_OFF, size);
106 rsd->rsd_uid = current->uid;
107 rsd->rsd_gid = current->gid;
108 rsd->rsd_fsuid = current->fsuid;
109 rsd->rsd_fsgid = current->fsgid;
110 rsd->rsd_cap = current->cap_effective;
111 rsd->rsd_ngroups = (size - sizeof(*rsd)) / sizeof(__u32);
112 LASSERT(rsd->rsd_ngroups <= LUSTRE_MAX_GROUPS);
114 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
116 if (rsd->rsd_ngroups > current->group_info->ngroups)
117 rsd->rsd_ngroups = current->group_info->ngroups;
118 memcpy(rsd->rsd_groups, current->group_info->blocks[0],
119 rsd->rsd_ngroups * sizeof(__u32));
120 task_unlock(current);
122 LASSERT(rsd->rsd_ngroups <= NGROUPS);
123 if (rsd->rsd_ngroups > current->ngroups)
124 rsd->rsd_ngroups = current->ngroups;
125 memcpy(rsd->rsd_groups, current->groups,
126 rsd->rsd_ngroups * sizeof(__u32));
131 int lustre_pack_request(struct ptlrpc_request *req,
132 int count, int *lens, char **bufs)
137 req->rq_reqlen = lustre_msg_size(count, lens);
138 rc = ptlrpcs_cli_alloc_reqbuf(req, req->rq_reqlen);
142 lustre_init_msg(req->rq_reqmsg, count, lens, bufs);
147 LIST_HEAD(ptlrpc_rs_debug_lru);
148 spinlock_t ptlrpc_rs_debug_lock = SPIN_LOCK_UNLOCKED;
150 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
152 unsigned long __flags; \
154 spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags); \
155 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
156 spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags); \
159 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
161 unsigned long __flags; \
163 spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags); \
164 list_del(&(rs)->rs_debug_list); \
165 spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags); \
168 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
169 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
172 int lustre_pack_reply(struct ptlrpc_request *req,
173 int count, int *lens, char **bufs)
175 struct ptlrpc_reply_state *rs;
179 LASSERT(req->rq_reply_state == NULL);
180 LASSERT(req->rq_svcsec);
181 LASSERT(req->rq_repmsg == NULL);
183 req->rq_replen = lustre_msg_size(count, lens);
184 rc = svcsec_alloc_repbuf(req->rq_svcsec, req, req->rq_replen);
187 LASSERT(req->rq_reply_state);
188 LASSERT(req->rq_repmsg == req->rq_reply_state->rs_msg);
190 rs = req->rq_reply_state;
191 rs->rs_svcsec = svcsec_get(req->rq_svcsec);
192 rs->rs_cb_id.cbid_fn = reply_out_callback;
193 rs->rs_cb_id.cbid_arg = rs;
194 rs->rs_srv_ni = req->rq_rqbd->rqbd_srv_ni;
195 INIT_LIST_HEAD(&rs->rs_exp_list);
196 INIT_LIST_HEAD(&rs->rs_obd_list);
198 lustre_init_msg(rs->rs_msg, count, lens, bufs);
200 PTLRPC_RS_DEBUG_LRU_ADD(rs);
205 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
207 struct ptlrpc_svcsec *svcsec = rs->rs_svcsec;
209 PTLRPC_RS_DEBUG_LRU_DEL(rs);
211 LASSERT(!rs->rs_difficult || rs->rs_handled);
212 LASSERT(!rs->rs_on_net);
213 LASSERT(!rs->rs_scheduled);
214 LASSERT(rs->rs_export == NULL);
215 LASSERT(rs->rs_nlocks == 0);
216 LASSERT(list_empty(&rs->rs_exp_list));
217 LASSERT(list_empty(&rs->rs_obd_list));
220 if (svcsec->free_repbuf)
221 svcsec->free_repbuf(svcsec, rs);
223 svcsec_free_reply_state(rs);
228 /* This returns the size of the buffer that is required to hold a lustre_msg
229 * with the given sub-buffer lengths. */
230 int lustre_msg_size(int count, int *lengths)
235 size = HDR_SIZE (count);
236 for (i = 0; i < count; i++)
237 size += size_round(lengths[i]);
242 int lustre_unpack_msg(struct lustre_msg *m, int len)
249 /* We can provide a slightly better error log, if we check the
250 * message magic and version first. In the future, struct
251 * lustre_msg may grow, and we'd like to log a version mismatch,
252 * rather than a short message.
255 required_len = MAX(offsetof(struct lustre_msg, version) +
257 offsetof(struct lustre_msg, magic) +
259 if (len < required_len) {
260 /* can't even look inside the message */
261 CERROR ("message length %d too small for magic/version check\n",
266 flipped = lustre_msg_swabbed(m);
268 __swab32s(&m->version);
269 else if (m->magic != PTLRPC_MSG_MAGIC) {
270 CERROR("wrong lustre_msg magic %#08x\n", m->magic);
274 if ((m->version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
275 CERROR("wrong lustre_msg version %#08x\n", m->version);
279 /* Now we know the sender speaks my language (but possibly flipped)...*/
280 required_len = HDR_SIZE(0);
281 if (len < required_len) {
282 /* can't even look inside the message */
283 CERROR("message length %d too small for lustre_msg\n", len);
290 __swab64s(&m->last_xid);
291 __swab64s(&m->last_committed);
292 __swab64s(&m->transno);
293 __swab32s(&m->status);
294 __swab32s(&m->bufcount);
295 __swab32s(&m->flags);
298 required_len = HDR_SIZE(m->bufcount);
300 if (len < required_len) {
301 /* didn't receive all the buffer lengths */
302 CERROR ("message length %d too small for %d buflens\n",
307 for (i = 0; i < m->bufcount; i++) {
309 __swab32s (&m->buflens[i]);
310 required_len += size_round(m->buflens[i]);
313 if (len < required_len) {
314 CERROR("len: %d, required_len %d\n", len, required_len);
315 CERROR("bufcount: %d\n", m->bufcount);
316 for (i = 0; i < m->bufcount; i++)
317 CERROR("buffer %d length %d\n", i, m->buflens[i]);
324 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
334 bufcount = m->bufcount;
336 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
341 buflen = m->buflens[n];
342 if (buflen < min_size) {
343 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
344 m, n, buflen, min_size);
348 offset = HDR_SIZE(bufcount);
349 for (i = 0; i < n; i++)
350 offset += size_round(m->buflens[i]);
352 return (char *)m + offset;
355 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
357 /* max_len == 0 means the string should fill the buffer */
358 char *str = lustre_msg_buf(m, index, 0);
363 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
367 blen = m->buflens[index];
368 slen = strnlen(str, blen);
370 if (slen == blen) { /* not NULL terminated */
371 CERROR ("can't unpack non-NULL terminated string in "
372 "msg %p buffer[%d] len %d\n", m, index, blen);
377 if (slen != blen - 1) {
378 CERROR ("can't unpack short string in msg %p "
379 "buffer[%d] len %d: strlen %d\n",
380 m, index, blen, slen);
383 } else if (slen > max_len) {
384 CERROR ("can't unpack oversized string in msg %p "
385 "buffer[%d] len %d strlen %d: max %d expected\n",
386 m, index, blen, slen, max_len);
393 /* Wrap up the normal fixed length cases */
394 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
399 ptr = lustre_msg_buf(msg, index, min_size);
403 if (swabber != NULL && lustre_msg_swabbed(msg))
404 ((void (*)(void *))swabber)(ptr);
409 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
412 LASSERT_REQSWAB(req, index);
413 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
416 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
419 LASSERT_REPSWAB(req, index);
420 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
423 /* byte flipping routines for all wire types declared in
424 * lustre_idl.h implemented here.
427 void lustre_swab_connect(struct obd_connect_data *ocd)
429 __swab64s(&ocd->ocd_connect_flags);
430 __swab32s(&ocd->ocd_nllu[0]);
431 __swab32s(&ocd->ocd_nllu[1]);
434 void lustre_swab_obdo(struct obdo *o)
438 __swab64s(&o->o_atime);
439 __swab64s(&o->o_mtime);
440 __swab64s(&o->o_ctime);
441 __swab64s(&o->o_size);
442 __swab64s(&o->o_blocks);
443 __swab64s(&o->o_grant);
444 __swab32s(&o->o_blksize);
445 __swab32s(&o->o_mode);
446 __swab32s(&o->o_uid);
447 __swab32s(&o->o_gid);
448 __swab32s(&o->o_flags);
449 __swab32s(&o->o_nlink);
450 __swab32s(&o->o_generation);
451 __swab64s(&o->o_valid);
452 __swab32s(&o->o_misc);
453 __swab32s(&o->o_easize);
454 __swab32s(&o->o_mds);
455 __swab64s(&o->o_fid);
456 /* o_inline is opaque */
459 /* mdc pack methods used by mdc and smfs*/
460 void *mdc_create_pack(struct lustre_msg *msg, int offset,
461 struct mdc_op_data *op_data, __u32 mode,
462 __u64 rdev, const void *data, int datalen)
464 struct mds_rec_create *rec;
466 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
468 rec->cr_opcode = REINT_CREATE;
469 rec->cr_id = op_data->id1;
470 memset(&rec->cr_replayid, 0, sizeof(rec->cr_replayid));
473 rec->cr_time = op_data->mod_time;
475 tmp = lustre_msg_buf(msg, offset + 1, op_data->namelen + 1);
476 LOGL0(op_data->name, op_data->namelen, tmp);
479 tmp = lustre_msg_buf(msg, offset + 2, datalen);
480 memcpy (tmp, data, datalen);
482 return ((void*)tmp + size_round(datalen));
485 __u32 mds_pack_open_flags(__u32 flags)
488 (flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC |
489 MDS_OPEN_DELAY_CREATE | MDS_OPEN_HAS_EA |
490 MDS_OPEN_HAS_OBJS)) |
491 ((flags & O_CREAT) ? MDS_OPEN_CREAT : 0) |
492 ((flags & O_EXCL) ? MDS_OPEN_EXCL : 0) |
493 ((flags & O_TRUNC) ? MDS_OPEN_TRUNC : 0) |
494 ((flags & O_APPEND) ? MDS_OPEN_APPEND : 0) |
495 ((flags & O_SYNC) ? MDS_OPEN_SYNC : 0) |
496 ((flags & O_DIRECTORY) ? MDS_OPEN_DIRECTORY : 0) |
500 void *mdc_setattr_pack(struct lustre_msg *msg, int offset,
501 struct mdc_op_data *data, struct iattr *iattr,
502 void *ea, int ealen, void *ea2, int ea2len,
503 void *ea3, int ea3len)
505 struct mds_rec_setattr *rec = lustre_msg_buf(msg, offset, sizeof(*rec));
508 rec->sa_opcode = REINT_SETATTR;
509 rec->sa_id = data->id1;
512 rec->sa_valid = iattr->ia_valid;
513 rec->sa_mode = iattr->ia_mode;
514 rec->sa_uid = iattr->ia_uid;
515 rec->sa_gid = iattr->ia_gid;
516 rec->sa_size = iattr->ia_size;
517 rec->sa_atime = LTIME_S(iattr->ia_atime);
518 rec->sa_mtime = LTIME_S(iattr->ia_mtime);
519 rec->sa_ctime = LTIME_S(iattr->ia_ctime);
520 rec->sa_attr_flags = iattr->ia_attr_flags;
522 tmp = (char*)rec + size_round(sizeof(*rec));
527 memcpy(lustre_msg_buf(msg, offset + 1, ealen), ea, ealen);
528 tmp += size_round(ealen);
533 memcpy(lustre_msg_buf(msg, offset + 2, ea2len), ea2, ea2len);
534 tmp += size_round(ea2len);
539 memcpy(lustre_msg_buf(msg, offset + 3, ea3len), ea3, ea3len);
540 tmp += size_round(ea3len);
545 void *mdc_unlink_pack(struct lustre_msg *msg, int offset,
546 struct mdc_op_data *data)
548 struct mds_rec_unlink *rec;
551 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
552 LASSERT (rec != NULL);
554 rec->ul_opcode = REINT_UNLINK;
555 rec->ul_mode = data->create_mode;
556 rec->ul_id1 = data->id1;
557 rec->ul_id2 = data->id2;
558 rec->ul_time = data->mod_time;
560 tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
561 LASSERT (tmp != NULL);
562 LOGL0(data->name, data->namelen, tmp);
566 void *mdc_link_pack(struct lustre_msg *msg, int offset,
567 struct mdc_op_data *data)
569 struct mds_rec_link *rec;
572 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
574 rec->lk_opcode = REINT_LINK;
575 rec->lk_id1 = data->id1;
576 rec->lk_id2 = data->id2;
577 rec->lk_time = data->mod_time;
579 tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
580 LOGL0(data->name, data->namelen, tmp);
585 void *mdc_rename_pack(struct lustre_msg *msg, int offset,
586 struct mdc_op_data *data,
587 const char *old, int oldlen,
588 const char *new, int newlen)
590 struct mds_rec_rename *rec;
593 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
595 /* XXX do something about time, uid, gid */
596 rec->rn_opcode = REINT_RENAME;
597 rec->rn_id1 = data->id1;
598 rec->rn_id2 = data->id2;
599 rec->rn_time = data->mod_time;
601 tmp = lustre_msg_buf(msg, offset + 1, oldlen + 1);
602 LOGL0(old, oldlen, tmp);
605 tmp = lustre_msg_buf(msg, offset + 2, newlen + 1);
606 LOGL0(new, newlen, tmp);
611 void lustre_swab_obd_statfs(struct obd_statfs *os)
613 __swab64s(&os->os_type);
614 __swab64s(&os->os_blocks);
615 __swab64s(&os->os_bfree);
616 __swab64s(&os->os_bavail);
617 __swab64s(&os->os_ffree);
618 /* no need to swap os_fsid */
619 __swab32s(&os->os_bsize);
620 __swab32s(&os->os_namelen);
621 /* no need to swap os_spare */
624 void lustre_swab_obd_ioobj(struct obd_ioobj *ioo)
626 __swab64s(&ioo->ioo_id);
627 __swab64s(&ioo->ioo_gr);
628 __swab32s(&ioo->ioo_type);
629 __swab32s(&ioo->ioo_bufcnt);
632 void lustre_swab_niobuf_remote(struct niobuf_remote *nbr)
634 __swab64s(&nbr->offset);
635 __swab32s(&nbr->len);
636 __swab32s(&nbr->flags);
639 void lustre_swab_ost_body(struct ost_body *b)
641 lustre_swab_obdo(&b->oa);
644 void lustre_swab_ost_last_id(obd_id *id)
649 void lustre_swab_generic_32s(__u32 *val)
654 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
656 __swab64s(&lvb->lvb_size);
657 __swab64s(&lvb->lvb_mtime);
658 __swab64s(&lvb->lvb_atime);
659 __swab64s(&lvb->lvb_ctime);
660 __swab64s(&lvb->lvb_blocks);
663 void lustre_swab_lustre_stc (struct lustre_stc *stc)
665 __swab64s(&stc->u.e3s.l3s_ino);
666 __swab32s(&stc->u.e3s.l3s_gen);
667 __swab32s(&stc->u.e3s.l3s_type);
670 void lustre_swab_lustre_fid(struct lustre_fid *fid)
672 __swab64s(&fid->lf_id);
673 __swab64s(&fid->lf_group);
674 /*__swab32s (&fid->lf_version);*/
677 void lustre_swab_lustre_id(struct lustre_id *id)
679 lustre_swab_lustre_stc(&id->li_stc);
680 lustre_swab_lustre_fid(&id->li_fid);
683 void lustre_swab_mds_status_req(struct mds_status_req *r)
685 __swab32s(&r->flags);
686 __swab32s(&r->repbuf);
690 * because sec_desc is variable buffer, we must check it by hand
692 struct mds_req_sec_desc *lustre_swab_mds_secdesc(struct ptlrpc_request *req,
695 struct mds_req_sec_desc *rsd;
696 struct lustre_msg *m;
699 LASSERT_REQSWAB(req, offset);
702 rsd = lustre_msg_buf(m, offset, sizeof(*rsd));
706 if (lustre_msg_swabbed(m)) {
707 __swab32s(&rsd->rsd_uid);
708 __swab32s(&rsd->rsd_gid);
709 __swab32s(&rsd->rsd_fsuid);
710 __swab32s(&rsd->rsd_fsgid);
711 __swab32s(&rsd->rsd_cap);
712 __swab32s(&rsd->rsd_ngroups);
715 if (rsd->rsd_ngroups > LUSTRE_MAX_GROUPS) {
716 CERROR("%u groups is not allowed\n", rsd->rsd_ngroups);
720 if (m->buflens[offset] !=
721 sizeof(*rsd) + rsd->rsd_ngroups * sizeof(__u32)) {
722 CERROR("bufflen %u while contains %u groups\n",
723 m->buflens[offset], rsd->rsd_ngroups);
727 if (lustre_msg_swabbed(m)) {
728 for (i = 0; i < rsd->rsd_ngroups; i++)
729 __swab32s(&rsd->rsd_groups[i]);
735 void lustre_swab_mds_body(struct mds_body *b)
737 lustre_swab_lustre_id(&b->id1);
738 lustre_swab_lustre_id(&b->id2);
739 /* handle is opaque */
741 __swab64s(&b->blocks);
742 __swab64s(&b->valid);
746 __swab32s(&b->mtime);
747 __swab32s(&b->ctime);
748 __swab32s(&b->atime);
749 __swab32s(&b->flags);
751 __swab32s(&b->nlink);
752 __swab32s(&b->eadatasize);
754 void lustre_swab_mds_rec_setattr(struct mds_rec_setattr *sa)
756 __swab32s(&sa->sa_opcode);
757 __swab32s(&sa->sa_valid);
758 lustre_swab_lustre_id(&sa->sa_id);
759 __swab32s(&sa->sa_mode);
760 __swab32s(&sa->sa_uid);
761 __swab32s(&sa->sa_gid);
762 __swab32s(&sa->sa_attr_flags);
763 __swab64s(&sa->sa_size);
764 __swab64s(&sa->sa_atime);
765 __swab64s(&sa->sa_mtime);
766 __swab64s(&sa->sa_ctime);
769 void lustre_swab_mds_rec_create(struct mds_rec_create *cr)
771 __swab32s(&cr->cr_opcode);
772 __swab32s(&cr->cr_flags); /* for use with open */
773 __swab32s(&cr->cr_mode);
774 lustre_swab_lustre_id(&cr->cr_id);
775 lustre_swab_lustre_id(&cr->cr_replayid);
776 __swab64s(&cr->cr_time);
777 __swab64s(&cr->cr_rdev);
780 void lustre_swab_mds_rec_link(struct mds_rec_link *lk)
782 __swab32s(&lk->lk_opcode);
783 lustre_swab_lustre_id(&lk->lk_id1);
784 lustre_swab_lustre_id(&lk->lk_id2);
787 void lustre_swab_mds_rec_unlink(struct mds_rec_unlink *ul)
789 __swab32s(&ul->ul_opcode);
790 __swab32s(&ul->ul_mode);
791 lustre_swab_lustre_id(&ul->ul_id1);
792 lustre_swab_lustre_id(&ul->ul_id2);
795 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
797 __swab32s(&rn->rn_opcode);
798 lustre_swab_lustre_id(&rn->rn_id1);
799 lustre_swab_lustre_id(&rn->rn_id2);
802 void lustre_swab_lov_desc(struct lov_desc *ld)
804 __swab32s(&ld->ld_tgt_count);
805 __swab32s(&ld->ld_active_tgt_count);
806 __swab32s(&ld->ld_default_stripe_count);
807 __swab64s(&ld->ld_default_stripe_size);
808 __swab64s(&ld->ld_default_stripe_offset);
809 __swab32s(&ld->ld_pattern);
810 /* uuid endian insensitive */
813 void lustre_swab_ldlm_res_id(struct ldlm_res_id *id)
817 for (i = 0; i < RES_NAME_SIZE; i++)
818 __swab64s(&id->name[i]);
821 void lustre_swab_ldlm_policy_data(ldlm_policy_data_t *d)
823 /* the lock data is a union and the first three fields of both EXTENT
824 * and FLOCK types are __u64, so it's ok to swab them in the same way */
825 __swab64s(&d->l_flock.start);
826 __swab64s(&d->l_flock.end);
827 __swab64s(&d->l_flock.pid);
828 __swab64s(&d->l_flock.blocking_pid);
831 void lustre_swab_ldlm_intent(struct ldlm_intent *i)
836 void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r)
838 __swab32s(&r->lr_type);
839 lustre_swab_ldlm_res_id(&r->lr_name);
842 void lustre_swab_ldlm_lock_desc(struct ldlm_lock_desc *l)
844 lustre_swab_ldlm_resource_desc(&l->l_resource);
845 __swab32s(&l->l_req_mode);
846 __swab32s(&l->l_granted_mode);
847 lustre_swab_ldlm_policy_data(&l->l_policy_data);
850 void lustre_swab_ldlm_request(struct ldlm_request *rq)
852 __swab32s(&rq->lock_flags);
853 lustre_swab_ldlm_lock_desc(&rq->lock_desc);
854 /* lock_handle1 opaque */
855 /* lock_handle2 opaque */
858 void lustre_swab_ldlm_reply(struct ldlm_reply *r)
860 __swab32s(&r->lock_flags);
861 lustre_swab_ldlm_lock_desc(&r->lock_desc);
862 /* lock_handle opaque */
863 __swab64s(&r->lock_policy_res1);
864 __swab64s(&r->lock_policy_res2);
867 void lustre_swab_ptlbd_op(struct ptlbd_op *op)
869 __swab16s(&op->op_cmd);
870 __swab16s(&op->op_lun);
871 __swab16s(&op->op_niob_cnt);
872 /* ignore op__padding */
873 __swab32s(&op->op_block_cnt);
876 void lustre_swab_ptlbd_niob(struct ptlbd_niob *n)
878 __swab64s(&n->n_xid);
879 __swab64s(&n->n_block_nr);
880 __swab32s(&n->n_offset);
881 __swab32s(&n->n_length);
884 void lustre_swab_ptlbd_rsp(struct ptlbd_rsp *r)
886 __swab16s(&r->r_status);
887 __swab16s(&r->r_error_cnt);
890 void lustre_swab_remote_perm(struct mds_remote_perm *p)
892 __swab32s(&p->mrp_auth_uid);
893 __swab32s(&p->mrp_auth_gid);
894 __swab16s(&p->mrp_perm);
897 /* no one calls this */
898 int llog_log_swabbed(struct llog_log_hdr *hdr)
900 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
902 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
907 void lustre_assert_wire_constants(void)
910 /* for gks key rec */
911 void lustre_swab_key_perms(struct key_perm *kperm)
914 __swab32s(&kperm->kp_uid);
915 __swab32s(&kperm->kp_gid);
916 __swab32s(&kperm->kp_mode);
917 __swab32s(&kperm->kp_acl_count);
918 for (i = 0; i < kperm->kp_acl_count; i++) {
919 __swab16s(&kperm->kp_acls[i].e_tag);
920 __swab16s(&kperm->kp_acls[i].e_perm);
921 __swab32s(&kperm->kp_acls[i].e_id);
924 void lustre_swab_key_context (struct key_context *kctxt)
926 __swab32s (&kctxt->kc_command);
927 __swab32s (&kctxt->kc_valid); /* for use with open */
928 lustre_swab_key_perms(&kctxt->kc_perm);