X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Freserve.c;h=b262b76b216c9534fa28a1045a30f09f1e419b77;hb=0d99c317e0ac4a98ccbe01ac960e4d0c35184eb9;hp=7dbede4b7c8aca7a395bafa95866eccadaba50db;hpb=86138bc5550dda95c576f6a059c29134cf3f4a04;p=bacula%2Fbacula diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 7dbede4b7c..b262b76b21 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - Bacula® is a registered trademark of John Walker. + Bacula® is a registered trademark of Kern Sibbald. The licensor of Bacula is the Free Software Foundation Europe (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. @@ -170,7 +170,7 @@ enum { debug_nolock = false }; -static void debug_list_volumes(const char *imsg) +void debug_list_volumes(const char *imsg) { VOLRES *vol; POOL_MEM msg(PM_MESSAGE); @@ -187,17 +187,6 @@ static void debug_list_volumes(const char *imsg) Dmsg1(dbglvl, "%s", msg.c_str()); } -#ifdef xxx - DEVICE *dev = NULL; - foreach_dlist(vol, vol_list) { - if (vol->dev == dev) { - Dmsg0(dbglvl, "Two Volumes on same device.\n"); - ASSERT(0); - dev = vol->dev; - } - } -#endif - unlock_volumes(); } @@ -346,8 +335,6 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName) if (strcmp(vol->vol_name, VolumeName) == 0) { Dmsg2(dbglvl, "=== set reserved vol=%s dev=%s\n", VolumeName, vol->dev->print_name()); - vol->set_in_use(); /* retake vol if released previously */ - dcr->reserved_volume = true; /* reserved volume */ goto get_out; /* Volume already on this device */ } else { /* Don't release a volume if it was reserved by someone other than us */ @@ -358,6 +345,7 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName) } Dmsg2(dbglvl, "reserve_vol free vol=%s at %p\n", vol->vol_name, vol->vol_name); free_volume(dev); + Dmsg0(50, "set_unload\n"); dev->set_unload(); /* have to unload current volume */ debug_list_volumes("reserve_vol free"); } @@ -398,8 +386,10 @@ 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 */ + Dmsg0(50, "set_unload\n"); + dev->set_unload(); /* Unload any volume that is on our drive */ dcr->dev = vol->dev; /* temp point to other dev */ - slot = get_autochanger_loaded_slot(dcr); /* get slot */ + slot = get_autochanger_loaded_slot(dcr); /* get slot on other drive */ dcr->dev = dev; /* restore dev */ vol->set_slot(slot); /* save slot */ vol->dev->set_unload(); /* unload the other drive */ @@ -428,6 +418,7 @@ get_out: vol->dev->print_name()); vol->set_in_use(); dcr->reserved_volume = true; + bstrncpy(dcr->VolumeName, vol->vol_name, sizeof(dcr->VolumeName)); } debug_list_volumes("end new volume"); unlock_volumes(); @@ -546,23 +537,12 @@ bool volume_unused(DCR *dcr) } if (dev->vol->is_swapping()) { Dmsg1(dbglvl, "vol_unused: vol being swapped on %s\n", dev->print_name()); - debug_list_volumes("swapping vol cannot unreserve_volume"); + Dmsg1(dbglvl, "=== clear in_use vol=%s\n", dev->vol->vol_name); + dev->vol->clear_in_use(); + debug_list_volumes("swapping vol cannot free_volume"); return false; } -#ifdef xxx - if (dev->is_busy()) { - Dmsg1(dbglvl, "vol_unused: busy on %s\n", dev->print_name()); - debug_list_volumes("dev busy cannot unreserve_volume"); - return false; - } -#endif -#ifdef xxx - if (dev->num_writers > 0 || dev->num_reserved() > 0) { - ASSERT(0); - } -#endif - /* * If this is a tape, we do not free the volume, rather we wait * until the autoloader unloads it, or until another tape is @@ -571,6 +551,7 @@ bool volume_unused(DCR *dcr) */ 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()); + Dmsg1(dbglvl, "=== clear in_use vol=%s\n", dev->vol->vol_name); dev->vol->clear_in_use(); if (dev->is_tape() || dev->is_autochanger()) { return true; @@ -598,9 +579,10 @@ bool free_volume(DEVICE *dev) vol = dev->vol; /* Don't free a volume while it is being swapped */ if (!vol->is_swapping()) { + Dmsg1(dbglvl, "=== clear in_use vol=%s\n", dev->vol->vol_name); dev->vol = NULL; vol_list->remove(vol); - Dmsg2(dbglvl, "=== free_volume %s dev=%s\n", vol->vol_name, dev->print_name()); + Dmsg2(dbglvl, "=== remove volume %s dev=%s\n", vol->vol_name, dev->print_name()); free_vol_item(vol); debug_list_volumes("free_volume"); } @@ -1040,7 +1022,7 @@ bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx) Dmsg0(dbglvl, "deleted temp vol list\n"); Dmsg0(dbglvl, "unlock volumes\n"); unlock_volumes(); - debug_list_volumes("=== After free temp table\n"); + debug_list_volumes("after free temp table"); } if (ok) { Dmsg1(dbglvl, "OK dev found. Vol=%s from in-use vols list\n", rctx.VolumeName); @@ -1100,6 +1082,11 @@ int search_res_for_device(RCTX &rctx) /* Try each device in this AutoChanger */ foreach_alist(rctx.device, changer->device) { Dmsg1(dbglvl, "Try changer device %s\n", rctx.device->hdr.name); + if (!rctx.device->autoselect) { + Dmsg1(100, "Device %s not autoselect skipped.\n", + rctx.device->hdr.name); + continue; /* device is not available */ + } stat = reserve_device(rctx); if (stat != 1) { /* try another device */ continue; @@ -1554,7 +1541,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 */