]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/mount.c
Fix SD crash due to mismatched lock/unlock in error condition
[bacula/bacula] / bacula / src / stored / mount.c
index ed6839fc288139ae66e8e315fe2047f84b579906..4ad41861a58556a5ff651eab86a98b4657aa5d8b 100644 (file)
@@ -37,7 +37,6 @@
 #include "bacula.h"                   /* pull in global headers */
 #include "stored.h"                   /* pull in Storage Deamon headers */
 
-
 enum {
    try_next_vol = 1,
    try_read_vol,
@@ -78,13 +77,14 @@ bool DCR::mount_next_write_volume()
       dev->print_name());
 
    init_device_wait_timers(dcr);
-   lock_volumes();
    
    /*
     * Attempt to mount the next volume. If something non-fatal goes
     *  wrong, we come back here to re-try (new op messages, re-read
     *  Volume, ...)
     */
+   lock_volumes();
+
 mount_next_vol:
    Dmsg1(150, "mount_next_vol retry=%d\n", retry);
    /* Ignore retry if this is poll request */
@@ -109,12 +109,10 @@ mount_next_vol:
    if (dev->must_unload()) {
       ask = true;                     /* ask operator to mount tape */
    }
-//   unlock_volumes();
    do_unload();
    do_swapping(true /*is_writing*/);
    do_load(true /*is_writing*/);
 
-//   lock_volumes();
    if (!find_a_volume()) {
       goto bail_out;
    }
@@ -136,7 +134,6 @@ mount_next_vol:
     * and move the tape to the end of data.
     *
     */
-//   unlock_volumes();
    dcr->setVolCatInfo(false);   /* out of date when Vols unlocked */
    if (autoload_device(dcr, true/*writing*/, NULL) > 0) {
       autochanger = true;
@@ -146,7 +143,6 @@ mount_next_vol:
       VolCatInfo.Slot = 0;
       ask = retry >= 2;
    }
-//   lock_volumes();
    Dmsg1(150, "autoload_dev returns %d\n", autochanger);
    /*
     * If we autochanged to correct Volume or (we have not just
@@ -324,13 +320,12 @@ no_lock_bail_out:
  * This routine is meant to be called once the first pass
  *   to ensure that we have a candidate volume to mount.
  *   Otherwise, we ask the sysop to created one.
- * Note, the the Volumes are locked on entry.
- *   They are unlocked on failure and remain locked on
- *   success.  The caller must know this!!!
+ * Note, the the Volumes are locked on entry and exit.
  */
-bool DCR::find_a_volume()  
+bool DCR::find_a_volume()
 {
    DCR *dcr = this;
+
    if (!is_suitable_volume_mounted()) {
       bool have_vol = false;
       /* Do we have a candidate volume? */
@@ -347,14 +342,17 @@ bool DCR::find_a_volume()
          while (!dir_find_next_appendable_volume(dcr)) {
             Dmsg0(200, "not dir_find_next\n");
             if (job_canceled(jcr)) {
-               unlock_volumes();
                return false;
             }
             unlock_volumes();
             if (!dir_ask_sysop_to_create_appendable_volume(dcr)) {
+               lock_volumes();
                return false;
              }
              lock_volumes();
+             if (job_canceled(jcr)) {
+                return false;
+             }
              Dmsg0(150, "Again dir_find_next_append...\n");
          }
       }
@@ -780,8 +778,6 @@ void DCR::release_volume()
    if (dev->is_open()) {
       dev->offline_or_rewind();
    }
-// Dmsg0(50, "set_unload\n");
-// dev->set_unload();
    Dmsg0(190, "release_volume\n");
 }