X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Fdev.h;h=108389760d69b636f6ca45b64e357eac8b44f83c;hb=4cad40b4beba29b87204024e96839131d596a00e;hp=37a9418f189d54e83e32e17e57ee7820be77b2ab;hpb=2a077f08e469e03b56576196f351faba15761b9f;p=bacula%2Fbacula diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 37a9418f18..108389760d 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -39,16 +39,15 @@ #ifndef __DEV_H #define __DEV_H 1 -#undef DCR /* used by Bacula */ - -/* #define NEW_LOCK 1 */ +#ifdef SD_DEBUG_LOCK +#define r_dlock() _r_dlock(__FILE__, __LINE__); /* in device.c */ +#define r_dunlock() _r_dunlock(__FILE__, __LINE__); /* in device.c */ +#define dlock() _dlock(__FILE__, __LINE__); /* in device.c */ +#define dunlock() _dunlock(__FILE__, __LINE__); /* in device.c */ +#endif -#define new_lock_device(dev) _new_lock_device(__FILE__, __LINE__, (dev)) -#define new_lock_device_state(dev,state) _new_lock_device(__FILE__, __LINE__, (dev), (state)) -#define new_unlock_device(dev) _new_unlock_device(__FILE__, __LINE__, (dev)) +#undef DCR /* used by Bacula */ -#define lock_device(d) _lock_device(__FILE__, __LINE__, (d)) -#define unlock_device(d) _unlock_device(__FILE__, __LINE__, (d)) #define block_device(d, s) _block_device(__FILE__, __LINE__, (d), s) #define unblock_device(d) _unblock_device(__FILE__, __LINE__, (d)) #define steal_device_lock(d, p, s) _steal_device_lock(__FILE__, __LINE__, (d), (p), s) @@ -196,6 +195,16 @@ typedef struct s_steal_lock { class DEVRES; /* Device resource defined in stored_conf.h */ class DCR; /* forward reference */ +class VOLRES; /* forward reference */ + +/* + * Used in unblock() call + */ +enum { + dev_locked = true, + dev_unlocked = false +}; + /* * Device structure definition. There is one of these for * each physical device. Everything here is "global" to @@ -205,6 +214,8 @@ class DEVICE { private: int m_fd; /* file descriptor */ int m_blocked; /* set if we must wait (i.e. change tape) */ + int m_count; /* Mutex use count -- DEBUG only */ + pthread_t m_pid; /* Thread that locked -- DEBUG only */ public: dlist *attached_dcrs; /* attached DCR list */ pthread_mutex_t m_mutex; /* access control */ @@ -227,6 +238,7 @@ public: int openmode; /* parameter passed to open_dev (useful to reopen the device) */ int dev_type; /* device type */ bool autoselect; /* Autoselect in autochanger */ + bool initiated; /* set when init_dev() called */ int label_type; /* Bacula/ANSI/IBM label types */ uint32_t drive_index; /* Autochanger drive index (base 0) */ int32_t Slot; /* Slot currently in drive (base 1) */ @@ -264,6 +276,7 @@ public: utime_t vol_poll_interval; /* interval between polling Vol mount */ DEVRES *device; /* pointer to Device Resource */ + VOLRES *vol; /* Pointer to Volume reservation item */ btimer_t *tid; /* timer id */ VOLUME_CAT_INFO VolCatInfo; /* Volume Catalog Information */ @@ -366,11 +379,22 @@ public: void clear_freespace_ok() { state &= ~ST_FREESPACE_OK; }; char *bstrerror(void) { return errmsg; }; char *print_errmsg() { return errmsg; }; - void lock() { P(m_mutex); } - void unlock() { V(m_mutex); } +#ifdef SD_DEBUG_LOCK + void _r_dlock(const char *, int); /* in device.c */ + void _r_dunlock(const char *, int); /* in device.c */ + void _dlock(const char *, int); /* in device.c */ + void _dunlock(const char *, int); /* in device.c */ +#else + void r_dlock(); /* in device.c */ + void r_dunlock() { dunlock(); } + void dlock() { P(m_mutex); } + void dunlock() { V(m_mutex); } +#endif + + void clear_volhdr(); /* in dev.c */ void block(int why); /* in dev.c */ - void unblock(); /* in dev.c */ + void unblock(bool locked=false); /* in dev.c */ void close(); /* in dev.c */ void close_part(DCR *dcr); /* in dev.c */ bool truncate(DCR *dcr); /* in dev.c */ @@ -392,6 +416,7 @@ public: bool weof(int num); /* in dev.c */ void lock_door(); /* in dev.c */ void unlock_door(); /* in dev.c */ + int32_t get_os_tape_file(); /* in dev.c */ bool scan_dir_for_volume(DCR *dcr); /* in scan.c */ bool reposition(DCR *dcr, uint32_t rfile, uint32_t rblock); /* in dev.c */ void clrerror(int func); /* in dev.c */ @@ -415,7 +440,6 @@ private: void open_dvd_device(DCR *dcr, int omode); /* in dev.c */ }; -/* Note, these return int not bool! */ inline const char *DEVICE::strerror() const { return errmsg; } inline const char *DEVICE::archive_name() const { return dev_name; } inline const char *DEVICE::print_name() const { return prt_name; } @@ -435,6 +459,7 @@ public: DEVRES *device; /* pointer to device resource */ DEV_BLOCK *block; /* pointer to block */ DEV_RECORD *rec; /* pointer to record */ + pthread_t tid; /* Thread running this dcr */ int spool_fd; /* fd if spooling */ bool spool_data; /* set to spool data */ bool spooling; /* set when actually spooling */ @@ -474,7 +499,6 @@ public: dlink link; char *vol_name; DEVICE *dev; - DCR *dcr; };