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