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 # include <linux/config.h>
32 # include <linux/module.h>
33 # include <linux/kernel.h>
35 # include <liblustre.h>
38 #include <linux/obd_class.h>
39 #include <linux/lustre_mdc.h>
40 #include "mdc_internal.h"
42 /* mdc_setattr does its own semaphore handling */
43 static int mdc_reint(struct ptlrpc_request *request,
44 struct mdc_rpc_lock *rpc_lock, int level)
48 request->rq_send_state = level;
50 mdc_get_rpc_lock(rpc_lock, NULL);
51 rc = ptlrpc_queue_wait(request);
52 mdc_put_rpc_lock(rpc_lock, NULL);
54 CDEBUG(D_INFO, "error in handling %d\n", rc);
55 else if (!lustre_swab_repbuf(request, 0, sizeof(struct mdt_body),
56 lustre_swab_mdt_body)) {
57 CERROR ("Can't unpack mdt_body\n");
63 /* If mdc_setattr is called with an 'iattr', then it is a normal RPC that
64 * should take the normal semaphore and go to the normal portal.
66 * If it is called with iattr->ia_valid & ATTR_FROM_OPEN, then it is a
67 * magic open-path setattr that should take the setattr semaphore and
68 * go to the setattr portal. */
69 int mdc_setattr(struct obd_export *exp, struct md_op_data *op_data,
70 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
71 struct ptlrpc_request **request)
73 struct ptlrpc_request *req;
74 struct mdt_rec_setattr *rec;
75 struct mdc_rpc_lock *rpc_lock;
76 struct obd_device *obd = exp->exp_obd;
77 int size[] = { sizeof(*rec), ealen, ea2len};
81 LASSERT(iattr != NULL);
89 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
90 MDS_REINT, bufcount, size, NULL);
94 if (iattr->ia_valid & ATTR_FROM_OPEN) {
95 req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
96 rpc_lock = obd->u.cli.cl_setattr_lock;
98 rpc_lock = obd->u.cli.cl_rpc_lock;
101 if (iattr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
102 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu\n",
103 LTIME_S(iattr->ia_mtime), LTIME_S(iattr->ia_ctime));
104 mdc_setattr_pack(req, MDS_REQ_REC_OFF, op_data, iattr, ea, ealen, ea2, ea2len);
106 size[0] = sizeof(struct mdt_body);
107 req->rq_replen = lustre_msg_size(1, size);
109 rc = mdc_reint(req, rpc_lock, LUSTRE_IMP_FULL);
111 if (rc == -ERESTARTSYS)
117 int mdc_create(struct obd_export *exp, struct md_op_data *op_data,
118 const void *data, int datalen, int mode, __u32 uid, __u32 gid,
119 __u32 cap_effective, __u64 rdev, struct ptlrpc_request **request)
121 struct obd_device *obd = exp->exp_obd;
122 struct ptlrpc_request *req;
123 int size[] = { sizeof(struct mdt_rec_create), op_data->namelen + 1, 0};
124 int rc, level, bufcount = 2;
127 if (data && datalen) {
128 size[bufcount] = datalen;
132 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
133 MDS_REINT, bufcount, size, NULL);
137 /* mdc_create_pack fills msg->bufs[1] with name
138 * and msg->bufs[2] with tgt, for symlinks or lov MD data */
139 mdc_create_pack(req, MDS_REQ_REC_OFF, op_data, data, datalen, mode,
140 uid, gid, cap_effective, rdev);
142 size[0] = sizeof(struct mdt_body);
143 req->rq_replen = lustre_msg_size(1, size);
145 level = LUSTRE_IMP_FULL;
147 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, level);
148 /* Resend if we were told to. */
149 if (rc == -ERESTARTSYS) {
150 level = LUSTRE_IMP_RECOVER;
158 int mdc_unlink(struct obd_export *exp, struct md_op_data *op_data,
159 struct ptlrpc_request **request)
161 struct obd_device *obd = class_exp2obd(exp);
162 struct ptlrpc_request *req = *request;
163 int rc, size[] = { sizeof(struct mdt_rec_unlink), op_data->namelen + 1};
166 LASSERT(req == NULL);
167 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
168 MDS_REINT, 2, size, NULL);
173 size[0] = sizeof(struct mdt_body);
174 size[1] = obd->u.cli.cl_max_mds_easize;
175 size[2] = obd->u.cli.cl_max_mds_cookiesize;
176 req->rq_replen = lustre_msg_size(3, size);
178 mdc_unlink_pack(req, MDS_REQ_REC_OFF, op_data);
180 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
181 if (rc == -ERESTARTSYS)
186 int mdc_link(struct obd_export *exp, struct md_op_data *op_data,
187 struct ptlrpc_request **request)
189 struct obd_device *obd = exp->exp_obd;
190 struct ptlrpc_request *req;
191 int rc, size[] = { sizeof(struct mdt_rec_link), op_data->namelen + 1};
194 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
195 MDS_REINT, 2, size, NULL);
199 mdc_link_pack(req, MDS_REQ_REC_OFF, op_data);
201 size[0] = sizeof(struct mdt_body);
202 req->rq_replen = lustre_msg_size(1, size);
204 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
206 if (rc == -ERESTARTSYS)
212 int mdc_rename(struct obd_export *exp, struct md_op_data *op_data,
213 const char *old, int oldlen, const char *new, int newlen,
214 struct ptlrpc_request **request)
216 struct obd_device *obd = exp->exp_obd;
217 struct ptlrpc_request *req;
218 int rc, size[] = { sizeof(struct mdt_rec_rename), oldlen +1, newlen +1};
221 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
222 MDS_REINT, 3, size, NULL);
226 mdc_rename_pack(req, MDS_REQ_REC_OFF, op_data, old, oldlen, new, newlen);
228 size[0] = sizeof(struct mdt_body);
229 size[1] = obd->u.cli.cl_max_mds_easize;
230 size[2] = obd->u.cli.cl_max_mds_cookiesize;
231 req->rq_replen = lustre_msg_size(3, size);
233 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
235 if (rc == -ERESTARTSYS)