From 114ffca84f3fe121793ac51d197591d90913988a Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 29 Jul 2007 12:50:33 +0000 Subject: [PATCH] kes Rework code in acquire.c that switches drives for reading when the Media Type does not match. This should fix bug #906 git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5263 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/acquire.c | 28 ++++++++++++---------------- bacula/src/stored/reserve.c | 2 -- bacula/src/version.h | 4 ++-- bacula/technotes-2.1 | 5 ++++- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 6ff42474fb..51827a3351 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -103,13 +103,15 @@ bool acquire_device_for_read(DCR *dcr) RCTX rctx; DIRSTORE *store; int stat; - DCR *dcr_save = jcr->dcr; Jmsg3(jcr, M_INFO, 0, _("Changing device. Want Media Type=\"%s\" have=\"%s\"\n" " device=%s\n"), dcr->media_type, dev->device->media_type, dev->print_name()); + + dev->dunblock(DEV_UNLOCKED); + detach_dcr_from_dev(dcr); /* release old device */ + lock_reservations(); - jcr->dcr = NULL; memset(&rctx, 0, sizeof(RCTX)); rctx.jcr = jcr; jcr->reserve_msgs = New(alist(10, not_owned_by_alist)); @@ -132,17 +134,7 @@ bool acquire_device_for_read(DCR *dcr) release_reserve_messages(jcr); /* release queued messages */ unlock_reservations(); if (stat == 1) { - DCR *ndcr = jcr->read_dcr; - dev->dunblock(DEV_UNLOCKED); - detach_dcr_from_dev(dcr); /* release old device */ - /* Copy important info from the new dcr */ - dev = dcr->dev = ndcr->dev; - jcr->read_dcr = dcr; - dcr->device = ndcr->device; - dcr->max_job_spool_size = dcr->device->max_job_spool_size; - attach_dcr_to_dev(dcr); - ndcr->VolumeName[0] = 0; - free_dcr(ndcr); + dcr->VolumeName[0] = 0; dev->dblock(BST_DOING_ACQUIRE); Jmsg(jcr, M_INFO, 0, _("Media Type change. New device %s chosen.\n"), dev->print_name()); @@ -157,10 +149,8 @@ bool acquire_device_for_read(DCR *dcr) /* error */ Jmsg1(jcr, M_FATAL, 0, _("No suitable device found to read Volume \"%s\"\n"), vol->VolumeName); - jcr->dcr = dcr_save; goto get_out; } - jcr->dcr = dcr_save; } @@ -620,6 +610,9 @@ DCR *new_dcr(JCR *jcr, DCR *dcr, DEVICE *dev) * Search the dcrs list for the given dcr. If it is found, * as it should be, then remove it. Also zap the jcr pointer * to the dcr if it is the same one. + * + * Note, this code will be turned on when we can write to multiple + * dcrs at the same time. */ #ifdef needed static void remove_dcr_from_dcrs(DCR *dcr) @@ -657,14 +650,17 @@ static void attach_dcr_to_dev(DCR *dcr) void detach_dcr_from_dev(DCR *dcr) { + DEVICE *dev = dcr->dev; Dmsg1(500, "JobId=%u enter detach_dcr_from_dev\n", (uint32_t)dcr->jcr->JobId); /* Detach this dcr only if attached */ - if (dcr->attached_to_dev && dcr->dev) { + if (dcr->attached_to_dev && dev) { + dev->dlock(); unreserve_device(dcr); dcr->dev->attached_dcrs->remove(dcr); /* detach dcr from device */ dcr->attached_to_dev = false; // remove_dcr_from_dcrs(dcr); /* remove dcr from jcr list */ + dev->dunlock(); } } diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 797a85c263..9f140ab0fd 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -416,7 +416,6 @@ VOLRES *find_volume(DCR *dcr) void unreserve_device(DCR *dcr) { DEVICE *dev = dcr->dev; - dev->dlock(); if (dcr->reserved_device) { dcr->reserved_device = false; dev->reserved_device--; @@ -433,7 +432,6 @@ void unreserve_device(DCR *dcr) } volume_unused(dcr); - dev->dunlock(); } /* diff --git a/bacula/src/version.h b/bacula/src/version.h index 6c86078834..ab8365e800 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.1.29" -#define BDATE "28 July 2007" -#define LSMDATE "28Jul07" +#define BDATE "29 July 2007" +#define LSMDATE "29Jul07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index 84fa959895..c951df563d 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,7 +1,10 @@ Technical notes on version 2.1 General: -28Jui07 +29Jul07 +kes Rework code in acquire.c that switches drives for reading when + the Media Type does not match. This should fix bug #906 +28Jul07 ebl Fix a director segfault during job setup #907 kes Correct seg fault in postgresql when first operation returns no rows. Fixes Dirks File browser problem seg fault with bat. -- 2.39.5