From ca1287936b99917c0e875d29eab7b8e4f42808fd Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Mon, 14 Nov 2011 16:51:46 +0100 Subject: [PATCH] Flush mntent cache on exit. Any daemon that uses fstype should call the flush_mntent_cache function as the fstype on Linux and OSF1 uses the mntent cache for mountpoint lookups. --- bacula/src/filed/filed.c | 2 ++ bacula/src/lib/mntent_cache.c | 26 ++++++++++++-------------- bacula/src/lib/mntent_cache.h | 1 + bacula/src/tools/fstype.c | 3 +++ bacula/src/tools/testfind.c | 3 +++ 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index 79dd1928aa..9526879b52 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -34,6 +34,7 @@ #include "bacula.h" #include "filed.h" +#include "lib/mntent_cache.h" #ifdef HAVE_PYTHON @@ -295,6 +296,7 @@ void terminate_filed(int sig) bnet_stop_thread_server(server_tid); generate_daemon_event(NULL, "Exit"); unload_plugins(); + flush_mntent_cache(); write_state_file(me->working_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs)); delete_pid_file(me->pid_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs)); diff --git a/bacula/src/lib/mntent_cache.c b/bacula/src/lib/mntent_cache.c index 75eefe2abf..aa46efa2a7 100644 --- a/bacula/src/lib/mntent_cache.c +++ b/bacula/src/lib/mntent_cache.c @@ -365,14 +365,21 @@ static void initialize_mntent_cache(void) /** * Flush the current content from the cache. - * This function should be called with a write lock on the mntent_cache. */ -static void flush_mntent_cache(void) +void flush_mntent_cache(void) { /** - * Make sure the cache is empty (either by flushing it or by initializing it.) + * Lock the cache. */ - clear_mount_cache(); + P(mntent_cache_lock); + + if (mntent_cache_entry_hashtable) { + previous_cache_hit = NULL; + mntent_cache_entry_hashtable->destroy(); + mntent_cache_entry_hashtable = NULL; + } + + V(mntent_cache_lock); } /** @@ -423,16 +430,7 @@ mntent_cache_entry_t *find_mntent_mapping(uint32_t dev) * the lookup again. */ if (!mce) { - /** - * Make sure the cache is empty (either by flushing it or by initializing it.) - */ - clear_mount_cache(); - - /** - * Refresh the cache. - */ - refresh_mount_cache(); - + initialize_mntent_cache(); mce = (mntent_cache_entry_t *)mntent_cache_entry_hashtable->lookup(dev); } diff --git a/bacula/src/lib/mntent_cache.h b/bacula/src/lib/mntent_cache.h index 8e1e79d67d..82c2f64f1f 100644 --- a/bacula/src/lib/mntent_cache.h +++ b/bacula/src/lib/mntent_cache.h @@ -60,5 +60,6 @@ struct mntent_cache_entry_t { }; mntent_cache_entry_t *find_mntent_mapping(uint32_t dev); +void flush_mntent_cache(void); #endif /* _MNTENT_CACHE_H */ diff --git a/bacula/src/tools/fstype.c b/bacula/src/tools/fstype.c index 2094bf5870..8a8c31a350 100644 --- a/bacula/src/tools/fstype.c +++ b/bacula/src/tools/fstype.c @@ -36,6 +36,7 @@ #include "bacula.h" #include "findlib/find.h" +#include "lib/mntent_cache.h" /* Dummy functions */ int generate_daemon_event(JCR *jcr, const char *event) @@ -103,5 +104,7 @@ main (int argc, char *const *argv) } } + flush_mntent_cache(); + exit(status); } diff --git a/bacula/src/tools/testfind.c b/bacula/src/tools/testfind.c index 15e4ac67f5..613a4186d1 100644 --- a/bacula/src/tools/testfind.c +++ b/bacula/src/tools/testfind.c @@ -35,6 +35,7 @@ #include "bacula.h" #include "dird/dird.h" #include "findlib/find.h" +#include "lib/mntent_cache.h" #include "ch.h" #if defined(HAVE_WIN32) @@ -241,6 +242,8 @@ main (int argc, char *const *argv) num_files, max_file_len, max_path_len, trunc_fname, trunc_path, hard_links); + flush_mntent_cache(); + term_msg(); close_memory_pool(); -- 2.39.5