]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/mntent_cache.c
Update version + date
[bacula/bacula] / bacula / src / lib / mntent_cache.c
index 6d762399805fbdc8b7468b24307e471a3215d024..c30cc912fee6008b80e548a6dad533bf736496f7 100644 (file)
@@ -104,6 +104,13 @@ static htable *mntent_cache_entry_hashtable = NULL;
  */
 static time_t last_rescan = 0;
 
+static const char *skipped_fs_types[] = {
+#if defined(HAVE_LINUX_OS)
+   "rootfs",
+#endif
+   NULL
+};
+
 /**
  * Add a new entry to the cache.
  * This function should be called with a write lock on the mntent_cache.
@@ -153,6 +160,18 @@ static inline void add_mntent_mapping(uint32_t dev,
    mntent_cache_entry_hashtable->insert(mce->dev, mce);
 }
 
+static inline bool skip_fstype(const char *fstype)
+{
+   int i;
+
+   for (i = 0; skipped_fs_types[i]; i++) {
+      if (bstrcmp(fstype, skipped_fs_types[i]))
+         return true;
+   }
+
+   return false;
+}
+
 /**
  * OS specific function to load the different mntents into the cache.
  * This function should be called with a write lock on the mntent_cache.
@@ -186,6 +205,10 @@ static void refresh_mount_cache(void)
 #endif
 
    while ((mnt = getmntent(fp)) != (struct mntent *)NULL) {
+      if (skip_fstype(mnt->mnt_type)) {
+         continue;
+      }
+
       if (stat(mnt->mnt_dir, &st) < 0) {
          continue;
       }
@@ -201,6 +224,10 @@ static void refresh_mount_cache(void)
       return;
 
    while (getmntent(fp, &mnt) == 0) {
+      if (skip_fstype(mnt.mnt_fstype)) {
+         continue;
+      }
+
       if (stat(mnt.mnt_mountp, &st) < 0) {
          continue;
       }
@@ -228,7 +255,8 @@ static void refresh_mount_cache(void)
 
    if ((cnt = getmntinfo(&mntinfo, flags)) > 0) {
       while (cnt > 0) {
-         if (stat(mntinfo->f_mntonname, &st) == 0) {
+         if (!skip_fstype(mntinfo->f_fstypename) &&
+             stat(mntinfo->f_mntonname, &st) == 0) {
             add_mntent_mapping(st.st_dev,
                                mntinfo->f_mntfromname,
                                mntinfo->f_mntonname,
@@ -262,6 +290,10 @@ static void refresh_mount_cache(void)
    while (cnt < n_entries) {
       vmp = (struct vmount *)current;
 
+      if (skip_fstype(ve->vfsent_name)) {
+         continue;
+      }
+
       if (stat(current + vmp->vmt_data[VMT_STUB].vmt_off, &st) < 0) {
          continue;
       }
@@ -299,6 +331,10 @@ static void refresh_mount_cache(void)
    cnt = 0;
    current = entries;
    while (cnt < n_entries) {
+      if (skip_fstype(current->f_fstypename)) {
+         continue;
+      }
+
       if (stat(current->f_mntonname, &st) < 0) {
          continue;
       }
@@ -348,14 +384,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 +397,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 +426,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 +458,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 +466,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 +477,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;
 }