- if (!vol->dev->is_busy()) {
- /* OK to move it -- I'm not sure this will work */
- Dmsg3(dbglvl, "==== Swap vol=%s from dev=%s to %s\n", VolumeName,
- vol->dev->print_name(), dev->print_name());
- vol->dev->vol = NULL; /* take vol from old drive */
- vol->dev->VolHdr.VolumeName[0] = 0;
- vol->dev = dev; /* point vol at new drive */
- dev->vol = vol; /* point dev at vol */
- dev->VolHdr.VolumeName[0] = 0;
+ if (!vol->dev->is_busy() && !vol->is_swapping()) {
+ 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 */
+ 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 */
+ 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());