blob: 1695f1b0dd456f84c0a4c989069296629b5ea37a [file] [log] [blame]
David Teiglande7fd4172006-01-18 09:30:29 +00001/******************************************************************************
2*******************************************************************************
3**
David Teiglandc36258b2007-09-27 15:53:38 -05004** Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
David Teiglande7fd4172006-01-18 09:30:29 +00005**
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
13#include "dlm_internal.h"
14#include "member.h"
15#include "lock.h"
16#include "dir.h"
17#include "config.h"
18#include "requestqueue.h"
19
20struct rq_entry {
21 struct list_head list;
David Teigland6d40c4a2012-04-23 16:36:01 -050022 uint32_t recover_seq;
David Teiglande7fd4172006-01-18 09:30:29 +000023 int nodeid;
Al Viro8b0d8e02008-01-25 00:28:28 -050024 struct dlm_message request;
David Teiglande7fd4172006-01-18 09:30:29 +000025};
26
27/*
28 * Requests received while the lockspace is in recovery get added to the
29 * request queue and processed when recovery is complete. This happens when
30 * the lockspace is suspended on some nodes before it is on others, or the
31 * lockspace is enabled on some while still suspended on others.
32 */
33
Al Viro8b0d8e02008-01-25 00:28:28 -050034void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_message *ms)
David Teiglande7fd4172006-01-18 09:30:29 +000035{
36 struct rq_entry *e;
Al Viro8b0d8e02008-01-25 00:28:28 -050037 int length = ms->m_header.h_length - sizeof(struct dlm_message);
David Teiglande7fd4172006-01-18 09:30:29 +000038
David Teigland573c24c2009-11-30 16:34:43 -060039 e = kmalloc(sizeof(struct rq_entry) + length, GFP_NOFS);
David Teiglande7fd4172006-01-18 09:30:29 +000040 if (!e) {
David Teiglandc36258b2007-09-27 15:53:38 -050041 log_print("dlm_add_requestqueue: out of memory len %d", length);
42 return;
David Teiglande7fd4172006-01-18 09:30:29 +000043 }
44
David Teigland6d40c4a2012-04-23 16:36:01 -050045 e->recover_seq = ls->ls_recover_seq & 0xFFFFFFFF;
David Teiglande7fd4172006-01-18 09:30:29 +000046 e->nodeid = nodeid;
Al Viro8b0d8e02008-01-25 00:28:28 -050047 memcpy(&e->request, ms, ms->m_header.h_length);
David Teiglande7fd4172006-01-18 09:30:29 +000048
David Teigland90135922006-01-20 08:47:07 +000049 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglandc36258b2007-09-27 15:53:38 -050050 list_add_tail(&e->list, &ls->ls_requestqueue);
David Teigland90135922006-01-20 08:47:07 +000051 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000052}
53
David Teiglandc36258b2007-09-27 15:53:38 -050054/*
55 * Called by dlm_recoverd to process normal messages saved while recovery was
56 * happening. Normal locking has been enabled before this is called. dlm_recv
57 * upon receiving a message, will wait for all saved messages to be drained
58 * here before processing the message it got. If a new dlm_ls_stop() arrives
59 * while we're processing these saved messages, it may block trying to suspend
60 * dlm_recv if dlm_recv is waiting for us in dlm_wait_requestqueue. In that
61 * case, we don't abort since locking_stopped is still 0. If dlm_recv is not
62 * waiting for us, then this processing may be aborted due to locking_stopped.
63 */
64
David Teiglande7fd4172006-01-18 09:30:29 +000065int dlm_process_requestqueue(struct dlm_ls *ls)
66{
67 struct rq_entry *e;
David Teigland48756472012-04-26 15:54:29 -050068 struct dlm_message *ms;
David Teiglande7fd4172006-01-18 09:30:29 +000069 int error = 0;
70
David Teigland90135922006-01-20 08:47:07 +000071 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000072
73 for (;;) {
74 if (list_empty(&ls->ls_requestqueue)) {
David Teigland90135922006-01-20 08:47:07 +000075 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000076 error = 0;
77 break;
78 }
79 e = list_entry(ls->ls_requestqueue.next, struct rq_entry, list);
David Teigland90135922006-01-20 08:47:07 +000080 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000081
David Teigland48756472012-04-26 15:54:29 -050082 ms = &e->request;
83
84 log_limit(ls, "dlm_process_requestqueue msg %d from %d "
85 "lkid %x remid %x result %d seq %u",
86 ms->m_type, ms->m_header.h_nodeid,
87 ms->m_lkid, ms->m_remid, ms->m_result,
88 e->recover_seq);
89
David Teigland6d40c4a2012-04-23 16:36:01 -050090 dlm_receive_message_saved(ls, &e->request, e->recover_seq);
David Teiglande7fd4172006-01-18 09:30:29 +000091
David Teigland90135922006-01-20 08:47:07 +000092 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000093 list_del(&e->list);
94 kfree(e);
95
96 if (dlm_locking_stopped(ls)) {
97 log_debug(ls, "process_requestqueue abort running");
David Teigland90135922006-01-20 08:47:07 +000098 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +000099 error = -EINTR;
100 break;
101 }
102 schedule();
103 }
104
105 return error;
106}
107
108/*
109 * After recovery is done, locking is resumed and dlm_recoverd takes all the
David Teiglandc36258b2007-09-27 15:53:38 -0500110 * saved requests and processes them as they would have been by dlm_recv. At
111 * the same time, dlm_recv will start receiving new requests from remote nodes.
112 * We want to delay dlm_recv processing new requests until dlm_recoverd has
113 * finished processing the old saved requests. We don't check for locking
114 * stopped here because dlm_ls_stop won't stop locking until it's suspended us
115 * (dlm_recv).
David Teiglande7fd4172006-01-18 09:30:29 +0000116 */
117
118void dlm_wait_requestqueue(struct dlm_ls *ls)
119{
120 for (;;) {
David Teigland90135922006-01-20 08:47:07 +0000121 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000122 if (list_empty(&ls->ls_requestqueue))
123 break;
David Teigland90135922006-01-20 08:47:07 +0000124 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000125 schedule();
126 }
David Teigland90135922006-01-20 08:47:07 +0000127 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000128}
129
130static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid)
131{
132 uint32_t type = ms->m_type;
133
David Teigland2896ee32006-11-27 11:31:22 -0600134 /* the ls is being cleaned up and freed by release_lockspace */
135 if (!ls->ls_count)
136 return 1;
137
David Teiglande7fd4172006-01-18 09:30:29 +0000138 if (dlm_is_removed(ls, nodeid))
139 return 1;
140
141 /* directory operations are always purged because the directory is
142 always rebuilt during recovery and the lookups resent */
143
144 if (type == DLM_MSG_REMOVE ||
145 type == DLM_MSG_LOOKUP ||
146 type == DLM_MSG_LOOKUP_REPLY)
147 return 1;
148
149 if (!dlm_no_directory(ls))
150 return 0;
151
David Teigland48756472012-04-26 15:54:29 -0500152 return 1;
David Teiglande7fd4172006-01-18 09:30:29 +0000153}
154
155void dlm_purge_requestqueue(struct dlm_ls *ls)
156{
157 struct dlm_message *ms;
158 struct rq_entry *e, *safe;
159
David Teigland90135922006-01-20 08:47:07 +0000160 mutex_lock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000161 list_for_each_entry_safe(e, safe, &ls->ls_requestqueue, list) {
Al Viro8b0d8e02008-01-25 00:28:28 -0500162 ms = &e->request;
David Teiglande7fd4172006-01-18 09:30:29 +0000163
164 if (purge_request(ls, ms, e->nodeid)) {
165 list_del(&e->list);
166 kfree(e);
167 }
168 }
David Teigland90135922006-01-20 08:47:07 +0000169 mutex_unlock(&ls->ls_requestqueue_mutex);
David Teiglande7fd4172006-01-18 09:30:29 +0000170}
171