blob: 97cf8f71451ffbbd02e85d2d4c4061ee73dfb75a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/nfs/callback_proc.c
3 *
4 * Copyright (C) 2004 Trond Myklebust
5 *
6 * NFSv4 callback procedures
7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/nfs4.h>
9#include <linux/nfs_fs.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000010#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include "callback.h"
12#include "delegation.h"
David Howells24c8dbb2006-08-22 20:06:10 -040013#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#define NFSDBG_FACILITY NFSDBG_CALLBACK
16
17unsigned nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res)
18{
David Howellsadfa6f92006-08-22 20:06:08 -040019 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 struct nfs_delegation *delegation;
21 struct nfs_inode *nfsi;
22 struct inode *inode;
23
24 res->bitmap[0] = res->bitmap[1] = 0;
25 res->status = htonl(NFS4ERR_BADHANDLE);
David Howells24c8dbb2006-08-22 20:06:10 -040026 clp = nfs_find_client(args->addr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 if (clp == NULL)
28 goto out;
29 inode = nfs_delegation_find_inode(clp, &args->fh);
30 if (inode == NULL)
31 goto out_putclient;
32 nfsi = NFS_I(inode);
33 down_read(&nfsi->rwsem);
34 delegation = nfsi->delegation;
35 if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0)
36 goto out_iput;
37 res->size = i_size_read(inode);
Trond Myklebustbeb2a5e2006-01-03 09:55:37 +010038 res->change_attr = delegation->change_attr;
39 if (nfsi->npages != 0)
40 res->change_attr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 res->ctime = inode->i_ctime;
42 res->mtime = inode->i_mtime;
43 res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) &
44 args->bitmap[0];
45 res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) &
46 args->bitmap[1];
47 res->status = 0;
48out_iput:
49 up_read(&nfsi->rwsem);
50 iput(inode);
51out_putclient:
David Howells24c8dbb2006-08-22 20:06:10 -040052 nfs_put_client(clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053out:
54 dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res->status));
55 return res->status;
56}
57
58unsigned nfs4_callback_recall(struct cb_recallargs *args, void *dummy)
59{
David Howellsadfa6f92006-08-22 20:06:08 -040060 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 struct inode *inode;
62 unsigned res;
63
64 res = htonl(NFS4ERR_BADHANDLE);
David Howells24c8dbb2006-08-22 20:06:10 -040065 clp = nfs_find_client(args->addr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 if (clp == NULL)
67 goto out;
68 inode = nfs_delegation_find_inode(clp, &args->fh);
69 if (inode == NULL)
70 goto out_putclient;
71 /* Set up a helper thread to actually return the delegation */
72 switch(nfs_async_inode_return_delegation(inode, &args->stateid)) {
73 case 0:
74 res = 0;
75 break;
76 case -ENOENT:
77 res = htonl(NFS4ERR_BAD_STATEID);
78 break;
79 default:
80 res = htonl(NFS4ERR_RESOURCE);
81 }
82 iput(inode);
83out_putclient:
David Howells24c8dbb2006-08-22 20:06:10 -040084 nfs_put_client(clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085out:
86 dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res));
87 return res;
88}