1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 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 #ifndef BAREOS_SRC_DIRD_JCR_PRIVATE_H_
25 #define BAREOS_SRC_DIRD_JCR_PRIVATE_H_
26 
27 #include "cats/cats.h"
28 #include "dird/client_connection_handshake_mode.h"
29 
30 typedef struct s_tree_root TREE_ROOT;
31 
32 namespace directordaemon {
33 class JobResource;
34 class StorageResource;
35 class ClientResource;
36 class PoolResource;
37 class FilesetResource;
38 class CatalogResource;
39 }  // namespace directordaemon
40 
41 namespace storagedaemon {
42 struct BootStrapRecord;
43 }  // namespace storagedaemon
44 
45 #define JobWaiting(jcr)                                                       \
46   (jcr->job_started &&                                                        \
47    (jcr->JobStatus == JS_WaitFD || jcr->JobStatus == JS_WaitSD ||             \
48     jcr->JobStatus == JS_WaitMedia || jcr->JobStatus == JS_WaitMount ||       \
49     jcr->JobStatus == JS_WaitStoreRes || jcr->JobStatus == JS_WaitJobRes ||   \
50     jcr->JobStatus == JS_WaitClientRes || jcr->JobStatus == JS_WaitMaxJobs || \
51     jcr->JobStatus == JS_WaitPriority ||                                      \
52     jcr->impl->SDJobStatus == JS_WaitMedia ||                                 \
53     jcr->impl->SDJobStatus == JS_WaitMount ||                                 \
54     jcr->impl->SDJobStatus == JS_WaitDevice ||                                \
55     jcr->impl->SDJobStatus == JS_WaitMaxJobs))
56 
57 /* clang-format off */
58 struct Resources {
59   directordaemon::JobResource* job{};           /**< Job resource */
60   directordaemon::JobResource* verify_job{};    /**< Job resource of verify previous job */
61   directordaemon::JobResource* previous_job{};  /**< Job resource of migration previous job */
62   directordaemon::StorageResource* read_storage{};  /**< Selected read storage */
63   directordaemon::StorageResource* write_storage{}; /**< Selected write storage */
64   directordaemon::StorageResource* paired_read_write_storage{}; /*< Selected paired storage (savedwrite_storage or read_storage)*/
65   directordaemon::ClientResource* client{};     /**< Client resource */
66   directordaemon::PoolResource* pool{};         /**< Pool resource = write for migration */
67   directordaemon::PoolResource* rpool{};        /**< Read pool. Used only in migration */
68   directordaemon::PoolResource* full_pool{};    /**< Full backup pool resource */
69   directordaemon::PoolResource* vfull_pool{};   /**< Virtual Full backup pool resource */
70   directordaemon::PoolResource* inc_pool{};     /**< Incremental backup pool resource */
71   directordaemon::PoolResource* diff_pool{};    /**< Differential backup pool resource */
72   directordaemon::PoolResource* next_pool{};    /**< Next Pool used for migration/copy and virtual backup */
73   directordaemon::FilesetResource* fileset{};   /**< FileSet resource */
74   directordaemon::CatalogResource* catalog{};   /**< Catalog resource */
75   MessagesResource* messages{};   /**< Default message handler */
76   POOLMEM* pool_source{};         /**< Where pool came from */
77   POOLMEM* npool_source{};        /**< Where next pool came from */
78   POOLMEM* rpool_source{};        /**< Where migrate read pool came from */
79   POOLMEM* rstore_source{};       /**< Where read storage came from */
80   POOLMEM* wstore_source{};       /**< Where write storage came from */
81   POOLMEM* catalog_source{};      /**< Where catalog came from */
82   alist* read_storage_list{};     /**< Read storage possibilities */
83   alist* write_storage_list{};    /**< Write storage possibilities */
84   alist* paired_read_write_storage_list{}; /**< Paired storage possibilities (saved write_storage_list or read_storage_list) */
85   bool run_pool_override{};       /**< Pool override was given on run cmdline */
86   bool run_full_pool_override{};  /**< Full pool override was given on run cmdline */
87   bool run_vfull_pool_override{}; /**< Virtual Full pool override was given on run cmdline */
88   bool run_inc_pool_override{};   /**< Incremental pool override was given on run cmdline */
89   bool run_diff_pool_override{};  /**< Differential pool override was given on run cmdline */
90   bool run_next_pool_override{};  /**< Next pool override was given on run cmdline */
91 };
92 
93 struct JobControlRecordPrivate {
JobControlRecordPrivateJobControlRecordPrivate94   JobControlRecordPrivate() {
95     RestoreJobId = 0; MigrateJobId = 0; VerifyJobId = 0;
96   }
97   pthread_t SD_msg_chan{};        /**< Message channel thread id */
98   bool SD_msg_chan_started{};     /**< Message channel thread started */
99   pthread_cond_t term_wait = PTHREAD_COND_INITIALIZER;      /**< Wait for job termination */
100   pthread_cond_t nextrun_ready = PTHREAD_COND_INITIALIZER;  /**< Wait for job next run to become ready */
101   Resources res;                  /**< Resources assigned */
102   TREE_ROOT* restore_tree_root{}; /**< Selected files to restore (some protocols need this info) */
103   storagedaemon::BootStrapRecord* bsr{}; /**< Bootstrap record -- has everything */
104   char* backup_format{};          /**< Backup format used when doing a NDMP backup */
105   char* plugin_options{};         /**< User set options for plugin */
106   uint32_t SDJobFiles{};          /**< Number of files written, this job */
107   uint64_t SDJobBytes{};          /**< Number of bytes processed this job */
108   uint32_t SDErrors{};            /**< Number of non-fatal errors */
109   volatile int32_t SDJobStatus{}; /**< Storage Job Status */
110   volatile int32_t FDJobStatus{}; /**< File daemon Job Status */
111   uint32_t DumpLevel{};           /**< Dump level when doing a NDMP backup */
112   uint32_t ExpectedFiles{};       /**< Expected restore files */
113   uint32_t MediaId{};             /**< DB record IDs associated with this job */
114   uint32_t FileIndex{};           /**< Last FileIndex processed */
115   utime_t MaxRunSchedTime{};      /**< Max run time in seconds from Initial Scheduled time */
116   JobDbRecord jr;                 /**< Job DB record for current job */
117   JobDbRecord previous_jr;        /**< Previous job database record */
118   JobControlRecord* mig_jcr{};    /**< JobControlRecord for migration/copy job */
119   char FSCreateTime[MAX_TIME_LENGTH]{}; /**< FileSet CreateTime as returned from DB */
120   char since[MAX_TIME_LENGTH]{};        /**< Since time */
121   char PrevJob[MAX_NAME_LENGTH]{};      /**< Previous job name assiciated with since time */
122   union {
123     JobId_t RestoreJobId;               /**< Restore JobId specified by UA */
124     JobId_t MigrateJobId;               /**< Migration JobId specified by UA */
125     JobId_t VerifyJobId;                /**< Verify JobId specified by UA */
126   };
127   POOLMEM* fname{};                     /**< Name to put into catalog */
128   POOLMEM* client_uname{};              /**< Client uname */
129   POOLMEM* FDSecureEraseCmd{};          /**< Report: Secure Erase Command  */
130   POOLMEM* SDSecureEraseCmd{};          /**< Report: Secure Erase Command  */
131   POOLMEM* vf_jobids{};                 /**< JobIds to use for Virtual Full */
132   uint32_t replace{};                   /**< Replace option */
133   int32_t NumVols{};                    /**< Number of Volume used in pool */
134   int32_t reschedule_count{};           /**< Number of times rescheduled */
135   int32_t FDVersion{};                  /**< File daemon version number */
136   int64_t spool_size{};                 /**< Spool size for this job */
137   volatile bool sd_msg_thread_done{};   /**< Set when Storage message thread done */
138   bool IgnoreDuplicateJobChecking{};    /**< Set in migration jobs */
139   bool IgnoreLevelPoolOverides{};       /**< Set if a cmdline pool was specified */
140   bool IgnoreClientConcurrency{};       /**< Set in migration jobs */
141   bool IgnoreStorageConcurrency{};      /**< Set in migration jobs */
142   bool spool_data{};                    /**< Spool data in SD */
143   bool acquired_resource_locks{};       /**< Set if resource locks acquired */
144   bool term_wait_inited{};              /**< Set when cond var inited */
145   bool nextrun_ready_inited{};          /**< Set when cond var inited */
146   bool fn_printed{};                    /**< Printed filename */
147   bool needs_sd{};                      /**< Set if SD needed by Job */
148   bool cloned{};                        /**< Set if cloned */
149   bool unlink_bsr{};                    /**< Unlink bsr file created */
150   bool VSS{};                           /**< VSS used by FD */
151   bool Encrypt{};                       /**< Encryption used by FD */
152   bool no_maxtime{};                    /**< Don't check Max*Time for this JobControlRecord */
153   bool keep_sd_auth_key{};              /**< Clear or not the SD auth key after connection*/
154   bool use_accurate_chksum{};           /**< Use or not checksum option in accurate code */
155   bool sd_canceled{};                   /**< Set if SD canceled */
156   bool remote_replicate{};              /**< Replicate data to remote SD */
157   bool HasQuota{};                      /**< Client has quota limits */
158   bool HasSelectedJobs{};               /**< Migration/Copy Job did actually select some JobIds */
159   directordaemon::ClientConnectionHandshakeMode connection_handshake_try_{
160     directordaemon::ClientConnectionHandshakeMode::kUndefined};
161 };
162 /* clang-format on */
163 
164 #endif  // BAREOS_SRC_DIRD_JCR_PRIVATE_H_
165