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);
40 rc = ptlrpc_check_status(request, rc);
43 CERROR("error in handling %d\n", rc);
45 /* For future resend/replays. */
46 u32 *opcodeptr = lustre_msg_buf(request->rq_reqmsg, 0);
47 *opcodeptr |= REINT_REPLAYING;
52 int mdc_setattr(struct lustre_handle *conn,
53 struct inode *inode, struct iattr *iattr,
54 struct ptlrpc_request **request)
56 struct ptlrpc_request *req;
57 struct mds_rec_setattr *rec;
58 int rc, size = sizeof(*rec);
61 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 1, &size,
66 mds_setattr_pack(req, 0, inode, iattr, NULL, 0);
68 size = sizeof(struct mds_body);
69 req->rq_replen = lustre_msg_size(1, &size);
71 rc = mdc_reint(req, LUSTRE_CONN_FULL);
73 if (rc == -ERESTARTSYS )
79 int mdc_create(struct lustre_handle *conn, struct inode *dir,
80 const char *name, int namelen, const void *data, int datalen,
81 int mode, __u32 uid, __u32 gid, __u64 time, __u64 rdev,
82 struct ptlrpc_request **request)
84 struct ptlrpc_request *req;
85 int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
86 int level, bufcount = 2;
89 if (data && datalen) {
90 size[bufcount] = datalen;
94 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
99 /* mds_create_pack fills msg->bufs[1] with name
100 * and msg->bufs[2] with tgt, for symlinks or lov MD data */
101 mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
102 name, namelen, data, datalen);
104 size[0] = sizeof(struct mds_body);
105 req->rq_replen = lustre_msg_size(1, size);
107 level = LUSTRE_CONN_FULL;
109 rc = mdc_reint(req, level);
110 /* Resend if we were told to. */
111 if (rc == -ERESTARTSYS) {
112 level = LUSTRE_CONN_RECOVD;
117 mdc_store_inode_generation(req, 0, 0);
123 int mdc_unlink(struct lustre_handle *conn, struct inode *dir,
124 struct inode *child, __u32 mode, const char *name, int namelen,
125 struct ptlrpc_request **request)
127 struct ptlrpc_request *req;
128 int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
131 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
135 mds_unlink_pack(req, 0, dir, child, mode, name, namelen);
137 size[0] = sizeof(struct mds_body);
138 req->rq_replen = lustre_msg_size(1, size);
140 rc = mdc_reint(req, LUSTRE_CONN_FULL);
142 if (rc == -ERESTARTSYS)
148 int mdc_link(struct lustre_handle *conn,
149 struct dentry *src, struct inode *dir, const char *name,
150 int namelen, struct ptlrpc_request **request)
152 struct ptlrpc_request *req;
153 int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
156 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
160 mds_link_pack(req, 0, src->d_inode, dir, name, namelen);
162 size[0] = sizeof(struct mds_body);
163 req->rq_replen = lustre_msg_size(1, size);
165 rc = mdc_reint(req, LUSTRE_CONN_FULL);
167 if (rc == -ERESTARTSYS )
173 int mdc_rename(struct lustre_handle *conn,
174 struct inode *src, struct inode *tgt, const char *old,
175 int oldlen, const char *new, int newlen,
176 struct ptlrpc_request **request)
178 struct ptlrpc_request *req;
179 int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
183 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 3, size, NULL);
187 mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
189 size[0] = sizeof(struct mds_body);
190 req->rq_replen = lustre_msg_size(1, size);
192 rc = mdc_reint(req, LUSTRE_CONN_FULL);
194 if (rc == -ERESTARTSYS)