Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) *******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) **  Copyright (C) 2005-2007 Red Hat, Inc.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) *******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) ******************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "dlm_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "member.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "lock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "dir.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "config.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "requestqueue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) struct rq_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	uint32_t recover_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	int nodeid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct dlm_message request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * Requests received while the lockspace is in recovery get added to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * request queue and processed when recovery is complete.  This happens when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * the lockspace is suspended on some nodes before it is on others, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * lockspace is enabled on some while still suspended on others.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_message *ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct rq_entry *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	int length = ms->m_header.h_length - sizeof(struct dlm_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	e = kmalloc(sizeof(struct rq_entry) + length, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (!e) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		log_print("dlm_add_requestqueue: out of memory len %d", length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	e->recover_seq = ls->ls_recover_seq & 0xFFFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	e->nodeid = nodeid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	memcpy(&e->request, ms, ms->m_header.h_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	mutex_lock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	list_add_tail(&e->list, &ls->ls_requestqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	mutex_unlock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * Called by dlm_recoverd to process normal messages saved while recovery was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * happening.  Normal locking has been enabled before this is called.  dlm_recv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * upon receiving a message, will wait for all saved messages to be drained
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * here before processing the message it got.  If a new dlm_ls_stop() arrives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * while we're processing these saved messages, it may block trying to suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * dlm_recv if dlm_recv is waiting for us in dlm_wait_requestqueue.  In that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * case, we don't abort since locking_stopped is still 0.  If dlm_recv is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * waiting for us, then this processing may be aborted due to locking_stopped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) int dlm_process_requestqueue(struct dlm_ls *ls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct rq_entry *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct dlm_message *ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	mutex_lock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		if (list_empty(&ls->ls_requestqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			mutex_unlock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		e = list_entry(ls->ls_requestqueue.next, struct rq_entry, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		mutex_unlock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		ms = &e->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		log_limit(ls, "dlm_process_requestqueue msg %d from %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			  "lkid %x remid %x result %d seq %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			  ms->m_type, ms->m_header.h_nodeid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			  ms->m_lkid, ms->m_remid, ms->m_result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			  e->recover_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		dlm_receive_message_saved(ls, &e->request, e->recover_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		mutex_lock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		list_del(&e->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		kfree(e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (dlm_locking_stopped(ls)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			log_debug(ls, "process_requestqueue abort running");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			mutex_unlock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			error = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * After recovery is done, locking is resumed and dlm_recoverd takes all the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * saved requests and processes them as they would have been by dlm_recv.  At
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * the same time, dlm_recv will start receiving new requests from remote nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * We want to delay dlm_recv processing new requests until dlm_recoverd has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * finished processing the old saved requests.  We don't check for locking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * stopped here because dlm_ls_stop won't stop locking until it's suspended us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * (dlm_recv).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) void dlm_wait_requestqueue(struct dlm_ls *ls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		mutex_lock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (list_empty(&ls->ls_requestqueue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		mutex_unlock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	mutex_unlock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	uint32_t type = ms->m_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* the ls is being cleaned up and freed by release_lockspace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (!ls->ls_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (dlm_is_removed(ls, nodeid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	/* directory operations are always purged because the directory is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	   always rebuilt during recovery and the lookups resent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (type == DLM_MSG_REMOVE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	    type == DLM_MSG_LOOKUP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	    type == DLM_MSG_LOOKUP_REPLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (!dlm_no_directory(ls))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) void dlm_purge_requestqueue(struct dlm_ls *ls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct dlm_message *ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct rq_entry *e, *safe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	mutex_lock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	list_for_each_entry_safe(e, safe, &ls->ls_requestqueue, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		ms =  &e->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		if (purge_request(ls, ms, e->nodeid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			list_del(&e->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			kfree(e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	mutex_unlock(&ls->ls_requestqueue_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)