From 77494335cfec5a512d88ec4bfcb2f2ac9ed3cce6 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 3 May 2008 14:51:06 +0000 Subject: [PATCH] kes Rework SD acquire for read to handle autochanger Volume swapping. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6886 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/acquire.c | 22 +++++++++++++++++++--- bacula/src/stored/askdir.c | 2 +- bacula/src/stored/autochanger.c | 7 +++++-- bacula/src/stored/dev.c | 3 +-- bacula/src/stored/dev.h | 2 +- bacula/src/stored/dircmd.c | 2 +- bacula/src/stored/mount.c | 13 +++++++------ bacula/src/stored/reserve.c | 2 +- bacula/technotes-2.3 | 2 ++ 9 files changed, 38 insertions(+), 17 deletions(-) diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 207e3415dc..1d0d8a4ed3 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -89,9 +89,27 @@ bool acquire_device_for_read(DCR *dcr) jcr->NumReadVolumes, jcr->CurReadVolume); goto get_out; /* should not happen */ } + /* + * Note, if we want to be able to work from a .bsr file only + * for disaster recovery, we must "simulate" reading the catalog + */ bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName)); + bstrncpy(dcr->VolCatInfo.VolCatName, vol->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type)); dcr->VolCatInfo.Slot = vol->Slot; + dcr->VolCatInfo.InChanger = vol->Slot > 0; + if (reserve_volume(dcr, dcr->VolumeName) == NULL) { + Dmsg2(100, "Could not reserve volume %s on %s\n", dcr->VolumeName, + dcr->dev->print_name()); + Jmsg2(jcr, M_FATAL, 0, _("Could not reserve volume %s on %s\n"), dcr->VolumeName, + dcr->dev->print_name()); + goto get_out; + } + if (dev->vol && dev->vol->is_swapping()) { + dev->vol->set_slot(vol->Slot); + Dmsg3(100, "swapping: slot=%d Vol=%s dev=%s\n", dev->vol->get_slot(), + dev->vol->vol_name, dev->print_name()); + } /* * If the MediaType requested for this volume is not the @@ -192,9 +210,7 @@ bool acquire_device_for_read(DCR *dcr) goto get_out; /* error return */ } - dcr->do_swapping(); - - autoload_device(dcr, 0, NULL); + dcr->do_swapping(false/*is_writing*/); /* * This code ensures that the device is ready for diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index a5ad1a6976..cf23a4fd9a 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -283,7 +283,7 @@ bool dir_find_next_appendable_volume(DCR *dcr) bstrncpy(lastVolume, dcr->VolumeName, sizeof(lastVolume)); if (dcr->can_i_use_volume()) { Dmsg1(100, "Call reserve_volume. Vol=%s\n", dcr->VolumeName); - if (reserve_volume(dcr, dcr->VolumeName) == 0) { + if (reserve_volume(dcr, dcr->VolumeName) == NULL) { Dmsg2(100, "Could not reserve volume %s on %s\n", dcr->VolumeName, dcr->dev->print_name()); continue; diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index 9ed6c8f768..57ad48194b 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -118,16 +118,19 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir) POOLMEM *changer; if (!dev->is_autochanger()) { - Dmsg1(200, "Device %s is not an autochanger\n", dev->print_name()); + Dmsg1(100, "Device %s is not an autochanger\n", dev->print_name()); return 0; } /* An empty ChangerCommand => virtual disk autochanger */ if (dcr->device->changer_command && dcr->device->changer_command[0] == 0) { + Dmsg0(100, "ChangerCommand=0, virtual disk changer\n"); return 1; /* nothing to load */ } slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0; + Dmsg3(100, "autoload: slot=%d InChgr=%d Vol=%s\n", dcr->VolCatInfo.Slot, + dcr->VolCatInfo.InChanger, dcr->VolCatInfo.VolCatName); /* * Handle autoloaders here. If we cannot autoload it, we * will return 0 so that the sysop will be asked to load it. @@ -249,7 +252,7 @@ int get_autochanger_loaded_slot(DCR *dcr) return -1; } if (!dcr->device->changer_command) { - Jmsg(jcr, M_FATAL, 0, _("3992 Missing Changer command.\n")); +// Jmsg(jcr, M_FATAL, 0, _("3992 Missing Changer command.\n")); return -1; } if (dev->Slot > 0) { diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 99eee1f09c..bcf5be97ce 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1886,7 +1886,7 @@ void DEVICE::close() * the Volume parts multiple times without losing track of what the * main Volume parameters are. */ -void DEVICE::close_part(DCR *dcr) +void DEVICE::close_part(DCR * /*dcr*/) { VOLUME_LABEL saveVolHdr; VOLUME_CAT_INFO saveVolCatInfo; /* Volume Catalog Information */ @@ -1897,7 +1897,6 @@ void DEVICE::close_part(DCR *dcr) close(); /* close current part */ VolHdr = saveVolHdr; /* structure assignment */ VolCatInfo = saveVolCatInfo; /* structure assignment */ - dcr->VolCatInfo = saveVolCatInfo; /* structure assignment */ } boffset_t DEVICE::lseek(DCR *dcr, boffset_t offset, int whence) diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 7a3f07665b..76f9bb34d8 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -533,7 +533,7 @@ public: bool is_eod_valid(); int check_volume_label(bool &ask, bool &autochanger); void release_volume(); - void do_swapping(); + void do_swapping(bool is_writing); }; /* diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 411d6687a3..ceac150446 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -913,7 +913,7 @@ static bool release_cmd(JCR *jcr) } else if (dev->is_busy()) { send_dir_busy_message(dir, dev); } else { /* device not being used */ - Dmsg0(90, "Device not in use, releaseing\n"); + Dmsg0(90, "Device not in use, releasing\n"); unload_autochanger(dcr, -1); dcr->release_volume(); dir->fsend(_("3022 Device %s released.\n"), diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index b38f179796..0a9634de2c 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -106,7 +106,7 @@ mount_next_vol: if (dev->must_unload()) { ask = true; /* ask operator to mount tape */ } - do_swapping(); + do_swapping(true /*writing*/); if (!is_suitable_volume_mounted()) { bool have_vol = false; @@ -153,7 +153,7 @@ mount_next_vol: * and move the tape to the end of data. * */ - if (autoload_device(dcr, 1, NULL) > 0) { + if (autoload_device(dcr, true/*writing*/, NULL) > 0) { autochanger = true; ask = false; } else { @@ -470,7 +470,7 @@ bool DCR::is_suitable_volume_mounted() return dir_get_volume_info(this, GET_VOL_INFO_FOR_WRITE); } -void DCR::do_swapping() +void DCR::do_swapping(bool is_writing) { if (dev->must_unload()) { Dmsg1(100, "swapping: unloading %s\n", dev->print_name()); @@ -502,8 +502,9 @@ void DCR::do_swapping() } if (dev->must_load()) { Dmsg1(100, "swapping: must load %s\n", dev->print_name()); - dev->clear_load(); - dev->clear_volhdr(); /* force "load" */ + if (autoload_device(this, is_writing, NULL) > 0) { + dev->clear_load(); + } } } @@ -680,7 +681,7 @@ void DCR::release_volume() dev->block_num = dev->file = 0; dev->EndBlock = dev->EndFile = 0; memset(&dev->VolCatInfo, 0, sizeof(dev->VolCatInfo)); - memset(&VolCatInfo, 0, sizeof(VolCatInfo)); +// memset(&VolCatInfo, 0, sizeof(VolCatInfo)); dev->clear_volhdr(); /* Force re-read of label */ dev->clear_labeled(); diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 7dbede4b7c..050c606bb2 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -1554,7 +1554,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 */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 9f70887825..58053cd53d 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -25,6 +25,8 @@ Add long term statistics job table General: 03May08 +kes Rework SD acquire for read to handle autochanger Volume + swapping. kes Implement regression that explicitly tests swapping a Volume from one drive to another. kes Enhance disk-changer to detect most error conditions. -- 2.39.5