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 <linux/lustre_acl.h>
38 #include "mdc_internal.h"
40 /* this function actually sends request to desired target. */
41 static int mdc_reint(struct ptlrpc_request *request,
42 struct mdc_rpc_lock *rpc_lock,
47 request->rq_send_state = level;
50 mdc_get_rpc_lock(rpc_lock, NULL);
52 rc = ptlrpc_queue_wait(request);
55 mdc_put_rpc_lock(rpc_lock, NULL);
57 CDEBUG(D_INFO, "error in handling %d\n", rc);
58 else if (!lustre_swab_repbuf(request, 0, sizeof(struct mds_body),
59 lustre_swab_mds_body)) {
60 CERROR ("Can't unpack mds_body\n");
66 /* If mdc_setattr is called with an 'iattr', then it is a normal RPC that should
67 * take the normal semaphore and go to the normal portal.
69 * If it is called with iattr->ia_valid & ATTR_FROM_OPEN, then it is a magic
70 * open-path setattr that should take the setattr semaphore and go to the
72 int mdc_setattr(struct obd_export *exp, struct mdc_op_data *data,
73 struct iattr *iattr, void *ea, int ealen, void *ea2,
74 int ea2len, void *ea3, int ea3len,
75 struct ptlrpc_request **request)
77 struct ptlrpc_request *req;
78 struct mds_rec_setattr *rec;
79 struct mdc_rpc_lock *rpc_lock;
80 struct obd_device *obd = exp->exp_obd;
81 int rc, bufcount = 2, size[4] = {0, sizeof(*rec), ealen, ea2len};
84 LASSERT(iattr != NULL);
86 size[0] = lustre_secdesc_size();
95 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
96 MDS_REINT, bufcount, size, NULL);
100 lustre_pack_secdesc(req, size[0]);
102 if (iattr->ia_valid & ATTR_FROM_OPEN) {
103 req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
104 rpc_lock = obd->u.cli.cl_setattr_lock;
106 rpc_lock = obd->u.cli.cl_rpc_lock;
109 if (iattr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
110 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu\n",
111 LTIME_S(iattr->ia_mtime), LTIME_S(iattr->ia_ctime));
112 mdc_setattr_pack(req->rq_reqmsg, 1, data, iattr, ea, ealen,
113 ea2, ea2len, ea3, ea3len);
115 /* prepare the reply buffer
118 size[0] = sizeof(struct mds_body);
120 /* This is a hack for setfacl remotely. XXX */
121 if (ealen == sizeof(XATTR_NAME_LUSTRE_ACL) &&
122 !strncmp((char *) ea, XATTR_NAME_LUSTRE_ACL, ealen)) {
123 size[bufcount++] = LUSTRE_ACL_SIZE_MAX;
126 req->rq_replen = lustre_msg_size(bufcount, size);
128 rc = mdc_reint(req, rpc_lock, LUSTRE_IMP_FULL);
130 if (rc == -ERESTARTSYS)
136 int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data,
137 const void *data, int datalen, int mode, __u32 uid,
138 __u32 gid, __u64 rdev, struct ptlrpc_request **request)
140 struct obd_device *obd = exp->exp_obd;
141 struct ptlrpc_request *req;
142 int rc, size[4] = {0, sizeof(struct mds_rec_create),
143 op_data->namelen + 1};
144 int level, bufcount = 3;
147 size[0] = lustre_secdesc_size();
148 if (data && datalen) {
149 size[bufcount] = datalen;
153 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
154 MDS_REINT, bufcount, size, NULL);
158 lustre_pack_secdesc(req, size[0]);
161 * mdc_create_pack() fills msg->bufs[1] with name and msg->bufs[2] with
162 * tgt, for symlinks or lov MD data.
164 mdc_create_pack(req->rq_reqmsg, 1, op_data, mode, rdev, data, datalen);
166 size[0] = sizeof(struct mds_body);
167 req->rq_replen = lustre_msg_size(1, size);
169 level = LUSTRE_IMP_FULL;
171 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, level);
173 /* resend if we were told to. */
174 if (rc == -ERESTARTSYS) {
175 level = LUSTRE_IMP_RECOVER;
180 mdc_store_inode_generation(exp, req, MDS_REQ_REC_OFF, 0);
186 int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data,
187 struct ptlrpc_request **request)
189 struct obd_device *obd = class_exp2obd(exp);
190 struct ptlrpc_request *req = *request;
191 int rc, size[4] = {0, sizeof(struct mds_rec_unlink),
193 obd->u.cli.cl_max_mds_cookiesize};
195 LASSERT(req == NULL);
197 size[0] = lustre_secdesc_size();
199 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
200 MDS_REINT, 4, size, NULL);
204 lustre_pack_secdesc(req, size[0]);
207 size[0] = sizeof(struct mds_body);
208 size[1] = obd->u.cli.cl_max_mds_easize;
209 size[2] = obd->u.cli.cl_max_mds_cookiesize;
211 req->rq_replen = lustre_msg_size(3, size);
213 mdc_unlink_pack(req->rq_reqmsg, 1, data);
215 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
216 if (rc == -ERESTARTSYS)
221 int mdc_link(struct obd_export *exp, struct mdc_op_data *data,
222 struct ptlrpc_request **request)
224 struct obd_device *obd = exp->exp_obd;
225 struct ptlrpc_request *req;
226 int rc, size[3] = {0, sizeof(struct mds_rec_link), data->namelen + 1};
229 size[0] = lustre_secdesc_size();
231 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
232 MDS_REINT, 3, size, NULL);
236 lustre_pack_secdesc(req, size[0]);
238 mdc_link_pack(req->rq_reqmsg, 1, data);
240 size[0] = sizeof(struct mds_body);
241 req->rq_replen = lustre_msg_size(1, size);
243 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
245 if (rc == -ERESTARTSYS)
251 int mdc_rename(struct obd_export *exp, struct mdc_op_data *data,
252 const char *old, int oldlen, const char *new, int newlen,
253 struct ptlrpc_request **request)
255 struct obd_device *obd = exp->exp_obd;
256 struct ptlrpc_request *req;
257 int rc, size[5] = {0, sizeof(struct mds_rec_rename), oldlen + 1,
258 newlen + 1, obd->u.cli.cl_max_mds_cookiesize};
261 size[0] = lustre_secdesc_size();
263 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
264 MDS_REINT, 5, size, NULL);
268 lustre_pack_secdesc(req, size[0]);
270 mdc_rename_pack(req->rq_reqmsg, 1, data, old, oldlen, new, newlen);
272 size[0] = sizeof(struct mds_body);
273 size[1] = obd->u.cli.cl_max_mds_easize;
274 size[2] = obd->u.cli.cl_max_mds_cookiesize;
275 req->rq_replen = lustre_msg_size(3, size);
277 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
279 if (rc == -ERESTARTSYS)