⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 recover.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************************************************************************************************  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.**  Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.****  This copyrighted material is made available to anyone wishing to use,**  modify, copy, or redistribute it subject to the terms and conditions**  of the GNU General Public License v.2.***************************************************************************************************************************************************************/#include "dlm_internal.h"#include "lockspace.h"#include "dir.h"#include "config.h"#include "ast.h"#include "memory.h"#include "rcom.h"#include "lock.h"#include "lowcomms.h"#include "member.h"#include "recover.h"/* * Recovery waiting routines: these functions wait for a particular reply from * a remote node, or for the remote node to report a certain status.  They need * to abort if the lockspace is stopped indicating a node has failed (perhaps * the one being waited for). *//* * Wait until given function returns non-zero or lockspace is stopped * (LS_RECOVERY_STOP set due to failure of a node in ls_nodes).  When another * function thinks it could have completed the waited-on task, they should wake * up ls_wait_general to get an immediate response rather than waiting for the * timer to detect the result.  A timer wakes us up periodically while waiting * to see if we should abort due to a node failure.  This should only be called * by the dlm_recoverd thread. */static void dlm_wait_timer_fn(unsigned long data){	struct dlm_ls *ls = (struct dlm_ls *) data;	mod_timer(&ls->ls_timer, jiffies + (dlm_config.ci_recover_timer * HZ));	wake_up(&ls->ls_wait_general);}int dlm_wait_function(struct dlm_ls *ls, int (*testfn) (struct dlm_ls *ls)){	int error = 0;	init_timer(&ls->ls_timer);	ls->ls_timer.function = dlm_wait_timer_fn;	ls->ls_timer.data = (long) ls;	ls->ls_timer.expires = jiffies + (dlm_config.ci_recover_timer * HZ);	add_timer(&ls->ls_timer);	wait_event(ls->ls_wait_general, testfn(ls) || dlm_recovery_stopped(ls));	del_timer_sync(&ls->ls_timer);	if (dlm_recovery_stopped(ls)) {		log_debug(ls, "dlm_wait_function aborted");		error = -EINTR;	}	return error;}/* * An efficient way for all nodes to wait for all others to have a certain * status.  The node with the lowest nodeid polls all the others for their * status (wait_status_all) and all the others poll the node with the low id * for its accumulated result (wait_status_low).  When all nodes have set * status flag X, then status flag X_ALL will be set on the low nodeid. */uint32_t dlm_recover_status(struct dlm_ls *ls){	uint32_t status;	spin_lock(&ls->ls_recover_lock);	status = ls->ls_recover_status;	spin_unlock(&ls->ls_recover_lock);	return status;}void dlm_set_recover_status(struct dlm_ls *ls, uint32_t status){	spin_lock(&ls->ls_recover_lock);	ls->ls_recover_status |= status;	spin_unlock(&ls->ls_recover_lock);}static int wait_status_all(struct dlm_ls *ls, uint32_t wait_status){	struct dlm_rcom *rc = (struct dlm_rcom *) ls->ls_recover_buf;	struct dlm_member *memb;	int error = 0, delay;	list_for_each_entry(memb, &ls->ls_nodes, list) {		delay = 0;		for (;;) {			if (dlm_recovery_stopped(ls)) {				error = -EINTR;				goto out;			}			error = dlm_rcom_status(ls, memb->nodeid);			if (error)				goto out;			if (rc->rc_result & wait_status)				break;			if (delay < 1000)				delay += 20;			msleep(delay);		}	} out:	return error;}static int wait_status_low(struct dlm_ls *ls, uint32_t wait_status){	struct dlm_rcom *rc = (struct dlm_rcom *) ls->ls_recover_buf;	int error = 0, delay = 0, nodeid = ls->ls_low_nodeid;	for (;;) {		if (dlm_recovery_stopped(ls)) {			error = -EINTR;			goto out;		}		error = dlm_rcom_status(ls, nodeid);		if (error)			break;		if (rc->rc_result & wait_status)			break;		if (delay < 1000)			delay += 20;		msleep(delay);	} out:	return error;}static int wait_status(struct dlm_ls *ls, uint32_t status){	uint32_t status_all = status << 1;	int error;	if (ls->ls_low_nodeid == dlm_our_nodeid()) {		error = wait_status_all(ls, status);		if (!error)			dlm_set_recover_status(ls, status_all);	} else		error = wait_status_low(ls, status_all);	return error;}int dlm_recover_members_wait(struct dlm_ls *ls){	return wait_status(ls, DLM_RS_NODES);}int dlm_recover_directory_wait(struct dlm_ls *ls){	return wait_status(ls, DLM_RS_DIR);}int dlm_recover_locks_wait(struct dlm_ls *ls){	return wait_status(ls, DLM_RS_LOCKS);}int dlm_recover_done_wait(struct dlm_ls *ls){	return wait_status(ls, DLM_RS_DONE);}/* * The recover_list contains all the rsb's for which we've requested the new * master nodeid.  As replies are returned from the resource directories the * rsb's are removed from the list.  When the list is empty we're done. * * The recover_list is later similarly used for all rsb's for which we've sent * new lkb's and need to receive new corresponding lkid's. * * We use the address of the rsb struct as a simple local identifier for the * rsb so we can match an rcom reply with the rsb it was sent for. */static int recover_list_empty(struct dlm_ls *ls){	int empty;	spin_lock(&ls->ls_recover_list_lock);	empty = list_empty(&ls->ls_recover_list);	spin_unlock(&ls->ls_recover_list_lock);	return empty;}static void recover_list_add(struct dlm_rsb *r){	struct dlm_ls *ls = r->res_ls;	spin_lock(&ls->ls_recover_list_lock);	if (list_empty(&r->res_recover_list)) {		list_add_tail(&r->res_recover_list, &ls->ls_recover_list);		ls->ls_recover_list_count++;		dlm_hold_rsb(r);	}	spin_unlock(&ls->ls_recover_list_lock);}static void recover_list_del(struct dlm_rsb *r){	struct dlm_ls *ls = r->res_ls;	spin_lock(&ls->ls_recover_list_lock);	list_del_init(&r->res_recover_list);	ls->ls_recover_list_count--;	spin_unlock(&ls->ls_recover_list_lock);	dlm_put_rsb(r);}static struct dlm_rsb *recover_list_find(struct dlm_ls *ls, uint64_t id){	struct dlm_rsb *r = NULL;	spin_lock(&ls->ls_recover_list_lock);	list_for_each_entry(r, &ls->ls_recover_list, res_recover_list) {		if (id == (unsigned long) r)			goto out;	}	r = NULL; out:	spin_unlock(&ls->ls_recover_list_lock);	return r;}static void recover_list_clear(struct dlm_ls *ls){	struct dlm_rsb *r, *s;	spin_lock(&ls->ls_recover_list_lock);	list_for_each_entry_safe(r, s, &ls->ls_recover_list, res_recover_list) {		list_del_init(&r->res_recover_list);		r->res_recover_locks_count = 0;		dlm_put_rsb(r);		ls->ls_recover_list_count--;	}	if (ls->ls_recover_list_count != 0) {		log_error(ls, "warning: recover_list_count %d",			  ls->ls_recover_list_count);		ls->ls_recover_list_count = 0;	}	spin_unlock(&ls->ls_recover_list_lock);}/* Master recovery: find new master node for rsb's that were   mastered on nodes that have been removed.   dlm_recover_masters   recover_master   dlm_send_rcom_lookup            ->  receive_rcom_lookup                                       dlm_dir_lookup   receive_rcom_lookup_reply       <-   dlm_recover_master_reply   set_new_master   set_master_lkbs   set_lock_master*//* * Set the lock master for all LKBs in a lock queue * If we are the new master of the rsb, we may have received new * MSTCPY locks from other nodes already which we need to ignore * when setting the new nodeid. */static void set_lock_master(struct list_head *queue, int nodeid){	struct dlm_lkb *lkb;	list_for_each_entry(lkb, queue, lkb_statequeue)		if (!(lkb->lkb_flags & DLM_IFL_MSTCPY))			lkb->lkb_nodeid = nodeid;}static void set_master_lkbs(struct dlm_rsb *r){	set_lock_master(&r->res_grantqueue, r->res_nodeid);	set_lock_master(&r->res_convertqueue, r->res_nodeid);	set_lock_master(&r->res_waitqueue, r->res_nodeid);}/* * Propogate the new master nodeid to locks * The NEW_MASTER flag tells dlm_recover_locks() which rsb's to consider. * The NEW_MASTER2 flag tells recover_lvb() and set_locks_purged() which * rsb's to consider. */static void set_new_master(struct dlm_rsb *r, int nodeid){	lock_rsb(r);	r->res_nodeid = nodeid;	set_master_lkbs(r);	rsb_set_flag(r, RSB_NEW_MASTER);	rsb_set_flag(r, RSB_NEW_MASTER2);	unlock_rsb(r);}/* * We do async lookups on rsb's that need new masters.  The rsb's * waiting for a lookup reply are kept on the recover_list. */static int recover_master(struct dlm_rsb *r){	struct dlm_ls *ls = r->res_ls;	int error, dir_nodeid, ret_nodeid, our_nodeid = dlm_our_nodeid();	dir_nodeid = dlm_dir_nodeid(r);	if (dir_nodeid == our_nodeid) {		error = dlm_dir_lookup(ls, our_nodeid, r->res_name,				       r->res_length, &ret_nodeid);		if (error)			log_error(ls, "recover dir lookup error %d", error);		if (ret_nodeid == our_nodeid)			ret_nodeid = 0;		set_new_master(r, ret_nodeid);	} else {		recover_list_add(r);		error = dlm_send_rcom_lookup(r, dir_nodeid);	}	return error;}/* * When not using a directory, most resource names will hash to a new static * master nodeid and the resource will need to be remastered. */static int recover_master_static(struct dlm_rsb *r){	int master = dlm_dir_nodeid(r);	if (master == dlm_our_nodeid())		master = 0;	if (r->res_nodeid != master) {		if (is_master(r))			dlm_purge_mstcpy_locks(r);		set_new_master(r, master);		return 1;	}	return 0;}/* * Go through local root resources and for each rsb which has a master which * has departed, get the new master nodeid from the directory.  The dir will * assign mastery to the first node to look up the new master.  That means * we'll discover in this lookup if we're the new master of any rsb's. * * We fire off all the dir lookup requests individually and asynchronously to * the correct dir node. */int dlm_recover_masters(struct dlm_ls *ls){	struct dlm_rsb *r;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -