]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
cloud: Fix #9419 Avoid abort when truncate() fails
authornorbert.bizet <norbert.bizet@baculasystems.com>
Fri, 9 Sep 2022 12:56:53 +0000 (08:56 -0400)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:58 +0000 (13:56 +0200)
bacula/src/stored/label.c
regress/tests/cloud-MT9419-wrong-device-volumes-in-error [new file with mode: 0755]

index 7c6dfbee2868ada433db07b046007a6bb1fa21fe..188dff4d61be83bf54f9b2bef7bb0e87b448cc33 100644 (file)
@@ -534,6 +534,9 @@ bail_out:
  *
  *  Returns: true if OK
  *           false if unable to write it
+ *  N.B. 2022: Function is called in a loop and should avoid FATAL errors as much as possible.
+ *             In order to fix MT9419 (corner case with cloud device), I moved the !truncate(dcr) error handling
+ *             from FATAL to ERROR so the truncated volumes can be effectively set in Error state.
  */
 bool DEVICE::rewrite_volume_label(DCR *dcr, bool recycle)
 {
@@ -572,7 +575,7 @@ bool DEVICE::rewrite_volume_label(DCR *dcr, bool recycle)
       if (recycle) {
          Dmsg1(150, "Doing recycle. Vol=%s\n", dcr->VolumeName);
          if (!truncate(dcr)) {
-            Jmsg3(jcr, M_FATAL, 0, _("Truncate error on %s device %s: ERR=%s\n"),
+            Jmsg3(jcr, M_ERROR, 0, _("Truncate error on %s device %s: ERR=%s\n"),
                   print_type(), print_name(), print_errmsg());
             Leave(100);
             return false;
diff --git a/regress/tests/cloud-MT9419-wrong-device-volumes-in-error b/regress/tests/cloud-MT9419-wrong-device-volumes-in-error
new file mode 100755 (executable)
index 0000000..0c32bb4
--- /dev/null
@@ -0,0 +1,103 @@
+#!/bin/sh
+#
+# Copyright (C) 2000-2021 Kern Sibbald
+# Copyright (C) 2021-2022 Bacula Systems SA
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
+# Cloud transfer test. Exercice the retry-waiting mecanism introduced to support S3 GLACIER restoration
+# Will work with all drivers but is mostly design to be run with file_driver.
+#
+TestName="cloud-MT9419-test"
+JobName=NightlySave
+. scripts/functions
+
+require_cloud
+
+#config is required for cloud cleanup
+scripts/copy-test-confs
+scripts/cleanup
+
+FORCE_FILE_SET=${FORCE_FILE_SET:-"${cwd}/build"}
+echo "$FORCE_FILE_SET" >${cwd}/tmp/file-list
+
+start_test
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "LabelFormat", "Vol", "Pool")'
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "MaximumVolumeBytes", "40000000", "Pool")'
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "VolumeRetention", "1s", "Pool")'
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MaximumUploadBandwidth", "4MB/s", "Cloud")'
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MaximumDownloadBandwidth", "4MB/s", "Cloud")'
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MaximumDownloadBandwidth", "4MB/s", "Cloud")'
+
+AccessKey=$($bperl -e "get_attribute('$conf/bacula-sd.conf', 'Cloud', '$CLOUD_NAME', 'AccessKey')")
+$bperl -e 'add_attribute("$conf/bacula-sd.conf", "AccessKey", '"${CLOUD_NAME}_WRONG"',, "Cloud")'
+
+
+cat <<END_OF_DATA >${cwd}/tmp/bconcmds
+@$out ${cwd}/tmp/log1.out
+run job=$JobName level=Full yes
+wait
+messages
+@$out ${cwd}/tmp/log1_list.out
+list media
+END_OF_DATA
+
+echo "Running job 1"
+run_bacula
+ls -l tmp/Vol*
+
+# exactly the same but log2
+cat <<END_OF_DATA >${cwd}/tmp/bconcmds
+@$out ${cwd}/tmp/log2.out
+run job=$JobName level=Full yes
+wait
+messages
+@$out ${cwd}/tmp/log2_list.out
+list media
+END_OF_DATA
+
+echo "Running job 2"
+run_bconsole
+ls -l tmp/Vol*
+
+
+sleep 2
+unset FORCE_CLOUD
+stop_bacula
+
+grep 'Marking Volume "Vol0001" in Error in Catalog.' $tmp/log2.out > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Vol0001 not set in error"
+    estat=1
+fi
+
+grep 'Marking Volume "Vol0002" in Error in Catalog.' $tmp/log2.out > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Vol0002 not set in error"
+    estat=2
+fi
+
+grep 'Marking Volume "Vol0003" in Error in Catalog.' $tmp/log2.out > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Vol0003 not set in error"
+    estat=3
+fi
+
+grep 'Vol0001    | Error' $tmp/log2_list.out > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Vol0001 not listed in error"
+    estat=4
+fi
+
+grep 'Vol0002    | Error' $tmp/log2_list.out > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Vol0002 not listed in error"
+    estat=5
+fi
+
+grep 'Vol0003    | Error' $tmp/log2_list.out > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Vol0003 not listed in error"
+    estat=6
+fi
+
+end_test