Whamcloud - gitweb
* Split struct niobuf into niobuf_local and niobuf_remote
[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 =
109                         lustre_msg_buf(req->rq_reqmsg, 0);
110                 level = LUSTRE_CONN_RECOVD;
111                 CERROR("Lost reply: re-create rep.\n");
112                 req->rq_flags = 0;
113                 hdr->ur_opcode = NTOH__u32(REINT_RECREATE);
114                 goto resend;
115         }
116
117         *request = req;
118         RETURN(rc);
119 }
120
121 int mdc_unlink(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
122                struct inode *dir, struct inode *child, const char *name,
123                int namelen, struct ptlrpc_request **request)
124 {
125         struct mds_rec_unlink *rec;
126         struct ptlrpc_request *req;
127         int rc, size[2] = {sizeof(*rec), namelen + 1};
128         char *tmp;
129         ENTRY;
130
131         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
132         if (!req)
133                 RETURN(-ENOMEM);
134
135         rec = lustre_msg_buf(req->rq_reqmsg, 0);
136         mds_unlink_pack(rec, dir, child);
137
138         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
139         LOGL0(name, namelen, tmp);
140
141         size[0] = sizeof(struct mds_body);
142         req->rq_replen = lustre_msg_size(1, size);
143
144         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
145         *request = req;
146         if (rc == -ERESTARTSYS )
147                 rc = 0;
148
149         RETURN(rc);
150 }
151
152 int mdc_link(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
153              struct dentry *src, struct inode *dir, const char *name,
154              int namelen, struct ptlrpc_request **request)
155 {
156         struct mds_rec_link *rec;
157         struct ptlrpc_request *req;
158         int rc, size[2] = {sizeof(*rec), namelen + 1};
159         char *tmp;
160         ENTRY;
161
162         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 2, size, NULL);
163         if (!req)
164                 RETURN(-ENOMEM);
165
166         rec = lustre_msg_buf(req->rq_reqmsg, 0);
167         mds_link_pack(rec, src->d_inode, dir);
168
169         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
170         LOGL0(name, namelen, tmp);
171
172         size[0] = sizeof(struct mds_body);
173         req->rq_replen = lustre_msg_size(1, size);
174
175         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
176         *request = req;
177         if (rc == -ERESTARTSYS )
178                 rc = 0;
179
180         RETURN(rc);
181 }
182
183 int mdc_rename(struct ptlrpc_client *cl, struct ptlrpc_connection *conn,
184                struct inode *src, struct inode *tgt, const char *old,
185                int oldlen, const char *new, int newlen,
186                struct ptlrpc_request **request)
187 {
188         struct mds_rec_rename *rec;
189         struct ptlrpc_request *req;
190         int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
191         char *tmp;
192         ENTRY;
193
194         req = ptlrpc_prep_req(cl, conn, MDS_REINT, 3, size, NULL);
195         if (!req)
196                 RETURN(-ENOMEM);
197
198         rec = lustre_msg_buf(req->rq_reqmsg, 0);
199         mds_rename_pack(rec, src, tgt);
200
201         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
202         LOGL0(old, oldlen, tmp);
203
204         if (tgt) {
205                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
206                 LOGL0(new, newlen, tmp);
207         }
208
209         size[0] = sizeof(struct mds_body);
210         req->rq_replen = lustre_msg_size(1, size);
211
212         rc = mdc_reint(cl, req, LUSTRE_CONN_FULL);
213         *request = req;
214         if (rc == -ERESTARTSYS )
215                 rc = 0;
216
217         RETURN(rc);
218 }