]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #10004 Check if volumes are used when setting the volume protection
authorEric Bollengier <eric@baculasystems.com>
Tue, 28 Mar 2023 16:07:57 +0000 (18:07 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:01 +0000 (13:57 +0200)
bacula/src/stored/dircmd.c
bacula/src/stored/protos.h
bacula/src/stored/vol_mgr.c

index 0428bbb6974627ef7f2517bb7713e4d6e30e469d..eff14c7f1ed8a13d6d376adc1ef628381c30bece 100644 (file)
@@ -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;
index 1c89487018c910db32f2dcd93e2309f08ad38d5d..0726110cf4c9fb68981837383c2e29e1779dcb80 100644 (file)
@@ -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);
index 5873f3e0ea02afe7dc9c19adbd826b73409b6618..dae448b879e9b8354a97e870c868e2a932076735 100644 (file)
@@ -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.
  */