NFSv4: Check the return value of decode_compound_hdr_arg()
[linux-block.git] / fs / nfs / callback_proc.c
CommitLineData
1da177e4
LT
1/*
2 * linux/fs/nfs/callback_proc.c
3 *
4 * Copyright (C) 2004 Trond Myklebust
5 *
6 * NFSv4 callback procedures
7 */
1da177e4
LT
8#include <linux/nfs4.h>
9#include <linux/nfs_fs.h>
4ce79717 10#include "nfs4_fs.h"
1da177e4
LT
11#include "callback.h"
12#include "delegation.h"
24c8dbbb 13#include "internal.h"
1da177e4 14
1d98fe67 15#ifdef NFS_DEBUG
1da177e4 16#define NFSDBG_FACILITY NFSDBG_CALLBACK
1d98fe67 17#endif
1da177e4 18
e6f684f6 19__be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res)
1da177e4 20{
adfa6f98 21 struct nfs_client *clp;
1da177e4
LT
22 struct nfs_delegation *delegation;
23 struct nfs_inode *nfsi;
24 struct inode *inode;
1d98fe67 25
1da177e4
LT
26 res->bitmap[0] = res->bitmap[1] = 0;
27 res->status = htonl(NFS4ERR_BADHANDLE);
ff052645 28 clp = nfs_find_client(args->addr, 4);
1da177e4
LT
29 if (clp == NULL)
30 goto out;
1d98fe67
CL
31
32 dprintk("NFS: GETATTR callback request from %s\n",
33 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
34
1da177e4
LT
35 inode = nfs_delegation_find_inode(clp, &args->fh);
36 if (inode == NULL)
37 goto out_putclient;
38 nfsi = NFS_I(inode);
39 down_read(&nfsi->rwsem);
40 delegation = nfsi->delegation;
41 if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0)
42 goto out_iput;
43 res->size = i_size_read(inode);
beb2a5ec
TM
44 res->change_attr = delegation->change_attr;
45 if (nfsi->npages != 0)
46 res->change_attr++;
1da177e4
LT
47 res->ctime = inode->i_ctime;
48 res->mtime = inode->i_mtime;
49 res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) &
50 args->bitmap[0];
51 res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) &
52 args->bitmap[1];
53 res->status = 0;
54out_iput:
55 up_read(&nfsi->rwsem);
56 iput(inode);
57out_putclient:
24c8dbbb 58 nfs_put_client(clp);
1da177e4
LT
59out:
60 dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res->status));
61 return res->status;
62}
63
e6f684f6 64__be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy)
1da177e4 65{
adfa6f98 66 struct nfs_client *clp;
1da177e4 67 struct inode *inode;
e6f684f6 68 __be32 res;
1da177e4
LT
69
70 res = htonl(NFS4ERR_BADHANDLE);
ff052645 71 clp = nfs_find_client(args->addr, 4);
1da177e4
LT
72 if (clp == NULL)
73 goto out;
1d98fe67
CL
74
75 dprintk("NFS: RECALL callback request from %s\n",
76 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
77
3fbd67ad
TM
78 do {
79 struct nfs_client *prev = clp;
80
81 inode = nfs_delegation_find_inode(clp, &args->fh);
82 if (inode != NULL) {
83 /* Set up a helper thread to actually return the delegation */
84 switch(nfs_async_inode_return_delegation(inode, &args->stateid)) {
85 case 0:
86 res = 0;
87 break;
88 case -ENOENT:
89 if (res != 0)
90 res = htonl(NFS4ERR_BAD_STATEID);
91 break;
92 default:
93 res = htonl(NFS4ERR_RESOURCE);
94 }
95 iput(inode);
96 }
97 clp = nfs_find_client_next(prev);
98 nfs_put_client(prev);
99 } while (clp != NULL);
1da177e4
LT
100out:
101 dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res));
102 return res;
103}