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 Lustre, http://www.sf.net/projects/lustre/
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.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_MDC
28 # include <linux/config.h>
29 # include <linux/module.h>
30 # include <linux/kernel.h>
32 # include <liblustre.h>
35 #include <linux/obd_class.h>
36 #include <linux/lustre_mds.h>
37 #include "mdc_internal.h"
39 /* mdc_setattr does its own semaphore handling */
40 int mdc_reint(struct ptlrpc_request *request,
41 struct mdc_rpc_lock *rpc_lock, int level)
45 request->rq_send_state = level;
48 mdc_get_rpc_lock(rpc_lock, NULL);
50 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, 0, sizeof(struct mds_body),
57 lustre_swab_mds_body)) {
58 CERROR ("Can't unpack mds_body\n");
63 EXPORT_SYMBOL(mdc_reint);
64 /* If mdc_setattr is called with an 'iattr', then it is a normal RPC that
65 * should take the normal semaphore and go to the normal portal.
67 * If it is called with iattr->ia_valid & ATTR_FROM_OPEN, then it is a
68 * magic open-path setattr that should take the setattr semaphore and
69 * go to the setattr portal. */
70 int mdc_setattr(struct obd_export *exp, struct mdc_op_data *data,
71 struct iattr *iattr, void *ea, int ealen, void *ea2, int ea2len,
72 struct ptlrpc_request **request)
74 struct ptlrpc_request *req;
75 struct mds_rec_setattr *rec;
76 struct mdc_rpc_lock *rpc_lock;
77 struct obd_device *obd = exp->exp_obd;
78 int rc, bufcount = 2, size[4] = {0, sizeof(*rec), ealen, ea2len};
81 LASSERT(iattr != NULL);
83 size[0] = mdc_get_secdesc_size();
90 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
91 MDS_REINT, bufcount, size, NULL);
95 mdc_pack_secdesc(req, size[0]);
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->rq_reqmsg, 1, data, iattr, ea, ealen,
110 size[0] = sizeof(struct mds_body);
111 req->rq_replen = lustre_msg_size(1, size);
113 rc = mdc_reint(req, rpc_lock, LUSTRE_IMP_FULL);
115 if (rc == -ERESTARTSYS)
121 int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data,
122 const void *data, int datalen, int mode, __u32 uid, __u32 gid,
123 __u64 rdev, struct ptlrpc_request **request)
125 struct obd_device *obd = exp->exp_obd;
126 struct ptlrpc_request *req;
127 int rc, size[4] = {0, sizeof(struct mds_rec_create),
128 op_data->namelen + 1};
129 int level, bufcount = 3;
132 size[0] = mdc_get_secdesc_size();
133 if (data && datalen) {
134 size[bufcount] = datalen;
138 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
139 MDS_REINT, bufcount, size, NULL);
143 mdc_pack_secdesc(req, size[0]);
145 /* mdc_create_pack fills msg->bufs[1] with name
146 * and msg->bufs[2] with tgt, for symlinks or lov MD data */
147 mdc_create_pack(req->rq_reqmsg, 1, op_data, mode, rdev, data, datalen);
149 size[0] = sizeof(struct mds_body);
150 req->rq_replen = lustre_msg_size(1, size);
152 level = LUSTRE_IMP_FULL;
154 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, level);
155 /* Resend if we were told to. */
156 if (rc == -ERESTARTSYS) {
157 level = LUSTRE_IMP_RECOVER;
162 mdc_store_inode_generation(exp, req, MDS_REQ_REC_OFF, 0);
168 int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data,
169 struct ptlrpc_request **request)
171 struct obd_device *obd = class_exp2obd(exp);
172 struct ptlrpc_request *req = *request;
173 int rc, size[4] = {0, sizeof(struct mds_rec_unlink),
175 obd->u.cli.cl_max_mds_cookiesize};
177 LASSERT(req == NULL);
179 size[0] = mdc_get_secdesc_size();
181 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
182 MDS_REINT, 4, size, NULL);
186 mdc_pack_secdesc(req, size[0]);
189 size[0] = sizeof(struct mds_body);
190 size[1] = obd->u.cli.cl_max_mds_easize;
191 size[2] = obd->u.cli.cl_max_mds_cookiesize;
193 req->rq_replen = lustre_msg_size(3, size);
195 mdc_unlink_pack(req->rq_reqmsg, 1, data);
197 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
198 if (rc == -ERESTARTSYS)
203 int mdc_link(struct obd_export *exp, struct mdc_op_data *data,
204 struct ptlrpc_request **request)
206 struct obd_device *obd = exp->exp_obd;
207 struct ptlrpc_request *req;
208 int rc, size[3] = {0, sizeof(struct mds_rec_link), data->namelen + 1};
211 size[0] = mdc_get_secdesc_size();
213 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
214 MDS_REINT, 3, size, NULL);
218 mdc_pack_secdesc(req, size[0]);
220 mdc_link_pack(req->rq_reqmsg, 1, data);
222 size[0] = sizeof(struct mds_body);
223 req->rq_replen = lustre_msg_size(1, size);
225 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
227 if (rc == -ERESTARTSYS)
233 int mdc_rename(struct obd_export *exp, struct mdc_op_data *data,
234 const char *old, int oldlen, const char *new, int newlen,
235 struct ptlrpc_request **request)
237 struct obd_device *obd = exp->exp_obd;
238 struct ptlrpc_request *req;
239 int rc, size[5] = {0, sizeof(struct mds_rec_rename), oldlen + 1,
240 newlen + 1, obd->u.cli.cl_max_mds_cookiesize};
243 size[0] = mdc_get_secdesc_size();
245 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
246 MDS_REINT, 5, size, NULL);
250 mdc_pack_secdesc(req, size[0]);
252 mdc_rename_pack(req->rq_reqmsg, 1, data, old, oldlen, new, newlen);
254 size[0] = sizeof(struct mds_body);
255 size[1] = obd->u.cli.cl_max_mds_easize;
256 size[2] = obd->u.cli.cl_max_mds_cookiesize;
257 req->rq_replen = lustre_msg_size(3, size);
259 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
261 if (rc == -ERESTARTSYS)