From 9d944d6cf9f8287c09780002170dc559c1354bab Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 23 Jan 2007 15:58:06 +0000 Subject: [PATCH] Fix refresh_toolcontext() always to wipe persistent device filter cache. Add is_long_lived to toolcontext. --- WHATS_NEW | 2 ++ daemons/clvmd/lvm-functions.c | 2 +- lib/commands/toolcontext.c | 27 +++++++++++++++++---------- lib/commands/toolcontext.h | 3 ++- tools/lvmcmdline.c | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 84b3ce2c5..eb28d97df 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,7 @@ Version 2.02.20 - =================================== + Fix refresh_toolcontext() always to wipe persistent device filter cache. + Add is_long_lived to toolcontext. Add --clustered to man pages. Streamline dm_report_field_* interface. Change remaining dmeventd terminology 'register' to 'monitor'. diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c index 6836eaf2b..1acfc9b2f 100644 --- a/daemons/clvmd/lvm-functions.c +++ b/daemons/clvmd/lvm-functions.c @@ -575,7 +575,7 @@ void init_lvhash() /* Called to initialise the LVM context of the daemon */ int init_lvm(int using_gulm) { - if (!(cmd = create_toolcontext(NULL, 0))) { + if (!(cmd = create_toolcontext(NULL, 0, 1))) { log_error("Failed to allocate command context"); return 0; } diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c index 6b61146af..02747df48 100644 --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -575,7 +575,7 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd) filters[0] : composite_filter_create(nr_filt, filters); } -static int _init_filters(struct cmd_context *cmd) +static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache) { const char *dev_cache; struct dev_filter *f3, *f4; @@ -608,8 +608,13 @@ static int _init_filters(struct cmd_context *cmd) if (!*cmd->sys_dir) cmd->dump_filter = 0; - if (!stat(dev_cache, &st) && - (st.st_ctime != config_file_timestamp(cmd->cft)) && + /* + * Only load persistent filter device cache on startup if it is newer + * than the config file and this is not a long-lived process. + */ + if (load_persistent_cache && !cmd->is_long_lived && + !stat(dev_cache, &st) && + (st.st_ctime > config_file_timestamp(cmd->cft)) && !persistent_filter_load(f4, NULL)) log_verbose("Failed to load existing device cache from %s", dev_cache); @@ -881,7 +886,8 @@ static int _init_backup(struct cmd_context *cmd) } /* Entry point */ -struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static) +struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static, + unsigned is_long_lived) { struct cmd_context *cmd; @@ -905,6 +911,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static) memset(cmd, 0, sizeof(*cmd)); cmd->args = the_args; cmd->is_static = is_static; + cmd->is_long_lived = is_long_lived; cmd->hosttags = 0; list_init(&cmd->formats); list_init(&cmd->segtypes); @@ -953,7 +960,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static) if (!_init_dev_cache(cmd)) goto error; - if (!_init_filters(cmd)) + if (!_init_filters(cmd, 1)) goto error; if (!(cmd->mem = dm_pool_create("command", 4 * 1024))) { @@ -1022,10 +1029,10 @@ int refresh_toolcontext(struct cmd_context *cmd) { log_verbose("Reloading config files"); - if (cmd->config_valid) { - if (cmd->dump_filter) - persistent_filter_dump(cmd->filter); - } + /* + * Don't update the persistent filter cache as we will + * perform a full rescan. + */ activation_release(); lvmcache_destroy(); @@ -1064,7 +1071,7 @@ int refresh_toolcontext(struct cmd_context *cmd) if (!_init_dev_cache(cmd)) return 0; - if (!_init_filters(cmd)) + if (!_init_filters(cmd, 0)) return 0; if (!_init_formats(cmd)) diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h index e6effc227..c194255db 100644 --- a/lib/commands/toolcontext.h +++ b/lib/commands/toolcontext.h @@ -65,6 +65,7 @@ struct cmd_context { struct arg *args; char **argv; unsigned is_static; /* Static binary? */ + unsigned is_long_lived; /* Optimises persistent_filter handling */ struct dev_filter *filter; int dump_filter; /* Dump filter when exiting? */ @@ -88,7 +89,7 @@ struct cmd_context { char proc_dir[PATH_MAX]; }; -struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static); +struct cmd_context *create_toolcontext(struct arg *the_args, unsigned is_static, unsigned is_long_lived); void destroy_toolcontext(struct cmd_context *cmd); int refresh_toolcontext(struct cmd_context *cmd); int config_files_changed(struct cmd_context *cmd); diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 554d5559a..2e2127c5d 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -1030,7 +1030,7 @@ struct cmd_context *init_lvm(unsigned is_static) { struct cmd_context *cmd; - if (!(cmd = create_toolcontext(&the_args[0], is_static))) { + if (!(cmd = create_toolcontext(&the_args[0], is_static, 0))) { stack; return NULL; }