]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/reserve.c
ebl update faketape driver to work with regress tests
[bacula/bacula] / bacula / src / stored / reserve.c
index 8d92efc5346fbac06e0395cdbc03f89f9ebb0c68..280abd01b60ddd20150ece3ae8e29fd6151600bd 100644 (file)
@@ -170,7 +170,7 @@ enum {
    debug_nolock = false
 };
 
-static void debug_list_volumes(const char *imsg)
+void debug_list_volumes(const char *imsg)
 {
    VOLRES *vol;
    POOL_MEM msg(PM_MESSAGE);
@@ -187,17 +187,6 @@ static void debug_list_volumes(const char *imsg)
       Dmsg1(dbglvl, "%s", msg.c_str());
    }
 
-#ifdef xxx
-   DEVICE *dev = NULL;
-   foreach_dlist(vol, vol_list) {
-      if (vol->dev == dev) {
-         Dmsg0(dbglvl, "Two Volumes on same device.\n");
-         ASSERT(0);
-         dev = vol->dev;
-      }
-   }
-#endif
-
    unlock_volumes();
 }
 
@@ -358,6 +347,7 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName)
          }
          Dmsg2(dbglvl, "reserve_vol free vol=%s at %p\n", vol->vol_name, vol->vol_name);
          free_volume(dev);
+//       volume_unused(dcr);
          dev->set_unload();             /* have to unload current volume */
          debug_list_volumes("reserve_vol free");
       }
@@ -386,22 +376,31 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName)
       nvol->dev = NULL;                  /* don't zap dev entry */
       free_vol_item(nvol);
 
-      /* Check if we are trying to use the Volume on a different drive */
+      /*
+       * Check if we are trying to use the Volume on a different drive
+       *  dev      is our device
+       *  vol->dev is where the Volume we want is
+       */
       if (dev != vol->dev) {
          /* Caller wants to switch Volume to another device */
          if (!vol->dev->is_busy() && !vol->is_swapping()) {
+            int32_t slot;
             Dmsg3(dbglvl, "==== Swap vol=%s from dev=%s to %s\n", 
                VolumeName, vol->dev->print_name(), dev->print_name());
             free_volume(dev);            /* free any volume attached to our drive */
-            vol->dev->set_unload();      /* unload our drive */
+//          volume_unused(dcr);
+            dev->set_unload();           /* Unload any volume that is on our drive */
+            dcr->dev = vol->dev;         /* temp point to other dev */
+            slot = get_autochanger_loaded_slot(dcr);  /* get slot on other drive */
+            dcr->dev = dev;              /* restore dev */
+            vol->set_slot(slot);         /* save slot */
+            vol->dev->set_unload();      /* unload the other drive */
             vol->set_swapping();         /* swap from other drive */
             dev->swap_dev = vol->dev;    /* remember to get this vol */
-            vol->dev->set_load();        /* then reload on our drive */
+            dev->set_load();             /* then reload on our drive */
             vol->dev->vol = NULL;        /* remove volume from other drive */
-            vol->dev = dev;              /* point it at our drive */
-            dev->vol = vol;              /* point our drive at it */
-            Dmsg3(dbglvl, "==== Swap vol=%s from dev=%s to %s\n", 
-               VolumeName, vol->dev->print_name(), dev->print_name());
+            vol->dev = dev;              /* point the Volume at our drive */
+            dev->vol = vol;              /* point our drive at the Volume */
          } else {
             Dmsg3(dbglvl, "==== Swap not possible Vol busy vol=%s from dev=%s to %s\n", 
                VolumeName, vol->dev->print_name(), dev->print_name());
@@ -421,6 +420,7 @@ get_out:
             vol->dev->print_name());
       vol->set_in_use();
       dcr->reserved_volume = true;
+      bstrncpy(dcr->VolumeName, vol->vol_name, sizeof(dcr->VolumeName));
    }
    debug_list_volumes("end new volume");
    unlock_volumes();
@@ -589,11 +589,14 @@ bool free_volume(DEVICE *dev)
    }
    lock_volumes();
    vol = dev->vol;
-   dev->vol = NULL;
-   vol_list->remove(vol);
-   Dmsg2(dbglvl, "=== free_volume %s dev=%s\n", vol->vol_name, dev->print_name());
-   free_vol_item(vol);
-   debug_list_volumes("free_volume");
+   /* Don't free a volume while it is being swapped */
+   if (!vol->is_swapping()) {
+      dev->vol = NULL;
+      vol_list->remove(vol);
+      Dmsg2(dbglvl, "=== remove volume %s dev=%s\n", vol->vol_name, dev->print_name());
+      free_vol_item(vol);
+      debug_list_volumes("free_volume");
+   }
    unlock_volumes();
    return true;
 }
@@ -1030,7 +1033,7 @@ bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx)
       Dmsg0(dbglvl, "deleted temp vol list\n");
       Dmsg0(dbglvl, "unlock volumes\n");
       unlock_volumes();
-      debug_list_volumes("=== After free temp table\n");
+      debug_list_volumes("after free temp table");
    }
    if (ok) {
       Dmsg1(dbglvl, "OK dev found. Vol=%s from in-use vols list\n", rctx.VolumeName);
@@ -1325,8 +1328,8 @@ bail_out:
 
 
 /*
- * We reserve the device for appending by incrementing the 
- *  reserved_device. We do virtually all the same work that
+ * We reserve the device for appending by incrementing
+ *  num_reserved(). We do virtually all the same work that
  *  is done in acquire_device_for_append(), but we do
  *  not attempt to mount the device. This routine allows
  *  the DIR to reserve multiple devices before *really* 
@@ -1544,7 +1547,7 @@ static int can_reserve_drive(DCR *dcr, RCTX &rctx)
             /* Changing pool, unload old tape if any in drive */
             Dmsg0(dbglvl, "OK dev: num_writers=0, not reserved, pool change, unload changer\n");
             /* ***FIXME*** use set_unload() */
-            unload_autochanger(dcr, 0);
+            unload_autochanger(dcr, -1);
          }
       }
       /* Device is available but not yet reserved, reserve it for us */