2 * linux/fs/nfs/nfs3proc.c
4 * Client-side NFSv3 procedures stubs.
6 * Copyright (C) 1997, Olaf Kirch
10 #include <linux/utsname.h>
11 #include <linux/errno.h>
12 #include <linux/string.h>
13 #include <linux/sunrpc/clnt.h>
14 #include <linux/nfs.h>
15 #include <linux/nfs3.h>
16 #include <linux/nfs_fs.h>
18 #define NFSDBG_FACILITY NFSDBG_PROC
20 /* A wrapper to handle the EJUKEBOX error message */
22 nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
26 rpc_clnt_sigmask(clnt, &oldset);
28 res = rpc_call_sync(clnt, msg, flags);
31 set_current_state(TASK_INTERRUPTIBLE);
32 schedule_timeout(NFS_JUKEBOX_RETRY_TIME);
34 } while (!signalled());
35 rpc_clnt_sigunmask(clnt, &oldset);
40 nfs3_rpc_call_wrapper(struct rpc_clnt *clnt, u32 proc, void *argp, void *resp, int flags)
42 struct rpc_message msg = { proc, argp, resp, NULL };
43 return nfs3_rpc_wrapper(clnt, &msg, flags);
46 #define rpc_call(clnt, proc, argp, resp, flags) \
47 nfs3_rpc_call_wrapper(clnt, proc, argp, resp, flags)
48 #define rpc_call_sync(clnt, msg, flags) \
49 nfs3_rpc_wrapper(clnt, msg, flags)
52 * Bare-bones access to getattr: this is for nfs_read_super.
55 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
56 struct nfs_fattr *fattr)
60 dprintk("NFS call getroot\n");
62 status = rpc_call(server->client, NFS3PROC_GETATTR, fhandle, fattr, 0);
63 dprintk("NFS reply getroot\n");
68 * One function for each procedure in the NFS protocol.
71 nfs3_proc_getattr(struct inode *inode, struct nfs_fattr *fattr)
75 dprintk("NFS call getattr\n");
77 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_GETATTR,
78 NFS_FH(inode), fattr, 0);
79 dprintk("NFS reply getattr\n");
84 nfs3_proc_setattr(struct inode *inode, struct nfs_fattr *fattr,
87 struct nfs3_sattrargs arg = { NFS_FH(inode), sattr, 0, 0 };
90 dprintk("NFS call setattr\n");
92 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_SETATTR, &arg, fattr, 0);
93 dprintk("NFS reply setattr\n");
98 nfs3_proc_lookup(struct inode *dir, struct qstr *name,
99 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
101 struct nfs_fattr dir_attr;
102 struct nfs3_diropargs arg = { NFS_FH(dir), name->name, name->len };
103 struct nfs3_diropres res = { &dir_attr, fhandle, fattr };
106 dprintk("NFS call lookup %s\n", name->name);
109 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_LOOKUP, &arg, &res, 0);
110 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR))
111 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_GETATTR,
113 dprintk("NFS reply lookup: %d\n", status);
115 status = nfs_refresh_inode(dir, &dir_attr);
120 nfs3_proc_access(struct inode *inode, int mode, int ruid)
122 struct nfs_fattr fattr;
123 struct nfs3_accessargs arg = { NFS_FH(inode), 0 };
124 struct nfs3_accessres res = { &fattr, 0 };
127 dprintk("NFS call access\n");
131 arg.access |= NFS3_ACCESS_READ;
132 if (S_ISDIR(inode->i_mode)) {
133 if (mode & MAY_WRITE)
134 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE;
136 arg.access |= NFS3_ACCESS_LOOKUP;
138 if (mode & MAY_WRITE)
139 arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND;
141 arg.access |= NFS3_ACCESS_EXECUTE;
143 flags = (ruid) ? RPC_CALL_REALUID : 0;
144 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_ACCESS, &arg, &res, flags);
145 nfs_refresh_inode(inode, &fattr);
146 dprintk("NFS reply access\n");
148 if (status == 0 && (arg.access & res.access) != arg.access)
154 nfs3_proc_readlink(struct inode *inode, struct page *page)
156 struct nfs_fattr fattr;
157 struct nfs3_readlinkargs args = { NFS_FH(inode), PAGE_CACHE_SIZE, &page };
160 dprintk("NFS call readlink\n");
162 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_READLINK,
164 nfs_refresh_inode(inode, &fattr);
165 dprintk("NFS reply readlink: %d\n", status);
170 nfs3_proc_read(struct inode *inode, struct rpc_cred *cred,
171 struct nfs_fattr *fattr, int flags,
172 unsigned int base, unsigned int count, struct page *page,
175 u64 offset = page_offset(page) + base;
176 struct nfs_readargs arg = { NFS_FH(inode), offset, count,
178 struct nfs_readres res = { fattr, count, 0 };
179 struct rpc_message msg = { NFS3PROC_READ, &arg, &res, cred };
182 dprintk("NFS call read %d @ %Ld\n", count, (long long)offset);
184 status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
185 dprintk("NFS reply read: %d\n", status);
191 nfs3_proc_write(struct inode *inode, struct rpc_cred *cred,
192 struct nfs_fattr *fattr, int flags,
193 unsigned int base, unsigned int count,
194 struct page *page, struct nfs_writeverf *verf)
196 u64 offset = page_offset(page) + base;
197 struct nfs_writeargs arg = { NFS_FH(inode), offset, count,
198 NFS_FILE_SYNC, base, &page };
199 struct nfs_writeres res = { fattr, verf, 0 };
200 struct rpc_message msg = { NFS3PROC_WRITE, &arg, &res, cred };
201 int status, rpcflags = 0;
203 dprintk("NFS call write %d @ %Ld\n", count, (long long)offset);
205 if (flags & NFS_RW_SWAP)
206 rpcflags |= NFS_RPC_SWAPFLAGS;
207 arg.stable = (flags & NFS_RW_SYNC) ? NFS_FILE_SYNC : NFS_UNSTABLE;
209 status = rpc_call_sync(NFS_CLIENT(inode), &msg, rpcflags);
211 dprintk("NFS reply read: %d\n", status);
212 return status < 0? status : res.count;
216 * Create a regular file.
217 * For now, we don't implement O_EXCL.
220 nfs3_proc_create(struct inode *dir, struct qstr *name, struct iattr *sattr,
221 int flags, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
223 struct nfs_fattr dir_attr;
224 struct nfs3_createargs arg = { NFS_FH(dir), name->name, name->len,
225 sattr, 0, { 0, 0 } };
226 struct nfs3_diropres res = { &dir_attr, fhandle, fattr };
229 dprintk("NFS call create %s\n", name->name);
230 arg.createmode = NFS3_CREATE_UNCHECKED;
231 if (flags & O_EXCL) {
232 arg.createmode = NFS3_CREATE_EXCLUSIVE;
233 arg.verifier[0] = jiffies;
234 arg.verifier[1] = current->pid;
240 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_CREATE, &arg, &res, 0);
241 nfs_refresh_inode(dir, &dir_attr);
243 /* If the server doesn't support the exclusive creation semantics,
244 * try again with simple 'guarded' mode. */
245 if (status == NFSERR_NOTSUPP) {
246 switch (arg.createmode) {
247 case NFS3_CREATE_EXCLUSIVE:
248 arg.createmode = NFS3_CREATE_GUARDED;
251 case NFS3_CREATE_GUARDED:
252 arg.createmode = NFS3_CREATE_UNCHECKED;
255 case NFS3_CREATE_UNCHECKED:
262 dprintk("NFS reply create: %d\n", status);
264 /* When we created the file with exclusive semantics, make
265 * sure we set the attributes afterwards. */
266 if (status == 0 && arg.createmode == NFS3_CREATE_EXCLUSIVE) {
267 struct nfs3_sattrargs arg = { fhandle, sattr, 0, 0 };
268 dprintk("NFS call setattr (post-create)\n");
270 /* Note: we could use a guarded setattr here, but I'm
271 * not sure this buys us anything (and I'd have
272 * to revamp the NFSv3 XDR code) */
274 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SETATTR,
276 dprintk("NFS reply setattr (post-create): %d\n", status);
283 nfs3_proc_remove(struct inode *dir, struct qstr *name)
285 struct nfs_fattr dir_attr;
286 struct nfs3_diropargs arg = { NFS_FH(dir), name->name, name->len };
287 struct rpc_message msg = { NFS3PROC_REMOVE, &arg, &dir_attr, NULL };
290 dprintk("NFS call remove %s\n", name->name);
292 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
293 nfs_refresh_inode(dir, &dir_attr);
294 dprintk("NFS reply remove: %d\n", status);
299 nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name)
301 struct nfs3_diropargs *arg;
302 struct nfs_fattr *res;
304 struct nfs3_diropargs arg;
305 struct nfs_fattr res;
308 ptr = (struct unlinkxdr *)kmalloc(sizeof(*ptr), GFP_KERNEL);
313 arg->fh = NFS_FH(dir->d_inode);
314 arg->name = name->name;
315 arg->len = name->len;
317 msg->rpc_proc = NFS3PROC_REMOVE;
324 nfs3_proc_unlink_done(struct dentry *dir, struct rpc_message *msg)
326 struct nfs_fattr *dir_attr;
329 dir_attr = (struct nfs_fattr*)msg->rpc_resp;
330 nfs_refresh_inode(dir->d_inode, dir_attr);
331 kfree(msg->rpc_argp);
336 nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
337 struct inode *new_dir, struct qstr *new_name)
339 struct nfs_fattr old_dir_attr, new_dir_attr;
340 struct nfs3_renameargs arg = { NFS_FH(old_dir),
341 old_name->name, old_name->len,
343 new_name->name, new_name->len };
344 struct nfs3_renameres res = { &old_dir_attr, &new_dir_attr };
347 dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name);
348 old_dir_attr.valid = 0;
349 new_dir_attr.valid = 0;
350 status = rpc_call(NFS_CLIENT(old_dir), NFS3PROC_RENAME, &arg, &res, 0);
351 nfs_refresh_inode(old_dir, &old_dir_attr);
352 nfs_refresh_inode(new_dir, &new_dir_attr);
353 dprintk("NFS reply rename: %d\n", status);
358 nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
360 struct nfs_fattr dir_attr, fattr;
361 struct nfs3_linkargs arg = { NFS_FH(inode), NFS_FH(dir),
362 name->name, name->len };
363 struct nfs3_linkres res = { &dir_attr, &fattr };
366 dprintk("NFS call link %s\n", name->name);
369 status = rpc_call(NFS_CLIENT(inode), NFS3PROC_LINK, &arg, &res, 0);
370 nfs_refresh_inode(dir, &dir_attr);
371 nfs_refresh_inode(inode, &fattr);
372 dprintk("NFS reply link: %d\n", status);
377 nfs3_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
378 struct iattr *sattr, struct nfs_fh *fhandle,
379 struct nfs_fattr *fattr)
381 struct nfs_fattr dir_attr;
382 struct nfs3_symlinkargs arg = { NFS_FH(dir), name->name, name->len,
383 path->name, path->len, sattr };
384 struct nfs3_diropres res = { &dir_attr, fhandle, fattr };
387 dprintk("NFS call symlink %s -> %s\n", name->name, path->name);
390 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_SYMLINK, &arg, &res, 0);
391 nfs_refresh_inode(dir, &dir_attr);
392 dprintk("NFS reply symlink: %d\n", status);
397 nfs3_proc_mkdir(struct inode *dir, struct qstr *name, struct iattr *sattr,
398 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
400 struct nfs_fattr dir_attr;
401 struct nfs3_mkdirargs arg = { NFS_FH(dir), name->name, name->len,
403 struct nfs3_diropres res = { &dir_attr, fhandle, fattr };
406 dprintk("NFS call mkdir %s\n", name->name);
409 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKDIR, &arg, &res, 0);
410 nfs_refresh_inode(dir, &dir_attr);
411 dprintk("NFS reply mkdir: %d\n", status);
416 nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
418 struct nfs_fattr dir_attr;
419 struct nfs3_diropargs arg = { NFS_FH(dir), name->name, name->len };
422 dprintk("NFS call rmdir %s\n", name->name);
424 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_RMDIR, &arg, &dir_attr, 0);
425 nfs_refresh_inode(dir, &dir_attr);
426 dprintk("NFS reply rmdir: %d\n", status);
431 * The READDIR implementation is somewhat hackish - we pass the user buffer
432 * to the encode function, which installs it in the receive iovec.
433 * The decode function itself doesn't perform any decoding, it just makes
434 * sure the reply is syntactically correct.
438 nfs3_proc_readdir(struct inode *dir, struct rpc_cred *cred,
439 u64 cookie, struct page *page, unsigned int count, int plus)
441 struct nfs_fattr dir_attr;
442 u32 *verf = NFS_COOKIEVERF(dir);
443 struct nfs3_readdirargs arg = { NFS_FH(dir), cookie, {verf[0], verf[1]},
444 plus, count, &page };
445 struct nfs3_readdirres res = { &dir_attr, verf, plus };
446 struct rpc_message msg = { NFS3PROC_READDIR, &arg, &res, cred };
449 dprintk("NFS call readdir %d\n", (unsigned int) cookie);
452 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
453 nfs_refresh_inode(dir, &dir_attr);
454 dprintk("NFS reply readdir: %d\n", status);
459 nfs3_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr,
460 dev_t rdev, struct nfs_fh *fh, struct nfs_fattr *fattr)
462 struct nfs_fattr dir_attr;
463 struct nfs3_mknodargs arg = { NFS_FH(dir), name->name, name->len, 0,
465 struct nfs3_diropres res = { &dir_attr, fh, fattr };
468 switch (sattr->ia_mode & S_IFMT) {
469 case S_IFBLK: arg.type = NF3BLK; break;
470 case S_IFCHR: arg.type = NF3CHR; break;
471 case S_IFIFO: arg.type = NF3FIFO; break;
472 case S_IFSOCK: arg.type = NF3SOCK; break;
473 default: return -EINVAL;
476 dprintk("NFS call mknod %s %x\n", name->name, rdev);
479 status = rpc_call(NFS_CLIENT(dir), NFS3PROC_MKNOD, &arg, &res, 0);
480 nfs_refresh_inode(dir, &dir_attr);
481 dprintk("NFS reply mknod: %d\n", status);
486 * This is a combo call of fsstat and fsinfo
489 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
490 struct nfs_fsinfo *info)
494 dprintk("NFS call fsstat\n");
495 memset((char *)info, 0, sizeof(*info));
496 status = rpc_call(server->client, NFS3PROC_FSSTAT, fhandle, info, 0);
499 status = rpc_call(server->client, NFS3PROC_FSINFO, fhandle, info, 0);
502 dprintk("NFS reply statfs: %d\n", status);
506 extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
508 struct nfs_rpc_ops nfs_v3_clientops = {
509 3, /* protocol version */
521 nfs3_proc_unlink_setup,
522 nfs3_proc_unlink_done,