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 MDS and OST request records
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/lustre_lib.h>
50 #include <linux/lustre_idl.h>
51 #include <linux/lustre_mds.h>
54 int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen,
55 struct mds_req_hdr **hdr, struct mds_req **req,
59 struct mds_req_packed *preq;
61 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
64 *buf = kmalloc(*len, GFP_KERNEL);
70 memset(*buf, 0, *len);
71 *hdr = (struct mds_req_hdr *)(*buf);
73 preq = (struct mds_req_packed *)(*buf + sizeof(**hdr));
74 ptr = *buf + sizeof(**hdr) + sizeof(*preq);
76 (*hdr)->type = MDS_TYPE_REQ;
78 (*req)->namelen = NTOH__u32(namelen);
80 preq->name_offset = (__u32)(ptr - (char *)preq);
81 LOGL(name, namelen, ptr);
84 (*req)->tgtlen = NTOH__u32(tgtlen);
86 preq->tgt_offset = (__u32)(ptr - (char *)preq);
87 LOGL(tgt, tgtlen, ptr);
93 int mds_unpack_req(char *buf, int len,
94 struct mds_req_hdr **hdr, struct mds_req **req)
96 struct mds_req_packed *preq;
100 if (len < sizeof(**hdr) + sizeof(**req)) {
105 *hdr = (struct mds_req_hdr *) (buf);
106 preq = (struct mds_req_packed *) (buf + sizeof(**hdr));
107 off1 = preq->name_offset;
108 off2 = preq->tgt_offset;
110 *req = (struct mds_req *) (buf + sizeof(**hdr));
111 (*req)->namelen = NTOH__u32((*req)->namelen);
112 (*req)->tgtlen = NTOH__u32((*req)->namelen);
114 if (len < sizeof(**hdr) + sizeof(**req) + (*req)->namelen +
120 if ((*req)->namelen) {
121 name = buf + sizeof(**hdr) + off1;
126 if ((*req)->tgtlen) {
127 tgt = buf + sizeof(**hdr) + off2;
138 int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen,
139 struct mds_rep_hdr **hdr, struct mds_rep **rep,
140 int *len, char **buf)
143 struct mds_rep_packed *prep;
145 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
148 *buf = kmalloc(*len, GFP_KERNEL);
154 memset(*buf, 0, *len);
155 *hdr = (struct mds_rep_hdr *)(*buf);
157 prep = (struct mds_rep_packed *)(*buf + sizeof(**hdr));
158 ptr = *buf + sizeof(**hdr) + sizeof(*prep);
160 (*hdr)->type = MDS_TYPE_REP;
162 (*rep)->namelen = NTOH__u32(namelen);
164 prep->name_offset = (__u32)(ptr - (char *)prep);
165 LOGL(name, namelen, ptr);
168 (*rep)->tgtlen = NTOH__u32(tgtlen);
170 prep->tgt_offset = (__u32)(ptr - (char *)prep);
171 LOGL(tgt, tgtlen, ptr);
177 int mds_unpack_rep(char *buf, int len,
178 struct mds_rep_hdr **hdr, struct mds_rep **rep)
180 struct mds_rep_packed *prep;
183 if (len < sizeof(**hdr) + sizeof(**rep)) {
188 *hdr = (struct mds_rep_hdr *) (buf);
189 prep = (struct mds_rep_packed *) (buf + sizeof(**hdr));
190 off1 = prep->name_offset;
191 off2 = prep->tgt_offset;
193 *rep = (struct mds_rep *) (buf + sizeof(**hdr));
194 (*rep)->namelen = NTOH__u32((*rep)->namelen);
195 (*rep)->tgtlen = NTOH__u32((*rep)->namelen);
197 if (len < sizeof(**hdr) + sizeof(**rep) + (*rep)->namelen +
203 if ((*rep)->namelen) {
204 (*rep)->name = buf + sizeof(**hdr) + off1;
209 if ((*rep)->tgtlen) {
210 (*rep)->tgt = buf + sizeof(**hdr) + off2;
221 int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen,
222 struct mds_rep_hdr **hdr, struct mds_rep **rep,
223 int *len, char **buf)
227 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
230 *buf = kmalloc(*len, GFP_KERNEL);
236 memset(*buf, 0, *len);
237 *hdr = (struct mds_rep_hdr *)(*buf);
238 *rep = (struct mds_rep *)(*buf + sizeof(**hdr));
239 ptr = *buf + sizeof(**hdr) + sizeof(**rep);
241 (*rep)->namelen = NTOH__u32(namelen);
243 LOGL(name, namelen, ptr);
246 (*rep)->tgtlen = NTOH__u32(tgtlen);
248 LOGL(tgt, tgtlen, ptr);
254 int mds_unpack_rep(char *buf, int len,
255 struct mds_rep_hdr **hdr, struct mds_rep **rep)
257 if (len < sizeof(**hdr) + sizeof(**rep)) {
262 *hdr = (struct mds_rep_hdr *) (buf);
263 *rep = (struct mds_rep *) (buf + sizeof(**hdr));
264 (*rep)->namelen = NTOH__u32((*rep)->namelen);
265 (*rep)->tgtlen = NTOH__u32((*rep)->namelen);
267 if (len < sizeof(**hdr) + sizeof(**rep) + (*rep)->namelen +
273 if ((*rep)->namelen) {
274 (*rep)->name = buf + sizeof(**hdr) + sizeof(**rep);
279 if ((*rep)->tgtlen) {
280 (*rep)->tgt = buf + sizeof(**hdr) + sizeof(**rep) +
281 size_round((*rep)->namelen);