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>
40 #define HDR_SIZE(count) \
41 size_round(offsetof (struct lustre_msg, buflens[(count)]))
43 int lustre_msg_swabbed(struct lustre_msg *msg)
45 return (msg->magic == __swab32(PTLRPC_MSG_MAGIC));
48 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
50 if (!lustre_msg_swabbed(msg))
51 return (msg->version & LUSTRE_VERSION_MASK) != version;
53 return (__swab32(msg->version) & LUSTRE_VERSION_MASK) != version;
56 void lustre_init_msg(struct lustre_msg *msg, int count,
57 int *lens, char **bufs)
62 msg->magic = PTLRPC_MSG_MAGIC;
63 msg->version = PTLRPC_MSG_VERSION;
64 msg->bufcount = count;
65 for (i = 0; i < count; i++)
66 msg->buflens[i] = lens[i];
71 ptr = (char *)msg + HDR_SIZE(count);
72 for (i = 0; i < count; i++) {
74 LOGL(tmp, lens[i], ptr);
78 int lustre_secdesc_size(void)
81 int ngroups = current_ngroups;
83 if (ngroups > LUSTRE_MAX_GROUPS)
84 ngroups = LUSTRE_MAX_GROUPS;
86 return sizeof(struct mds_req_sec_desc) +
87 sizeof(__u32) * ngroups;
94 * because group info might have changed since last time we call
95 * secdesc_size(), so here we did more sanity check to prevent garbage gids
97 void lustre_pack_secdesc(struct ptlrpc_request *req, int size)
100 struct mds_req_sec_desc *rsd;
102 rsd = lustre_msg_buf(req->rq_reqmsg,
103 MDS_REQ_SECDESC_OFF, size);
105 rsd->rsd_uid = current->uid;
106 rsd->rsd_gid = current->gid;
107 rsd->rsd_fsuid = current->fsuid;
108 rsd->rsd_fsgid = current->fsgid;
109 rsd->rsd_cap = current->cap_effective;
110 rsd->rsd_ngroups = (size - sizeof(*rsd)) / sizeof(__u32);
111 LASSERT(rsd->rsd_ngroups <= LUSTRE_MAX_GROUPS);
113 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
115 if (rsd->rsd_ngroups > current->group_info->ngroups)
116 rsd->rsd_ngroups = current->group_info->ngroups;
117 memcpy(rsd->rsd_groups, current->group_info->blocks[0],
118 rsd->rsd_ngroups * sizeof(__u32));
119 task_unlock(current);
121 LASSERT(rsd->rsd_ngroups <= NGROUPS);
122 if (rsd->rsd_ngroups > current->ngroups)
123 rsd->rsd_ngroups = current->ngroups;
124 memcpy(rsd->rsd_groups, current->groups,
125 rsd->rsd_ngroups * sizeof(__u32));
130 int lustre_pack_request(struct ptlrpc_request *req,
131 int count, int *lens, char **bufs)
136 req->rq_reqlen = lustre_msg_size(count, lens);
137 rc = ptlrpcs_cli_alloc_reqbuf(req, req->rq_reqlen);
141 lustre_init_msg(req->rq_reqmsg, count, lens, bufs);
146 LIST_HEAD(ptlrpc_rs_debug_lru);
147 spinlock_t ptlrpc_rs_debug_lock = SPIN_LOCK_UNLOCKED;
149 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
151 unsigned long __flags; \
153 spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags); \
154 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
155 spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags); \
158 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
160 unsigned long __flags; \
162 spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags); \
163 list_del(&(rs)->rs_debug_list); \
164 spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags); \
167 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
168 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
171 int lustre_pack_reply(struct ptlrpc_request *req,
172 int count, int *lens, char **bufs)
174 struct ptlrpc_reply_state *rs;
178 LASSERT(req->rq_reply_state == NULL);
179 LASSERT(req->rq_svcsec);
180 LASSERT(req->rq_repmsg == NULL);
182 req->rq_replen = lustre_msg_size(count, lens);
183 rc = svcsec_alloc_repbuf(req->rq_svcsec, req, req->rq_replen);
186 LASSERT(req->rq_reply_state);
187 LASSERT(req->rq_repmsg == req->rq_reply_state->rs_msg);
189 rs = req->rq_reply_state;
190 rs->rs_svcsec = svcsec_get(req->rq_svcsec);
191 rs->rs_cb_id.cbid_fn = reply_out_callback;
192 rs->rs_cb_id.cbid_arg = rs;
193 rs->rs_srv_ni = req->rq_rqbd->rqbd_srv_ni;
194 INIT_LIST_HEAD(&rs->rs_exp_list);
195 INIT_LIST_HEAD(&rs->rs_obd_list);
197 lustre_init_msg(rs->rs_msg, count, lens, bufs);
199 PTLRPC_RS_DEBUG_LRU_ADD(rs);
204 void lustre_free_reply_state(struct ptlrpc_reply_state *rs)
206 struct ptlrpc_svcsec *svcsec = rs->rs_svcsec;
208 PTLRPC_RS_DEBUG_LRU_DEL(rs);
210 LASSERT(!rs->rs_difficult || rs->rs_handled);
211 LASSERT(!rs->rs_on_net);
212 LASSERT(!rs->rs_scheduled);
213 LASSERT(rs->rs_export == NULL);
214 LASSERT(rs->rs_nlocks == 0);
215 LASSERT(list_empty(&rs->rs_exp_list));
216 LASSERT(list_empty(&rs->rs_obd_list));
219 if (svcsec->free_repbuf)
220 svcsec->free_repbuf(svcsec, rs);
222 svcsec_free_reply_state(rs);
227 /* This returns the size of the buffer that is required to hold a lustre_msg
228 * with the given sub-buffer lengths. */
229 int lustre_msg_size(int count, int *lengths)
234 size = HDR_SIZE (count);
235 for (i = 0; i < count; i++)
236 size += size_round(lengths[i]);
241 int lustre_unpack_msg(struct lustre_msg *m, int len)
248 /* We can provide a slightly better error log, if we check the
249 * message magic and version first. In the future, struct
250 * lustre_msg may grow, and we'd like to log a version mismatch,
251 * rather than a short message.
254 required_len = MAX(offsetof(struct lustre_msg, version) +
256 offsetof(struct lustre_msg, magic) +
258 if (len < required_len) {
259 /* can't even look inside the message */
260 CERROR ("message length %d too small for magic/version check\n",
265 flipped = lustre_msg_swabbed(m);
267 __swab32s(&m->version);
268 else if (m->magic != PTLRPC_MSG_MAGIC) {
269 CERROR("wrong lustre_msg magic %#08x\n", m->magic);
273 if ((m->version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
274 CERROR("wrong lustre_msg version %#08x\n", m->version);
278 /* Now we know the sender speaks my language (but possibly flipped)...*/
279 required_len = HDR_SIZE(0);
280 if (len < required_len) {
281 /* can't even look inside the message */
282 CERROR("message length %d too small for lustre_msg\n", len);
289 __swab64s(&m->last_xid);
290 __swab64s(&m->last_committed);
291 __swab64s(&m->transno);
292 __swab32s(&m->status);
293 __swab32s(&m->bufcount);
294 __swab32s(&m->flags);
297 required_len = HDR_SIZE(m->bufcount);
299 if (len < required_len) {
300 /* didn't receive all the buffer lengths */
301 CERROR ("message length %d too small for %d buflens\n",
306 for (i = 0; i < m->bufcount; i++) {
308 __swab32s (&m->buflens[i]);
309 required_len += size_round(m->buflens[i]);
312 if (len < required_len) {
313 CERROR("len: %d, required_len %d\n", len, required_len);
314 CERROR("bufcount: %d\n", m->bufcount);
315 for (i = 0; i < m->bufcount; i++)
316 CERROR("buffer %d length %d\n", i, m->buflens[i]);
323 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
333 bufcount = m->bufcount;
335 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
340 buflen = m->buflens[n];
341 if (buflen < min_size) {
342 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
343 m, n, buflen, min_size);
347 offset = HDR_SIZE(bufcount);
348 for (i = 0; i < n; i++)
349 offset += size_round(m->buflens[i]);
351 return (char *)m + offset;
354 char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
356 /* max_len == 0 means the string should fill the buffer */
357 char *str = lustre_msg_buf(m, index, 0);
362 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
366 blen = m->buflens[index];
367 slen = strnlen(str, blen);
369 if (slen == blen) { /* not NULL terminated */
370 CERROR ("can't unpack non-NULL terminated string in "
371 "msg %p buffer[%d] len %d\n", m, index, blen);
376 if (slen != blen - 1) {
377 CERROR ("can't unpack short string in msg %p "
378 "buffer[%d] len %d: strlen %d\n",
379 m, index, blen, slen);
382 } else if (slen > max_len) {
383 CERROR ("can't unpack oversized string in msg %p "
384 "buffer[%d] len %d strlen %d: max %d expected\n",
385 m, index, blen, slen, max_len);
392 /* Wrap up the normal fixed length cases */
393 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
398 ptr = lustre_msg_buf(msg, index, min_size);
402 if (swabber != NULL && lustre_msg_swabbed(msg))
403 ((void (*)(void *))swabber)(ptr);
408 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
411 LASSERT_REQSWAB(req, index);
412 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
415 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
418 LASSERT_REPSWAB(req, index);
419 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
422 /* byte flipping routines for all wire types declared in
423 * lustre_idl.h implemented here.
426 void lustre_swab_connect(struct obd_connect_data *ocd)
428 __swab64s(&ocd->ocd_connect_flags);
429 __swab32s(&ocd->ocd_nllu[0]);
430 __swab32s(&ocd->ocd_nllu[1]);
433 void lustre_swab_obdo(struct obdo *o)
437 __swab64s(&o->o_atime);
438 __swab64s(&o->o_mtime);
439 __swab64s(&o->o_ctime);
440 __swab64s(&o->o_size);
441 __swab64s(&o->o_blocks);
442 __swab64s(&o->o_grant);
443 __swab32s(&o->o_blksize);
444 __swab32s(&o->o_mode);
445 __swab32s(&o->o_uid);
446 __swab32s(&o->o_gid);
447 __swab32s(&o->o_flags);
448 __swab32s(&o->o_nlink);
449 __swab32s(&o->o_generation);
450 __swab64s(&o->o_valid);
451 __swab32s(&o->o_misc);
452 __swab32s(&o->o_easize);
453 __swab32s(&o->o_mds);
454 __swab64s(&o->o_fid);
455 /* o_inline is opaque */
458 /* mdc pack methods used by mdc and smfs*/
459 void *mdc_create_pack(struct lustre_msg *msg, int offset,
460 struct mdc_op_data *op_data, __u32 mode,
461 __u64 rdev, const void *data, int datalen)
463 struct mds_rec_create *rec;
465 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
467 rec->cr_opcode = REINT_CREATE;
468 rec->cr_id = op_data->id1;
469 rec->cr_replayid = op_data->id2;
472 rec->cr_flags = op_data->flags;
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 *op_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_flags = op_data->flags;
510 rec->sa_id = op_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 *op_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 = op_data->create_mode;
557 rec->ul_id1 = op_data->id1;
558 rec->ul_id2 = op_data->id2;
559 rec->ul_time = op_data->mod_time;
560 rec->ul_flags = op_data->flags;
562 tmp = lustre_msg_buf(msg, offset + 1, op_data->namelen + 1);
563 LASSERT (tmp != NULL);
564 LOGL0(op_data->name, op_data->namelen, tmp);
568 void *mdc_link_pack(struct lustre_msg *msg, int offset,
569 struct mdc_op_data *op_data)
571 struct mds_rec_link *rec;
574 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
576 rec->lk_opcode = REINT_LINK;
577 rec->lk_id1 = op_data->id1;
578 rec->lk_id2 = op_data->id2;
579 rec->lk_flags = op_data->flags;
580 rec->lk_time = op_data->mod_time;
582 tmp = lustre_msg_buf(msg, offset + 1, op_data->namelen + 1);
583 LOGL0(op_data->name, op_data->namelen, tmp);
588 void *mdc_rename_pack(struct lustre_msg *msg, int offset,
589 struct mdc_op_data *op_data,
590 const char *old, int oldlen,
591 const char *new, int newlen)
593 struct mds_rec_rename *rec;
596 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
598 /* XXX do something about time, uid, gid */
599 rec->rn_opcode = REINT_RENAME;
600 rec->rn_id1 = op_data->id1;
601 rec->rn_id2 = op_data->id2;
602 rec->rn_flags = op_data->flags;
603 rec->rn_time = op_data->mod_time;
605 tmp = lustre_msg_buf(msg, offset + 1, oldlen + 1);
606 LOGL0(old, oldlen, tmp);
609 tmp = lustre_msg_buf(msg, offset + 2, newlen + 1);
610 LOGL0(new, newlen, tmp);
615 void lustre_swab_obd_statfs(struct obd_statfs *os)
617 __swab64s(&os->os_type);
618 __swab64s(&os->os_blocks);
619 __swab64s(&os->os_bfree);
620 __swab64s(&os->os_bavail);
621 __swab64s(&os->os_ffree);
622 /* no need to swap os_fsid */
623 __swab32s(&os->os_bsize);
624 __swab32s(&os->os_namelen);
625 /* no need to swap os_spare */
628 void lustre_swab_obd_ioobj(struct obd_ioobj *ioo)
630 __swab64s(&ioo->ioo_id);
631 __swab64s(&ioo->ioo_gr);
632 __swab32s(&ioo->ioo_type);
633 __swab32s(&ioo->ioo_bufcnt);
636 void lustre_swab_niobuf_remote(struct niobuf_remote *nbr)
638 __swab64s(&nbr->offset);
639 __swab32s(&nbr->len);
640 __swab32s(&nbr->flags);
643 void lustre_swab_ost_body(struct ost_body *b)
645 lustre_swab_obdo(&b->oa);
648 void lustre_swab_ost_last_id(obd_id *id)
653 void lustre_swab_generic_32s(__u32 *val)
658 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
660 __swab64s(&lvb->lvb_size);
661 __swab64s(&lvb->lvb_mtime);
662 __swab64s(&lvb->lvb_atime);
663 __swab64s(&lvb->lvb_ctime);
664 __swab64s(&lvb->lvb_blocks);
667 void lustre_swab_lustre_stc (struct lustre_stc *stc)
669 __swab64s(&stc->u.e3s.l3s_ino);
670 __swab32s(&stc->u.e3s.l3s_gen);
671 __swab32s(&stc->u.e3s.l3s_type);
674 void lustre_swab_lustre_fid(struct lustre_fid *fid)
676 __swab64s(&fid->lf_id);
677 __swab64s(&fid->lf_group);
678 /*__swab32s (&fid->lf_version);*/
681 void lustre_swab_lustre_id(struct lustre_id *id)
683 lustre_swab_lustre_stc(&id->li_stc);
684 lustre_swab_lustre_fid(&id->li_fid);
687 void lustre_swab_parseid_pkg (struct parseid_pkg *pkg)
689 __swab32s(&pkg->pp_type);
690 __swab32s(&pkg->pp_rc);
691 lustre_swab_lustre_id(&pkg->pp_id1);
692 lustre_swab_lustre_id(&pkg->pp_id2);
695 void lustre_swab_mds_status_req(struct mds_status_req *r)
697 __swab32s(&r->flags);
698 __swab32s(&r->repbuf);
702 * because sec_desc is variable buffer, we must check it by hand
704 struct mds_req_sec_desc *lustre_swab_mds_secdesc(struct ptlrpc_request *req,
707 struct mds_req_sec_desc *rsd;
708 struct lustre_msg *m;
711 LASSERT_REQSWAB(req, offset);
714 rsd = lustre_msg_buf(m, offset, sizeof(*rsd));
718 if (lustre_msg_swabbed(m)) {
719 __swab32s(&rsd->rsd_uid);
720 __swab32s(&rsd->rsd_gid);
721 __swab32s(&rsd->rsd_fsuid);
722 __swab32s(&rsd->rsd_fsgid);
723 __swab32s(&rsd->rsd_cap);
724 __swab32s(&rsd->rsd_ngroups);
727 if (rsd->rsd_ngroups > LUSTRE_MAX_GROUPS) {
728 CERROR("%u groups is not allowed\n", rsd->rsd_ngroups);
732 if (m->buflens[offset] !=
733 sizeof(*rsd) + rsd->rsd_ngroups * sizeof(__u32)) {
734 CERROR("bufflen %u while contains %u groups\n",
735 m->buflens[offset], rsd->rsd_ngroups);
739 if (lustre_msg_swabbed(m)) {
740 for (i = 0; i < rsd->rsd_ngroups; i++)
741 __swab32s(&rsd->rsd_groups[i]);
747 void lustre_swab_mds_body(struct mds_body *b)
749 lustre_swab_lustre_id(&b->id1);
750 lustre_swab_lustre_id(&b->id2);
751 /* handle is opaque */
753 __swab64s(&b->blocks);
754 __swab64s(&b->valid);
755 __swab64s (&b->audit);
759 __swab32s(&b->mtime);
760 __swab32s(&b->ctime);
761 __swab32s(&b->atime);
762 __swab32s(&b->flags);
764 __swab32s(&b->nlink);
765 __swab32s(&b->eadatasize);
767 void lustre_swab_mds_rec_setattr(struct mds_rec_setattr *sa)
769 __swab32s(&sa->sa_opcode);
770 __swab32s(&sa->sa_flags);
771 __swab32s(&sa->sa_valid);
772 lustre_swab_lustre_id(&sa->sa_id);
773 __swab32s(&sa->sa_mode);
774 __swab32s(&sa->sa_uid);
775 __swab32s(&sa->sa_gid);
776 __swab32s(&sa->sa_attr_flags);
777 __swab64s(&sa->sa_size);
778 __swab64s(&sa->sa_atime);
779 __swab64s(&sa->sa_mtime);
780 __swab64s(&sa->sa_ctime);
783 void lustre_swab_mds_rec_create(struct mds_rec_create *cr)
785 __swab32s(&cr->cr_opcode);
786 __swab32s(&cr->cr_flags);
787 __swab32s(&cr->cr_mode);
788 lustre_swab_lustre_id(&cr->cr_id);
789 lustre_swab_lustre_id(&cr->cr_replayid);
790 __swab64s(&cr->cr_time);
791 __swab64s(&cr->cr_rdev);
792 __swab64s(&cr->cr_ioepoch);
795 void lustre_swab_mds_rec_link(struct mds_rec_link *lk)
797 __swab32s(&lk->lk_opcode);
798 __swab32s(&lk->lk_flags);
799 lustre_swab_lustre_id(&lk->lk_id1);
800 lustre_swab_lustre_id(&lk->lk_id2);
803 void lustre_swab_mds_rec_unlink(struct mds_rec_unlink *ul)
805 __swab32s(&ul->ul_opcode);
806 __swab32s(&ul->ul_flags);
807 __swab32s(&ul->ul_mode);
808 lustre_swab_lustre_id(&ul->ul_id1);
809 lustre_swab_lustre_id(&ul->ul_id2);
812 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
814 __swab32s(&rn->rn_opcode);
815 __swab32s(&rn->rn_flags);
816 lustre_swab_lustre_id(&rn->rn_id1);
817 lustre_swab_lustre_id(&rn->rn_id2);
820 void lustre_swab_lov_desc(struct lov_desc *ld)
822 __swab32s(&ld->ld_tgt_count);
823 __swab32s(&ld->ld_active_tgt_count);
824 __swab32s(&ld->ld_default_stripe_count);
825 __swab64s(&ld->ld_default_stripe_size);
826 __swab64s(&ld->ld_default_stripe_offset);
827 __swab32s(&ld->ld_pattern);
828 /* uuid endian insensitive */
831 void lustre_swab_fid_extent(struct fid_extent *ext)
833 __swab64s(&ext->fe_start);
834 __swab64s(&ext->fe_width);
837 void lustre_swab_ldlm_res_id(struct ldlm_res_id *id)
841 for (i = 0; i < RES_NAME_SIZE; i++)
842 __swab64s(&id->name[i]);
845 void lustre_swab_ldlm_policy_data(ldlm_policy_data_t *d)
847 /* the lock data is a union and the first three fields of both EXTENT
848 * and FLOCK types are __u64, so it's ok to swab them in the same way */
849 __swab64s(&d->l_flock.start);
850 __swab64s(&d->l_flock.end);
851 __swab64s(&d->l_flock.pid);
852 __swab64s(&d->l_flock.nid);
853 __swab64s(&d->l_flock.blocking_pid);
854 __swab64s(&d->l_flock.blocking_nid);
857 void lustre_swab_ldlm_intent(struct ldlm_intent *i)
862 void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r)
864 __swab32s(&r->lr_type);
865 lustre_swab_ldlm_res_id(&r->lr_name);
868 void lustre_swab_ldlm_lock_desc(struct ldlm_lock_desc *l)
870 lustre_swab_ldlm_resource_desc(&l->l_resource);
871 __swab32s(&l->l_req_mode);
872 __swab32s(&l->l_granted_mode);
873 lustre_swab_ldlm_policy_data(&l->l_policy_data);
876 void lustre_swab_ldlm_request(struct ldlm_request *rq)
878 __swab32s(&rq->lock_flags);
879 lustre_swab_ldlm_lock_desc(&rq->lock_desc);
880 /* lock_handle1 opaque */
881 /* lock_handle2 opaque */
884 void lustre_swab_ldlm_reply(struct ldlm_reply *r)
886 __swab32s(&r->lock_flags);
887 lustre_swab_ldlm_lock_desc(&r->lock_desc);
888 /* lock_handle opaque */
889 __swab64s(&r->lock_policy_res1);
890 __swab64s(&r->lock_policy_res2);
893 void lustre_swab_ptlbd_op(struct ptlbd_op *op)
895 __swab16s(&op->op_cmd);
896 __swab16s(&op->op_lun);
897 __swab16s(&op->op_niob_cnt);
898 /* ignore op__padding */
899 __swab32s(&op->op_block_cnt);
902 void lustre_swab_ptlbd_niob(struct ptlbd_niob *n)
904 __swab64s(&n->n_xid);
905 __swab64s(&n->n_block_nr);
906 __swab32s(&n->n_offset);
907 __swab32s(&n->n_length);
910 void lustre_swab_ptlbd_rsp(struct ptlbd_rsp *r)
912 __swab16s(&r->r_status);
913 __swab16s(&r->r_error_cnt);
916 void lustre_swab_remote_perm(struct mds_remote_perm *p)
918 __swab32s(&p->mrp_auth_uid);
919 __swab32s(&p->mrp_auth_gid);
920 __swab16s(&p->mrp_perm);
923 void lustre_swab_lustre_capa(struct lustre_capa *c)
925 __swab32s (&c->lc_uid);
926 __swab32s (&c->lc_ruid);
927 __swab32s (&c->lc_op);
928 __swab32s (&c->lc_igen);
929 __swab64s (&c->lc_ino);
930 __swab32s (&c->lc_mdsid);
931 __swab32s (&c->lc_keyid);
932 __swab64s (&c->lc_expiry);
933 __swab32s (&c->lc_flags);
936 void lustre_swab_lustre_capa_key (struct lustre_capa_key *k)
938 __swab32s (&k->lk_mdsid);
939 __swab32s (&k->lk_keyid);
940 __swab64s (&k->lk_expiry);
943 void lustre_swab_audit_msg (struct audit_msg *r)
945 lustre_swab_lustre_id(&r->id);
946 __swab32s (&r->code);
947 __swab32s (&r->result);
953 void lustre_swab_audit_attr (struct audit_attr_msg *r)
955 lustre_swab_lustre_id(&r->id);
956 __swab64s (&r->attr);
959 /* no one calls this */
960 int llog_log_swabbed(struct llog_log_hdr *hdr)
962 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
964 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
969 void lustre_assert_wire_constants(void)
973 /* for gks key rec */
974 void lustre_swab_key_perms(struct key_perm *kperm)
977 __swab32s(&kperm->kp_uid);
978 __swab32s(&kperm->kp_gid);
979 __swab32s(&kperm->kp_mode);
980 __swab32s(&kperm->kp_acl_count);
981 for (i = 0; i < kperm->kp_acl_count; i++) {
982 __swab16s(&kperm->kp_acls[i].e_tag);
983 __swab16s(&kperm->kp_acls[i].e_perm);
984 __swab32s(&kperm->kp_acls[i].e_id);
988 void lustre_swab_key_context (struct key_context *kctxt)
990 __swab32s(&kctxt->kc_command);
991 __swab32s(&kctxt->kc_valid); /* for use with open */
992 lustre_swab_key_perms(&kctxt->kc_perm);