Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/nfs/proc.c | |
3 | * | |
4 | * Copyright (C) 1992, 1993, 1994 Rick Sladkey | |
5 | * | |
6 | * OS-independent nfs remote procedure call functions | |
7 | * | |
8 | * Tuned by Alan Cox <A.Cox@swansea.ac.uk> for >3K buffers | |
9 | * so at last we can have decent(ish) throughput off a | |
10 | * Sun server. | |
11 | * | |
12 | * Coding optimized and cleaned up by Florian La Roche. | |
13 | * Note: Error returns are optimized for NFS_OK, which isn't translated via | |
14 | * nfs_stat_to_errno(), but happens to be already the right return code. | |
15 | * | |
16 | * Also, the code currently doesn't check the size of the packet, when | |
17 | * it decodes the packet. | |
18 | * | |
19 | * Feel free to fix it and mail me the diffs if it worries you. | |
20 | * | |
21 | * Completely rewritten to support the new RPC call interface; | |
22 | * rewrote and moved the entire XDR stuff to xdr.c | |
23 | * --Olaf Kirch June 1996 | |
24 | * | |
25 | * The code below initializes all auto variables explicitly, otherwise | |
26 | * it will fail to work as a module (gcc generates a memset call for an | |
27 | * incomplete struct). | |
28 | */ | |
29 | ||
30 | #include <linux/types.h> | |
31 | #include <linux/param.h> | |
32 | #include <linux/slab.h> | |
33 | #include <linux/time.h> | |
34 | #include <linux/mm.h> | |
35 | #include <linux/utsname.h> | |
36 | #include <linux/errno.h> | |
37 | #include <linux/string.h> | |
38 | #include <linux/in.h> | |
39 | #include <linux/pagemap.h> | |
40 | #include <linux/sunrpc/clnt.h> | |
41 | #include <linux/nfs.h> | |
42 | #include <linux/nfs2.h> | |
43 | #include <linux/nfs_fs.h> | |
44 | #include <linux/nfs_page.h> | |
45 | #include <linux/lockd/bind.h> | |
f7b422b1 | 46 | #include "internal.h" |
1da177e4 LT |
47 | |
48 | #define NFSDBG_FACILITY NFSDBG_PROC | |
49 | ||
1da177e4 LT |
50 | /* |
51 | * Bare-bones access to getattr: this is for nfs_read_super. | |
52 | */ | |
53 | static int | |
54 | nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, | |
55 | struct nfs_fsinfo *info) | |
56 | { | |
57 | struct nfs_fattr *fattr = info->fattr; | |
58 | struct nfs2_fsstat fsinfo; | |
dead28da CL |
59 | struct rpc_message msg = { |
60 | .rpc_proc = &nfs_procedures[NFSPROC_GETATTR], | |
61 | .rpc_argp = fhandle, | |
62 | .rpc_resp = fattr, | |
63 | }; | |
1da177e4 LT |
64 | int status; |
65 | ||
66 | dprintk("%s: call getattr\n", __FUNCTION__); | |
0e574af1 | 67 | nfs_fattr_init(fattr); |
5006a76c | 68 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); |
1da177e4 LT |
69 | dprintk("%s: reply getattr: %d\n", __FUNCTION__, status); |
70 | if (status) | |
71 | return status; | |
72 | dprintk("%s: call statfs\n", __FUNCTION__); | |
dead28da CL |
73 | msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS]; |
74 | msg.rpc_resp = &fsinfo; | |
5006a76c | 75 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); |
1da177e4 LT |
76 | dprintk("%s: reply statfs: %d\n", __FUNCTION__, status); |
77 | if (status) | |
78 | return status; | |
79 | info->rtmax = NFS_MAXDATA; | |
80 | info->rtpref = fsinfo.tsize; | |
81 | info->rtmult = fsinfo.bsize; | |
82 | info->wtmax = NFS_MAXDATA; | |
83 | info->wtpref = fsinfo.tsize; | |
84 | info->wtmult = fsinfo.bsize; | |
85 | info->dtpref = fsinfo.tsize; | |
86 | info->maxfilesize = 0x7FFFFFFF; | |
87 | info->lease_time = 0; | |
88 | return 0; | |
89 | } | |
90 | ||
91 | /* | |
92 | * One function for each procedure in the NFS protocol. | |
93 | */ | |
94 | static int | |
95 | nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, | |
96 | struct nfs_fattr *fattr) | |
97 | { | |
dead28da CL |
98 | struct rpc_message msg = { |
99 | .rpc_proc = &nfs_procedures[NFSPROC_GETATTR], | |
100 | .rpc_argp = fhandle, | |
101 | .rpc_resp = fattr, | |
102 | }; | |
1da177e4 LT |
103 | int status; |
104 | ||
105 | dprintk("NFS call getattr\n"); | |
0e574af1 | 106 | nfs_fattr_init(fattr); |
dead28da | 107 | status = rpc_call_sync(server->client, &msg, 0); |
1da177e4 LT |
108 | dprintk("NFS reply getattr: %d\n", status); |
109 | return status; | |
110 | } | |
111 | ||
112 | static int | |
113 | nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, | |
114 | struct iattr *sattr) | |
115 | { | |
116 | struct inode *inode = dentry->d_inode; | |
117 | struct nfs_sattrargs arg = { | |
118 | .fh = NFS_FH(inode), | |
119 | .sattr = sattr | |
120 | }; | |
dead28da CL |
121 | struct rpc_message msg = { |
122 | .rpc_proc = &nfs_procedures[NFSPROC_SETATTR], | |
123 | .rpc_argp = &arg, | |
124 | .rpc_resp = fattr, | |
125 | }; | |
1da177e4 LT |
126 | int status; |
127 | ||
cf3fff54 TM |
128 | /* Mask out the non-modebit related stuff from attr->ia_mode */ |
129 | sattr->ia_mode &= S_IALLUGO; | |
130 | ||
1da177e4 | 131 | dprintk("NFS call setattr\n"); |
0e574af1 | 132 | nfs_fattr_init(fattr); |
dead28da | 133 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
65e4308d TM |
134 | if (status == 0) |
135 | nfs_setattr_update_inode(inode, sattr); | |
1da177e4 LT |
136 | dprintk("NFS reply setattr: %d\n", status); |
137 | return status; | |
138 | } | |
139 | ||
140 | static int | |
141 | nfs_proc_lookup(struct inode *dir, struct qstr *name, | |
142 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) | |
143 | { | |
144 | struct nfs_diropargs arg = { | |
145 | .fh = NFS_FH(dir), | |
146 | .name = name->name, | |
147 | .len = name->len | |
148 | }; | |
149 | struct nfs_diropok res = { | |
150 | .fh = fhandle, | |
151 | .fattr = fattr | |
152 | }; | |
dead28da CL |
153 | struct rpc_message msg = { |
154 | .rpc_proc = &nfs_procedures[NFSPROC_LOOKUP], | |
155 | .rpc_argp = &arg, | |
156 | .rpc_resp = &res, | |
157 | }; | |
1da177e4 LT |
158 | int status; |
159 | ||
160 | dprintk("NFS call lookup %s\n", name->name); | |
0e574af1 | 161 | nfs_fattr_init(fattr); |
dead28da | 162 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
1da177e4 LT |
163 | dprintk("NFS reply lookup: %d\n", status); |
164 | return status; | |
165 | } | |
166 | ||
167 | static int nfs_proc_readlink(struct inode *inode, struct page *page, | |
168 | unsigned int pgbase, unsigned int pglen) | |
169 | { | |
170 | struct nfs_readlinkargs args = { | |
171 | .fh = NFS_FH(inode), | |
172 | .pgbase = pgbase, | |
173 | .pglen = pglen, | |
174 | .pages = &page | |
175 | }; | |
dead28da CL |
176 | struct rpc_message msg = { |
177 | .rpc_proc = &nfs_procedures[NFSPROC_READLINK], | |
178 | .rpc_argp = &args, | |
179 | }; | |
1da177e4 LT |
180 | int status; |
181 | ||
182 | dprintk("NFS call readlink\n"); | |
dead28da | 183 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
1da177e4 LT |
184 | dprintk("NFS reply readlink: %d\n", status); |
185 | return status; | |
186 | } | |
187 | ||
1da177e4 LT |
188 | static int |
189 | nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | |
02a913a7 | 190 | int flags, struct nameidata *nd) |
1da177e4 LT |
191 | { |
192 | struct nfs_fh fhandle; | |
193 | struct nfs_fattr fattr; | |
194 | struct nfs_createargs arg = { | |
195 | .fh = NFS_FH(dir), | |
196 | .name = dentry->d_name.name, | |
197 | .len = dentry->d_name.len, | |
198 | .sattr = sattr | |
199 | }; | |
200 | struct nfs_diropok res = { | |
201 | .fh = &fhandle, | |
202 | .fattr = &fattr | |
203 | }; | |
dead28da CL |
204 | struct rpc_message msg = { |
205 | .rpc_proc = &nfs_procedures[NFSPROC_CREATE], | |
206 | .rpc_argp = &arg, | |
207 | .rpc_resp = &res, | |
208 | }; | |
1da177e4 LT |
209 | int status; |
210 | ||
0e574af1 | 211 | nfs_fattr_init(&fattr); |
1da177e4 | 212 | dprintk("NFS call create %s\n", dentry->d_name.name); |
dead28da | 213 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
1da177e4 LT |
214 | if (status == 0) |
215 | status = nfs_instantiate(dentry, &fhandle, &fattr); | |
216 | dprintk("NFS reply create: %d\n", status); | |
217 | return status; | |
218 | } | |
219 | ||
220 | /* | |
221 | * In NFSv2, mknod is grafted onto the create call. | |
222 | */ | |
223 | static int | |
224 | nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | |
225 | dev_t rdev) | |
226 | { | |
227 | struct nfs_fh fhandle; | |
228 | struct nfs_fattr fattr; | |
229 | struct nfs_createargs arg = { | |
230 | .fh = NFS_FH(dir), | |
231 | .name = dentry->d_name.name, | |
232 | .len = dentry->d_name.len, | |
233 | .sattr = sattr | |
234 | }; | |
235 | struct nfs_diropok res = { | |
236 | .fh = &fhandle, | |
237 | .fattr = &fattr | |
238 | }; | |
dead28da CL |
239 | struct rpc_message msg = { |
240 | .rpc_proc = &nfs_procedures[NFSPROC_CREATE], | |
241 | .rpc_argp = &arg, | |
242 | .rpc_resp = &res, | |
243 | }; | |
1da177e4 LT |
244 | int status, mode; |
245 | ||
246 | dprintk("NFS call mknod %s\n", dentry->d_name.name); | |
247 | ||
248 | mode = sattr->ia_mode; | |
249 | if (S_ISFIFO(mode)) { | |
250 | sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR; | |
251 | sattr->ia_valid &= ~ATTR_SIZE; | |
252 | } else if (S_ISCHR(mode) || S_ISBLK(mode)) { | |
253 | sattr->ia_valid |= ATTR_SIZE; | |
254 | sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */ | |
255 | } | |
256 | ||
0e574af1 | 257 | nfs_fattr_init(&fattr); |
dead28da | 258 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
decf491f | 259 | nfs_mark_for_revalidate(dir); |
1da177e4 LT |
260 | |
261 | if (status == -EINVAL && S_ISFIFO(mode)) { | |
262 | sattr->ia_mode = mode; | |
0e574af1 | 263 | nfs_fattr_init(&fattr); |
dead28da | 264 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
1da177e4 LT |
265 | } |
266 | if (status == 0) | |
267 | status = nfs_instantiate(dentry, &fhandle, &fattr); | |
268 | dprintk("NFS reply mknod: %d\n", status); | |
269 | return status; | |
270 | } | |
271 | ||
272 | static int | |
273 | nfs_proc_remove(struct inode *dir, struct qstr *name) | |
274 | { | |
4fdc17b2 TM |
275 | struct nfs_removeargs arg = { |
276 | .fh = NFS_FH(dir), | |
277 | .name.len = name->len, | |
278 | .name.name = name->name, | |
1da177e4 | 279 | }; |
4fdc17b2 TM |
280 | struct rpc_message msg = { |
281 | .rpc_proc = &nfs_procedures[NFSPROC_REMOVE], | |
282 | .rpc_argp = &arg, | |
1da177e4 LT |
283 | }; |
284 | int status; | |
285 | ||
286 | dprintk("NFS call remove %s\n", name->name); | |
287 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | |
decf491f | 288 | nfs_mark_for_revalidate(dir); |
1da177e4 LT |
289 | |
290 | dprintk("NFS reply remove: %d\n", status); | |
291 | return status; | |
292 | } | |
293 | ||
e4eff1a6 TM |
294 | static void |
295 | nfs_proc_unlink_setup(struct rpc_message *msg, struct inode *dir) | |
1da177e4 | 296 | { |
1da177e4 | 297 | msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE]; |
1da177e4 LT |
298 | } |
299 | ||
e4eff1a6 | 300 | static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir) |
1da177e4 | 301 | { |
e4eff1a6 TM |
302 | nfs_mark_for_revalidate(dir); |
303 | return 1; | |
1da177e4 LT |
304 | } |
305 | ||
306 | static int | |
307 | nfs_proc_rename(struct inode *old_dir, struct qstr *old_name, | |
308 | struct inode *new_dir, struct qstr *new_name) | |
309 | { | |
310 | struct nfs_renameargs arg = { | |
311 | .fromfh = NFS_FH(old_dir), | |
312 | .fromname = old_name->name, | |
313 | .fromlen = old_name->len, | |
314 | .tofh = NFS_FH(new_dir), | |
315 | .toname = new_name->name, | |
316 | .tolen = new_name->len | |
317 | }; | |
dead28da CL |
318 | struct rpc_message msg = { |
319 | .rpc_proc = &nfs_procedures[NFSPROC_RENAME], | |
320 | .rpc_argp = &arg, | |
321 | }; | |
1da177e4 LT |
322 | int status; |
323 | ||
324 | dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name); | |
dead28da | 325 | status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0); |
decf491f TM |
326 | nfs_mark_for_revalidate(old_dir); |
327 | nfs_mark_for_revalidate(new_dir); | |
1da177e4 LT |
328 | dprintk("NFS reply rename: %d\n", status); |
329 | return status; | |
330 | } | |
331 | ||
332 | static int | |
333 | nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) | |
334 | { | |
335 | struct nfs_linkargs arg = { | |
336 | .fromfh = NFS_FH(inode), | |
337 | .tofh = NFS_FH(dir), | |
338 | .toname = name->name, | |
339 | .tolen = name->len | |
340 | }; | |
dead28da CL |
341 | struct rpc_message msg = { |
342 | .rpc_proc = &nfs_procedures[NFSPROC_LINK], | |
343 | .rpc_argp = &arg, | |
344 | }; | |
1da177e4 LT |
345 | int status; |
346 | ||
347 | dprintk("NFS call link %s\n", name->name); | |
dead28da | 348 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
5ba7cc48 | 349 | nfs_mark_for_revalidate(inode); |
decf491f | 350 | nfs_mark_for_revalidate(dir); |
1da177e4 LT |
351 | dprintk("NFS reply link: %d\n", status); |
352 | return status; | |
353 | } | |
354 | ||
355 | static int | |
94a6d753 CL |
356 | nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, |
357 | unsigned int len, struct iattr *sattr) | |
1da177e4 | 358 | { |
4f390c15 CL |
359 | struct nfs_fh fhandle; |
360 | struct nfs_fattr fattr; | |
1da177e4 LT |
361 | struct nfs_symlinkargs arg = { |
362 | .fromfh = NFS_FH(dir), | |
4f390c15 CL |
363 | .fromname = dentry->d_name.name, |
364 | .fromlen = dentry->d_name.len, | |
94a6d753 CL |
365 | .pages = &page, |
366 | .pathlen = len, | |
1da177e4 LT |
367 | .sattr = sattr |
368 | }; | |
dead28da CL |
369 | struct rpc_message msg = { |
370 | .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK], | |
371 | .rpc_argp = &arg, | |
372 | }; | |
1da177e4 LT |
373 | int status; |
374 | ||
94a6d753 | 375 | if (len > NFS2_MAXPATHLEN) |
1da177e4 | 376 | return -ENAMETOOLONG; |
4f390c15 | 377 | |
94a6d753 CL |
378 | dprintk("NFS call symlink %s\n", dentry->d_name.name); |
379 | ||
dead28da | 380 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
decf491f | 381 | nfs_mark_for_revalidate(dir); |
4f390c15 CL |
382 | |
383 | /* | |
384 | * V2 SYMLINK requests don't return any attributes. Setting the | |
385 | * filehandle size to zero indicates to nfs_instantiate that it | |
386 | * should fill in the data with a LOOKUP call on the wire. | |
387 | */ | |
388 | if (status == 0) { | |
389 | nfs_fattr_init(&fattr); | |
390 | fhandle.size = 0; | |
391 | status = nfs_instantiate(dentry, &fhandle, &fattr); | |
392 | } | |
393 | ||
1da177e4 LT |
394 | dprintk("NFS reply symlink: %d\n", status); |
395 | return status; | |
396 | } | |
397 | ||
398 | static int | |
399 | nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) | |
400 | { | |
401 | struct nfs_fh fhandle; | |
402 | struct nfs_fattr fattr; | |
403 | struct nfs_createargs arg = { | |
404 | .fh = NFS_FH(dir), | |
405 | .name = dentry->d_name.name, | |
406 | .len = dentry->d_name.len, | |
407 | .sattr = sattr | |
408 | }; | |
409 | struct nfs_diropok res = { | |
410 | .fh = &fhandle, | |
411 | .fattr = &fattr | |
412 | }; | |
dead28da CL |
413 | struct rpc_message msg = { |
414 | .rpc_proc = &nfs_procedures[NFSPROC_MKDIR], | |
415 | .rpc_argp = &arg, | |
416 | .rpc_resp = &res, | |
417 | }; | |
1da177e4 LT |
418 | int status; |
419 | ||
420 | dprintk("NFS call mkdir %s\n", dentry->d_name.name); | |
0e574af1 | 421 | nfs_fattr_init(&fattr); |
dead28da | 422 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
decf491f | 423 | nfs_mark_for_revalidate(dir); |
1da177e4 LT |
424 | if (status == 0) |
425 | status = nfs_instantiate(dentry, &fhandle, &fattr); | |
426 | dprintk("NFS reply mkdir: %d\n", status); | |
427 | return status; | |
428 | } | |
429 | ||
430 | static int | |
431 | nfs_proc_rmdir(struct inode *dir, struct qstr *name) | |
432 | { | |
433 | struct nfs_diropargs arg = { | |
434 | .fh = NFS_FH(dir), | |
435 | .name = name->name, | |
436 | .len = name->len | |
437 | }; | |
dead28da CL |
438 | struct rpc_message msg = { |
439 | .rpc_proc = &nfs_procedures[NFSPROC_RMDIR], | |
440 | .rpc_argp = &arg, | |
441 | }; | |
1da177e4 LT |
442 | int status; |
443 | ||
444 | dprintk("NFS call rmdir %s\n", name->name); | |
dead28da | 445 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
decf491f | 446 | nfs_mark_for_revalidate(dir); |
1da177e4 LT |
447 | dprintk("NFS reply rmdir: %d\n", status); |
448 | return status; | |
449 | } | |
450 | ||
451 | /* | |
452 | * The READDIR implementation is somewhat hackish - we pass a temporary | |
453 | * buffer to the encode function, which installs it in the receive | |
454 | * the receive iovec. The decode function just parses the reply to make | |
455 | * sure it is syntactically correct; the entries itself are decoded | |
456 | * from nfs_readdir by calling the decode_entry function directly. | |
457 | */ | |
458 | static int | |
459 | nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | |
460 | u64 cookie, struct page *page, unsigned int count, int plus) | |
461 | { | |
462 | struct inode *dir = dentry->d_inode; | |
463 | struct nfs_readdirargs arg = { | |
464 | .fh = NFS_FH(dir), | |
465 | .cookie = cookie, | |
466 | .count = count, | |
dead28da | 467 | .pages = &page, |
1da177e4 LT |
468 | }; |
469 | struct rpc_message msg = { | |
470 | .rpc_proc = &nfs_procedures[NFSPROC_READDIR], | |
471 | .rpc_argp = &arg, | |
dead28da | 472 | .rpc_cred = cred, |
1da177e4 LT |
473 | }; |
474 | int status; | |
475 | ||
1da177e4 LT |
476 | dprintk("NFS call readdir %d\n", (unsigned int)cookie); |
477 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | |
478 | ||
c4812998 TM |
479 | nfs_invalidate_atime(dir); |
480 | ||
1da177e4 | 481 | dprintk("NFS reply readdir: %d\n", status); |
1da177e4 LT |
482 | return status; |
483 | } | |
484 | ||
485 | static int | |
486 | nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, | |
487 | struct nfs_fsstat *stat) | |
488 | { | |
489 | struct nfs2_fsstat fsinfo; | |
dead28da CL |
490 | struct rpc_message msg = { |
491 | .rpc_proc = &nfs_procedures[NFSPROC_STATFS], | |
492 | .rpc_argp = fhandle, | |
493 | .rpc_resp = &fsinfo, | |
494 | }; | |
1da177e4 LT |
495 | int status; |
496 | ||
497 | dprintk("NFS call statfs\n"); | |
0e574af1 | 498 | nfs_fattr_init(stat->fattr); |
dead28da | 499 | status = rpc_call_sync(server->client, &msg, 0); |
1da177e4 LT |
500 | dprintk("NFS reply statfs: %d\n", status); |
501 | if (status) | |
502 | goto out; | |
503 | stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize; | |
504 | stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize; | |
505 | stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize; | |
506 | stat->tfiles = 0; | |
507 | stat->ffiles = 0; | |
508 | stat->afiles = 0; | |
509 | out: | |
510 | return status; | |
511 | } | |
512 | ||
513 | static int | |
514 | nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, | |
515 | struct nfs_fsinfo *info) | |
516 | { | |
517 | struct nfs2_fsstat fsinfo; | |
dead28da CL |
518 | struct rpc_message msg = { |
519 | .rpc_proc = &nfs_procedures[NFSPROC_STATFS], | |
520 | .rpc_argp = fhandle, | |
521 | .rpc_resp = &fsinfo, | |
522 | }; | |
1da177e4 LT |
523 | int status; |
524 | ||
525 | dprintk("NFS call fsinfo\n"); | |
0e574af1 | 526 | nfs_fattr_init(info->fattr); |
dead28da | 527 | status = rpc_call_sync(server->client, &msg, 0); |
1da177e4 LT |
528 | dprintk("NFS reply fsinfo: %d\n", status); |
529 | if (status) | |
530 | goto out; | |
531 | info->rtmax = NFS_MAXDATA; | |
532 | info->rtpref = fsinfo.tsize; | |
533 | info->rtmult = fsinfo.bsize; | |
534 | info->wtmax = NFS_MAXDATA; | |
535 | info->wtpref = fsinfo.tsize; | |
536 | info->wtmult = fsinfo.bsize; | |
537 | info->dtpref = fsinfo.tsize; | |
538 | info->maxfilesize = 0x7FFFFFFF; | |
539 | info->lease_time = 0; | |
540 | out: | |
541 | return status; | |
542 | } | |
543 | ||
544 | static int | |
545 | nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | |
546 | struct nfs_pathconf *info) | |
547 | { | |
548 | info->max_link = 0; | |
549 | info->max_namelen = NFS2_MAXNAMLEN; | |
550 | return 0; | |
551 | } | |
552 | ||
ec06c096 | 553 | static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data) |
1da177e4 | 554 | { |
1da177e4 LT |
555 | if (task->tk_status >= 0) { |
556 | nfs_refresh_inode(data->inode, data->res.fattr); | |
557 | /* Emulate the eof flag, which isn't normally needed in NFSv2 | |
558 | * as it is guaranteed to always return the file attributes | |
559 | */ | |
560 | if (data->args.offset + data->args.count >= data->res.fattr->size) | |
561 | data->res.eof = 1; | |
562 | } | |
ec06c096 | 563 | return 0; |
1da177e4 LT |
564 | } |
565 | ||
ec06c096 | 566 | static void nfs_proc_read_setup(struct nfs_read_data *data) |
1da177e4 | 567 | { |
1da177e4 LT |
568 | struct rpc_message msg = { |
569 | .rpc_proc = &nfs_procedures[NFSPROC_READ], | |
570 | .rpc_argp = &data->args, | |
571 | .rpc_resp = &data->res, | |
572 | .rpc_cred = data->cred, | |
573 | }; | |
574 | ||
ec06c096 | 575 | rpc_call_setup(&data->task, &msg, 0); |
1da177e4 LT |
576 | } |
577 | ||
788e7a89 | 578 | static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data) |
1da177e4 | 579 | { |
1da177e4 | 580 | if (task->tk_status >= 0) |
decf491f | 581 | nfs_post_op_update_inode(data->inode, data->res.fattr); |
788e7a89 | 582 | return 0; |
1da177e4 LT |
583 | } |
584 | ||
788e7a89 | 585 | static void nfs_proc_write_setup(struct nfs_write_data *data, int how) |
1da177e4 | 586 | { |
1da177e4 LT |
587 | struct rpc_message msg = { |
588 | .rpc_proc = &nfs_procedures[NFSPROC_WRITE], | |
589 | .rpc_argp = &data->args, | |
590 | .rpc_resp = &data->res, | |
591 | .rpc_cred = data->cred, | |
592 | }; | |
593 | ||
594 | /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */ | |
595 | data->args.stable = NFS_FILE_SYNC; | |
596 | ||
1da177e4 | 597 | /* Finalize the task. */ |
788e7a89 | 598 | rpc_call_setup(&data->task, &msg, 0); |
1da177e4 LT |
599 | } |
600 | ||
601 | static void | |
602 | nfs_proc_commit_setup(struct nfs_write_data *data, int how) | |
603 | { | |
604 | BUG(); | |
605 | } | |
606 | ||
607 | static int | |
608 | nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl) | |
609 | { | |
01cce933 | 610 | return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl); |
1da177e4 LT |
611 | } |
612 | ||
613 | ||
509de811 | 614 | const struct nfs_rpc_ops nfs_v2_clientops = { |
1da177e4 LT |
615 | .version = 2, /* protocol version */ |
616 | .dentry_ops = &nfs_dentry_operations, | |
617 | .dir_inode_ops = &nfs_dir_inode_operations, | |
92cfc62c | 618 | .file_inode_ops = &nfs_file_inode_operations, |
1da177e4 LT |
619 | .getroot = nfs_proc_get_root, |
620 | .getattr = nfs_proc_getattr, | |
621 | .setattr = nfs_proc_setattr, | |
622 | .lookup = nfs_proc_lookup, | |
623 | .access = NULL, /* access */ | |
624 | .readlink = nfs_proc_readlink, | |
1da177e4 LT |
625 | .create = nfs_proc_create, |
626 | .remove = nfs_proc_remove, | |
627 | .unlink_setup = nfs_proc_unlink_setup, | |
628 | .unlink_done = nfs_proc_unlink_done, | |
629 | .rename = nfs_proc_rename, | |
630 | .link = nfs_proc_link, | |
631 | .symlink = nfs_proc_symlink, | |
632 | .mkdir = nfs_proc_mkdir, | |
633 | .rmdir = nfs_proc_rmdir, | |
634 | .readdir = nfs_proc_readdir, | |
635 | .mknod = nfs_proc_mknod, | |
636 | .statfs = nfs_proc_statfs, | |
637 | .fsinfo = nfs_proc_fsinfo, | |
638 | .pathconf = nfs_proc_pathconf, | |
639 | .decode_dirent = nfs_decode_dirent, | |
640 | .read_setup = nfs_proc_read_setup, | |
ec06c096 | 641 | .read_done = nfs_read_done, |
1da177e4 | 642 | .write_setup = nfs_proc_write_setup, |
788e7a89 | 643 | .write_done = nfs_write_done, |
1da177e4 LT |
644 | .commit_setup = nfs_proc_commit_setup, |
645 | .file_open = nfs_open, | |
646 | .file_release = nfs_release, | |
647 | .lock = nfs_proc_lock, | |
648 | }; |