Whamcloud - gitweb
Landing b_lock_replay so that Phil can use my ldlm iterators and whatnot for his
[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
41         if (rc) {
42                 CERROR("error in handling %d\n", rc);
43         } else {
44                 /* For future resend/replays. */
45                 u32 *opcodeptr = lustre_msg_buf(request->rq_reqmsg, 0);
46                 *opcodeptr |= REINT_REPLAYING;
47         }
48         return rc;
49 }
50
51 int mdc_setattr(struct lustre_handle *conn,
52                 struct inode *inode, struct iattr *iattr,
53                 struct ptlrpc_request **request)
54 {
55         struct ptlrpc_request *req;
56         struct mds_rec_setattr *rec;
57         int rc, size = sizeof(*rec);
58         ENTRY;
59
60         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 1, &size,
61                               NULL);
62         if (!req)
63                 RETURN(-ENOMEM);
64
65         mds_setattr_pack(req, 0, inode, iattr, NULL, 0);
66
67         size = sizeof(struct mds_body);
68         req->rq_replen = lustre_msg_size(1, &size);
69
70         rc = mdc_reint(req, LUSTRE_CONN_FULL);
71         *request = req;
72         if (rc == -ERESTARTSYS )
73                 rc = 0;
74
75         RETURN(rc);
76 }
77
78 int mdc_create(struct lustre_handle *conn, struct inode *dir,
79                const char *name, int namelen, const void *data, int datalen,
80                int mode, __u32 uid, __u32 gid, __u64 time, __u64 rdev,
81                struct ptlrpc_request **request)
82 {
83         struct ptlrpc_request *req;
84         int rc, size[3] = {sizeof(struct mds_rec_create), namelen + 1, 0};
85         int level, bufcount = 2;
86         ENTRY;
87
88         if (data && datalen) {
89                 size[bufcount] = datalen;
90                 bufcount++;
91         }
92
93         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, bufcount,
94                               size, NULL);
95         if (!req)
96                 RETURN(-ENOMEM);
97
98         /* mds_create_pack fills msg->bufs[1] with name
99          * and msg->bufs[2] with tgt, for symlinks or lov MD data */
100         mds_create_pack(req, 0, dir, mode, rdev, uid, gid, time,
101                         name, namelen, data, datalen);
102
103         size[0] = sizeof(struct mds_body);
104         req->rq_replen = lustre_msg_size(1, size);
105
106         level = LUSTRE_CONN_FULL;
107  resend:
108         rc = mdc_reint(req, level);
109         /* Resend if we were told to. */
110         if (rc == -ERESTARTSYS) {
111                 level = LUSTRE_CONN_RECOVD;
112                 req->rq_flags = 0;
113                 goto resend;
114         }
115
116         mdc_store_inode_generation(req, 0, 0);
117
118         *request = req;
119         RETURN(rc);
120 }
121
122 int mdc_unlink(struct lustre_handle *conn, struct inode *dir,
123                struct inode *child, __u32 mode, const char *name, int namelen,
124                struct ptlrpc_request **request)
125 {
126         struct ptlrpc_request *req;
127         int rc, size[2] = {sizeof(struct mds_rec_unlink), namelen + 1};
128         ENTRY;
129
130         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
131         if (!req)
132                 RETURN(-ENOMEM);
133
134         mds_unlink_pack(req, 0, dir, child, mode, name, namelen);
135
136         size[0] = sizeof(struct mds_body);
137         req->rq_replen = lustre_msg_size(1, size);
138
139         rc = mdc_reint(req, LUSTRE_CONN_FULL);
140         *request = req;
141         if (rc == -ERESTARTSYS)
142                 rc = 0;
143
144         RETURN(rc);
145 }
146
147 int mdc_link(struct lustre_handle *conn,
148              struct dentry *src, struct inode *dir, const char *name,
149              int namelen, struct ptlrpc_request **request)
150 {
151         struct ptlrpc_request *req;
152         int rc, size[2] = {sizeof(struct mds_rec_link), namelen + 1};
153         ENTRY;
154
155         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 2, size, NULL);
156         if (!req)
157                 RETURN(-ENOMEM);
158
159         mds_link_pack(req, 0, src->d_inode, dir, name, namelen);
160
161         size[0] = sizeof(struct mds_body);
162         req->rq_replen = lustre_msg_size(1, size);
163
164         rc = mdc_reint(req, LUSTRE_CONN_FULL);
165         *request = req;
166         if (rc == -ERESTARTSYS )
167                 rc = 0;
168
169         RETURN(rc);
170 }
171
172 int mdc_rename(struct lustre_handle *conn,
173                struct inode *src, struct inode *tgt, const char *old,
174                int oldlen, const char *new, int newlen,
175                struct ptlrpc_request **request)
176 {
177         struct ptlrpc_request *req;
178         int rc, size[3] = {sizeof(struct mds_rec_rename), oldlen + 1,
179                            newlen + 1};
180         ENTRY;
181
182         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_REINT, 3, size, NULL);
183         if (!req)
184                 RETURN(-ENOMEM);
185
186         mds_rename_pack(req, 0, src, tgt, old, oldlen, new, newlen);
187
188         size[0] = sizeof(struct mds_body);
189         req->rq_replen = lustre_msg_size(1, size);
190
191         rc = mdc_reint(req, LUSTRE_CONN_FULL);
192         *request = req;
193         if (rc == -ERESTARTSYS)
194                 rc = 0;
195
196         RETURN(rc);
197 }