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 mds_body),
58 lustre_swab_mds_body)) {
59 CERROR ("Can't unpack mds_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 mdc_op_data *data,
72 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
73 struct ptlrpc_request **request)
75 struct ptlrpc_request *req;
76 struct mds_rec_setattr *rec;
77 struct mdc_rpc_lock *rpc_lock;
78 struct obd_device *obd = exp->exp_obd;
79 int size[4] = { sizeof(struct ptlrpc_body),
80 sizeof(*rec), ealen, ea2len };
84 LASSERT(iattr != NULL);
92 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
93 MDS_REINT, bufcount, size, NULL);
97 if (iattr->ia_valid & ATTR_FROM_OPEN) {
98 req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
99 rpc_lock = obd->u.cli.cl_setattr_lock;
101 rpc_lock = obd->u.cli.cl_rpc_lock;
104 if (iattr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
105 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu\n",
106 LTIME_S(iattr->ia_mtime), LTIME_S(iattr->ia_ctime));
107 mdc_setattr_pack(req, REQ_REC_OFF, data, iattr, ea, ealen, ea2, ea2len);
109 size[REPLY_REC_OFF] = sizeof(struct mds_body);
110 ptlrpc_req_set_repsize(req, 2, size);
112 rc = mdc_reint(req, rpc_lock, LUSTRE_IMP_FULL);
114 if (rc == -ERESTARTSYS)
120 int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data,
121 const void *data, int datalen, int mode, __u32 uid, __u32 gid,
122 __u32 cap_effective, __u64 rdev, struct ptlrpc_request **request)
124 struct obd_device *obd = exp->exp_obd;
125 struct ptlrpc_request *req;
126 int level, bufcount = 3, rc;
127 int size[4] = { sizeof(struct ptlrpc_body),
128 sizeof(struct mds_rec_create),
129 op_data->namelen + 1 };
132 if (data && datalen) {
133 size[bufcount] = datalen;
137 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
138 MDS_REINT, bufcount, size, NULL);
142 /* mdc_create_pack fills msg->bufs[1] with name
143 * and msg->bufs[2] with tgt, for symlinks or lov MD data */
144 mdc_create_pack(req, REQ_REC_OFF, op_data, data, datalen, mode, uid,
145 gid, cap_effective, rdev);
147 size[REPLY_REC_OFF] = sizeof(struct mds_body);
148 ptlrpc_req_set_repsize(req, 2, size);
150 level = LUSTRE_IMP_FULL;
152 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, level);
153 /* Resend if we were told to. */
154 if (rc == -ERESTARTSYS) {
155 level = LUSTRE_IMP_RECOVER;
160 mdc_store_inode_generation(req, REQ_REC_OFF, REPLY_REC_OFF);
166 int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data,
167 struct ptlrpc_request **request)
169 struct obd_device *obd = class_exp2obd(exp);
170 struct ptlrpc_request *req = *request;
171 int size[4] = { sizeof(struct ptlrpc_body),
172 sizeof(struct mds_rec_unlink),
177 LASSERT(req == NULL);
178 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
179 MDS_REINT, 3, size, NULL);
184 size[REPLY_REC_OFF] = sizeof(struct mds_body);
185 size[REPLY_REC_OFF + 1] = obd->u.cli.cl_max_mds_easize;
186 size[REPLY_REC_OFF + 2] = obd->u.cli.cl_max_mds_cookiesize;
187 ptlrpc_req_set_repsize(req, 4, size);
189 mdc_unlink_pack(req, REQ_REC_OFF, data);
191 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
192 if (rc == -ERESTARTSYS)
197 int mdc_link(struct obd_export *exp, struct mdc_op_data *data,
198 struct ptlrpc_request **request)
200 struct obd_device *obd = exp->exp_obd;
201 struct ptlrpc_request *req;
202 int size[3] = { sizeof(struct ptlrpc_body),
203 sizeof(struct mds_rec_link),
208 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
209 MDS_REINT, 3, size, NULL);
213 mdc_link_pack(req, REQ_REC_OFF, data);
215 size[REPLY_REC_OFF] = sizeof(struct mds_body);
216 ptlrpc_req_set_repsize(req, 2, size);
218 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
220 if (rc == -ERESTARTSYS)
226 int mdc_rename(struct obd_export *exp, struct mdc_op_data *data,
227 const char *old, int oldlen, const char *new, int newlen,
228 struct ptlrpc_request **request)
230 struct obd_device *obd = exp->exp_obd;
231 struct ptlrpc_request *req;
232 int size[4] = { sizeof(struct ptlrpc_body),
233 sizeof(struct mds_rec_rename),
239 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
240 MDS_REINT, 4, size, NULL);
244 mdc_rename_pack(req, REQ_REC_OFF, data, old, oldlen, new, newlen);
246 size[REPLY_REC_OFF] = sizeof(struct mds_body);
247 size[REPLY_REC_OFF + 1] = obd->u.cli.cl_max_mds_easize;
248 size[REPLY_REC_OFF + 2] = obd->u.cli.cl_max_mds_cookiesize;
249 ptlrpc_req_set_repsize(req, 4, size);
251 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
253 if (rc == -ERESTARTSYS)