callback_proc.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #define NFSDBG_FACILITY NFSDBG_CALLBACK
  15. __be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res)
  16. {
  17. struct nfs_client *clp;
  18. struct nfs_delegation *delegation;
  19. struct nfs_inode *nfsi;
  20. struct inode *inode;
  21. res->bitmap[0] = res->bitmap[1] = 0;
  22. res->status = htonl(NFS4ERR_BADHANDLE);
  23. clp = nfs_find_client(args->addr, 4);
  24. if (clp == NULL)
  25. goto out;
  26. inode = nfs_delegation_find_inode(clp, &args->fh);
  27. if (inode == NULL)
  28. goto out_putclient;
  29. nfsi = NFS_I(inode);
  30. down_read(&nfsi->rwsem);
  31. delegation = nfsi->delegation;
  32. if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0)
  33. goto out_iput;
  34. res->size = i_size_read(inode);
  35. res->change_attr = delegation->change_attr;
  36. if (nfsi->npages != 0)
  37. res->change_attr++;
  38. res->ctime = inode->i_ctime;
  39. res->mtime = inode->i_mtime;
  40. res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) &
  41. args->bitmap[0];
  42. res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) &
  43. args->bitmap[1];
  44. res->status = 0;
  45. out_iput:
  46. up_read(&nfsi->rwsem);
  47. iput(inode);
  48. out_putclient:
  49. nfs_put_client(clp);
  50. out:
  51. dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res->status));
  52. return res->status;
  53. }
  54. __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy)
  55. {
  56. struct nfs_client *clp;
  57. struct inode *inode;
  58. __be32 res;
  59. res = htonl(NFS4ERR_BADHANDLE);
  60. clp = nfs_find_client(args->addr, 4);
  61. if (clp == NULL)
  62. goto out;
  63. inode = nfs_delegation_find_inode(clp, &args->fh);
  64. if (inode == NULL)
  65. goto out_putclient;
  66. /* Set up a helper thread to actually return the delegation */
  67. switch(nfs_async_inode_return_delegation(inode, &args->stateid)) {
  68. case 0:
  69. res = 0;
  70. break;
  71. case -ENOENT:
  72. res = htonl(NFS4ERR_BAD_STATEID);
  73. break;
  74. default:
  75. res = htonl(NFS4ERR_RESOURCE);
  76. }
  77. iput(inode);
  78. out_putclient:
  79. nfs_put_client(clp);
  80. out:
  81. dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res));
  82. return res;
  83. }