From: Michal Rakowski Date: Tue, 25 May 2021 16:51:16 +0000 (+0200) Subject: Tweak bdirjson tool to work with Storage Group Policy X-Git-Tag: Release-11.3.2~523 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87743e3dfb19c32c14094c1faf82137a0e5c6481;p=thirdparty%2Fbacula.git Tweak bdirjson tool to work with Storage Group Policy --- diff --git a/bacula/src/dird/bdirjson.c b/bacula/src/dird/bdirjson.c index 0b6bf2e68..e9ec82585 100644 --- a/bacula/src/dird/bdirjson.c +++ b/bacula/src/dird/bdirjson.c @@ -1376,6 +1376,7 @@ static bool check_resources(bool apply_jobdefs) * Handle strings and directory strings */ if (job_items[i].handler == store_str || + job_items[i].handler == store_storage_mngr || job_items[i].handler == store_dir) { def_svalue = (char **)((char *)(job->jobdefs) + offset); Dmsg5(400, "Job \"%s\", field \"%s\" def_svalue=%s item %d offset=%u\n", diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index 353897d10..aa9e4f25c 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -134,28 +134,6 @@ BSOCK *CLIENT::getBSOCK(int timeout) return globals->socket->get(timeout); } -/* Store a storage group policy */ -void store_storage_mngr(LEX *lc, RES_ITEM *item, int index, int pass) -{ - lex_get_token(lc, T_STRING); - if (pass == 1) { - if (*(item->value)) { - scan_err5(lc, _("Attempt to redefine \"%s\" from \"%s\" to \"%s\" referenced on line %d : %s\n"), - item->name, *(item->value), lc->str, lc->line_no, lc->line); - return; - } - - if (!StorageManager::check_policy(lc->str)) { - scan_err0(lc, _("Invalid storage policy!\n")); - return; - } - - *(item->value) = bstrdup(lc->str); - } - scan_to_eol(lc); - set_bit(index, res_all.hdr.item_present); -} - bool CLIENT::getBSOCK_state(POOLMEM *&buf) { P(globals_mutex); diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index cb9e276a1..d434905bb 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -784,9 +784,6 @@ public: #define GetFileSetResWithName(x) ((FILESET *)GetResWithName(R_FILESET, (x))) #define GetCatalogResWithName(x) ((CAT *)GetResWithName(R_CATALOG, (x))) -/* Director daemon's specific */ -void store_storage_mngr(LEX *lc, RES_ITEM *item, int index, int pass); - /* Imported subroutines */ void store_jobtype(LEX *lc, RES_ITEM *item, int index, int pass); void store_level(LEX *lc, RES_ITEM *item, int index, int pass); diff --git a/bacula/src/dird/store_mngr.h b/bacula/src/dird/store_mngr.h index 876793bfb..fd0ec7e35 100644 --- a/bacula/src/dird/store_mngr.h +++ b/bacula/src/dird/store_mngr.h @@ -29,22 +29,6 @@ /* Forward delcaration */ class STORE; -/* Not so many policies for now... - * Some ideas for next ones: - * - Round robin - * - Most free space - * - Least CPU usage - * - Least network usage - * - A lot more - * - * Some protocol/interface changes will be needed to query all of the storages from - * the list about it's current status, depending of policy used. - */ -static char const *storage_mngmt_policy[] = { - "LeastUsed", - "ListedOrder", - NULL -}; /* * Helper class to make managing each storage type (write/read) easier. @@ -142,17 +126,6 @@ class StorageManager : public SMARTALLOC { StorageManager(const char *policy); - /* Helper to validate if policy user wants to use is a valid one */ - static bool check_policy(const char *policy) { - int i = 0; - while (storage_mngmt_policy[i]) { - if (strcasecmp(policy, storage_mngmt_policy[i]) == 0) { - return true; - } - i++; - } - return false; - } /************ READ STORAGE HELPERS ************/ STORE *get_rstore(); diff --git a/bacula/src/lib/bjson.c b/bacula/src/lib/bjson.c index 5163c90cd..8b1c34372 100644 --- a/bacula/src/lib/bjson.c +++ b/bacula/src/lib/bjson.c @@ -228,6 +228,7 @@ int display_global_item(HPKT &hpkt) display_res(hpkt); } else if (hpkt.ritem->handler == store_str || hpkt.ritem->handler == store_name || + hpkt.ritem->handler == store_storage_mngr || hpkt.ritem->handler == store_password || hpkt.ritem->handler == store_strname || hpkt.ritem->handler == store_dir) { diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index ab5235b02..89f6631b3 100644 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -1003,6 +1003,56 @@ void store_coll_type(LEX *lc, RES_ITEM *item, int index, int pass) set_bit(index, res_all.hdr.item_present); } +/* Not so many policies for now... + * Some ideas for next ones: + * - Most free space + * - Least CPU usage + * - Least network usage + * - ... + * + * Some protocol/interface changes will be needed to query all of the storages from + * the list about it's current status, depending of policy used. + */ +static char const *storage_mngmt_policy[] = { + "LeastUsed", + "ListedOrder", + NULL +}; + +/* Helper to validate if policy user wants to use is a valid one */ +static bool check_policy(const char *policy) { + int i = 0; + while (storage_mngmt_policy[i]) { + if (strcasecmp(policy, storage_mngmt_policy[i]) == 0) { + return true; + } + i++; + } + return false; +} + +/* Store a storage group policy */ +void store_storage_mngr(LEX *lc, RES_ITEM *item, int index, int pass) +{ + lex_get_token(lc, T_STRING); + if (pass == 1) { + if (*(item->value)) { + scan_err5(lc, _("Attempt to redefine \"%s\" from \"%s\" to \"%s\" referenced on line %d : %s\n"), + item->name, *(item->value), lc->str, lc->line_no, lc->line); + return; + } + + if (!check_policy(lc->str)) { + scan_err0(lc, _("Invalid storage policy!\n")); + return; + } + + + *(item->value) = bstrdup(lc->str); + } + scan_to_eol(lc); + set_bit(index, res_all.hdr.item_present); +} /* * diff --git a/bacula/src/lib/parse_conf.h b/bacula/src/lib/parse_conf.h index 3af72eda3..eed3d32e2 100644 --- a/bacula/src/lib/parse_conf.h +++ b/bacula/src/lib/parse_conf.h @@ -379,6 +379,10 @@ void store_defs(LEX *lc, RES_ITEM *item, int index, int pass); void store_label(LEX *lc, RES_ITEM *item, int index, int pass); void store_coll_type(LEX *lc, RES_ITEM *item, int index, int pass); + +/* Director daemon's specific routines */ +void store_storage_mngr(LEX *lc, RES_ITEM *item, int index, int pass); + /* ***FIXME*** eliminate these globals */ extern int32_t r_first; extern int32_t r_last;