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 ost_req_hdr **hdr, struct ost_req **req,
60 struct ost_req_packed *preq;
62 *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) +
65 *buf = kmalloc(*len, GFP_KERNEL);
71 memset(*buf, 0, *len);
72 *hdr = (struct ost_req_hdr *)(*buf);
74 preq = (struct ost_req_packed *)(*buf + sizeof(**hdr));
75 ptr = *buf + sizeof(**hdr) + sizeof(*preq);
77 *req = (struct ost_req *)(*buf + sizeof(**hdr));
79 (*hdr)->type = OST_TYPE_REQ;
81 (*req)->buflen1 = NTOH__u32(buflen1);
83 preq->bufoffset1 = (__u32)(ptr - (char *)preq);
84 LOGL(buf1, buflen1, ptr);
87 (*req)->buflen2 = NTOH__u32(buflen2);
89 preq->bufoffset2 = (__u32)(ptr - (char *)preq);
90 LOGL(buf2, buflen2, ptr);
95 int ost_unpack_req(char *buf, int len,
96 struct ost_req_hdr **hdr, struct ost_req **req)
98 struct ost_req_packed *reqp;
101 if (len < sizeof(**hdr) + sizeof(*reqp)) {
106 *hdr = (struct ost_req_hdr *) (buf);
107 reqp = (struct ost_req_packed *) (buf + sizeof(**hdr));
108 *req = (struct ost_req *) (buf + sizeof(**hdr));
110 (*req)->buflen1 = NTOH__u32(reqp->buflen1);
111 (*req)->buflen2 = NTOH__u32(reqp->buflen2);
112 off1 = NTOH__u32(reqp->bufoffset1);
113 off2 = NTOH__u32(reqp->bufoffset2);
115 if (len < sizeof(**hdr) + sizeof(*reqp) + size_round(reqp->buflen1) +
116 size_round(reqp->buflen2) ) {
121 if ((*req)->buflen1) {
122 (*req)->buf1 = (buf + sizeof(**hdr) + off1);
126 if ((*req)->buflen2) {
127 (*req)->buf2 = (buf + sizeof(**hdr) + off2);
136 int ost_pack_rep(void *buf1, __u32 buflen1, void *buf2, __u32 buflen2,
137 struct ost_rep_hdr **hdr, struct ost_rep **rep,
138 int *len, char **buf)
142 *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) +
145 *buf = kmalloc(*len, GFP_KERNEL);
151 memset(*buf, 0, *len);
152 *hdr = (struct ost_rep_hdr *)(*buf);
153 *rep = (struct ost_rep *)(*buf + sizeof(**hdr));
154 ptr = *buf + sizeof(**hdr) + sizeof(**rep);
156 (*rep)->buflen1 = NTOH__u32(buflen1);
158 LOGL(buf1, buflen1, ptr);
161 (*rep)->buflen2 = NTOH__u32(buflen2);
163 LOGL(buf2, buflen2, ptr);
169 int ost_unpack_rep(char *buf, int len,
170 struct ost_rep_hdr **hdr, struct ost_rep **rep)
172 struct ost_rep_packed *prep;
175 if (len < sizeof(**hdr) + sizeof(**rep)) {
180 *hdr = (struct ost_rep_hdr *) (buf);
181 *rep = (struct ost_rep *) (buf + sizeof(**hdr));
182 prep = (struct ost_rep_packed *) (buf + sizeof(**hdr));
183 (*rep)->buflen1 = NTOH__u32(prep->buflen1);
184 (*rep)->buflen2 = NTOH__u32(prep->buflen2);
185 off1 = prep->bufoffset1;
186 off2 = prep->bufoffset2;
188 if (len < sizeof(**hdr) + sizeof(*prep) + size_round((*rep)->buflen1) +
189 size_round((*rep)->buflen2) ) {
194 if ((*rep)->buflen1) {
195 (*rep)->buf1 = (buf + sizeof(**hdr) + off1);
199 if ((*rep)->buflen2) {
200 (*rep)->buf2 = (buf + sizeof(**hdr) + off2);