From 2e086a73458aa174ea074fbe95cd690d0df3e192 Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Sat, 12 Nov 2011 09:59:54 +0100 Subject: [PATCH] Change locking scheme of the mountpoint cache. We now lock the mount cache from the moment a caller enters find_mntent_mapping. This way we know for sure no one can be tampering our structures until we finish. As flush_mntent_cache is not called from the outside and now is a function which needs the lock hold we remove it as an external interface. --- bacula/src/lib/mntent_cache.c | 44 +++++++++++------------------------ bacula/src/lib/mntent_cache.h | 1 - 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/bacula/src/lib/mntent_cache.c b/bacula/src/lib/mntent_cache.c index 6d76239980..75eefe2abf 100644 --- a/bacula/src/lib/mntent_cache.c +++ b/bacula/src/lib/mntent_cache.c @@ -348,14 +348,10 @@ static void clear_mount_cache() /** * Initialize the cache for use. + * This function should be called with a write lock on the mntent_cache. */ static void initialize_mntent_cache(void) { - /** - * Lock the cache while we update it. - */ - P(mntent_cache_lock); - /** * Make sure the cache is empty (either by flushing it or by initializing it.) */ @@ -365,29 +361,18 @@ static void initialize_mntent_cache(void) * Refresh the cache. */ refresh_mount_cache(); - - /** - * We are done updating the cache. - */ - V(mntent_cache_lock); } -void flush_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) { - /** - * Lock the cache while we update it. - */ - P(mntent_cache_lock); - /** * Make sure the cache is empty (either by flushing it or by initializing it.) */ clear_mount_cache(); - - /** - * We are done updating the cache. - */ - V(mntent_cache_lock); } /** @@ -398,11 +383,17 @@ mntent_cache_entry_t *find_mntent_mapping(uint32_t dev) mntent_cache_entry_t *mce = NULL; time_t now; + /** + * Lock the cache. + */ + P(mntent_cache_lock); + /** * Shortcut when we get a request for the same device again. */ if (previous_cache_hit && previous_cache_hit->dev == dev) { - return previous_cache_hit; + mce = previous_cache_hit; + goto ok_out; } /** @@ -424,11 +415,6 @@ mntent_cache_entry_t *find_mntent_mapping(uint32_t dev) } } - /** - * Lock the cache while we walk it. - */ - P(mntent_cache_lock); - mce = (mntent_cache_entry_t *)mntent_cache_entry_hashtable->lookup(dev); /** @@ -457,9 +443,7 @@ mntent_cache_entry_t *find_mntent_mapping(uint32_t dev) previous_cache_hit = mce; } - /** - * We are done walking the cache. - */ +ok_out: V(mntent_cache_lock); return mce; } diff --git a/bacula/src/lib/mntent_cache.h b/bacula/src/lib/mntent_cache.h index 82c2f64f1f..8e1e79d67d 100644 --- a/bacula/src/lib/mntent_cache.h +++ b/bacula/src/lib/mntent_cache.h @@ -60,6 +60,5 @@ struct mntent_cache_entry_t { }; mntent_cache_entry_t *find_mntent_mapping(uint32_t dev); -void flush_mntent_cache(void); #endif /* _MNTENT_CACHE_H */ -- 2.39.2