]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
fix Cannot free Volume XXX, because it is reserved by someone else
authorAlain Spineux <alain@baculasystems.com>
Fri, 6 Jan 2023 12:36:04 +0000 (13:36 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:00 +0000 (13:57 +0200)
- when something goes wrong, sometime, the volume_unused() is not called
  and the volume stay stuck
- always call volume_unused() in the "check_bail_out:"
- load_encryption_key() can return a new error: VOL_ENC_ERROR
  that will trigger the call to volume_unused()

bacula/src/stored/dev.h
bacula/src/stored/label.c
bacula/src/stored/mount.c
bacula/src/stored/record.h

index d7fcea0a3567266305646b7e0af5377f15aef098..0b5ddadc02265d65c950a674795ca5e5e50b4eb3 100644 (file)
@@ -898,6 +898,7 @@ public:
    void mark_volume_in_error();
    void mark_volume_read_only();
    void mark_volume_not_inchanger();
+   void volume_is_unavailable();
    int try_autolabel(bool opened);
    bool find_a_volume();
    bool is_suitable_volume_mounted();
index b1e7f7467936851c9226d51ac2a3f963bed06011..e0da0ea271e036e0132b0f3df2ad81996c1aa57f 100644 (file)
@@ -280,6 +280,11 @@ int DEVICE::read_dev_volume_label(DCR *dcr)
       }
    }
 
+   if (!load_encryption_key(dcr, "READ", VolHdr.VolumeName, &VolHdr.EncCypherKeySize, VolHdr.EncCypherKey, &VolHdr.MasterKeyIdSize, VolHdr.MasterKeyId)) {
+      stat = VOL_ENC_ERROR;
+      goto bail_out; /* a message is already loaded into jcr->errmsg */
+   }
+
    Dmsg1(100, "Call reserve_volume=%s\n", VolHdr.VolumeName);
    if (reserve_volume(dcr, VolHdr.VolumeName) == NULL) {
       if (!jcr->errmsg[0]) {
@@ -291,11 +296,6 @@ int DEVICE::read_dev_volume_label(DCR *dcr)
       goto bail_out;
    }
 
-   if (!load_encryption_key(dcr, "READ", VolHdr.VolumeName, &VolHdr.EncCypherKeySize, VolHdr.EncCypherKey, &VolHdr.MasterKeyIdSize, VolHdr.MasterKeyId)) {
-      stat = VOL_LABEL_ERROR;
-      goto bail_out; /* a message is already loaded into jcr->errmsg */
-   }
-
    if (dcr->is_writing()) {
        empty_block(dcr->block);
    }
index 6f8f2d8a4b94fdde2aaef861b0f002a583e3ab80..8abfae889643b00db9e254cb57c458b00040f8ab 100644 (file)
@@ -541,6 +541,10 @@ int DCR::check_volume_label(bool &ask, bool &autochanger)
          break;
       }
       /* NOTE! Fall-through wanted. */
+   case VOL_ENC_ERROR:
+      volume_is_unavailable();
+      goto check_next_volume;
+      break;
    case VOL_NO_MEDIA:
    default:
       Dmsg0(200, "VOL_NO_MEDIA or default.\n");
@@ -569,6 +573,7 @@ check_next_volume:
    return check_next_vol;
 
 check_bail_out:
+   volume_unused(this);
    Leave(200);
    return check_error;
 
@@ -738,6 +743,17 @@ int DCR::try_autolabel(bool opened)
    return try_default;
 }
 
+/*
+ * The volume is unavailable (temporarily?) don't used it this time
+ */
+void DCR::volume_is_unavailable()
+{
+   Jmsg(jcr, M_INFO, 0, _("The Volume \"%s\" in unavailable now.\n"),
+        VolumeName);
+   volume_unused(this);
+   Dmsg0(50, "set_unload\n");
+   dev->set_unload();                 /* must get a new volume */
+}
 
 /*
  * Mark volume in error in catalog
index 5558c1d18f0fc2581a2dc90deb2ac951e42abc35..2be5455697e4cc49f93353a206bab34a70051807 100644 (file)
@@ -39,7 +39,8 @@ enum {
    VOL_VERSION_ERROR = 7,                 /* Bacula version error */
    VOL_LABEL_ERROR   = 8,                 /* Bad label type */
    VOL_NO_MEDIA      = 9,                 /* Hard error -- no media present */
-   VOL_TYPE_ERROR    = 10                 /* Volume type (aligned/non-aligned) error */
+   VOL_TYPE_ERROR    = 10,                /* Volume type (aligned/non-aligned) error */
+   VOL_ENC_ERROR     = 11                 /* something wrong with the encryption key */
 };
 
 enum rec_state {