1*2522fe45SThomas 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" 17e7fd4179SDavid Teigland 18e7fd4179SDavid Teigland struct rq_entry { 19e7fd4179SDavid Teigland struct list_head list; 206d40c4a7SDavid Teigland uint32_t recover_seq; 21e7fd4179SDavid Teigland int nodeid; 228b0d8e03SAl Viro struct dlm_message request; 23e7fd4179SDavid Teigland }; 24e7fd4179SDavid Teigland 25e7fd4179SDavid Teigland /* 26e7fd4179SDavid Teigland * Requests received while the lockspace is in recovery get added to the 27e7fd4179SDavid Teigland * request queue and processed when recovery is complete. This happens when 28e7fd4179SDavid Teigland * the lockspace is suspended on some nodes before it is on others, or the 29e7fd4179SDavid Teigland * lockspace is enabled on some while still suspended on others. 30e7fd4179SDavid Teigland */ 31e7fd4179SDavid Teigland 328b0d8e03SAl Viro void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_message *ms) 33e7fd4179SDavid Teigland { 34e7fd4179SDavid Teigland struct rq_entry *e; 358b0d8e03SAl Viro int length = ms->m_header.h_length - sizeof(struct dlm_message); 36e7fd4179SDavid Teigland 37573c24c4SDavid Teigland e = kmalloc(sizeof(struct rq_entry) + length, GFP_NOFS); 38e7fd4179SDavid Teigland if (!e) { 39c36258b5SDavid Teigland log_print("dlm_add_requestqueue: out of memory len %d", length); 40c36258b5SDavid Teigland return; 41e7fd4179SDavid Teigland } 42e7fd4179SDavid Teigland 436d40c4a7SDavid Teigland e->recover_seq = ls->ls_recover_seq & 0xFFFFFFFF; 44e7fd4179SDavid Teigland e->nodeid = nodeid; 458b0d8e03SAl Viro memcpy(&e->request, ms, ms->m_header.h_length); 46e7fd4179SDavid Teigland 4790135925SDavid Teigland mutex_lock(&ls->ls_requestqueue_mutex); 48e7fd4179SDavid Teigland list_add_tail(&e->list, &ls->ls_requestqueue); 4990135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 50e7fd4179SDavid Teigland } 51e7fd4179SDavid Teigland 52c36258b5SDavid Teigland /* 53c36258b5SDavid Teigland * Called by dlm_recoverd to process normal messages saved while recovery was 54c36258b5SDavid Teigland * happening. Normal locking has been enabled before this is called. dlm_recv 55c36258b5SDavid Teigland * upon receiving a message, will wait for all saved messages to be drained 56c36258b5SDavid Teigland * here before processing the message it got. If a new dlm_ls_stop() arrives 57c36258b5SDavid Teigland * while we're processing these saved messages, it may block trying to suspend 58c36258b5SDavid Teigland * dlm_recv if dlm_recv is waiting for us in dlm_wait_requestqueue. In that 59c36258b5SDavid Teigland * case, we don't abort since locking_stopped is still 0. If dlm_recv is not 60c36258b5SDavid Teigland * waiting for us, then this processing may be aborted due to locking_stopped. 61c36258b5SDavid Teigland */ 62c36258b5SDavid Teigland 63e7fd4179SDavid Teigland int dlm_process_requestqueue(struct dlm_ls *ls) 64e7fd4179SDavid Teigland { 65e7fd4179SDavid Teigland struct rq_entry *e; 664875647aSDavid Teigland struct dlm_message *ms; 67e7fd4179SDavid Teigland int error = 0; 68e7fd4179SDavid Teigland 6990135925SDavid Teigland mutex_lock(&ls->ls_requestqueue_mutex); 70e7fd4179SDavid Teigland 71e7fd4179SDavid Teigland for (;;) { 72e7fd4179SDavid Teigland if (list_empty(&ls->ls_requestqueue)) { 7390135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 74e7fd4179SDavid Teigland error = 0; 75e7fd4179SDavid Teigland break; 76e7fd4179SDavid Teigland } 77e7fd4179SDavid Teigland e = list_entry(ls->ls_requestqueue.next, struct rq_entry, list); 7890135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 79e7fd4179SDavid Teigland 804875647aSDavid Teigland ms = &e->request; 814875647aSDavid Teigland 824875647aSDavid Teigland log_limit(ls, "dlm_process_requestqueue msg %d from %d " 834875647aSDavid Teigland "lkid %x remid %x result %d seq %u", 844875647aSDavid Teigland ms->m_type, ms->m_header.h_nodeid, 854875647aSDavid Teigland ms->m_lkid, ms->m_remid, ms->m_result, 864875647aSDavid Teigland e->recover_seq); 874875647aSDavid Teigland 886d40c4a7SDavid Teigland dlm_receive_message_saved(ls, &e->request, e->recover_seq); 89e7fd4179SDavid Teigland 9090135925SDavid Teigland mutex_lock(&ls->ls_requestqueue_mutex); 91e7fd4179SDavid Teigland list_del(&e->list); 92e7fd4179SDavid Teigland kfree(e); 93e7fd4179SDavid Teigland 94e7fd4179SDavid Teigland if (dlm_locking_stopped(ls)) { 95e7fd4179SDavid Teigland log_debug(ls, "process_requestqueue abort running"); 9690135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 97e7fd4179SDavid Teigland error = -EINTR; 98e7fd4179SDavid Teigland break; 99e7fd4179SDavid Teigland } 100e7fd4179SDavid Teigland schedule(); 101e7fd4179SDavid Teigland } 102e7fd4179SDavid Teigland 103e7fd4179SDavid Teigland return error; 104e7fd4179SDavid Teigland } 105e7fd4179SDavid Teigland 106e7fd4179SDavid Teigland /* 107e7fd4179SDavid Teigland * After recovery is done, locking is resumed and dlm_recoverd takes all the 108c36258b5SDavid Teigland * saved requests and processes them as they would have been by dlm_recv. At 109c36258b5SDavid Teigland * the same time, dlm_recv will start receiving new requests from remote nodes. 110c36258b5SDavid Teigland * We want to delay dlm_recv processing new requests until dlm_recoverd has 111c36258b5SDavid Teigland * finished processing the old saved requests. We don't check for locking 112c36258b5SDavid Teigland * stopped here because dlm_ls_stop won't stop locking until it's suspended us 113c36258b5SDavid Teigland * (dlm_recv). 114e7fd4179SDavid Teigland */ 115e7fd4179SDavid Teigland 116e7fd4179SDavid Teigland void dlm_wait_requestqueue(struct dlm_ls *ls) 117e7fd4179SDavid Teigland { 118e7fd4179SDavid Teigland for (;;) { 11990135925SDavid Teigland mutex_lock(&ls->ls_requestqueue_mutex); 120e7fd4179SDavid Teigland if (list_empty(&ls->ls_requestqueue)) 121e7fd4179SDavid Teigland break; 12290135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 123e7fd4179SDavid Teigland schedule(); 124e7fd4179SDavid Teigland } 12590135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 126e7fd4179SDavid Teigland } 127e7fd4179SDavid Teigland 128e7fd4179SDavid Teigland static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid) 129e7fd4179SDavid Teigland { 130e7fd4179SDavid Teigland uint32_t type = ms->m_type; 131e7fd4179SDavid Teigland 1322896ee37SDavid Teigland /* the ls is being cleaned up and freed by release_lockspace */ 1332896ee37SDavid Teigland if (!ls->ls_count) 1342896ee37SDavid Teigland return 1; 1352896ee37SDavid Teigland 136e7fd4179SDavid Teigland if (dlm_is_removed(ls, nodeid)) 137e7fd4179SDavid Teigland return 1; 138e7fd4179SDavid Teigland 139e7fd4179SDavid Teigland /* directory operations are always purged because the directory is 140e7fd4179SDavid Teigland always rebuilt during recovery and the lookups resent */ 141e7fd4179SDavid Teigland 142e7fd4179SDavid Teigland if (type == DLM_MSG_REMOVE || 143e7fd4179SDavid Teigland type == DLM_MSG_LOOKUP || 144e7fd4179SDavid Teigland type == DLM_MSG_LOOKUP_REPLY) 145e7fd4179SDavid Teigland return 1; 146e7fd4179SDavid Teigland 147e7fd4179SDavid Teigland if (!dlm_no_directory(ls)) 148e7fd4179SDavid Teigland return 0; 149e7fd4179SDavid Teigland 150e7fd4179SDavid Teigland return 1; 151e7fd4179SDavid Teigland } 152e7fd4179SDavid Teigland 153e7fd4179SDavid Teigland void dlm_purge_requestqueue(struct dlm_ls *ls) 154e7fd4179SDavid Teigland { 155e7fd4179SDavid Teigland struct dlm_message *ms; 156e7fd4179SDavid Teigland struct rq_entry *e, *safe; 157e7fd4179SDavid Teigland 15890135925SDavid Teigland mutex_lock(&ls->ls_requestqueue_mutex); 159e7fd4179SDavid Teigland list_for_each_entry_safe(e, safe, &ls->ls_requestqueue, list) { 1608b0d8e03SAl Viro ms = &e->request; 161e7fd4179SDavid Teigland 162e7fd4179SDavid Teigland if (purge_request(ls, ms, e->nodeid)) { 163e7fd4179SDavid Teigland list_del(&e->list); 164e7fd4179SDavid Teigland kfree(e); 165e7fd4179SDavid Teigland } 166e7fd4179SDavid Teigland } 16790135925SDavid Teigland mutex_unlock(&ls->ls_requestqueue_mutex); 168e7fd4179SDavid Teigland } 169e7fd4179SDavid Teigland 170