Blame view

fs/dlm/requestqueue.c 4.7 KB
2522fe45a   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
e7fd41792   David Teigland   [DLM] The core of...
2
3
4
  /******************************************************************************
  *******************************************************************************
  **
c36258b59   David Teigland   [DLM] block dlm_r...
5
  **  Copyright (C) 2005-2007 Red Hat, Inc.  All rights reserved.
e7fd41792   David Teigland   [DLM] The core of...
6
  **
e7fd41792   David Teigland   [DLM] The core of...
7
8
9
10
11
12
13
14
15
16
17
18
19
  **
  *******************************************************************************
  ******************************************************************************/
  
  #include "dlm_internal.h"
  #include "member.h"
  #include "lock.h"
  #include "dir.h"
  #include "config.h"
  #include "requestqueue.h"
  
  struct rq_entry {
  	struct list_head list;
6d40c4a70   David Teigland   dlm: improve erro...
20
  	uint32_t recover_seq;
e7fd41792   David Teigland   [DLM] The core of...
21
  	int nodeid;
8b0d8e03f   Al Viro   dlm: use proper C...
22
  	struct dlm_message request;
e7fd41792   David Teigland   [DLM] The core of...
23
24
25
26
27
28
29
30
  };
  
  /*
   * Requests received while the lockspace is in recovery get added to the
   * request queue and processed when recovery is complete.  This happens when
   * the lockspace is suspended on some nodes before it is on others, or the
   * lockspace is enabled on some while still suspended on others.
   */
8b0d8e03f   Al Viro   dlm: use proper C...
31
  void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_message *ms)
e7fd41792   David Teigland   [DLM] The core of...
32
33
  {
  	struct rq_entry *e;
8b0d8e03f   Al Viro   dlm: use proper C...
34
  	int length = ms->m_header.h_length - sizeof(struct dlm_message);
e7fd41792   David Teigland   [DLM] The core of...
35

573c24c4a   David Teigland   dlm: always use G...
36
  	e = kmalloc(sizeof(struct rq_entry) + length, GFP_NOFS);
e7fd41792   David Teigland   [DLM] The core of...
37
  	if (!e) {
c36258b59   David Teigland   [DLM] block dlm_r...
38
39
  		log_print("dlm_add_requestqueue: out of memory len %d", length);
  		return;
e7fd41792   David Teigland   [DLM] The core of...
40
  	}
6d40c4a70   David Teigland   dlm: improve erro...
41
  	e->recover_seq = ls->ls_recover_seq & 0xFFFFFFFF;
e7fd41792   David Teigland   [DLM] The core of...
42
  	e->nodeid = nodeid;
8b0d8e03f   Al Viro   dlm: use proper C...
43
  	memcpy(&e->request, ms, ms->m_header.h_length);
e7fd41792   David Teigland   [DLM] The core of...
44

901359256   David Teigland   [DLM] Update DLM ...
45
  	mutex_lock(&ls->ls_requestqueue_mutex);
c36258b59   David Teigland   [DLM] block dlm_r...
46
  	list_add_tail(&e->list, &ls->ls_requestqueue);
901359256   David Teigland   [DLM] Update DLM ...
47
  	mutex_unlock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
48
  }
c36258b59   David Teigland   [DLM] block dlm_r...
49
50
51
52
53
54
55
56
57
58
  /*
   * Called by dlm_recoverd to process normal messages saved while recovery was
   * happening.  Normal locking has been enabled before this is called.  dlm_recv
   * upon receiving a message, will wait for all saved messages to be drained
   * here before processing the message it got.  If a new dlm_ls_stop() arrives
   * while we're processing these saved messages, it may block trying to suspend
   * dlm_recv if dlm_recv is waiting for us in dlm_wait_requestqueue.  In that
   * case, we don't abort since locking_stopped is still 0.  If dlm_recv is not
   * waiting for us, then this processing may be aborted due to locking_stopped.
   */
e7fd41792   David Teigland   [DLM] The core of...
59
60
61
  int dlm_process_requestqueue(struct dlm_ls *ls)
  {
  	struct rq_entry *e;
4875647a0   David Teigland   dlm: fixes for no...
62
  	struct dlm_message *ms;
e7fd41792   David Teigland   [DLM] The core of...
63
  	int error = 0;
901359256   David Teigland   [DLM] Update DLM ...
64
  	mutex_lock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
65
66
67
  
  	for (;;) {
  		if (list_empty(&ls->ls_requestqueue)) {
901359256   David Teigland   [DLM] Update DLM ...
68
  			mutex_unlock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
69
70
71
72
  			error = 0;
  			break;
  		}
  		e = list_entry(ls->ls_requestqueue.next, struct rq_entry, list);
901359256   David Teigland   [DLM] Update DLM ...
73
  		mutex_unlock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
74

4875647a0   David Teigland   dlm: fixes for no...
75
76
77
78
79
80
81
  		ms = &e->request;
  
  		log_limit(ls, "dlm_process_requestqueue msg %d from %d "
  			  "lkid %x remid %x result %d seq %u",
  			  ms->m_type, ms->m_header.h_nodeid,
  			  ms->m_lkid, ms->m_remid, ms->m_result,
  			  e->recover_seq);
6d40c4a70   David Teigland   dlm: improve erro...
82
  		dlm_receive_message_saved(ls, &e->request, e->recover_seq);
e7fd41792   David Teigland   [DLM] The core of...
83

901359256   David Teigland   [DLM] Update DLM ...
84
  		mutex_lock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
85
86
87
88
89
  		list_del(&e->list);
  		kfree(e);
  
  		if (dlm_locking_stopped(ls)) {
  			log_debug(ls, "process_requestqueue abort running");
901359256   David Teigland   [DLM] Update DLM ...
90
  			mutex_unlock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
91
92
93
94
95
96
97
98
99
100
101
  			error = -EINTR;
  			break;
  		}
  		schedule();
  	}
  
  	return error;
  }
  
  /*
   * After recovery is done, locking is resumed and dlm_recoverd takes all the
c36258b59   David Teigland   [DLM] block dlm_r...
102
103
104
105
106
107
   * saved requests and processes them as they would have been by dlm_recv.  At
   * the same time, dlm_recv will start receiving new requests from remote nodes.
   * We want to delay dlm_recv processing new requests until dlm_recoverd has
   * finished processing the old saved requests.  We don't check for locking
   * stopped here because dlm_ls_stop won't stop locking until it's suspended us
   * (dlm_recv).
e7fd41792   David Teigland   [DLM] The core of...
108
109
110
111
112
   */
  
  void dlm_wait_requestqueue(struct dlm_ls *ls)
  {
  	for (;;) {
901359256   David Teigland   [DLM] Update DLM ...
113
  		mutex_lock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
114
115
  		if (list_empty(&ls->ls_requestqueue))
  			break;
901359256   David Teigland   [DLM] Update DLM ...
116
  		mutex_unlock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
117
118
  		schedule();
  	}
901359256   David Teigland   [DLM] Update DLM ...
119
  	mutex_unlock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
120
121
122
123
124
  }
  
  static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid)
  {
  	uint32_t type = ms->m_type;
2896ee37c   David Teigland   [DLM] fix add_req...
125
126
127
  	/* the ls is being cleaned up and freed by release_lockspace */
  	if (!ls->ls_count)
  		return 1;
e7fd41792   David Teigland   [DLM] The core of...
128
129
130
131
132
133
134
135
136
137
138
139
140
  	if (dlm_is_removed(ls, nodeid))
  		return 1;
  
  	/* directory operations are always purged because the directory is
  	   always rebuilt during recovery and the lookups resent */
  
  	if (type == DLM_MSG_REMOVE ||
  	    type == DLM_MSG_LOOKUP ||
  	    type == DLM_MSG_LOOKUP_REPLY)
  		return 1;
  
  	if (!dlm_no_directory(ls))
  		return 0;
4875647a0   David Teigland   dlm: fixes for no...
141
  	return 1;
e7fd41792   David Teigland   [DLM] The core of...
142
143
144
145
146
147
  }
  
  void dlm_purge_requestqueue(struct dlm_ls *ls)
  {
  	struct dlm_message *ms;
  	struct rq_entry *e, *safe;
901359256   David Teigland   [DLM] Update DLM ...
148
  	mutex_lock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
149
  	list_for_each_entry_safe(e, safe, &ls->ls_requestqueue, list) {
8b0d8e03f   Al Viro   dlm: use proper C...
150
  		ms =  &e->request;
e7fd41792   David Teigland   [DLM] The core of...
151
152
153
154
155
156
  
  		if (purge_request(ls, ms, e->nodeid)) {
  			list_del(&e->list);
  			kfree(e);
  		}
  	}
901359256   David Teigland   [DLM] Update DLM ...
157
  	mutex_unlock(&ls->ls_requestqueue_mutex);
e7fd41792   David Teigland   [DLM] The core of...
158
  }