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.
24 #include <linux/config.h>
25 #include <linux/module.h>
26 #include <linux/kernel.h>
28 #define DEBUG_SUBSYSTEM S_MDC
30 #include <linux/obd_class.h>
31 #include <linux/lustre_mds.h>
33 /* mdc_setattr does its own semaphore handling */
34 static int mdc_reint(struct ptlrpc_request *request, int level)
37 __u32 *opcodeptr = lustre_msg_buf(request->rq_reqmsg, 0);
39 request->rq_level = level;
41 if (!(*opcodeptr == REINT_SETATTR))
42 mdc_get_rpc_lock(&mdc_rpc_lock, NULL);
43 rc = ptlrpc_queue_wait(request);
44 if (!(*opcodeptr == REINT_SETATTR))
45 mdc_put_rpc_lock(&mdc_rpc_lock, NULL);
48 CDEBUG(D_INFO, "error in handling %d\n", rc);
50 /* For future resend/replays. */
51 *opcodeptr |= REINT_REPLAYING;
56 /* If mdc_setattr is called with an 'iattr', then it is a normal RPC that
57 * should take the normal semaphore and go to the normal portal.
59 * If it is called with iattr->ia_valid & ATTR_FROM_OPEN, then it is a
60 * magic open-path setattr that should take the setattr semaphore and
61 * go to the setattr portal. */
62 int mdc_setattr(struct lustre_handle *conn, struct inode *inode,
63 struct iattr *iattr, void *ea, int ealen,
64 struct ptlrpc_request **request)
66 struct ptlrpc_request *req;
67 struct mds_rec_setattr *rec;
68 struct mdc_rpc_lock *rpc_lock;
69 int rc, bufcount = 1, size[2] = {sizeof(*rec), ealen};
72 LASSERT(iattr != NULL);
77 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
82 if (iattr->ia_valid & ATTR_FROM_OPEN) {
83 req->rq_request_portal = MDS_SETATTR_PORTAL; //XXX FIXME bug 249
84 rpc_lock = &mdc_setattr_lock;
86 rpc_lock = &mdc_rpc_lock;
88 mds_setattr_pack(req, inode, iattr, ea, ealen);
90 size[0] = sizeof(struct mds_body);
91 req->rq_replen = lustre_msg_size(1, size);
93 mdc_get_rpc_lock(rpc_lock, NULL);
94 rc = mdc_reint(req, LUSTRE_CONN_FULL);
95 mdc_put_rpc_lock(rpc_lock, NULL);
98 if (rc == -ERESTARTSYS)
104 int mdc_create(struct lustre_handle *conn, struct inode *dir,
105 const char *name, int namelen, const void *data, int datalen,
106 int mode, __u32 uid, __u32 gid, __u64 time, __u64 rdev,
107 struct ptlrpc_request **request)
109 struct ptlrpc_request *req;
110 int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
111 int level, bufcount = 2;
114 if (data && datalen) {
115 size[bufcount] = datalen;
119 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
124 /* mds_create_pack fills msg->bufs[1] with name
125 * and msg->bufs[2] with tgt, for symlinks or lov MD data */
126 mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
127 name, namelen, data, datalen);
129 size[0] = sizeof(struct mds_body);
130 req->rq_replen = lustre_msg_size(1, size);
132 level = LUSTRE_CONN_FULL;
134 rc = mdc_reint(req, level);
135 /* Resend if we were told to. */
136 if (rc == -ERESTARTSYS) {
137 level = LUSTRE_CONN_RECOVD;
143 mdc_store_inode_generation(req, 0, 0);
149 int mdc_unlink(struct lustre_handle *conn, struct inode *dir,
150 struct inode *child, __u32 mode, const char *name, int namelen,
151 struct ptlrpc_request **request)
153 struct obd_device *obddev = class_conn2obd(conn);
154 struct ptlrpc_request *req = *request;
155 int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
158 LASSERT(req == NULL);
160 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size,
166 size[0] = sizeof(struct mds_body);
167 size[1] = obddev->u.cli.cl_max_mds_easize;
168 req->rq_replen = lustre_msg_size(2, size);
170 mds_unlink_pack(req, 0, dir, child, mode, name, namelen);
172 rc = mdc_reint(req, LUSTRE_CONN_FULL);
173 if (rc == -ERESTARTSYS)
178 int mdc_link(struct lustre_handle *conn,
179 struct inode *src, struct inode *dir, const char *name,
180 int namelen, struct ptlrpc_request **request)
182 struct ptlrpc_request *req;
183 int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
186 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size,
191 mds_link_pack(req, 0, src, dir, name, namelen);
193 size[0] = sizeof(struct mds_body);
194 req->rq_replen = lustre_msg_size(1, size);
196 rc = mdc_reint(req, LUSTRE_CONN_FULL);
198 if (rc == -ERESTARTSYS)
204 int mdc_rename(struct lustre_handle *conn,
205 struct inode *src, struct inode *tgt, const char *old,
206 int oldlen, const char *new, int newlen,
207 struct ptlrpc_request **request)
209 struct ptlrpc_request *req;
210 int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
214 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 3, size,
219 mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
221 size[0] = sizeof(struct mds_body);
222 req->rq_replen = lustre_msg_size(1, size);
224 rc = mdc_reint(req, LUSTRE_CONN_FULL);
226 if (rc == -ERESTARTSYS)