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>
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, int *lens, char **bufs)
61 msg->magic = PTLRPC_MSG_MAGIC;
62 msg->version = PTLRPC_MSG_VERSION;
63 msg->bufcount = count;
64 for (i = 0; i < count; i++)
65 msg->buflens[i] = lens[i];
70 ptr = (char *)msg + HDR_SIZE(count);
71 for (i = 0; i < count; i++) {
73 LOGL(tmp, lens[i], ptr);
77 int lustre_secdesc_size(void)
80 int ngroups = current_ngroups;
82 if (ngroups > LUSTRE_MAX_GROUPS)
83 ngroups = LUSTRE_MAX_GROUPS;
85 return sizeof(struct mds_req_sec_desc) +
86 sizeof(__u32) * ngroups;
93 * because group info might have changed since last time we call
94 * secdesc_size(), so here we did more sanity check to prevent garbage gids
96 void lustre_pack_secdesc(struct ptlrpc_request *req, int size)
99 struct mds_req_sec_desc *rsd;
101 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
102 struct group_info *ginfo;
105 rsd = lustre_msg_buf(req->rq_reqmsg,
106 MDS_REQ_SECDESC_OFF, size);
108 rsd->rsd_uid = current->uid;
109 rsd->rsd_gid = current->gid;
110 rsd->rsd_fsuid = current->fsuid;
111 rsd->rsd_fsgid = current->fsgid;
112 rsd->rsd_cap = current->cap_effective;
113 rsd->rsd_ngroups = (size - sizeof(*rsd)) / sizeof(__u32);
114 LASSERT(rsd->rsd_ngroups <= LUSTRE_MAX_GROUPS);
116 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)
118 get_group_info(current->group_info);
119 ginfo = current->group_info;
120 task_unlock(current);
121 if (rsd->rsd_ngroups > ginfo->ngroups)
122 rsd->rsd_ngroups = ginfo->ngroups;
123 memcpy(rsd->rsd_groups, ginfo->blocks[0],
124 rsd->rsd_ngroups * sizeof(__u32));
126 LASSERT(rsd->rsd_ngroups <= NGROUPS);
127 if (rsd->rsd_ngroups > current->ngroups)
128 rsd->rsd_ngroups = current->ngroups;
129 memcpy(rsd->rsd_groups, current->groups,
130 rsd->rsd_ngroups * sizeof(__u32));
135 int lustre_pack_request (struct ptlrpc_request *req,
136 int count, int *lens, char **bufs)
141 req->rq_reqlen = lustre_msg_size(count, lens);
142 rc = ptlrpcs_cli_alloc_reqbuf(req, req->rq_reqlen);
146 lustre_init_msg(req->rq_reqmsg, count, lens, bufs);
151 LIST_HEAD(ptlrpc_rs_debug_lru);
152 spinlock_t ptlrpc_rs_debug_lock = SPIN_LOCK_UNLOCKED;
154 #define PTLRPC_RS_DEBUG_LRU_ADD(rs) \
156 unsigned long __flags; \
158 spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags); \
159 list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru); \
160 spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags); \
163 #define PTLRPC_RS_DEBUG_LRU_DEL(rs) \
165 unsigned long __flags; \
167 spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags); \
168 list_del(&(rs)->rs_debug_list); \
169 spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags); \
172 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
173 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
176 int lustre_pack_reply (struct ptlrpc_request *req,
177 int count, int *lens, char **bufs)
179 struct ptlrpc_reply_state *rs;
183 LASSERT(req->rq_reply_state == NULL);
184 LASSERT(req->rq_svcsec);
185 LASSERT(req->rq_repmsg == NULL);
187 req->rq_replen = lustre_msg_size(count, lens);
188 rc = svcsec_alloc_repbuf(req->rq_svcsec, req, req->rq_replen);
191 LASSERT(req->rq_reply_state);
192 LASSERT(req->rq_repmsg == req->rq_reply_state->rs_msg);
194 rs = req->rq_reply_state;
195 rs->rs_svcsec = svcsec_get(req->rq_svcsec);
196 rs->rs_cb_id.cbid_fn = reply_out_callback;
197 rs->rs_cb_id.cbid_arg = rs;
198 rs->rs_srv_ni = req->rq_rqbd->rqbd_srv_ni;
199 INIT_LIST_HEAD(&rs->rs_exp_list);
200 INIT_LIST_HEAD(&rs->rs_obd_list);
202 lustre_init_msg(rs->rs_msg, count, lens, bufs);
204 PTLRPC_RS_DEBUG_LRU_ADD(rs);
209 void lustre_free_reply_state (struct ptlrpc_reply_state *rs)
211 struct ptlrpc_svcsec *svcsec = rs->rs_svcsec;
213 PTLRPC_RS_DEBUG_LRU_DEL(rs);
215 LASSERT (!rs->rs_difficult || rs->rs_handled);
216 LASSERT (!rs->rs_on_net);
217 LASSERT (!rs->rs_scheduled);
218 LASSERT (rs->rs_export == NULL);
219 LASSERT (rs->rs_nlocks == 0);
220 LASSERT (list_empty(&rs->rs_exp_list));
221 LASSERT (list_empty(&rs->rs_obd_list));
224 if (svcsec->free_repbuf)
225 svcsec->free_repbuf(svcsec, rs);
227 svcsec_free_reply_state(rs);
232 /* This returns the size of the buffer that is required to hold a lustre_msg
233 * with the given sub-buffer lengths. */
234 int lustre_msg_size(int count, int *lengths)
239 size = HDR_SIZE (count);
240 for (i = 0; i < count; i++)
241 size += size_round(lengths[i]);
246 int lustre_unpack_msg(struct lustre_msg *m, int len)
253 /* We can provide a slightly better error log, if we check the
254 * message magic and version first. In the future, struct
255 * lustre_msg may grow, and we'd like to log a version mismatch,
256 * rather than a short message.
259 required_len = MAX (offsetof (struct lustre_msg, version) +
261 offsetof (struct lustre_msg, magic) +
263 if (len < required_len) {
264 /* can't even look inside the message */
265 CERROR ("message length %d too small for magic/version check\n",
270 flipped = lustre_msg_swabbed(m);
272 __swab32s (&m->version);
273 else if (m->magic != PTLRPC_MSG_MAGIC) {
274 CERROR("wrong lustre_msg magic %#08x\n", m->magic);
278 if ((m->version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
279 CERROR("wrong lustre_msg version %#08x\n", m->version);
283 /* Now we know the sender speaks my language (but possibly flipped)...*/
284 required_len = HDR_SIZE(0);
285 if (len < required_len) {
286 /* can't even look inside the message */
287 CERROR ("message length %d too small for lustre_msg\n", len);
292 __swab32s (&m->type);
294 __swab64s (&m->last_xid);
295 __swab64s (&m->last_committed);
296 __swab64s (&m->transno);
297 __swab32s (&m->status);
298 __swab32s (&m->bufcount);
299 __swab32s (&m->flags);
302 required_len = HDR_SIZE(m->bufcount);
304 if (len < required_len) {
305 /* didn't receive all the buffer lengths */
306 CERROR ("message length %d too small for %d buflens\n",
311 for (i = 0; i < m->bufcount; i++) {
313 __swab32s (&m->buflens[i]);
314 required_len += size_round(m->buflens[i]);
317 if (len < required_len) {
318 CERROR("len: %d, required_len %d\n", len, required_len);
319 CERROR("bufcount: %d\n", m->bufcount);
320 for (i = 0; i < m->bufcount; i++)
321 CERROR("buffer %d length %d\n", i, m->buflens[i]);
328 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
338 bufcount = m->bufcount;
340 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
345 buflen = m->buflens[n];
346 if (buflen < min_size) {
347 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
348 m, n, buflen, min_size);
352 offset = HDR_SIZE(bufcount);
353 for (i = 0; i < n; i++)
354 offset += size_round(m->buflens[i]);
356 return (char *)m + offset;
359 char *lustre_msg_string (struct lustre_msg *m, int index, int max_len)
361 /* max_len == 0 means the string should fill the buffer */
362 char *str = lustre_msg_buf (m, index, 0);
367 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
371 blen = m->buflens[index];
372 slen = strnlen (str, blen);
374 if (slen == blen) { /* not NULL terminated */
375 CERROR ("can't unpack non-NULL terminated string in "
376 "msg %p buffer[%d] len %d\n", m, index, blen);
381 if (slen != blen - 1) {
382 CERROR ("can't unpack short string in msg %p "
383 "buffer[%d] len %d: strlen %d\n",
384 m, index, blen, slen);
387 } else if (slen > max_len) {
388 CERROR ("can't unpack oversized string in msg %p "
389 "buffer[%d] len %d strlen %d: max %d expected\n",
390 m, index, blen, slen, max_len);
397 /* Wrap up the normal fixed length cases */
398 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
403 ptr = lustre_msg_buf(msg, index, min_size);
407 if (swabber != NULL && lustre_msg_swabbed(msg))
408 ((void (*)(void *))swabber)(ptr);
413 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
416 LASSERT_REQSWAB(req, index);
417 return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
420 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
423 LASSERT_REPSWAB(req, index);
424 return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
427 /* byte flipping routines for all wire types declared in
428 * lustre_idl.h implemented here.
431 void lustre_swab_connect(struct obd_connect_data *ocd)
433 __swab64s (&ocd->ocd_connect_flags);
434 __swab32s (&ocd->ocd_nllu[0]);
435 __swab32s (&ocd->ocd_nllu[1]);
438 void lustre_swab_obdo (struct obdo *o)
440 __swab64s (&o->o_id);
441 __swab64s (&o->o_gr);
442 __swab64s (&o->o_atime);
443 __swab64s (&o->o_mtime);
444 __swab64s (&o->o_ctime);
445 __swab64s (&o->o_size);
446 __swab64s (&o->o_blocks);
447 __swab64s (&o->o_grant);
448 __swab32s (&o->o_blksize);
449 __swab32s (&o->o_mode);
450 __swab32s (&o->o_uid);
451 __swab32s (&o->o_gid);
452 __swab32s (&o->o_flags);
453 __swab32s (&o->o_nlink);
454 __swab32s (&o->o_generation);
455 __swab64s (&o->o_valid);
456 __swab32s (&o->o_misc);
457 __swab32s (&o->o_easize);
458 __swab32s (&o->o_mds);
459 __swab64s (&o->o_fid);
460 /* o_inline is opaque */
463 /* mdc pack methods used by mdc and smfs*/
464 void *mdc_create_pack(struct lustre_msg *msg, int offset,
465 struct mdc_op_data *op_data, __u32 mode,
466 __u64 rdev, const void *data, int datalen)
468 struct mds_rec_create *rec;
470 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
472 rec->cr_opcode = REINT_CREATE;
473 rec->cr_id = op_data->id1;
474 memset(&rec->cr_replayid, 0, sizeof(rec->cr_replayid));
477 rec->cr_time = op_data->mod_time;
479 tmp = lustre_msg_buf(msg, offset + 1, op_data->namelen + 1);
480 LOGL0(op_data->name, op_data->namelen, tmp);
483 tmp = lustre_msg_buf(msg, offset + 2, datalen);
484 memcpy (tmp, data, datalen);
486 return ((void*)tmp + size_round(datalen));
489 void *mdc_setattr_pack(struct lustre_msg *msg, int offset,
490 struct mdc_op_data *data, struct iattr *iattr,
491 void *ea, int ealen, void *ea2, int ea2len)
493 struct mds_rec_setattr *rec = lustre_msg_buf(msg, offset, sizeof(*rec));
496 rec->sa_opcode = REINT_SETATTR;
497 rec->sa_id = data->id1;
500 rec->sa_valid = iattr->ia_valid;
501 rec->sa_mode = iattr->ia_mode;
502 rec->sa_uid = iattr->ia_uid;
503 rec->sa_gid = iattr->ia_gid;
504 rec->sa_size = iattr->ia_size;
505 rec->sa_atime = LTIME_S(iattr->ia_atime);
506 rec->sa_mtime = LTIME_S(iattr->ia_mtime);
507 rec->sa_ctime = LTIME_S(iattr->ia_ctime);
508 rec->sa_attr_flags = iattr->ia_attr_flags;
510 tmp = (char*)rec + size_round(sizeof(*rec));
515 memcpy(lustre_msg_buf(msg, offset + 1, ealen), ea, ealen);
516 tmp += size_round(ealen);
521 memcpy(lustre_msg_buf(msg, offset + 2, ea2len), ea2, ea2len);
522 tmp += size_round(ea2len);
526 void *mdc_unlink_pack(struct lustre_msg *msg, int offset,
527 struct mdc_op_data *data)
529 struct mds_rec_unlink *rec;
532 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
533 LASSERT (rec != NULL);
535 rec->ul_opcode = REINT_UNLINK;
536 rec->ul_mode = data->create_mode;
537 rec->ul_id1 = data->id1;
538 rec->ul_id2 = data->id2;
539 rec->ul_time = data->mod_time;
541 tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
542 LASSERT (tmp != NULL);
543 LOGL0(data->name, data->namelen, tmp);
547 void *mdc_link_pack(struct lustre_msg *msg, int offset,
548 struct mdc_op_data *data)
550 struct mds_rec_link *rec;
553 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
555 rec->lk_opcode = REINT_LINK;
556 rec->lk_id1 = data->id1;
557 rec->lk_id2 = data->id2;
558 rec->lk_time = data->mod_time;
560 tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
561 LOGL0(data->name, data->namelen, tmp);
566 void *mdc_rename_pack(struct lustre_msg *msg, int offset,
567 struct mdc_op_data *data,
568 const char *old, int oldlen,
569 const char *new, int newlen)
571 struct mds_rec_rename *rec;
574 rec = lustre_msg_buf(msg, offset, sizeof (*rec));
576 /* XXX do something about time, uid, gid */
577 rec->rn_opcode = REINT_RENAME;
578 rec->rn_id1 = data->id1;
579 rec->rn_id2 = data->id2;
580 rec->rn_time = data->mod_time;
582 tmp = lustre_msg_buf(msg, offset + 1, oldlen + 1);
583 LOGL0(old, oldlen, tmp);
586 tmp = lustre_msg_buf(msg, offset + 2, newlen + 1);
587 LOGL0(new, newlen, tmp);
592 void lustre_swab_obd_statfs (struct obd_statfs *os)
594 __swab64s (&os->os_type);
595 __swab64s (&os->os_blocks);
596 __swab64s (&os->os_bfree);
597 __swab64s (&os->os_bavail);
598 __swab64s (&os->os_ffree);
599 /* no need to swap os_fsid */
600 __swab32s (&os->os_bsize);
601 __swab32s (&os->os_namelen);
602 /* no need to swap os_spare */
605 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
607 __swab64s (&ioo->ioo_id);
608 __swab64s (&ioo->ioo_gr);
609 __swab32s (&ioo->ioo_type);
610 __swab32s (&ioo->ioo_bufcnt);
613 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
615 __swab64s (&nbr->offset);
616 __swab32s (&nbr->len);
617 __swab32s (&nbr->flags);
620 void lustre_swab_ost_body (struct ost_body *b)
622 lustre_swab_obdo (&b->oa);
625 void lustre_swab_ost_last_id(obd_id *id)
630 void lustre_swab_generic_32s(__u32 *val)
635 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
637 __swab64s(&lvb->lvb_size);
638 __swab64s(&lvb->lvb_mtime);
639 __swab64s(&lvb->lvb_atime);
640 __swab64s(&lvb->lvb_ctime);
641 __swab64s(&lvb->lvb_blocks);
644 void lustre_swab_lustre_stc (struct lustre_stc *stc)
646 __swab64s (&stc->u.e3s.l3s_ino);
647 __swab32s (&stc->u.e3s.l3s_gen);
648 __swab32s (&stc->u.e3s.l3s_type);
651 void lustre_swab_lustre_fid(struct lustre_fid *fid)
653 __swab64s (&fid->lf_id);
654 __swab64s (&fid->lf_group);
655 __swab32s (&fid->lf_version);
658 void lustre_swab_lustre_id (struct lustre_id *id)
660 lustre_swab_lustre_stc(&id->li_stc);
661 lustre_swab_lustre_fid(&id->li_fid);
664 void lustre_swab_mds_status_req (struct mds_status_req *r)
666 __swab32s (&r->flags);
667 __swab32s (&r->repbuf);
671 * because sec_desc is variable buffer, we must check it by hand
673 struct mds_req_sec_desc *lustre_swab_mds_secdesc(struct ptlrpc_request *req,
676 struct mds_req_sec_desc *rsd;
677 struct lustre_msg *m;
680 LASSERT_REQSWAB(req, offset);
683 rsd = lustre_msg_buf(m, offset, sizeof(*rsd));
687 if (lustre_msg_swabbed(m)) {
688 __swab32s(&rsd->rsd_uid);
689 __swab32s(&rsd->rsd_gid);
690 __swab32s(&rsd->rsd_fsuid);
691 __swab32s(&rsd->rsd_fsgid);
692 __swab32s(&rsd->rsd_cap);
693 __swab32s(&rsd->rsd_ngroups);
696 if (rsd->rsd_ngroups > LUSTRE_MAX_GROUPS) {
697 CERROR("%u groups is not allowed\n", rsd->rsd_ngroups);
701 if (m->buflens[offset] !=
702 sizeof(*rsd) + rsd->rsd_ngroups * sizeof(__u32)) {
703 CERROR("bufflen %u while contains %u groups\n",
704 m->buflens[offset], rsd->rsd_ngroups);
708 if (lustre_msg_swabbed(m)) {
709 for (i = 0; i < rsd->rsd_ngroups; i++)
710 __swab32s(&rsd->rsd_groups[i]);
716 void lustre_swab_mds_body (struct mds_body *b)
718 lustre_swab_lustre_id (&b->id1);
719 lustre_swab_lustre_id (&b->id2);
720 /* handle is opaque */
721 __swab64s (&b->size);
722 __swab64s (&b->blocks);
723 __swab64s (&b->valid);
724 __swab32s (&b->mode);
727 __swab32s (&b->mtime);
728 __swab32s (&b->ctime);
729 __swab32s (&b->atime);
730 __swab32s (&b->flags);
731 __swab32s (&b->rdev);
732 __swab32s (&b->nlink);
733 __swab32s (&b->eadatasize);
735 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
737 __swab32s (&sa->sa_opcode);
738 __swab32s (&sa->sa_valid);
739 lustre_swab_lustre_id (&sa->sa_id);
740 __swab32s (&sa->sa_mode);
741 __swab32s (&sa->sa_uid);
742 __swab32s (&sa->sa_gid);
743 __swab32s (&sa->sa_attr_flags);
744 __swab64s (&sa->sa_size);
745 __swab64s (&sa->sa_atime);
746 __swab64s (&sa->sa_mtime);
747 __swab64s (&sa->sa_ctime);
750 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
752 __swab32s (&cr->cr_opcode);
753 __swab32s (&cr->cr_flags); /* for use with open */
754 __swab32s (&cr->cr_mode);
755 lustre_swab_lustre_id (&cr->cr_id);
756 lustre_swab_lustre_id (&cr->cr_replayid);
757 __swab64s (&cr->cr_time);
758 __swab64s (&cr->cr_rdev);
761 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
763 __swab32s (&lk->lk_opcode);
764 lustre_swab_lustre_id (&lk->lk_id1);
765 lustre_swab_lustre_id (&lk->lk_id2);
768 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
770 __swab32s (&ul->ul_opcode);
771 __swab32s (&ul->ul_mode);
772 lustre_swab_lustre_id (&ul->ul_id1);
773 lustre_swab_lustre_id (&ul->ul_id2);
776 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
778 __swab32s (&rn->rn_opcode);
779 lustre_swab_lustre_id (&rn->rn_id1);
780 lustre_swab_lustre_id (&rn->rn_id2);
783 void lustre_swab_lov_desc (struct lov_desc *ld)
785 __swab32s (&ld->ld_tgt_count);
786 __swab32s (&ld->ld_active_tgt_count);
787 __swab32s (&ld->ld_default_stripe_count);
788 __swab64s (&ld->ld_default_stripe_size);
789 __swab64s (&ld->ld_default_stripe_offset);
790 __swab32s (&ld->ld_pattern);
791 /* uuid endian insensitive */
794 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
798 for (i = 0; i < RES_NAME_SIZE; i++)
799 __swab64s (&id->name[i]);
802 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
804 /* the lock data is a union and the first three fields of both EXTENT
805 * and FLOCK types are __u64, so it's ok to swab them in the same way */
806 __swab64s (&d->l_flock.start);
807 __swab64s (&d->l_flock.end);
808 __swab64s (&d->l_flock.pid);
809 __swab64s (&d->l_flock.blocking_pid);
812 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
817 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
819 __swab32s (&r->lr_type);
820 lustre_swab_ldlm_res_id (&r->lr_name);
823 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
825 lustre_swab_ldlm_resource_desc (&l->l_resource);
826 __swab32s (&l->l_req_mode);
827 __swab32s (&l->l_granted_mode);
828 lustre_swab_ldlm_policy_data (&l->l_policy_data);
831 void lustre_swab_ldlm_request (struct ldlm_request *rq)
833 __swab32s (&rq->lock_flags);
834 lustre_swab_ldlm_lock_desc (&rq->lock_desc);
835 /* lock_handle1 opaque */
836 /* lock_handle2 opaque */
839 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
841 __swab32s (&r->lock_flags);
842 lustre_swab_ldlm_lock_desc (&r->lock_desc);
843 /* lock_handle opaque */
844 __swab64s (&r->lock_policy_res1);
845 __swab64s (&r->lock_policy_res2);
848 void lustre_swab_ptlbd_op (struct ptlbd_op *op)
850 __swab16s (&op->op_cmd);
851 __swab16s (&op->op_lun);
852 __swab16s (&op->op_niob_cnt);
853 /* ignore op__padding */
854 __swab32s (&op->op_block_cnt);
857 void lustre_swab_ptlbd_niob (struct ptlbd_niob *n)
859 __swab64s (&n->n_xid);
860 __swab64s (&n->n_block_nr);
861 __swab32s (&n->n_offset);
862 __swab32s (&n->n_length);
865 void lustre_swab_ptlbd_rsp (struct ptlbd_rsp *r)
867 __swab16s (&r->r_status);
868 __swab16s (&r->r_error_cnt);
871 /* no one calls this */
872 int llog_log_swabbed(struct llog_log_hdr *hdr)
874 if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
876 if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
881 void lustre_swab_llogd_body (struct llogd_body *d)
883 __swab64s (&d->lgd_logid.lgl_oid);
884 __swab64s (&d->lgd_logid.lgl_ogr);
885 __swab32s (&d->lgd_logid.lgl_ogen);
886 __swab32s (&d->lgd_ctxt_idx);
887 __swab32s (&d->lgd_llh_flags);
888 __swab32s (&d->lgd_index);
889 __swab32s (&d->lgd_saved_index);
890 __swab32s (&d->lgd_len);
891 __swab64s (&d->lgd_cur_offset);
894 void lustre_swab_llog_hdr (struct llog_log_hdr *h)
896 __swab32s (&h->llh_hdr.lrh_index);
897 __swab32s (&h->llh_hdr.lrh_len);
898 __swab32s (&h->llh_hdr.lrh_type);
899 __swab64s (&h->llh_timestamp);
900 __swab32s (&h->llh_count);
901 __swab32s (&h->llh_bitmap_offset);
902 __swab32s (&h->llh_flags);
903 __swab32s (&h->llh_tail.lrt_index);
904 __swab32s (&h->llh_tail.lrt_len);
907 void lustre_swab_llogd_conn_body (struct llogd_conn_body *d)
909 __swab64s (&d->lgdc_gen.mnt_cnt);
910 __swab64s (&d->lgdc_gen.conn_cnt);
911 __swab64s (&d->lgdc_logid.lgl_oid);
912 __swab64s (&d->lgdc_logid.lgl_ogr);
913 __swab32s (&d->lgdc_logid.lgl_ogen);
914 __swab32s (&d->lgdc_ctxt_idx);
917 void lustre_assert_wire_constants(void)