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 the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
25 #define DEBUG_SUBSYSTEM S_MDC
28 # include <liblustre.h>
30 #include <linux/lustre_idl.h>
31 #include <linux/lustre_net.h>
32 #include <linux/lustre_mds.h>
33 #include "mdc_internal.h"
36 /* some liblustre hackings here */
42 void mdc_readdir_pack(struct ptlrpc_request *req, int pos, __u64 offset,
43 __u32 size, struct ll_fid *mdc_fid)
47 b = lustre_msg_buf(req->rq_reqmsg, pos, sizeof (*b));
48 b->fsuid = current->fsuid;
49 b->fsgid = current->fsgid;
50 b->capability = current->cap_effective;
52 b->size = offset; /* !! */
54 b->nlink = size; /* !! */
57 static void mdc_pack_body(struct mds_body *b)
61 b->fsuid = current->fsuid;
62 b->fsgid = current->fsgid;
63 b->capability = current->cap_effective;
66 void mdc_pack_req_body(struct ptlrpc_request *req, int offset,
67 __u64 valid, struct ll_fid *fid, int ea_size)
69 struct mds_body *b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*b));
74 b->eadatasize = ea_size;
78 /* packing of MDS records */
79 void mdc_create_pack(struct ptlrpc_request *req, int offset,
80 struct mdc_op_data *op_data, const void *data, int datalen,
81 __u32 mode, __u32 uid, __u32 gid, __u32 cap_effective,
84 struct mds_rec_create *rec;
86 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
88 rec->cr_opcode = REINT_CREATE;
91 rec->cr_cap = cap_effective;
92 rec->cr_fid = op_data->fid1;
93 memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
96 rec->cr_time = op_data->mod_time;
97 rec->cr_suppgid = op_data->suppgids[0];
99 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, op_data->namelen + 1);
100 LOGL0(op_data->name, op_data->namelen, tmp);
103 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, datalen);
104 memcpy (tmp, data, datalen);
108 static __u32 mds_pack_open_flags(__u32 flags)
111 (flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC |
112 MDS_OPEN_DELAY_CREATE | MDS_OPEN_HAS_EA |
113 MDS_OPEN_HAS_OBJS | MDS_OPEN_OWNEROVERRIDE)) |
114 ((flags & O_CREAT) ? MDS_OPEN_CREAT : 0) |
115 ((flags & O_EXCL) ? MDS_OPEN_EXCL : 0) |
116 ((flags & O_TRUNC) ? MDS_OPEN_TRUNC : 0) |
117 ((flags & O_APPEND) ? MDS_OPEN_APPEND : 0) |
118 ((flags & O_SYNC) ? MDS_OPEN_SYNC : 0) |
119 ((flags & O_DIRECTORY) ? MDS_OPEN_DIRECTORY : 0) |
120 ((flags & O_JOIN_FILE) ? MDS_OPEN_JOIN_FILE : 0) |
124 /* packing of MDS records */
125 void mdc_join_pack(struct ptlrpc_request *req, int offset,
126 struct mdc_op_data *op_data, __u64 head_size)
128 struct mds_rec_join *rec;
130 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*rec));
131 LASSERT(rec != NULL);
132 rec->jr_fid = op_data->fid2;
133 rec->jr_headsize = head_size;
136 void mdc_open_pack(struct ptlrpc_request *req, int offset,
137 struct mdc_op_data *op_data, __u32 mode, __u64 rdev,
138 __u32 flags, const void *lmm, int lmmlen)
140 struct mds_rec_create *rec;
142 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
144 /* XXX do something about time, uid, gid */
145 rec->cr_opcode = REINT_OPEN;
146 rec->cr_fsuid = current->fsuid;
147 rec->cr_fsgid = current->fsgid;
148 rec->cr_cap = current->cap_effective;
150 rec->cr_fid = op_data->fid1;
151 memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
153 rec->cr_flags = mds_pack_open_flags(flags);
155 rec->cr_time = op_data->mod_time;
156 rec->cr_suppgid = op_data->suppgids[0];
159 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
160 op_data->namelen + 1);
161 LOGL0(op_data->name, op_data->namelen, tmp);
165 rec->cr_flags |= MDS_OPEN_HAS_EA;
166 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, lmmlen);
167 memcpy (tmp, lmm, lmmlen);
171 void mdc_setattr_pack(struct ptlrpc_request *req, int offset,
172 struct mdc_op_data *data, struct iattr *iattr,
173 void *ea, int ealen, void *ea2, int ea2len)
175 struct mds_rec_setattr *rec = lustre_msg_buf(req->rq_reqmsg, offset,
177 rec->sa_opcode = REINT_SETATTR;
178 rec->sa_fsuid = current->fsuid;
179 rec->sa_fsgid = current->fsgid;
180 rec->sa_cap = current->cap_effective;
181 rec->sa_fid = data->fid1;
182 rec->sa_suppgid = -1;
185 rec->sa_valid = iattr->ia_valid;
186 rec->sa_mode = iattr->ia_mode;
187 rec->sa_uid = iattr->ia_uid;
188 rec->sa_gid = iattr->ia_gid;
189 rec->sa_size = iattr->ia_size;
190 rec->sa_atime = LTIME_S(iattr->ia_atime);
191 rec->sa_mtime = LTIME_S(iattr->ia_mtime);
192 rec->sa_ctime = LTIME_S(iattr->ia_ctime);
193 rec->sa_attr_flags = iattr->ia_attr_flags;
194 if ((iattr->ia_valid & ATTR_GID) && in_group_p(iattr->ia_gid))
195 rec->sa_suppgid = iattr->ia_gid;
197 rec->sa_suppgid = data->suppgids[0];
203 memcpy(lustre_msg_buf(req->rq_reqmsg, offset + 1, ealen), ea, ealen);
208 memcpy(lustre_msg_buf(req->rq_reqmsg, offset + 2, ea2len), ea2, ea2len);
211 void mdc_unlink_pack(struct ptlrpc_request *req, int offset,
212 struct mdc_op_data *data)
214 struct mds_rec_unlink *rec;
217 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
218 LASSERT (rec != NULL);
220 rec->ul_opcode = REINT_UNLINK;
221 rec->ul_fsuid = current->fsuid;
222 rec->ul_fsgid = current->fsgid;
223 rec->ul_cap = current->cap_effective;
224 rec->ul_mode = data->create_mode;
225 rec->ul_suppgid = data->suppgids[0];
226 rec->ul_fid1 = data->fid1;
227 rec->ul_fid2 = data->fid2;
228 rec->ul_time = data->mod_time;
230 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, data->namelen + 1);
231 LASSERT (tmp != NULL);
232 LOGL0(data->name, data->namelen, tmp);
235 void mdc_link_pack(struct ptlrpc_request *req, int offset,
236 struct mdc_op_data *data)
238 struct mds_rec_link *rec;
241 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
243 rec->lk_opcode = REINT_LINK;
244 rec->lk_fsuid = current->fsuid;
245 rec->lk_fsgid = current->fsgid;
246 rec->lk_cap = current->cap_effective;
247 rec->lk_suppgid1 = data->suppgids[0];
248 rec->lk_suppgid2 = data->suppgids[1];
249 rec->lk_fid1 = data->fid1;
250 rec->lk_fid2 = data->fid2;
251 rec->lk_time = data->mod_time;
253 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, data->namelen + 1);
254 LOGL0(data->name, data->namelen, tmp);
257 void mdc_rename_pack(struct ptlrpc_request *req, int offset,
258 struct mdc_op_data *data,
259 const char *old, int oldlen, const char *new, int newlen)
261 struct mds_rec_rename *rec;
264 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
266 /* XXX do something about time, uid, gid */
267 rec->rn_opcode = REINT_RENAME;
268 rec->rn_fsuid = current->fsuid;
269 rec->rn_fsgid = current->fsgid;
270 rec->rn_cap = current->cap_effective;
271 rec->rn_suppgid1 = data->suppgids[0];
272 rec->rn_suppgid2 = data->suppgids[1];
273 rec->rn_fid1 = data->fid1;
274 rec->rn_fid2 = data->fid2;
275 rec->rn_time = data->mod_time;
277 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, oldlen + 1);
278 LOGL0(old, oldlen, tmp);
281 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, newlen + 1);
282 LOGL0(new, newlen, tmp);
286 void mdc_getattr_pack(struct ptlrpc_request *req, int offset, int valid,
287 int flags, struct mdc_op_data *data)
290 b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*b));
292 b->fsuid = current->fsuid;
293 b->fsgid = current->fsgid;
294 b->capability = current->cap_effective;
297 b->suppgid = data->suppgids[0];
299 b->fid1 = data->fid1;
302 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
304 LOGL0(data->name, data->namelen, tmp);
308 void mdc_close_pack(struct ptlrpc_request *req, int offset, struct obdo *oa,
309 int valid, struct obd_client_handle *och)
311 struct mds_body *body;
313 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
315 mdc_pack_fid(&body->fid1, oa->o_id, 0, oa->o_mode);
316 memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
317 if (oa->o_valid & OBD_MD_FLATIME) {
318 body->atime = oa->o_atime;
319 body->valid |= OBD_MD_FLATIME;
321 if (oa->o_valid & OBD_MD_FLMTIME) {
322 body->mtime = oa->o_mtime;
323 body->valid |= OBD_MD_FLMTIME;
325 if (oa->o_valid & OBD_MD_FLCTIME) {
326 body->ctime = oa->o_ctime;
327 body->valid |= OBD_MD_FLCTIME;
329 if (oa->o_valid & OBD_MD_FLSIZE) {
330 body->size = oa->o_size;
331 body->valid |= OBD_MD_FLSIZE;
333 if (oa->o_valid & OBD_MD_FLBLOCKS) {
334 body->blocks = oa->o_blocks;
335 body->valid |= OBD_MD_FLBLOCKS;
337 if (oa->o_valid & OBD_MD_FLFLAGS) {
338 body->flags = oa->o_flags;
339 body->valid |= OBD_MD_FLFLAGS;