1 /* $NetBSD: locking.h,v 1.1.1.1 2008/12/22 00:18:04 haad Exp $ */ 2 3 /* 4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 5 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 6 * 7 * This file is part of LVM2. 8 * 9 * This copyrighted material is made available to anyone wishing to use, 10 * modify, copy, or redistribute it subject to the terms and conditions 11 * of the GNU Lesser General Public License v.2.1. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this program; if not, write to the Free Software Foundation, 15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 18 #ifndef _LVM_LOCKING_H 19 #define _LVM_LOCKING_H 20 21 #include "uuid.h" 22 #include "config.h" 23 24 int init_locking(int type, struct cmd_context *cmd); 25 void fin_locking(void); 26 void reset_locking(void); 27 int vg_write_lock_held(void); 28 int locking_is_clustered(void); 29 30 /* 31 * LCK_VG: 32 * Lock/unlock on-disk volume group data. 33 * Use VG_ORPHANS to lock all orphan PVs. 34 * Use VG_GLOBAL as a global lock and to wipe the internal cache. 35 * char *vol holds volume group name. 36 * Set the LCK_CACHE flag to invalidate 'vol' in the internal cache. 37 * 38 * LCK_LV: 39 * Lock/unlock an individual logical volume 40 * char *vol holds lvid 41 */ 42 int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags); 43 44 /* 45 * Internal locking representation. 46 * LCK_VG: Uses prefix V_ unless the vol begins with # (i.e. #global or #orphans) 47 * or the LCK_CACHE flag is set when it uses the prefix P_. 48 * If LCK_CACHE is set, we do not take out a real lock. 49 */ 50 51 /* 52 * Does the LVM1 driver have this VG active? 53 */ 54 int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname); 55 56 /* 57 * Lock type - these numbers are the same as VMS and the IBM DLM 58 */ 59 #define LCK_TYPE_MASK 0x00000007U 60 61 #define LCK_NULL 0x00000000U /* LCK$_NLMODE */ 62 #define LCK_READ 0x00000001U /* LCK$_CRMODE */ 63 /* LCK$_CWMODE */ 64 #define LCK_PREAD 0x00000003U /* LCK$_PRMODE */ 65 #define LCK_WRITE 0x00000004U /* LCK$_PWMODE */ 66 #define LCK_EXCL 0x00000005U /* LCK$_EXMODE */ 67 #define LCK_UNLOCK 0x00000006U /* This is ours */ 68 69 /* 70 * Lock scope 71 */ 72 #define LCK_SCOPE_MASK 0x00000008U 73 #define LCK_VG 0x00000000U 74 #define LCK_LV 0x00000008U 75 76 /* 77 * Lock bits 78 */ 79 #define LCK_NONBLOCK 0x00000010U /* Don't block waiting for lock? */ 80 #define LCK_HOLD 0x00000020U /* Hold lock when lock_vol returns? */ 81 #define LCK_LOCAL 0x00000040U /* Don't propagate to other nodes */ 82 #define LCK_CLUSTER_VG 0x00000080U /* VG is clustered */ 83 #define LCK_CACHE 0x00000100U /* Operation on cache only using P_ lock */ 84 85 /* 86 * Additional lock bits for cluster communication 87 */ 88 #define LCK_MIRROR_NOSYNC_MODE 0x00000002U /* Mirrors don't require sync */ 89 #define LCK_DMEVENTD_MONITOR_MODE 0x00000004U /* Register with dmeventd */ 90 91 /* 92 * Special cases of VG locks. 93 */ 94 #define VG_ORPHANS "#orphans" 95 #define VG_GLOBAL "#global" 96 97 /* 98 * Common combinations 99 */ 100 #define LCK_NONE (LCK_VG | LCK_NULL) 101 102 #define LCK_VG_READ (LCK_VG | LCK_READ | LCK_HOLD) 103 #define LCK_VG_WRITE (LCK_VG | LCK_WRITE | LCK_HOLD) 104 #define LCK_VG_UNLOCK (LCK_VG | LCK_UNLOCK) 105 #define LCK_VG_DROP_CACHE (LCK_VG | LCK_WRITE | LCK_CACHE) 106 107 #define LCK_LV_EXCLUSIVE (LCK_LV | LCK_EXCL | LCK_NONBLOCK) 108 #define LCK_LV_SUSPEND (LCK_LV | LCK_WRITE | LCK_NONBLOCK) 109 #define LCK_LV_RESUME (LCK_LV | LCK_UNLOCK | LCK_NONBLOCK) 110 #define LCK_LV_ACTIVATE (LCK_LV | LCK_READ | LCK_NONBLOCK) 111 #define LCK_LV_DEACTIVATE (LCK_LV | LCK_NULL | LCK_NONBLOCK) 112 113 #define LCK_LV_CLUSTERED(lv) \ 114 (vg_is_clustered((lv)->vg) ? LCK_CLUSTER_VG : 0) 115 116 #define lock_lv_vol(cmd, lv, flags) \ 117 lock_vol(cmd, (lv)->lvid.s, flags | LCK_LV_CLUSTERED(lv)) 118 119 #define unlock_vg(cmd, vol) lock_vol(cmd, vol, LCK_VG_UNLOCK) 120 121 #define resume_lv(cmd, lv) lock_lv_vol(cmd, lv, LCK_LV_RESUME) 122 #define suspend_lv(cmd, lv) lock_lv_vol(cmd, lv, LCK_LV_SUSPEND | LCK_HOLD) 123 #define deactivate_lv(cmd, lv) lock_lv_vol(cmd, lv, LCK_LV_DEACTIVATE) 124 #define activate_lv(cmd, lv) lock_lv_vol(cmd, lv, LCK_LV_ACTIVATE | LCK_HOLD) 125 #define activate_lv_excl(cmd, lv) \ 126 lock_lv_vol(cmd, lv, LCK_LV_EXCLUSIVE | LCK_HOLD) 127 #define activate_lv_local(cmd, lv) \ 128 lock_lv_vol(cmd, lv, LCK_LV_ACTIVATE | LCK_HOLD | LCK_LOCAL) 129 #define deactivate_lv_local(cmd, lv) \ 130 lock_lv_vol(cmd, lv, LCK_LV_DEACTIVATE | LCK_LOCAL) 131 #define drop_cached_metadata(vg) \ 132 lock_vol((vg)->cmd, (vg)->name, LCK_VG_DROP_CACHE) 133 134 /* Process list of LVs */ 135 int suspend_lvs(struct cmd_context *cmd, struct dm_list *lvs); 136 int resume_lvs(struct cmd_context *cmd, struct dm_list *lvs); 137 int activate_lvs(struct cmd_context *cmd, struct dm_list *lvs, unsigned exclusive); 138 139 /* Interrupt handling */ 140 void sigint_clear(void); 141 void sigint_allow(void); 142 void sigint_restore(void); 143 int sigint_caught(void); 144 145 #endif 146