Whamcloud - gitweb
Merged branch 'peter' with the tip. Pre-merge tag is 't_20020302_networking'.
[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 Portals, http://www.sf.net/projects/lustre/
7  *
8  *   Portals 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  *   Portals 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 Portals; 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 #include <linux/mm.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/locks.h>
33 #include <linux/unistd.h>
34
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
37 #include <linux/module.h>
38
39 #include <linux/fs.h>
40 #include <linux/stat.h>
41 #include <asm/uaccess.h>
42 #include <asm/segment.h>
43 #include <linux/miscdevice.h>
44
45 #define DEBUG_SUBSYSTEM S_MDC
46
47 #include <linux/obd_support.h>
48 #include <linux/obd_class.h>
49 #include <linux/lustre_lib.h>
50 #include <linux/lustre_idl.h>
51 #include <linux/lustre_mds.h>
52
53 extern int mdc_reint(struct ptlrpc_client *peer, struct ptlrpc_request *request);
54
55 int mdc_setattr(struct ptlrpc_client *peer, 
56                 struct inode *inode, struct iattr *iattr,
57                 struct mds_rep **rep, struct ptlrep_hdr **hdr)
58 {
59         int rc; 
60         struct ptlrpc_request *request;
61         struct mds_rec_setattr *rec;
62
63         request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, sizeof(*rec), NULL);
64         if (!request) { 
65                 CERROR("mdc request: cannot pack\n");
66                 return -ENOMEM;
67         }
68
69         rec = mds_req_tgt(request->rq_req.mds);
70         mds_setattr_pack(rec, inode, iattr); 
71         request->rq_req.mds->opcode = HTON__u32(REINT_SETATTR);
72         request->rq_replen = 
73                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
74
75         rc = mdc_reint(peer, request);
76         if (rc)
77                 return rc;
78
79         if (rep) { 
80                 *rep = request->rq_rep.mds;
81         }
82         if (hdr) { 
83                 *hdr = request->rq_rephdr;
84         }
85
86         return 0;
87 }
88
89 int mdc_create(struct ptlrpc_client *peer, 
90                struct inode *dir, const char *name, int namelen, 
91                const char *tgt, int tgtlen, 
92                int mode, __u64 id, __u32 uid, __u32 gid, __u64 time, 
93                 struct mds_rep **rep, struct ptlrep_hdr **hdr)
94 {
95         int rc; 
96         struct ptlrpc_request *request;
97         struct mds_rec_create *rec;
98
99         request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
100                                sizeof(*rec) + size_round0(namelen) + 
101                                size_round0(tgtlen), NULL);
102         if (!request) { 
103                 CERROR("mdc_create: cannot pack\n");
104                 return -ENOMEM;
105         }
106
107         request->rq_replen = 
108                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
109
110         rec = mds_req_tgt(request->rq_req.mds);
111         mds_create_pack(rec, dir, name, namelen, mode, id, uid, gid, time, 
112                         tgt, tgtlen); 
113
114         rc = mdc_reint(peer, request);
115
116         if (rep) { 
117                 *rep = request->rq_rep.mds;
118         }
119         if (hdr) { 
120                 *hdr = request->rq_rephdr;
121         }
122
123         OBD_FREE(request, sizeof(*request));
124         return rc;
125 }
126
127 int mdc_unlink(struct ptlrpc_client *peer, 
128                struct inode *dir, const char *name, int namelen, 
129                 struct mds_rep **rep, struct ptlrep_hdr **hdr)
130 {
131         int rc; 
132         struct ptlrpc_request *request;
133         struct mds_rec_unlink *rec;
134
135         request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
136                                sizeof(*rec) + size_round0(namelen), NULL);
137         if (!request) { 
138                 CERROR("mdc_unlink: cannot pack\n");
139                 return -ENOMEM;
140         }
141
142         request->rq_replen = 
143                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
144
145         rec = mds_req_tgt(request->rq_req.mds);
146         mds_unlink_pack(rec, dir, name, namelen);
147
148         rc = mdc_reint(peer, request);
149
150         if (rep) { 
151                 *rep = request->rq_rep.mds;
152         }
153         if (hdr) { 
154                 *hdr = request->rq_rephdr;
155         }
156
157         OBD_FREE(request, sizeof(*request));
158         return rc;
159 }
160
161 int mdc_link(struct ptlrpc_client *peer, struct dentry *src, 
162              struct inode *dir, const char *name, int namelen, 
163                 struct mds_rep **rep, struct ptlrep_hdr **hdr)
164 {
165         int rc; 
166         struct ptlrpc_request *request;
167         struct mds_rec_link *rec;
168
169         request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
170                                sizeof(*rec) + size_round0(namelen), NULL);
171         if (!request) { 
172                 CERROR("mdc_link: cannot pack\n");
173                 return -ENOMEM;
174         }
175
176         request->rq_replen = 
177                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
178
179         rec = mds_req_tgt(request->rq_req.mds);
180         mds_link_pack(rec, src->d_inode, dir, name, namelen);
181
182         rc = mdc_reint(peer, request);
183
184         if (rep) { 
185                 *rep = request->rq_rep.mds;
186         }
187         if (hdr) { 
188                 *hdr = request->rq_rephdr;
189         }
190
191         OBD_FREE(request, sizeof(*request));
192         return rc;
193 }
194
195 int mdc_rename(struct ptlrpc_client *peer, struct inode *src, 
196                struct inode *tgt, const char *old, int oldlen, 
197                const char *new, int newlen, 
198                struct mds_rep **rep, struct ptlrep_hdr **hdr)
199 {
200         int rc; 
201         struct ptlrpc_request *request;
202         struct mds_rec_rename *rec;
203
204         request = ptlrpc_prep_req(peer, MDS_REINT, 0, NULL, 
205                                sizeof(*rec) + size_round0(oldlen)
206                                + size_round0(newlen), NULL);
207         if (!request) { 
208                 CERROR("mdc_link: cannot pack\n");
209                 return -ENOMEM;
210         }
211
212         request->rq_replen = 
213                 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
214
215         rec = mds_req_tgt(request->rq_req.mds);
216         mds_rename_pack(rec, src, tgt, old, oldlen, new, newlen);
217
218         rc = mdc_reint(peer, request);
219
220         if (rep) { 
221                 *rep = request->rq_rep.mds;
222         }
223         if (hdr) { 
224                 *hdr = request->rq_rephdr;
225         }
226
227         OBD_FREE(request, sizeof(*request));
228         return rc;
229 }