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 InterMezzo, http://www.inter-mezzo.org.
8 * InterMezzo 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 * InterMezzo 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 InterMezzo; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Unpacking of KML 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>
53 int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen,
54 struct mds_req_hdr **hdr, struct mds_req **req,
59 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
62 *buf = kmalloc(*len, GFP_KERNEL);
68 memset(*buf, 0, *len);
69 *hdr = (struct mds_req_hdr *)(*buf);
70 *req = (struct mds_req *)(*buf + sizeof(**hdr));
71 ptr = *buf + sizeof(**hdr) + sizeof(**req);
73 (*hdr)->type = MDS_TYPE_REQ;
75 (*req)->namelen = NTOH__u32(namelen);
77 LOGL(name, namelen, ptr);
80 (*req)->tgtlen = NTOH__u32(tgtlen);
82 LOGL(tgt, tgtlen, ptr);
88 int mds_unpack_req(char *buf, int len,
89 struct mds_req_hdr **hdr, struct mds_req **req)
91 if (len < sizeof(**hdr) + sizeof(**req)) {
96 *hdr = (struct mds_req_hdr *) (buf);
97 *req = (struct mds_req *) (buf + sizeof(**hdr));
98 (*req)->namelen = NTOH__u32((*req)->namelen);
99 (*req)->tgtlen = NTOH__u32((*req)->namelen);
101 if (len < sizeof(**hdr) + sizeof(**req) + (*req)->namelen +
107 if ((*req)->namelen) {
108 (*req)->name = buf + sizeof(**hdr) + sizeof(**req);
113 if ((*req)->tgtlen) {
114 (*req)->tgt = buf + sizeof(**hdr) + sizeof(**req) +
115 size_round((*req)->namelen);
124 int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen,
125 struct mds_rep_hdr **hdr, struct mds_rep **rep,
126 int *len, char **buf)
130 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
133 *buf = kmalloc(*len, GFP_KERNEL);
139 memset(*buf, 0, *len);
140 *hdr = (struct mds_rep_hdr *)(*buf);
141 *rep = (struct mds_rep *)(*buf + sizeof(**hdr));
142 ptr = *buf + sizeof(**hdr) + sizeof(**rep);
144 (*rep)->namelen = NTOH__u32(namelen);
146 LOGL(name, namelen, ptr);
149 (*rep)->tgtlen = NTOH__u32(tgtlen);
151 LOGL(tgt, tgtlen, ptr);
157 int mds_unpack_rep(char *buf, int len,
158 struct mds_rep_hdr **hdr, struct mds_rep **rep)
160 if (len < sizeof(**hdr) + sizeof(**rep)) {
165 *hdr = (struct mds_rep_hdr *) (buf);
166 *rep = (struct mds_rep *) (buf + sizeof(**hdr));
167 (*rep)->namelen = NTOH__u32((*rep)->namelen);
168 (*rep)->tgtlen = NTOH__u32((*rep)->namelen);
170 if (len < sizeof(**hdr) + sizeof(**rep) + (*rep)->namelen +
176 if ((*rep)->namelen) {
177 (*rep)->name = buf + sizeof(**hdr) + sizeof(**rep);
182 if ((*rep)->tgtlen) {
183 (*rep)->tgt = buf + sizeof(**hdr) + sizeof(**rep) +
184 size_round((*rep)->namelen);