callback.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2002 Red Hat, Inc. All rights reserved.
  3. *
  4. * This software may be freely redistributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * You should have received a copy of the GNU General Public License
  8. * along with this program; if not, write to the Free Software
  9. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  10. *
  11. * Authors: David Woodhouse <dwmw2@cambridge.redhat.com>
  12. * David Howells <dhowells@redhat.com>
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include "server.h"
  19. #include "vnode.h"
  20. #include "internal.h"
  21. /*****************************************************************************/
  22. /*
  23. * allow the fileserver to request callback state (re-)initialisation
  24. */
  25. int SRXAFSCM_InitCallBackState(struct afs_server *server)
  26. {
  27. struct list_head callbacks;
  28. _enter("%p", server);
  29. INIT_LIST_HEAD(&callbacks);
  30. /* transfer the callback list from the server to a temp holding area */
  31. spin_lock(&server->cb_lock);
  32. list_add(&callbacks, &server->cb_promises);
  33. list_del_init(&server->cb_promises);
  34. /* munch our way through the list, grabbing the inode, dropping all the
  35. * locks and regetting them in the right order
  36. */
  37. while (!list_empty(&callbacks)) {
  38. struct afs_vnode *vnode;
  39. struct inode *inode;
  40. vnode = list_entry(callbacks.next, struct afs_vnode, cb_link);
  41. list_del_init(&vnode->cb_link);
  42. /* try and grab the inode - may fail */
  43. inode = igrab(AFS_VNODE_TO_I(vnode));
  44. if (inode) {
  45. int release = 0;
  46. spin_unlock(&server->cb_lock);
  47. spin_lock(&vnode->lock);
  48. if (vnode->cb_server == server) {
  49. vnode->cb_server = NULL;
  50. afs_kafstimod_del_timer(&vnode->cb_timeout);
  51. spin_lock(&afs_cb_hash_lock);
  52. list_del_init(&vnode->cb_hash_link);
  53. spin_unlock(&afs_cb_hash_lock);
  54. release = 1;
  55. }
  56. spin_unlock(&vnode->lock);
  57. iput(inode);
  58. afs_put_server(server);
  59. spin_lock(&server->cb_lock);
  60. }
  61. }
  62. spin_unlock(&server->cb_lock);
  63. _leave(" = 0");
  64. return 0;
  65. } /* end SRXAFSCM_InitCallBackState() */
  66. /*****************************************************************************/
  67. /*
  68. * allow the fileserver to break callback promises
  69. */
  70. int SRXAFSCM_CallBack(struct afs_server *server, size_t count,
  71. struct afs_callback callbacks[])
  72. {
  73. _enter("%p,%u,", server, count);
  74. for (; count > 0; callbacks++, count--) {
  75. struct afs_vnode *vnode = NULL;
  76. struct inode *inode = NULL;
  77. int valid = 0;
  78. _debug("- Fid { vl=%08x n=%u u=%u } CB { v=%u x=%u t=%u }",
  79. callbacks->fid.vid,
  80. callbacks->fid.vnode,
  81. callbacks->fid.unique,
  82. callbacks->version,
  83. callbacks->expiry,
  84. callbacks->type
  85. );
  86. /* find the inode for this fid */
  87. spin_lock(&afs_cb_hash_lock);
  88. list_for_each_entry(vnode,
  89. &afs_cb_hash(server, &callbacks->fid),
  90. cb_hash_link) {
  91. if (memcmp(&vnode->fid, &callbacks->fid,
  92. sizeof(struct afs_fid)) != 0)
  93. continue;
  94. /* right vnode, but is it same server? */
  95. if (vnode->cb_server != server)
  96. break; /* no */
  97. /* try and nail the inode down */
  98. inode = igrab(AFS_VNODE_TO_I(vnode));
  99. break;
  100. }
  101. spin_unlock(&afs_cb_hash_lock);
  102. if (inode) {
  103. /* we've found the record for this vnode */
  104. spin_lock(&vnode->lock);
  105. if (vnode->cb_server == server) {
  106. /* the callback _is_ on the calling server */
  107. vnode->cb_server = NULL;
  108. valid = 1;
  109. afs_kafstimod_del_timer(&vnode->cb_timeout);
  110. vnode->flags |= AFS_VNODE_CHANGED;
  111. spin_lock(&server->cb_lock);
  112. list_del_init(&vnode->cb_link);
  113. spin_unlock(&server->cb_lock);
  114. spin_lock(&afs_cb_hash_lock);
  115. list_del_init(&vnode->cb_hash_link);
  116. spin_unlock(&afs_cb_hash_lock);
  117. }
  118. spin_unlock(&vnode->lock);
  119. if (valid) {
  120. invalidate_remote_inode(inode);
  121. afs_put_server(server);
  122. }
  123. iput(inode);
  124. }
  125. }
  126. _leave(" = 0");
  127. return 0;
  128. } /* end SRXAFSCM_CallBack() */
  129. /*****************************************************************************/
  130. /*
  131. * allow the fileserver to see if the cache manager is still alive
  132. */
  133. int SRXAFSCM_Probe(struct afs_server *server)
  134. {
  135. _debug("SRXAFSCM_Probe(%p)\n", server);
  136. return 0;
  137. } /* end SRXAFSCM_Probe() */