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);
72 *req = (struct mds_req *)(*buf + sizeof(**hdr));
74 preq = (struct mds_req_packed *)(*buf + sizeof(**hdr));
75 ptr = *buf + sizeof(**hdr) + sizeof(*preq);
77 (*hdr)->type = MDS_TYPE_REQ;
79 (*req)->namelen = NTOH__u32(namelen);
81 preq->name_offset = (__u32)(ptr - (char *)preq);
82 LOGL(name, namelen, ptr);
85 (*req)->tgtlen = NTOH__u32(tgtlen);
87 preq->tgt_offset = (__u32)(ptr - (char *)preq);
88 LOGL(tgt, tgtlen, ptr);
94 int mds_unpack_req(char *buf, int len,
95 struct mds_req_hdr **hdr, struct mds_req **req)
97 struct mds_req_packed *preq;
101 if (len < sizeof(**hdr) + sizeof(**req)) {
106 *hdr = (struct mds_req_hdr *) (buf);
107 preq = (struct mds_req_packed *) (buf + sizeof(**hdr));
108 off1 = preq->name_offset;
109 off2 = preq->tgt_offset;
111 *req = (struct mds_req *) (buf + sizeof(**hdr));
112 (*req)->namelen = NTOH__u32((*req)->namelen);
113 (*req)->tgtlen = NTOH__u32((*req)->tgtlen);
115 if (len < sizeof(**hdr) + sizeof(**req) + (*req)->namelen +
121 if ((*req)->namelen) {
122 name = buf + sizeof(**hdr) + off1;
127 if ((*req)->tgtlen) {
128 tgt = buf + sizeof(**hdr) + off2;
139 int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen,
140 struct mds_rep_hdr **hdr, struct mds_rep **rep,
141 int *len, char **buf)
144 struct mds_rep_packed *prep;
146 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
149 *buf = kmalloc(*len, GFP_KERNEL);
155 memset(*buf, 0, *len);
156 *hdr = (struct mds_rep_hdr *)(*buf);
157 *rep = (struct mds_rep *)(*buf + sizeof(**hdr));
159 prep = (struct mds_rep_packed *)(*buf + sizeof(**hdr));
160 ptr = *buf + sizeof(**hdr) + sizeof(*prep);
162 (*hdr)->type = MDS_TYPE_REP;
164 (*rep)->namelen = NTOH__u32(namelen);
166 prep->name_offset = (__u32)(ptr - (char *)prep);
167 LOGL(name, namelen, ptr);
170 (*rep)->tgtlen = NTOH__u32(tgtlen);
172 prep->tgt_offset = (__u32)(ptr - (char *)prep);
173 LOGL(tgt, tgtlen, ptr);
179 int mds_unpack_rep(char *buf, int len,
180 struct mds_rep_hdr **hdr, struct mds_rep **rep)
182 struct mds_rep_packed *prep;
185 if (len < sizeof(**hdr) + sizeof(**rep)) {
190 *hdr = (struct mds_rep_hdr *) (buf);
191 prep = (struct mds_rep_packed *) (buf + sizeof(**hdr));
192 off1 = prep->name_offset;
193 off2 = prep->tgt_offset;
195 *rep = (struct mds_rep *) (buf + sizeof(**hdr));
196 (*rep)->namelen = NTOH__u32((*rep)->namelen);
197 (*rep)->tgtlen = NTOH__u32((*rep)->namelen);
199 if (len < sizeof(**hdr) + sizeof(**rep) + (*rep)->namelen +
205 if ((*rep)->namelen) {
206 (*rep)->name = buf + sizeof(**hdr) + off1;
211 if ((*rep)->tgtlen) {
212 (*rep)->tgt = buf + sizeof(**hdr) + off2;
223 int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen,
224 struct mds_rep_hdr **hdr, struct mds_rep **rep,
225 int *len, char **buf)
229 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
232 *buf = kmalloc(*len, GFP_KERNEL);
238 memset(*buf, 0, *len);
239 *hdr = (struct mds_rep_hdr *)(*buf);
240 *rep = (struct mds_rep *)(*buf + sizeof(**hdr));
241 ptr = *buf + sizeof(**hdr) + sizeof(**rep);
243 (*rep)->namelen = NTOH__u32(namelen);
245 LOGL(name, namelen, ptr);
248 (*rep)->tgtlen = NTOH__u32(tgtlen);
250 LOGL(tgt, tgtlen, ptr);
256 int mds_unpack_rep(char *buf, int len,
257 struct mds_rep_hdr **hdr, struct mds_rep **rep)
259 if (len < sizeof(**hdr) + sizeof(**rep)) {
264 *hdr = (struct mds_rep_hdr *) (buf);
265 *rep = (struct mds_rep *) (buf + sizeof(**hdr));
266 (*rep)->namelen = NTOH__u32((*rep)->namelen);
267 (*rep)->tgtlen = NTOH__u32((*rep)->namelen);
269 if (len < sizeof(**hdr) + sizeof(**rep) + (*rep)->namelen +
275 if ((*rep)->namelen) {
276 (*rep)->name = buf + sizeof(**hdr) + sizeof(**rep);
281 if ((*rep)->tgtlen) {
282 (*rep)->tgt = buf + sizeof(**hdr) + sizeof(**rep) +
283 size_round((*rep)->namelen);