*/
/* Requests from the Storage daemon */
-static char Find_media[] = "CatReq Job=%127s FindMedia=%d\n";
+static char Find_media[] = "CatReq Job=%127s FindMedia=%d pool_name=%127s media_type=%127s\n";
static char Get_Vol_Info[] = "CatReq Job=%127s GetVolInfo VolName=%127s write=%d\n";
static char Update_media[] = "CatReq Job=%127s UpdateMedia VolName=%s"
mr->VolParts,
mr->LabelType);
unbash_spaces(mr->VolumeName);
- Dmsg2(400, "Vol Info for %s: %s", jcr->Job, sd->msg);
+ Dmsg2(100, "Vol Info for %s: %s", jcr->Job, sd->msg);
return stat;
}
MEDIA_DBR mr, sdmr;
JOBMEDIA_DBR jm;
char Job[MAX_NAME_LENGTH];
+ char pool_name[MAX_NAME_LENGTH];
int index, ok, label, writing;
POOLMEM *omsg;
+ POOL_DBR pr;
memset(&mr, 0, sizeof(mr));
memset(&sdmr, 0, sizeof(sdmr));
/*
* Request to find next appendable Volume for this Job
*/
- Dmsg1(400, "catreq %s", bs->msg);
- if (sscanf(bs->msg, Find_media, &Job, &index) == 2) {
- ok = find_next_volume_for_append(jcr, &mr, true /*permit create new vol*/);
+ Dmsg1(100, "catreq %s", bs->msg);
+ if (!jcr->db) {
+ omsg = get_memory(bs->msglen+1);
+ pm_strcpy(omsg, bs->msg);
+ bnet_fsend(bs, "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));
+ ok = db_get_pool_record(jcr, jcr->db, &pr);
+ if (ok) {
+ mr.PoolId = pr.PoolId;
+ ok = find_next_volume_for_append(jcr, &mr, true /*permit create new vol*/);
+ }
/*
* Send Find Media response to Storage daemon
*/
send_volume_info_to_storage_daemon(jcr, bs, &mr);
} else {
bnet_fsend(bs, "1901 No Media.\n");
+ Dmsg0(500, "1901 No Media.\n");
}
/*
* Request to find specific Volume information
*/
} else if (sscanf(bs->msg, Get_Vol_Info, &Job, &mr.VolumeName, &writing) == 3) {
- Dmsg1(400, "CatReq GetVolInfo Vol=%s\n", mr.VolumeName);
+ Dmsg1(500, "CatReq GetVolInfo Vol=%s\n", mr.VolumeName);
/*
* Find the Volume
*/
} else {
bnet_fsend(bs, "1997 Volume \"%s\" not in catalog.\n", mr.VolumeName);
+ Dmsg1(400, "1997 Volume \"%s\" not in catalog.\n", mr.VolumeName);
}
-
/*
* Request to update Media record. Comes typically at the end
* of a Storage daemon Job Session, when labeling/relabeling a
return;
}
/* Set first written time if this is first job */
- if (mr.VolJobs == 0 || sdmr.VolJobs == 1) {
+ if (mr.FirstWritten == 0) {
mr.FirstWritten = jcr->start_time; /* use Job start time as first write */
+ mr.set_first_written = true;
}
/* If we just labeled the tape set time */
- Dmsg2(400, "label=%d labeldate=%d\n", label, mr.LabelDate);
if (label || mr.LabelDate == 0) {
- mr.LabelDate = time(NULL);
+ mr.LabelDate = jcr->start_time;
+ mr.set_label_date = true;
+ Dmsg2(400, "label=%d labeldate=%d\n", label, mr.LabelDate);
} else {
/*
* Insanity check for VolFiles get set to a smaller value
*/
if (sdmr.VolFiles < mr.VolFiles) {
- Jmsg(jcr, M_ERROR, 0, _("ERROR!! Volume Files at %u being set to %u. This is probably wrong.\n"),
- mr.VolFiles, sdmr.VolFiles);
+ Jmsg(jcr, M_FATAL, 0, _("Volume Files at %u being set to %u"
+ " for Volume \"%s\". This is incorrect.\n"),
+ mr.VolFiles, sdmr.VolFiles, mr.VolumeName);
+ bnet_fsend(bs, "1992 Update Media error\n");
+ db_unlock(jcr->db);
+ return;
}
}
Dmsg2(400, "Update media: BefVolJobs=%u After=%u\n", mr.VolJobs, sdmr.VolJobs);
* Check if it has expired, and if not update the DB. Note, if
* Volume has expired, has_volume_expired() will update the DB.
*/
- if (has_volume_expired(jcr, &mr)) {
- send_volume_info_to_storage_daemon(jcr, bs, &mr);
- } else if (db_update_media_record(jcr, jcr->db, &mr)) {
+ if (has_volume_expired(jcr, &mr) || db_update_media_record(jcr, jcr->db, &mr)) {
send_volume_info_to_storage_daemon(jcr, bs, &mr);
} else {
- Jmsg(jcr, M_ERROR, 0, _("Catalog error updating Media record. %s"),
+ Jmsg(jcr, M_FATAL, 0, _("Catalog error updating Media record. %s"),
db_strerror(jcr->db));
bnet_fsend(bs, "1992 Update Media error\n");
Dmsg0(400, "send error\n");
Dmsg6(400, "create_jobmedia JobId=%d MediaId=%d SF=%d EF=%d FI=%d LI=%d\n",
jm.JobId, jm.MediaId, jm.StartFile, jm.EndFile, jm.FirstIndex, jm.LastIndex);
if (!db_create_jobmedia_record(jcr, jcr->db, &jm)) {
- Jmsg(jcr, M_ERROR, 0, _("Catalog error creating JobMedia record. %s"),
+ Jmsg(jcr, M_FATAL, 0, _("Catalog error creating JobMedia record. %s"),
db_strerror(jcr->db));
bnet_fsend(bs, "1991 Update JobMedia error\n");
} else {
omsg = get_memory(bs->msglen+1);
pm_strcpy(omsg, bs->msg);
bnet_fsend(bs, "1990 Invalid Catalog Request: %s", omsg);
- Jmsg1(jcr, M_ERROR, 0, _("Invalid Catalog request: %s"), omsg);
+ Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog request: %s"), omsg);
free_memory(omsg);
}
Dmsg1(400, ">CatReq response: %s", bs->msg);