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_MDC
25 # include <liblustre.h>
27 #include <linux/lustre_idl.h>
28 #include <linux/lustre_net.h>
29 #include <linux/lustre_mds.h>
30 #include "mdc_internal.h"
33 /* some liblustre hackings here */
39 void mdc_readdir_pack(struct ptlrpc_request *req, __u64 offset, __u32 size,
40 struct ll_fid *mdc_fid)
44 b = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*b));
45 b->fsuid = current->fsuid;
46 b->fsgid = current->fsgid;
47 b->capability = current->cap_effective;
49 b->size = offset; /* !! */
51 b->nlink = size; /* !! */
54 static void mdc_pack_body(struct mds_body *b)
58 b->fsuid = current->fsuid;
59 b->fsgid = current->fsgid;
60 b->capability = current->cap_effective;
63 void mdc_pack_req_body(struct ptlrpc_request *req)
65 struct mds_body *b = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*b));
69 /* packing of MDS records */
70 void mdc_create_pack(struct ptlrpc_request *req, int offset,
71 struct mdc_op_data *op_data, __u32 mode, __u64 rdev,
72 const void *data, int datalen)
74 struct mds_rec_create *rec;
76 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
78 rec->cr_opcode = REINT_CREATE;
79 rec->cr_fsuid = current->fsuid;
80 rec->cr_fsgid = current->fsgid;
81 rec->cr_cap = current->cap_effective;
82 rec->cr_fid = op_data->fid1;
83 memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
86 rec->cr_time = op_data->mod_time;
87 rec->cr_suppgid = op_data->ctxt.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 static __u32 mds_pack_open_flags(__u32 flags)
101 (flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC |
102 MDS_OPEN_DELAY_CREATE | MDS_OPEN_HAS_EA |
103 MDS_OPEN_HAS_OBJS | MDS_OPEN_OWNEROVERRIDE)) |
104 ((flags & O_CREAT) ? MDS_OPEN_CREAT : 0) |
105 ((flags & O_EXCL) ? MDS_OPEN_EXCL : 0) |
106 ((flags & O_TRUNC) ? MDS_OPEN_TRUNC : 0) |
107 ((flags & O_APPEND) ? MDS_OPEN_APPEND : 0) |
108 ((flags & O_SYNC) ? MDS_OPEN_SYNC : 0) |
109 ((flags & O_DIRECTORY) ? MDS_OPEN_DIRECTORY : 0) |
113 /* packing of MDS records */
114 void mdc_open_pack(struct ptlrpc_request *req, int offset,
115 struct mdc_op_data *op_data, __u32 mode, __u64 rdev,
116 __u32 flags, const void *lmm, int lmmlen)
118 struct mds_rec_create *rec;
120 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
122 /* XXX do something about time, uid, gid */
123 rec->cr_opcode = REINT_OPEN;
124 rec->cr_fsuid = current->fsuid;
125 rec->cr_fsgid = current->fsgid;
126 rec->cr_cap = current->cap_effective;
128 rec->cr_fid = op_data->fid1;
129 memset(&rec->cr_replayfid, 0, sizeof(rec->cr_replayfid));
131 rec->cr_flags = mds_pack_open_flags(flags);
133 rec->cr_time = op_data->mod_time;
134 rec->cr_suppgid = op_data->ctxt.gid1;
137 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
138 op_data->namelen + 1);
139 LOGL0(op_data->name, op_data->namelen, tmp);
143 rec->cr_flags |= MDS_OPEN_HAS_EA;
144 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, lmmlen);
145 memcpy (tmp, lmm, lmmlen);
149 void mdc_setattr_pack(struct ptlrpc_request *req, struct mdc_op_data *data,
150 struct iattr *iattr, void *ea, int ealen,
151 void *ea2, int ea2len)
153 struct mds_rec_setattr *rec = lustre_msg_buf(req->rq_reqmsg, 0,
155 rec->sa_opcode = REINT_SETATTR;
156 rec->sa_fsuid = current->fsuid;
157 rec->sa_fsgid = current->fsgid;
158 rec->sa_cap = current->cap_effective;
159 rec->sa_fid = data->fid1;
162 rec->sa_valid = iattr->ia_valid;
163 rec->sa_mode = iattr->ia_mode;
164 rec->sa_uid = iattr->ia_uid;
165 rec->sa_gid = iattr->ia_gid;
166 rec->sa_size = iattr->ia_size;
167 rec->sa_atime = LTIME_S(iattr->ia_atime);
168 rec->sa_mtime = LTIME_S(iattr->ia_mtime);
169 rec->sa_ctime = LTIME_S(iattr->ia_ctime);
170 rec->sa_attr_flags = iattr->ia_attr_flags;
171 if ((iattr->ia_valid & ATTR_GID) && in_group_p(iattr->ia_gid))
172 rec->sa_suppgid = iattr->ia_gid;
173 else if ((iattr->ia_valid & ATTR_MODE) &&
174 in_group_p(iattr->ia_gid))
175 rec->sa_suppgid = data->ctxt.gid1;
176 else if ((iattr->ia_valid & (ATTR_MTIME|ATTR_CTIME)) &&
177 data->ctxt.gid1 != -1)
178 rec->sa_suppgid = data->ctxt.gid1;
184 memcpy(lustre_msg_buf(req->rq_reqmsg, 1, ealen), ea, ealen);
189 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, ea2len), ea2, ea2len);
192 void mdc_unlink_pack(struct ptlrpc_request *req, int offset,
193 struct mdc_op_data *data)
195 struct mds_rec_unlink *rec;
198 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
199 LASSERT (rec != NULL);
201 rec->ul_opcode = REINT_UNLINK;
202 rec->ul_fsuid = current->fsuid;
203 rec->ul_fsgid = current->fsgid;
204 rec->ul_cap = current->cap_effective;
205 rec->ul_mode = data->create_mode;
206 rec->ul_suppgid = data->ctxt.gid1;
207 rec->ul_fid1 = data->fid1;
208 rec->ul_fid2 = data->fid2;
209 rec->ul_time = data->mod_time;
211 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, data->namelen + 1);
212 LASSERT (tmp != NULL);
213 LOGL0(data->name, data->namelen, tmp);
216 void mdc_link_pack(struct ptlrpc_request *req, int offset,
217 struct mdc_op_data *data)
219 struct mds_rec_link *rec;
222 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
224 rec->lk_opcode = REINT_LINK;
225 rec->lk_fsuid = current->fsuid;
226 rec->lk_fsgid = current->fsgid;
227 rec->lk_cap = current->cap_effective;
228 rec->lk_suppgid1 = data->ctxt.gid1;
229 rec->lk_suppgid2 = data->ctxt.gid2;
230 rec->lk_fid1 = data->fid1;
231 rec->lk_fid2 = data->fid2;
232 rec->lk_time = data->mod_time;
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 rec->rn_suppgid1 = data->ctxt.gid1;
253 rec->rn_suppgid2 = data->ctxt.gid2;
254 rec->rn_fid1 = data->fid1;
255 rec->rn_fid2 = data->fid2;
256 rec->rn_time = data->mod_time;
258 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, oldlen + 1);
259 LOGL0(old, oldlen, tmp);
262 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, newlen + 1);
263 LOGL0(new, newlen, tmp);
267 void mdc_getattr_pack(struct ptlrpc_request *req, int valid, int offset,
268 int flags, struct mdc_op_data *data)
271 b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*b));
273 b->fsuid = current->fsuid;
274 b->fsgid = current->fsgid;
275 b->capability = current->cap_effective;
278 b->suppgid = data->ctxt.gid1;
280 b->fid1 = data->fid1;
283 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
285 LOGL0(data->name, data->namelen, tmp);
289 void mdc_close_pack(struct ptlrpc_request *req, int offset, struct obdo *oa,
290 int valid, struct obd_client_handle *och)
292 struct mds_body *body;
294 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
296 mdc_pack_fid(&body->fid1, oa->o_id, 0, oa->o_mode);
297 memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
298 if (oa->o_valid & OBD_MD_FLATIME) {
299 body->atime = oa->o_atime;
300 body->valid |= OBD_MD_FLATIME;
302 if (oa->o_valid & OBD_MD_FLMTIME) {
303 body->mtime = oa->o_mtime;
304 body->valid |= OBD_MD_FLMTIME;
306 if (oa->o_valid & OBD_MD_FLCTIME) {
307 body->ctime = oa->o_ctime;
308 body->valid |= OBD_MD_FLCTIME;
310 if (oa->o_valid & OBD_MD_FLSIZE) {
311 body->size = oa->o_size;
312 body->valid |= OBD_MD_FLSIZE;
314 if (oa->o_valid & OBD_MD_FLBLOCKS) {
315 body->blocks = oa->o_blocks;
316 body->valid |= OBD_MD_FLBLOCKS;
318 if (oa->o_valid & OBD_MD_FLFLAGS) {
319 body->flags = oa->o_flags;
320 body->valid |= OBD_MD_FLFLAGS;