Whamcloud - gitweb
Commented-out mdc_statfs method. Not sure of how to set up all the portals
[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, __u64 id, __u32 uid,
78                __u32 gid, __u64 time, struct ptlrpc_request **request)
79 {
80         struct mds_rec_create *rec;
81         struct ptlrpc_request *req;
82         int rc, size[3] = {sizeof(*rec), namelen + 1, tgtlen + 1};
83         char *tmp;
84         int level;
85         ENTRY;
86
87         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
88         if (!req)
89                 RETURN(-ENOMEM);
90
91         rec = lustre_msg_buf(req->rq_reqmsg, 0);
92         mds_create_pack(rec, dir, mode, id, uid, gid, time);
93
94         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
95         LOGL0(name, namelen, tmp);
96
97         if (tgt) {
98                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
99                 LOGL0(tgt, tgtlen, tmp);
100         }
101
102         size[0] = sizeof(struct mds_body);
103         req->rq_replen = lustre_msg_size(1, size);
104
105         level = LUSTRE_CONN_FULL;
106  resend:
107         rc = mdc_reint(cl, req, level);
108         if (rc == -ERESTARTSYS) {
109                 struct mds_update_record_hdr *hdr =
110                         lustre_msg_buf(req->rq_reqmsg, 0);
111                 level = LUSTRE_CONN_RECOVD;
112                 CERROR("Lost reply: re-create rep.\n");
113                 req->rq_flags = 0;
114                 hdr->ur_opcode = NTOH__u32(REINT_RECREATE);
115                 goto resend;
116         }
117
118         *request = req;
119         RETURN(rc);
120 }
121
122 int mdc_unlink(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
123                struct inode *dir, struct inode *child, const char *name,
124                int namelen, struct ptlrpc_request **request)
125 {
126         struct mds_rec_unlink *rec;
127         struct ptlrpc_request *req;
128         int rc, size[2] = {sizeof(*rec), namelen + 1};
129         char *tmp;
130         ENTRY;
131
132         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
133         if (!req)
134                 RETURN(-ENOMEM);
135
136         rec = lustre_msg_buf(req->rq_reqmsg, 0);
137         mds_unlink_pack(rec, dir, child);
138
139         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
140         LOGL0(name, namelen, tmp);
141
142         size[0] = sizeof(struct mds_body);
143         req->rq_replen = lustre_msg_size(1, size);
144
145         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
146         *request = req;
147         if (rc == -ERESTARTSYS )
148                 rc = 0;
149
150         RETURN(rc);
151 }
152
153 int mdc_link(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
154              struct dentry *src, struct inode *dir, const char *name,
155              int namelen, struct ptlrpc_request **request)
156 {
157         struct mds_rec_link *rec;
158         struct ptlrpc_request *req;
159         int rc, size[2] = {sizeof(*rec), namelen + 1};
160         char *tmp;
161         ENTRY;
162
163         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
164         if (!req)
165                 RETURN(-ENOMEM);
166
167         rec = lustre_msg_buf(req->rq_reqmsg, 0);
168         mds_link_pack(rec, src->d_inode, dir);
169
170         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
171         LOGL0(name, namelen, tmp);
172
173         size[0] = sizeof(struct mds_body);
174         req->rq_replen = lustre_msg_size(1, size);
175
176         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
177         *request = req;
178         if (rc == -ERESTARTSYS )
179                 rc = 0;
180
181         RETURN(rc);
182 }
183
184 int mdc_rename(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
185                struct inode *src, struct inode *tgt, const char *old,
186                int oldlen, const char *new, int newlen,
187                struct ptlrpc_request **request)
188 {
189         struct mds_rec_rename *rec;
190         struct ptlrpc_request *req;
191         int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
192         char *tmp;
193         ENTRY;
194
195         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
196         if (!req)
197                 RETURN(-ENOMEM);
198
199         rec = lustre_msg_buf(req->rq_reqmsg, 0);
200         mds_rename_pack(rec, src, tgt);
201
202         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
203         LOGL0(old, oldlen, tmp);
204
205         if (tgt) {
206                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
207                 LOGL0(new, newlen, tmp);
208         }
209
210         size[0] = sizeof(struct mds_body);
211         req->rq_replen = lustre_msg_size(1, size);
212
213         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
214         *request = req;
215         if (rc == -ERESTARTSYS )
216                 rc = 0;
217
218         RETURN(rc);
219 }