From: Marco van Wieringen Date: Sat, 12 Nov 2011 08:59:54 +0000 (+0100) Subject: Change locking scheme of the mountpoint cache. X-Git-Tag: Release-7.0.0~460 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c2b406782a1ed0fc15a3add622dc6a38abcaa451;p=bacula%2Fbacula 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. --- 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 */