Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/callback_proc.c |
| 3 | * |
| 4 | * Copyright (C) 2004 Trond Myklebust |
| 5 | * |
| 6 | * NFSv4 callback procedures |
| 7 | */ |
| 8 | #include <linux/config.h> |
| 9 | #include <linux/nfs4.h> |
| 10 | #include <linux/nfs_fs.h> |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 11 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include "callback.h" |
| 13 | #include "delegation.h" |
| 14 | |
| 15 | #define NFSDBG_FACILITY NFSDBG_CALLBACK |
| 16 | |
| 17 | unsigned nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res) |
| 18 | { |
| 19 | struct nfs4_client *clp; |
| 20 | 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); |
| 26 | clp = nfs4_find_client(&args->addr->sin_addr); |
| 27 | 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); |
| 38 | res->change_attr = NFS_CHANGE_ATTR(inode); |
| 39 | res->ctime = inode->i_ctime; |
| 40 | res->mtime = inode->i_mtime; |
| 41 | res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) & |
| 42 | args->bitmap[0]; |
| 43 | res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) & |
| 44 | args->bitmap[1]; |
| 45 | res->status = 0; |
| 46 | out_iput: |
| 47 | up_read(&nfsi->rwsem); |
| 48 | iput(inode); |
| 49 | out_putclient: |
| 50 | nfs4_put_client(clp); |
| 51 | out: |
| 52 | dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res->status)); |
| 53 | return res->status; |
| 54 | } |
| 55 | |
| 56 | unsigned nfs4_callback_recall(struct cb_recallargs *args, void *dummy) |
| 57 | { |
| 58 | struct nfs4_client *clp; |
| 59 | struct inode *inode; |
| 60 | unsigned res; |
| 61 | |
| 62 | res = htonl(NFS4ERR_BADHANDLE); |
| 63 | clp = nfs4_find_client(&args->addr->sin_addr); |
| 64 | if (clp == NULL) |
| 65 | goto out; |
| 66 | inode = nfs_delegation_find_inode(clp, &args->fh); |
| 67 | if (inode == NULL) |
| 68 | goto out_putclient; |
| 69 | /* Set up a helper thread to actually return the delegation */ |
| 70 | switch(nfs_async_inode_return_delegation(inode, &args->stateid)) { |
| 71 | case 0: |
| 72 | res = 0; |
| 73 | break; |
| 74 | case -ENOENT: |
| 75 | res = htonl(NFS4ERR_BAD_STATEID); |
| 76 | break; |
| 77 | default: |
| 78 | res = htonl(NFS4ERR_RESOURCE); |
| 79 | } |
| 80 | iput(inode); |
| 81 | out_putclient: |
| 82 | nfs4_put_client(clp); |
| 83 | out: |
| 84 | dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res)); |
| 85 | return res; |
| 86 | } |