1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2016 Planets Communications B.V.
6    Copyright (C) 2013-2019 Bareos GmbH & Co. KG
7 
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero 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    Affero General Public License for more details.
17 
18    You should have received a copy of the GNU Affero 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 /*
24  * Kern Sibbald, December MM
25  */
26 /**
27  * @file
28  * Includes specific to the Director
29  */
30 #ifndef BAREOS_DIRD_DIRD_H_
31 #define BAREOS_DIRD_DIRD_H_
32 #include "lib/connection_pool.h"
33 #include "lib/runscript.h"
34 #include "lib/breg.h"
35 #include "stored/bsr.h"
36 #include "dird_conf.h"
37 
38 #define DIRECTOR_DAEMON 1
39 
40 #include "dir_plugins.h"
41 #include "cats/cats.h"
42 
43 #include "include/jcr.h"
44 #include "dird/bsr.h"
45 #include "ua.h"
46 #include "jobq.h"
47 
48 namespace directordaemon {
49 
50 /* Used in ua_prune.c and ua_purge.c */
51 
52 struct s_count_ctx {
53    int count;
54 };
55 
56 #define MAX_DEL_LIST_LEN 2000000
57 
58 struct del_ctx {
59    JobId_t *JobId;                    /**< array of JobIds */
60    char *PurgedFiles;                 /**< Array of PurgedFile flags */
61    int num_ids;                       /**< ids stored */
62    int max_ids;                       /**< size of array */
63    int num_del;                       /**< number deleted */
64    int tot_ids;                       /**< total to process */
65 };
66 
67 /* Flags for FindNextVolumeForAppend() */
68 enum {
69   fnv_create_vol = true,
70   fnv_no_create_vol = false,
71   fnv_prune = true,
72   fnv_no_prune = false
73 };
74 
75 enum e_enabled_val {
76    VOL_NOT_ENABLED = 0,
77    VOL_ENABLED = 1,
78    VOL_ARCHIVED = 2
79 };
80 
81 enum e_prtmsg {
82    DISPLAY_ERROR,
83    NO_DISPLAY
84 };
85 
86 enum e_pool_op {
87    POOL_OP_UPDATE,
88    POOL_OP_CREATE
89 };
90 
91 enum e_move_op {
92    VOLUME_IMPORT,
93    VOLUME_EXPORT,
94    VOLUME_MOVE
95 };
96 
97 enum e_slot_flag {
98    can_import = 0x01,
99    can_export = 0x02,
100    by_oper = 0x04,
101    by_mte = 0x08
102 };
103 
104 typedef enum {
105    VOL_LIST_ALL,
106    VOL_LIST_PARTIAL
107 } vol_list_type;
108 
109 typedef enum {
110    slot_type_unknown,             /**< Unknown slot type */
111    slot_type_drive,               /**< Drive slot */
112    slot_type_storage,             /**< Storage slot */
113    slot_type_import,              /**< Import/export slot */
114    slot_type_picker               /**< Robotics */
115 } slot_type_t;
116 
117 typedef enum {
118    slot_status_unknown,          /**< Slot content is unknown */
119    slot_status_empty,            /**< Slot is empty */
120    slot_status_full              /**< Slot is full */
121 } slot_status_t;
122 
123 enum s_mapping_type {
124    LOGICAL_TO_PHYSICAL,
125    PHYSICAL_TO_LOGICAL
126 };
127 
128 /*
129  * Slot list definition
130  */
131 struct vol_list_t {
132    dlink link;                    /**< Link for list */
133    slot_number_t element_address ; /**< scsi element address */
134    slot_flags_t flags;            /**< Slot specific flags see e_slot_flag enum */
135    slot_type_t slot_type;                /**< See slot_type_* */
136    slot_status_t slot_status;          /**< See slot_status_* */
137    slot_number_t bareos_slot_number; /**< Drive number when slot_type_drive or actual slot number */
138    slot_number_t currently_loaded_slot_number; /**< Volume loaded in drive when slot_type_drive */
139    char *VolName;                 /**< Actual Volume Name */
140 };
141 
142 struct changer_vol_list_t {
143    int16_t reference_count;       /**< Number of references to this vol_list */
144    vol_list_type type;            /**< Type of vol_list see vol_list_type enum */
145    utime_t timestamp;             /**< When was this vol_list created */
146    dlist *contents;               /**< Contents of autochanger */
147 };
148 
149 /*
150  * Mapping from logical to physical storage address
151  */
152 struct storage_mapping_t {
153    dlink link;                   /**< Link for list */
154    slot_type_t slot_type;               /**< See slot_type_* */
155    slot_number_t element_address;/**< scsi element address */
156    slot_number_t Slot;           /**< Drive number when slot_type_drive or actual slot number */
157 };
158 
159 
160 
161 #if HAVE_NDMP
162 /**
163  * same as smc_element_address_assignment
164  * from ndmp/smc.h
165  * TODO: check if original definition can be used
166  */
167 struct smc_element_address_assignment {
168 
169   unsigned  mte_addr;   /* media transport element */
170   unsigned  mte_count;
171 
172   unsigned  se_addr;    /* storage element */
173   unsigned  se_count;
174 
175   unsigned  iee_addr; /* import/export element */
176   unsigned  iee_count;
177 
178   unsigned  dte_addr; /* data transfer element */
179   unsigned  dte_count;
180 
181 };
182 
183 struct ndmp_deviceinfo_t {
184   std::string device;
185   std::string model;
186   JobId_t JobIdUsingDevice;
187 };
188 #endif
189 
190 
191 struct runtime_storage_status_t {
192    int32_t NumConcurrentJobs;     /**< Number of concurrent jobs running */
193    int32_t NumConcurrentReadJobs; /**< Number of jobs reading */
194    drive_number_t drives;         /**< Number of drives in autochanger */
195    slot_number_t slots;           /**< Number of slots in autochanger */
196    pthread_mutex_t changer_lock;  /**< Any access to the autochanger is controlled by this lock */
197    unsigned char smc_ident[32];   /**< smc ident info = changer name */
198    changer_vol_list_t *vol_list;  /**< Cached content of autochanger */
199    pthread_mutex_t ndmp_deviceinfo_lock;  /**< Any access to the list devices is controlled by this lock */
200 #if HAVE_NDMP
201    smc_element_address_assignment storage_mapping;/**< smc element assignment */
202    std::list<ndmp_deviceinfo_t> *ndmp_deviceinfo; /**< NDMP device info for devices in this Storage */
203 #endif
204 };
205 
206 struct runtime_client_status_t {
207    int32_t NumConcurrentJobs;     /**< Number of concurrent jobs running */
208 };
209 
210 struct runtime_job_status_t {
211    int32_t NumConcurrentJobs;     /**< Number of concurrent jobs running */
212 };
213 
214 #define INDEX_DRIVE_OFFSET 0
215 #define INDEX_MAX_DRIVES 100
216 #define INDEX_SLOT_OFFSET 100
217 
218 #define FD_VERSION_1 1
219 #define FD_VERSION_2 2
220 #define FD_VERSION_3 3
221 #define FD_VERSION_4 4
222 #define FD_VERSION_5 5
223 #define FD_VERSION_51 51
224 #define FD_VERSION_52 52
225 #define FD_VERSION_53 53
226 #define FD_VERSION_54 54
227 
228 bool DoReloadConfig();
229 
230 } /* namespace directordaemon */
231 
232 #endif // BAREOS_DIRD_DIRD_H_
233