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>
38 #include <linux/poll.h>
39 #include <linux/init.h>
40 #include <linux/list.h>
42 #include <asm/segment.h>
43 #include <asm/system.h>
45 #include <asm/uaccess.h>
47 #define DEBUG_SUBSYSTEM S_MDS
49 #include <linux/obd_support.h>
50 #include <linux/lustre_lib.h>
51 #include <linux/lustre_idl.h>
52 #include <linux/lustre_mds.h>
54 int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen,
55 struct ptlreq_hdr **hdr, union ptl_req *r,
61 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
64 OBD_ALLOC(*buf, *len);
70 memset(*buf, 0, *len);
71 *hdr = (struct ptlreq_hdr *)(*buf);
72 req = (struct mds_req *)(*buf + sizeof(**hdr));
75 ptr = *buf + sizeof(**hdr) + sizeof(*req);
77 (*hdr)->type = MDS_TYPE_REQ;
79 req->namelen = NTOH__u32(namelen);
81 LOGL(name, namelen, ptr);
84 req->tgtlen = NTOH__u32(tgtlen);
86 LOGL(tgt, tgtlen, ptr);
92 int mds_unpack_req(char *buf, int len,
93 struct ptlreq_hdr **hdr, union ptl_req *r)
98 if (len < sizeof(**hdr) + sizeof(*req)) {
103 *hdr = (struct ptlreq_hdr *) (buf);
104 req = (struct mds_req *) (buf + sizeof(**hdr));
107 req->namelen = NTOH__u32(req->namelen);
108 req->tgtlen = NTOH__u32(req->tgtlen);
110 if (len < sizeof(**hdr) + sizeof(*req) +
111 size_round(req->namelen) + size_round(req->tgtlen) ) {
117 name = buf + sizeof(**hdr) + sizeof(*req);
123 tgt = buf + sizeof(**hdr) + sizeof(*req) +
124 size_round(req->namelen);
133 void *mds_req_tgt(struct mds_req *req)
137 return (void *)((char *)req + sizeof(*req) +
138 size_round(req->namelen));
141 void *mds_req_name(struct mds_req *req)
145 return (void *)((char *)req + sizeof(*req));
148 int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen,
149 struct ptlrep_hdr **hdr, union ptl_rep *r,
150 int *len, char **buf)
155 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
158 OBD_ALLOC(*buf, *len);
164 memset(*buf, 0, *len);
165 *hdr = (struct ptlrep_hdr *)(*buf);
166 rep = (struct mds_rep *)(*buf + sizeof(**hdr));
169 ptr = *buf + sizeof(**hdr) + sizeof(*rep);
171 (*hdr)->type = MDS_TYPE_REP;
173 rep->namelen = NTOH__u32(namelen);
175 LOGL(name, namelen, ptr);
178 rep->tgtlen = NTOH__u32(tgtlen);
180 LOGL(tgt, tgtlen, ptr);
185 int mds_unpack_rep(char *buf, int len,
186 struct ptlrep_hdr **hdr, union ptl_rep *r)
189 if (len < sizeof(**hdr)) {
193 *hdr = (struct ptlrep_hdr *) (buf);
195 if (len < sizeof(**hdr) + sizeof(*rep)) {
200 rep = (struct mds_rep *) (buf + sizeof(**hdr));
202 rep->namelen = NTOH__u32(rep->namelen);
203 rep->tgtlen = NTOH__u32(rep->namelen);
205 if (len < sizeof(**hdr) + sizeof(*rep)
206 + size_round(rep->namelen) + size_round(rep->tgtlen) ) {
215 void *mds_rep_name(struct mds_rep *rep)
219 return (void *)((char *)rep + sizeof(*rep));
222 void *mds_rep_tgt(struct mds_rep *rep)
226 return (void *)((char *)rep + sizeof(*rep) + size_round(rep->namelen));