callback_proc.c 2.4 KB

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