]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dev.h
kes When applying a storage override, release all previous storage
[bacula/bacula] / bacula / src / stored / dev.h
index 0fa2847e7a280fb2e40e5095f04a006c278b594a..37dc0ddc4f930b3418ba724543873b44cae001ca 100644 (file)
@@ -7,8 +7,8 @@
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
    modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
 #ifndef __DEV_H
 #define __DEV_H 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
-
 #undef DCR                            /* used by Bacula */
 
-#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)
-#define give_back_device_lock(d, p) _give_back_device_lock(__FILE__, __LINE__, (d), (p))
-
 /* Return values from wait_for_sysop() */
 enum {
    W_ERROR = 1,
@@ -143,16 +131,6 @@ enum {
 #define ST_PART_SPOOLED    (1<<18)    /* spooling part */
 #define ST_FREESPACE_OK    (1<<19)    /* Have valid freespace for DVD */
 
-/* m_blocked states (mutually exclusive) */
-enum {
-   BST_NOT_BLOCKED = 0,               /* not blocked */
-   BST_UNMOUNTED,                     /* User unmounted device */
-   BST_WAITING_FOR_SYSOP,             /* Waiting for operator to mount tape */
-   BST_DOING_ACQUIRE,                 /* Opening/validating/moving tape */
-   BST_WRITING_LABEL,                 /* Labeling a tape */
-   BST_UNMOUNTED_WAITING_FOR_SYSOP,   /* User unmounted during wait for op */
-   BST_MOUNT                          /* Mount request */
-};
 
 /* Volume Catalog Information structure definition */
 struct VOLUME_CAT_INFO {
@@ -186,24 +164,11 @@ struct VOLUME_CAT_INFO {
 };
 
 
-typedef struct s_steal_lock {
-   pthread_t  no_wait_id;             /* id of no wait thread */
-   int        dev_blocked;            /* state */
-   int        dev_prev_blocked;       /* previous blocked state */
-} bsteal_lock_t;
-
 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
@@ -227,10 +192,6 @@ public:
    int num_waiting;                   /* number of threads waiting */
    int num_writers;                   /* number of writing threads */
    int reserved_device;               /* number of device reservations */
-
-   /* New access control in process of being implemented */
-// brwlock_t xlock;                   /* New mutual exclusion lock */
-
    int capabilities;                  /* capabilities mask */
    int state;                         /* state mask */
    int dev_errno;                     /* Our own errno */
@@ -238,6 +199,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) */
@@ -379,21 +341,8 @@ public:
    char *bstrerror(void) { return errmsg; };
    char *print_errmsg() { return errmsg; };
 
-#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();                      /* in device.c */
-   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(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 */
@@ -423,14 +372,31 @@ public:
    bool update_pos(DCR *dcr);    /* in dev.c */
    bool update_freespace();      /* in dvd.c */
 
-   void set_blocked(int block) { m_blocked = block; };
-   int  blocked() const { return m_blocked; };
    uint32_t get_file() const { return file; };
-   uint32_t get_block() const { return block_num; };
-   const char *print_blocked() const; /* in dev.c */
-   bool is_blocked() const { return m_blocked != BST_NOT_BLOCKED; };
+   uint32_t get_block_num() const { return block_num; };
    int fd() const { return m_fd; };
 
+   /* 
+    * Locking and blocking calls
+    */
+#ifdef  SD_DEBUG_LOCK
+   void _r_dlock(const char *, int);      /* in lock.c */
+   void _r_dunlock(const char *, int);    /* in lock.c */
+   void _dlock(const char *, int);        /* in lock.c */
+   void _dunlock(const char *, int);      /* in lock.c */
+#else
+   void r_dlock();                        /* in lock.c */
+   void r_dunlock() { dunlock(); }
+   void dlock() { P(m_mutex); } 
+   void dunlock() { V(m_mutex); } 
+#endif
+   void dblock(int why);                  /* in lock.c */
+   void dunblock(bool locked=false);      /* in lock.c */
+   void set_blocked(int block) { m_blocked = block; };
+   int blocked() const { return m_blocked; };
+   bool is_blocked() const { return m_blocked != BST_NOT_BLOCKED; };
+   const char *print_blocked() const;     /* in dev.c */
+
 private:
    bool do_mount(int mount, int timeout);      /* in dev.c */
    void set_mode(int omode);                   /* in dev.c */
@@ -464,13 +430,14 @@ public:
    bool spooling;                     /* set when actually spooling */
    bool despooling;                   /* set when despooling */
    bool despool_wait;                 /* waiting for despooling */
-   bool dev_locked;                   /* set if dev already locked */
+   bool m_dev_locked;                 /* set if dev already locked */
    bool NewVol;                       /* set if new Volume mounted */
    bool WroteVol;                     /* set if Volume written */
    bool NewFile;                      /* set when EOF written */
    bool reserved_device;              /* set if reserve done */
    bool any_volume;                   /* Any OK for dir_find_next... */
    bool attached_to_dev;              /* set when attached to dev */
+   bool volume_in_use;                /* set in dir_find_next_appendable_volume() */
    uint32_t VolFirstIndex;            /* First file index this Volume */
    uint32_t VolLastIndex;             /* Last file index this Volume */
    uint32_t FileIndex;                /* Current File Index */
@@ -488,6 +455,13 @@ public:
    int Copy;                          /* identical copy number */
    int Stripe;                        /* RAIT stripe */
    VOLUME_CAT_INFO VolCatInfo;        /* Catalog info for desired volume */
+
+   /* Methods */
+   bool is_dev_locked() { return m_dev_locked; }
+   void dlock() { dev->dlock(); m_dev_locked = true; }
+   void dunlock() { dev->dunlock(); m_dev_locked = false;}
+   void dblock(int why) { dev->dblock(why); }
+
 };
 
 /*