]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/mntent_cache.c
Pull compiler warning cleanup code + other from master
[bacula/bacula] / bacula / src / lib / mntent_cache.c
index 6d762399805fbdc8b7468b24307e471a3215d024..aa46efa2a79317e7b6ba85b17bbb06362c446c60 100644 (file)
@@ -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,28 +361,24 @@ static void initialize_mntent_cache(void)
     * 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);
 }
 
@@ -398,11 +390,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 +422,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);
 
    /**
@@ -437,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);
    }
 
@@ -457,9 +441,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;
 }