]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Ensure that the disk space is checked when finding new media
authorEric Bollengier <eric@baculasystems.com>
Mon, 9 May 2022 14:23:37 +0000 (16:23 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:58 +0000 (13:56 +0200)
bacula/src/stored/askdir.c
bacula/src/stored/dev.c
bacula/src/stored/dev.h
bacula/src/stored/file_dev.c
bacula/src/stored/file_dev.h

index c2254f14bf080dc1a1b1b910393406bb7f4e1528..995953e33b8c186e76e2c8c949d6f3d47bcdbbe5 100644 (file)
@@ -321,6 +321,8 @@ bool dir_find_next_appendable_volume(DCR *dcr)
           dcr->is_reserved(), dcr->VolumeName, nb_retry);
     Mmsg(jcr->errmsg, "Unknown error\n");
 
+    bool can_create = !dcr->dev->is_fs_nearly_full(dcr->dev->min_free_space);
+
     /*
      * Try the thirty oldest or most available volumes.  Note,
      *   the most available could already be mounted on another
@@ -332,7 +334,6 @@ bool dir_find_next_appendable_volume(DCR *dcr)
     lastVolume[0] = 0;
     for (int vol_index=1;  vol_index < nb_retry; vol_index++) {
        /* Have we still some space to create a new volume? */
-       bool can_create = dcr->dev->is_nospace()==false;
        bash_spaces(dcr->media_type);
        bash_spaces(dcr->pool_name);
        dir->fsend(Find_media, jcr->JobId, vol_index, dcr->pool_name, dcr->media_type,
index e176b1ec91723089928b88892149fad5a49c8c61..973a115634459a7c385a029515e3cdcba22d6d2a 100644 (file)
@@ -658,15 +658,16 @@ void DEVICE::term(DCR *dcr)
 /* Get freespace values */
 void DEVICE::get_freespace(uint64_t *freeval, uint64_t *totalval)
 {
-   get_os_device_freespace();
-   P(freespace_mutex);
-   if (is_freespace_ok()) {
-      *freeval = free_space;
-      *totalval = total_space;
-   } else {
-      *freeval = *totalval = 0;
+   if (get_os_device_freespace()) {
+      P(freespace_mutex);
+      if (is_freespace_ok()) {
+         *freeval = free_space;
+         *totalval = total_space;
+      } else {
+         *freeval = *totalval = 0;
+      }
+      V(freespace_mutex);
    }
-   V(freespace_mutex);
 }
 
 /* Set freespace values */
@@ -689,15 +690,6 @@ void DEVICE::set_freespace(uint64_t freeval, uint64_t totalval, int errnoval, bo
  */
 bool DEVICE::is_fs_nearly_full(uint64_t threshold)
 {
-   uint64_t freeval, totalval;
-   if (is_file()) {
-      get_freespace(&freeval, &totalval);
-      if (totalval > 0) {
-         if (freeval < threshold) {
-            return true;
-         }
-      }
-   }
    return false;
 }
 
@@ -846,19 +838,6 @@ void DEVICE::clear_read()
  */
 bool DEVICE::get_os_device_freespace()
 {
-   int64_t freespace, totalspace;
-
-   if (!is_file()) {
-      return true;
-   }
-   if (fs_get_free_space(dev_name, &freespace, &totalspace) == 0) {
-      set_freespace(freespace,  totalspace, 0, true);
-      Mmsg(errmsg, "");
-      return true;
-
-   } else {
-      set_freespace(0, 0, 0, false); /* No valid freespace */
-   }
    return false;
 }
 
index 0b337cf65117538c5ea55fd65aca7670e80754dc..fa0a29c0574f416f6a140b5a87a29b6bd7c2856f 100644 (file)
@@ -458,7 +458,7 @@ public:
    };
    void get_freespace(uint64_t *freeval, uint64_t *totalval); /* in dev.c */
    void set_freespace(uint64_t freeval, uint64_t totalval, int errnoval, bool valid); /* in dev.c */
-   bool is_fs_nearly_full(uint64_t threshold);
+   virtual bool is_fs_nearly_full(uint64_t threshold);
    bool is_volume_to_unload() const { \
       return m_unload && strcmp(VolHdr.VolumeName, LoadedVolName) == 0; };
    void set_load() { m_load = true; };
@@ -510,7 +510,7 @@ public:
    void set_slot(int32_t slot);  /* in dev.c */
    void clear_slot();            /* in dev.c */
    bool update_freespace();              /* in dev.c */
-   bool get_os_device_freespace();       /* in dev.c */
+   virtual bool get_os_device_freespace();                      /* in dev.c */
    void notify_newvol_in_attached_dcrs(const char *VolumeName); /* in dev.c */
    void notify_newfile_in_attached_dcrs();/* in dev.c */
    void attach_dcr_to_dev(DCR *dcr);      /* in acquire.c */
index b81c7a6b35b334a5f40d1378e1b743a1779064bb..c869a23e776de379db8fcf73ee0b0bac7ba7e519 100644 (file)
@@ -340,7 +340,6 @@ bool DEVICE::truncate(DCR *dcr)
    return true;
 }
 
-
 /*
  * (Un)mount the device
  */
@@ -900,3 +899,29 @@ int file_dev::device_specific_init(JCR *jcr, DEVRES *device)
    capabilities |= CAP_LSEEK;
    return 0;
 }
+
+bool file_dev::is_fs_nearly_full(uint64_t threshold)
+{
+   uint64_t freeval, totalval;
+   get_freespace(&freeval, &totalval);
+   if (totalval > 0) {
+      if (freeval < threshold) {
+         return true;
+      }
+   }
+   return false;
+}
+
+bool file_dev::get_os_device_freespace()
+{
+   int64_t freespace, totalspace;
+   if (fs_get_free_space(dev_name, &freespace, &totalspace) == 0) {
+      set_freespace(freespace,  totalspace, 0, true);
+      Mmsg(errmsg, "");
+      return true;
+
+   } else {
+      set_freespace(0, 0, 0, false); /* No valid freespace */
+   }
+   return false;
+}
index f0a0db27323100a624280a799d2928f5949c788f..83baf8a0f6e4c3dc8fa9789bd0a3bff133b92fd2 100644 (file)
@@ -48,6 +48,8 @@ public:
    bool set_immutable(const char *vol_name);
    bool clear_immutable(const char *vol_name);
    bool check_volume_protection_time(const char *vol_name);
+   bool get_os_device_freespace();
+   bool is_fs_nearly_full(uint64_t threshold);
 };
 
 #endif /* __FILE_DEV_ */