1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
21 * (Un)packing of OST requests
25 #include <linux/module.h>
26 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/major.h>
29 #include <linux/sched.h>
31 #include <linux/slab.h>
32 #include <linux/ioport.h>
33 #include <linux/fcntl.h>
34 #include <linux/delay.h>
35 #include <linux/skbuff.h>
36 #include <linux/proc_fs.h>
38 #include <linux/poll.h>
39 #include <linux/init.h>
40 #include <linux/list.h>
42 #include <asm/segment.h>
43 #include <asm/system.h>
45 #include <asm/uaccess.h>
47 #define DEBUG_SUBSYSTEM S_OST
49 #include <linux/obd_support.h>
50 #include <linux/obd_class.h>
51 #include <linux/obd_ost.h>
52 #include <linux/lustre_lib.h>
53 #include <linux/lustre_idl.h>
55 int ost_pack_req(char *buf1, int buflen1, char *buf2, int buflen2,
56 struct ptlreq_hdr **hdr, union ptl_req *r,
62 *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) +
65 OBD_ALLOC(*buf, *len);
71 memset(*buf, 0, *len);
72 *hdr = (struct ptlreq_hdr *)(*buf);
73 req = (struct ost_req *)(*buf + sizeof(**hdr));
76 ptr = *buf + sizeof(**hdr) + sizeof(*req);
78 (*hdr)->type = OST_TYPE_REQ;
80 req->buflen1 = HTON__u32(buflen1);
82 LOGL(buf1, buflen1, ptr);
85 req->buflen2 = HTON__u32(buflen2);
87 LOGL(buf2, buflen2, ptr);
92 int ost_unpack_req(char *buf, int len,
93 struct ptlreq_hdr **hdr, union ptl_req *r)
97 if (len < sizeof(**hdr) + sizeof(*req)) {
102 *hdr = (struct ptlreq_hdr *) (buf);
103 req = (struct ost_req *) (buf + sizeof(**hdr));
106 req->buflen1 = NTOH__u32(req->buflen1);
107 req->buflen2 = NTOH__u32(req->buflen2);
109 if (len < sizeof(**hdr) + sizeof(*req) +
110 size_round(req->buflen1) + size_round(req->buflen2) ) {
120 void *ost_req_buf1(struct ost_req *req)
124 return (void *)((char *)req + sizeof(*req));
127 void *ost_req_buf2(struct ost_req *req)
131 return (void *)((char *)req + sizeof(*req) +
132 size_round(req->buflen1));
135 int ost_pack_rep(char *buf1, int buflen1, char *buf2, int buflen2,
136 struct ptlrep_hdr **hdr, union ptl_rep *r,
137 int *len, char **buf)
142 *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) +
145 OBD_ALLOC(*buf, *len);
151 memset(*buf, 0, *len);
152 *hdr = (struct ptlrep_hdr *)(*buf);
153 rep = (struct ost_rep *)(*buf + sizeof(**hdr));
156 ptr = *buf + sizeof(**hdr) + sizeof(*rep);
158 rep->buflen1 = HTON__u32(buflen1);
160 LOGL(buf1, buflen1, ptr);
162 ptr += size_round(buflen1);
165 rep->buflen2 = HTON__u32(buflen2);
167 LOGL(buf2, buflen2, ptr);
173 int ost_unpack_rep(char *buf, int len,
174 struct ptlrep_hdr **hdr, union ptl_rep *r)
178 if (len < sizeof(**hdr) + sizeof(*rep)) {
183 *hdr = (struct ptlrep_hdr *) (buf);
184 rep = (struct ost_rep *) (buf + sizeof(**hdr));
187 rep->buflen1 = NTOH__u32(rep->buflen1);
188 rep->buflen2 = NTOH__u32(rep->buflen2);
190 if (len < sizeof(**hdr) + sizeof(*rep) +
191 size_round(rep->buflen1) + size_round(rep->buflen2) ) {
200 void *ost_rep_buf1(struct ost_rep *rep)
204 return (void *)((char *)rep + sizeof(*rep));
207 void *ost_rep_buf2(struct ost_rep *rep)
211 return (void *)((char *)rep + sizeof(*rep) +
212 size_round(rep->buflen1));
215 void ost_pack_ioo(void **tmp, struct obdo *oa, int bufcnt)
217 struct obd_ioobj *ioo = *tmp;
220 ioo->ioo_id = HTON__u64(oa->o_id);
221 ioo->ioo_gr = HTON__u64(oa->o_gr);
222 ioo->ioo_type = HTON__u64(oa->o_mode);
223 ioo->ioo_bufcnt = HTON__u32(bufcnt);
224 *tmp = c + sizeof(*ioo);
227 void ost_unpack_ioo(void **tmp, struct obd_ioobj **ioop)
230 struct obd_ioobj *ioo = *tmp;
233 ioo->ioo_id = NTOH__u64(ioo->ioo_id);
234 ioo->ioo_gr = NTOH__u64(ioo->ioo_gr);
235 ioo->ioo_type = NTOH__u64(ioo->ioo_type);
236 ioo->ioo_bufcnt = NTOH__u32(ioo->ioo_bufcnt);
237 *tmp = c + sizeof(*ioo);
240 void ost_pack_niobuf(void **tmp, void *addr, __u64 offset, __u32 len,
241 __u32 flags, __u32 xid)
243 struct niobuf *ioo = *tmp;
246 ioo->addr = HTON__u64((__u64)(unsigned long)addr);
247 ioo->offset = HTON__u64(offset);
248 ioo->len = HTON__u32(len);
249 ioo->flags = HTON__u32(flags);
250 ioo->xid = HTON__u32(xid);
251 *tmp = c + sizeof(*ioo);
254 void ost_unpack_niobuf(void **tmp, struct niobuf **nbp)
257 struct niobuf *nb = *tmp;
261 nb->addr = NTOH__u64(nb->addr);
262 nb->offset = NTOH__u64(nb->offset);
263 nb->len = NTOH__u32(nb->len);
264 nb->flags = NTOH__u32(nb->flags);
266 *tmp = c + sizeof(*nb);