requestqueue.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) 2005 Red Hat, Inc. All rights reserved.
  5. **
  6. ** This copyrighted material is made available to anyone wishing to use,
  7. ** modify, copy, or redistribute it subject to the terms and conditions
  8. ** of the GNU General Public License v.2.
  9. **
  10. *******************************************************************************
  11. ******************************************************************************/
  12. #include "dlm_internal.h"
  13. #include "member.h"
  14. #include "lock.h"
  15. #include "dir.h"
  16. #include "config.h"
  17. #include "requestqueue.h"
  18. struct rq_entry {
  19. struct list_head list;
  20. int nodeid;
  21. char request[1];
  22. };
  23. /*
  24. * Requests received while the lockspace is in recovery get added to the
  25. * request queue and processed when recovery is complete. This happens when
  26. * the lockspace is suspended on some nodes before it is on others, or the
  27. * lockspace is enabled on some while still suspended on others.
  28. */
  29. void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_header *hd)
  30. {
  31. struct rq_entry *e;
  32. int length = hd->h_length;
  33. if (dlm_is_removed(ls, nodeid))
  34. return;
  35. e = kmalloc(sizeof(struct rq_entry) + length, GFP_KERNEL);
  36. if (!e) {
  37. log_print("dlm_add_requestqueue: out of memory\n");
  38. return;
  39. }
  40. e->nodeid = nodeid;
  41. memcpy(e->request, hd, length);
  42. mutex_lock(&ls->ls_requestqueue_mutex);
  43. list_add_tail(&e->list, &ls->ls_requestqueue);
  44. mutex_unlock(&ls->ls_requestqueue_mutex);
  45. }
  46. int dlm_process_requestqueue(struct dlm_ls *ls)
  47. {
  48. struct rq_entry *e;
  49. struct dlm_header *hd;
  50. int error = 0;
  51. mutex_lock(&ls->ls_requestqueue_mutex);
  52. for (;;) {
  53. if (list_empty(&ls->ls_requestqueue)) {
  54. mutex_unlock(&ls->ls_requestqueue_mutex);
  55. error = 0;
  56. break;
  57. }
  58. e = list_entry(ls->ls_requestqueue.next, struct rq_entry, list);
  59. mutex_unlock(&ls->ls_requestqueue_mutex);
  60. hd = (struct dlm_header *) e->request;
  61. error = dlm_receive_message(hd, e->nodeid, 1);
  62. if (error == -EINTR) {
  63. /* entry is left on requestqueue */
  64. log_debug(ls, "process_requestqueue abort eintr");
  65. break;
  66. }
  67. mutex_lock(&ls->ls_requestqueue_mutex);
  68. list_del(&e->list);
  69. kfree(e);
  70. if (dlm_locking_stopped(ls)) {
  71. log_debug(ls, "process_requestqueue abort running");
  72. mutex_unlock(&ls->ls_requestqueue_mutex);
  73. error = -EINTR;
  74. break;
  75. }
  76. schedule();
  77. }
  78. return error;
  79. }
  80. /*
  81. * After recovery is done, locking is resumed and dlm_recoverd takes all the
  82. * saved requests and processes them as they would have been by dlm_recvd. At
  83. * the same time, dlm_recvd will start receiving new requests from remote
  84. * nodes. We want to delay dlm_recvd processing new requests until
  85. * dlm_recoverd has finished processing the old saved requests.
  86. */
  87. void dlm_wait_requestqueue(struct dlm_ls *ls)
  88. {
  89. for (;;) {
  90. mutex_lock(&ls->ls_requestqueue_mutex);
  91. if (list_empty(&ls->ls_requestqueue))
  92. break;
  93. if (dlm_locking_stopped(ls))
  94. break;
  95. mutex_unlock(&ls->ls_requestqueue_mutex);
  96. schedule();
  97. }
  98. mutex_unlock(&ls->ls_requestqueue_mutex);
  99. }
  100. static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid)
  101. {
  102. uint32_t type = ms->m_type;
  103. if (dlm_is_removed(ls, nodeid))
  104. return 1;
  105. /* directory operations are always purged because the directory is
  106. always rebuilt during recovery and the lookups resent */
  107. if (type == DLM_MSG_REMOVE ||
  108. type == DLM_MSG_LOOKUP ||
  109. type == DLM_MSG_LOOKUP_REPLY)
  110. return 1;
  111. if (!dlm_no_directory(ls))
  112. return 0;
  113. /* with no directory, the master is likely to change as a part of
  114. recovery; requests to/from the defunct master need to be purged */
  115. switch (type) {
  116. case DLM_MSG_REQUEST:
  117. case DLM_MSG_CONVERT:
  118. case DLM_MSG_UNLOCK:
  119. case DLM_MSG_CANCEL:
  120. /* we're no longer the master of this resource, the sender
  121. will resend to the new master (see waiter_needs_recovery) */
  122. if (dlm_hash2nodeid(ls, ms->m_hash) != dlm_our_nodeid())
  123. return 1;
  124. break;
  125. case DLM_MSG_REQUEST_REPLY:
  126. case DLM_MSG_CONVERT_REPLY:
  127. case DLM_MSG_UNLOCK_REPLY:
  128. case DLM_MSG_CANCEL_REPLY:
  129. case DLM_MSG_GRANT:
  130. /* this reply is from the former master of the resource,
  131. we'll resend to the new master if needed */
  132. if (dlm_hash2nodeid(ls, ms->m_hash) != nodeid)
  133. return 1;
  134. break;
  135. }
  136. return 0;
  137. }
  138. void dlm_purge_requestqueue(struct dlm_ls *ls)
  139. {
  140. struct dlm_message *ms;
  141. struct rq_entry *e, *safe;
  142. mutex_lock(&ls->ls_requestqueue_mutex);
  143. list_for_each_entry_safe(e, safe, &ls->ls_requestqueue, list) {
  144. ms = (struct dlm_message *) e->request;
  145. if (purge_request(ls, ms, e->nodeid)) {
  146. list_del(&e->list);
  147. kfree(e);
  148. }
  149. }
  150. mutex_unlock(&ls->ls_requestqueue_mutex);
  151. }