blob: e89e0ff8bfa3ad5fefb3065e747f8a40fdcd5b02 [file] [log] [blame]
Thomas Gleixner2522fe42019-05-28 09:57:20 -07001// SPDX-License-Identifier: GPL-2.0-only
David Teiglande7fd4172006-01-18 09:30:29 +00002/******************************************************************************
3*******************************************************************************
4**
David Teiglandc36258b2007-09-27 15:53:38 -05005** Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
David Teiglande7fd4172006-01-18 09:30:29 +00006**
David Teiglande7fd4172006-01-18 09:30:29 +00007**
8*******************************************************************************
9******************************************************************************/
10
11#include "dlm_internal.h"
12#include "member.h"
13#include "lock.h"
14#include "dir.h"
15#include "config.h"
16#include "requestqueue.h"
17
18struct rq_entry {
19 struct list_head list;
David Teigland6d40c4a2012-04-23 16:36:01 -050020 uint32_t recover_seq;
David Teiglande7fd4172006-01-18 09:30:29 +000021 int nodeid;
Al Viro8b0d8e02008-01-25 00:28:28 -050022 struct dlm_message request;
David Teiglande7fd4172006-01-18 09:30:29 +000023};
24
25/*
26 * Requests received while the lockspace is in recovery get added to the
27 * request queue and processed when recovery is complete. This happens when
28 * the lockspace is suspended on some nodes before it is on others, or the
29 * lockspace is enabled on some while still suspended on others.
30 */
31
Al Viro8b0d8e02008-01-25 00:28:28 -050032void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_message *ms)
David Teiglande7fd4172006-01-18 09:30:29 +000033{
34 struct rq_entry *e;
Al Viro8b0d8e02008-01-25 00:28:28 -050035 int length = ms->m_header.h_length - sizeof(struct dlm_message);
David Teiglande7fd4172006-01-18 09:30:29 +000036
David Teigland573c24c2009-11-30 16:34:43 -060037 e = kmalloc(sizeof(struct rq_entry) + length, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000038 if (!e) {
David Teiglandc36258b2007-09-27 15:53:38 -050039 log_print("dlm_add_requestqueue: out of memory len %d", length);
40 return;
David Teiglande7fd4172006-01-18 09:30:29 +000041 }
42
David Teigland6d40c4a2012-04-23 16:36:01 -050043 e->recover_seq = ls->ls_recover_seq & 0xFFFFFFFF;
David Teiglande7fd4172006-01-18 09:30:29 +000044 e->nodeid = nodeid;
Al Viro8b0d8e02008-01-25 00:28:28 -050045 memcpy(&e->request, ms, ms->m_header.h_length);
David Teiglande7fd4172006-01-18 09:30:29 +000046
David Teigland90135922006-01-20 08:47:07 +000047 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglandc36258b2007-09-27 15:53:38 -050048 list_add_tail(&e->list, &ls->ls_requestqueue);
David Teigland90135922006-01-20 08:47:07 +000049 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000050}
51
David Teiglandc36258b2007-09-27 15:53:38 -050052/*
53 * Called by dlm_recoverd to process normal messages saved while recovery was
54 * happening. Normal locking has been enabled before this is called. dlm_recv
55 * upon receiving a message, will wait for all saved messages to be drained
56 * here before processing the message it got. If a new dlm_ls_stop() arrives
57 * while we're processing these saved messages, it may block trying to suspend
58 * dlm_recv if dlm_recv is waiting for us in dlm_wait_requestqueue. In that
59 * case, we don't abort since locking_stopped is still 0. If dlm_recv is not
60 * waiting for us, then this processing may be aborted due to locking_stopped.
61 */
62
David Teiglande7fd4172006-01-18 09:30:29 +000063int dlm_process_requestqueue(struct dlm_ls *ls)
64{
65 struct rq_entry *e;
David Teigland48756472012-04-26 15:54:29 -050066 struct dlm_message *ms;
David Teiglande7fd4172006-01-18 09:30:29 +000067 int error = 0;
68
David Teigland90135922006-01-20 08:47:07 +000069 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000070
71 for (;;) {
72 if (list_empty(&ls->ls_requestqueue)) {
David Teigland90135922006-01-20 08:47:07 +000073 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000074 error = 0;
75 break;
76 }
77 e = list_entry(ls->ls_requestqueue.next, struct rq_entry, list);
David Teigland90135922006-01-20 08:47:07 +000078 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000079
David Teigland48756472012-04-26 15:54:29 -050080 ms = &e->request;
81
82 log_limit(ls, "dlm_process_requestqueue msg %d from %d "
83 "lkid %x remid %x result %d seq %u",
84 ms->m_type, ms->m_header.h_nodeid,
85 ms->m_lkid, ms->m_remid, ms->m_result,
86 e->recover_seq);
87
David Teigland6d40c4a2012-04-23 16:36:01 -050088 dlm_receive_message_saved(ls, &e->request, e->recover_seq);
David Teiglande7fd4172006-01-18 09:30:29 +000089
David Teigland90135922006-01-20 08:47:07 +000090 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000091 list_del(&e->list);
92 kfree(e);
93
94 if (dlm_locking_stopped(ls)) {
95 log_debug(ls, "process_requestqueue abort running");
David Teigland90135922006-01-20 08:47:07 +000096 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000097 error = -EINTR;
98 break;
99 }
100 schedule();
101 }
102
103 return error;
104}
105
106/*
107 * After recovery is done, locking is resumed and dlm_recoverd takes all the
David Teiglandc36258b2007-09-27 15:53:38 -0500108 * saved requests and processes them as they would have been by dlm_recv. At
109 * the same time, dlm_recv will start receiving new requests from remote nodes.
110 * We want to delay dlm_recv processing new requests until dlm_recoverd has
111 * finished processing the old saved requests. We don't check for locking
112 * stopped here because dlm_ls_stop won't stop locking until it's suspended us
113 * (dlm_recv).
David Teiglande7fd4172006-01-18 09:30:29 +0000114 */
115
116void dlm_wait_requestqueue(struct dlm_ls *ls)
117{
118 for (;;) {
David Teigland90135922006-01-20 08:47:07 +0000119 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000120 if (list_empty(&ls->ls_requestqueue))
121 break;
David Teigland90135922006-01-20 08:47:07 +0000122 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000123 schedule();
124 }
David Teigland90135922006-01-20 08:47:07 +0000125 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000126}
127
128static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid)
129{
130 uint32_t type = ms->m_type;
131
David Teigland2896ee32006-11-27 11:31:22 -0600132 /* the ls is being cleaned up and freed by release_lockspace */
133 if (!ls->ls_count)
134 return 1;
135
David Teiglande7fd4172006-01-18 09:30:29 +0000136 if (dlm_is_removed(ls, nodeid))
137 return 1;
138
139 /* directory operations are always purged because the directory is
140 always rebuilt during recovery and the lookups resent */
141
142 if (type == DLM_MSG_REMOVE ||
143 type == DLM_MSG_LOOKUP ||
144 type == DLM_MSG_LOOKUP_REPLY)
145 return 1;
146
147 if (!dlm_no_directory(ls))
148 return 0;
149
David Teigland48756472012-04-26 15:54:29 -0500150 return 1;
David Teiglande7fd4172006-01-18 09:30:29 +0000151}
152
153void dlm_purge_requestqueue(struct dlm_ls *ls)
154{
155 struct dlm_message *ms;
156 struct rq_entry *e, *safe;
157
David Teigland90135922006-01-20 08:47:07 +0000158 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000159 list_for_each_entry_safe(e, safe, &ls->ls_requestqueue, list) {
Al Viro8b0d8e02008-01-25 00:28:28 -0500160 ms = &e->request;
David Teiglande7fd4172006-01-18 09:30:29 +0000161
162 if (purge_request(ls, ms, e->nodeid)) {
163 list_del(&e->list);
164 kfree(e);
165 }
166 }
David Teigland90135922006-01-20 08:47:07 +0000167 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000168}
169