Whamcloud - gitweb
8b3c33a6674fb054235e723f50dafc908467177d
[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
27 #include <linux/obd_ost.h>
28 #include <linux/lustre_net.h>
29
30 void ost_pack_ioo(void **tmp, struct lov_stripe_md *lsm, int bufcnt)
31 {
32         struct obd_ioobj *ioo = *tmp;
33         char *c = *tmp;
34
35         ioo->ioo_id = HTON__u64(lsm->lsm_object_id);
36         ioo->ioo_gr = HTON__u64(0);
37         ioo->ioo_type = HTON__u32(S_IFREG);
38         ioo->ioo_bufcnt = HTON__u32(bufcnt);
39         *tmp = c + sizeof(*ioo);
40 }
41
42 void ost_unpack_ioo(void **tmp, struct obd_ioobj **ioop)
43 {
44         char *c = *tmp;
45         struct obd_ioobj *ioo = *tmp;
46         *ioop = *tmp;
47
48         ioo->ioo_id = NTOH__u64(ioo->ioo_id);
49         ioo->ioo_gr = NTOH__u64(ioo->ioo_gr);
50         ioo->ioo_type = NTOH__u32(ioo->ioo_type);
51         ioo->ioo_bufcnt = NTOH__u32(ioo->ioo_bufcnt);
52         *tmp = c + sizeof(*ioo);
53 }
54
55 void ost_pack_niobuf(void **tmp, __u64 offset, __u32 len, __u32 flags,
56                      __u32 xid)
57 {
58         struct niobuf_remote *nb = *tmp;
59         char *c = *tmp;
60
61         nb->offset = HTON__u64(offset);
62         nb->len = HTON__u32(len);
63         nb->flags = HTON__u32(flags);
64         nb->xid = HTON__u32(xid);
65         *tmp = c + sizeof(*nb);
66 }
67
68 void ost_unpack_niobuf(void **tmp, struct niobuf_remote **nbp)
69 {
70         char *c = *tmp;
71         struct niobuf_remote *nb = *tmp;
72
73         *nbp = *tmp;
74
75         nb->offset = NTOH__u64(nb->offset);
76         nb->len = NTOH__u32(nb->len);
77         nb->flags = NTOH__u32(nb->flags);
78
79         *tmp = c + sizeof(*nb);
80 }