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 #include <linux/obd_support.h>
48 #include <linux/lustre_lib.h>
49 #include <linux/lustre_idl.h>
50 #include <linux/lustre_mds.h>
53 int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen,
54 struct ptlreq_hdr **hdr, struct mds_req **req,
59 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
62 OBD_ALLOC(*buf, *len);
68 memset(*buf, 0, *len);
69 *hdr = (struct ptlreq_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 ptlreq_hdr **hdr, struct mds_req **req)
93 if (len < sizeof(**hdr) + sizeof(**req)) {
98 *hdr = (struct ptlreq_hdr *) (buf);
99 *req = (struct mds_req *) (buf + sizeof(**hdr));
101 (*req)->namelen = NTOH__u32((*req)->namelen);
102 (*req)->tgtlen = NTOH__u32((*req)->tgtlen);
104 if (len < sizeof(**hdr) + sizeof(**req) +
105 size_round((*req)->namelen) + size_round((*req)->tgtlen) ) {
110 if ((*req)->namelen) {
111 name = buf + sizeof(**hdr) + sizeof(**req);
116 if ((*req)->tgtlen) {
117 tgt = buf + sizeof(**hdr) + sizeof(**req) +
118 size_round((*req)->namelen);
127 void *mds_req_tgt(struct mds_req *req)
131 return (void *)((char *)req + sizeof(*req) +
132 size_round(req->namelen));
135 void *mds_req_name(struct mds_req *req)
139 return (void *)((char *)req + sizeof(*req));
142 int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen,
143 struct ptlrep_hdr **hdr, struct mds_rep **rep,
144 int *len, char **buf)
148 *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) +
151 OBD_ALLOC(*buf, *len);
157 memset(*buf, 0, *len);
158 *hdr = (struct ptlrep_hdr *)(*buf);
159 *rep = (struct mds_rep *)(*buf + sizeof(**hdr));
161 ptr = *buf + sizeof(**hdr) + sizeof(**rep);
163 (*hdr)->type = MDS_TYPE_REP;
165 (*rep)->namelen = NTOH__u32(namelen);
167 LOGL(name, namelen, ptr);
170 (*rep)->tgtlen = NTOH__u32(tgtlen);
172 LOGL(tgt, tgtlen, ptr);
177 int mds_unpack_rep(char *buf, int len,
178 struct ptlrep_hdr **hdr, struct mds_rep **rep)
181 if (len < sizeof(**hdr)) {
185 *hdr = (struct ptlrep_hdr *) (buf);
187 if (len < sizeof(**hdr) + sizeof(**rep)) {
192 *rep = (struct mds_rep *) (buf + sizeof(**hdr));
193 (*rep)->namelen = NTOH__u32((*rep)->namelen);
194 (*rep)->tgtlen = NTOH__u32((*rep)->namelen);
196 if (len < sizeof(**hdr) + sizeof(**rep)
197 + size_round((*rep)->namelen) + size_round((*rep)->tgtlen) ) {
206 void *mds_rep_name(struct mds_rep *rep)
210 return (void *)((char *)rep + sizeof(*rep));
213 void *mds_rep_tgt(struct mds_rep *rep)
217 return (void *)((char *)rep + sizeof(*rep) + size_round(rep->namelen));