Whamcloud - gitweb
Large commit which implements more "intelligent" offsets for stripe
[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 #include <linux/obd_lov.h>
34
35 static int mdc_reint(struct ptlrpc_request *request, int level)
36 {
37         int rc;
38         request->rq_level = level;
39
40         rc = ptlrpc_queue_wait(request);
41         rc = ptlrpc_check_status(request, rc);
42
43         if (rc)
44                 CERROR("error in handling %d\n", rc);
45
46         return rc;
47 }
48
49 int mdc_setattr(struct lustre_handle *conn,
50                 struct inode *inode, struct iattr *iattr,
51                 struct ptlrpc_request **request)
52 {
53         struct ptlrpc_request *req;
54         struct mds_rec_setattr *rec;
55         int rc, size = sizeof(*rec);
56         ENTRY;
57
58         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 1, &size,
59                               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 lustre_handle *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 lov_stripe_md *lsm,
80                struct ptlrpc_request **request)
81 {
82         struct mds_rec_create *rec;
83         struct ptlrpc_request *req;
84         int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
85         char *tmp;
86         int level, bufcount = 2;
87         ENTRY;
88
89         if (S_ISREG(mode)) {
90                 if (!lsm) {
91                         CERROR("File create, but no stripe md (%ld, %*s)\n",
92                                dir->i_ino, namelen, name);
93                         LBUG();
94                 }
95                 // size[2] = mdc->cl_max_mds_easize; soon...
96                 size[2] = lsm->lsm_mds_easize;
97                 bufcount = 3;
98         } else if (S_ISLNK(mode)) {
99                 size[2] = tgtlen + 1;
100                 bufcount = 3;
101         }
102
103         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount, size,
104                               NULL);
105         if (!req)
106                 RETURN(-ENOMEM);
107
108         /* mds_create_pack fills msg->bufs[1] with name */
109         rec = lustre_msg_buf(req->rq_reqmsg, 0);
110         mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
111                         name, namelen, NULL, 0);
112
113         if (S_ISREG(mode)) {
114                 lov_packmd(lustre_msg_buf(req->rq_reqmsg, 2), lsm);
115         } else if (S_ISLNK(mode)) {
116                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
117                 LOGL0(tgt, tgtlen, tmp);
118         }
119
120         size[0] = sizeof(struct mds_body);
121         req->rq_replen = lustre_msg_size(1, size);
122
123         level = LUSTRE_CONN_FULL;
124  resend:
125         rc = mdc_reint(req, level);
126         if (rc == -ERESTARTSYS) {
127                 __u32 *opcode = lustre_msg_buf(req->rq_reqmsg, 0);
128                 level = LUSTRE_CONN_RECOVD;
129                 CERROR("Lost reply: re-create rep.\n");
130                 req->rq_flags = 0;
131                 *opcode = NTOH__u32(REINT_RECREATE);
132                 goto resend;
133         }
134
135         *request = req;
136         RETURN(rc);
137 }
138
139 int mdc_unlink(struct lustre_handle *conn, struct inode *dir,
140                struct inode *child, __u32 mode, const char *name, int namelen,
141                struct ptlrpc_request **request)
142 {
143         struct ptlrpc_request *req;
144         int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
145         ENTRY;
146
147         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
148         if (!req)
149                 RETURN(-ENOMEM);
150
151         mds_unlink_pack(req, 0, dir, child, mode, 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 lustre_handle *conn,
165              struct dentry *src, struct inode *dir, const char *name,
166              int namelen, struct ptlrpc_request **request)
167 {
168         struct ptlrpc_request *req;
169         int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
170         ENTRY;
171
172         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
173         if (!req)
174                 RETURN(-ENOMEM);
175
176         mds_link_pack(req, 0, src->d_inode, dir, name, namelen);
177
178         size[0] = sizeof(struct mds_body);
179         req->rq_replen = lustre_msg_size(1, size);
180
181         rc = mdc_reint(req, LUSTRE_CONN_FULL);
182         *request = req;
183         if (rc == -ERESTARTSYS )
184                 rc = 0;
185
186         RETURN(rc);
187 }
188
189 int mdc_rename(struct lustre_handle *conn,
190                struct inode *src, struct inode *tgt, const char *old,
191                int oldlen, const char *new, int newlen,
192                struct ptlrpc_request **request)
193 {
194         struct ptlrpc_request *req;
195         int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
196                            newlen + 1};
197         ENTRY;
198
199         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 3, size, NULL);
200         if (!req)
201                 RETURN(-ENOMEM);
202
203         mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
204
205         size[0] = sizeof(struct mds_body);
206         req->rq_replen = lustre_msg_size(1, size);
207
208         rc = mdc_reint(req, LUSTRE_CONN_FULL);
209         *request = req;
210         if (rc == -ERESTARTSYS )
211                 rc = 0;
212
213         RETURN(rc);
214 }