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 DEBUG_SUBSYSTEM S_MDC
26 # include <linux/config.h>
27 # include <linux/module.h>
28 # include <linux/kernel.h>
30 # include <liblustre.h>
33 #include <linux/obd_class.h>
34 #include <linux/lustre_mds.h>
35 #include "mdc_internal.h"
37 /* mdc_setattr does its own semaphore handling */
38 static int mdc_reint(struct ptlrpc_request *request, int level)
43 opcodeptr = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*opcodeptr));
44 request->rq_level = level;
46 if (!(*opcodeptr == REINT_SETATTR))
47 mdc_get_rpc_lock(&mdc_rpc_lock, NULL);
48 rc = ptlrpc_queue_wait(request);
49 if (!(*opcodeptr == REINT_SETATTR))
50 mdc_put_rpc_lock(&mdc_rpc_lock, NULL);
53 CDEBUG(D_INFO, "error in handling %d\n", rc);
57 /* If mdc_setattr is called with an 'iattr', then it is a normal RPC that
58 * should take the normal semaphore and go to the normal portal.
60 * If it is called with iattr->ia_valid & ATTR_FROM_OPEN, then it is a
61 * magic open-path setattr that should take the setattr semaphore and
62 * go to the setattr portal. */
63 int mdc_setattr(struct lustre_handle *conn,
64 struct mdc_op_data *data,
65 struct iattr *iattr, void *ea, int ealen,
66 struct ptlrpc_request **request)
68 struct ptlrpc_request *req;
69 struct mds_rec_setattr *rec;
70 struct mdc_rpc_lock *rpc_lock;
71 int rc, bufcount = 1, size[2] = {sizeof(*rec), ealen};
74 LASSERT(iattr != NULL);
79 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
84 if (iattr->ia_valid & ATTR_FROM_OPEN) {
85 req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
86 rpc_lock = &mdc_setattr_lock;
88 rpc_lock = &mdc_rpc_lock;
90 mds_setattr_pack(req, data, iattr, ea, ealen);
92 size[0] = sizeof(struct mds_body);
93 req->rq_replen = lustre_msg_size(1, size);
95 mdc_get_rpc_lock(rpc_lock, NULL);
96 rc = mdc_reint(req, LUSTRE_CONN_FULL);
97 mdc_put_rpc_lock(rpc_lock, NULL);
100 if (rc == -ERESTARTSYS)
106 int mdc_create(struct lustre_handle *conn,
107 struct mdc_op_data *op_data,
108 const void *data, int datalen,
109 int mode, __u32 uid, __u32 gid, __u64 time, __u64 rdev,
110 struct ptlrpc_request **request)
112 struct ptlrpc_request *req;
113 int rc, size[3] = {sizeof(struct mds_rec_create),
114 op_data->namelen + 1, 0};
115 int level, bufcount = 2;
118 if (data && datalen) {
119 size[bufcount] = datalen;
123 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
129 /* mds_create_pack fills msg->bufs[1] with name
130 * and msg->bufs[2] with tgt, for symlinks or lov MD data */
131 mds_create_pack(req, 0, op_data,
132 mode, rdev, uid, gid, time,
135 size[0] = sizeof(struct mds_body);
136 req->rq_replen = lustre_msg_size(1, size);
138 level = LUSTRE_CONN_FULL;
140 rc = mdc_reint(req, level);
141 /* Resend if we were told to. */
142 if (rc == -ERESTARTSYS) {
143 level = LUSTRE_CONN_RECOVER;
148 mdc_store_inode_generation(req, 0, 0);
155 int mdc_unlink(struct lustre_handle *conn,
156 struct mdc_op_data *data,
157 struct ptlrpc_request **request)
159 struct obd_device *obddev = class_conn2obd(conn);
160 struct ptlrpc_request *req = *request;
161 int rc, size[2] = {sizeof(struct mds_rec_unlink), data->namelen + 1};
164 LASSERT(req == NULL);
166 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size,
172 size[0] = sizeof(struct mds_body);
173 size[1] = obddev->u.cli.cl_max_mds_easize;
174 req->rq_replen = lustre_msg_size(2, size);
176 mds_unlink_pack(req, 0, data);
178 rc = mdc_reint(req, LUSTRE_CONN_FULL);
179 if (rc == -ERESTARTSYS)
184 int mdc_link(struct lustre_handle *conn,
185 struct mdc_op_data *data,
186 struct ptlrpc_request **request)
188 struct ptlrpc_request *req;
189 int rc, size[2] = {sizeof(struct mds_rec_link), data->namelen + 1};
192 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size,
197 mds_link_pack(req, 0, data);
199 size[0] = sizeof(struct mds_body);
200 req->rq_replen = lustre_msg_size(1, size);
202 rc = mdc_reint(req, LUSTRE_CONN_FULL);
204 if (rc == -ERESTARTSYS)
210 int mdc_rename(struct lustre_handle *conn,
211 struct mdc_op_data *data,
212 const char *old, int oldlen,
213 const char *new, int newlen,
214 struct ptlrpc_request **request)
216 struct ptlrpc_request *req;
217 int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
221 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 3, size,
226 mds_rename_pack(req, 0, data, old, oldlen, new, newlen);
228 size[0] = sizeof(struct mds_body);
229 req->rq_replen = lustre_msg_size(1, size);
231 rc = mdc_reint(req, LUSTRE_CONN_FULL);
233 if (rc == -ERESTARTSYS)