Whamcloud - gitweb
Tweak autogen.sh and Makefiles to be compatible with Automake 1.6.2.
[fs/lustre-release.git] / lustre / mdc / mdc_reint.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #define EXPORT_SYMTAB
24
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28
29 #define DEBUG_SUBSYSTEM S_MDC
30
31 #include <linux/obd_class.h>
32 #include <linux/lustre_mds.h>
33
34 static int mdc_reint(struct ptlrpc_request *request, int level)
35 {
36         int rc;
37         request->rq_level = level;
38
39         rc = ptlrpc_queue_wait(request);
40         rc = ptlrpc_check_status(request, rc);
41
42         if (rc)
43                 CERROR("error in handling %d\n", rc);
44
45         return rc;
46 }
47
48 int mdc_setattr(struct lustre_handle *conn,
49                 struct inode *inode, struct iattr *iattr,
50                 struct ptlrpc_request **request)
51 {
52         struct ptlrpc_client *cl;
53         struct ptlrpc_connection *connection;
54         struct lustre_handle *rconn;
55         struct mds_rec_setattr *rec;
56         struct ptlrpc_request *req;
57         int rc, size = sizeof(*rec);
58         ENTRY;
59
60         mdc_con2cl(conn, &cl, &connection, &rconn);
61         req = ptlrpc_prep_req2(cl, connection, rconn,
62                                MDS_REINT, 1, &size, NULL);
63         if (!req)
64                 RETURN(-ENOMEM);
65
66         mds_setattr_pack(req, 0, inode, iattr, NULL, 0);
67
68         size = sizeof(struct mds_body);
69         req->rq_replen = lustre_msg_size(1, &size);
70
71         rc = mdc_reint(req, LUSTRE_CONN_FULL);
72         *request = req;
73         if (rc == -ERESTARTSYS )
74                 rc = 0;
75
76         RETURN(rc);
77 }
78
79 int mdc_create(struct lustre_handle *conn,
80                struct inode *dir, const char *name, int namelen,
81                const char *tgt, int tgtlen, int mode, __u32 uid,
82                __u32 gid, __u64 time, __u64 rdev, struct lov_stripe_md *smd,
83                struct ptlrpc_request **request)
84 {
85         struct mds_rec_create *rec;
86         struct ptlrpc_client *cl;
87         struct ptlrpc_connection *connection;
88         struct lustre_handle *rconn;
89         struct ptlrpc_request *req;
90         int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
91         char *tmp, *bufs[3] = {NULL, NULL, NULL};
92         int level, bufcount = 2;
93         ENTRY;
94
95         if (S_ISREG(mode)) {
96                 if (!smd) {
97                         CERROR("File create, but no md (%ld, %*s)\n",
98                                dir->i_ino, namelen, name); 
99                         LBUG();
100                 }
101                 size[2] = smd->lmd_size;
102                 bufs[2] = (char *)smd;
103                 bufcount = 3;
104         } else if (S_ISLNK(mode)) {
105                 size[2] = tgtlen + 1;
106                 bufcount = 3;
107         }
108
109         mdc_con2cl(conn, &cl, &connection, &rconn);
110         req = ptlrpc_prep_req2(cl, connection, rconn,
111                                MDS_REINT, bufcount, size, bufs);
112         if (!req)
113                 RETURN(-ENOMEM);
114
115         /* mds_create_pack fills bufs[1] with name */
116         rec = lustre_msg_buf(req->rq_reqmsg, 0);
117         mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
118                         name, namelen, NULL, 0);
119
120         if (S_ISREG(mode)) {
121                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
122                 memcpy(tmp, smd, smd->lmd_size);
123         } else if (S_ISLNK(mode)) {
124                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
125                 LOGL0(tgt, tgtlen, tmp);
126         }
127
128         size[0] = sizeof(struct mds_body);
129         req->rq_replen = lustre_msg_size(1, size);
130
131         level = LUSTRE_CONN_FULL;
132  resend:
133         rc = mdc_reint(req, level);
134         if (rc == -ERESTARTSYS) {
135                 struct mds_update_record_hdr *hdr =
136                         lustre_msg_buf(req->rq_reqmsg, 0);
137                 level = LUSTRE_CONN_RECOVD;
138                 CERROR("Lost reply: re-create rep.\n");
139                 req->rq_flags = 0;
140                 hdr->ur_opcode = NTOH__u32(REINT_RECREATE);
141                 goto resend;
142         }
143
144         *request = req;
145         RETURN(rc);
146 }
147
148 int mdc_unlink(struct lustre_handle *conn,
149                struct inode *dir, struct inode *child, const char *name,
150                int namelen, struct ptlrpc_request **request)
151 {
152         struct ptlrpc_client *cl;
153         struct ptlrpc_connection *connection;
154         struct lustre_handle *rconn;
155         struct ptlrpc_request *req;
156         int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
157         ENTRY;
158
159         mdc_con2cl(conn, &cl, &connection, &rconn);
160         req = ptlrpc_prep_req2(cl, connection, rconn,
161                                MDS_REINT, 2, size, NULL);
162         if (!req)
163                 RETURN(-ENOMEM);
164
165         mds_unlink_pack(req, 0, dir, child, name, namelen);
166
167         size[0] = sizeof(struct mds_body);
168         req->rq_replen = lustre_msg_size(1, size);
169
170         rc = mdc_reint(req, LUSTRE_CONN_FULL);
171         *request = req;
172         if (rc == -ERESTARTSYS )
173                 rc = 0;
174
175         RETURN(rc);
176 }
177
178 int mdc_link(struct lustre_handle *conn,
179              struct dentry *src, struct inode *dir, const char *name,
180              int namelen, struct ptlrpc_request **request)
181 {
182         struct ptlrpc_client *cl;
183         struct ptlrpc_connection *connection;
184         struct lustre_handle *rconn;
185         struct ptlrpc_request *req;
186         int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
187         ENTRY;
188
189         mdc_con2cl(conn, &cl, &connection, &rconn);
190         req = ptlrpc_prep_req2(cl, connection, rconn,
191                                MDS_REINT, 2, size, NULL);
192         if (!req)
193                 RETURN(-ENOMEM);
194
195         mds_link_pack(req, 0, src->d_inode, dir, name, namelen);
196
197         size[0] = sizeof(struct mds_body);
198         req->rq_replen = lustre_msg_size(1, size);
199
200         rc = mdc_reint(req, LUSTRE_CONN_FULL);
201         *request = req;
202         if (rc == -ERESTARTSYS )
203                 rc = 0;
204
205         RETURN(rc);
206 }
207
208 int mdc_rename(struct lustre_handle *conn,
209                struct inode *src, struct inode *tgt, const char *old,
210                int oldlen, const char *new, int newlen,
211                struct ptlrpc_request **request)
212 {
213         struct ptlrpc_client *cl;
214         struct ptlrpc_connection *connection;
215         struct lustre_handle *rconn;
216         struct ptlrpc_request *req;
217         int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
218                            newlen + 1};
219         ENTRY;
220
221         mdc_con2cl(conn, &cl, &connection, &rconn);
222         req = ptlrpc_prep_req2(cl, connection, rconn,
223                                MDS_REINT, 3, size, NULL);
224         if (!req)
225                 RETURN(-ENOMEM);
226
227         mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
228
229         size[0] = sizeof(struct mds_body);
230         req->rq_replen = lustre_msg_size(1, size);
231
232         rc = mdc_reint(req, LUSTRE_CONN_FULL);
233         *request = req;
234         if (rc == -ERESTARTSYS )
235                 rc = 0;
236
237         RETURN(rc);
238 }