From: Eric Bollengier Date: Tue, 28 Mar 2023 16:07:57 +0000 (+0200) Subject: Fix #10004 Check if volumes are used when setting the volume protection X-Git-Tag: Beta-15.0.0~215 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d94701d6c9ffdbb2d58a51ae68c17bf259e29bd;p=thirdparty%2Fbacula.git Fix #10004 Check if volumes are used when setting the volume protection --- diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 0428bbb69..eff14c7f1 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -1349,6 +1349,10 @@ static bool volumeprotect_cmd(JCR *jcr) unbash_spaces(mediatype); unbash_spaces(device.c_str()); unbash_spaces(volume); + if (is_writing_volume(volume)) { + dir->fsend(_("3900 Unable to set immutable flag on %s, volume still in use\n"), volume); + return true; + } DCR *dcr = find_any_device(jcr, device, mediatype, drive); if (dcr) { DEVICE *dev = dcr->dev; diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 1c8948701..0726110cf 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -275,6 +275,7 @@ void _dbg_list_one_device(DEVICE *dev, const char *f, int l); _dbg_list_one_device(dev, __FILE__, __LINE__) /* From vol_mgr.c */ +bool is_writing_volume(const char *VolumeName); void init_vol_list_lock(); void term_vol_list_lock(); VOLRES *reserve_volume(DCR *dcr, const char *VolumeName); @@ -286,7 +287,6 @@ bool volume_unused(DCR *dcr); void create_volume_lists(); void free_volume_lists(); void list_volumes(void sendit(const char *msg, int len, void *sarg), void *arg); -bool is_volume_in_use(DCR *dcr); extern int vol_list_lock_count; void add_read_volume(JCR *jcr, const char *VolumeName); void remove_read_volume(JCR *jcr, const char *VolumeName); diff --git a/bacula/src/stored/vol_mgr.c b/bacula/src/stored/vol_mgr.c index 5873f3e0e..dae448b87 100644 --- a/bacula/src/stored/vol_mgr.c +++ b/bacula/src/stored/vol_mgr.c @@ -168,6 +168,20 @@ bool is_read_volume(JCR *jcr, const char *VolumeName) return fvol != NULL; } +/* + * Check if volume name is in the read list. + */ +bool is_writing_volume(const char *VolumeName) +{ + VOLRES vol, *fvol; + lock_volumes(); + vol.vol_name = bstrdup(VolumeName); + fvol = (VOLRES *)vol_list->binary_search(&vol, name_compare); + free(vol.vol_name); + unlock_volumes(); + return fvol && fvol->is_writing(); +} + /* * Remove a given volume name from the read list. */