]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/jcr.h
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / jcr.h
1 /*
2  * Bacula JCR Structure definition for Daemons and the Library
3  *  This definition consists of a "Global" definition common
4  *  to all daemons and used by the library routines, and a
5  *  daemon specific part that is enabled with #defines.
6  *
7  * Kern Sibbald, Nov MM
8  *
9  */
10
11 /*
12    Copyright (C) 2000, 2001 Kern Sibbald and John Walker
13
14    This program is free software; you can redistribute it and/or
15    modify it under the terms of the GNU General Public License
16    as published by the Free Software Foundation; either version 2
17    of the License, or (at your option) any later version.
18
19    This program is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22    GNU General Public License for more details.
23
24    You should have received a copy of the GNU General Public License
25    along with this program; if not, write to the Free Software
26    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27  */
28  
29 #ifndef __JCR_H_
30 #define __JCR_H_ 1
31
32 /* Backup/Verify level code */
33 #define L_FULL                   'F'
34 #define L_INCREMENTAL            'I'  /* since last backup */
35 #define L_DIFFERENTIAL           'D'  /* since last full backup */
36 #define L_LEVEL                  'L'
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          'O'  /* verify we can read volume */
41 #define L_VERIFY_DATA            'A'  /* verify data on volume */
42
43
44 /* Job Types */
45 #define JT_BACKUP                'B'
46 #define JT_VERIFY                'V'
47 #define JT_RESTORE               'R'
48 #define JT_CONSOLE               'C'  /* console program */
49
50 /* Job Status */
51 #define JS_Created               'C'
52 #define JS_Running               'R'
53 #define JS_Blocked               'B'
54 #define JS_Terminated            'T'  /* terminated normally */
55 #define JS_ErrorTerminated       'E'
56 #define JS_Errored               'E'
57 #define JS_Differences           'D'  /* Verify differences */
58 #define JS_Cancelled             'A'  /* cancelled by user */
59 #define JS_WaitFD                'F'  /* waiting on File daemon */
60 #define JS_WaitSD                'S'  /* waiting on the Storage daemon */
61 #define JS_WaitMedia             'm'  /* waiting for new media */
62 #define JS_WaitMount             'M'  /* waiting for Mount */
63
64 #define job_cancelled(jcr) \
65   (jcr->JobStatus == JS_Cancelled || jcr->JobStatus == JS_ErrorTerminated)
66
67 typedef void (JCR_free_HANDLER)(struct s_jcr *jcr);
68
69 /* Job Control Record (JCR) */
70 struct s_jcr {
71    /* Global part of JCR common to all daemons */
72    struct s_jcr *next;
73    struct s_jcr *prev;
74    pthread_t my_thread_id;            /* id of thread controlling jcr */
75    pthread_mutex_t mutex;             /* jcr mutex */
76    BSOCK *dir_bsock;                  /* Director bsock or NULL if we are him */
77    BSOCK *store_bsock;                /* Storage connection socket */
78    BSOCK *file_bsock;                 /* File daemon connection socket */
79    JCR_free_HANDLER *daemon_free_jcr; /* Local free routine */
80    int use_count;                     /* use count */
81    char *errmsg;                      /* edited error message */
82    char Job[MAX_NAME_LENGTH];         /* Job name */
83    uint32_t JobId;                    /* Director's JobId */
84    uint32_t VolSessionId;
85    uint32_t VolSessionTime;
86    uint32_t JobFiles;                 /* Number of files written, this job */
87    uint32_t JobErrors;
88    uint64_t JobBytes;                 /* Number of bytes processed this job */
89    int JobStatus;                     /* ready, running, blocked, terminated */ 
90    int JobTermCode;                   /* termination code */
91    int JobType;                       /* backup, restore, verify ... */
92    int level;
93    int authenticated;                 /* set when client authenticated */
94    time_t sched_time;                 /* job schedule time, i.e. when it should start */
95    time_t start_time;                 /* when job actually started */
96    time_t run_time;                   /* used for computing speed */
97    time_t end_time;                   /* job end time */
98    char *VolumeName;                  /* Volume name desired -- pool_memory */
99    char *client_name;                 /* client name */
100    char *sd_auth_key;                 /* SD auth key */
101    MSGS *msgs;                        /* Message resource */
102    DEST *dest_chain;                  /* Job message destination chain */
103    char send_msg[nbytes_for_bits(M_MAX+1)]; /* message bit mask */
104
105    /* Daemon specific part of JCR */
106    /* This should be empty in the library */
107
108 #ifdef DIRECTOR_DAEMON
109    /* Director Daemon specific part of JCR */
110    pthread_t SD_msg_chan;             /* Message channel thread id */
111    pthread_cond_t term_wait;          /* Wait for job termination */
112    int msg_thread_done;               /* Set when Storage message thread terms */
113    BSOCK *ua;                         /* User agent */
114    JOB *job;                          /* Job resource */
115    STORE *store;                      /* Storage resource */
116    CLIENT *client;                    /* Client resource */
117    POOL *pool;                        /* Pool resource */
118    FILESET *fileset;                  /* FileSet resource */
119    CAT *catalog;                      /* Catalog resource */
120    int SDJobStatus;                   /* Storage Job Status */
121    int mode;                          /* manual/auto run */
122    B_DB *db;                          /* database pointer */
123    int MediaId;                       /* DB record IDs associated with this job */
124    int ClientId;                      /* Client associated with file */
125    uint32_t PoolId;                   /* Pool record id */
126    FileId_t FileId;                   /* Last file id inserted */
127    uint32_t FileIndex;                /* Last FileIndex processed */
128    char *fname;                       /* name to put into catalog */
129    int fn_printed;                    /* printed filename */
130    char *stime;                       /* start time for incremental/differential */
131    JOB_DBR jr;                        /* Job record in Database */
132    int RestoreJobId;                  /* Id specified by UA */
133    char *RestoreWhere;                /* Where to restore the files */
134 #endif /* DIRECTOR_DAEMON */
135
136 #ifdef FILE_DAEMON
137    /* File Daemon specific part of JCR */
138    uint32_t num_files_examined;       /* files examined this job */
139    char *last_fname;                  /* last file saved */
140    /*********FIXME********* add missing files and files to be retried */
141    int incremental;                   /* set if incremental for SINCE */
142    time_t mtime;                      /* begin time for SINCE */
143    int mode;                          /* manual/auto run */
144    int status;                        /* job status */
145    long Ticket;                       /* Ticket */
146    int save_level;                    /* save level */
147    char *big_buf;                     /* I/O buffer */
148    char *compress_buf;                /* Compression buffer */
149    char *where;                       /* Root where to restore */
150    int buf_size;                      /* length of buffer */
151    FF_PKT *ff;                        /* Find Files packet */
152    char stored_addr[MAX_NAME_LENGTH]; /* storage daemon address */
153    uint32_t StartFile;
154    uint32_t EndFile;
155    uint32_t StartBlock;
156    uint32_t EndBlock;
157 #endif /* FILE_DAEMON */
158
159 #ifdef STORAGE_DAEMON
160    /* Storage Daemon specific part of JCR */
161    pthread_cond_t job_start_wait;     /* Wait for FD to start Job */
162    int type;
163    DEVRES *device;                    /* device to use */
164    VOLUME_CAT_INFO VolCatInfo;        /* Catalog info for desired volume */
165    char *pool_name;                   /* pool to use */
166    char *pool_type;                   /* pool type to use */
167    char *job_name;                    /* job name */
168    char *media_type;                  /* media type */
169    char *dev_name;                    /* device name */
170    long NumVolumes;                   /* number of volumes used */
171    long CurVolume;                    /* current volume number */
172    int mode;                          /* manual/auto run */
173    int label_status;                  /* device volume label status */
174    int session_opened;
175    DEV_RECORD rec;                    /* Read/Write record */
176    long Ticket;                       /* ticket for this job */
177    uint32_t VolFirstFile;             /* First file index this Volume */
178    uint32_t start_block;              /* Start write block */
179    uint32_t start_file;               /* Start write file */
180    uint32_t end_block;                /* Ending block written */
181    uint32_t end_file;                 /* End file written */
182
183    /* Parmaters for Open Read Session */
184    uint32_t read_VolSessionId;
185    uint32_t read_VolSessionTime;
186    uint32_t read_StartFile;
187    uint32_t read_EndFile;
188    uint32_t read_StartBlock;
189    uint32_t read_EndBlock;
190
191 #endif /* STORAGE_DAEMON */
192
193 }; 
194
195 /* 
196  * Structure for all daemons that keeps some summary
197  *  info on the last job run.
198  */
199 struct s_last_job {
200    int NumJobs;
201    int JobType;
202    int JobStatus;
203    uint32_t JobId;
204    uint32_t VolSessionId;
205    uint32_t VolSessionTime;
206    uint32_t JobFiles;
207    uint64_t JobBytes;
208    time_t start_time;
209    time_t end_time;
210    char Job[MAX_NAME_LENGTH];
211 };
212
213 extern struct s_last_job last_job;
214
215 #undef JCR
216 typedef struct s_jcr JCR;
217
218
219 /* The following routines are found in lib/jcr.c */
220 extern JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr);
221 extern void free_jcr(JCR *jcr);
222 extern void free_locked_jcr(JCR *jcr);
223 extern JCR *get_jcr_by_id(uint32_t JobId);
224 extern JCR *get_jcr_by_partial_name(char *Job);
225 extern JCR *get_jcr_by_full_name(char *Job);
226 extern JCR *get_next_jcr(JCR *jcr);
227 extern void lock_jcr_chain();
228 extern void unlock_jcr_chain();
229
230 #endif /* __JCR_H_ */