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