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