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_class.h>
50 #include <linux/obd_ost.h>
51 #include <linux/lustre_net.h>
53 int ost_pack_req(char *buf1, int buflen1, char *buf2, int buflen2,
54 struct ptlreq_hdr **hdr, union ptl_req *r,
60 *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) +
63 OBD_ALLOC(*buf, *len);
68 memset(*buf, 0, *len);
69 *hdr = (struct ptlreq_hdr *)(*buf);
70 req = (struct ost_req *)((*buf) + sizeof(**hdr));
73 ptr = *buf + sizeof(**hdr) + sizeof(*req);
75 (*hdr)->type = PTL_RPC_REQUEST;
77 req->buflen1 = HTON__u32(buflen1);
78 LOGL(buf1, buflen1, ptr);
80 req->buflen2 = HTON__u32(buflen2);
81 LOGL(buf2, buflen2, ptr);
86 int ost_unpack_req(char *buf, int len,
87 struct ptlreq_hdr **hdr, union ptl_req *r)
91 if (len < sizeof(**hdr) + sizeof(*req)) {
95 *hdr = (struct ptlreq_hdr *) (buf);
96 req = (struct ost_req *) (buf + sizeof(**hdr));
99 req->buflen1 = NTOH__u32(req->buflen1);
100 req->buflen2 = NTOH__u32(req->buflen2);
102 if (len < sizeof(**hdr) + sizeof(*req) +
103 size_round(req->buflen1) + size_round(req->buflen2) ) {
111 void *ost_req_buf1(struct ost_req *req)
115 return (void *)((char *)req + sizeof(*req));
118 void *ost_req_buf2(struct ost_req *req)
122 return (void *)((char *)req + sizeof(*req) +
123 size_round(req->buflen1));
126 int ost_pack_rep(char *buf1, int buflen1, char *buf2, int buflen2,
127 struct ptlrep_hdr **hdr, union ptl_rep *r,
128 int *len, char **buf)
133 *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) +
136 OBD_ALLOC(*buf, *len);
142 memset(*buf, 0, *len);
143 *hdr = (struct ptlrep_hdr *)(*buf);
144 rep = (struct ost_rep *)(*buf + sizeof(**hdr));
147 ptr = *buf + sizeof(**hdr) + sizeof(*rep);
149 rep->buflen1 = HTON__u32(buflen1);
151 LOGL(buf1, buflen1, ptr);
153 ptr += size_round(buflen1);
156 rep->buflen2 = HTON__u32(buflen2);
158 LOGL(buf2, buflen2, ptr);
164 int ost_unpack_rep(char *buf, int len,
165 struct ptlrep_hdr **hdr, union ptl_rep *r)
169 if (len < sizeof(**hdr) + sizeof(*rep)) {
174 *hdr = (struct ptlrep_hdr *) (buf);
175 rep = (struct ost_rep *) (buf + sizeof(**hdr));
178 rep->buflen1 = NTOH__u32(rep->buflen1);
179 rep->buflen2 = NTOH__u32(rep->buflen2);
181 if (len < sizeof(**hdr) + sizeof(*rep) +
182 size_round(rep->buflen1) + size_round(rep->buflen2) ) {
191 void *ost_rep_buf1(struct ost_rep *rep)
195 return (void *)((char *)rep + sizeof(*rep));
198 void *ost_rep_buf2(struct ost_rep *rep)
202 return (void *)((char *)rep + sizeof(*rep) +
203 size_round(rep->buflen1));
206 void ost_pack_ioo(void **tmp, struct obdo *oa, int bufcnt)
208 struct obd_ioobj *ioo = *tmp;
211 ioo->ioo_id = HTON__u64(oa->o_id);
212 ioo->ioo_gr = HTON__u64(oa->o_gr);
213 ioo->ioo_type = HTON__u64(oa->o_mode);
214 ioo->ioo_bufcnt = HTON__u32(bufcnt);
215 *tmp = c + sizeof(*ioo);
218 void ost_unpack_ioo(void **tmp, struct obd_ioobj **ioop)
221 struct obd_ioobj *ioo = *tmp;
224 ioo->ioo_id = NTOH__u64(ioo->ioo_id);
225 ioo->ioo_gr = NTOH__u64(ioo->ioo_gr);
226 ioo->ioo_type = NTOH__u64(ioo->ioo_type);
227 ioo->ioo_bufcnt = NTOH__u32(ioo->ioo_bufcnt);
228 *tmp = c + sizeof(*ioo);
231 void ost_pack_niobuf(void **tmp, void *addr, __u64 offset, __u32 len,
232 __u32 flags, __u32 xid)
234 struct niobuf *ioo = *tmp;
237 ioo->addr = HTON__u64((__u64)(unsigned long)addr);
238 ioo->offset = HTON__u64(offset);
239 ioo->len = HTON__u32(len);
240 ioo->flags = HTON__u32(flags);
241 ioo->xid = HTON__u32(xid);
242 *tmp = c + sizeof(*ioo);
245 void ost_unpack_niobuf(void **tmp, struct niobuf **nbp)
248 struct niobuf *nb = *tmp;
252 nb->addr = NTOH__u64(nb->addr);
253 nb->offset = NTOH__u64(nb->offset);
254 nb->len = NTOH__u32(nb->len);
255 nb->flags = NTOH__u32(nb->flags);
257 *tmp = c + sizeof(*nb);