From: Kern Sibbald Date: Sun, 13 Apr 2008 15:32:46 +0000 (+0000) Subject: kes Tweak the swap Volume from one drive to another code so that X-Git-Tag: Release-3.0.0~1561 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=356ad8deb8e101f49306eceb0ba687ca3f677f48;p=bacula%2Fbacula kes Tweak the swap Volume from one drive to another code so that it now seems to work. kes Resolve several problems with recycling that broke the new code (these problems are in 2.2.9 as well). kes Remove the volume lock when calling the sysop code. kes Don't mark a reserved volume with no writers as unused otherwise jobs fail. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6804 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 67080def3d..16d77130ae 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -464,7 +464,7 @@ bool release_device(DCR *dcr) Dmsg2(200, "dir_update_vol_info. Release vol=%s dev=%s\n", dev->VolCatInfo.VolCatName, dev->print_name()); } - if (!dev->num_writers) { /* if no more writers */ + if (!dev->is_busy()) { /* if not being used */ volume_unused(dcr); /* we obviously are not using the volume */ } } diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index d1bcec1103..3d791f4fb0 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -461,7 +461,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) return false; } if (recycle) { - volume_unused(dcr); /* mark volume unused */ +// volume_unused(dcr); /* mark volume unused */ if (!dev->truncate(dcr)) { Jmsg2(jcr, M_FATAL, 0, _("Truncate error on device %s: ERR=%s\n"), dev->print_name(), dev->print_errmsg()); diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 17a34d5d78..38db3c7e15 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -89,11 +89,13 @@ mount_next_vol: if (!dev->poll && retry++ > 4) { /* Last ditch effort before giving up, force operator to respond */ VolCatInfo.Slot = 0; + unlock_volumes(); if (!dir_ask_sysop_to_mount_volume(dcr, ST_APPEND)) { Jmsg(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"), dev->print_name()); - goto bail_out; + goto no_lock_bail_out; } + lock_volumes(); } if (job_canceled(jcr)) { Jmsg(jcr, M_FATAL, 0, _("Job %d canceled.\n"), jcr->JobId); @@ -124,6 +126,10 @@ mount_next_vol: } dev->swap_dev = NULL; } + if (dev->must_load()) { + dev->clear_load(); + dev->clear_volhdr(); /* force "load" */ + } if (!is_suitable_volume_mounted()) { bool have_vol = false; /* Do we have a candidate volume? */ @@ -139,9 +145,14 @@ mount_next_vol: Dmsg0(200, "Before dir_find_next_appendable_volume.\n"); while (!dir_find_next_appendable_volume(dcr)) { Dmsg0(200, "not dir_find_next\n"); - if (job_canceled(jcr) || !dir_ask_sysop_to_create_appendable_volume(dcr)) { + if (job_canceled(jcr)) { goto bail_out; + } + unlock_volumes(); + if (!dir_ask_sysop_to_create_appendable_volume(dcr)) { + goto no_lock_bail_out; } + lock_volumes(); Dmsg0(200, "Again dir_find_next_append...\n"); } goto mount_next_vol; @@ -320,6 +331,8 @@ read_volume: bail_out: unlock_volumes(); + +no_lock_bail_out: return false; } @@ -349,7 +362,7 @@ int DCR::check_volume_label(bool &ask, bool &autochanger) */ switch (vol_label_status) { case VOL_OK: - Dmsg1(150, "Vol OK name=%s\n", VolumeName); + Dmsg1(150, "Vol OK name=%s\n", dev->VolHdr.VolumeName); dev->VolCatInfo = VolCatInfo; /* structure assignment */ break; /* got a Volume */ case VOL_NAME_ERROR: @@ -413,7 +426,7 @@ int DCR::check_volume_label(bool &ask, bool &autochanger) * This was not the volume we expected, but it is OK with * the Director, so use it. */ - Dmsg1(150, "want new name=%s\n", VolumeName); + Dmsg1(150, "Got new Volume name=%s\n", VolumeName); dev->VolCatInfo = VolCatInfo; /* structure assignment */ break; /* got a Volume */ /* diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 5a3d2cf47a..a106cff04d 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -393,12 +393,13 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName) 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->set_swapping(); - vol->dev->set_unload(); + 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->vol = NULL; /* take volume */ - vol->dev = dev; - dev->vol = 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()); } else { @@ -561,11 +562,9 @@ bool volume_unused(DCR *dcr) * explicitly read in this drive. This allows the SD to remember * where the tapes are or last were. */ - Dmsg3(dbglvl, "=== mark not reserved vol=%s num_writers=%d dev_reserved=%d\n", - dev->vol->vol_name, dev->num_writers, dev->num_reserved()); + Dmsg4(dbglvl, "=== set not reserved vol=%s num_writers=%d dev_reserved=%d dev=%s\n", + dev->vol->vol_name, dev->num_writers, dev->num_reserved(), dev->print_name()); dev->vol->clear_in_use(); - Dmsg2(dbglvl, "=== set not reserved. Vol=%s dev=%s\n", dev->vol->vol_name, - dev->print_name()); if (dev->is_tape() || dev->is_autochanger()) { return true; } else { @@ -1426,10 +1425,14 @@ static bool is_max_jobs_ok(DCR *dcr) DEVICE *dev = dcr->dev; JCR *jcr = dcr->jcr; - Dmsg4(dbglvl, "MaxJobs=%d Jobs=%d reserves=%d Vol=%s\n", + Dmsg5(dbglvl, "MaxJobs=%d Jobs=%d reserves=%d Status=%s Vol=%s\n", dcr->VolCatInfo.VolCatMaxJobs, dcr->VolCatInfo.VolCatJobs, dev->num_reserved(), + dcr->VolCatInfo.VolCatStatus, dcr->VolumeName); + if (strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") == 0) { + return true; + } if (dcr->VolCatInfo.VolCatMaxJobs > 0 && dcr->VolCatInfo.VolCatMaxJobs <= (dcr->VolCatInfo.VolCatJobs + dev->num_reserved())) { /* Max Job Vols depassed or already reserved */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index cfa908b0d6..8b7802ee0d 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -24,6 +24,14 @@ Add long term statistics job table General: +13Apr08 +kes Tweak the swap Volume from one drive to another code so that + it now seems to work. +kes Resolve several problems with recycling that broke the new + code (these problems are in 2.2.9 as well). +kes Remove the volume lock when calling the sysop code. +kes Don't mark a reserved volume with no writers as unused otherwise + jobs fail. 12Apr08 kes Rework class structures for VOLRES, DCR, and DEVICE to make the method names a bit more logical, and for more logically