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 extern struct semaphore mdc_sem;
35 static int mdc_reint(struct ptlrpc_request *request, int level)
38 __u32 *opcodeptr = lustre_msg_buf(request->rq_reqmsg, 0);
40 request->rq_level = level;
42 if (!(*opcodeptr == REINT_SETATTR))
43 mdc_get_rpc_lock(&mdc_rpc_lock, NULL);
45 rc = ptlrpc_queue_wait(request);
46 if (!(*opcodeptr == REINT_SETATTR))
47 mdc_put_rpc_lock(&mdc_rpc_lock, NULL);
50 CDEBUG(D_INFO, "error in handling %d\n", rc);
52 /* For future resend/replays. */
53 *opcodeptr |= REINT_REPLAYING;
58 int mdc_setattr(struct lustre_handle *conn, struct inode *inode,
59 struct iattr *iattr, void *ea, int ealen,
60 struct ptlrpc_request **request)
62 struct ptlrpc_request *req;
63 struct mds_rec_setattr *rec;
64 int rc, bufcount = 1, size[2] = {sizeof(*rec), ealen};
70 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
75 /* XXX FIXME bug 249 */
76 req->rq_request_portal = MDS_GETATTR_PORTAL;
78 mds_setattr_pack(req, inode, iattr, ea, ealen);
80 size[0] = sizeof(struct mds_body);
81 req->rq_replen = lustre_msg_size(1, size);
83 rc = mdc_reint(req, LUSTRE_CONN_FULL);
85 if (rc == -ERESTARTSYS)
91 int mdc_create(struct lustre_handle *conn, struct inode *dir,
92 const char *name, int namelen, const void *data, int datalen,
93 int mode, __u32 uid, __u32 gid, __u64 time, __u64 rdev,
94 struct ptlrpc_request **request)
96 struct ptlrpc_request *req;
97 int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
98 int level, bufcount = 2;
101 if (data && datalen) {
102 size[bufcount] = datalen;
106 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
111 /* mds_create_pack fills msg->bufs[1] with name
112 * and msg->bufs[2] with tgt, for symlinks or lov MD data */
113 mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
114 name, namelen, data, datalen);
116 size[0] = sizeof(struct mds_body);
117 req->rq_replen = lustre_msg_size(1, size);
119 level = LUSTRE_CONN_FULL;
121 rc = mdc_reint(req, level);
122 /* Resend if we were told to. */
123 if (rc == -ERESTARTSYS) {
124 level = LUSTRE_CONN_RECOVD;
130 mdc_store_inode_generation(req, 0, 0);
136 int mdc_unlink(struct lustre_handle *conn, struct inode *dir,
137 struct inode *child, __u32 mode, const char *name, int namelen,
138 struct ptlrpc_request **request)
140 struct obd_device *obddev = class_conn2obd(conn);
141 struct ptlrpc_request *req = *request;
142 int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
145 LASSERT(req == NULL);
147 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size,
153 size[0] = sizeof(struct mds_body);
154 size[1] = obddev->u.cli.cl_max_mds_easize;
155 req->rq_replen = lustre_msg_size(2, size);
157 mds_unlink_pack(req, 0, dir, child, mode, name, namelen);
159 rc = mdc_reint(req, LUSTRE_CONN_FULL);
160 if (rc == -ERESTARTSYS)
165 int mdc_link(struct lustre_handle *conn,
166 struct inode *src, struct inode *dir, const char *name,
167 int namelen, struct ptlrpc_request **request)
169 struct ptlrpc_request *req;
170 int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
173 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size,
178 mds_link_pack(req, 0, src, dir, name, namelen);
180 size[0] = sizeof(struct mds_body);
181 req->rq_replen = lustre_msg_size(1, size);
183 rc = mdc_reint(req, LUSTRE_CONN_FULL);
185 if (rc == -ERESTARTSYS)
191 int mdc_rename(struct lustre_handle *conn,
192 struct inode *src, struct inode *tgt, const char *old,
193 int oldlen, const char *new, int newlen,
194 struct ptlrpc_request **request)
196 struct ptlrpc_request *req;
197 int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
201 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 3, size,
206 mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
208 size[0] = sizeof(struct mds_body);
209 req->rq_replen = lustre_msg_size(1, size);
211 rc = mdc_reint(req, LUSTRE_CONN_FULL);
213 if (rc == -ERESTARTSYS)