]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/dev.h
Make SD lock tracing work again. Has not worked for some time.
[bacula/bacula] / bacula / src / stored / dev.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2009 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 using the Device functions in Bacula
30  *  Tape and File storage access
31  *
32  * Kern Sibbald, MM
33  *
34  *   Version $Id$
35  *
36  */
37
38 /*
39  * Some details of how volume and device reservations work
40  *
41  * class VOLRES:
42  *   set_in_use()     volume being used on current drive
43  *   clear_in_use()   no longer being used.  Can be re-used or moved.
44  *   set_swapping()   set volume being moved to another drive
45  *   is_swapping()    volume is being moved to another drive
46  *   clear_swapping() volume normal
47  *
48  * class DEVICE:
49  *   set_load()       set to load volume
50  *   needs_load()     volume must be loaded (i.e. set_load done)
51  *   clear_load()     load done.
52  *   set_unload()     set to unload volume
53  *   needs_unload()    volume must be unloaded
54  *   clear_unload()   volume unloaded
55  *
56  *    reservations are temporary until the drive is acquired
57  *   inc_reserved()   increments num of reservations
58  *   dec_reserved()   decrements num of reservations
59  *   num_reserved()   number of reservations
60  *
61  * class DCR:
62  *   set_reserved()   sets local reserve flag and calls dev->inc_reserved()
63  *   clear_reserved() clears local reserve flag and calls dev->dec_reserved()
64  *   is_reserved()    returns local reserved flag
65  *   unreserve_device()  much more complete unreservation
66  *
67  */
68
69
70 #ifndef __DEV_H
71 #define __DEV_H 1
72
73 #undef DCR                            /* used by Bacula */
74
75 /* Return values from wait_for_sysop() */
76 enum {
77    W_ERROR = 1,
78    W_TIMEOUT,
79    W_POLL,
80    W_MOUNT,
81    W_WAKE
82 };
83
84 /* Arguments to open_dev() */
85 enum {
86    CREATE_READ_WRITE = 1,
87    OPEN_READ_WRITE,
88    OPEN_READ_ONLY,
89    OPEN_WRITE_ONLY
90 };
91
92 /* Device types */
93 enum {
94    B_FILE_DEV = 1,
95    B_TAPE_DEV,
96    B_DVD_DEV,
97    B_FIFO_DEV,
98    B_VTAPE_DEV,                       /* change to B_TAPE_DEV after init */
99    B_VTL_DEV
100 };
101
102 /* Generic status bits returned from status_dev() */
103 #define BMT_TAPE           (1<<0)     /* is tape device */
104 #define BMT_EOF            (1<<1)     /* just read EOF */
105 #define BMT_BOT            (1<<2)     /* at beginning of tape */
106 #define BMT_EOT            (1<<3)     /* end of tape reached */
107 #define BMT_SM             (1<<4)     /* DDS setmark */
108 #define BMT_EOD            (1<<5)     /* DDS at end of data */
109 #define BMT_WR_PROT        (1<<6)     /* tape write protected */
110 #define BMT_ONLINE         (1<<7)     /* tape online */
111 #define BMT_DR_OPEN        (1<<8)     /* tape door open */
112 #define BMT_IM_REP_EN      (1<<9)     /* immediate report enabled */
113
114
115 /* Bits for device capabilities */
116 #define CAP_EOF            (1<<0)     /* has MTWEOF */
117 #define CAP_BSR            (1<<1)     /* has MTBSR */
118 #define CAP_BSF            (1<<2)     /* has MTBSF */
119 #define CAP_FSR            (1<<3)     /* has MTFSR */
120 #define CAP_FSF            (1<<4)     /* has MTFSF */
121 #define CAP_EOM            (1<<5)     /* has MTEOM */
122 #define CAP_REM            (1<<6)     /* is removable media */
123 #define CAP_RACCESS        (1<<7)     /* is random access device */
124 #define CAP_AUTOMOUNT      (1<<8)     /* Read device at start to see what is there */
125 #define CAP_LABEL          (1<<9)     /* Label blank tapes */
126 #define CAP_ANONVOLS       (1<<10)    /* Mount without knowing volume name */
127 #define CAP_ALWAYSOPEN     (1<<11)    /* always keep device open */
128 #define CAP_AUTOCHANGER    (1<<12)    /* AutoChanger */
129 #define CAP_OFFLINEUNMOUNT (1<<13)    /* Offline before unmount */
130 #define CAP_STREAM         (1<<14)    /* Stream device */
131 #define CAP_BSFATEOM       (1<<15)    /* Backspace file at EOM */
132 #define CAP_FASTFSF        (1<<16)    /* Fast forward space file */
133 #define CAP_TWOEOF         (1<<17)    /* Write two eofs for EOM */
134 #define CAP_CLOSEONPOLL    (1<<18)    /* Close device on polling */
135 #define CAP_POSITIONBLOCKS (1<<19)    /* Use block positioning */
136 #define CAP_MTIOCGET       (1<<20)    /* Basic support for fileno and blkno */
137 #define CAP_REQMOUNT       (1<<21)    /* Require mount to read files back (typically: DVD) */
138 #define CAP_CHECKLABELS    (1<<22)    /* Check for ANSI/IBM labels */
139
140 /* Test state */
141 #define dev_state(dev, st_state) ((dev)->state & (st_state))
142
143 /* Device state bits */
144 #define ST_XXXXXX          (1<<0)     /* was ST_OPENED */
145 #define ST_XXXXX           (1<<1)     /* was ST_TAPE */
146 #define ST_XXXX            (1<<2)     /* was ST_FILE */
147 #define ST_XXX             (1<<3)     /* was ST_FIFO */
148 #define ST_XX              (1<<4)     /* was ST_DVD */
149 #define ST_X               (1<<5)     /* was ST_PROG */
150
151 #define ST_LABEL           (1<<6)     /* label found */
152 #define ST_MALLOC          (1<<7)     /* dev packet malloc'ed in init_dev() */
153 #define ST_APPEND          (1<<8)     /* ready for Bacula append */
154 #define ST_READ            (1<<9)     /* ready for Bacula read */
155 #define ST_EOT             (1<<10)    /* at end of tape */
156 #define ST_WEOT            (1<<11)    /* Got EOT on write */
157 #define ST_EOF             (1<<12)    /* Read EOF i.e. zero bytes */
158 #define ST_NEXTVOL         (1<<13)    /* Start writing on next volume */
159 #define ST_SHORT           (1<<14)    /* Short block read */
160 #define ST_MOUNTED         (1<<15)    /* the device is mounted to the mount point */
161 #define ST_MEDIA           (1<<16)    /* Media found in mounted device */
162 #define ST_OFFLINE         (1<<17)    /* set offline by operator */
163 #define ST_PART_SPOOLED    (1<<18)    /* spooling part */
164 #define ST_FREESPACE_OK    (1<<19)    /* Have valid freespace for DVD */
165
166
167 /* Volume Catalog Information structure definition */
168 struct VOLUME_CAT_INFO {
169    /* Media info for the current Volume */
170    uint32_t VolCatJobs;               /* number of jobs on this Volume */
171    uint32_t VolCatFiles;              /* Number of files */
172    uint32_t VolCatBlocks;             /* Number of blocks */
173    uint64_t VolCatBytes;              /* Number of bytes written */
174    uint32_t VolCatParts;              /* Number of parts written */
175    uint32_t VolCatMounts;             /* Number of mounts this volume */
176    uint32_t VolCatErrors;             /* Number of errors this volume */
177    uint32_t VolCatWrites;             /* Number of writes this volume */
178    uint32_t VolCatReads;              /* Number of reads this volume */
179    uint64_t VolCatRBytes;             /* Number of bytes read */
180    uint32_t VolCatRecycles;           /* Number of recycles this volume */
181    uint32_t EndFile;                  /* Last file number */
182    uint32_t EndBlock;                 /* Last block number */
183    int32_t  LabelType;                /* Bacula/ANSI/IBM */
184    int32_t  Slot;                     /* >0=Slot loaded, 0=nothing, -1=unknown */
185    uint32_t VolCatMaxJobs;            /* Maximum Jobs to write to volume */
186    uint32_t VolCatMaxFiles;           /* Maximum files to write to volume */
187    uint64_t VolCatMaxBytes;           /* Max bytes to write to volume */
188    uint64_t VolCatCapacityBytes;      /* capacity estimate */
189    btime_t  VolReadTime;              /* time spent reading */
190    btime_t  VolWriteTime;             /* time spent writing this Volume */
191    int64_t  VolMediaId;               /* MediaId */
192    utime_t  VolFirstWritten;          /* Time of first write */
193    utime_t  VolLastWritten;           /* Time of last write */
194    bool     InChanger;                /* Set if vol in current magazine */
195    char VolCatStatus[20];             /* Volume status */
196    char VolCatName[MAX_NAME_LENGTH];  /* Desired volume to mount */
197 };
198
199
200 class DEVRES;                        /* Device resource defined in stored_conf.h */
201 class DCR; /* forward reference */
202 class VOLRES; /* forward reference */
203
204 /*
205  * Device structure definition. There is one of these for
206  *  each physical device. Everything here is "global" to
207  *  that device and effects all jobs using the device.
208  */
209 class DEVICE {
210 private:
211    int m_fd;                          /* file descriptor */
212    int m_blocked;                     /* set if we must wait (i.e. change tape) */
213    int m_count;                       /* Mutex use count -- DEBUG only */
214    pthread_t m_pid;                   /* Thread that locked -- DEBUG only */
215    bool m_unload;                     /* set when Volume must be unloaded */
216    bool m_load;                       /* set when Volume must be loaded */
217    int m_num_reserved;                /* counter of device reservations */
218    int32_t m_slot;                    /* slot loaded in drive or -1 if none */ 
219
220 public:
221    DEVICE * volatile swap_dev;        /* Swap vol from this device */
222    dlist *attached_dcrs;              /* attached DCR list */
223    pthread_mutex_t m_mutex;           /* access control */
224    pthread_mutex_t spool_mutex;       /* mutex for updating spool_size */
225    pthread_cond_t wait;               /* thread wait variable */
226    pthread_cond_t wait_next_vol;      /* wait for tape to be mounted */
227    pthread_t no_wait_id;              /* this thread must not wait */
228    int dev_prev_blocked;              /* previous blocked state */
229    int num_waiting;                   /* number of threads waiting */
230    int num_writers;                   /* number of writing threads */
231    int capabilities;                  /* capabilities mask */
232    int state;                         /* state mask */
233    int dev_errno;                     /* Our own errno */
234    int mode;                          /* read/write modes */
235    int openmode;                      /* parameter passed to open_dev (useful to reopen the device) */
236    int dev_type;                      /* device type */
237    bool autoselect;                   /* Autoselect in autochanger */
238    bool initiated;                    /* set when init_dev() called */
239    int label_type;                    /* Bacula/ANSI/IBM label types */
240    uint32_t drive_index;              /* Autochanger drive index (base 0) */
241    POOLMEM *dev_name;                 /* Physical device name */
242    POOLMEM *prt_name;                 /* Name used for display purposes */
243    char *errmsg;                      /* nicely edited error message */
244    uint32_t block_num;                /* current block number base 0 */
245    uint32_t LastBlock;                /* last DEV_BLOCK number written to Volume */
246    uint32_t file;                     /* current file number base 0 */
247    uint64_t file_addr;                /* Current file read/write address */
248    uint64_t file_size;                /* Current file size */
249    uint32_t EndBlock;                 /* last block written */
250    uint32_t EndFile;                  /* last file written */
251    uint32_t min_block_size;           /* min block size */
252    uint32_t max_block_size;           /* max block size */
253    uint64_t max_volume_size;          /* max bytes to put on one volume */
254    uint64_t max_file_size;            /* max file size to put in one file on volume */
255    uint64_t max_concurrent_jobs;      /* maximum simultaneous jobs this drive */
256    uint64_t volume_capacity;          /* advisory capacity */
257    uint64_t max_spool_size;           /* maximum spool file size */
258    uint64_t spool_size;               /* current spool size for this device */
259    uint32_t max_rewind_wait;          /* max secs to allow for rewind */
260    uint32_t max_open_wait;            /* max secs to allow for open */
261    uint32_t max_open_vols;            /* max simultaneous open volumes */
262    
263    uint64_t max_part_size;            /* max part size */
264    uint64_t part_size;                /* current part size */
265    uint32_t part;                     /* current part number (starts at 0) */
266    uint64_t part_start;               /* current part start address (relative to the whole volume) */
267    uint32_t num_dvd_parts;            /* number of parts WRITTEN on the DVD */
268    /* state ST_FREESPACE_OK is set if free_space is valid */
269    uint64_t free_space;               /* current free space on medium (without the current part) */
270    int free_space_errno;              /* indicates errno getting freespace */
271    bool truncating;                   /* if set, we are currently truncating the DVD */
272    bool blank_dvd;                    /* if set, we have a blank DVD in the drive */
273    
274    
275    utime_t  vol_poll_interval;        /* interval between polling Vol mount */
276    DEVRES *device;                    /* pointer to Device Resource */
277    VOLRES *vol;                       /* Pointer to Volume reservation item */
278    btimer_t *tid;                     /* timer id */
279
280    VOLUME_CAT_INFO VolCatInfo;        /* Volume Catalog Information */
281    VOLUME_LABEL VolHdr;               /* Actual volume label */
282    char pool_name[MAX_NAME_LENGTH];   /* pool name */
283    char pool_type[MAX_NAME_LENGTH];   /* pool type */
284
285    char UnloadVolName[MAX_NAME_LENGTH];  /* Last wrong Volume mounted */
286    bool poll;                         /* set to poll Volume */
287    /* Device wait times ***FIXME*** look at durations */
288    int min_wait;
289    int max_wait;
290    int max_num_wait;
291    int wait_sec;
292    int rem_wait_sec;
293    int num_wait;
294
295    btime_t last_timer;        /* used by read/write/seek to get stats (usec) */
296    btime_t last_tick;         /* contains last read/write time (usec) */
297
298    btime_t  DevReadTime;
299    btime_t  DevWriteTime;
300    uint64_t DevWriteBytes;
301    uint64_t DevReadBytes;
302
303    /* Methods */
304    btime_t get_timer_count();         /* return the last timer interval (ms) */
305
306    int has_cap(int cap) const { return capabilities & cap; }
307    void clear_cap(int cap) { capabilities &= ~cap; }
308    void set_cap(int cap) { capabilities |= cap; }
309    int is_autochanger() const { return capabilities & CAP_AUTOCHANGER; }
310    int requires_mount() const { return capabilities & CAP_REQMOUNT; }
311    int is_removable() const { return capabilities & CAP_REM; }
312    int is_tape() const { return (dev_type == B_TAPE_DEV || 
313                                  dev_type == B_VTAPE_DEV); }
314    int is_file() const { return dev_type == B_FILE_DEV; }
315    int is_fifo() const { return dev_type == B_FIFO_DEV; }
316    int is_dvd() const  { return dev_type == B_DVD_DEV; }
317    int is_vtl() const  { return dev_type == B_VTL_DEV; }
318    int is_vtape() const  { return dev_type == B_VTAPE_DEV; }
319    int is_open() const { return m_fd >= 0; }
320    int is_offline() const { return state & ST_OFFLINE; }
321    int is_labeled() const { return state & ST_LABEL; }
322    int is_mounted() const { return state & ST_MOUNTED; }
323    int is_unmountable() const { return (is_dvd() || (is_file() && is_removable())); }
324    int num_reserved() const { return m_num_reserved; };
325    int is_part_spooled() const { return state & ST_PART_SPOOLED; }
326    int have_media() const { return state & ST_MEDIA; }
327    int is_short_block() const { return state & ST_SHORT; }
328    int is_busy() const { return (state & ST_READ) || num_writers || num_reserved(); }
329    int at_eof() const { return state & ST_EOF; }
330    int at_eot() const { return state & ST_EOT; }
331    int at_weot() const { return state & ST_WEOT; }
332    int can_append() const { return state & ST_APPEND; }
333    int is_freespace_ok() const { return state & ST_FREESPACE_OK; }
334    /*
335     * can_write() is meant for checking at the end of a job to see
336     * if we still have a tape (perhaps not if at end of tape
337     * and the job is canceled).
338     */
339    int can_write() const { return is_open() && can_append() &&
340                             is_labeled() && !at_weot(); }
341    int can_read() const   { return state & ST_READ; }
342    bool can_steal_lock() const { return m_blocked &&
343                     (m_blocked == BST_UNMOUNTED ||
344                      m_blocked == BST_WAITING_FOR_SYSOP ||
345                      m_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP); };
346    bool waiting_for_mount() const { return 
347                     (m_blocked == BST_UNMOUNTED ||
348                      m_blocked == BST_WAITING_FOR_SYSOP ||
349                      m_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP); };
350    bool must_unload() const { return m_unload; };
351    bool must_load() const { return m_load; };
352    const char *strerror() const;
353    const char *archive_name() const;
354    const char *name() const;
355    const char *print_name() const;    /* Name for display purposes */
356    void set_ateof(); /* in dev.c */
357    void set_ateot(); /* in dev.c */
358    void set_eot() { state |= ST_EOT; };
359    void set_eof() { state |= ST_EOF; };
360    void set_append() { state |= ST_APPEND; };
361    void set_labeled() { state |= ST_LABEL; };
362    inline void set_read() { state |= ST_READ; };
363    void set_offline() { state |= ST_OFFLINE; };
364    void set_mounted() { state |= ST_MOUNTED; };
365    void set_media() { state |= ST_MEDIA; };
366    void set_short_block() { state |= ST_SHORT; };
367    void set_freespace_ok() { state |= ST_FREESPACE_OK; }
368    void set_part_spooled(int val) { if (val) state |= ST_PART_SPOOLED; \
369           else state &= ~ST_PART_SPOOLED;
370    };
371    bool is_volume_to_unload() const { \
372       return m_unload && strcmp(VolHdr.VolumeName, UnloadVolName) == 0; };
373    void set_load() { m_load = true; };
374    void inc_reserved() { m_num_reserved++; }
375    void set_mounted(int val) { if (val) state |= ST_MOUNTED; \
376           else state &= ~ST_MOUNTED; };
377    void dec_reserved() { m_num_reserved--; ASSERT(m_num_reserved>=0); };
378    void clear_append() { state &= ~ST_APPEND; };
379    void clear_read() { state &= ~ST_READ; };
380    void clear_labeled() { state &= ~ST_LABEL; };
381    void clear_offline() { state &= ~ST_OFFLINE; };
382    void clear_eot() { state &= ~ST_EOT; };
383    void clear_eof() { state &= ~ST_EOF; };
384    void clear_opened() { m_fd = -1; };
385    void clear_mounted() { state &= ~ST_MOUNTED; };
386    void clear_media() { state &= ~ST_MEDIA; };
387    void clear_short_block() { state &= ~ST_SHORT; };
388    void clear_freespace_ok() { state &= ~ST_FREESPACE_OK; };
389    void clear_unload() { m_unload = false; UnloadVolName[0] = 0; };
390    void clear_load() { m_load = false; };
391    char *bstrerror(void) { return errmsg; };
392    char *print_errmsg() { return errmsg; };
393    int32_t get_slot() const { return m_slot; };
394
395    void set_unload();            /* in dev.c */
396    void clear_volhdr();          /* in dev.c */
397    void close();                 /* in dev.c */
398    void close_part(DCR *dcr);    /* in dev.c */
399    bool truncate(DCR *dcr);      /* in dev.c */
400    int open(DCR *dcr, int mode); /* in dev.c */
401    void term(void);              /* in dev.c */
402    ssize_t read(void *buf, size_t len); /* in dev.c */
403    ssize_t write(const void *buf, size_t len);  /* in dev.c */
404    bool rewind(DCR *dcr);        /* in dev.c */
405    bool mount(int timeout);      /* in dev.c */
406    bool unmount(int timeout);    /* in dev.c */
407    void edit_mount_codes(POOL_MEM &omsg, const char *imsg); /* in dev.c */
408    bool offline_or_rewind();     /* in dev.c */
409    bool offline();               /* in dev.c */
410    bool bsf(int count);          /* in dev.c */
411    bool eod(DCR *dcr);           /* in dev.c */
412    bool fsr(int num);            /* in dev.c */
413    bool fsf(int num);            /* in dev.c */
414    bool bsr(int num);            /* in dev.c */
415    bool weof(int num);           /* in dev.c */
416    void lock_door();             /* in dev.c */
417    void unlock_door();           /* in dev.c */
418    int32_t get_os_tape_file();   /* in dev.c */
419    bool scan_dir_for_volume(DCR *dcr); /* in scan.c */
420    bool reposition(DCR *dcr, uint32_t rfile, uint32_t rblock); /* in dev.c */
421    void clrerror(int func);      /* in dev.c */
422    boffset_t lseek(DCR *dcr, boffset_t offset, int whence); /* in dev.c */
423    bool update_pos(DCR *dcr);    /* in dev.c */
424    void set_slot(int32_t slot);  /* in dev.c */
425    void clear_slot();            /* in dev.c */
426
427
428    bool update_freespace();      /* in dvd.c */
429
430    uint32_t get_file() const { return file; };
431    uint32_t get_block_num() const { return block_num; };
432    int fd() const { return m_fd; };
433
434    /* low level operations */
435    void init_backend();
436    int (*d_open)(const char *pathname, int flags, ...);
437    int (*d_close)(int fd);
438    int (*d_ioctl)(int fd, ioctl_req_t request, ...);
439    ssize_t (*d_read)(int fd, void *buffer, size_t count);
440    ssize_t (*d_write)(int fd, const void *buffer, size_t count);
441
442    /* 
443     * Locking and blocking calls
444     */
445 #ifdef  SD_DEBUG_LOCK
446    void _r_dlock(const char *, int);      /* in lock.c */
447    void _r_dunlock(const char *, int);    /* in lock.c */
448    void _dlock(const char *, int);        /* in lock.c */
449    void _dunlock(const char *, int);      /* in lock.c */
450 #else
451    void r_dlock();                        /* in lock.c */
452    void r_dunlock() { dunlock(); }
453    void dlock() { P(m_mutex); } 
454    void dunlock() { V(m_mutex); } 
455 #endif
456    void dblock(int why);                  /* in lock.c */
457    void dunblock(bool locked=false);      /* in lock.c */
458    bool is_device_unmounted();            /* in lock.c */
459    void set_blocked(int block) { m_blocked = block; };
460    int blocked() const { return m_blocked; };
461    bool is_blocked() const { return m_blocked != BST_NOT_BLOCKED; };
462    const char *print_blocked() const;     /* in dev.c */
463
464 private:
465    bool do_mount(int mount, int timeout);      /* in dev.c */
466    void set_mode(int omode);                   /* in dev.c */
467    void open_tape_device(DCR *dcr, int omode); /* in dev.c */
468    void open_file_device(DCR *dcr, int omode); /* in dev.c */
469    void open_dvd_device(DCR *dcr, int omode);  /* in dev.c */
470 };
471
472 inline const char *DEVICE::strerror() const { return errmsg; }
473 inline const char *DEVICE::archive_name() const { return dev_name; }
474 inline const char *DEVICE::print_name() const { return prt_name; }
475
476 /*
477  * Device Context (or Control) Record.
478  *  There is one of these records for each Job that is using
479  *  the device. Items in this record are "local" to the Job and
480  *  do not affect other Jobs. Note, a job can have multiple
481  *  DCRs open, each pointing to a different device. 
482  */
483 class DCR {
484 private:
485    bool m_dev_locked;                 /* set if dev already locked */
486    bool m_reserved;                   /* set if reserved device */
487    bool m_found_in_use;               /* set if a volume found in use */
488
489 public:
490    dlink dev_link;                    /* link to attach to dev */
491    JCR *jcr;                          /* pointer to JCR */
492    DEVICE * volatile dev;             /* pointer to device */
493    DEVRES *device;                    /* pointer to device resource */
494    DEV_BLOCK *block;                  /* pointer to block */
495    DEV_RECORD *rec;                   /* pointer to record */
496    pthread_t tid;                     /* Thread running this dcr */
497    int spool_fd;                      /* fd if spooling */
498    bool spool_data;                   /* set to spool data */
499    bool spooling;                     /* set when actually spooling */
500    bool despooling;                   /* set when despooling */
501    bool despool_wait;                 /* waiting for despooling */
502    bool NewVol;                       /* set if new Volume mounted */
503    bool WroteVol;                     /* set if Volume written */
504    bool NewFile;                      /* set when EOF written */
505    bool reserved_volume;              /* set if we reserved a volume */
506    bool any_volume;                   /* Any OK for dir_find_next... */
507    bool attached_to_dev;              /* set when attached to dev */
508    bool keep_dcr;                     /* do not free dcr in release_dcr */
509    uint32_t VolFirstIndex;            /* First file index this Volume */
510    uint32_t VolLastIndex;             /* Last file index this Volume */
511    uint32_t FileIndex;                /* Current File Index */
512    uint32_t EndFile;                  /* End file written */
513    uint32_t StartFile;                /* Start write file */
514    uint32_t StartBlock;               /* Start write block */
515    uint32_t EndBlock;                 /* Ending block written */
516    int64_t  VolMediaId;               /* MediaId */
517    int64_t job_spool_size;            /* Current job spool size */
518    int64_t max_job_spool_size;        /* Max job spool size */
519    char VolumeName[MAX_NAME_LENGTH];  /* Volume name */
520    char pool_name[MAX_NAME_LENGTH];   /* pool name */
521    char pool_type[MAX_NAME_LENGTH];   /* pool type */
522    char media_type[MAX_NAME_LENGTH];  /* media type */
523    char dev_name[MAX_NAME_LENGTH];    /* dev name */
524    int Copy;                          /* identical copy number */
525    int Stripe;                        /* RAIT stripe */
526    VOLUME_CAT_INFO VolCatInfo;        /* Catalog info for desired volume */
527
528    /* Methods */
529    bool found_in_use() const { return m_found_in_use; };
530    void set_found_in_use() { m_found_in_use = true; };
531    void clear_found_in_use() { m_found_in_use = false; };
532    bool is_reserved() const { return m_reserved; };
533    bool is_dev_locked() { return m_dev_locked; }
534 #ifdef SD_DEBUG_LOCK
535    void _dlock(const char *, int);      /* in lock.c */
536    void _dunlock(const char *, int);    /* in lock.c */
537 #else
538    void dlock() { dev->dlock(); m_dev_locked = true; }
539    void dunlock() { m_dev_locked = false; dev->dunlock(); }
540 #endif
541    void dblock(int why) { dev->dblock(why); }
542
543
544    /* Methods in reserve.c */
545    void clear_reserved();
546    void set_reserved();
547    void unreserve_device();
548
549    /* Methods in vol_mgr.c */
550    bool can_i_use_volume();
551    bool can_i_write_volume();
552
553    /* Methods in mount.c */
554    bool mount_next_write_volume();
555    bool mount_next_read_volume();
556    void mark_volume_in_error();
557    void mark_volume_not_inchanger();
558    int try_autolabel(bool opened);
559    bool find_a_volume();
560    bool is_suitable_volume_mounted();
561    bool is_eod_valid();
562    int check_volume_label(bool &ask, bool &autochanger);
563    void release_volume();
564    void do_swapping(bool is_writing);
565    bool do_unload();
566    bool do_load(bool is_writing);
567    bool is_tape_position_ok();
568 };
569
570 /*
571  * Volume reservation class -- see reserve.c
572  */
573 class VOLRES { 
574    bool m_swapping;                   /* set when swapping to another drive */
575    bool m_in_use;                     /* set when volume reserved or in use */
576    int32_t m_slot;                    /* slot of swapping volume */
577    uint32_t m_JobId;                  /* JobId for read volumes */
578 public:
579    dlink link;
580    char *vol_name;                    /* Volume name */
581    DEVICE *dev;                       /* Pointer to device to which we are attached */
582
583    bool is_swapping() const { return m_swapping; };
584    void set_swapping() { m_swapping = true; };
585    void clear_swapping() { m_swapping = false; };
586    bool is_in_use() const { return m_in_use; };
587    void set_in_use() { m_in_use = true; };
588    void clear_in_use() { m_in_use = false; };
589    void set_slot(int32_t slot) { m_slot = slot; };
590    void clear_slot() { m_slot = -1; };
591    int32_t get_slot() const { return m_slot; };
592    uint32_t get_jobid() const { return m_JobId; };
593    void set_jobid(uint32_t JobId) { m_JobId = JobId; };
594 };
595
596
597 /* Get some definition of function to position
598  *  to the end of the medium in MTEOM. System
599  *  dependent. Arrgggg!
600  */
601 #ifndef MTEOM
602 #ifdef  MTSEOD
603 #define MTEOM MTSEOD
604 #endif
605 #ifdef MTEOD
606 #undef MTEOM
607 #define MTEOM MTEOD
608 #endif
609 #endif
610
611 #endif