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>
33 #include <linux/obd_lov.h>
35 static int mdc_reint(struct ptlrpc_request *request, int level)
38 request->rq_level = level;
40 rc = ptlrpc_queue_wait(request);
41 rc = ptlrpc_check_status(request, rc);
44 CERROR("error in handling %d\n", rc);
46 /* For future resend/replays. */
47 u32 *opcodeptr = lustre_msg_buf(request->rq_reqmsg, 0);
48 *opcodeptr |= REINT_REPLAYING;
53 int mdc_setattr(struct lustre_handle *conn,
54 struct inode *inode, struct iattr *iattr,
55 struct ptlrpc_request **request)
57 struct ptlrpc_request *req;
58 struct mds_rec_setattr *rec;
59 int rc, size = sizeof(*rec);
62 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 1, &size,
67 mds_setattr_pack(req, 0, inode, iattr, NULL, 0);
69 size = sizeof(struct mds_body);
70 req->rq_replen = lustre_msg_size(1, &size);
72 rc = mdc_reint(req, LUSTRE_CONN_FULL);
74 if (rc == -ERESTARTSYS )
80 int mdc_create(struct lustre_handle *conn,
81 struct inode *dir, const char *name, int namelen,
82 const char *tgt, int tgtlen, int mode, __u32 uid,
83 __u32 gid, __u64 time, __u64 rdev, struct lov_stripe_md *lsm,
84 struct ptlrpc_request **request)
86 struct ptlrpc_request *req;
87 int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
88 int level, bufcount = 2;
96 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
101 /* mds_create_pack fills msg->bufs[1] with name
102 * and msg->bufs[2] with tgt, for symlinks */
103 mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
104 name, namelen, tgt, tgtlen);
106 size[0] = sizeof(struct mds_body);
107 req->rq_replen = lustre_msg_size(1, size);
109 level = LUSTRE_CONN_FULL;
111 rc = mdc_reint(req, level);
112 /* Resend if we were told to. */
113 if (rc == -ERESTARTSYS) {
114 level = LUSTRE_CONN_RECOVD;
119 mdc_store_inode_generation(req, 0, 0);
125 int mdc_unlink(struct lustre_handle *conn, struct inode *dir,
126 struct inode *child, __u32 mode, const char *name, int namelen,
127 struct ptlrpc_request **request)
129 struct ptlrpc_request *req;
130 int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
133 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
137 mds_unlink_pack(req, 0, dir, child, mode, name, namelen);
139 size[0] = sizeof(struct mds_body);
140 req->rq_replen = lustre_msg_size(1, size);
142 rc = mdc_reint(req, LUSTRE_CONN_FULL);
144 if (rc == -ERESTARTSYS)
150 int mdc_link(struct lustre_handle *conn,
151 struct dentry *src, struct inode *dir, const char *name,
152 int namelen, struct ptlrpc_request **request)
154 struct ptlrpc_request *req;
155 int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
158 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
162 mds_link_pack(req, 0, src->d_inode, dir, name, namelen);
164 size[0] = sizeof(struct mds_body);
165 req->rq_replen = lustre_msg_size(1, size);
167 rc = mdc_reint(req, LUSTRE_CONN_FULL);
169 if (rc == -ERESTARTSYS )
175 int mdc_rename(struct lustre_handle *conn,
176 struct inode *src, struct inode *tgt, const char *old,
177 int oldlen, const char *new, int newlen,
178 struct ptlrpc_request **request)
180 struct ptlrpc_request *req;
181 int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
185 req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 3, size, NULL);
189 mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
191 size[0] = sizeof(struct mds_body);
192 req->rq_replen = lustre_msg_size(1, size);
194 rc = mdc_reint(req, LUSTRE_CONN_FULL);
196 if (rc == -ERESTARTSYS )