2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 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 Bacula® is a registered trademark of Kern Sibbald.
17 * Definitions for locking and blocking functions in the SD
19 * Kern Sibbald, pulled out of dev.h June 2007
27 void _lock_reservations(const char *file="**Unknown**", int line=0);
28 void _unlock_reservations();
29 void _lock_volumes(const char *file="**Unknown**", int line=0);
30 void _unlock_volumes();
34 #define lock_reservations() \
35 do { Dmsg3(sd_dbglvl, "lock_reservations at %s:%d precnt=%d\n", \
37 reservations_lock_count); \
38 _lock_reservations(__FILE__, __LINE__); \
39 Dmsg0(sd_dbglvl, "lock_reservations: got lock\n"); \
41 #define unlock_reservations() \
42 do { Dmsg3(sd_dbglvl, "unlock_reservations at %s:%d precnt=%d\n", \
44 reservations_lock_count); \
45 _unlock_reservations(); } while (0)
47 #define lock_volumes() \
48 do { Dmsg3(sd_dbglvl, "lock_volumes at %s:%d precnt=%d\n", \
50 vol_list_lock_count); \
51 _lock_volumes(__FILE__, __LINE__); \
52 Dmsg0(sd_dbglvl, "lock_volumes: got lock\n"); \
55 #define unlock_volumes() \
56 do { Dmsg3(sd_dbglvl, "unlock_volumes at %s:%d precnt=%d\n", \
58 vol_list_lock_count); \
59 _unlock_volumes(); } while (0)
63 #define lock_reservations() _lock_reservations(__FILE__, __LINE__)
64 #define unlock_reservations() _unlock_reservations()
65 #define lock_volumes() _lock_volumes(__FILE__, __LINE__)
66 #define unlock_volumes() _unlock_volumes()
71 #define Lock() dbg_Lock(__FILE__, __LINE__)
72 #define Unlock() dbg_Unlock(__FILE__, __LINE__)
73 #define rLock(locked) dbg_rLock(__FILE__, __LINE__, locked)
74 #define rUnlock() dbg_rUnlock(__FILE__, __LINE__)
78 #define Lock_acquire() dbg_Lock_acquire(__FILE__, __LINE__)
79 #define Unlock_acquire() dbg_Unlock_acquire(__FILE__, __LINE__)
80 #define Lock_read_acquire() dbg_Lock_read_acquire(__FILE__, __LINE__)
81 #define Unlock_read_acquire() dbg_Unlock_read_acquire(__FILE__, __LINE__)
82 #define Lock_VolCatInfo() dbg_Lock_VolCatInfo(__FILE__, __LINE__)
83 #define Unlock_VolCatInfo() dbg_Unlock_VolCatInfo(__FILE__, __LINE__)
86 #define block_device(d, s) _block_device(__FILE__, __LINE__, (d), s)
87 #define unblock_device(d) _unblock_device(__FILE__, __LINE__, (d))
88 #define steal_device_lock(d, p, s) _steal_device_lock(__FILE__, __LINE__, (d), (p), s)
89 #define give_back_device_lock(d, p) _give_back_device_lock(__FILE__, __LINE__, (d), (p))
91 /* m_blocked states (mutually exclusive) */
93 BST_NOT_BLOCKED = 0, /* not blocked */
94 BST_UNMOUNTED, /* User unmounted device */
95 BST_WAITING_FOR_SYSOP, /* Waiting for operator to mount tape */
96 BST_DOING_ACQUIRE, /* Opening/validating/moving tape */
97 BST_WRITING_LABEL, /* Labeling a tape */
98 BST_UNMOUNTED_WAITING_FOR_SYSOP, /* User unmounted during wait for op */
99 BST_MOUNT, /* Mount request */
100 BST_DESPOOLING, /* Despooling -- i.e. multiple writes */
101 BST_RELEASING /* Releasing the device */
104 typedef struct s_steal_lock {
105 pthread_t no_wait_id; /* id of no wait thread */
106 int dev_blocked; /* state */
107 int dev_prev_blocked; /* previous blocked state */
111 * Used in unblock() call