Skip to content

Commit

Permalink
Print config should suppress data from JobDefs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent f3a62db commit 2d1f2b0
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 87 deletions.
18 changes: 18 additions & 0 deletions src/dird/dird_conf.c
Expand Up @@ -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:
/*
Expand All @@ -2261,13 +2262,15 @@ 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:
/*
* Handle alist resources
*/
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:
Expand All @@ -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:
Expand All @@ -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:
/*
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}

/*
Expand All @@ -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);
}

/*
Expand Down Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/dird/inc_conf.c
Expand Up @@ -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);
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/dird/run_conf.c
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/filed/filed_conf.c
Expand Up @@ -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);
}

/*
Expand Down
15 changes: 13 additions & 2 deletions src/lib/parse_conf.c
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

/*
Expand Down Expand Up @@ -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);
}
}

/*
Expand Down
27 changes: 14 additions & 13 deletions src/lib/parse_conf.h
Expand Up @@ -96,37 +96,38 @@ 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 */
};

/*
* Master Resource configuration structure definition
* 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 */
};

Expand Down

0 comments on commit 2d1f2b0

Please sign in to comment.