From: Eric Bollengier Date: Mon, 9 May 2022 14:23:37 +0000 (+0200) Subject: Ensure that the disk space is checked when finding new media X-Git-Tag: Beta-15.0.0~586 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=79bff056b6c5df892087687c2f543831be966b4d;p=thirdparty%2Fbacula.git Ensure that the disk space is checked when finding new media --- diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index c2254f14b..995953e33 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -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, diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index e176b1ec9..973a11563 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -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; } diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 0b337cf65..fa0a29c05 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -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 */ diff --git a/bacula/src/stored/file_dev.c b/bacula/src/stored/file_dev.c index b81c7a6b3..c869a23e7 100644 --- a/bacula/src/stored/file_dev.c +++ b/bacula/src/stored/file_dev.c @@ -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; +} diff --git a/bacula/src/stored/file_dev.h b/bacula/src/stored/file_dev.h index f0a0db273..83baf8a0f 100644 --- a/bacula/src/stored/file_dev.h +++ b/bacula/src/stored/file_dev.h @@ -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_ */