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/lustre_audit.h>
38 #include <linux/fcntl.h>
39 #include <linux/posix_acl.h>
42 #define HDR_SIZE(count) \
43 size_round(offsetof (struct lustre_msg, buflens[(count)]))
45 int lustre_msg_swabbed(struct lustre_msg *msg)
47 return (msg->magic == __swab32(PTLRPC_MSG_MAGIC));
50 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
52 if (!lustre_msg_swabbed(msg))
53 return (msg->version & LUSTRE_VERSION_MASK) != version;
55 return (__swab32(msg->version) & LUSTRE_VERSION_MASK) != version;
58 void lustre_init_msg(struct lustre_msg *msg, int count,
59 int *lens, char **bufs)
64 msg->magic = PTLRPC_MSG_MAGIC;
65 msg->version = PTLRPC_MSG_VERSION;
66 msg->bufcount = count;
67 for (i = 0; i < count; i++)
68 msg->buflens[i] = lens[i];
73 ptr = (char *)msg + HDR_SIZE(count);
74 for (i = 0; i < count; i++) {
76 LOGL(tmp, lens[i], ptr);
80 int lustre_secdesc_size(void)
83 int ngroups = current_ngroups;
85 if (ngroups > LUSTRE_MAX_GROUPS)
86 ngroups = LUSTRE_MAX_GROUPS;
88 return sizeof(struct mds_req_sec_desc) +
89 sizeof(__u32) * ngroups;
96 * because group info might have changed since last time we call
97 * secdesc_size(), so here we did more sanity check to prevent garbage gids
99 void lustre_pack_secdesc(struct ptlrpc_request *req, int size)
102 struct mds_req_sec_desc *rsd;
104 rsd = lustre_msg_buf(req->rq_reqmsg,
105 MDS_REQ_SECDESC_OFF, size);
107 rsd->rsd_uid = current->uid;
108 rsd->rsd_gid = current->gid;
109 rsd->rsd_fsuid = current->fsuid;
110 rsd->rsd_fsgid = current->fsgid;
111 rsd->rsd_cap = current->cap_effective;
112 rsd->rsd_ngroups = (size - sizeof(*rsd)) / sizeof(__u32);
113 LASSERT(rsd->rsd_ngroups <= LUSTRE_MAX_GROUPS);
115 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
117 if (rsd->rsd_ngroups > current->group_info->ngroups)
118 rsd->rsd_ngroups = current->group_info->ngroups;
119 memcpy(rsd->rsd_groups, current->group_info->blocks[0],
120 rsd->rsd_ngroups * sizeof(__u32));
121 task_unlock(current);
123 LASSERT(rsd->rsd_ngroups <= NGROUPS);
124 if (rsd->rsd_ngroups > current->ngroups)
125 rsd->rsd_ngroups = current->ngroups;
126 memcpy(rsd->rsd_groups, current->groups,
127 rsd->rsd_ngroups * sizeof(__u32));
132 int lustre_pack_request(struct ptlrpc_request *req,
133 int count, int *lens, char **bufs)
138 req->rq_reqlen = lustre_msg_size(count, lens);
139 rc = ptlrpcs_cli_alloc_reqbuf(req, req->rq_reqlen);
143 lustre_init_msg(req->rq_reqmsg, count, lens, bufs);
148 LIST_HEAD(ptlrpc_rs_debug_lru);
149 spinlock_t ptlrpc_rs_debug_lock = SPIN_LOCK_UNLOCKED;
151 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
153 unsigned long __flags; \
155 spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags); \
156 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
157 spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags); \
160 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
162 unsigned long __flags; \
164 spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags); \
165 list_del(&(rs)->rs_debug_list); \
166 spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags); \
169 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
170 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
173 int lustre_pack_reply(struct ptlrpc_request *req,
174 int count, int *lens, char **bufs)
176 struct ptlrpc_reply_state *rs;
180 LASSERT(req->rq_reply_state == NULL);
181 LASSERT(req->rq_svcsec);
182 LASSERT(req->rq_repmsg == NULL);
184 req->rq_replen = lustre_msg_size(count, lens);
185 rc = svcsec_alloc_repbuf(req->rq_svcsec, req, req->rq_replen);
188 LASSERT(req->rq_reply_state);
189 LASSERT(req->rq_repmsg == req->rq_reply_state->rs_msg);
191 rs = req->rq_reply_state;
192 rs->rs_svcsec = svcsec_get(req->rq_svcsec);
193 rs->rs_cb_id.cbid_fn = reply_out_callback;
194 rs->rs_cb_id.cbid_arg = rs;
195 rs->rs_srv_ni = req->rq_rqbd->rqbd_srv_ni;
196 INIT_LIST_HEAD(&rs->rs_exp_list);
197 INIT_LIST_HEAD(&rs->rs_obd_list);
199 lustre_init_msg(rs->rs_msg, count, lens, bufs);
201 PTLRPC_RS_DEBUG_LRU_ADD(rs);
206 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
208 struct ptlrpc_svcsec *svcsec = rs->rs_svcsec;
210 PTLRPC_RS_DEBUG_LRU_DEL(rs);
212 LASSERT(!rs->rs_difficult || rs->rs_handled);
213 LASSERT(!rs->rs_on_net);
214 LASSERT(!rs->rs_scheduled);
215 LASSERT(rs->rs_export == NULL);
216 LASSERT(rs->rs_nlocks == 0);
217 LASSERT(list_empty(&rs->rs_exp_list));
218 LASSERT(list_empty(&rs->rs_obd_list));
221 if (svcsec->free_repbuf)
222 svcsec->free_repbuf(svcsec, rs);
224 svcsec_free_reply_state(rs);
229 /* This returns the size of the buffer that is required to hold a lustre_msg
230 * with the given sub-buffer lengths. */
231 int lustre_msg_size(int count, int *lengths)
236 size = HDR_SIZE (count);
237 for (i = 0; i < count; i++)
238 size += size_round(lengths[i]);
243 int lustre_unpack_msg(struct lustre_msg *m, int len)
250 /* We can provide a slightly better error log, if we check the
251 * message magic and version first. In the future, struct
252 * lustre_msg may grow, and we'd like to log a version mismatch,
253 * rather than a short message.
256 required_len = MAX(offsetof(struct lustre_msg, version) +
258 offsetof(struct lustre_msg, magic) +
260 if (len < required_len) {
261 /* can't even look inside the message */
262 CERROR ("message length %d too small for magic/version check\n",
267 flipped = lustre_msg_swabbed(m);
269 __swab32s(&m->version);
270 else if (m->magic != PTLRPC_MSG_MAGIC) {
271 CERROR("wrong lustre_msg magic %#08x\n", m->magic);
275 if ((m->version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
276 CERROR("wrong lustre_msg version %#08x\n", m->version);
280 /* Now we know the sender speaks my language (but possibly flipped)...*/
281 required_len = HDR_SIZE(0);
282 if (len < required_len) {
283 /* can't even look inside the message */
284 CERROR("message length %d too small for lustre_msg\n", len);
291 __swab64s(&m->last_xid);
292 __swab64s(&m->last_committed);
293 __swab64s(&m->transno);
294 __swab32s(&m->status);
295 __swab32s(&m->bufcount);
296 __swab32s(&m->flags);
299 required_len = HDR_SIZE(m->bufcount);
301 if (len < required_len) {
302 /* didn't receive all the buffer lengths */
303 CERROR ("message length %d too small for %d buflens\n",
308 for (i = 0; i < m->bufcount; i++) {
310 __swab32s (&m->buflens[i]);
311 required_len += size_round(m->buflens[i]);
314 if (len < required_len) {
315 CERROR("len: %d, required_len %d\n", len, required_len);
316 CERROR("bufcount: %d\n", m->bufcount);
317 for (i = 0; i < m->bufcount; i++)
318 CERROR("buffer %d length %d\n", i, m->buflens[i]);
325 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
335 bufcount = m->bufcount;
337 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
342 buflen = m->buflens[n];
343 if (buflen < min_size) {
344 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
345 m, n, buflen, min_size);
349 offset = HDR_SIZE(bufcount);
350 for (i = 0; i < n; i++)
351 offset += size_round(m->buflens[i]);
353 return (char *)m + offset;
356 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
358 /* max_len == 0 means the string should fill the buffer */
359 char *str = lustre_msg_buf(m, index, 0);
364 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
368 blen = m->buflens[index];
369 slen = strnlen(str, blen);
371 if (slen == blen) { /* not NULL terminated */
372 CERROR ("can't unpack non-NULL terminated string in "
373 "msg %p buffer[%d] len %d\n", m, index, blen);
378 if (slen != blen - 1) {
379 CERROR ("can't unpack short string in msg %p "
380 "buffer[%d] len %d: strlen %d\n",
381 m, index, blen, slen);
384 } else if (slen > max_len) {
385 CERROR ("can't unpack oversized string in msg %p "
386 "buffer[%d] len %d strlen %d: max %d expected\n",
387 m, index, blen, slen, max_len);
394 /* Wrap up the normal fixed length cases */
395 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
400 ptr = lustre_msg_buf(msg, index, min_size);
404 if (swabber != NULL && lustre_msg_swabbed(msg))
405 ((void (*)(void *))swabber)(ptr);
410 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
413 LASSERT_REQSWAB(req, index);
414 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
417 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
420 LASSERT_REPSWAB(req, index);
421 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
424 /* byte flipping routines for all wire types declared in
425 * lustre_idl.h implemented here.
428 void lustre_swab_connect(struct obd_connect_data *ocd)
430 __swab64s(&ocd->ocd_connect_flags);
431 __swab32s(&ocd->ocd_nllu[0]);
432 __swab32s(&ocd->ocd_nllu[1]);
435 void lustre_swab_obdo(struct obdo *o)
439 __swab64s(&o->o_atime);
440 __swab64s(&o->o_mtime);
441 __swab64s(&o->o_ctime);
442 __swab64s(&o->o_size);
443 __swab64s(&o->o_blocks);
444 __swab64s(&o->o_grant);
445 __swab32s(&o->o_blksize);
446 __swab32s(&o->o_mode);
447 __swab32s(&o->o_uid);
448 __swab32s(&o->o_gid);
449 __swab32s(&o->o_flags);
450 __swab32s(&o->o_nlink);
451 __swab32s(&o->o_generation);
452 __swab64s(&o->o_valid);
453 __swab32s(&o->o_misc);
454 __swab32s(&o->o_easize);
455 __swab32s(&o->o_mds);
456 __swab64s(&o->o_fid);
457 /* o_inline is opaque */
460 /* mdc pack methods used by mdc and smfs*/
461 void *mdc_create_pack(struct lustre_msg *msg, int offset,
462 struct mdc_op_data *op_data, __u32 mode,
463 __u64 rdev, const void *data, int datalen)
465 struct mds_rec_create *rec;
467 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
469 rec->cr_opcode = REINT_CREATE;
470 rec->cr_id = op_data->id1;
471 memset(&rec->cr_replayid, 0, sizeof(rec->cr_replayid));
474 rec->cr_time = op_data->mod_time;
476 tmp = lustre_msg_buf(msg, offset + 1, op_data->namelen + 1);
477 LOGL0(op_data->name, op_data->namelen, tmp);
480 tmp = lustre_msg_buf(msg, offset + 2, datalen);
481 memcpy (tmp, data, datalen);
483 return ((void*)tmp + size_round(datalen));
486 __u32 mds_pack_open_flags(__u32 flags)
489 (flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC |
490 MDS_OPEN_DELAY_CREATE | MDS_OPEN_HAS_EA |
491 MDS_OPEN_HAS_OBJS)) |
492 ((flags & O_CREAT) ? MDS_OPEN_CREAT : 0) |
493 ((flags & O_EXCL) ? MDS_OPEN_EXCL : 0) |
494 ((flags & O_TRUNC) ? MDS_OPEN_TRUNC : 0) |
495 ((flags & O_APPEND) ? MDS_OPEN_APPEND : 0) |
496 ((flags & O_SYNC) ? MDS_OPEN_SYNC : 0) |
497 ((flags & O_DIRECTORY) ? MDS_OPEN_DIRECTORY : 0) |
501 void *mdc_setattr_pack(struct lustre_msg *msg, int offset,
502 struct mdc_op_data *data, struct iattr *iattr,
503 void *ea, int ealen, void *ea2, int ea2len,
504 void *ea3, int ea3len)
506 struct mds_rec_setattr *rec = lustre_msg_buf(msg, offset, sizeof(*rec));
509 rec->sa_opcode = REINT_SETATTR;
510 rec->sa_id = data->id1;
513 rec->sa_valid = iattr->ia_valid;
514 rec->sa_mode = iattr->ia_mode;
515 rec->sa_uid = iattr->ia_uid;
516 rec->sa_gid = iattr->ia_gid;
517 rec->sa_size = iattr->ia_size;
518 rec->sa_atime = LTIME_S(iattr->ia_atime);
519 rec->sa_mtime = LTIME_S(iattr->ia_mtime);
520 rec->sa_ctime = LTIME_S(iattr->ia_ctime);
521 rec->sa_attr_flags = iattr->ia_attr_flags;
523 tmp = (char*)rec + size_round(sizeof(*rec));
528 memcpy(lustre_msg_buf(msg, offset + 1, ealen), ea, ealen);
529 tmp += size_round(ealen);
534 memcpy(lustre_msg_buf(msg, offset + 2, ea2len), ea2, ea2len);
535 tmp += size_round(ea2len);
540 memcpy(lustre_msg_buf(msg, offset + 3, ea3len), ea3, ea3len);
541 tmp += size_round(ea3len);
546 void *mdc_unlink_pack(struct lustre_msg *msg, int offset,
547 struct mdc_op_data *data)
549 struct mds_rec_unlink *rec;
552 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
553 LASSERT (rec != NULL);
555 rec->ul_opcode = REINT_UNLINK;
556 rec->ul_mode = data->create_mode;
557 rec->ul_id1 = data->id1;
558 rec->ul_id2 = data->id2;
559 rec->ul_time = data->mod_time;
561 tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
562 LASSERT (tmp != NULL);
563 LOGL0(data->name, data->namelen, tmp);
567 void *mdc_link_pack(struct lustre_msg *msg, int offset,
568 struct mdc_op_data *data)
570 struct mds_rec_link *rec;
573 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
575 rec->lk_opcode = REINT_LINK;
576 rec->lk_id1 = data->id1;
577 rec->lk_id2 = data->id2;
578 rec->lk_time = data->mod_time;
580 tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
581 LOGL0(data->name, data->namelen, tmp);
586 void *mdc_rename_pack(struct lustre_msg *msg, int offset,
587 struct mdc_op_data *data,
588 const char *old, int oldlen,
589 const char *new, int newlen)
591 struct mds_rec_rename *rec;
594 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
596 /* XXX do something about time, uid, gid */
597 rec->rn_opcode = REINT_RENAME;
598 rec->rn_id1 = data->id1;
599 rec->rn_id2 = data->id2;
600 rec->rn_time = data->mod_time;
602 tmp = lustre_msg_buf(msg, offset + 1, oldlen + 1);
603 LOGL0(old, oldlen, tmp);
606 tmp = lustre_msg_buf(msg, offset + 2, newlen + 1);
607 LOGL0(new, newlen, tmp);
612 void lustre_swab_obd_statfs(struct obd_statfs *os)
614 __swab64s(&os->os_type);
615 __swab64s(&os->os_blocks);
616 __swab64s(&os->os_bfree);
617 __swab64s(&os->os_bavail);
618 __swab64s(&os->os_ffree);
619 /* no need to swap os_fsid */
620 __swab32s(&os->os_bsize);
621 __swab32s(&os->os_namelen);
622 /* no need to swap os_spare */
625 void lustre_swab_obd_ioobj(struct obd_ioobj *ioo)
627 __swab64s(&ioo->ioo_id);
628 __swab64s(&ioo->ioo_gr);
629 __swab32s(&ioo->ioo_type);
630 __swab32s(&ioo->ioo_bufcnt);
633 void lustre_swab_niobuf_remote(struct niobuf_remote *nbr)
635 __swab64s(&nbr->offset);
636 __swab32s(&nbr->len);
637 __swab32s(&nbr->flags);
640 void lustre_swab_ost_body(struct ost_body *b)
642 lustre_swab_obdo(&b->oa);
645 void lustre_swab_ost_last_id(obd_id *id)
650 void lustre_swab_generic_32s(__u32 *val)
655 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
657 __swab64s(&lvb->lvb_size);
658 __swab64s(&lvb->lvb_mtime);
659 __swab64s(&lvb->lvb_atime);
660 __swab64s(&lvb->lvb_ctime);
661 __swab64s(&lvb->lvb_blocks);
664 void lustre_swab_lustre_stc (struct lustre_stc *stc)
666 __swab64s(&stc->u.e3s.l3s_ino);
667 __swab32s(&stc->u.e3s.l3s_gen);
668 __swab32s(&stc->u.e3s.l3s_type);
671 void lustre_swab_lustre_fid(struct lustre_fid *fid)
673 __swab64s(&fid->lf_id);
674 __swab64s(&fid->lf_group);
675 /*__swab32s (&fid->lf_version);*/
678 void lustre_swab_lustre_id(struct lustre_id *id)
680 lustre_swab_lustre_stc(&id->li_stc);
681 lustre_swab_lustre_fid(&id->li_fid);
684 void lustre_swab_parseid_pkg (struct parseid_pkg *pkg)
686 __swab32s(&pkg->pp_type);
687 __swab32s(&pkg->pp_rc);
688 lustre_swab_lustre_id(&pkg->pp_id1);
689 lustre_swab_lustre_id(&pkg->pp_id2);
692 void lustre_swab_mds_status_req(struct mds_status_req *r)
694 __swab32s(&r->flags);
695 __swab32s(&r->repbuf);
699 * because sec_desc is variable buffer, we must check it by hand
701 struct mds_req_sec_desc *lustre_swab_mds_secdesc(struct ptlrpc_request *req,
704 struct mds_req_sec_desc *rsd;
705 struct lustre_msg *m;
708 LASSERT_REQSWAB(req, offset);
711 rsd = lustre_msg_buf(m, offset, sizeof(*rsd));
715 if (lustre_msg_swabbed(m)) {
716 __swab32s(&rsd->rsd_uid);
717 __swab32s(&rsd->rsd_gid);
718 __swab32s(&rsd->rsd_fsuid);
719 __swab32s(&rsd->rsd_fsgid);
720 __swab32s(&rsd->rsd_cap);
721 __swab32s(&rsd->rsd_ngroups);
724 if (rsd->rsd_ngroups > LUSTRE_MAX_GROUPS) {
725 CERROR("%u groups is not allowed\n", rsd->rsd_ngroups);
729 if (m->buflens[offset] !=
730 sizeof(*rsd) + rsd->rsd_ngroups * sizeof(__u32)) {
731 CERROR("bufflen %u while contains %u groups\n",
732 m->buflens[offset], rsd->rsd_ngroups);
736 if (lustre_msg_swabbed(m)) {
737 for (i = 0; i < rsd->rsd_ngroups; i++)
738 __swab32s(&rsd->rsd_groups[i]);
744 void lustre_swab_mds_body(struct mds_body *b)
746 lustre_swab_lustre_id(&b->id1);
747 lustre_swab_lustre_id(&b->id2);
748 /* handle is opaque */
750 __swab64s(&b->blocks);
751 __swab64s(&b->valid);
752 __swab64s (&b->audit);
756 __swab32s(&b->mtime);
757 __swab32s(&b->ctime);
758 __swab32s(&b->atime);
759 __swab32s(&b->flags);
761 __swab32s(&b->nlink);
762 __swab32s(&b->eadatasize);
764 void lustre_swab_mds_rec_setattr(struct mds_rec_setattr *sa)
766 __swab32s(&sa->sa_opcode);
767 __swab32s(&sa->sa_valid);
768 lustre_swab_lustre_id(&sa->sa_id);
769 __swab32s(&sa->sa_mode);
770 __swab32s(&sa->sa_uid);
771 __swab32s(&sa->sa_gid);
772 __swab32s(&sa->sa_attr_flags);
773 __swab64s(&sa->sa_size);
774 __swab64s(&sa->sa_atime);
775 __swab64s(&sa->sa_mtime);
776 __swab64s(&sa->sa_ctime);
779 void lustre_swab_mds_rec_create(struct mds_rec_create *cr)
781 __swab32s(&cr->cr_opcode);
782 __swab32s(&cr->cr_flags); /* for use with open */
783 __swab32s(&cr->cr_mode);
784 lustre_swab_lustre_id(&cr->cr_id);
785 lustre_swab_lustre_id(&cr->cr_replayid);
786 __swab64s(&cr->cr_time);
787 __swab64s(&cr->cr_rdev);
790 void lustre_swab_mds_rec_link(struct mds_rec_link *lk)
792 __swab32s(&lk->lk_opcode);
793 lustre_swab_lustre_id(&lk->lk_id1);
794 lustre_swab_lustre_id(&lk->lk_id2);
797 void lustre_swab_mds_rec_unlink(struct mds_rec_unlink *ul)
799 __swab32s(&ul->ul_opcode);
800 __swab32s(&ul->ul_mode);
801 lustre_swab_lustre_id(&ul->ul_id1);
802 lustre_swab_lustre_id(&ul->ul_id2);
805 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
807 __swab32s(&rn->rn_opcode);
808 lustre_swab_lustre_id(&rn->rn_id1);
809 lustre_swab_lustre_id(&rn->rn_id2);
812 void lustre_swab_lov_desc(struct lov_desc *ld)
814 __swab32s(&ld->ld_tgt_count);
815 __swab32s(&ld->ld_active_tgt_count);
816 __swab32s(&ld->ld_default_stripe_count);
817 __swab64s(&ld->ld_default_stripe_size);
818 __swab64s(&ld->ld_default_stripe_offset);
819 __swab32s(&ld->ld_pattern);
820 /* uuid endian insensitive */
823 void lustre_swab_ldlm_res_id(struct ldlm_res_id *id)
827 for (i = 0; i < RES_NAME_SIZE; i++)
828 __swab64s(&id->name[i]);
831 void lustre_swab_ldlm_policy_data(ldlm_policy_data_t *d)
833 /* the lock data is a union and the first three fields of both EXTENT
834 * and FLOCK types are __u64, so it's ok to swab them in the same way */
835 __swab64s(&d->l_flock.start);
836 __swab64s(&d->l_flock.end);
837 __swab64s(&d->l_flock.pid);
838 __swab64s(&d->l_flock.blocking_pid);
841 void lustre_swab_ldlm_intent(struct ldlm_intent *i)
846 void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r)
848 __swab32s(&r->lr_type);
849 lustre_swab_ldlm_res_id(&r->lr_name);
852 void lustre_swab_ldlm_lock_desc(struct ldlm_lock_desc *l)
854 lustre_swab_ldlm_resource_desc(&l->l_resource);
855 __swab32s(&l->l_req_mode);
856 __swab32s(&l->l_granted_mode);
857 lustre_swab_ldlm_policy_data(&l->l_policy_data);
860 void lustre_swab_ldlm_request(struct ldlm_request *rq)
862 __swab32s(&rq->lock_flags);
863 lustre_swab_ldlm_lock_desc(&rq->lock_desc);
864 /* lock_handle1 opaque */
865 /* lock_handle2 opaque */
868 void lustre_swab_ldlm_reply(struct ldlm_reply *r)
870 __swab32s(&r->lock_flags);
871 lustre_swab_ldlm_lock_desc(&r->lock_desc);
872 /* lock_handle opaque */
873 __swab64s(&r->lock_policy_res1);
874 __swab64s(&r->lock_policy_res2);
877 void lustre_swab_ptlbd_op(struct ptlbd_op *op)
879 __swab16s(&op->op_cmd);
880 __swab16s(&op->op_lun);
881 __swab16s(&op->op_niob_cnt);
882 /* ignore op__padding */
883 __swab32s(&op->op_block_cnt);
886 void lustre_swab_ptlbd_niob(struct ptlbd_niob *n)
888 __swab64s(&n->n_xid);
889 __swab64s(&n->n_block_nr);
890 __swab32s(&n->n_offset);
891 __swab32s(&n->n_length);
894 void lustre_swab_ptlbd_rsp(struct ptlbd_rsp *r)
896 __swab16s(&r->r_status);
897 __swab16s(&r->r_error_cnt);
900 void lustre_swab_remote_perm(struct mds_remote_perm *p)
902 __swab32s(&p->mrp_auth_uid);
903 __swab32s(&p->mrp_auth_gid);
904 __swab16s(&p->mrp_perm);
907 void lustre_swab_audit_msg (struct audit_msg *r)
909 lustre_swab_lustre_id(&r->id);
910 __swab32s (&r->code);
911 __swab32s (&r->result);
917 void lustre_swab_audit_attr (struct audit_attr_msg *r)
919 lustre_swab_lustre_id(&r->id);
920 __swab64s (&r->attr);
923 /* no one calls this */
924 int llog_log_swabbed(struct llog_log_hdr *hdr)
926 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
928 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
933 void lustre_assert_wire_constants(void)
936 /* for gks key rec */
937 void lustre_swab_key_perms(struct key_perm *kperm)
940 __swab32s(&kperm->kp_uid);
941 __swab32s(&kperm->kp_gid);
942 __swab32s(&kperm->kp_mode);
943 __swab32s(&kperm->kp_acl_count);
944 for (i = 0; i < kperm->kp_acl_count; i++) {
945 __swab16s(&kperm->kp_acls[i].e_tag);
946 __swab16s(&kperm->kp_acls[i].e_perm);
947 __swab32s(&kperm->kp_acls[i].e_id);
950 void lustre_swab_key_context (struct key_context *kctxt)
952 __swab32s (&kctxt->kc_command);
953 __swab32s (&kctxt->kc_valid); /* for use with open */
954 lustre_swab_key_perms(&kctxt->kc_perm);