/**
* 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.)
*/
* Refresh the cache.
*/
refresh_mount_cache();
-
- /**
- * We are done updating the cache.
- */
- V(mntent_cache_lock);
}
+/**
+ * Flush the current content from the cache.
+ */
void flush_mntent_cache(void)
{
/**
- * Lock the cache while we update it.
+ * Lock the cache.
*/
P(mntent_cache_lock);
- /**
- * Make sure the cache is empty (either by flushing it or by initializing it.)
- */
- clear_mount_cache();
+ if (mntent_cache_entry_hashtable) {
+ previous_cache_hit = NULL;
+ mntent_cache_entry_hashtable->destroy();
+ mntent_cache_entry_hashtable = NULL;
+ }
- /**
- * We are done updating the cache.
- */
V(mntent_cache_lock);
}
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;
}
/**
}
}
- /**
- * Lock the cache while we walk it.
- */
- P(mntent_cache_lock);
-
mce = (mntent_cache_entry_t *)mntent_cache_entry_hashtable->lookup(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);
}
previous_cache_hit = mce;
}
- /**
- * We are done walking the cache.
- */
+ok_out:
V(mntent_cache_lock);
return mce;
}