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 /* this function actually sends request to desired target. */
40 static int mdc_reint(struct ptlrpc_request *request,
41 struct mdc_rpc_lock *rpc_lock,
46 request->rq_send_state = level;
49 mdc_get_rpc_lock(rpc_lock, NULL);
51 rc = ptlrpc_queue_wait(request);
54 mdc_put_rpc_lock(rpc_lock, NULL);
56 CDEBUG(D_INFO, "error in handling %d\n", rc);
57 else if (!lustre_swab_repbuf(request, 0, 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 should
66 * 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 magic
69 * open-path setattr that should take the setattr semaphore and go to the
71 int mdc_setattr(struct obd_export *exp, struct mdc_op_data *data,
72 struct iattr *iattr, void *ea, int ealen, void *ea2,
73 int ea2len, 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 rc, bufcount = 2, size[4] = {0, sizeof(*rec), ealen, ea2len};
82 LASSERT(iattr != NULL);
84 size[0] = lustre_secdesc_size();
91 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
92 MDS_REINT, bufcount, size, NULL);
96 lustre_pack_secdesc(req, size[0]);
98 if (iattr->ia_valid & ATTR_FROM_OPEN) {
99 req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
100 rpc_lock = obd->u.cli.cl_setattr_lock;
102 rpc_lock = obd->u.cli.cl_rpc_lock;
105 if (iattr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
106 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu\n",
107 LTIME_S(iattr->ia_mtime), LTIME_S(iattr->ia_ctime));
108 mdc_setattr_pack(req->rq_reqmsg, 1, data, iattr, ea, ealen,
111 size[0] = sizeof(struct mds_body);
112 req->rq_replen = lustre_msg_size(1, size);
114 rc = mdc_reint(req, rpc_lock, LUSTRE_IMP_FULL);
116 if (rc == -ERESTARTSYS)
122 int mdc_create(struct obd_export *exp, struct mdc_op_data *op_data,
123 const void *data, int datalen, int mode, __u32 uid,
124 __u32 gid, __u64 rdev, struct ptlrpc_request **request)
126 struct obd_device *obd = exp->exp_obd;
127 struct ptlrpc_request *req;
128 int rc, size[4] = {0, sizeof(struct mds_rec_create),
129 op_data->namelen + 1};
130 int level, bufcount = 3;
133 size[0] = lustre_secdesc_size();
134 if (data && datalen) {
135 size[bufcount] = datalen;
139 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
140 MDS_REINT, bufcount, size, NULL);
144 lustre_pack_secdesc(req, size[0]);
147 * mdc_create_pack() fills msg->bufs[1] with name and msg->bufs[2] with
148 * tgt, for symlinks or lov MD data.
150 mdc_create_pack(req->rq_reqmsg, 1, op_data, mode, rdev, data, datalen);
152 size[0] = sizeof(struct mds_body);
153 req->rq_replen = lustre_msg_size(1, size);
155 level = LUSTRE_IMP_FULL;
157 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, level);
159 /* resend if we were told to. */
160 if (rc == -ERESTARTSYS) {
161 level = LUSTRE_IMP_RECOVER;
166 mdc_store_inode_generation(exp, req, MDS_REQ_REC_OFF, 0);
172 int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data,
173 struct ptlrpc_request **request)
175 struct obd_device *obd = class_exp2obd(exp);
176 struct ptlrpc_request *req = *request;
177 int rc, size[4] = {0, sizeof(struct mds_rec_unlink),
179 obd->u.cli.cl_max_mds_cookiesize};
181 LASSERT(req == NULL);
183 size[0] = lustre_secdesc_size();
185 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
186 MDS_REINT, 4, size, NULL);
190 lustre_pack_secdesc(req, size[0]);
193 size[0] = sizeof(struct mds_body);
194 size[1] = obd->u.cli.cl_max_mds_easize;
195 size[2] = obd->u.cli.cl_max_mds_cookiesize;
197 req->rq_replen = lustre_msg_size(3, size);
199 mdc_unlink_pack(req->rq_reqmsg, 1, data);
201 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
202 if (rc == -ERESTARTSYS)
207 int mdc_link(struct obd_export *exp, struct mdc_op_data *data,
208 struct ptlrpc_request **request)
210 struct obd_device *obd = exp->exp_obd;
211 struct ptlrpc_request *req;
212 int rc, size[3] = {0, sizeof(struct mds_rec_link), data->namelen + 1};
215 size[0] = lustre_secdesc_size();
217 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
218 MDS_REINT, 3, size, NULL);
222 lustre_pack_secdesc(req, size[0]);
224 mdc_link_pack(req->rq_reqmsg, 1, data);
226 size[0] = sizeof(struct mds_body);
227 req->rq_replen = lustre_msg_size(1, size);
229 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
231 if (rc == -ERESTARTSYS)
237 int mdc_rename(struct obd_export *exp, struct mdc_op_data *data,
238 const char *old, int oldlen, const char *new, int newlen,
239 struct ptlrpc_request **request)
241 struct obd_device *obd = exp->exp_obd;
242 struct ptlrpc_request *req;
243 int rc, size[5] = {0, sizeof(struct mds_rec_rename), oldlen + 1,
244 newlen + 1, obd->u.cli.cl_max_mds_cookiesize};
247 size[0] = lustre_secdesc_size();
249 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
250 MDS_REINT, 5, size, NULL);
254 lustre_pack_secdesc(req, size[0]);
256 mdc_rename_pack(req->rq_reqmsg, 1, data, old, oldlen, new, newlen);
258 size[0] = sizeof(struct mds_body);
259 size[1] = obd->u.cli.cl_max_mds_easize;
260 size[2] = obd->u.cli.cl_max_mds_cookiesize;
261 req->rq_replen = lustre_msg_size(3, size);
263 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
265 if (rc == -ERESTARTSYS)