From bdcddd32cafd978761406b7ad3ca006597c8f1d7 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 31 May 2008 07:09:35 +0000 Subject: [PATCH] Get correct slot when auto unloading a device. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7067 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/autochanger.c | 22 +++++++++++++++++----- bacula/technotes-2.3 | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index e3afcf24d6..b622561335 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -258,6 +258,7 @@ int get_autochanger_loaded_slot(DCR *dcr) if (dev->get_slot() > 0) { return dev->get_slot(); } + /* Virtual disk autochanger */ if (dcr->device->changer_command[0] == 0) { return 1; @@ -434,6 +435,9 @@ static bool unload_other_drive(DCR *dcr, int slot) return unload_dev(dcr, dev); } +/* + * Unconditionally unload a specified drive + */ bool unload_dev(DCR *dcr, DEVICE *dev) { JCR *jcr = dcr->jcr; @@ -443,9 +447,21 @@ bool unload_dev(DCR *dcr, DEVICE *dev) DEVICE *save_dev; int save_slot; - if (!changer || dev->get_slot() <= 0) { + if (!changer) { return false; } + + save_dev = dcr->dev; /* save dcr device */ + dcr->dev = dev; /* temporarily point dcr at other device */ + save_slot = dcr->VolCatInfo.Slot; + + if (dev->get_slot() <= 0 && get_autochanger_loaded_slot(dcr) <= 0) { + dcr->VolCatInfo.Slot = save_slot; + dcr->dev = save_dev; + return false; + } + dcr->VolCatInfo.Slot = dev->get_slot(); + dev->dlock(); POOLMEM *changer_cmd = get_pool_memory(PM_FNAME); @@ -458,10 +474,6 @@ bool unload_dev(DCR *dcr, DEVICE *dev) Dmsg2(100, "Issuing autochanger \"unload slot %d, drive %d\" command.\n", dev->get_slot(), dev->drive_index); - save_dev = dcr->dev; - dcr->dev = dev; - save_slot = dcr->VolCatInfo.Slot; - dcr->VolCatInfo.Slot = dev->get_slot(); changer_cmd = edit_device_codes(dcr, changer_cmd, dcr->device->changer_command, "unload"); dev->close(); diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 917c750d2b..255ecbdac6 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -24,6 +24,8 @@ Add long term statistics job table General: +31May08 +kes Get correct slot when auto unloading a device. 30May08 kes Fix multiple media restore. kes Make DEVICE Slot private and access it via a method. -- 2.39.5