]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/lock.h
Fix SD Vol+dev lock race bug
[bacula/bacula] / bacula / src / stored / lock.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Definitions for locking and blocking functions in the SD
30  *
31  * Kern Sibbald, pulled out of dev.h June 2007
32  *
33  *   Version $Id$
34  *
35  */
36
37
38 #ifndef __LOCK_H
39 #define __LOCK_H 1
40
41 #ifdef SD_DEBUG_LOCK
42 #define r_dlock()   _r_dlock(__FILE__, __LINE__);    /* in lock.c */
43 #define r_dunlock() _r_dunlock(__FILE__, __LINE__);  /* in lock.c */
44 #define dlock()     _dlock(__FILE__, __LINE__);      /* in lock.c */
45 #define dunlock()   _dunlock(__FILE__, __LINE__);    /* in lock.c */
46 #endif
47
48 #define block_device(d, s)          _block_device(__FILE__, __LINE__, (d), s)
49 #define unblock_device(d)           _unblock_device(__FILE__, __LINE__, (d))
50 #define steal_device_lock(d, p, s)  _steal_device_lock(__FILE__, __LINE__, (d), (p), s)
51 #define give_back_device_lock(d, p) _give_back_device_lock(__FILE__, __LINE__, (d), (p))
52
53 /* m_blocked states (mutually exclusive) */
54 enum {
55    BST_NOT_BLOCKED = 0,               /* not blocked */
56    BST_UNMOUNTED,                     /* User unmounted device */
57    BST_WAITING_FOR_SYSOP,             /* Waiting for operator to mount tape */
58    BST_DOING_ACQUIRE,                 /* Opening/validating/moving tape */
59    BST_WRITING_LABEL,                 /* Labeling a tape */
60    BST_UNMOUNTED_WAITING_FOR_SYSOP,   /* User unmounted during wait for op */
61    BST_MOUNT,                         /* Mount request */
62    BST_DESPOOLING,                    /* Despooling -- i.e. multiple writes */
63    BST_RELEASING                      /* Releasing the device */
64 };
65
66 typedef struct s_steal_lock {
67    pthread_t  no_wait_id;             /* id of no wait thread */
68    int        dev_blocked;            /* state */
69    int        dev_prev_blocked;       /* previous blocked state */
70 } bsteal_lock_t;
71
72 /*
73  * Used in unblock() call
74  */
75 enum {
76    DEV_LOCKED = true,
77    DEV_UNLOCKED = false
78 };
79
80 #endif