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