- /*
- * 2. Try finding a recycled volume
- */
- ok = find_recycled_volume(jcr, InChanger, mr);
- Dmsg2(100, "find_recycled_volume %d FW=%d\n", ok, mr->FirstWritten);
- if (!ok) {
- /*
- * 3. Try recycling any purged volume
- */
- ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
- if (!ok) {
- /*
- * 4. Try pruning Volumes
- */
- prune_volumes(jcr);
- ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
- if (InChanger) {
- InChanger = false;
- if (!ok) {
- continue; /* retry again accepting any volume */
- }
- }
- Dmsg2(200, "find_recycled_volume2 %d FW=%d\n", ok, mr->FirstWritten);
- if (!ok && create) {
- /*
- * 5. Try "creating" a new Volume
- */
- ok = newVolume(jcr, mr);
- }
- }
- }
-
- /*
- * Look at more drastic ways to find an Appendable Volume
- */
- if (!ok && (jcr->pool->purge_oldest_volume ||
- jcr->pool->recycle_oldest_volume)) {
- Dmsg2(200, "No next volume found. PurgeOldest=%d\n RecyleOldest=%d",
- jcr->pool->purge_oldest_volume, jcr->pool->recycle_oldest_volume);
- /* Find oldest volume to recycle */
- ok = db_find_next_volume(jcr, jcr->db, -1, InChanger, mr);
- Dmsg1(400, "Find oldest=%d\n", ok);
- if (ok) {
- UAContext *ua;
- Dmsg0(400, "Try purge.\n");
- /*
- * 5. Try to purging oldest volume only if not UA calling us.
- */
- ua = new_ua_context(jcr);
- if (jcr->pool->purge_oldest_volume && create) {
- Jmsg(jcr, M_INFO, 0, _("Purging oldest volume \"%s\"\n"), mr->VolumeName);
- ok = purge_jobs_from_volume(ua, mr);
- /*
- * 5. or try recycling the oldest volume
- */
- } else if (jcr->pool->recycle_oldest_volume) {
- Jmsg(jcr, M_INFO, 0, _("Pruning oldest volume \"%s\"\n"), mr->VolumeName);
- ok = prune_volume(ua, mr);
- }
- free_ua_context(ua);
- if (ok) {
- ok = recycle_volume(jcr, mr);
- Dmsg1(400, "Recycle after purge oldest=%d\n", ok);
- }
- }
- }
+ /*
+ * No volume found, apply algorithm
+ */
+ Dmsg4(dbglvl, "after find_next_vol ok=%d index=%d InChanger=%d Vstat=%s\n",
+ ok, index, InChanger, mr->VolStatus);
+ /*
+ * 2. Try finding a recycled volume
+ */
+ ok = find_recycled_volume(jcr, InChanger, mr, store);
+ set_storageid_in_mr(store, mr); /* put StorageId in new record */
+ Dmsg2(dbglvl, "find_recycled_volume ok=%d FW=%d\n", ok, mr->FirstWritten);
+ if (!ok) {
+ /*
+ * 3. Try recycling any purged volume
+ */
+ ok = recycle_oldest_purged_volume(jcr, InChanger, mr, store);
+ set_storageid_in_mr(store, mr); /* put StorageId in new record */
+ if (!ok) {
+ /*
+ * 4. Try pruning Volumes
+ */
+ if (prune) {
+ Dmsg0(dbglvl, "Call prune_volumes\n");
+ prune_volumes(jcr, InChanger, mr, store);
+ }
+ ok = recycle_oldest_purged_volume(jcr, InChanger, mr, store);
+ set_storageid_in_mr(store, mr); /* put StorageId in new record */
+ if (!ok && create) {
+ Dmsg4(dbglvl, "after prune volumes_vol ok=%d index=%d InChanger=%d Vstat=%s\n",
+ ok, index, InChanger, mr->VolStatus);
+ /*
+ * 5. Try pulling a volume from the Scratch pool
+ */
+ ok = get_scratch_volume(jcr, InChanger, mr, store);
+ set_storageid_in_mr(store, mr); /* put StorageId in new record */
+ Dmsg4(dbglvl, "after get scratch volume ok=%d index=%d InChanger=%d Vstat=%s\n",
+ ok, index, InChanger, mr->VolStatus);
+ }
+ /*
+ * If we are using an Autochanger and have not found
+ * a volume, retry looking for any volume.
+ */
+ if (!ok && InChanger) {
+ InChanger = false;
+ continue; /* retry again accepting any volume */
+ }
+ }
+ }
+
+
+ if (!ok && create) {
+ /*
+ * 6. Try "creating" a new Volume
+ */
+ ok = newVolume(jcr, mr, store);
+ }
+ /*
+ * Look at more drastic ways to find an Appendable Volume
+ */
+ if (!ok && (jcr->pool->purge_oldest_volume ||
+ jcr->pool->recycle_oldest_volume)) {
+ Dmsg2(dbglvl, "No next volume found. PurgeOldest=%d\n RecyleOldest=%d",
+ jcr->pool->purge_oldest_volume, jcr->pool->recycle_oldest_volume);
+ /* Find oldest volume to recycle */
+ set_storageid_in_mr(store, mr); /* update storage id */
+ ok = db_find_next_volume(jcr, jcr->db, -1, InChanger, mr);
+ set_storageid_in_mr(store, mr); /* update storageid */
+ Dmsg1(dbglvl, "Find oldest=%d Volume\n", ok);
+ if (ok && prune) {
+ UAContext *ua;
+ Dmsg0(dbglvl, "Try purge Volume.\n");
+ /*
+ * 7. Try to purging oldest volume only if not UA calling us.
+ */
+ ua = new_ua_context(jcr);
+ if (jcr->pool->purge_oldest_volume && create) {
+ Jmsg(jcr, M_INFO, 0, _("Purging oldest volume \"%s\"\n"), mr->VolumeName);
+ ok = purge_jobs_from_volume(ua, mr);
+ /*
+ * 8. or try recycling the oldest volume
+ */
+ } else if (jcr->pool->recycle_oldest_volume) {
+ Jmsg(jcr, M_INFO, 0, _("Pruning oldest volume \"%s\"\n"), mr->VolumeName);
+ ok = prune_volume(ua, mr);
+ }
+ free_ua_context(ua);
+ if (ok) {
+ ok = recycle_volume(jcr, mr);
+ Dmsg1(dbglvl, "Recycle after purge oldest=%d\n", ok);
+ }
+ }
+ }