12522fe45SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2e7fd4179SDavid Teigland /****************************************************************************** 3e7fd4179SDavid Teigland ******************************************************************************* 4e7fd4179SDavid Teigland ** 5c36258b5SDavid Teigland ** Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved. 6e7fd4179SDavid Teigland ** 7e7fd4179SDavid Teigland ** 8e7fd4179SDavid Teigland ******************************************************************************* 9e7fd4179SDavid Teigland ******************************************************************************/ 10e7fd4179SDavid Teigland 11e7fd4179SDavid Teigland #include "dlm_internal.h" 12e7fd4179SDavid Teigland #include "member.h" 13e7fd4179SDavid Teigland #include "lock.h" 14e7fd4179SDavid Teigland #include "dir.h" 15e7fd4179SDavid Teigland #include "config.h" 16e7fd4179SDavid Teigland #include "requestqueue.h" 1700e99ccdSAlexander Aring #include "util.h" 18e7fd4179SDavid Teigland 19e7fd4179SDavid Teigland struct rq_entry { 20e7fd4179SDavid Teigland struct list_head list; 216d40c4a7SDavid Teigland uint32_t recover_seq; 22e7fd4179SDavid Teigland int nodeid; 238b0d8e03SAl Viro struct dlm_message request; 24e7fd4179SDavid Teigland }; 25e7fd4179SDavid Teigland 26e7fd4179SDavid Teigland /* 27e7fd4179SDavid Teigland * Requests received while the lockspace is in recovery get added to the 28e7fd4179SDavid Teigland * request queue and processed when recovery is complete. This happens when 29e7fd4179SDavid Teigland * the lockspace is suspended on some nodes before it is on others, or the 30e7fd4179SDavid Teigland * lockspace is enabled on some while still suspended on others. 31e7fd4179SDavid Teigland */ 32e7fd4179SDavid Teigland 33*11519351SAlexander Aring void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, 34*11519351SAlexander Aring const struct dlm_message *ms) 35e7fd4179SDavid Teigland { 36e7fd4179SDavid Teigland struct rq_entry *e; 373428785aSAlexander Aring int length = le16_to_cpu(ms->m_header.h_length) - 383428785aSAlexander Aring sizeof(struct dlm_message); 39e7fd4179SDavid Teigland 40573c24c4SDavid Teigland e = kmalloc(sizeof(struct rq_entry) + length, GFP_NOFS); 41e7fd4179SDavid Teigland if (!e) { 42c36258b5SDavid Teigland log_print("dlm_add_requestqueue: out of memory len %d", length); 43c36258b5SDavid Teigland return; 44e7fd4179SDavid Teigland } 45e7fd4179SDavid Teigland 466d40c4a7SDavid Teigland e->recover_seq = ls->ls_recover_seq & 0xFFFFFFFF; 47e7fd4179SDavid Teigland e->nodeid = nodeid; 48f217d7ccSAlexander Aring memcpy(&e->request, ms, sizeof(*ms)); 49f217d7ccSAlexander Aring memcpy(&e->request.m_extra, ms->m_extra, length); 50e7fd4179SDavid Teigland 51164d88abSAlexander Aring atomic_inc(&ls->ls_requestqueue_cnt); 5290135925SDavid Teigland mutex_lock(&ls->ls_requestqueue_mutex); 53e7fd4179SDavid Teigland list_add_tail(&e->list, &ls->ls_requestqueue); 5490135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 55e7fd4179SDavid Teigland } 56e7fd4179SDavid Teigland 57c36258b5SDavid Teigland /* 58c36258b5SDavid Teigland * Called by dlm_recoverd to process normal messages saved while recovery was 59c36258b5SDavid Teigland * happening. Normal locking has been enabled before this is called. dlm_recv 60c36258b5SDavid Teigland * upon receiving a message, will wait for all saved messages to be drained 61c36258b5SDavid Teigland * here before processing the message it got. If a new dlm_ls_stop() arrives 62c36258b5SDavid Teigland * while we're processing these saved messages, it may block trying to suspend 63c36258b5SDavid Teigland * dlm_recv if dlm_recv is waiting for us in dlm_wait_requestqueue. In that 64c36258b5SDavid Teigland * case, we don't abort since locking_stopped is still 0. If dlm_recv is not 65c36258b5SDavid Teigland * waiting for us, then this processing may be aborted due to locking_stopped. 66c36258b5SDavid Teigland */ 67c36258b5SDavid Teigland 68e7fd4179SDavid Teigland int dlm_process_requestqueue(struct dlm_ls *ls) 69e7fd4179SDavid Teigland { 70e7fd4179SDavid Teigland struct rq_entry *e; 714875647aSDavid Teigland struct dlm_message *ms; 72e7fd4179SDavid Teigland int error = 0; 73e7fd4179SDavid Teigland 7490135925SDavid Teigland mutex_lock(&ls->ls_requestqueue_mutex); 75e7fd4179SDavid Teigland 76e7fd4179SDavid Teigland for (;;) { 77e7fd4179SDavid Teigland if (list_empty(&ls->ls_requestqueue)) { 7890135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 79e7fd4179SDavid Teigland error = 0; 80e7fd4179SDavid Teigland break; 81e7fd4179SDavid Teigland } 82e7fd4179SDavid Teigland e = list_entry(ls->ls_requestqueue.next, struct rq_entry, list); 8390135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 84e7fd4179SDavid Teigland 854875647aSDavid Teigland ms = &e->request; 864875647aSDavid Teigland 874875647aSDavid Teigland log_limit(ls, "dlm_process_requestqueue msg %d from %d " 884875647aSDavid Teigland "lkid %x remid %x result %d seq %u", 8900e99ccdSAlexander Aring le32_to_cpu(ms->m_type), 9000e99ccdSAlexander Aring le32_to_cpu(ms->m_header.h_nodeid), 9100e99ccdSAlexander Aring le32_to_cpu(ms->m_lkid), le32_to_cpu(ms->m_remid), 9200e99ccdSAlexander Aring from_dlm_errno(le32_to_cpu(ms->m_result)), 934875647aSDavid Teigland e->recover_seq); 944875647aSDavid Teigland 956d40c4a7SDavid Teigland dlm_receive_message_saved(ls, &e->request, e->recover_seq); 96e7fd4179SDavid Teigland 9790135925SDavid Teigland mutex_lock(&ls->ls_requestqueue_mutex); 98e7fd4179SDavid Teigland list_del(&e->list); 99164d88abSAlexander Aring if (atomic_dec_and_test(&ls->ls_requestqueue_cnt)) 100164d88abSAlexander Aring wake_up(&ls->ls_requestqueue_wait); 101e7fd4179SDavid Teigland kfree(e); 102e7fd4179SDavid Teigland 103e7fd4179SDavid Teigland if (dlm_locking_stopped(ls)) { 104e7fd4179SDavid Teigland log_debug(ls, "process_requestqueue abort running"); 10590135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 106e7fd4179SDavid Teigland error = -EINTR; 107e7fd4179SDavid Teigland break; 108e7fd4179SDavid Teigland } 109e7fd4179SDavid Teigland schedule(); 110e7fd4179SDavid Teigland } 111e7fd4179SDavid Teigland 112e7fd4179SDavid Teigland return error; 113e7fd4179SDavid Teigland } 114e7fd4179SDavid Teigland 115e7fd4179SDavid Teigland /* 116e7fd4179SDavid Teigland * After recovery is done, locking is resumed and dlm_recoverd takes all the 117c36258b5SDavid Teigland * saved requests and processes them as they would have been by dlm_recv. At 118c36258b5SDavid Teigland * the same time, dlm_recv will start receiving new requests from remote nodes. 119c36258b5SDavid Teigland * We want to delay dlm_recv processing new requests until dlm_recoverd has 120c36258b5SDavid Teigland * finished processing the old saved requests. We don't check for locking 121c36258b5SDavid Teigland * stopped here because dlm_ls_stop won't stop locking until it's suspended us 122c36258b5SDavid Teigland * (dlm_recv). 123e7fd4179SDavid Teigland */ 124e7fd4179SDavid Teigland 125e7fd4179SDavid Teigland void dlm_wait_requestqueue(struct dlm_ls *ls) 126e7fd4179SDavid Teigland { 127164d88abSAlexander Aring wait_event(ls->ls_requestqueue_wait, 128164d88abSAlexander Aring atomic_read(&ls->ls_requestqueue_cnt) == 0); 129e7fd4179SDavid Teigland } 130e7fd4179SDavid Teigland 131e7fd4179SDavid Teigland static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid) 132e7fd4179SDavid Teigland { 13300e99ccdSAlexander Aring __le32 type = ms->m_type; 134e7fd4179SDavid Teigland 1352896ee37SDavid Teigland /* the ls is being cleaned up and freed by release_lockspace */ 1363cb5977cSAlexander Aring if (!atomic_read(&ls->ls_count)) 1372896ee37SDavid Teigland return 1; 1382896ee37SDavid Teigland 139e7fd4179SDavid Teigland if (dlm_is_removed(ls, nodeid)) 140e7fd4179SDavid Teigland return 1; 141e7fd4179SDavid Teigland 142e7fd4179SDavid Teigland /* directory operations are always purged because the directory is 143e7fd4179SDavid Teigland always rebuilt during recovery and the lookups resent */ 144e7fd4179SDavid Teigland 14500e99ccdSAlexander Aring if (type == cpu_to_le32(DLM_MSG_REMOVE) || 14600e99ccdSAlexander Aring type == cpu_to_le32(DLM_MSG_LOOKUP) || 14700e99ccdSAlexander Aring type == cpu_to_le32(DLM_MSG_LOOKUP_REPLY)) 148e7fd4179SDavid Teigland return 1; 149e7fd4179SDavid Teigland 150e7fd4179SDavid Teigland if (!dlm_no_directory(ls)) 151e7fd4179SDavid Teigland return 0; 152e7fd4179SDavid Teigland 153e7fd4179SDavid Teigland return 1; 154e7fd4179SDavid Teigland } 155e7fd4179SDavid Teigland 156e7fd4179SDavid Teigland void dlm_purge_requestqueue(struct dlm_ls *ls) 157e7fd4179SDavid Teigland { 158e7fd4179SDavid Teigland struct dlm_message *ms; 159e7fd4179SDavid Teigland struct rq_entry *e, *safe; 160e7fd4179SDavid Teigland 16190135925SDavid Teigland mutex_lock(&ls->ls_requestqueue_mutex); 162e7fd4179SDavid Teigland list_for_each_entry_safe(e, safe, &ls->ls_requestqueue, list) { 1638b0d8e03SAl Viro ms = &e->request; 164e7fd4179SDavid Teigland 165e7fd4179SDavid Teigland if (purge_request(ls, ms, e->nodeid)) { 166e7fd4179SDavid Teigland list_del(&e->list); 167164d88abSAlexander Aring if (atomic_dec_and_test(&ls->ls_requestqueue_cnt)) 168164d88abSAlexander Aring wake_up(&ls->ls_requestqueue_wait); 169e7fd4179SDavid Teigland kfree(e); 170e7fd4179SDavid Teigland } 171e7fd4179SDavid Teigland } 17290135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 173e7fd4179SDavid Teigland } 174e7fd4179SDavid Teigland 175