X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Freserve.c;h=b262b76b216c9534fa28a1045a30f09f1e419b77;hb=0d99c317e0ac4a98ccbe01ac960e4d0c35184eb9;hp=5a3d2cf47a51eda8ab89c5bc559511ad34d63f9a;hpb=17350b711d777172e5ef8b1e865d979e92ff0a5c;p=bacula%2Fbacula diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 5a3d2cf47a..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"); } @@ -386,21 +374,31 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName) nvol->dev = NULL; /* don't zap dev entry */ free_vol_item(nvol); - /* Check if we are trying to use the Volume on a different drive */ + /* + * Check if we are trying to use the Volume on a different drive + * dev is our device + * vol->dev is where the Volume we want is + */ if (dev != vol->dev) { /* Caller wants to switch Volume to another device */ if (!vol->dev->is_busy() && !vol->is_swapping()) { + int32_t slot; 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(); + 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 on other drive */ + dcr->dev = dev; /* restore dev */ + vol->set_slot(slot); /* save slot */ + vol->dev->set_unload(); /* unload the other 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; - Dmsg3(dbglvl, "==== Swap vol=%s from dev=%s to %s\n", - VolumeName, vol->dev->print_name(), dev->print_name()); + dev->set_load(); /* then reload on our drive */ + vol->dev->vol = NULL; /* remove volume from other drive */ + vol->dev = dev; /* point the Volume at our drive */ + dev->vol = vol; /* point our drive at the Volume */ } else { Dmsg3(dbglvl, "==== Swap not possible Vol busy vol=%s from dev=%s to %s\n", VolumeName, vol->dev->print_name(), dev->print_name()); @@ -420,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(); @@ -538,34 +537,22 @@ 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 * 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()); + Dmsg1(dbglvl, "=== clear in_use vol=%s\n", dev->vol->vol_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 { @@ -590,11 +577,15 @@ bool free_volume(DEVICE *dev) } lock_volumes(); vol = dev->vol; - dev->vol = NULL; - vol_list->remove(vol); - Dmsg2(dbglvl, "=== free_volume %s dev=%s\n", vol->vol_name, dev->print_name()); - free_vol_item(vol); - debug_list_volumes("free_volume"); + /* 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, "=== remove volume %s dev=%s\n", vol->vol_name, dev->print_name()); + free_vol_item(vol); + debug_list_volumes("free_volume"); + } unlock_volumes(); return true; } @@ -792,9 +783,6 @@ static bool use_storage_cmd(JCR *jcr) rctx.PreferMountedVols = false; rctx.exact_match = false; rctx.autochanger_only = true; - Dmsg5(dbglvl, "PrefMnt=%d exact=%d suitable=%d chgronly=%d any=%d\n", - rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device, - rctx.autochanger_only, rctx.any_drive); if ((ok = find_suitable_device_for_job(jcr, rctx))) { break; } @@ -807,9 +795,6 @@ static bool use_storage_cmd(JCR *jcr) rctx.try_low_use_drive = false; } rctx.autochanger_only = false; - Dmsg5(dbglvl, "PrefMnt=%d exact=%d suitable=%d chgronly=%d any=%d\n", - rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device, - rctx.autochanger_only, rctx.any_drive); if ((ok = find_suitable_device_for_job(jcr, rctx))) { break; } @@ -822,25 +807,16 @@ static bool use_storage_cmd(JCR *jcr) rctx.PreferMountedVols = true; rctx.exact_match = true; rctx.autochanger_only = false; - Dmsg5(dbglvl, "PrefMnt=%d exact=%d suitable=%d chgronly=%d any=%d\n", - rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device, - rctx.autochanger_only, rctx.any_drive); if ((ok = find_suitable_device_for_job(jcr, rctx))) { break; } /* Look for any mounted drive */ rctx.exact_match = false; - Dmsg5(dbglvl, "PrefMnt=%d exact=%d suitable=%d chgronly=%d any=%d\n", - rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device, - rctx.autochanger_only, rctx.any_drive); if ((ok = find_suitable_device_for_job(jcr, rctx))) { break; } /* Try any drive */ rctx.any_drive = true; - Dmsg5(dbglvl, "PrefMnt=%d exact=%d suitable=%d chgronly=%d any=%d\n", - rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device, - rctx.autochanger_only, rctx.any_drive); if ((ok = find_suitable_device_for_job(jcr, rctx))) { break; } @@ -933,9 +909,9 @@ bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx) } else { dirstore = jcr->read_store; } - Dmsg4(dbglvl, "PrefMnt=%d exact=%d suitable=%d chgronly=%d\n", - rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device, - rctx.autochanger_only); + Dmsg5(dbglvl, "Start find_suit_dev PrefMnt=%d exact=%d suitable=%d chgronly=%d any=%d\n", + rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device, + rctx.autochanger_only, rctx.any_drive); /* * If the appropriate conditions of this if are met, namely that @@ -1046,10 +1022,10 @@ 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, "Usable dev found. Vol=%s from in-use vols list\n", rctx.VolumeName); + Dmsg1(dbglvl, "OK dev found. Vol=%s from in-use vols list\n", rctx.VolumeName); return true; } @@ -1081,7 +1057,9 @@ bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx) } } if (ok) { - Dmsg1(dbglvl, "Usable dev found. Vol=%s\n", rctx.VolumeName); + Dmsg1(dbglvl, "OK dev found. Vol=%s\n", rctx.VolumeName); + } else { + Dmsg0(dbglvl, "Leave find_suit_dev: no dev found.\n"); } return ok; } @@ -1104,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; @@ -1339,8 +1322,8 @@ bail_out: /* - * We reserve the device for appending by incrementing the - * reserved_device. We do virtually all the same work that + * We reserve the device for appending by incrementing + * num_reserved(). We do virtually all the same work that * is done in acquire_device_for_append(), but we do * not attempt to mount the device. This routine allows * the DIR to reserve multiple devices before *really* @@ -1426,10 +1409,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 */ @@ -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 */