From 2d1f2b0364ba00b7a4152966301a8cc50e7ab135 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Sun, 5 Oct 2014 11:45:49 +0200 Subject: [PATCH] Print config should suppress data from JobDefs Some specific config items in the Job resource could be coming from a JobDef so we should not print those values in the actual Job resource. We add a new bitmap analog to item_present bitmap already existing in the RES class. When we mark that bit when we populate the jobdef in the populate_jobdefs() function in src/dird/dird_conf.c we can check this bit in the printing function. (Overhead is currently 80 / 8 = 10 bytes) We also use the same bitmap for defaults so we can use some shortcut logic when printing the config as we then know that the default was set and never replaced by an other setting. We clear the bit in all other parse functions so we know the default is cleared. If the default is replaced with the same value as the original default that is still detected. Only real exception is when omit defaults is set to true then we just like before always print the defaults (but not the data populated from a JobDef.) Fixes #343: Print config should suppress data from JobDefs --- src/dird/dird_conf.c | 18 ++++ src/dird/inc_conf.c | 1 + src/dird/run_conf.c | 1 + src/filed/filed_conf.c | 1 + src/lib/parse_conf.c | 15 +++- src/lib/parse_conf.h | 27 +++--- src/lib/res.c | 183 ++++++++++++++++++++++++--------------- src/stored/stored_conf.c | 4 + 8 files changed, 163 insertions(+), 87 deletions(-) diff --git a/src/dird/dird_conf.c b/src/dird/dird_conf.c index 5673265a087..09a3bc9f8be 100644 --- a/src/dird/dird_conf.c +++ b/src/dird/dird_conf.c @@ -2247,6 +2247,7 @@ bool populate_jobdefs() } *svalue = bstrdup(*def_svalue); set_bit(i, job->hdr.item_present); + set_bit(i, job->hdr.inherit_content); break; case CFG_TYPE_RES: /* @@ -2261,6 +2262,7 @@ bool populate_jobdefs() } *svalue = *def_svalue; set_bit(i, job->hdr.item_present); + set_bit(i, job->hdr.inherit_content); break; case CFG_TYPE_ALIST_RES: /* @@ -2268,6 +2270,7 @@ bool populate_jobdefs() */ if (bit_is_set(i, job->jobdefs->hdr.item_present)) { set_bit(i, job->hdr.item_present); + set_bit(i, job->hdr.inherit_content); } break; case CFG_TYPE_BIT: @@ -2289,6 +2292,7 @@ bool populate_jobdefs() ivalue = (uint32_t *)((char *)job + offset); *ivalue = *def_ivalue; set_bit(i, job->hdr.item_present); + set_bit(i, job->hdr.inherit_content); break; case CFG_TYPE_TIME: case CFG_TYPE_SIZE64: @@ -2303,6 +2307,7 @@ bool populate_jobdefs() lvalue = (int64_t *)((char *)job + offset); *lvalue = *def_lvalue; set_bit(i, job->hdr.item_present); + set_bit(i, job->hdr.inherit_content); break; case CFG_TYPE_BOOL: /* @@ -2314,6 +2319,7 @@ bool populate_jobdefs() bvalue = (bool *)((char *)job + offset); *bvalue = *def_bvalue; set_bit(i, job->hdr.item_present); + set_bit(i, job->hdr.inherit_content); break; default: break; @@ -2409,6 +2415,7 @@ static void store_actiononpurge(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -2454,6 +2461,7 @@ static void store_device(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } else { store_resource(CFG_TYPE_ALIST_RES, lc, item, index, pass); } @@ -2484,6 +2492,7 @@ static void store_migtype(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -2511,6 +2520,7 @@ static void store_jobtype(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -2538,6 +2548,7 @@ static void store_protocoltype(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } static void store_replace(LEX *lc, RES_ITEM *item, int index, int pass) @@ -2562,6 +2573,7 @@ static void store_replace(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -2588,6 +2600,7 @@ static void store_authprotocoltype(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -2615,6 +2628,7 @@ static void store_authtype(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -2642,6 +2656,7 @@ static void store_level(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -2727,6 +2742,7 @@ static void store_acl(LEX *lc, RES_ITEM *item, int index, int pass) break; } set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -2756,6 +2772,7 @@ static void store_audit(LEX *lc, RES_ITEM *item, int index, int pass) break; } set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* * Store a runscript->when in a bit field @@ -3004,6 +3021,7 @@ static void store_runscript(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* diff --git a/src/dird/inc_conf.c b/src/dird/inc_conf.c index 59cc28f163d..29d90919779 100644 --- a/src/dird/inc_conf.c +++ b/src/dird/inc_conf.c @@ -752,6 +752,7 @@ static void store_newinc(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* diff --git a/src/dird/run_conf.c b/src/dird/run_conf.c index b5bc68e2e61..ba1b6dc23a3 100644 --- a/src/dird/run_conf.c +++ b/src/dird/run_conf.c @@ -741,4 +741,5 @@ void store_run(LEX *lc, RES_ITEM *item, int index, int pass) lc->options = options; /* Restore scanner options */ set_bit(index, res_all->res_sch.hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } diff --git a/src/filed/filed_conf.c b/src/filed/filed_conf.c index a6cfa2680e9..b8e0184d403 100644 --- a/src/filed/filed_conf.c +++ b/src/filed/filed_conf.c @@ -519,6 +519,7 @@ static void store_cipher(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* diff --git a/src/lib/parse_conf.c b/src/lib/parse_conf.c index a2cbfc0404e..f69e5aa22da 100644 --- a/src/lib/parse_conf.c +++ b/src/lib/parse_conf.c @@ -454,9 +454,12 @@ RES **CONFIG::new_res_head() */ void CONFIG::init_resource(int type, RES_ITEM *items, int pass) { + URES *res_all; + memset(m_res_all, 0, m_res_all_size); - ((URES *)m_res_all)->hdr.rcode = type; - ((URES *)m_res_all)->hdr.refcnt = 1; + res_all = ((URES *)m_res_all); + res_all->hdr.rcode = type; + res_all->hdr.refcnt = 1; /* * See what pass of the config parsing this is. @@ -559,6 +562,10 @@ void CONFIG::init_resource(int type, RES_ITEM *items, int pass) } break; } + + if (!m_omit_defaults) { + set_bit(i, res_all->hdr.inherit_content); + } } /* @@ -625,6 +632,10 @@ void CONFIG::init_resource(int type, RES_ITEM *items, int pass) } break; } + + if (!m_omit_defaults) { + set_bit(i, res_all->hdr.inherit_content); + } } /* diff --git a/src/lib/parse_conf.h b/src/lib/parse_conf.h index 8cb5105081f..2ad19a0daf4 100644 --- a/src/lib/parse_conf.h +++ b/src/lib/parse_conf.h @@ -96,27 +96,28 @@ struct RES_ITEM { alist **alistvalue; dlist **dlistvalue; }; - int32_t code; /* item code/additional info */ - uint32_t flags; /* flags: See CFG_ITEM_* */ - const char *default_value; /* default value */ + int32_t code; /* Item code/additional info */ + uint32_t flags; /* Flags: See CFG_ITEM_* */ + const char *default_value; /* Default value */ }; /* For storing name_addr items in res_items table */ #define ITEM(x) {(char **)&res_all.x} -#define MAX_RES_ITEMS 80 /* maximum resource items per RES */ +#define MAX_RES_ITEMS 80 /* Maximum resource items per RES */ /* * This is the universal header that is at the beginning of every resource record. */ class RES { public: - RES *next; /* pointer to next resource of this type */ - char *name; /* resource name */ - char *desc; /* resource description */ - uint32_t rcode; /* resource id or type */ - int32_t refcnt; /* reference count for releasing */ - char item_present[MAX_RES_ITEMS]; /* set if item is present in conf file */ + RES *next; /* Pointer to next resource of this type */ + char *name; /* Resource name */ + char *desc; /* Resource description */ + uint32_t rcode; /* Resource id or type */ + int32_t refcnt; /* Reference count for releasing */ + char item_present[MAX_RES_ITEMS]; /* Set if item is present in conf file */ + char inherit_content[MAX_RES_ITEMS]; /* Set if item has inherited content */ }; /* @@ -124,9 +125,9 @@ class RES { * This is the structure that defines the resources that are available to this daemon. */ struct RES_TABLE { - const char *name; /* resource name */ - RES_ITEM *items; /* list of resource keywords */ - uint32_t rcode; /* code if needed */ + const char *name; /* Resource name */ + RES_ITEM *items; /* List of resource keywords */ + uint32_t rcode; /* Code if needed */ uint32_t size; /* Size of resource */ }; diff --git a/src/lib/res.c b/src/lib/res.c index 7ce81041dc4..78ca881dd5d 100644 --- a/src/lib/res.c +++ b/src/lib/res.c @@ -220,6 +220,7 @@ static void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); Dmsg0(900, "Done store_msgs\n"); } @@ -278,7 +279,7 @@ static void scan_types(LEX *lc, MSGSRES *msg, int dest_code, char *where, char * /* * This routine is ONLY for resource names - * Store a name at specified address. + * Store a name at specified address. */ static void store_name(LEX *lc, RES_ITEM *item, int index, int pass) { @@ -296,12 +297,13 @@ static void store_name(LEX *lc, RES_ITEM *item, int index, int pass) */ if (*(item->value)) { scan_err2(lc, _("Attempt to redefine name \"%s\" to \"%s\"."), - *(item->value), lc->str); + *(item->value), lc->str); return; } *(item->value) = bstrdup(lc->str); scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -327,6 +329,7 @@ static void store_strname(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -348,6 +351,7 @@ static void store_str(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -374,6 +378,7 @@ static void store_dir(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -417,6 +422,7 @@ static void store_md5password(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -440,6 +446,7 @@ static void store_clearpassword(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -469,6 +476,7 @@ static void store_res(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -523,6 +531,7 @@ static void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -563,6 +572,7 @@ static void store_alist_str(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -610,6 +620,7 @@ static void store_alist_dir(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -647,6 +658,7 @@ static void store_plugin_names(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -686,6 +698,7 @@ static void store_int32(LEX *lc, RES_ITEM *item, int index, int pass) *(item->i32value) = lc->int32_val; scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -699,6 +712,7 @@ static void store_pint32(LEX *lc, RES_ITEM *item, int index, int pass) *(item->ui32value) = lc->pint32_val; scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -712,6 +726,7 @@ static void store_int64(LEX *lc, RES_ITEM *item, int index, int pass) *(item->i64value) = lc->int64_val; scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -795,6 +810,7 @@ static void store_int_unit(LEX *lc, RES_ITEM *item, int index, int pass, scan_to_eol(lc); } set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); Dmsg0(900, "Leave store_unit\n"); } @@ -866,6 +882,7 @@ static void store_time(LEX *lc, RES_ITEM *item, int index, int pass) scan_to_eol(lc); } set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -886,6 +903,7 @@ static void store_bit(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -906,6 +924,7 @@ static void store_bool(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -933,6 +952,7 @@ static void store_label(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); + clear_bit(index, res_all->hdr.inherit_content); } /* @@ -1438,83 +1458,102 @@ bool BRSRES::print_config(POOL_MEM &buff) print_item = true; } else if (items[i].flags & CFG_ITEM_DEFAULT) { /* - * Check for default values. + * See if the item has inherited content from somewhere. + * If that is true there is no need to check the whole default setting. */ - switch (items[i].type) { - case CFG_TYPE_STR: - case CFG_TYPE_DIR: - case CFG_TYPE_NAME: - case CFG_TYPE_STRNAME: - print_item = !bstrcmp(*(items[i].value), items[i].default_value); - break; - case CFG_TYPE_INT32: - print_item = (*(items[i].i32value) != str_to_int32(items[i].default_value)); - break; - case CFG_TYPE_PINT32: - print_item = (*(items[i].ui32value) != (uint32_t)str_to_int32(items[i].default_value)); - break; - case CFG_TYPE_INT64: - print_item = (*(items[i].i64value) != str_to_int64(items[i].default_value)); - break; - case CFG_TYPE_SPEED: - print_item = (*(items[i].ui64value) != (uint64_t)str_to_int64(items[i].default_value)); - break; - case CFG_TYPE_SIZE64: - print_item = (*(items[i].ui64value) != (uint64_t)str_to_int64(items[i].default_value)); - break; - case CFG_TYPE_SIZE32: - print_item = (*(items[i].ui32value) != (uint32_t)str_to_int32(items[i].default_value)); - break; - case CFG_TYPE_TIME: - print_item = (*(items[i].ui64value) != (uint64_t)str_to_int64(items[i].default_value)); - break; - case CFG_TYPE_BOOL: { - bool default_value = bstrcasecmp(items[i].default_value, "true") || - bstrcasecmp(items[i].default_value, "yes"); + if (!bit_is_set(i, this->hdr.inherit_content)) { + /* + * Check for default values. + */ + switch (items[i].type) { + case CFG_TYPE_STR: + case CFG_TYPE_DIR: + case CFG_TYPE_NAME: + case CFG_TYPE_STRNAME: + print_item = !bstrcmp(*(items[i].value), items[i].default_value); + break; + case CFG_TYPE_INT32: + print_item = (*(items[i].i32value) != str_to_int32(items[i].default_value)); + break; + case CFG_TYPE_PINT32: + print_item = (*(items[i].ui32value) != (uint32_t)str_to_int32(items[i].default_value)); + break; + case CFG_TYPE_INT64: + print_item = (*(items[i].i64value) != str_to_int64(items[i].default_value)); + break; + case CFG_TYPE_SPEED: + print_item = (*(items[i].ui64value) != (uint64_t)str_to_int64(items[i].default_value)); + break; + case CFG_TYPE_SIZE64: + print_item = (*(items[i].ui64value) != (uint64_t)str_to_int64(items[i].default_value)); + break; + case CFG_TYPE_SIZE32: + print_item = (*(items[i].ui32value) != (uint32_t)str_to_int32(items[i].default_value)); + break; + case CFG_TYPE_TIME: + print_item = (*(items[i].ui64value) != (uint64_t)str_to_int64(items[i].default_value)); + break; + case CFG_TYPE_BOOL: { + bool default_value = bstrcasecmp(items[i].default_value, "true") || + bstrcasecmp(items[i].default_value, "yes"); - print_item = (*items[i].boolvalue != default_value); - break; - } - default: - break; + print_item = (*items[i].boolvalue != default_value); + break; + } + default: + break; + } } } else { - switch (items[i].type) { - case CFG_TYPE_STR: - case CFG_TYPE_DIR: - case CFG_TYPE_NAME: - case CFG_TYPE_STRNAME: - print_item = *(items[i].value) != NULL; - break; - case CFG_TYPE_INT32: - print_item = (*(items[i].i32value) > 0); - break; - case CFG_TYPE_PINT32: - print_item = (*(items[i].ui32value) > 0); - break; - case CFG_TYPE_INT64: - print_item = (*(items[i].i64value) > 0); - break; - case CFG_TYPE_SPEED: - print_item = (*(items[i].ui64value) > 0); - break; - case CFG_TYPE_SIZE64: - print_item = (*(items[i].ui64value) > 0); - break; - case CFG_TYPE_SIZE32: - print_item = (*(items[i].ui32value) > 0); - break; - case CFG_TYPE_TIME: - print_item = (*(items[i].ui64value) > 0); - break; - case CFG_TYPE_BOOL: - print_item = (*items[i].boolvalue != false); - break; - default: - break; + /* + * See if the item has inherited content from somewhere. + * If that is true there is no need to check the whole default setting. + */ + if (!bit_is_set(i, this->hdr.inherit_content)) { + switch (items[i].type) { + case CFG_TYPE_STR: + case CFG_TYPE_DIR: + case CFG_TYPE_NAME: + case CFG_TYPE_STRNAME: + print_item = *(items[i].value) != NULL; + break; + case CFG_TYPE_INT32: + print_item = (*(items[i].i32value) > 0); + break; + case CFG_TYPE_PINT32: + print_item = (*(items[i].ui32value) > 0); + break; + case CFG_TYPE_INT64: + print_item = (*(items[i].i64value) > 0); + break; + case CFG_TYPE_SPEED: + print_item = (*(items[i].ui64value) > 0); + break; + case CFG_TYPE_SIZE64: + print_item = (*(items[i].ui64value) > 0); + break; + case CFG_TYPE_SIZE32: + print_item = (*(items[i].ui32value) > 0); + break; + case CFG_TYPE_TIME: + print_item = (*(items[i].ui64value) > 0); + break; + case CFG_TYPE_BOOL: + print_item = (*items[i].boolvalue != false); + break; + default: + break; + } } } + /* + * See if the item has inherited content from somewhere. + */ + if (bit_is_set(i, this->hdr.inherit_content)) { + continue; + } + switch (items[i].type) { case CFG_TYPE_STR: case CFG_TYPE_DIR: diff --git a/src/stored/stored_conf.c b/src/stored/stored_conf.c index 29704222007..6f7e8bc4be9 100644 --- a/src/stored/stored_conf.c +++ b/src/stored/stored_conf.c @@ -320,6 +320,7 @@ static void store_authtype(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -374,6 +375,7 @@ static void store_devtype(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -408,6 +410,7 @@ static void store_io_direction(LEX *lc, RES_ITEM *item, int index, int pass) } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /* @@ -430,6 +433,7 @@ static void store_compressionalgorithm(LEX *lc, RES_ITEM *item, int index, int p } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); + clear_bit(index, res_all.hdr.inherit_content); } /*