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 = 1, size[3] = {sizeof(*rec), ealen, ea2len};
81 LASSERT(iattr != NULL);
89 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_REINT, bufcount,
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->rq_reqmsg, data, iattr, ea, ealen, ea2, ea2len);
106 size[0] = sizeof(struct mds_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 mdc_op_data *op_data,
118 const void *data, int datalen, int mode, __u32 uid, __u32 gid,
119 __u64 rdev, struct ptlrpc_request **request)
121 struct obd_device *obd = exp->exp_obd;
122 struct ptlrpc_request *req;
123 int rc, size[3] = {sizeof(struct mds_rec_create), op_data->namelen + 1};
124 int level, bufcount = 2;
127 if (data && datalen) {
128 size[bufcount] = datalen;
132 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_REINT, bufcount,
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->rq_reqmsg, 0, op_data, mode, rdev, data, datalen);
141 size[0] = sizeof(struct mds_body);
142 req->rq_replen = lustre_msg_size(1, size);
144 level = LUSTRE_IMP_FULL;
146 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, level);
147 /* Resend if we were told to. */
148 if (rc == -ERESTARTSYS) {
149 level = LUSTRE_IMP_RECOVER;
154 mdc_store_inode_generation(exp, req, 0, 0);
160 int mdc_unlink(struct obd_export *exp, struct mdc_op_data *data,
161 struct ptlrpc_request **request)
163 struct obd_device *obddev = class_exp2obd(exp);
164 struct ptlrpc_request *req = *request;
165 int rc, size[3] = {sizeof(struct mds_rec_unlink),
167 obddev->u.cli.cl_max_mds_cookiesize};
170 LASSERT(req == NULL);
171 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_REINT, 3, size,
177 size[0] = sizeof(struct mds_body);
178 size[1] = obddev->u.cli.cl_max_mds_easize;
179 size[2] = obddev->u.cli.cl_max_mds_cookiesize;
180 req->rq_replen = lustre_msg_size(3, size);
182 mdc_unlink_pack(req->rq_reqmsg, 0, data);
184 rc = mdc_reint(req, obddev->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
185 if (rc == -ERESTARTSYS)
190 int mdc_link(struct obd_export *exp, struct mdc_op_data *data,
191 struct ptlrpc_request **request)
193 struct obd_device *obd = exp->exp_obd;
194 struct ptlrpc_request *req;
195 int rc, size[2] = {sizeof(struct mds_rec_link), data->namelen + 1};
198 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_REINT, 2, size,
203 mdc_link_pack(req->rq_reqmsg, 0, data);
205 size[0] = sizeof(struct mds_body);
206 req->rq_replen = lustre_msg_size(1, size);
208 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
210 if (rc == -ERESTARTSYS)
216 int mdc_rename(struct obd_export *exp, struct mdc_op_data *data,
217 const char *old, int oldlen, const char *new, int newlen,
218 struct ptlrpc_request **request)
220 struct obd_device *obd = exp->exp_obd;
221 struct ptlrpc_request *req;
222 int rc, size[4] = {sizeof(struct mds_rec_rename), oldlen + 1,
223 newlen + 1, obd->u.cli.cl_max_mds_cookiesize};
226 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_REINT, 4, size,
231 mdc_rename_pack(req->rq_reqmsg, 0, data, old, oldlen, new, newlen);
233 size[0] = sizeof(struct mds_body);
234 size[1] = obd->u.cli.cl_max_mds_easize;
235 size[2] = obd->u.cli.cl_max_mds_cookiesize;
236 req->rq_replen = lustre_msg_size(3, size);
238 rc = mdc_reint(req, obd->u.cli.cl_rpc_lock, LUSTRE_IMP_FULL);
240 if (rc == -ERESTARTSYS)