1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 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.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
29 #define DEBUG_SUBSYSTEM S_MDC
31 #include <linux/obd_class.h>
32 #include <linux/lustre_mds.h>
34 static int mdc_reint(struct ptlrpc_request *request, int level)
37 request->rq_level = level;
39 rc = ptlrpc_queue_wait(request);
42 CERROR("error in handling %d\n", rc);
44 /* For future resend/replays. */
45 u32 *opcodeptr = lustre_msg_buf(request->rq_reqmsg, 0);
46 *opcodeptr |= REINT_REPLAYING;
51 int mdc_setattr(struct lustre_handle *conn,
52 struct inode *inode, struct iattr *iattr,
53 struct ptlrpc_request **request)
55 struct ptlrpc_request *req;
56 struct mds_rec_setattr *rec;
57 int rc, size = sizeof(*rec);
60 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 1, &size,
65 mds_setattr_pack(req, 0, inode, iattr, NULL, 0);
67 size = sizeof(struct mds_body);
68 req->rq_replen = lustre_msg_size(1, &size);
70 rc = mdc_reint(req, LUSTRE_CONN_FULL);
72 if (rc == -ERESTARTSYS )
78 int mdc_create(struct lustre_handle *conn, struct inode *dir,
79 const char *name, int namelen, const void *data, int datalen,
80 int mode, __u32 uid, __u32 gid, __u64 time, __u64 rdev,
81 struct ptlrpc_request **request)
83 struct ptlrpc_request *req;
84 int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
85 int level, bufcount = 2;
88 if (data && datalen) {
89 size[bufcount] = datalen;
93 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
98 /* mds_create_pack fills msg->bufs[1] with name
99 * and msg->bufs[2] with tgt, for symlinks or lov MD data */
100 mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
101 name, namelen, data, datalen);
103 size[0] = sizeof(struct mds_body);
104 req->rq_replen = lustre_msg_size(1, size);
106 level = LUSTRE_CONN_FULL;
108 rc = mdc_reint(req, level);
109 /* Resend if we were told to. */
110 if (rc == -ERESTARTSYS) {
111 level = LUSTRE_CONN_RECOVD;
116 mdc_store_inode_generation(req, 0, 0);
122 int mdc_unlink(struct lustre_handle *conn, struct inode *dir,
123 struct inode *child, __u32 mode, const char *name, int namelen,
124 struct ptlrpc_request **request)
126 struct ptlrpc_request *req;
127 int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
130 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
134 mds_unlink_pack(req, 0, dir, child, mode, name, namelen);
136 size[0] = sizeof(struct mds_body);
137 req->rq_replen = lustre_msg_size(1, size);
139 rc = mdc_reint(req, LUSTRE_CONN_FULL);
141 if (rc == -ERESTARTSYS)
147 int mdc_link(struct lustre_handle *conn,
148 struct dentry *src, struct inode *dir, const char *name,
149 int namelen, struct ptlrpc_request **request)
151 struct ptlrpc_request *req;
152 int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
155 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
159 mds_link_pack(req, 0, src->d_inode, dir, name, namelen);
161 size[0] = sizeof(struct mds_body);
162 req->rq_replen = lustre_msg_size(1, size);
164 rc = mdc_reint(req, LUSTRE_CONN_FULL);
166 if (rc == -ERESTARTSYS )
172 int mdc_rename(struct lustre_handle *conn,
173 struct inode *src, struct inode *tgt, const char *old,
174 int oldlen, const char *new, int newlen,
175 struct ptlrpc_request **request)
177 struct ptlrpc_request *req;
178 int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
182 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 3, size, NULL);
186 mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
188 size[0] = sizeof(struct mds_body);
189 req->rq_replen = lustre_msg_size(1, size);
191 rc = mdc_reint(req, LUSTRE_CONN_FULL);
193 if (rc == -ERESTARTSYS)