callback_proc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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(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", __func__, 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. do {
  70. struct nfs_client *prev = clp;
  71. inode = nfs_delegation_find_inode(clp, &args->fh);
  72. if (inode != NULL) {
  73. /* Set up a helper thread to actually return the delegation */
  74. switch(nfs_async_inode_return_delegation(inode, &args->stateid)) {
  75. case 0:
  76. res = 0;
  77. break;
  78. case -ENOENT:
  79. if (res != 0)
  80. res = htonl(NFS4ERR_BAD_STATEID);
  81. break;
  82. default:
  83. res = htonl(NFS4ERR_RESOURCE);
  84. }
  85. iput(inode);
  86. }
  87. clp = nfs_find_client_next(prev);
  88. nfs_put_client(prev);
  89. } while (clp != NULL);
  90. out:
  91. dprintk("%s: exit with status = %d\n", __func__, ntohl(res));
  92. return res;
  93. }