2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Definitions for locking and blocking functions in the SD
22 * Kern Sibbald, pulled out of dev.h June 2007
30 void _lock_reservations(const char *file="**Unknown**", int line=0);
31 void _unlock_reservations();
32 void _lock_volumes(const char *file="**Unknown**", int line=0);
33 void _unlock_volumes();
37 #define lock_reservations() \
38 do { Dmsg3(sd_dbglvl, "lock_reservations at %s:%d precnt=%d\n", \
40 reservations_lock_count); \
41 _lock_reservations(__FILE__, __LINE__); \
42 Dmsg0(sd_dbglvl, "lock_reservations: got lock\n"); \
44 #define unlock_reservations() \
45 do { Dmsg3(sd_dbglvl, "unlock_reservations at %s:%d precnt=%d\n", \
47 reservations_lock_count); \
48 _unlock_reservations(); } while (0)
50 #define lock_volumes() \
51 do { Dmsg3(sd_dbglvl, "lock_volumes at %s:%d precnt=%d\n", \
53 vol_list_lock_count); \
54 _lock_volumes(__FILE__, __LINE__); \
55 Dmsg0(sd_dbglvl, "lock_volumes: got lock\n"); \
58 #define unlock_volumes() \
59 do { Dmsg3(sd_dbglvl, "unlock_volumes at %s:%d precnt=%d\n", \
61 vol_list_lock_count); \
62 _unlock_volumes(); } while (0)
66 #define lock_reservations() _lock_reservations(__FILE__, __LINE__)
67 #define unlock_reservations() _unlock_reservations()
68 #define lock_volumes() _lock_volumes(__FILE__, __LINE__)
69 #define unlock_volumes() _unlock_volumes()
74 #define Lock() dbg_Lock(__FILE__, __LINE__)
75 #define Unlock() dbg_Unlock(__FILE__, __LINE__)
76 #define rLock(locked) dbg_rLock(__FILE__, __LINE__, locked)
77 #define rUnlock() dbg_rUnlock(__FILE__, __LINE__)
81 #define Lock_acquire() dbg_Lock_acquire(__FILE__, __LINE__)
82 #define Unlock_acquire() dbg_Unlock_acquire(__FILE__, __LINE__)
83 #define Lock_read_acquire() dbg_Lock_read_acquire(__FILE__, __LINE__)
84 #define Unlock_read_acquire() dbg_Unlock_read_acquire(__FILE__, __LINE__)
85 #define Lock_VolCatInfo() dbg_Lock_VolCatInfo(__FILE__, __LINE__)
86 #define Unlock_VolCatInfo() dbg_Unlock_VolCatInfo(__FILE__, __LINE__)
89 #define block_device(d, s) _block_device(__FILE__, __LINE__, (d), s)
90 #define unblock_device(d) _unblock_device(__FILE__, __LINE__, (d))
91 #define obtain_device_block(d, p, s) _obtain_device_block(__FILE__, __LINE__, (d), (p), s)
92 #define give_back_device_block(d, p) _give_back_device_block(__FILE__, __LINE__, (d), (p))
94 /* m_blocked states (mutually exclusive) */
96 BST_NOT_BLOCKED = 0, /* not blocked */
97 BST_UNMOUNTED, /* User unmounted device */
98 BST_WAITING_FOR_SYSOP, /* Waiting for operator to mount tape */
99 BST_DOING_ACQUIRE, /* Opening/validating/moving tape */
100 BST_WRITING_LABEL, /* Labeling a tape */
101 BST_UNMOUNTED_WAITING_FOR_SYSOP, /* User unmounted during wait for op */
102 BST_MOUNT, /* Mount request */
103 BST_DESPOOLING, /* Despooling -- i.e. multiple writes */
104 BST_RELEASING /* Releasing the device */
107 typedef struct s_steal_lock {
108 pthread_t no_wait_id; /* id of no wait thread */
109 int dev_blocked; /* state */
110 int dev_prev_blocked; /* previous blocked state */
111 uint32_t blocked_by; /* previous blocker */
115 * Used in unblock() call