Whamcloud - gitweb
- mds failover code
[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_client *cl, 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         CERROR("error in handling %d\n", rc);
43
44         return rc;
45 }
46
47 int mdc_setattr(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
48                 struct inode *inode, struct iattr *iattr,
49                 struct ptlrpc_request **request)
50 {
51         struct mds_rec_setattr *rec;
52         struct ptlrpc_request *req;
53         int rc, size = sizeof(*rec);
54         ENTRY;
55
56         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 1, &size, NULL);
57         if (!req)
58                 RETURN(-ENOMEM);
59
60         rec = lustre_msg_buf(req->rq_reqmsg, 0);
61         mds_setattr_pack(rec, inode, iattr);
62
63         size = sizeof(struct mds_body);
64         req->rq_replen = lustre_msg_size(1, &size);
65
66         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
67         *request = req;
68         if (rc == -ERESTARTSYS )
69                 rc = 0;
70
71         RETURN(rc);
72 }
73
74 int mdc_create(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
75                struct inode *dir, const char *name, int namelen,
76                const char *tgt, int tgtlen, int mode, __u64 id, __u32 uid,
77                __u32 gid, __u64 time, struct ptlrpc_request **request)
78 {
79         struct mds_rec_create *rec;
80         struct ptlrpc_request *req;
81         int rc, size[3] = {sizeof(*rec), namelen + 1, tgtlen + 1};
82         char *tmp;
83         int level;
84         ENTRY;
85
86         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
87         if (!req)
88                 RETURN(-ENOMEM);
89
90         rec = lustre_msg_buf(req->rq_reqmsg, 0);
91         mds_create_pack(rec, dir, mode, id, uid, gid, time);
92
93         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
94         LOGL0(name, namelen, tmp);
95
96         if (tgt) {
97                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
98                 LOGL0(tgt, tgtlen, tmp);
99         }
100
101         size[0] = sizeof(struct mds_body);
102         req->rq_replen = lustre_msg_size(1, size);
103
104         level = LUSTRE_CONN_FULL;
105  resend:
106         rc = mdc_reint(cl, req, level);
107         if (rc == -ERESTARTSYS ) { 
108                 struct mds_update_record_hdr *hdr = lustre_msg_buf(req->rq_reqmsg, 0);
109                 level = LUSTRE_CONN_RECOVD;
110                 CERROR("Lost reply: re-create rep.\n"); 
111                 req->rq_flags = 0;
112                 hdr->ur_opcode = NTOH__u32(REINT_RECREATE);
113                 goto resend;
114         }
115
116         *request = req;
117         RETURN(rc);
118 }
119
120 int mdc_unlink(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
121                struct inode *dir, struct inode *child, const char *name,
122                int namelen, struct ptlrpc_request **request)
123 {
124         struct mds_rec_unlink *rec;
125         struct ptlrpc_request *req;
126         int rc, size[2] = {sizeof(*rec), namelen + 1};
127         char *tmp;
128         ENTRY;
129
130         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
131         if (!req)
132                 RETURN(-ENOMEM);
133
134         rec = lustre_msg_buf(req->rq_reqmsg, 0);
135         mds_unlink_pack(rec, dir, child);
136
137         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
138         LOGL0(name, namelen, tmp);
139
140         size[0] = sizeof(struct mds_body);
141         req->rq_replen = lustre_msg_size(1, size);
142
143         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
144         *request = req;
145         if (rc == -ERESTARTSYS )
146                 rc = 0;
147
148         RETURN(rc);
149 }
150
151 int mdc_link(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
152              struct dentry *src, struct inode *dir, const char *name,
153              int namelen, struct ptlrpc_request **request)
154 {
155         struct mds_rec_link *rec;
156         struct ptlrpc_request *req;
157         int rc, size[2] = {sizeof(*rec), namelen + 1};
158         char *tmp;
159         ENTRY;
160
161         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
162         if (!req)
163                 RETURN(-ENOMEM);
164
165         rec = lustre_msg_buf(req->rq_reqmsg, 0);
166         mds_link_pack(rec, src->d_inode, dir);
167
168         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
169         LOGL0(name, namelen, tmp);
170
171         size[0] = sizeof(struct mds_body);
172         req->rq_replen = lustre_msg_size(1, size);
173
174         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
175         *request = req;
176         if (rc == -ERESTARTSYS )
177                 rc = 0;
178
179         RETURN(rc);
180 }
181
182 int mdc_rename(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
183                struct inode *src, struct inode *tgt, const char *old,
184                int oldlen, const char *new, int newlen,
185                struct ptlrpc_request **request)
186 {
187         struct mds_rec_rename *rec;
188         struct ptlrpc_request *req;
189         int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
190         char *tmp;
191         ENTRY;
192
193         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
194         if (!req)
195                 RETURN(-ENOMEM);
196
197         rec = lustre_msg_buf(req->rq_reqmsg, 0);
198         mds_rename_pack(rec, src, tgt);
199
200         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
201         LOGL0(old, oldlen, tmp);
202
203         if (tgt) {
204                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
205                 LOGL0(new, newlen, tmp);
206         }
207
208         size[0] = sizeof(struct mds_body);
209         req->rq_replen = lustre_msg_size(1, size);
210
211         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
212         *request = req;
213         if (rc == -ERESTARTSYS )
214                 rc = 0;
215
216         RETURN(rc);
217 }