]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/jcr.h
Backport from BEE
[bacula/bacula] / bacula / src / jcr.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
5
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.
8
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.
13
14    Bacula® is a registered trademark of Kern Sibbald.
15 */
16 /*
17  * Bacula JCR Structure definition for Daemons and the Library
18  *  This definition consists of a "Global" definition common
19  *  to all daemons and used by the library routines, and a
20  *  daemon specific part that is enabled with #defines.
21  *
22  *  Written by Kern Sibbald, Nov MM
23  */
24
25
26 #ifndef __JCR_H_
27 #define __JCR_H_ 1
28
29 /* Backup/Verify level code. These are stored in the DB */
30 #define L_FULL                   'F'  /* Full backup */
31 #define L_INCREMENTAL            'I'  /* since last backup */
32 #define L_DIFFERENTIAL           'D'  /* since last full backup */
33 #define L_SINCE                  'S'
34 #define L_VERIFY_CATALOG         'C'  /* verify from catalog */
35 #define L_VERIFY_INIT            'V'  /* verify save (init DB) */
36 #define L_VERIFY_VOLUME_TO_CATALOG 'O'  /* verify Volume to catalog entries */
37 #define L_VERIFY_DISK_TO_CATALOG 'd'  /* verify Disk attributes to catalog */
38 #define L_VERIFY_DATA            'A'  /* verify data on volume */
39 #define L_BASE                   'B'  /* Base level job */
40 #define L_NONE                   ' '  /* None, for Restore and Admin */
41 #define L_VIRTUAL_FULL           'f'  /* Virtual full backup */
42
43
44 /* Job Types. These are stored in the DB */
45 #define JT_BACKUP                'B'  /* Backup Job */
46 #define JT_MIGRATED_JOB          'M'  /* A previous backup job that was migrated */
47 #define JT_VERIFY                'V'  /* Verify Job */
48 #define JT_RESTORE               'R'  /* Restore Job */
49 #define JT_CONSOLE               'U'  /* console program */
50 #define JT_SYSTEM                'I'  /* internal system "job" */
51 #define JT_ADMIN                 'D'  /* admin job */
52 #define JT_ARCHIVE               'A'  /* Archive Job */
53 #define JT_JOB_COPY              'C'  /* Copy of a Job */
54 #define JT_COPY                  'c'  /* Copy Job */
55 #define JT_MIGRATE               'g'  /* Migration Job */
56 #define JT_SCAN                  'S'  /* Scan Job */
57
58 /* Job Status. Some of these are stored in the DB */
59 #define JS_Canceled              'A'  /* canceled by user */
60 #define JS_Blocked               'B'  /* blocked */
61 #define JS_Created               'C'  /* created but not yet running */
62 #define JS_Differences           'D'  /* Verify differences */
63 #define JS_ErrorTerminated       'E'  /* Job terminated in error */
64 #define JS_WaitFD                'F'  /* waiting on File daemon */
65 #define JS_DataCommitting        'L'  /* Committing data (last despool) */
66 #define JS_WaitMount             'M'  /* waiting for Mount */
67 #define JS_Running               'R'  /* running */
68 #define JS_WaitSD                'S'  /* waiting on the Storage daemon */
69 #define JS_Terminated            'T'  /* terminated normally */
70 #define JS_Warnings              'W'  /* Terminated normally with warnings */
71
72 #define JS_AttrDespooling        'a'  /* SD despooling attributes */
73 #define JS_WaitClientRes         'c'  /* Waiting for Client resource */
74 #define JS_WaitMaxJobs           'd'  /* Waiting for maximum jobs */
75 #define JS_Error                 'e'  /* Non-fatal error */
76 #define JS_FatalError            'f'  /* Fatal error */
77 #define JS_AttrInserting         'i'  /* Doing batch insert file records */
78 #define JS_WaitJobRes            'j'  /* Waiting for job resource */
79 #define JS_DataDespooling        'l'  /* Doing data despooling */
80 #define JS_WaitMedia             'm'  /* waiting for new media */
81 #define JS_WaitPriority          'p'  /* Waiting for higher priority jobs to finish */
82 #define JS_WaitDevice            'q'  /* Queued waiting for device */
83 #define JS_WaitStoreRes          's'  /* Waiting for storage resource */
84 #define JS_WaitStartTime         't'  /* Waiting for start time */
85
86
87 /* Migration selection types */
88 enum {
89    MT_SMALLEST_VOL = 1,
90    MT_OLDEST_VOL,
91    MT_POOL_OCCUPANCY,
92    MT_POOL_TIME,
93    MT_POOL_UNCOPIED_JOBS,
94    MT_CLIENT,
95    MT_VOLUME,
96    MT_JOB,
97    MT_SQLQUERY
98 };
99
100 #define job_canceled(jcr) \
101   (jcr->JobStatus == JS_Canceled || \
102    jcr->JobStatus == JS_ErrorTerminated || \
103    jcr->JobStatus == JS_FatalError \
104   )
105
106 #define job_waiting(jcr) \
107  (jcr->job_started &&    \
108   (jcr->JobStatus == JS_WaitFD       || \
109    jcr->JobStatus == JS_WaitSD       || \
110    jcr->JobStatus == JS_WaitMedia    || \
111    jcr->JobStatus == JS_WaitMount    || \
112    jcr->JobStatus == JS_WaitStoreRes || \
113    jcr->JobStatus == JS_WaitJobRes   || \
114    jcr->JobStatus == JS_WaitClientRes|| \
115    jcr->JobStatus == JS_WaitMaxJobs  || \
116    jcr->JobStatus == JS_WaitPriority || \
117    jcr->SDJobStatus == JS_WaitMedia  || \
118    jcr->SDJobStatus == JS_WaitMount  || \
119    jcr->SDJobStatus == JS_WaitDevice || \
120    jcr->SDJobStatus == JS_WaitMaxJobs))
121
122
123
124 #define foreach_jcr(jcr) \
125    for (jcr=jcr_walk_start(); jcr; (jcr=jcr_walk_next(jcr)) )
126
127 #define endeach_jcr(jcr) jcr_walk_end(jcr)
128
129 #define SD_APPEND true
130 #define SD_READ   false
131
132 /* Forward referenced structures */
133 class JCR;
134 class BSOCK;
135 struct FF_PKT;
136 class  B_DB;
137 struct ATTR_DBR;
138 class Plugin;
139 struct save_pkt;
140 struct bpContext;
141 struct xattr_private_data_t;
142
143 #ifdef FILE_DAEMON
144 class htable;
145 struct acl_data_t;
146 struct xattr_data_t;
147
148 struct CRYPTO_CTX {
149    bool pki_sign;                     /* Enable PKI Signatures? */
150    bool pki_encrypt;                  /* Enable PKI Encryption? */
151    DIGEST *digest;                    /* Last file's digest context */
152    X509_KEYPAIR *pki_keypair;         /* Encryption key pair */
153    alist *pki_signers;                /* Trusted Signers */
154    alist *pki_recipients;             /* Trusted Recipients */
155    CRYPTO_SESSION *pki_session;       /* PKE Public Keys + Symmetric Session Keys */
156    POOLMEM *pki_session_encoded;      /* Cached DER-encoded copy of pki_session */
157    int32_t pki_session_encoded_size;  /* Size of DER-encoded pki_session */
158    POOLMEM *crypto_buf;               /* Encryption/Decryption buffer */
159 };
160 #endif
161
162 typedef void (JCR_free_HANDLER)(JCR *jcr);
163
164 /* Job Control Record (JCR) */
165 class JCR {
166 private:
167    pthread_mutex_t mutex;             /* jcr mutex */
168    volatile int32_t _use_count;       /* use count */
169    int32_t m_JobType;                 /* backup, restore, verify ... */
170    int32_t m_JobLevel;                /* Job level */
171    bool my_thread_killable;           /* can we kill the thread? */
172 public:
173    void lock() {P(mutex); };
174    void unlock() {V(mutex); };
175    void inc_use_count(void) {lock(); _use_count++; unlock(); };
176    void dec_use_count(void) {lock(); _use_count--; unlock(); };
177    int32_t use_count() const { return _use_count; };
178    void init_mutex(void) {pthread_mutex_init(&mutex, NULL); };
179    void destroy_mutex(void) {pthread_mutex_destroy(&mutex); };
180    bool is_job_canceled() {return job_canceled(this); };
181    bool is_canceled() {return job_canceled(this); };
182    bool is_JobLevel(int32_t JobLevel) { return JobLevel == m_JobLevel; };
183    bool is_JobType(int32_t JobType) { return JobType == m_JobType; };
184    bool is_JobStatus(int32_t aJobStatus) { return aJobStatus == JobStatus; };
185    void setJobLevel(int32_t JobLevel) { m_JobLevel = JobLevel; };
186    void setJobType(int32_t JobType) { m_JobType = JobType; };
187    void forceJobStatus(int32_t aJobStatus) { JobStatus = aJobStatus; };
188    void setJobStarted();
189    int32_t getJobType() const { return m_JobType; };
190    int32_t getJobLevel() const { return m_JobLevel; };
191    int32_t getJobStatus() const { return JobStatus; };
192    bool no_client_used() const {
193       return (m_JobLevel == L_VIRTUAL_FULL);
194    };
195    const char *get_OperationName();       /* in lib/jcr.c */
196    const char *get_ActionName(bool past); /* in lib/jcr.c */
197    void setJobStatus(int newJobStatus);   /* in lib/jcr.c */
198    bool sendJobStatus();                  /* in lib/jcr.c */
199    bool sendJobStatus(int newJobStatus);  /* in lib/jcr.c */
200    bool JobReads();                       /* in lib/jcr.c */
201    void my_thread_send_signal(int sig);   /* in lib/jcr.c */
202    void set_killable(bool killable);      /* in lib/jcr.c */
203    bool is_killable() const { return my_thread_killable; };
204
205    /* Global part of JCR common to all daemons */
206    dlink link;                        /* JCR chain link */
207    pthread_t my_thread_id;            /* id of thread controlling jcr */
208    BSOCK *dir_bsock;                  /* Director bsock or NULL if we are him */
209    BSOCK *store_bsock;                /* Storage connection socket */
210    BSOCK *file_bsock;                 /* File daemon connection socket */
211    JCR_free_HANDLER *daemon_free_jcr; /* Local free routine */
212    dlist *msg_queue;                  /* Queued messages */
213    pthread_mutex_t msg_queue_mutex;   /* message queue mutex */
214    bool dequeuing_msgs;               /* Set when dequeuing messages */
215    alist job_end_push;                /* Job end pushed calls */
216    POOLMEM *VolumeName;               /* Volume name desired -- pool_memory */
217    POOLMEM *errmsg;                   /* edited error message */
218    char Job[MAX_NAME_LENGTH];         /* Unique name of this Job */
219    char event[MAX_NAME_LENGTH];       /* Current event (python) */
220    uint32_t eventType;                /* Current event type (plugin) */
221
222    uint32_t JobId;                    /* Director's JobId */
223    uint32_t VolSessionId;
224    uint32_t VolSessionTime;
225    uint32_t JobFiles;                 /* Number of files written, this job */
226    uint32_t JobErrors;                /* Number of non-fatal errors this job */
227    uint32_t JobWarnings;              /* Number of warning messages */
228    uint32_t LastRate;                 /* Last sample bytes/sec */
229    uint64_t JobBytes;                 /* Number of bytes processed this job */
230    uint64_t LastJobBytes;             /* Last sample number bytes */
231    uint64_t ReadBytes;                /* Bytes read */
232    FileId_t FileId;                   /* Last FileId used */
233    volatile int32_t JobStatus;        /* ready, running, blocked, terminated */
234    int32_t JobPriority;               /* Job priority */
235    time_t sched_time;                 /* job schedule time, i.e. when it should start */
236    time_t initial_sched_time;         /* original sched time before any reschedules are done */
237    time_t start_time;                 /* when job actually started */
238    time_t run_time;                   /* used for computing speed */
239    time_t last_time;                  /* Last sample time */
240    time_t end_time;                   /* job end time */
241    time_t wait_time_sum;              /* cumulative wait time since job start */
242    time_t wait_time;                  /* timestamp when job have started to wait */
243    time_t job_started_time;           /* Time when the MaxRunTime start to count */
244    POOLMEM *client_name;              /* client name */
245    POOLMEM *JobIds;                   /* User entered string of JobIds */
246    POOLMEM *RestoreBootstrap;         /* Bootstrap file to restore */
247    POOLMEM *stime;                    /* start time for incremental/differential */
248    char *sd_auth_key;                 /* SD auth key */
249    MSGS *jcr_msgs;                    /* Copy of message resource -- actually used */
250    uint32_t ClientId;                 /* Client associated with Job */
251    char *where;                       /* prefix to restore files to */
252    char *RegexWhere;                  /* file relocation in restore */
253    alist *where_bregexp;              /* BREGEXP alist for path manipulation */
254    int32_t cached_pnl;                /* cached path length */
255    POOLMEM *cached_path;              /* cached path */
256    bool prefix_links;                 /* Prefix links with Where path */
257    bool gui;                          /* set if gui using console */
258    bool authenticated;                /* set when client authenticated */
259    bool cached_attribute;             /* set if attribute is cached */
260    bool batch_started;                /* is batch mode already started ? */
261    bool cmd_plugin;                   /* Set when processing a command Plugin = */
262    bool opt_plugin;                   /* Set when processing an option Plugin = */
263    bool keep_path_list;               /* Keep newly created path in a hash */
264    bool accurate;                     /* true if job is accurate */
265    bool HasBase;                      /* True if job use base jobs */
266    bool rerunning;                    /* rerunning an incomplete job */
267    bool job_started;                  /* Set when the job is actually started */
268    bool sd_calls_client;              /* Set for SD to call client (FD/SD) */
269
270    void *Python_job;                  /* Python Job Object */
271    void *Python_events;               /* Python Events Object */
272    POOLMEM *attr;                     /* Attribute string from SD */
273    B_DB *db;                          /* database pointer */
274    B_DB *db_batch;                    /* database pointer for batch and accurate */
275    uint64_t nb_base_files;            /* Number of base files */
276    uint64_t nb_base_files_used;       /* Number of useful files in base */
277
278    ATTR_DBR *ar;                      /* DB attribute record */
279    guid_list *id_list;                /* User/group id to name list */
280
281    bpContext *plugin_ctx_list;        /* list of contexts for plugins */
282    bpContext *plugin_ctx;             /* current plugin context */
283    Plugin *plugin;                    /* plugin instance */
284    save_pkt *plugin_sp;               /* plugin save packet */
285    char *plugin_options;              /* user set options for plugin */
286    POOLMEM *comment;                  /* Comment for this Job */
287    int64_t max_bandwidth;             /* Bandwidth limit for this Job */
288    htable *path_list;                 /* Directory list (used by findlib) */
289
290    /* Daemon specific part of JCR */
291    /* This should be empty in the library */
292
293 #ifdef DIRECTOR_DAEMON
294    /* Director Daemon specific data part of JCR */
295    pthread_t SD_msg_chan;             /* Message channel thread id */
296    pthread_cond_t term_wait;          /* Wait for job termination */
297    workq_ele_t *work_item;            /* Work queue item if scheduled */
298    BSOCK *ua;                         /* User agent */
299    JOB *job;                          /* Job resource */
300    JOB *verify_job;                   /* Job resource of verify previous job */
301    alist *plugin_config;              /* List of ConfigFile needed for restore */
302    alist *rstorage;                   /* Read storage possibilities */
303    STORE *rstore;                     /* Selected read storage */
304    alist *wstorage;                   /* Write storage possibilities */
305    STORE *wstore;                     /* Selected write storage */
306    CLIENT *client;                    /* Client resource */
307    POOL *pool;                        /* Pool resource = write for migration */
308    POOL *next_pool;                   /* Next pool override */
309    POOL *rpool;                       /* Read pool. Used only in migration */
310    POOL *full_pool;                   /* Full backup pool resource */
311    POOL *inc_pool;                    /* Incremental backup pool resource */
312    POOL *diff_pool;                   /* Differential backup pool resource */
313    FILESET *fileset;                  /* FileSet resource */
314    CAT *catalog;                      /* Catalog resource */
315    MSGS *messages;                    /* Default message handler */
316    uint32_t SDJobFiles;               /* Number of files written, this job */
317    uint64_t SDJobBytes;               /* Number of bytes processed this job */
318    uint32_t SDErrors;                 /* Number of non-fatal errors */
319    volatile int32_t SDJobStatus;      /* Storage Job Status */
320    volatile int32_t FDJobStatus;      /* File daemon Job Status */
321    uint32_t ExpectedFiles;            /* Expected restore files */
322    uint32_t MediaId;                  /* DB record IDs associated with this job */
323    uint32_t FileIndex;                /* Last FileIndex processed */
324    utime_t MaxRunSchedTime;           /* max run time in seconds from Initial Scheduled time */
325    POOLMEM *fname;                    /* name to put into catalog */
326    POOLMEM *media_type;               /* Set if user supplied Storage */
327    JOB_DBR jr;                        /* Job DB record for current job */
328    JOB_DBR previous_jr;               /* previous job database record */
329    JOB *previous_job;                 /* Job resource of migration previous job */
330    JCR *wjcr;                         /* JCR for migration/copy write job */
331    char FSCreateTime[MAX_TIME_LENGTH]; /* FileSet CreateTime as returned from DB */
332    char since[MAX_TIME_LENGTH];       /* since time */
333    char PrevJob[MAX_NAME_LENGTH];     /* Previous job name assiciated with since time */
334    union {
335       JobId_t RestoreJobId;           /* Id specified by UA */
336       JobId_t MigrateJobId;
337    };
338    POOLMEM *client_uname;             /* client uname */
339    POOLMEM *pool_source;              /* Where pool came from */
340    POOLMEM *next_pool_source;         /* Where next pool came from */
341    POOLMEM *rpool_source;             /* Where migrate read pool came from */
342    POOLMEM *rstore_source;            /* Where read storage came from */
343    POOLMEM *wstore_source;            /* Where write storage came from */
344    POOLMEM *catalog_source;           /* Where catalog came from */
345    uint32_t replace;                  /* Replace option */
346    int32_t NumVols;                   /* Number of Volume used in pool */
347    int32_t reschedule_count;          /* Number of times rescheduled */
348    int32_t FDVersion;                 /* File daemon version number */
349    int32_t SDVersion;                 /* Storage daemon version number */
350    int64_t spool_size;                /* Spool size for this job */
351    volatile bool sd_msg_thread_done;  /* Set when Storage message thread done */
352    bool wasVirtualFull;               /* set if job was VirtualFull */
353    bool IgnoreDuplicateJobChecking;   /* set in migration jobs */
354    bool spool_data;                   /* Spool data in SD */
355    bool acquired_resource_locks;      /* set if resource locks acquired */
356    bool term_wait_inited;             /* Set when cond var inited */
357    bool fn_printed;                   /* printed filename */
358    bool write_part_after_job;         /* Write part after job in SD */
359    bool needs_sd;                     /* set if SD needed by Job */
360    bool cloned;                       /* set if cloned */
361    bool unlink_bsr;                   /* Unlink bsr file created */
362    bool VSS;                          /* VSS used by FD */
363    bool Encrypt;                      /* Encryption used by FD */
364    bool stats_enabled;                /* Keep all job records in a table for long term statistics */
365    bool no_maxtime;                   /* Don't check Max*Time for this JCR */
366    bool keep_sd_auth_key;             /* Clear or not the SD auth key after connection*/
367    bool use_accurate_chksum;          /* Use or not checksum option in accurate code */
368    bool run_pool_override;
369    bool run_next_pool_override;       /* Next pool is overridden */
370    bool run_full_pool_override;
371    bool run_inc_pool_override;
372    bool run_diff_pool_override;
373    bool sd_canceled;                  /* set if SD canceled */
374    bool RescheduleIncompleteJobs;     /* set if incomplete can be rescheduled */
375    bool use_all_JobIds;               /* Use all jobids present in command line */
376    bool sd_client;                    /* This job runs as SD client */
377 #endif /* DIRECTOR_DAEMON */
378
379
380 #ifdef FILE_DAEMON
381    /* File Daemon specific part of JCR */
382    uint32_t num_files_examined;       /* files examined this job */
383    POOLMEM *last_fname;               /* last file saved/verified */
384    POOLMEM *job_metadata;             /* VSS job metadata */
385    pthread_cond_t job_start_wait;     /* Wait for SD to start Job */
386    acl_data_t *acl_data;              /* ACLs for backup/restore */
387    xattr_data_t *xattr_data;          /* Extended Attributes for backup/restore */
388    int32_t last_type;                 /* type of last file saved/verified */
389    int incremental;                   /* set if incremental for SINCE */
390    time_t last_stat_time;             /* Last time stats sent to Dir */
391    time_t stat_interval;              /* Stats send interval */
392    utime_t mtime;                     /* begin time for SINCE */
393    int listing;                       /* job listing in estimate */
394    long Ticket;                       /* Ticket */
395    char *big_buf;                     /* I/O buffer */
396    POOLMEM *compress_buf;             /* Compression buffer */
397    int32_t compress_buf_size;         /* Length of compression buffer */
398    void *pZLIB_compress_workset;      /* zlib compression session data */
399    void *LZO_compress_workset;        /* lzo compression session data */
400    int32_t replace;                   /* Replace options */
401    int32_t buf_size;                  /* length of buffer */
402    FF_PKT *ff;                        /* Find Files packet */
403    char stored_addr[MAX_NAME_LENGTH]; /* storage daemon address */
404    char PrevJob[MAX_NAME_LENGTH];     /* Previous job name assiciated with since time */
405    uint32_t ExpectedFiles;            /* Expected restore files */
406    uint32_t StartFile;
407    uint32_t EndFile;
408    uint32_t StartBlock;
409    uint32_t EndBlock;
410    pthread_t heartbeat_id;            /* id of heartbeat thread */
411    volatile bool hb_started;          /* heartbeat running */
412    BSOCK *hb_bsock;                   /* duped SD socket */
413    BSOCK *hb_dir_bsock;               /* duped DIR socket */
414    alist *RunScripts;                 /* Commands to run before and after job */
415    CRYPTO_CTX crypto;                 /* Crypto ctx */
416    DIRRES* director;                  /* Director resource */
417    bool VSS;                          /* VSS used by FD */
418    bool got_metadata;                 /* set when found job_metatdata */
419    bool multi_restore;                /* Dir can do multiple storage restore */
420    htable *file_list;                 /* Previous file list (accurate mode) */
421    uint64_t base_size;                /* compute space saved with base job */
422 #endif /* FILE_DAEMON */
423
424
425 #ifdef STORAGE_DAEMON
426    /* Storage Daemon specific part of JCR */
427    JCR *next_dev;                     /* next JCR attached to device */
428    JCR *prev_dev;                     /* previous JCR attached to device */
429    char *dir_auth_key;                /* Dir auth key */
430    pthread_cond_t job_start_wait;     /* Wait for FD to start Job */
431    int32_t type;
432    DCR *read_dcr;                     /* device context for reading */
433    DCR *dcr;                          /* device context record */
434    alist *dcrs;                       /* list of dcrs open */
435    POOLMEM *job_name;                 /* base Job name (not unique) */
436    POOLMEM *fileset_name;             /* FileSet */
437    POOLMEM *fileset_md5;              /* MD5 for FileSet */
438    char stored_addr[MAX_NAME_LENGTH]; /* storage daemon address */
439    char client_addr[MAX_NAME_LENGTH]; /* client daemon address */
440    VOL_LIST *VolList;                 /* list to read */
441    int32_t NumWriteVolumes;           /* number of volumes written */
442    int32_t NumReadVolumes;            /* total number of volumes to read */
443    int32_t CurReadVolume;             /* current read volume number */
444    int32_t label_errors;              /* count of label errors */
445    int32_t DIRVersion;                /* Director version number */
446    int32_t FDVersion;                 /* File daemon version number */
447    int32_t SDVersion;                 /* Storage daemon version number */
448    bool session_opened;
449    long Ticket;                       /* ticket for this job */
450    bool ignore_label_errors;          /* ignore Volume label errors */
451    bool spool_attributes;             /* set if spooling attributes */
452    bool no_attributes;                /* set if no attributes wanted */
453    int64_t spool_size;                /* Spool size for this job */
454    bool spool_data;                   /* set to spool data */
455    int32_t CurVol;                    /* Current Volume count */
456    DIRRES* director;                  /* Director resource */
457    alist *write_store;                /* list of write storage devices sent by DIR */
458    alist *read_store;                 /* list of read devices sent by DIR */
459    alist *reserve_msgs;               /* reserve fail messages */
460    bool write_part_after_job;         /* Set to write part after job */
461    bool PreferMountedVols;            /* Prefer mounted vols rather than new */
462    bool Resched;                      /* Job may be rescheduled */
463    bool bscan_insert_jobmedia_records; /*Bscan: needs to insert job media records */
464    bool sd_client;                    /* Set if acting as client */
465
466    /* Parmaters for Open Read Session */
467    BSR *bsr;                          /* Bootstrap record -- has everything */
468    bool mount_next_volume;            /* set to cause next volume mount */
469    uint32_t read_VolSessionId;
470    uint32_t read_VolSessionTime;
471    uint32_t read_StartFile;
472    uint32_t read_EndFile;
473    uint32_t read_StartBlock;
474    uint32_t read_EndBlock;
475    /* Device wait times */
476    int32_t min_wait;
477    int32_t max_wait;
478    int32_t max_num_wait;
479    int32_t wait_sec;
480    int32_t rem_wait_sec;
481    int32_t num_wait;
482 #endif /* STORAGE_DAEMON */
483
484 };
485
486 /*
487  * Setting a NULL in tsd doesn't clear the tsd but instead tells
488  *   pthreads not to call the tsd destructor. Consequently, we
489  *   define this *invalid* jcr address and stuff it in the tsd
490  *   when the jcr is not valid.
491  */
492 #define INVALID_JCR ((JCR *)(-1))
493
494
495 /*
496  * Structure for all daemons that keeps some summary
497  *  info on the last job run.
498  */
499 struct s_last_job {
500    dlink link;
501    int32_t Errors;                    /* FD/SD errors */
502    int32_t JobType;
503    int32_t JobStatus;
504    int32_t JobLevel;
505    uint32_t JobId;
506    uint32_t VolSessionId;
507    uint32_t VolSessionTime;
508    uint32_t JobFiles;
509    uint64_t JobBytes;
510    utime_t start_time;
511    utime_t end_time;
512    char Job[MAX_NAME_LENGTH];
513 };
514
515 extern struct s_last_job last_job;
516 extern DLL_IMP_EXP dlist *last_jobs;
517
518
519 /* The following routines are found in lib/jcr.c */
520 extern int get_next_jobid_from_list(char **p, uint32_t *JobId);
521 extern bool init_jcr_subsystem(void);
522 extern JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr);
523 extern JCR *get_jcr_by_id(uint32_t JobId);
524 extern JCR *get_jcr_by_session(uint32_t SessionId, uint32_t SessionTime);
525 extern JCR *get_jcr_by_partial_name(char *Job);
526 extern JCR *get_jcr_by_full_name(char *Job);
527 extern JCR *get_next_jcr(JCR *jcr);
528 extern void set_jcr_job_status(JCR *jcr, int JobStatus);
529 extern int DLL_IMP_EXP num_jobs_run;
530
531 #ifdef DEBUG
532 extern void b_free_jcr(const char *file, int line, JCR *jcr);
533 #define free_jcr(jcr) b_free_jcr(__FILE__, __LINE__, (jcr))
534 #else
535 extern void free_jcr(JCR *jcr);
536 #endif
537
538 /* Used to display specific job information after a fatal signal */
539 typedef void (dbg_jcr_hook_t)(JCR *jcr, FILE *fp);
540 extern void dbg_jcr_add_hook(dbg_jcr_hook_t *fct);
541
542 #endif /* __JCR_H_ */