Whamcloud - gitweb
Removes all traces of mds_req, mds_rep, ost_req, and ost_rep. All subsystems
[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)
35 {
36         int rc;
37
38         rc = ptlrpc_queue_wait(cl, request);
39         rc = ptlrpc_check_status(request, rc);
40         if (rc)
41                 CERROR("error in handling %d\n", rc);
42
43         return rc;
44 }
45
46 int mdc_setattr(struct ptlrpc_client *cl, struct inode *inode,
47                 struct iattr *iattr, struct ptlrpc_request **request)
48 {
49         struct mds_rec_setattr *rec;
50         struct ptlrpc_request *req;
51         int rc, size = sizeof(*rec);
52         ENTRY;
53
54         req = ptlrpc_prep_req(cl, MDS_REINT, 1, &size, NULL);
55         if (!req)
56                 RETURN(-ENOMEM);
57
58         rec = lustre_msg_buf(req->rq_reqmsg, 0);
59         mds_setattr_pack(rec, inode, iattr);
60
61         size = sizeof(struct mds_body);
62         req->rq_replen = lustre_msg_size(1, &size);
63
64         rc = mdc_reint(cl, req);
65         *request = req;
66
67         RETURN(rc);
68 }
69
70 int mdc_create(struct ptlrpc_client *cl, struct inode *dir, const char *name,
71                int namelen, const char *tgt, int tgtlen, int mode, __u64 id,
72                __u32 uid, __u32 gid, __u64 time,
73                struct ptlrpc_request **request)
74 {
75         struct mds_rec_create *rec;
76         struct ptlrpc_request *req;
77         int rc, size[3] = {sizeof(*rec), namelen + 1, tgtlen + 1};
78         char *tmp;
79         ENTRY;
80
81         req = ptlrpc_prep_req(cl, MDS_REINT, 3, size, NULL);
82         if (!req)
83                 RETURN(-ENOMEM);
84
85         rec = lustre_msg_buf(req->rq_reqmsg, 0);
86         mds_create_pack(rec, dir, mode, id, uid, gid, time);
87
88         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
89         LOGL0(name, namelen, tmp);
90
91         if (tgt) {
92                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
93                 LOGL0(tgt, tgtlen, tmp);
94         }
95
96         size[0] = sizeof(struct mds_body);
97         req->rq_replen = lustre_msg_size(1, size);
98
99         rc = mdc_reint(cl, req);
100         *request = req;
101
102         RETURN(rc);
103 }
104
105 int mdc_unlink(struct ptlrpc_client *cl,  struct inode *dir,
106                struct inode *child, const char *name, int namelen,
107                struct ptlrpc_request **request)
108 {
109         struct mds_rec_unlink *rec;
110         struct ptlrpc_request *req;
111         int rc, size[2] = {sizeof(*rec), namelen + 1};
112         char *tmp;
113         ENTRY;
114
115         req = ptlrpc_prep_req(cl, MDS_REINT, 2, size, NULL);
116         if (!req)
117                 RETURN(-ENOMEM);
118
119         rec = lustre_msg_buf(req->rq_reqmsg, 0);
120         mds_unlink_pack(rec, dir, child);
121
122         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
123         LOGL0(name, namelen, tmp);
124
125         size[0] = sizeof(struct mds_body);
126         req->rq_replen = lustre_msg_size(1, size);
127
128         rc = mdc_reint(cl, req);
129         *request = req;
130
131         RETURN(rc);
132 }
133
134 int mdc_link(struct ptlrpc_client *cl, struct dentry *src, struct inode *dir,
135              const char *name, int namelen, struct ptlrpc_request **request)
136 {
137         struct mds_rec_link *rec;
138         struct ptlrpc_request *req;
139         int rc, size[2] = {sizeof(*rec), namelen + 1};
140         char *tmp;
141         ENTRY;
142
143         req = ptlrpc_prep_req(cl, MDS_REINT, 2, size, NULL);
144         if (!req)
145                 RETURN(-ENOMEM);
146
147         rec = lustre_msg_buf(req->rq_reqmsg, 0);
148         mds_link_pack(rec, src->d_inode, dir);
149
150         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
151         LOGL0(name, namelen, tmp);
152
153         size[0] = sizeof(struct mds_body);
154         req->rq_replen = lustre_msg_size(1, size);
155
156         rc = mdc_reint(cl, req);
157         *request = req;
158
159         RETURN(rc);
160 }
161
162 int mdc_rename(struct ptlrpc_client *cl, struct inode *src, struct inode *tgt,
163                const char *old, int oldlen, const char *new, int newlen,
164                struct ptlrpc_request **request)
165 {
166         struct mds_rec_rename *rec;
167         struct ptlrpc_request *req;
168         int rc, size[3] = {sizeof(*rec), oldlen + 1, newlen + 1};
169         char *tmp;
170         ENTRY;
171
172         req = ptlrpc_prep_req(cl, MDS_REINT, 3, size, NULL);
173         if (!req)
174                 RETURN(-ENOMEM);
175
176         rec = lustre_msg_buf(req->rq_reqmsg, 0);
177         mds_rename_pack(rec, src, tgt);
178
179         tmp = lustre_msg_buf(req->rq_reqmsg, 1);
180         LOGL0(old, oldlen, tmp);
181
182         if (tgt) {
183                 tmp = lustre_msg_buf(req->rq_reqmsg, 2);
184                 LOGL0(new, newlen, tmp);
185         }
186
187         size[0] = sizeof(struct mds_body);
188         req->rq_replen = lustre_msg_size(1, size);
189
190         rc = mdc_reint(cl, req);
191         *request = req;
192
193         RETURN(rc);
194 }