Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[fs/lustre-release.git] / lustre / lib / obd_pack.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * (Un)packing of OST requests
22  *
23  */
24
25 #define DEBUG_SUBSYSTEM S_OST
26 #ifndef __KERNEL__
27 #include <liblustre.h>
28 #endif
29
30 #include <linux/obd_ost.h>
31 #include <linux/lustre_net.h>
32
33 void ost_pack_ioo(struct obd_ioobj **tmp, struct lov_stripe_md *lsm,int bufcnt)
34 {
35         struct obd_ioobj *ioo = *tmp;
36         void *p = *tmp;
37
38         ioo->ioo_id = HTON__u64(lsm->lsm_object_id);
39         ioo->ioo_gr = HTON__u64(0);
40         ioo->ioo_type = HTON__u32(S_IFREG);
41         ioo->ioo_bufcnt = HTON__u32(bufcnt);
42         *tmp = p + sizeof(*ioo);
43 }
44
45 void ost_unpack_ioo(struct obd_ioobj **tmp, struct obd_ioobj **ioop)
46 {
47         void *p = *tmp;
48         struct obd_ioobj *ioo = *tmp;
49         *ioop = *tmp;
50
51         ioo->ioo_id = NTOH__u64(ioo->ioo_id);
52         ioo->ioo_gr = NTOH__u64(ioo->ioo_gr);
53         ioo->ioo_type = NTOH__u32(ioo->ioo_type);
54         ioo->ioo_bufcnt = NTOH__u32(ioo->ioo_bufcnt);
55         *tmp = p + sizeof(*ioo);
56 }
57
58 void ost_pack_niobuf(void **tmp, __u64 offset, __u32 len, __u32 flags,
59                      __u32 xid)
60 {
61         struct niobuf_remote *nb = *tmp;
62         char *c = *tmp;
63
64         nb->offset = HTON__u64(offset);
65         nb->len = HTON__u32(len);
66         nb->flags = HTON__u32(flags);
67         nb->xid = HTON__u32(xid);
68         *tmp = c + sizeof(*nb);
69 }
70
71 void ost_unpack_niobuf(void **tmp, struct niobuf_remote **nbp)
72 {
73         char *c = *tmp;
74         struct niobuf_remote *nb = *tmp;
75
76         *nbp = *tmp;
77
78         nb->offset = NTOH__u64(nb->offset);
79         nb->len = NTOH__u32(nb->len);
80         nb->flags = NTOH__u32(nb->flags);
81
82         *tmp = c + sizeof(*nb);
83 }