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 <lustre/lustre_idl.h>
31 #include <lustre_net.h>
32 #include "mdc_internal.h"
35 /* some liblustre hackings here */
41 void mdc_readdir_pack(struct ptlrpc_request *req, int pos, __u64 offset,
42 __u32 size, const struct lu_fid *fid)
46 b = lustre_msg_buf(req->rq_reqmsg, pos, sizeof(*b));
47 b->fsuid = current->fsuid;
48 b->fsgid = current->fsgid;
49 b->capability = current->cap_effective;
51 b->size = offset; /* !! */
53 b->nlink = size; /* !! */
56 static void mdc_pack_body(struct mdt_body *b)
60 b->fsuid = current->fsuid;
61 b->fsgid = current->fsgid;
62 b->capability = current->cap_effective;
65 void mdc_pack_req_body(struct ptlrpc_request *req, int offset,
66 __u64 valid, const struct lu_fid *fid,
67 int ea_size, int flags)
69 struct mdt_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 md_op_data *op_data, const void *data, int datalen,
81 __u32 mode, __u32 uid, __u32 gid, __u32 cap_effective,
84 struct mdt_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_fid1 = op_data->fid1;
93 rec->cr_fid2 = op_data->fid2;
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 |
112 MDS_OPEN_DELAY_CREATE | MDS_OPEN_HAS_EA |
113 MDS_OPEN_HAS_OBJS | MDS_OPEN_OWNEROVERRIDE |
115 ((flags & O_CREAT) ? MDS_OPEN_CREAT : 0) |
116 ((flags & O_EXCL) ? MDS_OPEN_EXCL : 0) |
117 ((flags & O_TRUNC) ? MDS_OPEN_TRUNC : 0) |
118 ((flags & O_APPEND) ? MDS_OPEN_APPEND : 0) |
119 ((flags & O_SYNC) ? MDS_OPEN_SYNC : 0) |
120 ((flags & O_DIRECTORY) ? MDS_OPEN_DIRECTORY : 0) |
121 ((flags & O_JOIN_FILE) ? MDS_OPEN_JOIN_FILE : 0) |
123 ((flags & FMODE_EXEC) ? MDS_FMODE_EXEC : 0) |
128 /* packing of MDS records */
129 void mdc_join_pack(struct ptlrpc_request *req, int offset,
130 struct md_op_data *op_data, __u64 head_size)
132 struct mdt_rec_join *rec;
134 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*rec));
135 LASSERT(rec != NULL);
136 rec->jr_fid = op_data->fid2;
137 rec->jr_headsize = head_size;
140 void mdc_open_pack(struct ptlrpc_request *req, int offset,
141 struct md_op_data *op_data, __u32 mode, __u64 rdev,
142 __u32 flags, const void *lmm, int lmmlen)
144 struct mdt_rec_create *rec;
146 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
148 /* XXX do something about time, uid, gid */
149 rec->cr_opcode = REINT_OPEN;
150 rec->cr_fsuid = current->fsuid;
151 rec->cr_fsgid = current->fsgid;
152 rec->cr_cap = current->cap_effective;
153 if (op_data != NULL) {
154 rec->cr_fid1 = op_data->fid1;
155 rec->cr_fid2 = op_data->fid2;
158 rec->cr_flags = mds_pack_open_flags(flags);
160 rec->cr_time = op_data->mod_time;
161 rec->cr_suppgid = op_data->suppgids[0];
164 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
165 op_data->namelen + 1);
166 LOGL0(op_data->name, op_data->namelen, tmp);
170 rec->cr_flags |= MDS_OPEN_HAS_EA;
172 /*XXX a hack for liblustre to set EA (LL_IOC_LOV_SETSTRIPE) */
173 rec->cr_fid2 = op_data->fid2;
175 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, lmmlen);
176 memcpy (tmp, lmm, lmmlen);
180 void mdc_setattr_pack(struct ptlrpc_request *req, int offset,
181 struct md_op_data *op_data, struct iattr *iattr,
182 void *ea, int ealen, void *ea2, int ea2len)
184 struct mdt_rec_setattr *rec = lustre_msg_buf(req->rq_reqmsg, offset,
186 rec->sa_opcode = REINT_SETATTR;
187 rec->sa_fsuid = current->fsuid;
188 rec->sa_fsgid = current->fsgid;
189 rec->sa_cap = current->cap_effective;
190 rec->sa_fid = op_data->fid1;
191 rec->sa_suppgid = -1;
194 rec->sa_valid = iattr->ia_valid;
195 rec->sa_mode = iattr->ia_mode;
196 rec->sa_uid = iattr->ia_uid;
197 rec->sa_gid = iattr->ia_gid;
198 rec->sa_size = iattr->ia_size;
199 rec->sa_atime = LTIME_S(iattr->ia_atime);
200 rec->sa_mtime = LTIME_S(iattr->ia_mtime);
201 rec->sa_ctime = LTIME_S(iattr->ia_ctime);
203 ((struct ll_iattr_struct *)iattr)->ia_attr_flags;
204 if ((iattr->ia_valid & ATTR_GID) && in_group_p(iattr->ia_gid))
205 rec->sa_suppgid = iattr->ia_gid;
207 rec->sa_suppgid = op_data->suppgids[0];
213 memcpy(lustre_msg_buf(req->rq_reqmsg, offset + 1, ealen), ea, ealen);
218 memcpy(lustre_msg_buf(req->rq_reqmsg, offset + 2, ea2len), ea2, ea2len);
221 void mdc_unlink_pack(struct ptlrpc_request *req, int offset,
222 struct md_op_data *op_data)
224 struct mdt_rec_unlink *rec;
227 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
228 LASSERT (rec != NULL);
230 rec->ul_opcode = REINT_UNLINK;
231 rec->ul_fsuid = op_data->fsuid;//current->fsuid;
232 rec->ul_fsgid = op_data->fsgid;//current->fsgid;
233 rec->ul_cap = current->cap_effective;
234 rec->ul_mode = op_data->create_mode;
235 rec->ul_suppgid = op_data->suppgids[0];
236 rec->ul_fid1 = op_data->fid1;
237 rec->ul_fid2 = op_data->fid2;
238 rec->ul_time = op_data->mod_time;
240 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, op_data->namelen + 1);
241 LASSERT (tmp != NULL);
242 LOGL0(op_data->name, op_data->namelen, tmp);
245 void mdc_link_pack(struct ptlrpc_request *req, int offset,
246 struct md_op_data *op_data)
248 struct mdt_rec_link *rec;
251 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
253 rec->lk_opcode = REINT_LINK;
254 rec->lk_fsuid = op_data->fsuid;//current->fsuid;
255 rec->lk_fsgid = op_data->fsgid;//current->fsgid;
256 rec->lk_cap = current->cap_effective;
257 rec->lk_suppgid1 = op_data->suppgids[0];
258 rec->lk_suppgid2 = op_data->suppgids[1];
259 rec->lk_fid1 = op_data->fid1;
260 rec->lk_fid2 = op_data->fid2;
261 rec->lk_time = op_data->mod_time;
263 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, op_data->namelen + 1);
264 LOGL0(op_data->name, op_data->namelen, tmp);
267 void mdc_rename_pack(struct ptlrpc_request *req, int offset,
268 struct md_op_data *op_data,
269 const char *old, int oldlen, const char *new, int newlen)
271 struct mdt_rec_rename *rec;
274 rec = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*rec));
276 /* XXX do something about time, uid, gid */
277 rec->rn_opcode = REINT_RENAME;
278 rec->rn_fsuid = op_data->fsuid;//current->fsuid;
279 rec->rn_fsgid = op_data->fsgid;//current->fsgid;
280 rec->rn_cap = current->cap_effective;
281 rec->rn_suppgid1 = op_data->suppgids[0];
282 rec->rn_suppgid2 = op_data->suppgids[1];
283 rec->rn_fid1 = op_data->fid1;
284 rec->rn_fid2 = op_data->fid2;
285 rec->rn_time = op_data->mod_time;
287 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1, oldlen + 1);
288 LOGL0(old, oldlen, tmp);
291 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 2, newlen + 1);
292 LOGL0(new, newlen, tmp);
296 void mdc_getattr_pack(struct ptlrpc_request *req, int offset, __u64 valid,
297 int flags, struct md_op_data *op_data)
300 b = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*b));
302 b->fsuid = current->fsuid;
303 b->fsgid = current->fsgid;
304 b->capability = current->cap_effective;
306 b->flags = flags | MDS_BFLAG_EXT_FLAGS;
307 b->suppgid = op_data->suppgids[0];
309 b->fid1 = op_data->fid1;
310 b->fid2 = op_data->fid2;
313 tmp = lustre_msg_buf(req->rq_reqmsg, offset + 1,
314 op_data->namelen + 1);
315 LOGL0(op_data->name, op_data->namelen, tmp);
319 void mdc_close_pack(struct ptlrpc_request *req, int offset,
320 struct md_op_data *op_data, __u64 valid,
321 struct obd_client_handle *och)
323 struct mdt_body *body;
325 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
327 body->fid1 = op_data->fid1;
328 memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
329 if (op_data->valid & OBD_MD_FLATIME) {
330 body->atime = op_data->atime;
331 body->valid |= OBD_MD_FLATIME;
333 if (op_data->valid & OBD_MD_FLMTIME) {
334 body->mtime = op_data->mtime;
335 body->valid |= OBD_MD_FLMTIME;
337 if (op_data->valid & OBD_MD_FLCTIME) {
338 body->ctime = op_data->ctime;
339 body->valid |= OBD_MD_FLCTIME;
341 if (op_data->valid & OBD_MD_FLSIZE) {
342 body->size = op_data->size;
343 body->valid |= OBD_MD_FLSIZE;
345 if (op_data->valid & OBD_MD_FLBLOCKS) {
346 body->blocks = op_data->blocks;
347 body->valid |= OBD_MD_FLBLOCKS;
349 if (op_data->valid & OBD_MD_FLFLAGS) {
350 body->flags = op_data->flags;
351 body->valid |= OBD_MD_FLFLAGS;
355 struct mdc_cache_waiter {
356 struct list_head mcw_entry;
357 wait_queue_head_t mcw_waitq;
360 static int mdc_req_avail(struct client_obd *cli, struct mdc_cache_waiter *mcw)
364 spin_lock(&cli->cl_loi_list_lock);
365 rc = list_empty(&mcw->mcw_entry);
366 spin_unlock(&cli->cl_loi_list_lock);
370 /* We record requests in flight in cli->cl_r_in_flight here.
371 * There is only one write rpc possible in mdc anyway. If this to change
372 * in the future - the code may need to be revisited. */
373 void mdc_enter_request(struct client_obd *cli)
375 struct mdc_cache_waiter mcw;
376 struct l_wait_info lwi = { 0 };
378 spin_lock(&cli->cl_loi_list_lock);
379 if (cli->cl_r_in_flight >= cli->cl_max_rpcs_in_flight) {
380 list_add_tail(&mcw.mcw_entry, &cli->cl_cache_waiters);
381 init_waitqueue_head(&mcw.mcw_waitq);
382 spin_unlock(&cli->cl_loi_list_lock);
383 l_wait_event(mcw.mcw_waitq, mdc_req_avail(cli, &mcw), &lwi);
385 cli->cl_r_in_flight++;
386 spin_unlock(&cli->cl_loi_list_lock);
390 void mdc_exit_request(struct client_obd *cli)
392 struct list_head *l, *tmp;
393 struct mdc_cache_waiter *mcw;
395 spin_lock(&cli->cl_loi_list_lock);
396 cli->cl_r_in_flight--;
397 list_for_each_safe(l, tmp, &cli->cl_cache_waiters) {
399 if (cli->cl_r_in_flight >= cli->cl_max_rpcs_in_flight) {
400 /* No free request slots anymore */
404 mcw = list_entry(l, struct mdc_cache_waiter, mcw_entry);
405 list_del_init(&mcw->mcw_entry);
406 cli->cl_r_in_flight++;
407 wake_up(&mcw->mcw_waitq);
409 /* Empty waiting list? Decrease reqs in-flight number */
411 spin_unlock(&cli->cl_loi_list_lock);