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