18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/****************************************************************************** 38c2ecf20Sopenharmony_ci******************************************************************************* 48c2ecf20Sopenharmony_ci** 58c2ecf20Sopenharmony_ci** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 68c2ecf20Sopenharmony_ci** Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. 78c2ecf20Sopenharmony_ci** 88c2ecf20Sopenharmony_ci** 98c2ecf20Sopenharmony_ci******************************************************************************* 108c2ecf20Sopenharmony_ci******************************************************************************/ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef __DLM_INTERNAL_DOT_H__ 138c2ecf20Sopenharmony_ci#define __DLM_INTERNAL_DOT_H__ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* 168c2ecf20Sopenharmony_ci * This is the main header file to be included in each DLM source file. 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <linux/slab.h> 208c2ecf20Sopenharmony_ci#include <linux/sched.h> 218c2ecf20Sopenharmony_ci#include <linux/types.h> 228c2ecf20Sopenharmony_ci#include <linux/ctype.h> 238c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 248c2ecf20Sopenharmony_ci#include <linux/vmalloc.h> 258c2ecf20Sopenharmony_ci#include <linux/list.h> 268c2ecf20Sopenharmony_ci#include <linux/errno.h> 278c2ecf20Sopenharmony_ci#include <linux/random.h> 288c2ecf20Sopenharmony_ci#include <linux/delay.h> 298c2ecf20Sopenharmony_ci#include <linux/socket.h> 308c2ecf20Sopenharmony_ci#include <linux/kthread.h> 318c2ecf20Sopenharmony_ci#include <linux/kobject.h> 328c2ecf20Sopenharmony_ci#include <linux/kref.h> 338c2ecf20Sopenharmony_ci#include <linux/kernel.h> 348c2ecf20Sopenharmony_ci#include <linux/jhash.h> 358c2ecf20Sopenharmony_ci#include <linux/miscdevice.h> 368c2ecf20Sopenharmony_ci#include <linux/mutex.h> 378c2ecf20Sopenharmony_ci#include <linux/idr.h> 388c2ecf20Sopenharmony_ci#include <linux/ratelimit.h> 398c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#include <linux/dlm.h> 428c2ecf20Sopenharmony_ci#include "config.h" 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* Size of the temp buffer midcomms allocates on the stack. 458c2ecf20Sopenharmony_ci We try to make this large enough so most messages fit. 468c2ecf20Sopenharmony_ci FIXME: should sctp make this unnecessary? */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define DLM_INBUF_LEN 148 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_cistruct dlm_ls; 518c2ecf20Sopenharmony_cistruct dlm_lkb; 528c2ecf20Sopenharmony_cistruct dlm_rsb; 538c2ecf20Sopenharmony_cistruct dlm_member; 548c2ecf20Sopenharmony_cistruct dlm_rsbtable; 558c2ecf20Sopenharmony_cistruct dlm_recover; 568c2ecf20Sopenharmony_cistruct dlm_header; 578c2ecf20Sopenharmony_cistruct dlm_message; 588c2ecf20Sopenharmony_cistruct dlm_rcom; 598c2ecf20Sopenharmony_cistruct dlm_mhandle; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define log_print(fmt, args...) \ 628c2ecf20Sopenharmony_ci printk(KERN_ERR "dlm: "fmt"\n" , ##args) 638c2ecf20Sopenharmony_ci#define log_error(ls, fmt, args...) \ 648c2ecf20Sopenharmony_ci printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args) 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci#define log_rinfo(ls, fmt, args...) \ 678c2ecf20Sopenharmony_cido { \ 688c2ecf20Sopenharmony_ci if (dlm_config.ci_log_info) \ 698c2ecf20Sopenharmony_ci printk(KERN_INFO "dlm: %s: " fmt "\n", \ 708c2ecf20Sopenharmony_ci (ls)->ls_name, ##args); \ 718c2ecf20Sopenharmony_ci else if (dlm_config.ci_log_debug) \ 728c2ecf20Sopenharmony_ci printk(KERN_DEBUG "dlm: %s: " fmt "\n", \ 738c2ecf20Sopenharmony_ci (ls)->ls_name , ##args); \ 748c2ecf20Sopenharmony_ci} while (0) 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define log_debug(ls, fmt, args...) \ 778c2ecf20Sopenharmony_cido { \ 788c2ecf20Sopenharmony_ci if (dlm_config.ci_log_debug) \ 798c2ecf20Sopenharmony_ci printk(KERN_DEBUG "dlm: %s: " fmt "\n", \ 808c2ecf20Sopenharmony_ci (ls)->ls_name , ##args); \ 818c2ecf20Sopenharmony_ci} while (0) 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#define log_limit(ls, fmt, args...) \ 848c2ecf20Sopenharmony_cido { \ 858c2ecf20Sopenharmony_ci if (dlm_config.ci_log_debug) \ 868c2ecf20Sopenharmony_ci printk_ratelimited(KERN_DEBUG "dlm: %s: " fmt "\n", \ 878c2ecf20Sopenharmony_ci (ls)->ls_name , ##args); \ 888c2ecf20Sopenharmony_ci} while (0) 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#define DLM_ASSERT(x, do) \ 918c2ecf20Sopenharmony_ci{ \ 928c2ecf20Sopenharmony_ci if (!(x)) \ 938c2ecf20Sopenharmony_ci { \ 948c2ecf20Sopenharmony_ci printk(KERN_ERR "\nDLM: Assertion failed on line %d of file %s\n" \ 958c2ecf20Sopenharmony_ci "DLM: assertion: \"%s\"\n" \ 968c2ecf20Sopenharmony_ci "DLM: time = %lu\n", \ 978c2ecf20Sopenharmony_ci __LINE__, __FILE__, #x, jiffies); \ 988c2ecf20Sopenharmony_ci {do} \ 998c2ecf20Sopenharmony_ci printk("\n"); \ 1008c2ecf20Sopenharmony_ci panic("DLM: Record message above and reboot.\n"); \ 1018c2ecf20Sopenharmony_ci } \ 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#define DLM_RTF_SHRINK 0x00000001 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistruct dlm_rsbtable { 1088c2ecf20Sopenharmony_ci struct rb_root keep; 1098c2ecf20Sopenharmony_ci struct rb_root toss; 1108c2ecf20Sopenharmony_ci spinlock_t lock; 1118c2ecf20Sopenharmony_ci uint32_t flags; 1128c2ecf20Sopenharmony_ci}; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* 1168c2ecf20Sopenharmony_ci * Lockspace member (per node in a ls) 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistruct dlm_member { 1208c2ecf20Sopenharmony_ci struct list_head list; 1218c2ecf20Sopenharmony_ci int nodeid; 1228c2ecf20Sopenharmony_ci int weight; 1238c2ecf20Sopenharmony_ci int slot; 1248c2ecf20Sopenharmony_ci int slot_prev; 1258c2ecf20Sopenharmony_ci int comm_seq; 1268c2ecf20Sopenharmony_ci uint32_t generation; 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci/* 1308c2ecf20Sopenharmony_ci * Save and manage recovery state for a lockspace. 1318c2ecf20Sopenharmony_ci */ 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistruct dlm_recover { 1348c2ecf20Sopenharmony_ci struct list_head list; 1358c2ecf20Sopenharmony_ci struct dlm_config_node *nodes; 1368c2ecf20Sopenharmony_ci int nodes_count; 1378c2ecf20Sopenharmony_ci uint64_t seq; 1388c2ecf20Sopenharmony_ci}; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci/* 1418c2ecf20Sopenharmony_ci * Pass input args to second stage locking function. 1428c2ecf20Sopenharmony_ci */ 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistruct dlm_args { 1458c2ecf20Sopenharmony_ci uint32_t flags; 1468c2ecf20Sopenharmony_ci void (*astfn) (void *astparam); 1478c2ecf20Sopenharmony_ci void *astparam; 1488c2ecf20Sopenharmony_ci void (*bastfn) (void *astparam, int mode); 1498c2ecf20Sopenharmony_ci int mode; 1508c2ecf20Sopenharmony_ci struct dlm_lksb *lksb; 1518c2ecf20Sopenharmony_ci unsigned long timeout; 1528c2ecf20Sopenharmony_ci}; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci/* 1568c2ecf20Sopenharmony_ci * Lock block 1578c2ecf20Sopenharmony_ci * 1588c2ecf20Sopenharmony_ci * A lock can be one of three types: 1598c2ecf20Sopenharmony_ci * 1608c2ecf20Sopenharmony_ci * local copy lock is mastered locally 1618c2ecf20Sopenharmony_ci * (lkb_nodeid is zero and DLM_LKF_MSTCPY is not set) 1628c2ecf20Sopenharmony_ci * process copy lock is mastered on a remote node 1638c2ecf20Sopenharmony_ci * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is not set) 1648c2ecf20Sopenharmony_ci * master copy master node's copy of a lock owned by remote node 1658c2ecf20Sopenharmony_ci * (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is set) 1668c2ecf20Sopenharmony_ci * 1678c2ecf20Sopenharmony_ci * lkb_exflags: a copy of the most recent flags arg provided to dlm_lock or 1688c2ecf20Sopenharmony_ci * dlm_unlock. The dlm does not modify these or use any private flags in 1698c2ecf20Sopenharmony_ci * this field; it only contains DLM_LKF_ flags from dlm.h. These flags 1708c2ecf20Sopenharmony_ci * are sent as-is to the remote master when the lock is remote. 1718c2ecf20Sopenharmony_ci * 1728c2ecf20Sopenharmony_ci * lkb_flags: internal dlm flags (DLM_IFL_ prefix) from dlm_internal.h. 1738c2ecf20Sopenharmony_ci * Some internal flags are shared between the master and process nodes; 1748c2ecf20Sopenharmony_ci * these shared flags are kept in the lower two bytes. One of these 1758c2ecf20Sopenharmony_ci * flags set on the master copy will be propagated to the process copy 1768c2ecf20Sopenharmony_ci * and v.v. Other internal flags are private to the master or process 1778c2ecf20Sopenharmony_ci * node (e.g. DLM_IFL_MSTCPY). These are kept in the high two bytes. 1788c2ecf20Sopenharmony_ci * 1798c2ecf20Sopenharmony_ci * lkb_sbflags: status block flags. These flags are copied directly into 1808c2ecf20Sopenharmony_ci * the caller's lksb.sb_flags prior to the dlm_lock/dlm_unlock completion 1818c2ecf20Sopenharmony_ci * ast. All defined in dlm.h with DLM_SBF_ prefix. 1828c2ecf20Sopenharmony_ci * 1838c2ecf20Sopenharmony_ci * lkb_status: the lock status indicates which rsb queue the lock is 1848c2ecf20Sopenharmony_ci * on, grant, convert, or wait. DLM_LKSTS_ WAITING/GRANTED/CONVERT 1858c2ecf20Sopenharmony_ci * 1868c2ecf20Sopenharmony_ci * lkb_wait_type: the dlm message type (DLM_MSG_ prefix) for which a 1878c2ecf20Sopenharmony_ci * reply is needed. Only set when the lkb is on the lockspace waiters 1888c2ecf20Sopenharmony_ci * list awaiting a reply from a remote node. 1898c2ecf20Sopenharmony_ci * 1908c2ecf20Sopenharmony_ci * lkb_nodeid: when the lkb is a local copy, nodeid is 0; when the lkb 1918c2ecf20Sopenharmony_ci * is a master copy, nodeid specifies the remote lock holder, when the 1928c2ecf20Sopenharmony_ci * lkb is a process copy, the nodeid specifies the lock master. 1938c2ecf20Sopenharmony_ci */ 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci/* lkb_status */ 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci#define DLM_LKSTS_WAITING 1 1988c2ecf20Sopenharmony_ci#define DLM_LKSTS_GRANTED 2 1998c2ecf20Sopenharmony_ci#define DLM_LKSTS_CONVERT 3 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci/* lkb_flags */ 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci#define DLM_IFL_MSTCPY 0x00010000 2048c2ecf20Sopenharmony_ci#define DLM_IFL_RESEND 0x00020000 2058c2ecf20Sopenharmony_ci#define DLM_IFL_DEAD 0x00040000 2068c2ecf20Sopenharmony_ci#define DLM_IFL_OVERLAP_UNLOCK 0x00080000 2078c2ecf20Sopenharmony_ci#define DLM_IFL_OVERLAP_CANCEL 0x00100000 2088c2ecf20Sopenharmony_ci#define DLM_IFL_ENDOFLIFE 0x00200000 2098c2ecf20Sopenharmony_ci#define DLM_IFL_WATCH_TIMEWARN 0x00400000 2108c2ecf20Sopenharmony_ci#define DLM_IFL_TIMEOUT_CANCEL 0x00800000 2118c2ecf20Sopenharmony_ci#define DLM_IFL_DEADLOCK_CANCEL 0x01000000 2128c2ecf20Sopenharmony_ci#define DLM_IFL_STUB_MS 0x02000000 /* magic number for m_flags */ 2138c2ecf20Sopenharmony_ci#define DLM_IFL_USER 0x00000001 2148c2ecf20Sopenharmony_ci#define DLM_IFL_ORPHAN 0x00000002 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci#define DLM_CALLBACKS_SIZE 6 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci#define DLM_CB_CAST 0x00000001 2198c2ecf20Sopenharmony_ci#define DLM_CB_BAST 0x00000002 2208c2ecf20Sopenharmony_ci#define DLM_CB_SKIP 0x00000004 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistruct dlm_callback { 2238c2ecf20Sopenharmony_ci uint64_t seq; 2248c2ecf20Sopenharmony_ci uint32_t flags; /* DLM_CBF_ */ 2258c2ecf20Sopenharmony_ci int sb_status; /* copy to lksb status */ 2268c2ecf20Sopenharmony_ci uint8_t sb_flags; /* copy to lksb flags */ 2278c2ecf20Sopenharmony_ci int8_t mode; /* rq mode of bast, gr mode of cast */ 2288c2ecf20Sopenharmony_ci}; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_cistruct dlm_lkb { 2318c2ecf20Sopenharmony_ci struct dlm_rsb *lkb_resource; /* the rsb */ 2328c2ecf20Sopenharmony_ci struct kref lkb_ref; 2338c2ecf20Sopenharmony_ci int lkb_nodeid; /* copied from rsb */ 2348c2ecf20Sopenharmony_ci int lkb_ownpid; /* pid of lock owner */ 2358c2ecf20Sopenharmony_ci uint32_t lkb_id; /* our lock ID */ 2368c2ecf20Sopenharmony_ci uint32_t lkb_remid; /* lock ID on remote partner */ 2378c2ecf20Sopenharmony_ci uint32_t lkb_exflags; /* external flags from caller */ 2388c2ecf20Sopenharmony_ci uint32_t lkb_sbflags; /* lksb flags */ 2398c2ecf20Sopenharmony_ci uint32_t lkb_flags; /* internal flags */ 2408c2ecf20Sopenharmony_ci uint32_t lkb_lvbseq; /* lvb sequence number */ 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci int8_t lkb_status; /* granted, waiting, convert */ 2438c2ecf20Sopenharmony_ci int8_t lkb_rqmode; /* requested lock mode */ 2448c2ecf20Sopenharmony_ci int8_t lkb_grmode; /* granted lock mode */ 2458c2ecf20Sopenharmony_ci int8_t lkb_highbast; /* highest mode bast sent for */ 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci int8_t lkb_wait_type; /* type of reply waiting for */ 2488c2ecf20Sopenharmony_ci int8_t lkb_wait_count; 2498c2ecf20Sopenharmony_ci int lkb_wait_nodeid; /* for debugging */ 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci struct list_head lkb_statequeue; /* rsb g/c/w list */ 2528c2ecf20Sopenharmony_ci struct list_head lkb_rsb_lookup; /* waiting for rsb lookup */ 2538c2ecf20Sopenharmony_ci struct list_head lkb_wait_reply; /* waiting for remote reply */ 2548c2ecf20Sopenharmony_ci struct list_head lkb_ownqueue; /* list of locks for a process */ 2558c2ecf20Sopenharmony_ci struct list_head lkb_time_list; 2568c2ecf20Sopenharmony_ci ktime_t lkb_timestamp; 2578c2ecf20Sopenharmony_ci ktime_t lkb_wait_time; 2588c2ecf20Sopenharmony_ci unsigned long lkb_timeout_cs; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci struct mutex lkb_cb_mutex; 2618c2ecf20Sopenharmony_ci struct work_struct lkb_cb_work; 2628c2ecf20Sopenharmony_ci struct list_head lkb_cb_list; /* for ls_cb_delay or proc->asts */ 2638c2ecf20Sopenharmony_ci struct dlm_callback lkb_callbacks[DLM_CALLBACKS_SIZE]; 2648c2ecf20Sopenharmony_ci struct dlm_callback lkb_last_cast; 2658c2ecf20Sopenharmony_ci struct dlm_callback lkb_last_bast; 2668c2ecf20Sopenharmony_ci ktime_t lkb_last_cast_time; /* for debugging */ 2678c2ecf20Sopenharmony_ci ktime_t lkb_last_bast_time; /* for debugging */ 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci uint64_t lkb_recover_seq; /* from ls_recover_seq */ 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci char *lkb_lvbptr; 2728c2ecf20Sopenharmony_ci struct dlm_lksb *lkb_lksb; /* caller's status block */ 2738c2ecf20Sopenharmony_ci void (*lkb_astfn) (void *astparam); 2748c2ecf20Sopenharmony_ci void (*lkb_bastfn) (void *astparam, int mode); 2758c2ecf20Sopenharmony_ci union { 2768c2ecf20Sopenharmony_ci void *lkb_astparam; /* caller's ast arg */ 2778c2ecf20Sopenharmony_ci struct dlm_user_args *lkb_ua; 2788c2ecf20Sopenharmony_ci }; 2798c2ecf20Sopenharmony_ci}; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci/* 2828c2ecf20Sopenharmony_ci * res_master_nodeid is "normal": 0 is unset/invalid, non-zero is the real 2838c2ecf20Sopenharmony_ci * nodeid, even when nodeid is our_nodeid. 2848c2ecf20Sopenharmony_ci * 2858c2ecf20Sopenharmony_ci * res_nodeid is "odd": -1 is unset/invalid, zero means our_nodeid, 2868c2ecf20Sopenharmony_ci * greater than zero when another nodeid. 2878c2ecf20Sopenharmony_ci * 2888c2ecf20Sopenharmony_ci * (TODO: remove res_nodeid and only use res_master_nodeid) 2898c2ecf20Sopenharmony_ci */ 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_cistruct dlm_rsb { 2928c2ecf20Sopenharmony_ci struct dlm_ls *res_ls; /* the lockspace */ 2938c2ecf20Sopenharmony_ci struct kref res_ref; 2948c2ecf20Sopenharmony_ci struct mutex res_mutex; 2958c2ecf20Sopenharmony_ci unsigned long res_flags; 2968c2ecf20Sopenharmony_ci int res_length; /* length of rsb name */ 2978c2ecf20Sopenharmony_ci int res_nodeid; 2988c2ecf20Sopenharmony_ci int res_master_nodeid; 2998c2ecf20Sopenharmony_ci int res_dir_nodeid; 3008c2ecf20Sopenharmony_ci int res_id; /* for ls_recover_idr */ 3018c2ecf20Sopenharmony_ci uint32_t res_lvbseq; 3028c2ecf20Sopenharmony_ci uint32_t res_hash; 3038c2ecf20Sopenharmony_ci uint32_t res_bucket; /* rsbtbl */ 3048c2ecf20Sopenharmony_ci unsigned long res_toss_time; 3058c2ecf20Sopenharmony_ci uint32_t res_first_lkid; 3068c2ecf20Sopenharmony_ci struct list_head res_lookup; /* lkbs waiting on first */ 3078c2ecf20Sopenharmony_ci union { 3088c2ecf20Sopenharmony_ci struct list_head res_hashchain; 3098c2ecf20Sopenharmony_ci struct rb_node res_hashnode; /* rsbtbl */ 3108c2ecf20Sopenharmony_ci }; 3118c2ecf20Sopenharmony_ci struct list_head res_grantqueue; 3128c2ecf20Sopenharmony_ci struct list_head res_convertqueue; 3138c2ecf20Sopenharmony_ci struct list_head res_waitqueue; 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci struct list_head res_root_list; /* used for recovery */ 3168c2ecf20Sopenharmony_ci struct list_head res_recover_list; /* used for recovery */ 3178c2ecf20Sopenharmony_ci int res_recover_locks_count; 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci char *res_lvbptr; 3208c2ecf20Sopenharmony_ci char res_name[DLM_RESNAME_MAXLEN+1]; 3218c2ecf20Sopenharmony_ci}; 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci/* dlm_master_lookup() flags */ 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci#define DLM_LU_RECOVER_DIR 1 3268c2ecf20Sopenharmony_ci#define DLM_LU_RECOVER_MASTER 2 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci/* dlm_master_lookup() results */ 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci#define DLM_LU_MATCH 1 3318c2ecf20Sopenharmony_ci#define DLM_LU_ADD 2 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci/* find_rsb() flags */ 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci#define R_REQUEST 0x00000001 3368c2ecf20Sopenharmony_ci#define R_RECEIVE_REQUEST 0x00000002 3378c2ecf20Sopenharmony_ci#define R_RECEIVE_RECOVER 0x00000004 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci/* rsb_flags */ 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_cienum rsb_flags { 3428c2ecf20Sopenharmony_ci RSB_MASTER_UNCERTAIN, 3438c2ecf20Sopenharmony_ci RSB_VALNOTVALID, 3448c2ecf20Sopenharmony_ci RSB_VALNOTVALID_PREV, 3458c2ecf20Sopenharmony_ci RSB_NEW_MASTER, 3468c2ecf20Sopenharmony_ci RSB_NEW_MASTER2, 3478c2ecf20Sopenharmony_ci RSB_RECOVER_CONVERT, 3488c2ecf20Sopenharmony_ci RSB_RECOVER_GRANT, 3498c2ecf20Sopenharmony_ci RSB_RECOVER_LVB_INVAL, 3508c2ecf20Sopenharmony_ci}; 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_cistatic inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag) 3538c2ecf20Sopenharmony_ci{ 3548c2ecf20Sopenharmony_ci __set_bit(flag, &r->res_flags); 3558c2ecf20Sopenharmony_ci} 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_cistatic inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag) 3588c2ecf20Sopenharmony_ci{ 3598c2ecf20Sopenharmony_ci __clear_bit(flag, &r->res_flags); 3608c2ecf20Sopenharmony_ci} 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_cistatic inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag) 3638c2ecf20Sopenharmony_ci{ 3648c2ecf20Sopenharmony_ci return test_bit(flag, &r->res_flags); 3658c2ecf20Sopenharmony_ci} 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci/* dlm_header is first element of all structs sent between nodes */ 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci#define DLM_HEADER_MAJOR 0x00030000 3718c2ecf20Sopenharmony_ci#define DLM_HEADER_MINOR 0x00000001 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci#define DLM_HEADER_SLOTS 0x00000001 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci#define DLM_MSG 1 3768c2ecf20Sopenharmony_ci#define DLM_RCOM 2 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_cistruct dlm_header { 3798c2ecf20Sopenharmony_ci uint32_t h_version; 3808c2ecf20Sopenharmony_ci uint32_t h_lockspace; 3818c2ecf20Sopenharmony_ci uint32_t h_nodeid; /* nodeid of sender */ 3828c2ecf20Sopenharmony_ci uint16_t h_length; 3838c2ecf20Sopenharmony_ci uint8_t h_cmd; /* DLM_MSG, DLM_RCOM */ 3848c2ecf20Sopenharmony_ci uint8_t h_pad; 3858c2ecf20Sopenharmony_ci}; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci#define DLM_MSG_REQUEST 1 3898c2ecf20Sopenharmony_ci#define DLM_MSG_CONVERT 2 3908c2ecf20Sopenharmony_ci#define DLM_MSG_UNLOCK 3 3918c2ecf20Sopenharmony_ci#define DLM_MSG_CANCEL 4 3928c2ecf20Sopenharmony_ci#define DLM_MSG_REQUEST_REPLY 5 3938c2ecf20Sopenharmony_ci#define DLM_MSG_CONVERT_REPLY 6 3948c2ecf20Sopenharmony_ci#define DLM_MSG_UNLOCK_REPLY 7 3958c2ecf20Sopenharmony_ci#define DLM_MSG_CANCEL_REPLY 8 3968c2ecf20Sopenharmony_ci#define DLM_MSG_GRANT 9 3978c2ecf20Sopenharmony_ci#define DLM_MSG_BAST 10 3988c2ecf20Sopenharmony_ci#define DLM_MSG_LOOKUP 11 3998c2ecf20Sopenharmony_ci#define DLM_MSG_REMOVE 12 4008c2ecf20Sopenharmony_ci#define DLM_MSG_LOOKUP_REPLY 13 4018c2ecf20Sopenharmony_ci#define DLM_MSG_PURGE 14 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_cistruct dlm_message { 4048c2ecf20Sopenharmony_ci struct dlm_header m_header; 4058c2ecf20Sopenharmony_ci uint32_t m_type; /* DLM_MSG_ */ 4068c2ecf20Sopenharmony_ci uint32_t m_nodeid; 4078c2ecf20Sopenharmony_ci uint32_t m_pid; 4088c2ecf20Sopenharmony_ci uint32_t m_lkid; /* lkid on sender */ 4098c2ecf20Sopenharmony_ci uint32_t m_remid; /* lkid on receiver */ 4108c2ecf20Sopenharmony_ci uint32_t m_parent_lkid; 4118c2ecf20Sopenharmony_ci uint32_t m_parent_remid; 4128c2ecf20Sopenharmony_ci uint32_t m_exflags; 4138c2ecf20Sopenharmony_ci uint32_t m_sbflags; 4148c2ecf20Sopenharmony_ci uint32_t m_flags; 4158c2ecf20Sopenharmony_ci uint32_t m_lvbseq; 4168c2ecf20Sopenharmony_ci uint32_t m_hash; 4178c2ecf20Sopenharmony_ci int m_status; 4188c2ecf20Sopenharmony_ci int m_grmode; 4198c2ecf20Sopenharmony_ci int m_rqmode; 4208c2ecf20Sopenharmony_ci int m_bastmode; 4218c2ecf20Sopenharmony_ci int m_asts; 4228c2ecf20Sopenharmony_ci int m_result; /* 0 or -EXXX */ 4238c2ecf20Sopenharmony_ci char m_extra[]; /* name or lvb */ 4248c2ecf20Sopenharmony_ci}; 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci#define DLM_RS_NODES 0x00000001 4288c2ecf20Sopenharmony_ci#define DLM_RS_NODES_ALL 0x00000002 4298c2ecf20Sopenharmony_ci#define DLM_RS_DIR 0x00000004 4308c2ecf20Sopenharmony_ci#define DLM_RS_DIR_ALL 0x00000008 4318c2ecf20Sopenharmony_ci#define DLM_RS_LOCKS 0x00000010 4328c2ecf20Sopenharmony_ci#define DLM_RS_LOCKS_ALL 0x00000020 4338c2ecf20Sopenharmony_ci#define DLM_RS_DONE 0x00000040 4348c2ecf20Sopenharmony_ci#define DLM_RS_DONE_ALL 0x00000080 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci#define DLM_RCOM_STATUS 1 4378c2ecf20Sopenharmony_ci#define DLM_RCOM_NAMES 2 4388c2ecf20Sopenharmony_ci#define DLM_RCOM_LOOKUP 3 4398c2ecf20Sopenharmony_ci#define DLM_RCOM_LOCK 4 4408c2ecf20Sopenharmony_ci#define DLM_RCOM_STATUS_REPLY 5 4418c2ecf20Sopenharmony_ci#define DLM_RCOM_NAMES_REPLY 6 4428c2ecf20Sopenharmony_ci#define DLM_RCOM_LOOKUP_REPLY 7 4438c2ecf20Sopenharmony_ci#define DLM_RCOM_LOCK_REPLY 8 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_cistruct dlm_rcom { 4468c2ecf20Sopenharmony_ci struct dlm_header rc_header; 4478c2ecf20Sopenharmony_ci uint32_t rc_type; /* DLM_RCOM_ */ 4488c2ecf20Sopenharmony_ci int rc_result; /* multi-purpose */ 4498c2ecf20Sopenharmony_ci uint64_t rc_id; /* match reply with request */ 4508c2ecf20Sopenharmony_ci uint64_t rc_seq; /* sender's ls_recover_seq */ 4518c2ecf20Sopenharmony_ci uint64_t rc_seq_reply; /* remote ls_recover_seq */ 4528c2ecf20Sopenharmony_ci char rc_buf[]; 4538c2ecf20Sopenharmony_ci}; 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ciunion dlm_packet { 4568c2ecf20Sopenharmony_ci struct dlm_header header; /* common to other two */ 4578c2ecf20Sopenharmony_ci struct dlm_message message; 4588c2ecf20Sopenharmony_ci struct dlm_rcom rcom; 4598c2ecf20Sopenharmony_ci}; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci#define DLM_RSF_NEED_SLOTS 0x00000001 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci/* RCOM_STATUS data */ 4648c2ecf20Sopenharmony_cistruct rcom_status { 4658c2ecf20Sopenharmony_ci __le32 rs_flags; 4668c2ecf20Sopenharmony_ci __le32 rs_unused1; 4678c2ecf20Sopenharmony_ci __le64 rs_unused2; 4688c2ecf20Sopenharmony_ci}; 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci/* RCOM_STATUS_REPLY data */ 4718c2ecf20Sopenharmony_cistruct rcom_config { 4728c2ecf20Sopenharmony_ci __le32 rf_lvblen; 4738c2ecf20Sopenharmony_ci __le32 rf_lsflags; 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci /* DLM_HEADER_SLOTS adds: */ 4768c2ecf20Sopenharmony_ci __le32 rf_flags; 4778c2ecf20Sopenharmony_ci __le16 rf_our_slot; 4788c2ecf20Sopenharmony_ci __le16 rf_num_slots; 4798c2ecf20Sopenharmony_ci __le32 rf_generation; 4808c2ecf20Sopenharmony_ci __le32 rf_unused1; 4818c2ecf20Sopenharmony_ci __le64 rf_unused2; 4828c2ecf20Sopenharmony_ci}; 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_cistruct rcom_slot { 4858c2ecf20Sopenharmony_ci __le32 ro_nodeid; 4868c2ecf20Sopenharmony_ci __le16 ro_slot; 4878c2ecf20Sopenharmony_ci __le16 ro_unused1; 4888c2ecf20Sopenharmony_ci __le64 ro_unused2; 4898c2ecf20Sopenharmony_ci}; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_cistruct rcom_lock { 4928c2ecf20Sopenharmony_ci __le32 rl_ownpid; 4938c2ecf20Sopenharmony_ci __le32 rl_lkid; 4948c2ecf20Sopenharmony_ci __le32 rl_remid; 4958c2ecf20Sopenharmony_ci __le32 rl_parent_lkid; 4968c2ecf20Sopenharmony_ci __le32 rl_parent_remid; 4978c2ecf20Sopenharmony_ci __le32 rl_exflags; 4988c2ecf20Sopenharmony_ci __le32 rl_flags; 4998c2ecf20Sopenharmony_ci __le32 rl_lvbseq; 5008c2ecf20Sopenharmony_ci __le32 rl_result; 5018c2ecf20Sopenharmony_ci int8_t rl_rqmode; 5028c2ecf20Sopenharmony_ci int8_t rl_grmode; 5038c2ecf20Sopenharmony_ci int8_t rl_status; 5048c2ecf20Sopenharmony_ci int8_t rl_asts; 5058c2ecf20Sopenharmony_ci __le16 rl_wait_type; 5068c2ecf20Sopenharmony_ci __le16 rl_namelen; 5078c2ecf20Sopenharmony_ci char rl_name[DLM_RESNAME_MAXLEN]; 5088c2ecf20Sopenharmony_ci char rl_lvb[]; 5098c2ecf20Sopenharmony_ci}; 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci/* 5128c2ecf20Sopenharmony_ci * The max number of resources per rsbtbl bucket that shrink will attempt 5138c2ecf20Sopenharmony_ci * to remove in each iteration. 5148c2ecf20Sopenharmony_ci */ 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci#define DLM_REMOVE_NAMES_MAX 8 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_cistruct dlm_ls { 5198c2ecf20Sopenharmony_ci struct list_head ls_list; /* list of lockspaces */ 5208c2ecf20Sopenharmony_ci dlm_lockspace_t *ls_local_handle; 5218c2ecf20Sopenharmony_ci uint32_t ls_global_id; /* global unique lockspace ID */ 5228c2ecf20Sopenharmony_ci uint32_t ls_generation; 5238c2ecf20Sopenharmony_ci uint32_t ls_exflags; 5248c2ecf20Sopenharmony_ci int ls_lvblen; 5258c2ecf20Sopenharmony_ci int ls_count; /* refcount of processes in 5268c2ecf20Sopenharmony_ci the dlm using this ls */ 5278c2ecf20Sopenharmony_ci int ls_create_count; /* create/release refcount */ 5288c2ecf20Sopenharmony_ci unsigned long ls_flags; /* LSFL_ */ 5298c2ecf20Sopenharmony_ci unsigned long ls_scan_time; 5308c2ecf20Sopenharmony_ci struct kobject ls_kobj; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci struct idr ls_lkbidr; 5338c2ecf20Sopenharmony_ci spinlock_t ls_lkbidr_spin; 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci struct dlm_rsbtable *ls_rsbtbl; 5368c2ecf20Sopenharmony_ci uint32_t ls_rsbtbl_size; 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci struct mutex ls_waiters_mutex; 5398c2ecf20Sopenharmony_ci struct list_head ls_waiters; /* lkbs needing a reply */ 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci struct mutex ls_orphans_mutex; 5428c2ecf20Sopenharmony_ci struct list_head ls_orphans; 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci struct mutex ls_timeout_mutex; 5458c2ecf20Sopenharmony_ci struct list_head ls_timeout; 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci spinlock_t ls_new_rsb_spin; 5488c2ecf20Sopenharmony_ci int ls_new_rsb_count; 5498c2ecf20Sopenharmony_ci struct list_head ls_new_rsb; /* new rsb structs */ 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci spinlock_t ls_remove_spin; 5528c2ecf20Sopenharmony_ci char ls_remove_name[DLM_RESNAME_MAXLEN+1]; 5538c2ecf20Sopenharmony_ci char *ls_remove_names[DLM_REMOVE_NAMES_MAX]; 5548c2ecf20Sopenharmony_ci int ls_remove_len; 5558c2ecf20Sopenharmony_ci int ls_remove_lens[DLM_REMOVE_NAMES_MAX]; 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci struct list_head ls_nodes; /* current nodes in ls */ 5588c2ecf20Sopenharmony_ci struct list_head ls_nodes_gone; /* dead node list, recovery */ 5598c2ecf20Sopenharmony_ci int ls_num_nodes; /* number of nodes in ls */ 5608c2ecf20Sopenharmony_ci int ls_low_nodeid; 5618c2ecf20Sopenharmony_ci int ls_total_weight; 5628c2ecf20Sopenharmony_ci int *ls_node_array; 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci int ls_slot; 5658c2ecf20Sopenharmony_ci int ls_num_slots; 5668c2ecf20Sopenharmony_ci int ls_slots_size; 5678c2ecf20Sopenharmony_ci struct dlm_slot *ls_slots; 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci struct dlm_rsb ls_stub_rsb; /* for returning errors */ 5708c2ecf20Sopenharmony_ci struct dlm_lkb ls_stub_lkb; /* for returning errors */ 5718c2ecf20Sopenharmony_ci struct dlm_message ls_stub_ms; /* for faking a reply */ 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci struct dentry *ls_debug_rsb_dentry; /* debugfs */ 5748c2ecf20Sopenharmony_ci struct dentry *ls_debug_waiters_dentry; /* debugfs */ 5758c2ecf20Sopenharmony_ci struct dentry *ls_debug_locks_dentry; /* debugfs */ 5768c2ecf20Sopenharmony_ci struct dentry *ls_debug_all_dentry; /* debugfs */ 5778c2ecf20Sopenharmony_ci struct dentry *ls_debug_toss_dentry; /* debugfs */ 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci wait_queue_head_t ls_uevent_wait; /* user part of join/leave */ 5808c2ecf20Sopenharmony_ci int ls_uevent_result; 5818c2ecf20Sopenharmony_ci struct completion ls_members_done; 5828c2ecf20Sopenharmony_ci int ls_members_result; 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci struct miscdevice ls_device; 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci struct workqueue_struct *ls_callback_wq; 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci /* recovery related */ 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci struct mutex ls_cb_mutex; 5918c2ecf20Sopenharmony_ci struct list_head ls_cb_delay; /* save for queue_work later */ 5928c2ecf20Sopenharmony_ci struct timer_list ls_timer; 5938c2ecf20Sopenharmony_ci struct task_struct *ls_recoverd_task; 5948c2ecf20Sopenharmony_ci struct mutex ls_recoverd_active; 5958c2ecf20Sopenharmony_ci spinlock_t ls_recover_lock; 5968c2ecf20Sopenharmony_ci unsigned long ls_recover_begin; /* jiffies timestamp */ 5978c2ecf20Sopenharmony_ci uint32_t ls_recover_status; /* DLM_RS_ */ 5988c2ecf20Sopenharmony_ci uint64_t ls_recover_seq; 5998c2ecf20Sopenharmony_ci struct dlm_recover *ls_recover_args; 6008c2ecf20Sopenharmony_ci struct rw_semaphore ls_in_recovery; /* block local requests */ 6018c2ecf20Sopenharmony_ci struct rw_semaphore ls_recv_active; /* block dlm_recv */ 6028c2ecf20Sopenharmony_ci struct list_head ls_requestqueue;/* queue remote requests */ 6038c2ecf20Sopenharmony_ci struct mutex ls_requestqueue_mutex; 6048c2ecf20Sopenharmony_ci struct dlm_rcom *ls_recover_buf; 6058c2ecf20Sopenharmony_ci int ls_recover_nodeid; /* for debugging */ 6068c2ecf20Sopenharmony_ci unsigned int ls_recover_dir_sent_res; /* for log info */ 6078c2ecf20Sopenharmony_ci unsigned int ls_recover_dir_sent_msg; /* for log info */ 6088c2ecf20Sopenharmony_ci unsigned int ls_recover_locks_in; /* for log info */ 6098c2ecf20Sopenharmony_ci uint64_t ls_rcom_seq; 6108c2ecf20Sopenharmony_ci spinlock_t ls_rcom_spin; 6118c2ecf20Sopenharmony_ci struct list_head ls_recover_list; 6128c2ecf20Sopenharmony_ci spinlock_t ls_recover_list_lock; 6138c2ecf20Sopenharmony_ci int ls_recover_list_count; 6148c2ecf20Sopenharmony_ci struct idr ls_recover_idr; 6158c2ecf20Sopenharmony_ci spinlock_t ls_recover_idr_lock; 6168c2ecf20Sopenharmony_ci wait_queue_head_t ls_wait_general; 6178c2ecf20Sopenharmony_ci wait_queue_head_t ls_recover_lock_wait; 6188c2ecf20Sopenharmony_ci struct mutex ls_clear_proc_locks; 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci struct list_head ls_root_list; /* root resources */ 6218c2ecf20Sopenharmony_ci struct rw_semaphore ls_root_sem; /* protect root_list */ 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci const struct dlm_lockspace_ops *ls_ops; 6248c2ecf20Sopenharmony_ci void *ls_ops_arg; 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci int ls_namelen; 6278c2ecf20Sopenharmony_ci char ls_name[1]; 6288c2ecf20Sopenharmony_ci}; 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci/* 6318c2ecf20Sopenharmony_ci * LSFL_RECOVER_STOP - dlm_ls_stop() sets this to tell dlm recovery routines 6328c2ecf20Sopenharmony_ci * that they should abort what they're doing so new recovery can be started. 6338c2ecf20Sopenharmony_ci * 6348c2ecf20Sopenharmony_ci * LSFL_RECOVER_DOWN - dlm_ls_stop() sets this to tell dlm_recoverd that it 6358c2ecf20Sopenharmony_ci * should do down_write() on the in_recovery rw_semaphore. (doing down_write 6368c2ecf20Sopenharmony_ci * within dlm_ls_stop causes complaints about the lock acquired/released 6378c2ecf20Sopenharmony_ci * in different contexts.) 6388c2ecf20Sopenharmony_ci * 6398c2ecf20Sopenharmony_ci * LSFL_RECOVER_LOCK - dlm_recoverd holds the in_recovery rw_semaphore. 6408c2ecf20Sopenharmony_ci * It sets this after it is done with down_write() on the in_recovery 6418c2ecf20Sopenharmony_ci * rw_semaphore and clears it after it has released the rw_semaphore. 6428c2ecf20Sopenharmony_ci * 6438c2ecf20Sopenharmony_ci * LSFL_RECOVER_WORK - dlm_ls_start() sets this to tell dlm_recoverd that it 6448c2ecf20Sopenharmony_ci * should begin recovery of the lockspace. 6458c2ecf20Sopenharmony_ci * 6468c2ecf20Sopenharmony_ci * LSFL_RUNNING - set when normal locking activity is enabled. 6478c2ecf20Sopenharmony_ci * dlm_ls_stop() clears this to tell dlm locking routines that they should 6488c2ecf20Sopenharmony_ci * quit what they are doing so recovery can run. dlm_recoverd sets 6498c2ecf20Sopenharmony_ci * this after recovery is finished. 6508c2ecf20Sopenharmony_ci */ 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci#define LSFL_RECOVER_STOP 0 6538c2ecf20Sopenharmony_ci#define LSFL_RECOVER_DOWN 1 6548c2ecf20Sopenharmony_ci#define LSFL_RECOVER_LOCK 2 6558c2ecf20Sopenharmony_ci#define LSFL_RECOVER_WORK 3 6568c2ecf20Sopenharmony_ci#define LSFL_RUNNING 4 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci#define LSFL_RCOM_READY 5 6598c2ecf20Sopenharmony_ci#define LSFL_RCOM_WAIT 6 6608c2ecf20Sopenharmony_ci#define LSFL_UEVENT_WAIT 7 6618c2ecf20Sopenharmony_ci#define LSFL_TIMEWARN 8 6628c2ecf20Sopenharmony_ci#define LSFL_CB_DELAY 9 6638c2ecf20Sopenharmony_ci#define LSFL_NODIR 10 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci/* much of this is just saving user space pointers associated with the 6668c2ecf20Sopenharmony_ci lock that we pass back to the user lib with an ast */ 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_cistruct dlm_user_args { 6698c2ecf20Sopenharmony_ci struct dlm_user_proc *proc; /* each process that opens the lockspace 6708c2ecf20Sopenharmony_ci device has private data 6718c2ecf20Sopenharmony_ci (dlm_user_proc) on the struct file, 6728c2ecf20Sopenharmony_ci the process's locks point back to it*/ 6738c2ecf20Sopenharmony_ci struct dlm_lksb lksb; 6748c2ecf20Sopenharmony_ci struct dlm_lksb __user *user_lksb; 6758c2ecf20Sopenharmony_ci void __user *castparam; 6768c2ecf20Sopenharmony_ci void __user *castaddr; 6778c2ecf20Sopenharmony_ci void __user *bastparam; 6788c2ecf20Sopenharmony_ci void __user *bastaddr; 6798c2ecf20Sopenharmony_ci uint64_t xid; 6808c2ecf20Sopenharmony_ci}; 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci#define DLM_PROC_FLAGS_CLOSING 1 6838c2ecf20Sopenharmony_ci#define DLM_PROC_FLAGS_COMPAT 2 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ci/* locks list is kept so we can remove all a process's locks when it 6868c2ecf20Sopenharmony_ci exits (or orphan those that are persistent) */ 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_cistruct dlm_user_proc { 6898c2ecf20Sopenharmony_ci dlm_lockspace_t *lockspace; 6908c2ecf20Sopenharmony_ci unsigned long flags; /* DLM_PROC_FLAGS */ 6918c2ecf20Sopenharmony_ci struct list_head asts; 6928c2ecf20Sopenharmony_ci spinlock_t asts_spin; 6938c2ecf20Sopenharmony_ci struct list_head locks; 6948c2ecf20Sopenharmony_ci spinlock_t locks_spin; 6958c2ecf20Sopenharmony_ci struct list_head unlocking; 6968c2ecf20Sopenharmony_ci wait_queue_head_t wait; 6978c2ecf20Sopenharmony_ci}; 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_cistatic inline int dlm_locking_stopped(struct dlm_ls *ls) 7008c2ecf20Sopenharmony_ci{ 7018c2ecf20Sopenharmony_ci return !test_bit(LSFL_RUNNING, &ls->ls_flags); 7028c2ecf20Sopenharmony_ci} 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_cistatic inline int dlm_recovery_stopped(struct dlm_ls *ls) 7058c2ecf20Sopenharmony_ci{ 7068c2ecf20Sopenharmony_ci return test_bit(LSFL_RECOVER_STOP, &ls->ls_flags); 7078c2ecf20Sopenharmony_ci} 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_cistatic inline int dlm_no_directory(struct dlm_ls *ls) 7108c2ecf20Sopenharmony_ci{ 7118c2ecf20Sopenharmony_ci return test_bit(LSFL_NODIR, &ls->ls_flags); 7128c2ecf20Sopenharmony_ci} 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ciint dlm_netlink_init(void); 7158c2ecf20Sopenharmony_civoid dlm_netlink_exit(void); 7168c2ecf20Sopenharmony_civoid dlm_timeout_warn(struct dlm_lkb *lkb); 7178c2ecf20Sopenharmony_ciint dlm_plock_init(void); 7188c2ecf20Sopenharmony_civoid dlm_plock_exit(void); 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci#ifdef CONFIG_DLM_DEBUG 7218c2ecf20Sopenharmony_civoid dlm_register_debugfs(void); 7228c2ecf20Sopenharmony_civoid dlm_unregister_debugfs(void); 7238c2ecf20Sopenharmony_civoid dlm_create_debug_file(struct dlm_ls *ls); 7248c2ecf20Sopenharmony_civoid dlm_delete_debug_file(struct dlm_ls *ls); 7258c2ecf20Sopenharmony_ci#else 7268c2ecf20Sopenharmony_cistatic inline void dlm_register_debugfs(void) { } 7278c2ecf20Sopenharmony_cistatic inline void dlm_unregister_debugfs(void) { } 7288c2ecf20Sopenharmony_cistatic inline void dlm_create_debug_file(struct dlm_ls *ls) { } 7298c2ecf20Sopenharmony_cistatic inline void dlm_delete_debug_file(struct dlm_ls *ls) { } 7308c2ecf20Sopenharmony_ci#endif 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci#endif /* __DLM_INTERNAL_DOT_H__ */ 7338c2ecf20Sopenharmony_ci 734