1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-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.
26 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_MDC
31 #ifdef HAVE_KERNEL_CONFIG_H
32 # include <linux/config.h>
34 # include <linux/module.h>
35 # include <linux/kernel.h>
37 # include <liblustre.h>
40 #include <obd_class.h>
41 #include "mdc_internal.h"
43 /* mdc_setattr does its own semaphore handling */
44 static int mdc_reint(struct ptlrpc_request *request,
45 struct mdc_rpc_lock *rpc_lock, int level)
49 request->rq_send_state = level;
51 mdc_get_rpc_lock(rpc_lock, NULL);
52 rc = ptlrpc_queue_wait(request);
53 mdc_put_rpc_lock(rpc_lock, NULL);
55 CDEBUG(D_INFO, "error in handling %d\n", rc);
56 else if (!lustre_swab_repbuf(request, REPLY_REC_OFF,
57 sizeof(struct mdt_body),
58 lustre_swab_mdt_body)) {
59 CERROR ("Can't unpack mdt_body\n");
65 /* If mdc_setattr is called with an 'iattr', then it is a normal RPC that
66 * should take the normal semaphore and go to the normal portal.
68 * If it is called with iattr->ia_valid & ATTR_FROM_OPEN, then it is a
69 * magic open-path setattr that should take the setattr semaphore and
70 * go to the setattr portal. */
71 int mdc_setattr(struct obd_export *exp, struct md_op_data *op_data,
72 void *ea, int ealen, void *ea2, int ea2len,
73 struct ptlrpc_request **request)
75 struct ptlrpc_request *req;
76 struct mdt_rec_setattr *rec;
77 struct mdc_rpc_lock *rpc_lock;
78 struct obd_device *obd = exp->exp_obd;
79 int size[6] = { sizeof(struct ptlrpc_body),
80 sizeof(*rec), 0, 0, ealen, ea2len };
84 LASSERT(op_data != NULL);
86 size[REQ_REC_OFF + 1] = op_data->op_capa1 ?
87 sizeof(struct lustre_capa) : 0;
89 if (op_data->op_flags & (MF_SOM_CHANGE | MF_EPOCH_OPEN))
90 size[REQ_REC_OFF + 2] = sizeof(struct mdt_epoch);
98 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
99 MDS_REINT, bufcount, size, NULL);
103 if (op_data->op_attr.ia_valid & ATTR_FROM_OPEN) {
104 req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
105 rpc_lock = obd->u.cli.cl_setattr_lock;
107 rpc_lock = obd->u.cli.cl_rpc_lock;
110 if (op_data->op_attr.ia_valid & (ATTR_MTIME | ATTR_CTIME))
111 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu\n",
112 LTIME_S(op_data->op_attr.ia_mtime),
113 LTIME_S(op_data->op_attr.ia_ctime));
114 mdc_setattr_pack(req, REQ_REC_OFF, op_data, ea, ealen, ea2, ea2len);
116 size[REPLY_REC_OFF] = sizeof(struct mdt_body);
117 size[REPLY_REC_OFF + 1] = sizeof(struct lustre_capa);
118 ptlrpc_req_set_repsize(req, 3, size);
120 rc = mdc_reint(req, rpc_lock, LUSTRE_IMP_FULL);
122 if (rc == -ERESTARTSYS)
128 int mdc_create(struct obd_export *exp, struct md_op_data *op_data,
129 const void *data, int datalen, int mode, __u32 uid, __u32 gid,
130 __u32 cap_effective, __u64 rdev, struct ptlrpc_request **request)
132 int size[5] = { sizeof(struct ptlrpc_body),
133 sizeof(struct mdt_rec_create),
134 0, op_data->op_namelen + 1 };
135 struct obd_device *obd = exp->exp_obd;
136 int level, bufcount = 4, rc;
137 struct ptlrpc_request *req;
140 /* For case if upper layer did not alloc fid, do it now. */
141 if (!fid_is_sane(&op_data->op_fid2)) {
143 * mdc_fid_alloc() may return errno 1 in case of switch to new
144 * sequence, handle this.
146 rc = mdc_fid_alloc(exp, &op_data->op_fid2, op_data);
148 CERROR("Can't alloc new fid, rc %d\n", rc);
153 size[REQ_REC_OFF + 1] = op_data->op_capa1 ?
154 sizeof(struct lustre_capa) : 0;
156 if (data && datalen) {
157 size[bufcount] = datalen;
161 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
162 MDS_REINT, bufcount, size, NULL);
167 * mdc_create_pack() fills msg->bufs[1] with name and msg->bufs[2] with
168 * tgt, for symlinks or lov MD data.
170 mdc_create_pack(req, REQ_REC_OFF, op_data, data, datalen, mode, uid,
171 gid, cap_effective, rdev);
173 size[REPLY_REC_OFF] = sizeof(struct mdt_body);
174 size[REPLY_REC_OFF + 1] = sizeof(struct lustre_capa);
175 ptlrpc_req_set_repsize(req, 3, size);
177 level = LUSTRE_IMP_FULL;
179 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, level);
181 /* Resend if we were told to. */
182 if (rc == -ERESTARTSYS) {
183 level = LUSTRE_IMP_RECOVER;
185 } else if (rc == 0) {
186 struct mdt_body *body;
187 struct lustre_capa *capa;
189 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
192 if (body->valid & OBD_MD_FLMDSCAPA) {
193 capa = lustre_unpack_capa(req->rq_repmsg,
196 CERROR("Missing/short MDS capability\n");
206 int mdc_unlink(struct obd_export *exp, struct md_op_data *op_data,
207 struct ptlrpc_request **request)
209 struct obd_device *obd = class_exp2obd(exp);
210 struct ptlrpc_request *req = *request;
211 int size[4] = { sizeof(struct ptlrpc_body),
212 sizeof(struct mdt_rec_unlink),
213 0, op_data->op_namelen + 1 };
217 LASSERT(req == NULL);
219 size[REQ_REC_OFF + 1] = op_data->op_capa1 ?
220 sizeof(struct lustre_capa) : 0;
222 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
223 MDS_REINT, 4, size, NULL);
228 size[REPLY_REC_OFF] = sizeof(struct mdt_body);
229 size[REPLY_REC_OFF + 1] = obd->u.cli.cl_max_mds_easize;
230 size[REPLY_REC_OFF + 2] = obd->u.cli.cl_max_mds_cookiesize;
231 ptlrpc_req_set_repsize(req, 4, size);
233 mdc_unlink_pack(req, REQ_REC_OFF, op_data);
235 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
236 if (rc == -ERESTARTSYS)
241 int mdc_link(struct obd_export *exp, struct md_op_data *op_data,
242 struct ptlrpc_request **request)
244 struct obd_device *obd = exp->exp_obd;
245 struct ptlrpc_request *req;
246 int size[5] = { sizeof(struct ptlrpc_body),
247 sizeof(struct mdt_rec_link),
248 0, 0, op_data->op_namelen + 1 };
252 size[REQ_REC_OFF + 1] = op_data->op_capa1 ?
253 sizeof(struct lustre_capa) : 0;
254 size[REQ_REC_OFF + 2] = op_data->op_capa2 ?
255 sizeof(struct lustre_capa) : 0;
257 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
258 MDS_REINT, 5, size, NULL);
262 mdc_link_pack(req, REQ_REC_OFF, op_data);
264 size[REPLY_REC_OFF] = sizeof(struct mdt_body);
265 ptlrpc_req_set_repsize(req, 2, size);
267 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
269 if (rc == -ERESTARTSYS)
275 int mdc_rename(struct obd_export *exp, struct md_op_data *op_data,
276 const char *old, int oldlen, const char *new, int newlen,
277 struct ptlrpc_request **request)
279 struct obd_device *obd = exp->exp_obd;
280 struct ptlrpc_request *req;
281 int size[6] = { sizeof(struct ptlrpc_body),
282 sizeof(struct mdt_rec_rename),
283 0, 0, oldlen + 1, newlen + 1 };
287 size[REQ_REC_OFF + 1] = op_data->op_capa1 ?
288 sizeof(struct lustre_capa) : 0;
289 size[REQ_REC_OFF + 2] = op_data->op_capa2 ?
290 sizeof(struct lustre_capa) : 0;
292 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
293 MDS_REINT, 6, size, NULL);
297 mdc_rename_pack(req, REQ_REC_OFF, op_data, old, oldlen, new, newlen);
299 size[REPLY_REC_OFF] = sizeof(struct mdt_body);
300 size[REPLY_REC_OFF + 1] = obd->u.cli.cl_max_mds_easize;
301 size[REPLY_REC_OFF + 2] = obd->u.cli.cl_max_mds_cookiesize;
302 ptlrpc_req_set_repsize(req, 4, size);
304 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
306 if (rc == -ERESTARTSYS)