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