Whamcloud - gitweb
- landing of b_fid after merge with b_hd_cleanup_merge.
[fs/lustre-release.git] / lustre / ptlrpc / pack_generic.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
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>
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
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.
14  *
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.
19  *
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.
23  *
24  * (Un)packing of OST requests
25  *
26  */
27
28 #define DEBUG_SUBSYSTEM S_RPC
29 #ifndef __KERNEL__
30 # include <liblustre.h>
31 #endif
32
33 #include <linux/obd_support.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_net.h>
36 #include <linux/fcntl.h>
37
38
39 #define HDR_SIZE(count) \
40     size_round(offsetof (struct lustre_msg, buflens[(count)]))
41
42 int lustre_msg_swabbed(struct lustre_msg *msg)
43 {
44         return (msg->magic == __swab32(PTLRPC_MSG_MAGIC));
45 }
46
47 int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
48 {
49         if (!lustre_msg_swabbed(msg))
50                 return (msg->version & LUSTRE_VERSION_MASK) != version;
51
52         return (__swab32(msg->version) & LUSTRE_VERSION_MASK) != version;
53 }
54
55 void lustre_init_msg (struct lustre_msg *msg, int count, int *lens, char **bufs)
56 {
57         char *ptr;
58         int   i;
59
60         msg->magic = PTLRPC_MSG_MAGIC;
61         msg->version = PTLRPC_MSG_VERSION;
62         msg->bufcount = count;
63         for (i = 0; i < count; i++)
64                 msg->buflens[i] = lens[i];
65
66         if (bufs == NULL)
67                 return;
68
69         ptr = (char *)msg + HDR_SIZE(count);
70         for (i = 0; i < count; i++) {
71                 char *tmp = bufs[i];
72                 LOGL(tmp, lens[i], ptr);
73         }
74 }
75
76 int lustre_pack_request (struct ptlrpc_request *req,
77                          int count, int *lens, char **bufs)
78 {
79         ENTRY;
80
81         req->rq_reqlen = lustre_msg_size (count, lens);
82         OBD_ALLOC(req->rq_reqmsg, req->rq_reqlen);
83         if (req->rq_reqmsg == NULL)
84                 RETURN(-ENOMEM);
85
86         lustre_init_msg (req->rq_reqmsg, count, lens, bufs);
87         RETURN (0);
88 }
89
90 #if RS_DEBUG
91 LIST_HEAD(ptlrpc_rs_debug_lru);
92 spinlock_t ptlrpc_rs_debug_lock = SPIN_LOCK_UNLOCKED;
93
94 #define PTLRPC_RS_DEBUG_LRU_ADD(rs)                                     \
95 do {                                                                    \
96         unsigned long __flags;                                          \
97                                                                         \
98         spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags);              \
99         list_add_tail(&(rs)->rs_debug_list, &ptlrpc_rs_debug_lru);      \
100         spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags);         \
101 } while (0)
102
103 #define PTLRPC_RS_DEBUG_LRU_DEL(rs)                                     \
104 do {                                                                    \
105         unsigned long __flags;                                          \
106                                                                         \
107         spin_lock_irqsave(&ptlrpc_rs_debug_lock, __flags);              \
108         list_del(&(rs)->rs_debug_list);                                 \
109         spin_unlock_irqrestore(&ptlrpc_rs_debug_lock, __flags);         \
110 } while (0)
111 #else
112 # define PTLRPC_RS_DEBUG_LRU_ADD(rs) do {} while(0)
113 # define PTLRPC_RS_DEBUG_LRU_DEL(rs) do {} while(0)
114 #endif
115
116 int lustre_pack_reply (struct ptlrpc_request *req,
117                        int count, int *lens, char **bufs)
118 {
119         struct ptlrpc_reply_state *rs;
120         int                        msg_len;
121         int                        size;
122         ENTRY;
123
124         LASSERT (req->rq_reply_state == NULL);
125
126         msg_len = lustre_msg_size (count, lens);
127         size = offsetof (struct ptlrpc_reply_state, rs_msg) + msg_len;
128         OBD_ALLOC (rs, size);
129         if (rs == NULL)
130                 RETURN (-ENOMEM);
131
132         rs->rs_cb_id.cbid_fn = reply_out_callback;
133         rs->rs_cb_id.cbid_arg = rs;
134         rs->rs_srv_ni = req->rq_rqbd->rqbd_srv_ni;
135         rs->rs_size = size;
136         INIT_LIST_HEAD(&rs->rs_exp_list);
137         INIT_LIST_HEAD(&rs->rs_obd_list);
138
139         req->rq_replen = msg_len;
140         req->rq_reply_state = rs;
141         req->rq_repmsg = &rs->rs_msg;
142         lustre_init_msg (&rs->rs_msg, count, lens, bufs);
143
144         PTLRPC_RS_DEBUG_LRU_ADD(rs);
145
146         RETURN (0);
147 }
148
149 void lustre_free_reply_state (struct ptlrpc_reply_state *rs)
150 {
151         PTLRPC_RS_DEBUG_LRU_DEL(rs);
152
153         LASSERT (!rs->rs_difficult || rs->rs_handled);
154         LASSERT (!rs->rs_on_net);
155         LASSERT (!rs->rs_scheduled);
156         LASSERT (rs->rs_export == NULL);
157         LASSERT (rs->rs_nlocks == 0);
158         LASSERT (list_empty(&rs->rs_exp_list));
159         LASSERT (list_empty(&rs->rs_obd_list));
160
161         OBD_FREE (rs, rs->rs_size);
162 }
163
164 /* This returns the size of the buffer that is required to hold a lustre_msg
165  * with the given sub-buffer lengths. */
166 int lustre_msg_size(int count, int *lengths)
167 {
168         int size;
169         int i;
170
171         size = HDR_SIZE (count);
172         for (i = 0; i < count; i++)
173                 size += size_round(lengths[i]);
174
175         return size;
176 }
177
178 int lustre_unpack_msg(struct lustre_msg *m, int len)
179 {
180         int   flipped;
181         int   required_len;
182         int   i;
183         ENTRY;
184
185         /* We can provide a slightly better error log, if we check the
186          * message magic and version first.  In the future, struct
187          * lustre_msg may grow, and we'd like to log a version mismatch,
188          * rather than a short message.
189          *
190          */
191         required_len = MAX (offsetof (struct lustre_msg, version) +
192                             sizeof (m->version),
193                             offsetof (struct lustre_msg, magic) +
194                             sizeof (m->magic));
195         if (len < required_len) {
196                 /* can't even look inside the message */
197                 CERROR ("message length %d too small for magic/version check\n",
198                         len);
199                 RETURN (-EINVAL);
200         }
201
202         flipped = lustre_msg_swabbed(m);
203         if (flipped)
204                 __swab32s (&m->version);
205         else if (m->magic != PTLRPC_MSG_MAGIC) {
206                 CERROR("wrong lustre_msg magic %#08x\n", m->magic);
207                 RETURN (-EINVAL);
208         }
209
210         if ((m->version & ~LUSTRE_VERSION_MASK) != PTLRPC_MSG_VERSION) {
211                 CERROR("wrong lustre_msg version %#08x\n", m->version);
212                 RETURN (-EINVAL);
213         }
214
215         /* Now we know the sender speaks my language (but possibly flipped)...*/
216         required_len = HDR_SIZE(0);
217         if (len < required_len) {
218                 /* can't even look inside the message */
219                 CERROR ("message length %d too small for lustre_msg\n", len);
220                 RETURN (-EINVAL);
221         }
222
223         if (flipped) {
224                 __swab32s (&m->type);
225                 __swab32s (&m->opc);
226                 __swab64s (&m->last_xid);
227                 __swab64s (&m->last_committed);
228                 __swab64s (&m->transno);
229                 __swab32s (&m->status);
230                 __swab32s (&m->bufcount);
231                 __swab32s (&m->flags);
232         }
233
234         required_len = HDR_SIZE(m->bufcount);
235
236         if (len < required_len) {
237                 /* didn't receive all the buffer lengths */
238                 CERROR ("message length %d too small for %d buflens\n",
239                         len, m->bufcount);
240                 RETURN(-EINVAL);
241         }
242
243         for (i = 0; i < m->bufcount; i++) {
244                 if (flipped)
245                         __swab32s (&m->buflens[i]);
246                 required_len += size_round(m->buflens[i]);
247         }
248
249         if (len < required_len) {
250                 CERROR("len: %d, required_len %d\n", len, required_len);
251                 CERROR("bufcount: %d\n", m->bufcount);
252                 for (i = 0; i < m->bufcount; i++)
253                         CERROR("buffer %d length %d\n", i, m->buflens[i]);
254                 RETURN(-EINVAL);
255         }
256
257         RETURN(0);
258 }
259
260 void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
261 {
262         int i;
263         int offset;
264         int buflen;
265         int bufcount;
266
267         LASSERT (m != NULL);
268         LASSERT (n >= 0);
269
270         bufcount = m->bufcount;
271         if (n >= bufcount) {
272                 CDEBUG(D_INFO, "msg %p buffer[%d] not present (count %d)\n",
273                        m, n, bufcount);
274                 return NULL;
275         }
276
277         buflen = m->buflens[n];
278         if (buflen < min_size) {
279                 CERROR("msg %p buffer[%d] size %d too small (required %d)\n",
280                        m, n, buflen, min_size);
281                 return NULL;
282         }
283
284         offset = HDR_SIZE(bufcount);
285         for (i = 0; i < n; i++)
286                 offset += size_round(m->buflens[i]);
287
288         return (char *)m + offset;
289 }
290
291 char *lustre_msg_string (struct lustre_msg *m, int index, int max_len)
292 {
293         /* max_len == 0 means the string should fill the buffer */
294         char *str = lustre_msg_buf (m, index, 0);
295         int   slen;
296         int   blen;
297
298         if (str == NULL) {
299                 CERROR ("can't unpack string in msg %p buffer[%d]\n", m, index);
300                 return (NULL);
301         }
302
303         blen = m->buflens[index];
304         slen = strnlen (str, blen);
305
306         if (slen == blen) {                     /* not NULL terminated */
307                 CERROR ("can't unpack non-NULL terminated string in "
308                         "msg %p buffer[%d] len %d\n", m, index, blen);
309                 return (NULL);
310         }
311
312         if (max_len == 0) {
313                 if (slen != blen - 1) {
314                         CERROR ("can't unpack short string in msg %p "
315                                 "buffer[%d] len %d: strlen %d\n",
316                                 m, index, blen, slen);
317                         return (NULL);
318                 }
319         } else if (slen > max_len) {
320                 CERROR ("can't unpack oversized string in msg %p "
321                         "buffer[%d] len %d strlen %d: max %d expected\n",
322                         m, index, blen, slen, max_len);
323                 return (NULL);
324         }
325
326         return (str);
327 }
328
329 /* Wrap up the normal fixed length cases */
330 void *lustre_swab_buf(struct lustre_msg *msg, int index, int min_size,
331                       void *swabber)
332 {
333         void *ptr;
334
335         ptr = lustre_msg_buf(msg, index, min_size);
336         if (ptr == NULL)
337                 return NULL;
338
339         if (swabber != NULL && lustre_msg_swabbed(msg))
340                 ((void (*)(void *))swabber)(ptr);
341
342         return ptr;
343 }
344
345 void *lustre_swab_reqbuf(struct ptlrpc_request *req, int index, int min_size,
346                          void *swabber)
347 {
348         LASSERT_REQSWAB(req, index);
349         return lustre_swab_buf(req->rq_reqmsg, index, min_size, swabber);
350 }
351
352 void *lustre_swab_repbuf(struct ptlrpc_request *req, int index, int min_size,
353                          void *swabber)
354 {
355         LASSERT_REPSWAB(req, index);
356         return lustre_swab_buf(req->rq_repmsg, index, min_size, swabber);
357 }
358
359 /* byte flipping routines for all wire types declared in
360  * lustre_idl.h implemented here.
361  */
362
363 void lustre_swab_obdo (struct obdo  *o)
364 {
365         __swab64s (&o->o_id);
366         __swab64s (&o->o_gr);
367         __swab64s (&o->o_atime);
368         __swab64s (&o->o_mtime);
369         __swab64s (&o->o_ctime);
370         __swab64s (&o->o_size);
371         __swab64s (&o->o_blocks);
372         __swab64s (&o->o_grant);
373         __swab32s (&o->o_blksize);
374         __swab32s (&o->o_mode);
375         __swab32s (&o->o_uid);
376         __swab32s (&o->o_gid);
377         __swab32s (&o->o_flags);
378         __swab32s (&o->o_nlink);
379         __swab32s (&o->o_generation);
380         __swab32s (&o->o_valid);
381         __swab32s (&o->o_misc);
382         __swab32s (&o->o_easize);
383         __swab32s (&o->o_mds);
384         __swab64s (&o->o_fid);
385         /* o_inline is opaque */
386 }
387
388 /* mdc pack methods used by mdc and smfs*/
389 void *mdc_create_pack(struct lustre_msg *msg, int offset,
390                       struct mdc_op_data *op_data, __u32 mode,
391                       __u64 rdev, const void *data, int datalen)
392 {
393         struct mds_rec_create *rec;
394         char *tmp;
395         rec = lustre_msg_buf(msg, offset, sizeof (*rec));
396
397         rec->cr_opcode = REINT_CREATE;
398         rec->cr_id = op_data->id1;
399         memset(&rec->cr_replayid, 0, sizeof(rec->cr_replayid));
400         rec->cr_mode = mode;
401         rec->cr_rdev = rdev;
402         rec->cr_time = op_data->mod_time;
403
404         tmp = lustre_msg_buf(msg, offset + 1, op_data->namelen + 1);
405         LOGL0(op_data->name, op_data->namelen, tmp);
406
407         if (data) {
408                 tmp = lustre_msg_buf(msg, offset + 2, datalen);
409                 memcpy (tmp, data, datalen);
410         }
411         return ((void*)tmp + size_round(datalen));
412 }
413
414 void *mdc_setattr_pack(struct lustre_msg *msg, int offset,
415                        struct mdc_op_data *data, struct iattr *iattr,
416                        void *ea, int ealen, void *ea2, int ea2len)
417 {
418         struct mds_rec_setattr *rec = lustre_msg_buf(msg, offset, sizeof(*rec));
419         char *tmp = NULL;
420
421         rec->sa_opcode = REINT_SETATTR;
422         rec->sa_id = data->id1;
423
424         if (iattr) {
425                 rec->sa_valid = iattr->ia_valid;
426                 rec->sa_mode = iattr->ia_mode;
427                 rec->sa_uid = iattr->ia_uid;
428                 rec->sa_gid = iattr->ia_gid;
429                 rec->sa_size = iattr->ia_size;
430                 rec->sa_atime = LTIME_S(iattr->ia_atime);
431                 rec->sa_mtime = LTIME_S(iattr->ia_mtime);
432                 rec->sa_ctime = LTIME_S(iattr->ia_ctime);
433                 rec->sa_attr_flags = iattr->ia_attr_flags;
434         }
435         tmp = (char*)rec + size_round(sizeof(*rec));
436                 
437         if (ealen == 0)
438                 return (void*)tmp;
439
440         memcpy(lustre_msg_buf(msg, offset + 1, ealen), ea, ealen);
441         tmp += size_round(ealen);
442
443         if (ea2len == 0)
444                 return (void*)tmp;
445
446         memcpy(lustre_msg_buf(msg, offset + 2, ea2len), ea2, ea2len);
447         tmp += size_round(ea2len);
448         return (void*)tmp;
449 }
450
451 void *mdc_unlink_pack(struct lustre_msg *msg, int offset,
452                       struct mdc_op_data *data)
453 {
454         struct mds_rec_unlink *rec;
455         char *tmp;
456
457         rec = lustre_msg_buf(msg, offset, sizeof (*rec));
458         LASSERT (rec != NULL);
459
460         rec->ul_opcode = REINT_UNLINK;
461         rec->ul_mode = data->create_mode;
462         rec->ul_id1 = data->id1;
463         rec->ul_id2 = data->id2;
464         rec->ul_time = data->mod_time;
465
466         tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
467         LASSERT (tmp != NULL);
468         LOGL0(data->name, data->namelen, tmp);
469         return (void*)tmp;        
470 }
471
472 void *mdc_link_pack(struct lustre_msg *msg, int offset,
473                     struct mdc_op_data *data)
474 {
475         struct mds_rec_link *rec;
476         char *tmp;
477
478         rec = lustre_msg_buf(msg, offset, sizeof (*rec));
479
480         rec->lk_opcode = REINT_LINK;
481         rec->lk_id1 = data->id1;
482         rec->lk_id2 = data->id2;
483         rec->lk_time = data->mod_time;
484
485         tmp = lustre_msg_buf(msg, offset + 1, data->namelen + 1);
486         LOGL0(data->name, data->namelen, tmp);
487         
488         return (void*)tmp; 
489 }
490
491 void *mdc_rename_pack(struct lustre_msg *msg, int offset,
492                       struct mdc_op_data *data,
493                       const char *old, int oldlen,
494                       const char *new, int newlen)
495 {
496         struct mds_rec_rename *rec;
497         char *tmp;
498
499         rec = lustre_msg_buf(msg, offset, sizeof (*rec));
500
501         /* XXX do something about time, uid, gid */
502         rec->rn_opcode = REINT_RENAME;
503         rec->rn_id1 = data->id1;
504         rec->rn_id2 = data->id2;
505         rec->rn_time = data->mod_time;
506
507         tmp = lustre_msg_buf(msg, offset + 1, oldlen + 1);
508         LOGL0(old, oldlen, tmp);
509
510         if (new) {
511                 tmp = lustre_msg_buf(msg, offset + 2, newlen + 1);
512                 LOGL0(new, newlen, tmp);
513         }
514         return (void*)tmp;
515 }
516
517 void lustre_swab_obd_statfs (struct obd_statfs *os)
518 {
519         __swab64s (&os->os_type);
520         __swab64s (&os->os_blocks);
521         __swab64s (&os->os_bfree);
522         __swab64s (&os->os_bavail);
523         __swab64s (&os->os_ffree);
524         /* no need to swap os_fsid */
525         __swab32s (&os->os_bsize);
526         __swab32s (&os->os_namelen);
527         /* no need to swap os_spare */
528 }
529
530 void lustre_swab_obd_ioobj (struct obd_ioobj *ioo)
531 {
532         __swab64s (&ioo->ioo_id);
533         __swab64s (&ioo->ioo_gr);
534         __swab32s (&ioo->ioo_type);
535         __swab32s (&ioo->ioo_bufcnt);
536 }
537
538 void lustre_swab_niobuf_remote (struct niobuf_remote *nbr)
539 {
540         __swab64s (&nbr->offset);
541         __swab32s (&nbr->len);
542         __swab32s (&nbr->flags);
543 }
544
545 void lustre_swab_ost_body (struct ost_body *b)
546 {
547         lustre_swab_obdo (&b->oa);
548 }
549
550 void lustre_swab_ost_last_id(obd_id *id)
551 {
552         __swab64s(id);
553 }
554
555 void lustre_swab_generic_32s(__u32 *val)
556 {
557         __swab32s(val);
558 }
559
560 void lustre_swab_ost_lvb(struct ost_lvb *lvb)
561 {
562         __swab64s(&lvb->lvb_size);
563         __swab64s(&lvb->lvb_mtime);
564         __swab64s(&lvb->lvb_atime);
565         __swab64s(&lvb->lvb_ctime);
566         __swab64s(&lvb->lvb_blocks);
567 }
568
569 void lustre_swab_lustre_stc (struct lustre_stc *stc)
570 {
571         __swab64s (&stc->u.e3s.l3s_ino);
572         __swab32s (&stc->u.e3s.l3s_gen);
573         __swab32s (&stc->u.e3s.l3s_type);
574 }
575
576 void lustre_swab_lustre_fid(struct lustre_fid *fid)
577 {
578         __swab64s (&fid->lf_id);
579         __swab64s (&fid->lf_group);
580         __swab32s (&fid->lf_version);
581 }
582
583 void lustre_swab_lustre_id (struct lustre_id *id)
584 {
585         lustre_swab_lustre_stc(&id->li_stc);
586         lustre_swab_lustre_fid(&id->li_fid);
587 }
588
589 void lustre_swab_mds_status_req (struct mds_status_req *r)
590 {
591         __swab32s (&r->flags);
592         __swab32s (&r->repbuf);
593 }
594
595 /* 
596  * because sec_desc is variable buffer, we must check it by hand
597  */
598 struct mds_req_sec_desc *lustre_swab_mds_secdesc(struct ptlrpc_request *req,
599                                                  int offset)
600 {
601         struct mds_req_sec_desc *rsd;
602         struct lustre_msg *m;
603         __u32 i;
604
605         LASSERT_REQSWAB(req, offset);
606
607         m = req->rq_reqmsg;
608         rsd = lustre_msg_buf(m, offset, sizeof(*rsd));
609         if (!rsd)
610                 return NULL;
611
612         if (lustre_msg_swabbed(m)) {
613                 __swab32s(&rsd->rsd_uid);
614                 __swab32s(&rsd->rsd_gid);
615                 __swab32s(&rsd->rsd_fsuid);
616                 __swab32s(&rsd->rsd_fsgid);
617                 __swab32s(&rsd->rsd_cap);
618                 __swab32s(&rsd->rsd_ngroups);
619         }
620
621         if (m->buflens[offset] !=
622             sizeof(*rsd) + rsd->rsd_ngroups * sizeof(__u32)) {
623                 CERROR("bufflen %u while contains %u groups\n",
624                         m->buflens[offset], rsd->rsd_ngroups);
625                 return NULL;
626         }
627
628         if (lustre_msg_swabbed(m)) {
629                 for (i = 0; i < rsd->rsd_ngroups; i++)
630                         __swab32s(&rsd->rsd_groups[i]);
631         }
632
633         return rsd;
634 }
635
636 void lustre_swab_mds_body (struct mds_body *b)
637 {
638         lustre_swab_lustre_id (&b->id1);
639         lustre_swab_lustre_id (&b->id2);
640         /* handle is opaque */
641         __swab64s (&b->size);
642         __swab64s (&b->blocks);
643         __swab32s (&b->valid);
644         __swab32s (&b->mode);
645         __swab32s (&b->uid);
646         __swab32s (&b->gid);
647         __swab32s (&b->mtime);
648         __swab32s (&b->ctime);
649         __swab32s (&b->atime);
650         __swab32s (&b->flags);
651         __swab32s (&b->rdev);
652         __swab32s (&b->nlink);
653         __swab32s (&b->eadatasize);
654 }
655 void lustre_swab_mds_rec_setattr (struct mds_rec_setattr *sa)
656 {
657         __swab32s (&sa->sa_opcode);
658         __swab32s (&sa->sa_valid);
659         lustre_swab_lustre_id (&sa->sa_id);
660         __swab32s (&sa->sa_mode);
661         __swab32s (&sa->sa_uid);
662         __swab32s (&sa->sa_gid);
663         __swab32s (&sa->sa_attr_flags);
664         __swab64s (&sa->sa_size);
665         __swab64s (&sa->sa_atime);
666         __swab64s (&sa->sa_mtime);
667         __swab64s (&sa->sa_ctime);
668 }
669
670 void lustre_swab_mds_rec_create (struct mds_rec_create *cr)
671 {
672         __swab32s (&cr->cr_opcode);
673         __swab32s (&cr->cr_flags); /* for use with open */
674         __swab32s (&cr->cr_mode);
675         lustre_swab_lustre_id (&cr->cr_id);
676         lustre_swab_lustre_id (&cr->cr_replayid);
677         __swab64s (&cr->cr_time);
678         __swab64s (&cr->cr_rdev);
679 }
680
681 void lustre_swab_mds_rec_link (struct mds_rec_link *lk)
682 {
683         __swab32s (&lk->lk_opcode);
684         lustre_swab_lustre_id (&lk->lk_id1);
685         lustre_swab_lustre_id (&lk->lk_id2);
686 }
687
688 void lustre_swab_mds_rec_unlink (struct mds_rec_unlink *ul)
689 {
690         __swab32s (&ul->ul_opcode);
691         __swab32s (&ul->ul_mode);
692         lustre_swab_lustre_id (&ul->ul_id1);
693         lustre_swab_lustre_id (&ul->ul_id2);
694 }
695
696 void lustre_swab_mds_rec_rename (struct mds_rec_rename *rn)
697 {
698         __swab32s (&rn->rn_opcode);
699         lustre_swab_lustre_id (&rn->rn_id1);
700         lustre_swab_lustre_id (&rn->rn_id2);
701 }
702
703 void lustre_swab_lov_desc (struct lov_desc *ld)
704 {
705         __swab32s (&ld->ld_tgt_count);
706         __swab32s (&ld->ld_active_tgt_count);
707         __swab32s (&ld->ld_default_stripe_count);
708         __swab64s (&ld->ld_default_stripe_size);
709         __swab64s (&ld->ld_default_stripe_offset);
710         __swab32s (&ld->ld_pattern);
711         /* uuid endian insensitive */
712 }
713
714 void lustre_swab_ldlm_res_id (struct ldlm_res_id *id)
715 {
716         int  i;
717
718         for (i = 0; i < RES_NAME_SIZE; i++)
719                 __swab64s (&id->name[i]);
720 }
721
722 void lustre_swab_ldlm_policy_data (ldlm_policy_data_t *d)
723 {
724         /* the lock data is a union and the first three fields of both EXTENT
725          * and FLOCK types are __u64, so it's ok to swab them in the same way */
726         __swab64s (&d->l_flock.start);
727         __swab64s (&d->l_flock.end);
728         __swab64s (&d->l_flock.pid);
729         __swab64s (&d->l_flock.blocking_pid);
730 }
731
732 void lustre_swab_ldlm_intent (struct ldlm_intent *i)
733 {
734         __swab64s (&i->opc);
735 }
736
737 void lustre_swab_ldlm_resource_desc (struct ldlm_resource_desc *r)
738 {
739         __swab32s (&r->lr_type);
740         lustre_swab_ldlm_res_id (&r->lr_name);
741 }
742
743 void lustre_swab_ldlm_lock_desc (struct ldlm_lock_desc *l)
744 {
745         lustre_swab_ldlm_resource_desc (&l->l_resource);
746         __swab32s (&l->l_req_mode);
747         __swab32s (&l->l_granted_mode);
748         lustre_swab_ldlm_policy_data (&l->l_policy_data);
749 }
750
751 void lustre_swab_ldlm_request (struct ldlm_request *rq)
752 {
753         __swab32s (&rq->lock_flags);
754         lustre_swab_ldlm_lock_desc (&rq->lock_desc);
755         /* lock_handle1 opaque */
756         /* lock_handle2 opaque */
757 }
758
759 void lustre_swab_ldlm_reply (struct ldlm_reply *r)
760 {
761         __swab32s (&r->lock_flags);
762         lustre_swab_ldlm_lock_desc (&r->lock_desc);
763         /* lock_handle opaque */
764         __swab64s (&r->lock_policy_res1);
765         __swab64s (&r->lock_policy_res2);
766 }
767
768 void lustre_swab_ptlbd_op (struct ptlbd_op *op)
769 {
770         __swab16s (&op->op_cmd);
771         __swab16s (&op->op_lun);
772         __swab16s (&op->op_niob_cnt);
773         /* ignore op__padding */
774         __swab32s (&op->op_block_cnt);
775 }
776
777 void lustre_swab_ptlbd_niob (struct ptlbd_niob *n)
778 {
779         __swab64s (&n->n_xid);
780         __swab64s (&n->n_block_nr);
781         __swab32s (&n->n_offset);
782         __swab32s (&n->n_length);
783 }
784
785 void lustre_swab_ptlbd_rsp (struct ptlbd_rsp *r)
786 {
787         __swab16s (&r->r_status);
788         __swab16s (&r->r_error_cnt);
789 }
790
791 /* no one calls this */
792 int llog_log_swabbed(struct llog_log_hdr *hdr)
793 {
794         if (hdr->llh_hdr.lrh_type == __swab32(LLOG_HDR_MAGIC))
795                 return 1;
796         if (hdr->llh_hdr.lrh_type == LLOG_HDR_MAGIC)
797                 return 0;
798         return -1;
799 }
800
801 void lustre_swab_llogd_body (struct llogd_body *d)
802 {
803         __swab64s (&d->lgd_logid.lgl_oid);
804         __swab64s (&d->lgd_logid.lgl_ogr);
805         __swab32s (&d->lgd_logid.lgl_ogen);
806         __swab32s (&d->lgd_ctxt_idx);
807         __swab32s (&d->lgd_llh_flags);
808         __swab32s (&d->lgd_index);
809         __swab32s (&d->lgd_saved_index);
810         __swab32s (&d->lgd_len);
811         __swab64s (&d->lgd_cur_offset);
812 }
813
814 void lustre_swab_llog_hdr (struct llog_log_hdr *h)
815 {
816         __swab32s (&h->llh_hdr.lrh_index);
817         __swab32s (&h->llh_hdr.lrh_len);
818         __swab32s (&h->llh_hdr.lrh_type);
819         __swab64s (&h->llh_timestamp);
820         __swab32s (&h->llh_count);
821         __swab32s (&h->llh_bitmap_offset);
822         __swab32s (&h->llh_flags);
823         __swab32s (&h->llh_tail.lrt_index);
824         __swab32s (&h->llh_tail.lrt_len);
825 }
826
827 void lustre_swab_llogd_conn_body (struct llogd_conn_body *d)
828 {
829         __swab64s (&d->lgdc_gen.mnt_cnt);
830         __swab64s (&d->lgdc_gen.conn_cnt);
831         __swab64s (&d->lgdc_logid.lgl_oid);
832         __swab64s (&d->lgdc_logid.lgl_ogr);
833         __swab32s (&d->lgdc_logid.lgl_ogen);
834         __swab32s (&d->lgdc_ctxt_idx);
835 }
836
837 void lustre_assert_wire_constants(void)
838 {
839 }
840