Skip to content

Commit

Permalink
config: rename res_head_container_ -> config_resources_container_
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz authored and alaaeddineelamri committed Aug 4, 2022
1 parent 421ef4b commit 4d60c18
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 90 deletions.
3 changes: 0 additions & 3 deletions core/src/console/console_conf.cc
Expand Up @@ -35,9 +35,6 @@

namespace console {

/* static BareosResource* sres_head[R_NUM]; */
/* static BareosResource** res_head = sres_head; */

static bool SaveResource(int type, ResourceItem* items, int pass);
static void FreeResource(BareosResource* sres, int type);
static void DumpResource(int type,
Expand Down
19 changes: 9 additions & 10 deletions core/src/dird/dird_conf.cc
Expand Up @@ -77,8 +77,6 @@ extern struct s_kw RunFields[];
* types. Note, these should be unique for each
* daemon though not a requirement.
*/
/* static BareosResource* sres_head[R_NUM]; */
/* static BareosResource** res_head = sres_head; */
static PoolMem* configure_usage_string = NULL;

extern void StoreInc(LEX* lc, ResourceItem* item, int index, int pass);
Expand Down Expand Up @@ -2533,24 +2531,25 @@ static void StoreDevice(LEX* lc,
ResourceItem* item,
int index,
int pass,
BareosResource** res_head)
BareosResource** configuration_resources)
{
int rindex = R_DEVICE;

if (pass == 1) {
LexGetToken(lc, BCT_NAME);
if (!res_head[rindex]) {
if (!configuration_resources[rindex]) {
DeviceResource* device_resource = new DeviceResource;
device_resource->rcode_ = R_DEVICE;
device_resource->resource_name_ = strdup(lc->str);
res_head[rindex] = device_resource; /* store first entry */
configuration_resources[rindex] = device_resource; /* store first entry */
Dmsg3(900, "Inserting first %s res: %s index=%d\n",
my_config->ResToStr(R_DEVICE), device_resource->resource_name_,
rindex);
} else {
bool found = false;
BareosResource* next;
for (next = res_head[rindex]; next->next_; next = next->next_) {
for (next = configuration_resources[rindex]; next->next_;
next = next->next_) {
if (bstrcmp(next->resource_name_, lc->str)) {
found = true; // already defined
break;
Expand Down Expand Up @@ -2580,7 +2579,7 @@ static void StoreMigtype(LEX* lc,
ResourceItem* item,
int index,
int pass,
BareosResource** res_head)
BareosResource** configuration_resources)
{
LexGetToken(lc, BCT_NAME);
// Store the type both in pass 1 and pass 2
Expand Down Expand Up @@ -3216,7 +3215,7 @@ static void ParseConfigCb(LEX* lc,
ResourceItem* item,
int index,
int pass,
BareosResource** res_head)
BareosResource** configuration_resources)
{
switch (item->type) {
case CFG_TYPE_AUTOPASSWORD:
Expand All @@ -3235,7 +3234,7 @@ static void ParseConfigCb(LEX* lc,
StoreAuthtype(lc, item, index, pass);
break;
case CFG_TYPE_DEVICE:
StoreDevice(lc, item, index, pass, res_head);
StoreDevice(lc, item, index, pass, configuration_resources);
break;
case CFG_TYPE_JOBTYPE:
StoreJobtype(lc, item, index, pass);
Expand All @@ -3256,7 +3255,7 @@ static void ParseConfigCb(LEX* lc,
StoreRunscript(lc, item, index, pass);
break;
case CFG_TYPE_MIGTYPE:
StoreMigtype(lc, item, index, pass, res_head);
StoreMigtype(lc, item, index, pass, configuration_resources);
break;
case CFG_TYPE_INCEXC:
StoreInc(lc, item, index, pass);
Expand Down
8 changes: 4 additions & 4 deletions core/src/dird/jcr_private.h
Expand Up @@ -96,14 +96,14 @@ struct Resources {
};

struct JobControlRecordPrivate {
JobControlRecordPrivate( std::shared_ptr<ResHeadContainer> res_head_container) {
job_res_head_container_ = res_head_container;
JobControlRecordPrivate( std::shared_ptr<ResHeadContainer> configuration_resources_container) {
job_config_resources_container_ = configuration_resources_container;
RestoreJobId = 0; MigrateJobId = 0; VerifyJobId = 0;
}
~JobControlRecordPrivate() {
job_res_head_container_ = nullptr;
job_config_resources_container_ = nullptr;
}
std::shared_ptr<ResHeadContainer> job_res_head_container_;
std::shared_ptr<ResHeadContainer> job_config_resources_container_;
pthread_t SD_msg_chan{}; /**< Message channel thread id */
bool SD_msg_chan_started{}; /**< Message channel thread started */
pthread_cond_t term_wait = PTHREAD_COND_INITIALIZER; /**< Wait for job termination */
Expand Down
9 changes: 5 additions & 4 deletions core/src/dird/job.cc
Expand Up @@ -1627,10 +1627,11 @@ void GetJobStorage(UnifiedStorageResource* store,
JobControlRecord* NewDirectorJcr()
{
JobControlRecord* jcr = new_jcr(DirdFreeJcr);
jcr->impl = new JobControlRecordPrivate(my_config->res_head_container_);
Dmsg1(10, "NewDirectorJcr(): res_head_ is at %p %s\n",
my_config->res_head_container_->res_head_,
my_config->res_head_container_->TimeStampAsString().c_str());
jcr->impl
= new JobControlRecordPrivate(my_config->config_resources_container_);
Dmsg1(10, "NewDirectorJcr(): configuration_resources_ is at %p %s\n",
my_config->config_resources_container_->configuration_resources_,
my_config->config_resources_container_->TimeStampAsString().c_str());
return jcr;
}

Expand Down
14 changes: 9 additions & 5 deletions core/src/dird/ua_output.cc
Expand Up @@ -184,10 +184,13 @@ static void ShowAll(UaContext* ua, bool hide_sensitive_data, bool verbose)
// Skip R_DEVICE since it is really not used or updated
continue;
default:
if (my_config->res_head_container_->res_head_[j]) {
my_config->DumpResourceCb_(
j, my_config->res_head_container_->res_head_[j], bsendmsg, ua,
hide_sensitive_data, verbose);
if (my_config->config_resources_container_
->configuration_resources_[j]) {
my_config->DumpResourceCb_(j,
my_config->config_resources_container_
->configuration_resources_[j],
bsendmsg, ua, hide_sensitive_data,
verbose);
}
break;
}
Expand Down Expand Up @@ -264,7 +267,8 @@ bool show_cmd(UaContext* ua, const char* cmd)
len)) {
type = show_cmd_available_resources[j].type;
if (type > 0) {
res = my_config->res_head_container_->res_head_[type];
res = my_config->config_resources_container_
->configuration_resources_[type];
} else {
res = NULL;
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/dird/ua_server.cc
Expand Up @@ -56,7 +56,9 @@ JobControlRecord* new_control_jcr(const char* base_name, int job_type)
jcr = NewDirectorJcr();

// exclude JT_SYSTEM job from shared config counting
if (job_type == JT_SYSTEM) { jcr->impl->job_res_head_container_ = nullptr; }
if (job_type == JT_SYSTEM) {
jcr->impl->job_config_resources_container_ = nullptr;
}

/* The job and defaults are not really used, but we set them up to ensure that
* everything is correctly initialized. */
Expand Down
5 changes: 1 addition & 4 deletions core/src/filed/filed_conf.cc
Expand Up @@ -56,9 +56,6 @@

namespace filedaemon {

/* static BareosResource* sres_head[R_NUM]; */
/* static BareosResource** res_head = sres_head; */

static bool SaveResource(int type, ResourceItem* items, int pass);
static void FreeResource(BareosResource* sres, int type);
static void DumpResource(int type,
Expand Down Expand Up @@ -232,7 +229,7 @@ static void ParseConfigCb(LEX* lc,
ResourceItem* item,
int index,
int pass,
BareosResource** res_head)
BareosResource** configuration_resources)
{
switch (item->type) {
case CFG_TYPE_CIPHER:
Expand Down
59 changes: 26 additions & 33 deletions core/src/lib/parse_conf.cc
Expand Up @@ -96,8 +96,6 @@ ConfigurationParser::ConfigurationParser()
, r_own_(0)
, own_resource_(nullptr)
, resource_definitions_(0)
/* , res_head_(nullptr) */
/* , res_head_backup_(nullptr) */
, SaveResourceCb_(nullptr)
, DumpResourceCb_(nullptr)
, FreeResourceCb_(nullptr)
Expand Down Expand Up @@ -138,7 +136,7 @@ ConfigurationParser::ConfigurationParser(
err_type_ = err_type;
r_num_ = r_num;
resource_definitions_ = resource_definitions;
res_head_container_.reset(new ResHeadContainer(this));
config_resources_container_.reset(new ResHeadContainer(this));
config_default_filename_
= config_default_filename == nullptr ? "" : config_default_filename;
config_include_dir_ = config_include_dir == nullptr ? "" : config_include_dir;
Expand All @@ -151,17 +149,7 @@ ConfigurationParser::ConfigurationParser(
DumpResourceCb_ = DumpResourceCb;
FreeResourceCb_ = FreeResourceCb;
}
ConfigurationParser::~ConfigurationParser()
{
#if 0
if (res_head_) {
for (int i = 0; i <= r_num_ - 1; i++) {
if (res_head_[i]) { FreeResourceCb_(res_head_[i], i); }
res_head_[i] = nullptr;
}
}
#endif
}
ConfigurationParser::~ConfigurationParser() {}

void ConfigurationParser::InitializeQualifiedResourceNameTypeConverter(
const std::map<int, std::string>& map)
Expand Down Expand Up @@ -208,7 +196,7 @@ bool ConfigurationParser::ParseConfig()
scan_warning_);
if (success && ParseConfigReadyCb_) { ParseConfigReadyCb_(*this); }

res_head_container_->timestamp_ = std::chrono::system_clock::now();
config_resources_container_->timestamp_ = std::chrono::system_clock::now();

return success;
}
Expand Down Expand Up @@ -290,13 +278,15 @@ bool ConfigurationParser::AppendToResourcesChain(BareosResource* new_resource,
return false;
}

if (!res_head_container_->res_head_[rindex]) {
res_head_container_->res_head_[rindex] = new_resource;
if (!config_resources_container_->configuration_resources_[rindex]) {
config_resources_container_->configuration_resources_[rindex]
= new_resource;
Dmsg3(900, "Inserting first %s res: %s index=%d\n", ResToStr(rcode),
new_resource->resource_name_, rindex);
} else { // append
BareosResource* last = nullptr;
BareosResource* current = res_head_container_->res_head_[rindex];
BareosResource* current
= config_resources_container_->configuration_resources_[rindex];
do {
if (bstrcmp(current->resource_name_, new_resource->resource_name_)) {
Emsg2(M_ERROR, 0,
Expand Down Expand Up @@ -521,23 +511,23 @@ bool ConfigurationParser::FindConfigPath(PoolMem& full_path)
// when last job also owning finishes
void ConfigurationParser::ReleasePreviousResourceTable()
{
res_head_container_backup_ = nullptr;
config_resources_container_backup_ = nullptr;
}

// swap the previously saved res_head_previous_ with res_head_
// and release the res_head_previous_
// swap the previously saved configuration_resources_previous_ with
// configuration_resources_ and release the configuration_resources_previous_
void ConfigurationParser::RestoreResourceTable()
{
std::swap(res_head_container_, res_head_container_backup_);
res_head_container_backup_ = nullptr;
std::swap(config_resources_container_, config_resources_container_backup_);
config_resources_container_backup_ = nullptr;
}

// copy the current resource table to res_head_backup_
// and create a new empty res_head_container_
// copy the current resource table to configuration_resources_backup_
// and create a new empty config_resources_container_
void ConfigurationParser::BackupResourceTable()
{
std::swap(res_head_container_, res_head_container_backup_);
res_head_container_.reset(new ResHeadContainer(this));
std::swap(config_resources_container_, config_resources_container_backup_);
config_resources_container_.reset(new ResHeadContainer(this));
}

bool ConfigurationParser::RemoveResource(int rcode, const char* name)
Expand All @@ -554,14 +544,16 @@ bool ConfigurationParser::RemoveResource(int rcode, const char* name)
* resource_definitions must be added. If it is referenced, don't remove it.
*/
last = nullptr;
for (BareosResource* res = res_head_container_->res_head_[rindex]; res;
res = res->next_) {
for (BareosResource* res
= config_resources_container_->configuration_resources_[rindex];
res; res = res->next_) {
if (bstrcmp(res->resource_name_, name)) {
if (!last) {
Dmsg2(900,
_("removing resource %s, name=%s (first resource in list)\n"),
ResToStr(rcode), name);
res_head_container_->res_head_[rindex] = res->next_;
config_resources_container_->configuration_resources_[rindex]
= res->next_;
} else {
Dmsg2(900, _("removing resource %s, name=%s\n"), ResToStr(rcode), name);
last->next_ = res->next_;
Expand Down Expand Up @@ -615,9 +607,10 @@ void ConfigurationParser::DumpResources(bool sendit(void* sock,
bool hide_sensitive_data)
{
for (int i = 0; i <= r_num_ - 1; i++) {
if (res_head_container_->res_head_[i]) {
DumpResourceCb_(i, res_head_container_->res_head_[i], sendit, sock,
hide_sensitive_data, false);
if (config_resources_container_->configuration_resources_[i]) {
DumpResourceCb_(i,
config_resources_container_->configuration_resources_[i],
sendit, sock, hide_sensitive_data, false);
}
}
}
Expand Down
26 changes: 14 additions & 12 deletions core/src/lib/parse_conf.h
Expand Up @@ -185,7 +185,7 @@ typedef void(STORE_RES_HANDLER)(LEX* lc,
ResourceItem* item,
int index,
int pass,
BareosResource** res_head);
BareosResource** configuration_resources);
typedef void(PRINT_RES_HANDLER)(ResourceItem& item,
OutputFormatterResource& send,
bool hide_sensitive_data,
Expand Down Expand Up @@ -219,8 +219,8 @@ class ConfigurationParser {
BareosResource* own_resource_; /* Pointer to own resource */
ResourceTable*
resource_definitions_; /* Pointer to table of permitted resources */
std::shared_ptr<ResHeadContainer> res_head_container_;
std::shared_ptr<ResHeadContainer> res_head_container_backup_;
std::shared_ptr<ResHeadContainer> config_resources_container_;
std::shared_ptr<ResHeadContainer> config_resources_container_backup_;
mutable brwlock_t res_lock_; /* Resource lock */

SaveResourceCb_t SaveResourceCb_;
Expand Down Expand Up @@ -433,30 +433,32 @@ static std::string TPAsString(const std::chrono::system_clock::time_point& tp)
class ResHeadContainer {
public:
std::chrono::time_point<std::chrono::system_clock> timestamp_{};
BareosResource** res_head_ = nullptr;
BareosResource** configuration_resources_ = nullptr;
ConfigurationParser* config_ = nullptr;

ResHeadContainer(ConfigurationParser* config)
{
config_ = config;
int num = config_->r_num_;
res_head_ = (BareosResource**)malloc(num * sizeof(BareosResource*));
configuration_resources_
= (BareosResource**)malloc(num * sizeof(BareosResource*));

for (int i = 0; i < num; i++) { res_head_[i] = nullptr; }
Dmsg1(10, "ResHeadContainer: new res_head_ %p\n", res_head_);
for (int i = 0; i < num; i++) { configuration_resources_[i] = nullptr; }
Dmsg1(10, "ResHeadContainer: new configuration_resources_ %p\n",
configuration_resources_);
}

~ResHeadContainer()
{
Dmsg1(10, "ResHeadContainer freeing %p %s\n", res_head_,
Dmsg1(10, "ResHeadContainer freeing %p %s\n", configuration_resources_,
TPAsString(timestamp_).c_str());
int num = config_->r_num_;
for (int j = 0; j < num; j++) {
config_->FreeResourceCb_(res_head_[j], j);
res_head_[j] = nullptr;
config_->FreeResourceCb_(configuration_resources_[j], j);
configuration_resources_[j] = nullptr;
}
free(res_head_);
res_head_ = nullptr;
free(configuration_resources_);
configuration_resources_ = nullptr;
}

std::string TimeStampAsString() { return TPAsString(timestamp_); }
Expand Down
10 changes: 6 additions & 4 deletions core/src/lib/parse_conf_state_machine.cc
Expand Up @@ -145,7 +145,8 @@ ConfigParserStateMachine::ScanResource(int token)
if (my_config_.store_res_) {
my_config_.store_res_(lexical_parser_, item, resource_item_index,
parser_pass_number_,
my_config_.res_head_container_->res_head_);
my_config_.config_resources_container_
->configuration_resources_);
}
}
} else {
Expand Down Expand Up @@ -281,9 +282,10 @@ void ConfigParserStateMachine::DumpResourcesAfterSecondPass()
{
if (debug_level >= 900 && parser_pass_number_ == 2) {
for (int i = 0; i <= my_config_.r_num_ - 1; i++) {
my_config_.DumpResourceCb_(i,
my_config_.res_head_container_->res_head_[i],
PrintMessage, nullptr, false, false);
my_config_.DumpResourceCb_(
i,
my_config_.config_resources_container_->configuration_resources_[i],
PrintMessage, nullptr, false, false);
}
}
}
Expand Down

0 comments on commit 4d60c18

Please sign in to comment.