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