callback_proc.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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>
  11. #include "nfs4_fs.h"
  12. #include "callback.h"
  13. #include "delegation.h"
  14. #define NFSDBG_FACILITY NFSDBG_CALLBACK
  15. unsigned nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res)
  16. {
  17. struct nfs4_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 = nfs4_find_client(&args->addr->sin_addr);
  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 = NFS_CHANGE_ATTR(inode);
  36. res->ctime = inode->i_ctime;
  37. res->mtime = inode->i_mtime;
  38. res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) &
  39. args->bitmap[0];
  40. res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) &
  41. args->bitmap[1];
  42. res->status = 0;
  43. out_iput:
  44. up_read(&nfsi->rwsem);
  45. iput(inode);
  46. out_putclient:
  47. nfs4_put_client(clp);
  48. out:
  49. dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res->status));
  50. return res->status;
  51. }
  52. unsigned nfs4_callback_recall(struct cb_recallargs *args, void *dummy)
  53. {
  54. struct nfs4_client *clp;
  55. struct inode *inode;
  56. unsigned res;
  57. res = htonl(NFS4ERR_BADHANDLE);
  58. clp = nfs4_find_client(&args->addr->sin_addr);
  59. if (clp == NULL)
  60. goto out;
  61. inode = nfs_delegation_find_inode(clp, &args->fh);
  62. if (inode == NULL)
  63. goto out_putclient;
  64. /* Set up a helper thread to actually return the delegation */
  65. switch(nfs_async_inode_return_delegation(inode, &args->stateid)) {
  66. case 0:
  67. res = 0;
  68. break;
  69. case -ENOENT:
  70. res = htonl(NFS4ERR_BAD_STATEID);
  71. break;
  72. default:
  73. res = htonl(NFS4ERR_RESOURCE);
  74. }
  75. iput(inode);
  76. out_putclient:
  77. nfs4_put_client(clp);
  78. out:
  79. dprintk("%s: exit with status = %d\n", __FUNCTION__, ntohl(res));
  80. return res;
  81. }