1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2003 Cluster File Systems, Inc.
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.
22 #define DEBUG_SUBSYSTEM S_MDS
24 # include <liblustre.h>
26 #include <linux/lustre_idl.h>
27 #include <linux/lustre_net.h>
28 #include <linux/lustre_mds.h>
29 #include <linux/lustre_lite.h>
31 void mdc_readdir_pack(struct ptlrpc_request *req, __u64 offset, __u32 size,
32 obd_id ino, int type, __u64 xid)
36 b = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*b));
37 b->fsuid = current->fsuid;
38 b->fsgid = current->fsgid;
39 b->capability = current->cap_effective;
41 b->fid1.f_type = type;
42 b->size = offset; /* !! */
44 b->blocks = xid; /* !! */
45 b->nlink = size; /* !! */
48 static void mdc_pack_body(struct mds_body *b)
52 b->fsuid = current->fsuid;
53 b->fsgid = current->fsgid;
54 b->capability = current->cap_effective;
57 void mdc_pack_req_body(struct ptlrpc_request *req)
59 struct mds_body *b = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*b));
63 /* packing of MDS records */
64 void mdc_create_pack(struct ptlrpc_request *req, int offset,
65 struct mdc_op_data *op_data,
66 __u32 mode, __u64 rdev, __u32 uid, __u32 gid, __u64 time,
67 const void *data, int datalen)
69 struct mds_rec_create *rec;
71 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
73 rec->cr_opcode = REINT_CREATE;
74 rec->cr_fsuid = current->fsuid;
75 rec->cr_fsgid = current->fsgid;
76 rec->cr_cap = current->cap_effective;
77 ll_ino2fid(&rec->cr_fid, op_data->ino1, op_data->gen1, op_data->typ1);
78 memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
84 if (in_group_p(op_data->gid1))
85 rec->cr_suppgid = op_data->gid1;
89 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, op_data->namelen + 1);
90 LOGL0(op_data->name, op_data->namelen, tmp);
93 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, datalen);
94 memcpy (tmp, data, datalen);
98 /* packing of MDS records */
99 void mdc_open_pack(struct ptlrpc_request *req, int offset,
100 struct mdc_op_data *op_data,
101 __u32 mode, __u64 rdev, __u32 uid, __u32 gid, __u64 time,
102 __u32 flags, const void *data, int datalen)
104 struct mds_rec_create *rec;
106 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
108 /* XXX do something about time, uid, gid */
109 rec->cr_opcode = REINT_OPEN;
110 rec->cr_fsuid = current->fsuid;
111 rec->cr_fsgid = current->fsgid;
112 rec->cr_cap = current->cap_effective;
114 ll_ino2fid(&rec->cr_fid, op_data->ino1,
115 op_data->gen1, op_data->typ1);
116 memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
118 rec->cr_flags = flags;
123 if (in_group_p(op_data->gid1))
124 rec->cr_suppgid = op_data->gid1;
126 rec->cr_suppgid = -1;
129 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
130 op_data->namelen + 1);
131 LOGL0(op_data->name, op_data->namelen, tmp);
135 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, datalen);
136 memcpy (tmp, data, datalen);
140 void mdc_setattr_pack(struct ptlrpc_request *req,
141 struct mdc_op_data *data,
142 struct iattr *iattr, void *ea, int ealen,
143 void *ea2, int ea2len)
145 struct mds_rec_setattr *rec = lustre_msg_buf(req->rq_reqmsg, 0,
147 rec->sa_opcode = REINT_SETATTR;
148 rec->sa_fsuid = current->fsuid;
149 rec->sa_fsgid = current->fsgid;
150 rec->sa_cap = current->cap_effective;
151 ll_ino2fid(&rec->sa_fid, data->ino1, data->gen1, data->typ1);
154 rec->sa_valid = iattr->ia_valid;
155 rec->sa_mode = iattr->ia_mode;
156 rec->sa_uid = iattr->ia_uid;
157 rec->sa_gid = iattr->ia_gid;
158 rec->sa_size = iattr->ia_size;
159 rec->sa_atime = LTIME_S(iattr->ia_atime);
160 rec->sa_mtime = LTIME_S(iattr->ia_mtime);
161 rec->sa_ctime = LTIME_S(iattr->ia_ctime);
162 rec->sa_attr_flags = iattr->ia_attr_flags;
164 if ((iattr->ia_valid & ATTR_GID) && in_group_p(iattr->ia_gid))
165 rec->sa_suppgid = iattr->ia_gid;
166 else if ((iattr->ia_valid & ATTR_MODE) &&
167 in_group_p(data->gid1))
168 rec->sa_suppgid = data->gid1;
170 rec->sa_suppgid = -1;
176 memcpy(lustre_msg_buf(req->rq_reqmsg, 1, ealen), ea, ealen);
181 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, ea2len), ea2, ea2len);
184 void mdc_unlink_pack(struct ptlrpc_request *req, int offset,
185 struct mdc_op_data *data)
187 struct mds_rec_unlink *rec;
190 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
191 LASSERT (rec != NULL);
193 rec->ul_opcode = REINT_UNLINK;
194 rec->ul_fsuid = current->fsuid;
195 rec->ul_fsgid = current->fsgid;
196 rec->ul_cap = current->cap_effective;
197 rec->ul_mode = data->mode;
198 if (in_group_p(data->gid1))
199 rec->ul_suppgid = data->gid1;
201 rec->ul_suppgid = -1;
202 ll_ino2fid(&rec->ul_fid1, data->ino1, data->gen1, data->typ1);
204 ll_ino2fid(&rec->ul_fid2, data->ino2, data->gen2, data->typ2);
206 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, data->namelen + 1);
207 LASSERT (tmp != NULL);
208 LOGL0(data->name, data->namelen, tmp);
211 void mdc_link_pack(struct ptlrpc_request *req, int offset,
212 struct mdc_op_data *data)
214 struct mds_rec_link *rec;
217 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
219 rec->lk_opcode = REINT_LINK;
220 rec->lk_fsuid = current->fsuid;
221 rec->lk_fsgid = current->fsgid;
222 rec->lk_cap = current->cap_effective;
223 if (in_group_p(data->gid1))
224 rec->lk_suppgid1 = data->gid1;
226 rec->lk_suppgid1 = -1;
227 if (in_group_p(data->gid2))
228 rec->lk_suppgid2 = data->gid2;
230 rec->lk_suppgid2 = -1;
231 ll_ino2fid(&rec->lk_fid1, data->ino1, data->gen1, data->typ1);
232 ll_ino2fid(&rec->lk_fid2, data->ino2, data->gen2, data->typ2);
234 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, data->namelen + 1);
235 LOGL0(data->name, data->namelen, tmp);
238 void mdc_rename_pack(struct ptlrpc_request *req, int offset,
239 struct mdc_op_data *data,
240 const char *old, int oldlen, const char *new, int newlen)
242 struct mds_rec_rename *rec;
245 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
247 /* XXX do something about time, uid, gid */
248 rec->rn_opcode = REINT_RENAME;
249 rec->rn_fsuid = current->fsuid;
250 rec->rn_fsgid = current->fsgid;
251 rec->rn_cap = current->cap_effective;
252 if (in_group_p(data->gid1))
253 rec->rn_suppgid1 = data->gid1;
255 rec->rn_suppgid1 = -1;
256 if (in_group_p(data->gid2))
257 rec->rn_suppgid2 = data->gid2;
259 rec->rn_suppgid2 = -1;
260 ll_ino2fid(&rec->rn_fid1, data->ino1, data->gen1, data->typ1);
261 ll_ino2fid(&rec->rn_fid2, data->ino2, data->gen2, data->typ2);
263 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, oldlen + 1);
264 LOGL0(old, oldlen, tmp);
267 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, newlen + 1);
268 LOGL0(new, newlen, tmp);
272 void mdc_getattr_pack(struct ptlrpc_request *req, int valid, int offset,
273 int flags, struct mdc_op_data *data)
276 b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*b));
278 b->fsuid = current->fsuid;
279 b->fsgid = current->fsgid;
280 b->capability = current->cap_effective;
283 if (in_group_p(data->gid1))
284 b->suppgid = data->gid1;
288 ll_ino2fid(&b->fid1, data->ino1, data->gen1, data->typ1);
291 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
293 LOGL0(data->name, data->namelen, tmp);