- Dmsg1(200, "catreq %s", bs->msg);
- if (sscanf(bs->msg, Find_media, &Job, &index) == 2) {
- mr.PoolId = jcr->PoolId;
- strcpy(mr.MediaType, jcr->store->media_type);
- Dmsg2(120, "CatReq FindMedia: Id=%d, MediaType=%s\n",
- mr.PoolId, mr.MediaType);
- /*
- * Find the Next Volume for Append
- */
-next_volume:
- strcpy(mr.VolStatus, "Append"); /* want only appendable volumes */
- ok = db_find_next_volume(jcr, jcr->db, index, &mr);
- Dmsg2(100, "catreq after find_next_vol ok=%d FW=%d\n", ok, mr.FirstWritten);
- if (!ok) {
- Dmsg1(200, "No next volume found. RecycleOldest=%d\n",
- jcr->pool->recycle_oldest_volume);
- if (jcr->pool->recycle_oldest_volume) {
- Dmsg0(200, "Request to find oldest volume.\n");
- /* Find oldest volume to recycle */
- ok = db_find_next_volume(jcr, jcr->db, -1, &mr);
- Dmsg1(400, "Find oldest=%d\n", ok);
- if (ok) {
- UAContext ua;
- Dmsg0(400, "Try purge.\n");
- /* Try to purge oldest volume */
- create_ua_context(jcr, &ua);
- ok = purge_jobs_from_volume(&ua, &mr);
- free_ua_context(&ua);
- if (ok) {
- ok = recycle_oldest_purged_volume(jcr, &mr);
- Dmsg1(400, "Recycle after recycle oldest=%d\n", ok);
- }
- }
- }
- if (!ok) {
- /* Well, try finding recycled tapes */
- ok = find_recycled_volume(jcr, &mr);
- Dmsg2(100, "find_recycled_volume1 %d FW=%d\n", ok, mr.FirstWritten);
- if (!ok) {
- prune_volumes(jcr);
- ok = recycle_oldest_purged_volume(jcr, &mr);
- Dmsg2(200, "find_recycled_volume2 %d FW=%d\n", ok, mr.FirstWritten);
- if (!ok) {
- /* See if we can create a new Volume */
- ok = newVolume(jcr, &mr);
- }
- }
- }
- }
- /* Check if use duration has expired */
- Dmsg2(100, "VolJobs=%d FirstWritten=%d\n", mr.VolJobs, mr.FirstWritten);
- if (ok && mr.VolJobs > 0 && mr.VolUseDuration > 0 &&
- strcmp(mr.VolStatus, "Append") == 0) {
- utime_t now = time(NULL);
- if (mr.VolUseDuration <= (now - mr.FirstWritten)) {
- Dmsg4(100, "Duration=%d now=%d start=%d now-start=%d\n",
- (int)mr.VolUseDuration, (int)now, (int)mr.FirstWritten,
- (int)(now-mr.FirstWritten));
- Jmsg(jcr, M_INFO, 0, _("Max configured use duration exceeded. "
- "Marking Volume \"%s\" as Used.\n"), mr.VolumeName);
- strcpy(mr.VolStatus, "Used"); /* yes, mark as used */
- if (!db_update_media_record(jcr, jcr->db, &mr)) {
- Jmsg(jcr, M_ERROR, 0, _("Catalog error updating Media record. %s"),
- db_strerror(jcr->db));
- } else if (retry++ < 200) { /* sanity check */
- goto next_volume;
- } else {
- Jmsg(jcr, M_ERROR, 0, _(
-"We seem to be looping trying to find the next volume. I give up. Ask operator.\n"));
- }
- ok = FALSE; /* give up */
- }
+ Dmsg1(100, "catreq %s", bs->msg);
+ if (!jcr->db) {
+ omsg = get_memory(bs->msglen+1);
+ pm_strcpy(omsg, bs->msg);
+ bs->fsend(_("1990 Invalid Catalog Request: %s"), omsg);
+ Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog request; DB not open: %s"), omsg);
+ free_memory(omsg);
+ return;
+ }
+ /*
+ * Find next appendable medium for SD
+ */
+ if (sscanf(bs->msg, Find_media, &Job, &index, &pool_name, &mr.MediaType) == 4) {
+ memset(&pr, 0, sizeof(pr));
+ bstrncpy(pr.Name, pool_name, sizeof(pr.Name));
+ unbash_spaces(pr.Name);
+ ok = db_get_pool_record(jcr, jcr->db, &pr);
+ if (ok) {
+ mr.PoolId = pr.PoolId;
+ mr.StorageId = jcr->wstore->StorageId;
+ mr.ScratchPoolId = pr.ScratchPoolId;
+ ok = find_next_volume_for_append(jcr, &mr, index, fnv_create_vol, fnv_prune);
+ Dmsg3(050, "find_media ok=%d idx=%d vol=%s\n", ok, index, mr.VolumeName);