- case PRE_LABEL:
- Pmsg0(000, _("Volume is prelabeled. This tape cannot be scanned.\n"));
- return;
- break;
- case VOL_LABEL:
- unser_volume_label(dev, rec);
- /* Check Pool info */
- strcpy(pr.Name, dev->VolHdr.PoolName);
- strcpy(pr.PoolType, dev->VolHdr.PoolType);
- if (db_get_pool_record(bjcr, db, &pr)) {
- if (verbose) {
- Pmsg1(000, _("Pool record for %s found in DB.\n"), pr.Name);
- }
- } else {
- if (!update_db) {
- Pmsg1(000, _("VOL_LABEL: Pool record not found for Pool: %s\n"),
- pr.Name);
- }
- create_pool_record(db, &pr);
- }
- if (strcmp(pr.PoolType, dev->VolHdr.PoolType) != 0) {
- Pmsg2(000, _("VOL_LABEL: PoolType mismatch. DB=%s Vol=%s\n"),
- pr.PoolType, dev->VolHdr.PoolType);
- return;
- } else if (verbose) {
- Pmsg1(000, _("Pool type \"%s\" is OK.\n"), pr.PoolType);
- }
-
- /* Check Media Info */
- memset(&mr, 0, sizeof(mr));
- strcpy(mr.VolumeName, dev->VolHdr.VolName);
- mr.PoolId = pr.PoolId;
- if (db_get_media_record(bjcr, db, &mr)) {
- if (verbose) {
- Pmsg1(000, _("Media record for %s found in DB.\n"), mr.VolumeName);
- }
- /* Clear out some volume statistics that will be updated */
- mr.VolJobs = mr.VolFiles = mr.VolBlocks = 0;
- mr.VolBytes = rec->data_len + 20;
- } else {
- if (!update_db) {
- Pmsg1(000, _("VOL_LABEL: Media record not found for Volume: %s\n"),
- mr.VolumeName);
- }
- strcpy(mr.MediaType, dev->VolHdr.MediaType);
- create_media_record(db, &mr, &dev->VolHdr);
- }
- if (strcmp(mr.MediaType, dev->VolHdr.MediaType) != 0) {
- Pmsg2(000, _("VOL_LABEL: MediaType mismatch. DB=%s Vol=%s\n"),
- mr.MediaType, dev->VolHdr.MediaType);
- return;
- } else if (verbose) {
- Pmsg1(000, _("Media type \"%s\" is OK.\n"), mr.MediaType);
- }
- /* Reset some JCR variables */
- for (mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
- mjcr->VolFirstIndex = mjcr->FileIndex = 0;
- mjcr->StartBlock = mjcr->EndBlock = 0;
- mjcr->StartFile = mjcr->EndFile = 0;
- }
-
- Pmsg1(000, _("VOL_LABEL: OK for Volume: %s\n"), mr.VolumeName);
- break;
- case SOS_LABEL:
- mr.VolJobs++;
- if (ignored_msgs > 0) {
- Pmsg1(000, _("%d \"errors\" ignored before first Start of Session record.\n"),
- ignored_msgs);
- ignored_msgs = 0;
- }
- unser_session_label(&label, rec);
- memset(&jr, 0, sizeof(jr));
- jr.JobId = label.JobId;
- if (db_get_job_record(bjcr, db, &jr)) {
- /* Job record already exists in DB */
- update_db = 0; /* don't change db in create_job_record */
- if (verbose) {
- Pmsg1(000, _("SOS_LABEL: Found Job record for JobId: %d\n"), jr.JobId);
- }
- } else {
- /* Must create a Job record in DB */
- if (!update_db) {
- Pmsg1(000, _("SOS_LABEL: Job record not found for JobId: %d\n"),
- jr.JobId);
- }
- }
- /* Create Client record if not already there */
- strcpy(cr.Name, label.ClientName);
- create_client_record(db, &cr);
- jr.ClientId = cr.ClientId;
-
- /* process label, if Job record exists don't update db */
- mjcr = create_job_record(db, &jr, &label, rec);
- update_db = save_update_db;
-
- jr.PoolId = pr.PoolId;
- /* Set start positions into JCR */
- if (dev->state & ST_TAPE) {
- mjcr->StartBlock = dev->block_num;
- mjcr->StartFile = dev->file;
- } else {
- mjcr->StartBlock = (uint32_t)dev->file_addr;
- mjcr->StartFile = (uint32_t)(dev->file_addr >> 32);
- }
- mjcr->start_time = jr.StartTime;
- mjcr->JobLevel = jr.Level;
-
- mjcr->client_name = get_pool_memory(PM_FNAME);
- pm_strcpy(&mjcr->client_name, label.ClientName);
- mjcr->pool_type = get_pool_memory(PM_FNAME);
- pm_strcpy(&mjcr->pool_type, label.PoolType);
- mjcr->fileset_name = get_pool_memory(PM_FNAME);
- pm_strcpy(&mjcr->fileset_name, label.FileSetName);
- mjcr->pool_name = get_pool_memory(PM_FNAME);
- pm_strcpy(&mjcr->pool_name, label.PoolName);
-
- if (rec->VolSessionId != jr.VolSessionId) {
- Pmsg3(000, _("SOS_LABEL: VolSessId mismatch for JobId=%u. DB=%d Vol=%d\n"),
- jr.JobId,
- jr.VolSessionId, rec->VolSessionId);
- return;
- }
- if (rec->VolSessionTime != jr.VolSessionTime) {
- Pmsg3(000, _("SOS_LABEL: VolSessTime mismatch for JobId=%u. DB=%d Vol=%d\n"),
- jr.JobId,
- jr.VolSessionTime, rec->VolSessionTime);
- return;
- }
- if (jr.PoolId != pr.PoolId) {
- Pmsg3(000, _("SOS_LABEL: PoolId mismatch for JobId=%u. DB=%d Vol=%d\n"),
- jr.JobId,
- jr.PoolId, pr.PoolId);
- return;
- }
- break;
- case EOS_LABEL:
- unser_session_label(&elabel, rec);
-
- /* Create FileSet record */
- strcpy(fsr.FileSet, label.FileSetName);
- strcpy(fsr.MD5, label.FileSetMD5);
- create_fileset_record(db, &fsr);
- jr.FileSetId = fsr.FileSetId;
-
- mjcr = get_jcr_by_session(rec->VolSessionId, rec->VolSessionTime);
- if (!mjcr) {
- Pmsg2(000, _("Could not find SessId=%d SessTime=%d for EOS record.\n"),
- rec->VolSessionId, rec->VolSessionTime);
- break;
- }
-
- /* Do the final update to the Job record */
- update_job_record(db, &jr, &elabel, rec);
-
- mjcr->end_time = jr.EndTime;
- mjcr->JobStatus = JS_Terminated;
-
- /* Create JobMedia record */
- create_jobmedia_record(db, mjcr);
- detach_jcr_from_device(dev, mjcr);
- free_jcr(mjcr);
-
- break;
- case EOM_LABEL:
- break;
- case EOT_LABEL: /* end of all tapes */
- /*
- * Wiffle through all jobs still open and close
- * them.
- */
- if (update_db) {
- for (mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
- jr.JobId = mjcr->JobId;
- jr.JobStatus = JS_ErrorTerminated;
- jr.JobFiles = mjcr->JobFiles;
- jr.JobBytes = mjcr->JobBytes;
- jr.VolSessionId = mjcr->VolSessionId;
- jr.VolSessionTime = mjcr->VolSessionTime;
- jr.JobTDate = (utime_t)mjcr->start_time;
- jr.ClientId = mjcr->ClientId;
- free_jcr(mjcr);
- if (!db_update_job_end_record(bjcr, db, &jr)) {
- Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db));
- }
- }
- }
- mr.VolFiles = rec->File;
- mr.VolBlocks = rec->Block;
- mr.VolBytes += mr.VolBlocks * WRITE_BLKHDR_LENGTH; /* approx. */
- mr.VolMounts++;
- update_media_record(db, &mr);
- Pmsg3(0, _("End of Volume. VolFiles=%u VolBlocks=%u VolBytes=%s\n"), mr.VolFiles,
- mr.VolBlocks, edit_uint64_with_commas(mr.VolBytes, ec1));
- break;
- default:
- break;
- }
- return;
+ case PRE_LABEL:
+ Pmsg0(000, _("Volume is prelabeled. This tape cannot be scanned.\n"));
+ return false;
+ break;
+
+ case VOL_LABEL:
+ unser_volume_label(dev, rec);
+ /* Check Pool info */
+ bstrncpy(pr.Name, dev->VolHdr.PoolName, sizeof(pr.Name));
+ bstrncpy(pr.PoolType, dev->VolHdr.PoolType, sizeof(pr.PoolType));
+ num_pools++;
+ if (db_get_pool_record(bjcr, db, &pr)) {
+ if (verbose) {
+ Pmsg1(000, _("Pool record for %s found in DB.\n"), pr.Name);
+ }
+ } else {
+ if (!update_db) {
+ Pmsg1(000, _("VOL_LABEL: Pool record not found for Pool: %s\n"),
+ pr.Name);
+ }
+ create_pool_record(db, &pr);
+ }
+ if (strcmp(pr.PoolType, dev->VolHdr.PoolType) != 0) {
+ Pmsg2(000, _("VOL_LABEL: PoolType mismatch. DB=%s Vol=%s\n"),
+ pr.PoolType, dev->VolHdr.PoolType);
+ return true;
+ } else if (verbose) {
+ Pmsg1(000, _("Pool type \"%s\" is OK.\n"), pr.PoolType);
+ }
+
+ /* Check Media Info */
+ memset(&mr, 0, sizeof(mr));
+ bstrncpy(mr.VolumeName, dev->VolHdr.VolumeName, sizeof(mr.VolumeName));
+ mr.PoolId = pr.PoolId;
+ num_media++;
+ if (db_get_media_record(bjcr, db, &mr)) {
+ if (verbose) {
+ Pmsg1(000, _("Media record for %s found in DB.\n"), mr.VolumeName);
+ }
+ /* Clear out some volume statistics that will be updated */
+ mr.VolJobs = mr.VolFiles = mr.VolBlocks = 0;
+ mr.VolBytes = rec->data_len + 20;
+ } else {
+ if (!update_db) {
+ Pmsg1(000, _("VOL_LABEL: Media record not found for Volume: %s\n"),
+ mr.VolumeName);
+ }
+ bstrncpy(mr.MediaType, dev->VolHdr.MediaType, sizeof(mr.MediaType));
+ create_media_record(db, &mr, &dev->VolHdr);
+ }
+ if (strcmp(mr.MediaType, dev->VolHdr.MediaType) != 0) {
+ Pmsg2(000, _("VOL_LABEL: MediaType mismatch. DB=%s Vol=%s\n"),
+ mr.MediaType, dev->VolHdr.MediaType);
+ return true; /* ignore error */
+ } else if (verbose) {
+ Pmsg1(000, _("Media type \"%s\" is OK.\n"), mr.MediaType);
+ }
+ /* Reset some DCR variables */
+ foreach_dlist(dcr, dev->attached_dcrs) {
+ dcr->VolFirstIndex = dcr->FileIndex = 0;
+ dcr->StartBlock = dcr->EndBlock = 0;
+ dcr->StartFile = dcr->EndFile = 0;
+ }
+
+ Pmsg1(000, _("VOL_LABEL: OK for Volume: %s\n"), mr.VolumeName);
+ break;
+
+ case SOS_LABEL:
+ mr.VolJobs++;
+ num_jobs++;
+ if (ignored_msgs > 0) {
+ Pmsg1(000, _("%d \"errors\" ignored before first Start of Session record.\n"),
+ ignored_msgs);
+ ignored_msgs = 0;
+ }
+ unser_session_label(&label, rec);
+ memset(&jr, 0, sizeof(jr));
+ bstrncpy(jr.Job, label.Job, sizeof(jr.Job));
+ if (db_get_job_record(bjcr, db, &jr)) {
+ /* Job record already exists in DB */
+ update_db = false; /* don't change db in create_job_record */
+ if (verbose) {
+ Pmsg1(000, _("SOS_LABEL: Found Job record for JobId: %d\n"), jr.JobId);
+ }
+ } else {
+ /* Must create a Job record in DB */
+ if (!update_db) {
+ Pmsg1(000, _("SOS_LABEL: Job record not found for JobId: %d\n"),
+ jr.JobId);
+ }
+ }
+ /* Create Client record if not already there */
+ bstrncpy(cr.Name, label.ClientName, sizeof(cr.Name));
+ create_client_record(db, &cr);
+ jr.ClientId = cr.ClientId;
+
+ /* process label, if Job record exists don't update db */
+ mjcr = create_job_record(db, &jr, &label, rec);
+ dcr = mjcr->read_dcr;
+ update_db = save_update_db;
+
+ jr.PoolId = pr.PoolId;
+#ifdef xxx
+ /* Set start positions into JCR */
+ if (dev->is_tape()) {
+ /*
+ * Note, we have already advanced past current block,
+ * so the correct number is block_num - 1
+ */
+ dcr->StartBlock = dev->block_num - 1;
+ dcr->StartFile = dev->file;
+ } else {
+ dcr->StartBlock = (uint32_t)dev->file_addr;
+ dcr->StartFile = (uint32_t)(dev->file_addr >> 32);
+ }
+#endif
+ mjcr->start_time = jr.StartTime;
+ mjcr->JobLevel = jr.JobLevel;
+
+ mjcr->client_name = get_pool_memory(PM_FNAME);
+ pm_strcpy(mjcr->client_name, label.ClientName);
+ mjcr->fileset_name = get_pool_memory(PM_FNAME);
+ pm_strcpy(mjcr->fileset_name, label.FileSetName);
+ bstrncpy(dcr->pool_type, label.PoolType, sizeof(dcr->pool_type));
+ bstrncpy(dcr->pool_name, label.PoolName, sizeof(dcr->pool_name));
+
+ if (rec->VolSessionId != jr.VolSessionId) {
+ Pmsg3(000, _("SOS_LABEL: VolSessId mismatch for JobId=%u. DB=%d Vol=%d\n"),
+ jr.JobId,
+ jr.VolSessionId, rec->VolSessionId);
+ return true; /* ignore error */
+ }
+ if (rec->VolSessionTime != jr.VolSessionTime) {
+ Pmsg3(000, _("SOS_LABEL: VolSessTime mismatch for JobId=%u. DB=%d Vol=%d\n"),
+ jr.JobId,
+ jr.VolSessionTime, rec->VolSessionTime);
+ return true; /* ignore error */
+ }
+ if (jr.PoolId != pr.PoolId) {
+ Pmsg3(000, _("SOS_LABEL: PoolId mismatch for JobId=%u. DB=%d Vol=%d\n"),
+ jr.JobId,
+ jr.PoolId, pr.PoolId);
+ return true; /* ignore error */
+ }
+ break;
+
+ case EOS_LABEL:
+ unser_session_label(&elabel, rec);
+
+ /* Create FileSet record */
+ bstrncpy(fsr.FileSet, label.FileSetName, sizeof(fsr.FileSet));
+ bstrncpy(fsr.MD5, label.FileSetMD5, sizeof(fsr.MD5));
+ create_fileset_record(db, &fsr);
+ jr.FileSetId = fsr.FileSetId;
+
+ mjcr = get_jcr_by_session(rec->VolSessionId, rec->VolSessionTime);
+ if (!mjcr) {
+ Pmsg2(000, _("Could not find SessId=%d SessTime=%d for EOS record.\n"),
+ rec->VolSessionId, rec->VolSessionTime);
+ break;
+ }
+
+ /* Do the final update to the Job record */
+ update_job_record(db, &jr, &elabel, rec);
+
+ mjcr->end_time = jr.EndTime;
+ mjcr->JobStatus = JS_Terminated;
+
+ /* Create JobMedia record */
+ mjcr->read_dcr->VolLastIndex = dcr->VolLastIndex;
+ create_jobmedia_record(db, mjcr);
+ detach_dcr_from_dev(mjcr->read_dcr);
+ free_jcr(mjcr);
+
+ break;
+
+ case EOM_LABEL:
+ break;
+
+ case EOT_LABEL: /* end of all tapes */
+ /*
+ * Wiffle through all jobs still open and close
+ * them.
+ */
+ if (update_db) {
+ DCR *mdcr;
+ foreach_dlist(mdcr, dev->attached_dcrs) {
+ JCR *mjcr = mdcr->jcr;
+ if (!mjcr || mjcr->JobId == 0) {
+ continue;
+ }
+ jr.JobId = mjcr->JobId;
+ /* Mark Job as Error Terimined */
+ jr.JobStatus = JS_ErrorTerminated;
+ jr.JobFiles = mjcr->JobFiles;
+ jr.JobBytes = mjcr->JobBytes;
+ jr.VolSessionId = mjcr->VolSessionId;
+ jr.VolSessionTime = mjcr->VolSessionTime;
+ jr.JobTDate = (utime_t)mjcr->start_time;
+ jr.ClientId = mjcr->ClientId;
+ if (!db_update_job_end_record(bjcr, db, &jr)) {
+ Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db));
+ }
+ mjcr->read_dcr = NULL;
+ free_jcr(mjcr);
+ }
+ }
+ mr.VolFiles = rec->File;
+ mr.VolBlocks = rec->Block;
+ mr.VolBytes += mr.VolBlocks * WRITE_BLKHDR_LENGTH; /* approx. */
+ mr.VolMounts++;
+ update_media_record(db, &mr);
+ Pmsg3(0, _("End of all Volumes. VolFiles=%u VolBlocks=%u VolBytes=%s\n"), mr.VolFiles,
+ mr.VolBlocks, edit_uint64_with_commas(mr.VolBytes, ec1));
+ break;
+ default:
+ break;
+ } /* end switch */
+ return true;