callback.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #include "cmservice.h"
  22. /*****************************************************************************/
  23. /*
  24. * allow the fileserver to request callback state (re-)initialisation
  25. */
  26. int SRXAFSCM_InitCallBackState(struct afs_server *server)
  27. {
  28. struct list_head callbacks;
  29. _enter("%p", server);
  30. INIT_LIST_HEAD(&callbacks);
  31. /* transfer the callback list from the server to a temp holding area */
  32. spin_lock(&server->cb_lock);
  33. list_add(&callbacks, &server->cb_promises);
  34. list_del_init(&server->cb_promises);
  35. /* munch our way through the list, grabbing the inode, dropping all the
  36. * locks and regetting them in the right order
  37. */
  38. while (!list_empty(&callbacks)) {
  39. struct afs_vnode *vnode;
  40. struct inode *inode;
  41. vnode = list_entry(callbacks.next, struct afs_vnode, cb_link);
  42. list_del_init(&vnode->cb_link);
  43. /* try and grab the inode - may fail */
  44. inode = igrab(AFS_VNODE_TO_I(vnode));
  45. if (inode) {
  46. int release = 0;
  47. spin_unlock(&server->cb_lock);
  48. spin_lock(&vnode->lock);
  49. if (vnode->cb_server == server) {
  50. vnode->cb_server = NULL;
  51. afs_kafstimod_del_timer(&vnode->cb_timeout);
  52. spin_lock(&afs_cb_hash_lock);
  53. list_del_init(&vnode->cb_hash_link);
  54. spin_unlock(&afs_cb_hash_lock);
  55. release = 1;
  56. }
  57. spin_unlock(&vnode->lock);
  58. iput(inode);
  59. afs_put_server(server);
  60. spin_lock(&server->cb_lock);
  61. }
  62. }
  63. spin_unlock(&server->cb_lock);
  64. _leave(" = 0");
  65. return 0;
  66. } /* end SRXAFSCM_InitCallBackState() */
  67. /*****************************************************************************/
  68. /*
  69. * allow the fileserver to break callback promises
  70. */
  71. int SRXAFSCM_CallBack(struct afs_server *server, size_t count,
  72. struct afs_callback callbacks[])
  73. {
  74. _enter("%p,%u,", server, count);
  75. for (; count > 0; callbacks++, count--) {
  76. struct afs_vnode *vnode = NULL;
  77. struct inode *inode = NULL;
  78. int valid = 0;
  79. _debug("- Fid { vl=%08x n=%u u=%u } CB { v=%u x=%u t=%u }",
  80. callbacks->fid.vid,
  81. callbacks->fid.vnode,
  82. callbacks->fid.unique,
  83. callbacks->version,
  84. callbacks->expiry,
  85. callbacks->type
  86. );
  87. /* find the inode for this fid */
  88. spin_lock(&afs_cb_hash_lock);
  89. list_for_each_entry(vnode,
  90. &afs_cb_hash(server, &callbacks->fid),
  91. cb_hash_link) {
  92. if (memcmp(&vnode->fid, &callbacks->fid,
  93. sizeof(struct afs_fid)) != 0)
  94. continue;
  95. /* right vnode, but is it same server? */
  96. if (vnode->cb_server != server)
  97. break; /* no */
  98. /* try and nail the inode down */
  99. inode = igrab(AFS_VNODE_TO_I(vnode));
  100. break;
  101. }
  102. spin_unlock(&afs_cb_hash_lock);
  103. if (inode) {
  104. /* we've found the record for this vnode */
  105. spin_lock(&vnode->lock);
  106. if (vnode->cb_server == server) {
  107. /* the callback _is_ on the calling server */
  108. vnode->cb_server = NULL;
  109. valid = 1;
  110. afs_kafstimod_del_timer(&vnode->cb_timeout);
  111. vnode->flags |= AFS_VNODE_CHANGED;
  112. spin_lock(&server->cb_lock);
  113. list_del_init(&vnode->cb_link);
  114. spin_unlock(&server->cb_lock);
  115. spin_lock(&afs_cb_hash_lock);
  116. list_del_init(&vnode->cb_hash_link);
  117. spin_unlock(&afs_cb_hash_lock);
  118. }
  119. spin_unlock(&vnode->lock);
  120. if (valid) {
  121. invalidate_remote_inode(inode);
  122. afs_put_server(server);
  123. }
  124. iput(inode);
  125. }
  126. }
  127. _leave(" = 0");
  128. return 0;
  129. } /* end SRXAFSCM_CallBack() */
  130. /*****************************************************************************/
  131. /*
  132. * allow the fileserver to see if the cache manager is still alive
  133. */
  134. int SRXAFSCM_Probe(struct afs_server *server)
  135. {
  136. _debug("SRXAFSCM_Probe(%p)\n", server);
  137. return 0;
  138. } /* end SRXAFSCM_Probe() */