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>
37 #include <linux/vmalloc.h>
39 #include <linux/poll.h>
40 #include <linux/init.h>
41 #include <linux/list.h>
43 #include <asm/segment.h>
44 #include <asm/system.h>
46 #include <asm/uaccess.h>
48 #include <linux/obd_support.h>
49 #include <linux/obd_class.h>
50 #include <linux/obd_ost.h>
51 #include <linux/lustre_lib.h>
52 #include <linux/lustre_idl.h>
55 int ost_pack_req(char *buf1, int buflen1, char *buf2, int buflen2,
56 struct ptlreq_hdr **hdr, struct ost_req **req,
61 *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) +
64 *buf = kmalloc(*len, GFP_KERNEL);
70 memset(*buf, 0, *len);
71 *hdr = (struct ptlreq_hdr *)(*buf);
72 *req = (struct ost_req *)(*buf + sizeof(**hdr));
74 ptr = *buf + sizeof(**hdr) + sizeof(**req);
76 (*hdr)->type = OST_TYPE_REQ;
78 (*req)->buflen1 = NTOH__u32(buflen1);
80 LOGL(buf1, buflen1, ptr);
83 (*req)->buflen2 = NTOH__u32(buflen2);
85 LOGL(buf2, buflen2, ptr);
90 int ost_unpack_req(char *buf, int len,
91 struct ptlreq_hdr **hdr, struct ost_req **req)
94 if (len < sizeof(**hdr) + sizeof(**req)) {
99 *hdr = (struct ptlreq_hdr *) (buf);
100 *req = (struct ost_req *) (buf + sizeof(**hdr));
102 (*req)->buflen1 = NTOH__u32((*req)->buflen1);
103 (*req)->buflen2 = NTOH__u32((*req)->buflen2);
105 if (len < sizeof(**hdr) + sizeof(**req) +
106 size_round((*req)->buflen1) + size_round((*req)->buflen2) ) {
116 void *ost_req_buf1(struct ost_req *req)
120 return (void *)((char *)req + sizeof(*req));
123 void *ost_req_buf2(struct ost_req *req)
127 return (void *)((char *)req + sizeof(*req) +
128 size_round(req->buflen1));
131 int ost_pack_rep(void *buf1, __u32 buflen1, void *buf2, __u32 buflen2,
132 struct ptlrep_hdr **hdr, struct ost_rep **rep,
133 int *len, char **buf)
137 *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) +
140 *buf = kmalloc(*len, GFP_KERNEL);
146 memset(*buf, 0, *len);
147 *hdr = (struct ptlrep_hdr *)(*buf);
148 *rep = (struct ost_rep *)(*buf + sizeof(**hdr));
149 ptr = *buf + sizeof(**hdr) + sizeof(**rep);
151 (*rep)->buflen1 = NTOH__u32(buflen1);
153 LOGL(buf1, buflen1, ptr);
156 (*rep)->buflen2 = NTOH__u32(buflen2);
158 LOGL(buf2, buflen2, ptr);
164 int ost_unpack_rep(char *buf, int len,
165 struct ptlrep_hdr **hdr, struct ost_rep **rep)
167 if (len < sizeof(**hdr) + sizeof(**rep)) {
172 *hdr = (struct ptlrep_hdr *) (buf);
173 *rep = (struct ost_rep *) (buf + sizeof(**hdr));
175 (*rep)->buflen1 = NTOH__u32((*rep)->buflen1);
176 (*rep)->buflen2 = NTOH__u32((*rep)->buflen2);
178 if (len < sizeof(**hdr) + sizeof(**rep) +
179 size_round((*rep)->buflen1) + size_round((*rep)->buflen2) ) {
188 void *ost_rep_buf1(struct ost_rep *rep)
192 return (void *)((char *)rep + sizeof(*rep));
195 void *ost_rep_buf2(struct ost_rep *rep)
199 return (void *)((char *)rep + sizeof(*rep) +
200 size_round(rep->buflen1));
203 void ost_pack_ioo(void **tmp, struct obdo *oa, int bufcnt)
205 struct obd_ioobj *ioo = *tmp;
208 ioo->ioo_id = NTOH__u64(oa->o_id);
209 ioo->ioo_gr = NTOH__u64(oa->o_gr);
210 ioo->ioo_type = NTOH__u64(oa->o_mode);
211 ioo->ioo_bufcnt = NTOH__u32(bufcnt);
212 *tmp = c + sizeof(*ioo);
215 void ost_unpack_ioo(void **tmp, struct obd_ioobj **ioop)
218 struct obd_ioobj *ioo = *tmp;
221 ioo->ioo_id = NTOH__u64(ioo->ioo_id);
222 ioo->ioo_gr = NTOH__u64(ioo->ioo_gr);
223 ioo->ioo_type = NTOH__u64(ioo->ioo_type);
224 ioo->ioo_bufcnt = NTOH__u32(ioo->ioo_bufcnt);
225 *tmp = c + sizeof(*ioo);
228 void ost_pack_niobuf(void **tmp, void *addr, __u64 offset, __u32 len,
231 struct niobuf *ioo = *tmp;
234 ioo->addr = NTOH__u64((__u64)(unsigned long)addr);
235 ioo->offset = NTOH__u64(offset);
236 ioo->len = NTOH__u32(len);
237 ioo->flags = NTOH__u32(flags);
238 *tmp = c + sizeof(*ioo);
241 void ost_unpack_niobuf(void **tmp, struct niobuf **nbp)
244 struct niobuf *nb = *tmp;
248 nb->addr = NTOH__u64((__u64)(unsigned long)nb->addr);
249 nb->offset = NTOH__u64(nb->offset);
250 nb->len = NTOH__u32(nb->len);
251 nb->flags = NTOH__u32(nb->flags);
253 *tmp = c + sizeof(*nb);