From 4d27d0e0d37b359aa9ffd60ca0924a54e02d3825 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 11 Apr 2005 08:30:05 +0000 Subject: [PATCH] - Remove Created new FileSet message as it always comes out in the daemon messages. - eliminate dev_is_tape() in favor of method dev->is_tape() - Turn on disk seeking during restore for Disk Volumes. This required some changes to bscan -- they seem a bit suspect as they are not symmetrical for tape/files. - Remove some of the recursion in stored/parse_bsr.c - Move rescue out to a new Bacula project. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1923 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 59 ++-- bacula/src/dird/job.c | 2 + bacula/src/stored/acquire.c | 6 +- bacula/src/stored/bscan.c | 604 ++++++++++++++++---------------- bacula/src/stored/dev.c | 543 ++++++++++++++-------------- bacula/src/stored/device.c | 82 ++--- bacula/src/stored/dircmd.c | 4 +- bacula/src/stored/match_bsr.c | 122 ++++--- bacula/src/stored/mount.c | 154 ++++---- bacula/src/stored/parse_bsr.c | 316 +++++++++-------- bacula/src/stored/protos.h | 1 - bacula/src/stored/read_record.c | 316 ++++++++--------- 12 files changed, 1110 insertions(+), 1099 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index e735d56d9d..c64a47047a 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -1,5 +1,5 @@ Kern's ToDo List - 11 March 2005 + 09 April 2005 Major development: Project Developer @@ -10,13 +10,13 @@ Version 1.37 Kern (see below) 1.37 Major Projects: #3 Migration (Move, Copy, Archive Jobs) -#4 Embedded Python Scripting - (Implemented in Dir/SD) #7 Single Job Writing to Multiple Storage Devices + (probably not) ## Integrate web-bacula into a new Bacula project with bimagemgr. ## Consider moving docs to their own project. +## Move rescue to its own project. Autochangers: - 3. Prevent two drives requesting the same Volume in any given @@ -24,19 +24,13 @@ Autochangers: in an Autochanger. - 7. Implement new Console commands to allow offlining/reserving drives, and possibly manipulating the autochanger (much asked for). +- Make "update slots" when pointing to Autochanger, remove + all Volumes from other drives. "update slots all-drives"? For 1.37: -- Add disk seeking on restore. -- If the user puts "Purge Oldest Volume = yes" or "Recycle Oldest Volume = yes" - and there is only one volume in the pool, refuse to do it -- otherwise - he fills the Volume, then immediately starts reusing it. +- Add disk seeking on restore; turn off seek on tapes. + stored/match_bsr.c - Implement "NewVolumeEachJob = yes|no" in Dir. -- Make "update slots" when pointing to Autochanger, remove - all Volumes from other drives. "update slots all-drives"? -- Add Python writable variable for changing the Priority, - Client, Storage, JobStatus (error), ... -- SD Python - - Solicit Events - FD Python - Python script to save with Python, not save, save with Bacula. - Python script to do backup. @@ -45,27 +39,26 @@ For 1.37: - Look at adding full Volume and Pool information to a Volume label so that bscan can get *all* the info. - Implement Maximum Job Spool Size -- 28-Mar 23:19 rufus-sd: acquire.c:379 Device "DDS-4" (/dev/nst0) - is busy reading. Job 6 canceled. - Remove all old Device resource code in Dir and code to pass it - back in SD. -- Fix code to either handle updating NumVol or to calculate it in - Dir next_vol.c + back in SD -- better, rework it to pass back device statistics. - Finish implementation of passing all Storage and Device needs to the SD. - Check locking of resources -- be sure to lock devices where previously resources were locked. - Add global lock on all devices when creating a device structure. -- Remove separate thread for opening devices in SD. On the other - hand, don't block waiting for open() for devices. - Make sure that Python has access to Client address/port so that it can check if Clients are alive. -- Implement copies and stripes. -- Add history file to console. +- Cleanup and complete Python scripting. + - What events? + - Change the Priority, Client, Storage, JobStatus (error) + at the start of a job. Maybe in 1.37: -- Ensure that you cannot exclude a directory or a file explicitly - Included with File. +- If the user puts "Purge Oldest Volume = yes" or "Recycle Oldest Volume = yes" + and there is only one volume in the pool, refuse to do it -- otherwise + he fills the Volume, then immediately starts reusing it. +- Implement copies and stripes. +- Add history file to console. - Each file on tape creates a JobMedia record. Peter has 4 million files spread over 10000 tape files and four tapes. A restore takes 16 hours to build the restore list. @@ -157,6 +150,10 @@ Regression tests (Scott): - A HOLD command to stop all jobs from starting. - A PAUSE command to pause all running jobs ==> release the drive. +- Media Type = LTO,LTO-2,LTO-3 + Media Type Read = LTO,LTO2,LTO3 + Media Type Write = LTO2, LTO3 + === From Carsten Menke Following is a list of what I think in the situations where I'm faced with, @@ -1288,3 +1285,17 @@ Block Position: 0 recycled and no label created. This happens when using autolabeling -- even when Python doesn't generate the name. - Scratch Pool where the volumes can be re-assigned to any Pool. +- 28-Mar 23:19 rufus-sd: acquire.c:379 Device "DDS-4" (/dev/nst0) + is busy reading. Job 6 canceled. +- Remove separate thread for opening devices in SD. On the other + hand, don't block waiting for open() for devices. +- Fix code to either handle updating NumVol or to calculate it in + Dir next_vol.c +- Ensure that you cannot exclude a directory or a file explicitly + Included with File. +#4 Embedded Python Scripting + (Implemented in Dir/SD/FD) +- Add Python writable variable for changing the Priority, + Client, Storage, JobStatus (error), ... +- SD Python + - Solicit Events diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 87191888f8..0ff1adbae5 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -652,10 +652,12 @@ bool get_or_create_fileset_record(JCR *jcr, FILESET_DBR *fsr) } } jcr->jr.FileSetId = fsr->FileSetId; +#ifdef needed if (fsr->created && jcr != NULL) { Jmsg(jcr, M_INFO, 0, _("Created new FileSet record \"%s\" %s\n"), fsr->FileSet, fsr->cCreateTime); } +#endif Dmsg2(119, "Created FileSet %s record %u\n", jcr->fileset->hdr.name, jcr->jr.FileSetId); return true; diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 4c44872002..9e2d4a9fee 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -401,7 +401,7 @@ bool reserve_device_for_append(DCR *dcr) dev->block(BST_DOING_ACQUIRE); } - Dmsg1(190, "reserve_append device is %s\n", dev_is_tape(dev)?"tape":"disk"); + Dmsg1(190, "reserve_append device is %s\n", dev->is_tape()?"tape":"disk"); for ( ;; ) { switch (can_reserve_drive(dcr)) { @@ -504,7 +504,7 @@ DCR *acquire_device_for_append(DCR *dcr) init_device_wait_timers(dcr); dev->block(BST_DOING_ACQUIRE); - Dmsg1(190, "acquire_append device is %s\n", dev_is_tape(dev)?"tape":"disk"); + Dmsg1(190, "acquire_append device is %s\n", dev->is_tape()?"tape":"disk"); if (dcr->reserved_device) { dev->reserved_device--; @@ -611,7 +611,7 @@ bool release_device(DCR *dcr) bool ok = true; lock_device(dev); - Dmsg1(100, "release_device device is %s\n", dev_is_tape(dev)?"tape":"disk"); + Dmsg1(100, "release_device device is %s\n", dev->is_tape()?"tape":"disk"); /* if device is reserved, job never started, so release the reserve here */ if (dcr->reserved_device) { diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index cc40e5d23a..65278ca54c 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -38,14 +38,14 @@ static void do_scan(void); static bool record_cb(DCR *dcr, DEV_RECORD *rec); static int create_file_attributes_record(B_DB *db, JCR *mjcr, - char *fname, char *lname, int type, - char *ap, DEV_RECORD *rec); + char *fname, char *lname, int type, + char *ap, DEV_RECORD *rec); static int create_media_record(B_DB *db, MEDIA_DBR *mr, VOLUME_LABEL *vl); static bool update_media_record(B_DB *db, MEDIA_DBR *mr); static int create_pool_record(B_DB *db, POOL_DBR *pr); static JCR *create_job_record(B_DB *db, JOB_DBR *mr, SESSION_LABEL *label, DEV_RECORD *rec); static int update_job_record(B_DB *db, JOB_DBR *mr, SESSION_LABEL *elabel, - DEV_RECORD *rec); + DEV_RECORD *rec); static int create_client_record(B_DB *db, CLIENT_DBR *cr); static int create_fileset_record(B_DB *db, FILESET_DBR *fsr); static int create_jobmedia_record(B_DB *db, JCR *jcr); @@ -64,7 +64,7 @@ int win32_client = 0; /* Local variables */ static DEVICE *dev = NULL; static B_DB *db; -static JCR *bjcr; /* jcr for bscan */ +static JCR *bjcr; /* jcr for bscan */ static BSR *bsr = NULL; static MEDIA_DBR mr; static POOL_DBR pr; @@ -99,8 +99,8 @@ static int num_files = 0; #define CONFIG_FILE "bacula-sd.conf" char *configfile; -STORES *me = NULL; /* our Global resource */ -bool forge_on = false; /* proceed inspite of I/O errors */ +STORES *me = NULL; /* our Global resource */ +bool forge_on = false; /* proceed inspite of I/O errors */ pthread_mutex_t device_release_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t wait_device_release = PTHREAD_COND_INITIALIZER; @@ -143,72 +143,72 @@ int main (int argc, char *argv[]) while ((ch = getopt(argc, argv, "b:c:d:h:mn:pP:rsSu:vV:w:?")) != -1) { switch (ch) { case 'S' : - showProgress = true; - break; + showProgress = true; + break; case 'b': - bsr = parse_bsr(NULL, optarg); - break; + bsr = parse_bsr(NULL, optarg); + break; case 'c': /* specify config file */ - if (configfile != NULL) { - free(configfile); - } - configfile = bstrdup(optarg); - break; + if (configfile != NULL) { + free(configfile); + } + configfile = bstrdup(optarg); + break; case 'd': /* debug level */ - debug_level = atoi(optarg); - if (debug_level <= 0) - debug_level = 1; - break; + debug_level = atoi(optarg); + if (debug_level <= 0) + debug_level = 1; + break; case 'h': - db_host = optarg; - break; + db_host = optarg; + break; case 'm': - update_vol_info = true; - break; + update_vol_info = true; + break; case 'n': - db_name = optarg; - break; + db_name = optarg; + break; case 'u': - db_user = optarg; - break; + db_user = optarg; + break; case 'P': - db_password = optarg; - break; + db_password = optarg; + break; case 'p': - forge_on = true; - break; + forge_on = true; + break; case 'r': - list_records = true; - break; + list_records = true; + break; case 's': - update_db = true; - break; + update_db = true; + break; case 'v': - verbose++; - break; + verbose++; + break; case 'V': /* Volume name */ - VolumeName = optarg; - break; + VolumeName = optarg; + break; case 'w': - wd = optarg; - break; + wd = optarg; + break; case '?': default: - usage(); + usage(); } } @@ -230,7 +230,7 @@ int main (int argc, char *argv[]) if (!me) { UnlockRes(); Emsg1(M_ERROR_TERM, 0, _("No Storage resource defined in %s. Cannot continue.\n"), - configfile); + configfile); } UnlockRes(); /* Check if -w option given, otherwise use resource for working directory */ @@ -238,7 +238,7 @@ int main (int argc, char *argv[]) working_directory = wd; } else if (!me->working_directory) { Emsg1(M_ERROR_TERM, 0, _("No Working Directory defined in %s. Cannot continue.\n"), - configfile); + configfile); } else { working_directory = me->working_directory; } @@ -246,11 +246,11 @@ int main (int argc, char *argv[]) /* Check that working directory is good */ if (stat(working_directory, &stat_buf) != 0) { Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s not found. Cannot continue.\n"), - working_directory); + working_directory); } if (!S_ISDIR(stat_buf.st_mode)) { Emsg1(M_ERROR_TERM, 0, _("Working Directory: %s is not a directory. Cannot continue.\n"), - working_directory); + working_directory); } bjcr = setup_jcr("bscan", argv[0], bsr, VolumeName, 1); /* read device */ @@ -264,11 +264,11 @@ int main (int argc, char *argv[]) fstat(dev->fd, &sb); currentVolumeSize = sb.st_size; Pmsg1(000, _("First Volume Size = %sn"), - edit_uint64(currentVolumeSize, ed1)); + edit_uint64(currentVolumeSize, ed1)); } if ((db=db_init_database(NULL, db_name, db_user, db_password, - db_host, 0, NULL, 0)) == NULL) { + db_host, 0, NULL, 0)) == NULL) { Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n")); } if (!db_open_database(NULL, db)) { @@ -302,21 +302,21 @@ static bool bscan_mount_next_read_volume(DCR *dcr) foreach_dlist(mdcr, dev->attached_dcrs) { JCR *mjcr = mdcr->jcr; if (mjcr->JobId == 0) { - continue; + continue; } if (verbose) { Pmsg1(000, _("Create JobMedia for Job %s\n"), mjcr->Job); } - if (dev->state & ST_TAPE) { - mdcr->EndBlock = dev->EndBlock; - mdcr->EndFile = dev->EndFile; - } else { - mdcr->EndBlock = (uint32_t)dev->file_addr; - mdcr->EndFile = (uint32_t)(dev->file_addr >> 32); + if (dev->is_tape()) { + mdcr->EndBlock = dcr->EndBlock; + mdcr->EndFile = dcr->EndFile; +// } else { +// mdcr->EndBlock = (uint32_t)dcr->file_addr; +// mdcr->EndFile = (uint32_t)(dcr->file_addr >> 32); } if (!create_jobmedia_record(db, mjcr)) { Pmsg2(000, _("Could not create JobMedia record for Volume=%s Job=%s\n"), - dev->VolCatInfo.VolCatName, mjcr->Job); + dev->VolCatInfo.VolCatName, mjcr->Job); } } /* Now let common read routine get up next tape. Note, @@ -331,7 +331,7 @@ static bool bscan_mount_next_read_volume(DCR *dcr) fstat(dev->fd, &sb); currentVolumeSize = sb.st_size; Pmsg1(000, _("First Volume Size = %sn"), - edit_uint64(currentVolumeSize, ed1)); + edit_uint64(currentVolumeSize, ed1)); } return stat; } @@ -356,7 +356,7 @@ static void do_scan() /* * Returns: true if OK - * false if error + * false if error */ static bool record_cb(DCR *dcr, DEV_RECORD *rec) { @@ -369,19 +369,19 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) if (rec->data_len > 0) { mr.VolBytes += rec->data_len + WRITE_RECHDR_LENGTH; /* Accumulate Volume bytes */ if (showProgress) { - int pct = (mr.VolBytes * 100) / currentVolumeSize; - if (pct != last_pct) { + int pct = (mr.VolBytes * 100) / currentVolumeSize; + if (pct != last_pct) { fprintf(stdout, "done: %d%%\n", pct); - fflush(stdout); - last_pct = pct; - } + fflush(stdout); + last_pct = pct; + } } } if (list_records) { Pmsg5(000, _("Record: SessId=%u SessTim=%u FileIndex=%d Stream=%d len=%u\n"), - rec->VolSessionId, rec->VolSessionTime, rec->FileIndex, - rec->Stream, rec->data_len); + rec->VolSessionId, rec->VolSessionTime, rec->FileIndex, + rec->Stream, rec->data_len); } /* * Check for Start or End of Session Record @@ -391,223 +391,223 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) bool save_update_db = update_db; if (verbose > 1) { - dump_label_record(dev, rec, 1); + dump_label_record(dev, rec, 1); } switch (rec->FileIndex) { case PRE_LABEL: Pmsg0(000, _("Volume is prelabeled. This tape cannot be scanned.\n")); - return false; - break; + 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) { + 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) { + } + } 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) { + 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) { + 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.VolName, sizeof(mr.VolumeName)); - mr.PoolId = pr.PoolId; - num_media++; - if (db_get_media_record(bjcr, db, &mr)) { - if (verbose) { + } + + /* Check Media Info */ + memset(&mr, 0, sizeof(mr)); + bstrncpy(mr.VolumeName, dev->VolHdr.VolName, 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) { + } + /* 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) { + 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) { + 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; - } + } + /* 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; + break; case SOS_LABEL: - mr.VolJobs++; - num_jobs++; - if (ignored_msgs > 0) { + 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 */ + 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) { + 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) { + } + } 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; + 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->dcr; - update_db = save_update_db; - - jr.PoolId = pr.PoolId; - /* Set start positions into JCR */ - if (dev->state & ST_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); - } - 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) { + mjcr = create_job_record(db, &jr, &label, rec); + dcr = mjcr->dcr; + update_db = save_update_db; + + jr.PoolId = pr.PoolId; + /* 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); + } + 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) { + 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) { + 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; + jr.JobId, + jr.PoolId, pr.PoolId); + return true; /* ignore error */ + } + break; case EOS_LABEL: - unser_session_label(&elabel, rec); + 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; + /* 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) { + 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; - } + rec->VolSessionId, rec->VolSessionTime); + break; + } - /* Do the final update to the Job record */ - update_job_record(db, &jr, &elabel, rec); + /* Do the final update to the Job record */ + update_job_record(db, &jr, &elabel, rec); - mjcr->end_time = jr.EndTime; - mjcr->JobStatus = JS_Terminated; + mjcr->end_time = jr.EndTime; + mjcr->JobStatus = JS_Terminated; - /* Create JobMedia record */ - create_jobmedia_record(db, mjcr); - dev->attached_dcrs->remove(mjcr->dcr); - free_jcr(mjcr); + /* Create JobMedia record */ + create_jobmedia_record(db, mjcr); + dev->attached_dcrs->remove(mjcr->dcr); + free_jcr(mjcr); - break; + 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)) { + 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->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); + } + mjcr->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; + mr.VolBlocks, edit_uint64_with_commas(mr.VolBytes, ec1)); + break; default: - break; + break; } /* end switch */ return true; } @@ -616,9 +616,9 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) if (!mjcr) { if (mr.VolJobs > 0) { Pmsg2(000, _("Could not find Job for SessId=%d SessTime=%d record.\n"), - rec->VolSessionId, rec->VolSessionTime); + rec->VolSessionId, rec->VolSessionTime); } else { - ignored_msgs++; + ignored_msgs++; } return true; } @@ -638,27 +638,27 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) if (attr->file_index != rec->FileIndex) { Emsg2(M_ERROR_TERM, 0, _("Record header file index %ld not equal record index %ld\n"), - rec->FileIndex, attr->file_index); + rec->FileIndex, attr->file_index); } if (verbose > 1) { - decode_stat(attr->attr, &attr->statp, &attr->LinkFI); - build_attr_output_fnames(bjcr, attr); - print_ls_output(bjcr, attr); + decode_stat(attr->attr, &attr->statp, &attr->LinkFI); + build_attr_output_fnames(bjcr, attr); + print_ls_output(bjcr, attr); } fr.JobId = mjcr->JobId; fr.FileId = 0; num_files++; if (verbose && (num_files & 0x7FFF) == 0) { - char ed1[30], ed2[30], ed3[30], ed4[30]; + char ed1[30], ed2[30], ed3[30], ed4[30]; Pmsg4(000, _("%s file records. At file:blk=%s:%s bytes=%s\n"), - edit_uint64_with_commas(num_files, ed1), - edit_uint64_with_commas(rec->File, ed2), - edit_uint64_with_commas(rec->Block, ed3), - edit_uint64_with_commas(mr.VolBytes, ed4)); + edit_uint64_with_commas(num_files, ed1), + edit_uint64_with_commas(rec->File, ed2), + edit_uint64_with_commas(rec->Block, ed3), + edit_uint64_with_commas(mr.VolBytes, ed4)); } create_file_attributes_record(db, mjcr, attr->fname, attr->lname, - attr->type, attr->attr, rec); + attr->type, attr->attr, rec); free_jcr(mjcr); break; @@ -668,26 +668,26 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) case STREAM_SPARSE_DATA: mjcr->JobBytes += rec->data_len; if (rec->Stream == STREAM_SPARSE_DATA) { - mjcr->JobBytes -= sizeof(uint64_t); + mjcr->JobBytes -= sizeof(uint64_t); } - free_jcr(mjcr); /* done using JCR */ + free_jcr(mjcr); /* done using JCR */ break; case STREAM_GZIP_DATA: mjcr->JobBytes += rec->data_len; /* No correct, we should expand it */ - free_jcr(mjcr); /* done using JCR */ + free_jcr(mjcr); /* done using JCR */ break; case STREAM_SPARSE_GZIP_DATA: mjcr->JobBytes += rec->data_len - sizeof(uint64_t); /* No correct, we should expand it */ - free_jcr(mjcr); /* done using JCR */ + free_jcr(mjcr); /* done using JCR */ break; /* Win32 GZIP stream */ case STREAM_WIN32_GZIP_DATA: mjcr->JobBytes += rec->data_len; - free_jcr(mjcr); /* done using JCR */ + free_jcr(mjcr); /* done using JCR */ break; case STREAM_MD5_SIGNATURE: @@ -759,8 +759,8 @@ static void bscan_free_jcr(JCR *jcr) * record, and then create the attributes record. */ static int create_file_attributes_record(B_DB *db, JCR *mjcr, - char *fname, char *lname, int type, - char *ap, DEV_RECORD *rec) + char *fname, char *lname, int type, + char *ap, DEV_RECORD *rec) { DCR *dcr = mjcr->dcr; ar.fname = fname; @@ -916,8 +916,8 @@ static int create_fileset_record(B_DB *db, FILESET_DBR *fsr) } else { if (!db_create_fileset_record(bjcr, db, fsr)) { Pmsg2(0, _("Could not create FileSet record \"%s\". ERR=%s\n"), - fsr->FileSet, db_strerror(db)); - return 0; + fsr->FileSet, db_strerror(db)); + return 0; } if (verbose) { Pmsg1(000, _("Created FileSet record \"%s\"\n"), fsr->FileSet); @@ -932,7 +932,7 @@ static int create_fileset_record(B_DB *db, FILESET_DBR *fsr) * begins running. */ static JCR *create_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *label, - DEV_RECORD *rec) + DEV_RECORD *rec) { JCR *mjcr; struct date_time dt; @@ -977,8 +977,8 @@ static JCR *create_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *label, return mjcr; } Pmsg2(000, _("Created new JobId=%u record for original JobId=%u\n"), jr->JobId, - label->JobId); - mjcr->JobId = jr->JobId; /* set new JobId */ + label->JobId); + mjcr->JobId = jr->JobId; /* set new JobId */ return mjcr; } @@ -987,7 +987,7 @@ static JCR *create_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *label, * at Job termination time. */ static int update_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *elabel, - DEV_RECORD *rec) + DEV_RECORD *rec) { struct date_time dt; struct tm tm; @@ -996,7 +996,7 @@ static int update_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *elabel, 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); + rec->VolSessionId, rec->VolSessionTime); return 0; } if (elabel->VerNum >= 11) { @@ -1032,7 +1032,7 @@ static int update_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *elabel, } if (verbose) { Pmsg2(000, _("Updated Job termination record for JobId=%u TermStat=%c\n"), jr->JobId, - jr->JobStatus); + jr->JobStatus); } if (verbose > 1) { const char *term_msg; @@ -1043,18 +1043,18 @@ static int update_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *elabel, switch (mjcr->JobStatus) { case JS_Terminated: term_msg = _("Backup OK"); - break; + break; case JS_FatalError: case JS_ErrorTerminated: term_msg = _("*** Backup Error ***"); - break; + break; case JS_Canceled: term_msg = _("Backup Canceled"); - break; + break; default: - term_msg = term_code; + term_msg = term_code; sprintf(term_code, _("Job Termination code: %d"), mjcr->JobStatus); - break; + break; } bstrftime(sdt, sizeof(sdt), mjcr->start_time); bstrftime(edt, sizeof(edt), mjcr->end_time); @@ -1072,20 +1072,20 @@ static int update_job_record(B_DB *db, JOB_DBR *jr, SESSION_LABEL *elabel, "Volume Session Time: %d\n" "Last Volume Bytes: %s\n" "Termination: %s\n\n"), - edt, - mjcr->JobId, - mjcr->Job, - mjcr->fileset_name, - job_level_to_str(mjcr->JobLevel), - mjcr->client_name, - sdt, - edt, - edit_uint64_with_commas(mjcr->JobFiles, ec1), - edit_uint64_with_commas(mjcr->JobBytes, ec2), - mjcr->VolSessionId, - mjcr->VolSessionTime, - edit_uint64_with_commas(mr.VolBytes, ec3), - term_msg); + edt, + mjcr->JobId, + mjcr->Job, + mjcr->fileset_name, + job_level_to_str(mjcr->JobLevel), + mjcr->client_name, + sdt, + edt, + edit_uint64_with_commas(mjcr->JobFiles, ec1), + edit_uint64_with_commas(mjcr->JobBytes, ec2), + mjcr->VolSessionId, + mjcr->VolSessionTime, + edit_uint64_with_commas(mr.VolBytes, ec3), + term_msg); } free_jcr(mjcr); return 1; @@ -1096,13 +1096,15 @@ static int create_jobmedia_record(B_DB *db, JCR *mjcr) JOBMEDIA_DBR jmr; DCR *dcr = mjcr->dcr; - if (dev->state & ST_TAPE) { + if (dev->is_tape()) { dcr->EndBlock = dev->EndBlock; dcr->EndFile = dev->EndFile; +#ifdef needed } else { dcr->EndBlock = (uint32_t)dev->file_addr; dcr->EndFile = (uint32_t)(dev->file_addr >> 32); - } +#endif + } memset(&jmr, 0, sizeof(jmr)); jmr.JobId = mjcr->JobId; @@ -1125,7 +1127,7 @@ static int create_jobmedia_record(B_DB *db, JCR *mjcr) } if (verbose) { Pmsg2(000, _("Created JobMedia record JobId %d, MediaId %d\n"), - jmr.JobId, jmr.MediaId); + jmr.JobId, jmr.MediaId); } return 1; } @@ -1141,9 +1143,9 @@ static int update_SIG_record(B_DB *db, char *SIGbuf, DEV_RECORD *rec, int type) if (!mjcr) { if (mr.VolJobs > 0) { Pmsg2(000, _("Could not find SessId=%d SessTime=%d for MD5/SHA1 record.\n"), - rec->VolSessionId, rec->VolSessionTime); + rec->VolSessionId, rec->VolSessionTime); } else { - ignored_msgs++; + ignored_msgs++; } return 0; } @@ -1174,7 +1176,7 @@ static JCR *create_jcr(JOB_DBR *jr, DEV_RECORD *rec, uint32_t JobId) JCR *jobjcr; /* * Transfer as much as possible to the Job JCR. Most important is - * the JobId and the ClientId. + * the JobId and the ClientId. */ jobjcr = new_jcr(sizeof(JCR), bscan_free_jcr); jobjcr->JobType = jr->JobType; @@ -1192,13 +1194,13 @@ static JCR *create_jcr(JOB_DBR *jr, DEV_RECORD *rec, uint32_t JobId) } /* Dummies to replace askdir.c */ -bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { return 1;} -bool dir_find_next_appendable_volume(DCR *dcr) { return 1;} -bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; } -bool dir_create_jobmedia_record(DCR *dcr) { return 1; } -bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; } -bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;} -bool dir_send_job_status(JCR *jcr) {return 1;} +bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { return 1;} +bool dir_find_next_appendable_volume(DCR *dcr) { return 1;} +bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; } +bool dir_create_jobmedia_record(DCR *dcr) { return 1; } +bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; } +bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;} +bool dir_send_job_status(JCR *jcr) {return 1;} bool dir_ask_sysop_to_mount_volume(DCR *dcr) @@ -1211,7 +1213,7 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr) } force_close_dev(dev); fprintf(stderr, "Mount Volume \"%s\" on device %s and press return when ready: ", - dcr->VolumeName, dev->print_name()); + dcr->VolumeName, dev->print_name()); getchar(); return true; } diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 6ddcdf162e..ccc0c64aeb 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -2,18 +2,18 @@ * * dev.c -- low level operations on device (storage device) * - * Kern Sibbald, MM + * Kern Sibbald, MM * * NOTE!!!! None of these routines are reentrant. You must - * use lock_device() and unlock_device() at a higher level, - * or use the xxx_device() equivalents. By moving the - * thread synchronization to a higher level, we permit + * use lock_device() and unlock_device() at a higher level, + * or use the xxx_device() equivalents. By moving the + * thread synchronization to a higher level, we permit * the higher level routines to "seize" the device and - * to carry out operations without worrying about who - * set what lock (i.e. race conditions). + * to carry out operations without worrying about who + * set what lock (i.e. race conditions). * * Note, this is the device dependent code, and my have - * to be modified for each system, but is meant to + * to be modified for each system, but is meant to * be as "generic" as possible. * * The purpose of this code is to develop a SIMPLE Storage @@ -120,10 +120,10 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device) if (stat(device->device_name, &statp) < 0) { berrno be; if (dev) { - dev->dev_errno = errno; + dev->dev_errno = errno; } Jmsg2(jcr, M_ERROR, 0, _("Unable to stat device %s: ERR=%s\n"), - device->device_name, be.strerror()); + device->device_name, be.strerror()); return NULL; } @@ -138,10 +138,10 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device) fifo = true; } else if (!(device->cap_bits & CAP_REQMOUNT)) { if (dev) { - dev->dev_errno = ENODEV; + dev->dev_errno = ENODEV; } Jmsg2(jcr, M_ERROR, 0, _("%s is an unknown device type. Must be tape or directory. st_mode=%x\n"), - device->device_name, statp.st_mode); + device->device_name, statp.st_mode); return NULL; } if (!dev) { @@ -198,11 +198,11 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device) */ if (dev->is_file() && device->cap_bits & CAP_REQMOUNT) { if (stat(device->mount_point, &statp) < 0) { - berrno be; - dev->dev_errno = errno; + berrno be; + dev->dev_errno = errno; Jmsg2(jcr, M_ERROR, 0, _("Unable to stat mount point %s: ERR=%s\n"), - device->mount_point, be.strerror()); - return NULL; + device->mount_point, be.strerror()); + return NULL; } if (!device->mount_command || !device->unmount_command) { Jmsg0(jcr, M_ERROR_TERM, 0, _("Mount and unmount commands must defined for a device which requires mount.\n")); @@ -215,12 +215,12 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device) if (dev->max_block_size > 1000000) { Jmsg3(jcr, M_ERROR, 0, _("Block size %u on device %s is too large, using default %u\n"), - dev->max_block_size, dev->print_name(), DEFAULT_BLOCK_SIZE); + dev->max_block_size, dev->print_name(), DEFAULT_BLOCK_SIZE); dev->max_block_size = 0; } if (dev->max_block_size % TAPE_BSIZE != 0) { Jmsg2(jcr, M_WARNING, 0, _("Max block size %u not multiple of device %s block size.\n"), - dev->max_block_size, dev->print_name()); + dev->max_block_size, dev->print_name()); } dev->errmsg = get_pool_memory(PM_EMSG); @@ -259,7 +259,7 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device) dev->fd = -1; dev->attached_dcrs = New(dlist(dcr, &dcr->dev_link)); - Dmsg2(29, "init_dev: tape=%d dev_name=%s\n", dev_is_tape(dev), dev->dev_name); + Dmsg2(29, "init_dev: tape=%d dev_name=%s\n", dev->is_tape(), dev->dev_name); return dev; } @@ -269,7 +269,7 @@ init_dev(JCR *jcr, DEVICE *dev, DEVRES *device) * initialize buffer pointers. * * Returns: -1 on error - * fd on success + * fd on success * * Note, for a tape, the VolName is the name we give to the * volume (not really used here), but for a file, the @@ -288,11 +288,11 @@ open_dev(DEVICE *dev, char *VolName, int mode) * starts and snatches up the device. */ if (VolName && strcmp(dev->VolCatInfo.VolCatName, VolName) != 0) { - return -1; + return -1; } dev->use_count++; - Mmsg2(&dev->errmsg, _("WARNING!!!! device %s opened %d times!!!\n"), - dev->print_name(), dev->use_count); + Mmsg2(dev->errmsg, _("WARNING!!!! device %s opened %d times!!!\n"), + dev->print_name(), dev->use_count); Emsg1(M_WARNING, 0, "%s", dev->errmsg); return dev->fd; } @@ -302,8 +302,8 @@ open_dev(DEVICE *dev, char *VolName, int mode) dev->VolCatInfo.VolCatName[0] = 0; } - Dmsg3(29, "open_dev: tape=%d dev_name=%s vol=%s\n", dev_is_tape(dev), - dev->dev_name, dev->VolCatInfo.VolCatName); + Dmsg3(29, "open_dev: tape=%d dev_name=%s vol=%s\n", dev->is_tape(), + dev->dev_name, dev->VolCatInfo.VolCatName); dev->state &= ~(ST_LABEL|ST_APPEND|ST_READ|ST_EOT|ST_WEOT|ST_EOF); dev->label_type = B_BACULA_LABEL; if (dev->is_tape() || dev->is_fifo()) { @@ -350,43 +350,43 @@ open_again: Dmsg2(500, "Open error errno=%d ERR=%s\n", errno, be.strerror()); if (errno == EINTR || errno == EAGAIN) { Dmsg0(500, "Continue open\n"); - continue; + continue; } /* Busy wait for specified time (default = 5 mins) */ if (errno == EBUSY && timeout-- > 0) { Dmsg2(100, "Device %s busy. ERR=%s\n", dev->print_name(), be.strerror()); - bmicrosleep(1, 0); - continue; + bmicrosleep(1, 0); + continue; } /* IO error (no volume) try 10 times every 6 seconds */ if (errno == EIO && ioerrcnt-- > 0) { - bmicrosleep(5, 0); + bmicrosleep(5, 0); Dmsg0(500, "Continue open\n"); - continue; + continue; } dev->dev_errno = errno; - Mmsg2(&dev->errmsg, _("Unable to open device %s: ERR=%s\n"), - dev->print_name(), be.strerror(dev->dev_errno)); + Mmsg2(dev->errmsg, _("Unable to open device %s: ERR=%s\n"), + dev->print_name(), be.strerror(dev->dev_errno)); /* Stop any open timer we set */ if (dev->tid) { - stop_thread_timer(dev->tid); - dev->tid = 0; + stop_thread_timer(dev->tid); + dev->tid = 0; } Emsg0(M_FATAL, 0, dev->errmsg); break; } if (dev->fd >= 0) { if (mode != 0) { - /* If opened in non-block mode, close it an open it normally */ - mode = 0; - close(dev->fd); - goto open_again; + /* If opened in non-block mode, close it an open it normally */ + mode = 0; + close(dev->fd); + goto open_again; } dev->dev_errno = 0; dev->state |= ST_OPENED; dev->use_count = 1; - update_pos_dev(dev); /* update position */ - set_os_device_parameters(dev); /* do system dependent stuff */ + update_pos_dev(dev); /* update position */ + set_os_device_parameters(dev); /* do system dependent stuff */ Dmsg0(500, "Open OK\n"); } /* Stop any open() timer we started */ @@ -406,7 +406,7 @@ static void open_file_device(DEVICE *dev, int mode) struct stat filestat; /* * Handle opening of File Archive (not a tape) - */ + */ if (dev->part == 0) { dev->file_size = 0; } @@ -420,7 +420,7 @@ static void open_file_device(DEVICE *dev, int mode) if (dev->VolCatInfo.VolCatName[0] == 0) { Mmsg(dev->errmsg, _("Could not open file device %s. No Volume name given.\n"), - dev->print_name()); + dev->print_name()); dev->fd = -1; return; } @@ -428,18 +428,18 @@ static void open_file_device(DEVICE *dev, int mode) if (mount_dev(dev, 1) < 0) { Mmsg(dev->errmsg, _("Could not mount device %s.\n"), - dev->print_name()); + dev->print_name()); Emsg0(M_FATAL, 0, dev->errmsg); dev->fd = -1; return; } - + Dmsg2(29, "open_dev: device is disk %s (mode:%d)\n", archive_name.c_str(), mode); dev->openmode = mode; /* * If we are not trying to access the last part, set mode to - * OPEN_READ_ONLY as writing would be an error. + * OPEN_READ_ONLY as writing would be an error. */ if (dev->part < dev->num_parts) { mode = OPEN_READ_ONLY; @@ -458,22 +458,22 @@ static void open_file_device(DEVICE *dev, int mode) if ((dev->fd = open(archive_name.c_str(), dev->mode, 0640)) < 0) { berrno be; dev->dev_errno = errno; - Mmsg2(&dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(), - be.strerror()); + Mmsg2(dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(), + be.strerror()); Emsg0(M_FATAL, 0, dev->errmsg); } else { dev->dev_errno = 0; dev->state |= ST_OPENED; dev->use_count = 1; - update_pos_dev(dev); /* update position */ + update_pos_dev(dev); /* update position */ if (fstat(dev->fd, &filestat) < 0) { - berrno be; - dev->dev_errno = errno; - Mmsg2(&dev->errmsg, _("Could not fstat: %s, ERR=%s\n"), archive_name.c_str(), - be.strerror()); - Emsg0(M_FATAL, 0, dev->errmsg); + berrno be; + dev->dev_errno = errno; + Mmsg2(dev->errmsg, _("Could not fstat: %s, ERR=%s\n"), archive_name.c_str(), + be.strerror()); + Emsg0(M_FATAL, 0, dev->errmsg); } else { - dev->part_size = filestat.st_size; + dev->part_size = filestat.st_size; } } Dmsg4(29, "open_dev: disk fd=%d opened, part=%d/%d, part_size=%u\n", dev->fd, dev->part, dev->num_parts, dev->part_size); @@ -495,7 +495,7 @@ bool _rewind_dev(char *file, int line, DEVICE *dev) /* * Rewind the device. * Returns: true on success - * false on failure + * false on failure */ bool rewind_dev(DEVICE *dev) { @@ -505,8 +505,8 @@ bool rewind_dev(DEVICE *dev) Dmsg1(29, "rewind_dev %s\n", dev->print_name()); if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg1(&dev->errmsg, _("Bad call to rewind_dev. Device %s not open\n"), - dev->print_name()); + Mmsg1(dev->errmsg, _("Bad call to rewind_dev. Device %s not open\n"), + dev->print_name()); Emsg0(M_ABORT, 0, dev->errmsg); return false; } @@ -522,30 +522,30 @@ bool rewind_dev(DEVICE *dev) * retrying every 5 seconds. */ for (i=dev->max_rewind_wait; ; i -= 5) { - if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { - berrno be; - clrerror_dev(dev, MTREW); - if (i == dev->max_rewind_wait) { + if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + berrno be; + clrerror_dev(dev, MTREW); + if (i == dev->max_rewind_wait) { Dmsg1(200, "Rewind error, %s. retrying ...\n", be.strerror()); - } - if (dev->dev_errno == EIO && i > 0) { + } + if (dev->dev_errno == EIO && i > 0) { Dmsg0(200, "Sleeping 5 seconds.\n"); - bmicrosleep(5, 0); - continue; - } - Mmsg2(&dev->errmsg, _("Rewind error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); - return false; - } - break; + bmicrosleep(5, 0); + continue; + } + Mmsg2(dev->errmsg, _("Rewind error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); + return false; + } + break; } } else if (dev->is_file()) { if (lseek_dev(dev, (off_t)0, SEEK_SET) < 0) { - berrno be; - dev->dev_errno = errno; - Mmsg2(&dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); - return false; + berrno be; + dev->dev_errno = errno; + Mmsg2(dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); + return false; } } return true; @@ -585,13 +585,13 @@ void DEVICE::set_eof() void DEVICE::set_eot() { state |= (ST_EOF|ST_EOT|ST_WEOT); - state &= ~ST_APPEND; /* make tape read-only */ + state &= ~ST_APPEND; /* make tape read-only */ } /* * Position device to end of medium (end of data) * Returns: true on succes - * false on error + * false on error */ bool eod_dev(DEVICE *dev) @@ -603,8 +603,8 @@ eod_dev(DEVICE *dev) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg1(&dev->errmsg, _("Bad call to eod_dev. Device %s not open\n"), - dev->print_name()); + Mmsg1(dev->errmsg, _("Bad call to eod_dev. Device %s not open\n"), + dev->print_name()); return false; } Dmsg0(29, "eod_dev\n"); @@ -622,14 +622,14 @@ eod_dev(DEVICE *dev) pos = lseek_dev(dev, (off_t)0, SEEK_END); // Dmsg1(100, "====== Seek to %lld\n", pos); if (pos >= 0) { - update_pos_dev(dev); - dev->state |= ST_EOT; - return true; + update_pos_dev(dev); + dev->state |= ST_EOT; + return true; } dev->dev_errno = errno; berrno be; - Mmsg2(&dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + Mmsg2(dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); return false; } #ifdef MTEOM @@ -637,9 +637,9 @@ eod_dev(DEVICE *dev) Dmsg0(100,"Using FAST FSF for EOM\n"); /* If unknown position, rewind */ if (!dev_get_os_pos(dev, &mt_stat)) { - if (!rewind_dev(dev)) { - return false; - } + if (!rewind_dev(dev)) { + return false; + } } mt_com.mt_op = MTFSF; /* @@ -648,33 +648,33 @@ eod_dev(DEVICE *dev) */ mt_com.mt_count = INT16_MAX; /* use big positive number */ if (mt_com.mt_count < 0) { - mt_com.mt_count = INT16_MAX; /* brain damaged system */ + mt_com.mt_count = INT16_MAX; /* brain damaged system */ } } if (dev_cap(dev, CAP_MTIOCGET) && (dev_cap(dev, CAP_FASTFSF) || dev_cap(dev, CAP_EOM))) { if (dev_cap(dev, CAP_EOM)) { Dmsg0(100,"Using EOM for EOM\n"); - mt_com.mt_op = MTEOM; - mt_com.mt_count = 1; + mt_com.mt_op = MTEOM; + mt_com.mt_count = 1; } if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { - berrno be; - clrerror_dev(dev, mt_com.mt_op); + berrno be; + clrerror_dev(dev, mt_com.mt_op); Dmsg1(50, "ioctl error: %s\n", be.strerror()); - update_pos_dev(dev); - Mmsg2(&dev->errmsg, _("ioctl MTEOM error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); - return false; + update_pos_dev(dev); + Mmsg2(dev->errmsg, _("ioctl MTEOM error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); + return false; } if (!dev_get_os_pos(dev, &mt_stat)) { - berrno be; - clrerror_dev(dev, -1); - Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); - return false; + berrno be; + clrerror_dev(dev, -1); + Mmsg2(dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); + return false; } Dmsg2(100, "EOD file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno); dev->set_eof(); @@ -687,7 +687,7 @@ eod_dev(DEVICE *dev) * Rewind then use FSF until EOT reached */ if (!rewind_dev(dev)) { - return false; + return false; } /* * Move file by file to the end of the tape @@ -695,24 +695,24 @@ eod_dev(DEVICE *dev) int file_num; for (file_num=dev->file; !dev->at_eot(); file_num++) { Dmsg0(200, "eod_dev: doing fsf 1\n"); - if (!fsf_dev(dev, 1)) { + if (!fsf_dev(dev, 1)) { Dmsg0(200, "fsf_dev error.\n"); - return false; - } - /* - * Avoid infinite loop. ***FIXME*** possibly add code - * to set EOD or to turn off CAP_FASTFSF if on. - */ - if (file_num == (int)dev->file) { - struct mtget mt_stat; + return false; + } + /* + * Avoid infinite loop. ***FIXME*** possibly add code + * to set EOD or to turn off CAP_FASTFSF if on. + */ + if (file_num == (int)dev->file) { + struct mtget mt_stat; Dmsg1(100, "fsf_dev did not advance from file %d\n", file_num); - if (dev_get_os_pos(dev, &mt_stat)) { + if (dev_get_os_pos(dev, &mt_stat)) { Dmsg2(100, "Adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno); - dev->set_eof(); - dev->file = mt_stat.mt_fileno; - } - return false; - } + dev->set_eof(); + dev->file = mt_stat.mt_fileno; + } + return false; + } } } /* @@ -727,12 +727,12 @@ eod_dev(DEVICE *dev) /* If BSF worked and fileno is known (not -1), set file */ if (dev_get_os_pos(dev, &mt_stat)) { Dmsg2(100, "BSFATEOF adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno); - dev->file = mt_stat.mt_fileno; + dev->file = mt_stat.mt_fileno; } else { - dev->file++; /* wing it -- not correct on all OSes */ + dev->file++; /* wing it -- not correct on all OSes */ } } else { - update_pos_dev(dev); /* update position */ + update_pos_dev(dev); /* update position */ } Dmsg1(200, "EOD dev->file=%d\n", dev->file); return ok; @@ -742,7 +742,7 @@ eod_dev(DEVICE *dev) * Set the position of the device -- only for files * For other devices, there is no generic way to do it. * Returns: true on succes - * false on error + * false on error */ bool update_pos_dev(DEVICE *dev) { @@ -751,7 +751,7 @@ bool update_pos_dev(DEVICE *dev) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, _("Bad device call. Device not open\n")); + Mmsg0(dev->errmsg, _("Bad device call. Device not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return false; } @@ -762,14 +762,14 @@ bool update_pos_dev(DEVICE *dev) dev->file_addr = 0; pos = lseek_dev(dev, (off_t)0, SEEK_CUR); if (pos < 0) { - berrno be; - dev->dev_errno = errno; + berrno be; + dev->dev_errno = errno; Pmsg1(000, "Seek error: ERR=%s\n", be.strerror()); - Mmsg2(&dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); - ok = false; + Mmsg2(dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); + ok = false; } else { - dev->file_addr = pos; + dev->file_addr = pos; } } return ok; @@ -803,49 +803,49 @@ uint32_t status_dev(DEVICE *dev) Dmsg0(-20," Bacula status:"); Dmsg2(-20," file=%d block=%d\n", dev->file, dev->block_num); if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) { - berrno be; - dev->dev_errno = errno; - Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); - return 0; + berrno be; + dev->dev_errno = errno; + Mmsg2(dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); + return 0; } Dmsg0(-20, " Device status:"); #if defined(HAVE_LINUX_OS) if (GMT_EOF(mt_stat.mt_gstat)) { - stat |= BMT_EOF; + stat |= BMT_EOF; Dmsg0(-20, " EOF"); } if (GMT_BOT(mt_stat.mt_gstat)) { - stat |= BMT_BOT; + stat |= BMT_BOT; Dmsg0(-20, " BOT"); } if (GMT_EOT(mt_stat.mt_gstat)) { - stat |= BMT_EOT; + stat |= BMT_EOT; Dmsg0(-20, " EOT"); } if (GMT_SM(mt_stat.mt_gstat)) { - stat |= BMT_SM; + stat |= BMT_SM; Dmsg0(-20, " SM"); } if (GMT_EOD(mt_stat.mt_gstat)) { - stat |= BMT_EOD; + stat |= BMT_EOD; Dmsg0(-20, " EOD"); } if (GMT_WR_PROT(mt_stat.mt_gstat)) { - stat |= BMT_WR_PROT; + stat |= BMT_WR_PROT; Dmsg0(-20, " WR_PROT"); } if (GMT_ONLINE(mt_stat.mt_gstat)) { - stat |= BMT_ONLINE; + stat |= BMT_ONLINE; Dmsg0(-20, " ONLINE"); } if (GMT_DR_OPEN(mt_stat.mt_gstat)) { - stat |= BMT_DR_OPEN; + stat |= BMT_DR_OPEN; Dmsg0(-20, " DR_OPEN"); } if (GMT_IM_REP_EN(mt_stat.mt_gstat)) { - stat |= BMT_IM_REP_EN; + stat |= BMT_IM_REP_EN; Dmsg0(-20, " IM_REP_EN"); } #endif /* !SunOS && !OSF */ @@ -864,7 +864,7 @@ uint32_t status_dev(DEVICE *dev) /* * Load medium in device * Returns: true on success - * false on failure + * false on failure */ bool load_dev(DEVICE *dev) { @@ -874,7 +874,7 @@ bool load_dev(DEVICE *dev) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, _("Bad call to load_dev. Device not open\n")); + Mmsg0(dev->errmsg, _("Bad call to load_dev. Device not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return false; } @@ -884,9 +884,9 @@ bool load_dev(DEVICE *dev) #ifndef MTLOAD Dmsg0(200, "stored: MTLOAD command not available\n"); berrno be; - dev->dev_errno = ENOTTY; /* function not available */ - Mmsg2(&dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + dev->dev_errno = ENOTTY; /* function not available */ + Mmsg2(dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); return false; #else @@ -898,8 +898,8 @@ bool load_dev(DEVICE *dev) if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; dev->dev_errno = errno; - Mmsg2(&dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + Mmsg2(dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); return false; } return true; @@ -909,7 +909,7 @@ bool load_dev(DEVICE *dev) /* * Rewind device and put it offline * Returns: true on success - * false on failure + * false on failure */ bool offline_dev(DEVICE *dev) { @@ -917,7 +917,7 @@ bool offline_dev(DEVICE *dev) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, _("Bad call to offline_dev. Device not open\n")); + Mmsg0(dev->errmsg, _("Bad call to offline_dev. Device not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return false; } @@ -940,8 +940,8 @@ bool offline_dev(DEVICE *dev) if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; dev->dev_errno = errno; - Mmsg2(&dev->errmsg, _("ioctl MTOFFL error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + Mmsg2(dev->errmsg, _("ioctl MTOFFL error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); return false; } Dmsg1(100, "Offlined device %s\n", dev->print_name()); @@ -971,7 +971,7 @@ bool offline_or_rewind_dev(DEVICE *dev) /* * Foward space a file * Returns: true on success - * false on failure + * false on failure */ bool fsf_dev(DEVICE *dev, int num) @@ -982,7 +982,7 @@ fsf_dev(DEVICE *dev, int num) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, _("Bad call to fsf_dev. Device not open\n")); + Mmsg0(dev->errmsg, _("Bad call to fsf_dev. Device not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return false; } @@ -1013,14 +1013,14 @@ fsf_dev(DEVICE *dev, int num) mt_com.mt_count = num; stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com); if (stat < 0 || !dev_get_os_pos(dev, &mt_stat)) { - berrno be; - dev->state |= ST_EOT; + berrno be; + dev->state |= ST_EOT; Dmsg0(200, "Set ST_EOT\n"); - clrerror_dev(dev, MTFSF); + clrerror_dev(dev, MTFSF); Mmsg2(dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + dev->print_name(), be.strerror()); Dmsg1(200, "%s", dev->errmsg); - return false; + return false; } Dmsg2(200, "fsf file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno); dev->set_eof(); @@ -1039,60 +1039,60 @@ fsf_dev(DEVICE *dev, int num) int rbuf_len; Dmsg0(200, "FSF has cap_fsf\n"); if (dev->max_block_size == 0) { - rbuf_len = DEFAULT_BLOCK_SIZE; + rbuf_len = DEFAULT_BLOCK_SIZE; } else { - rbuf_len = dev->max_block_size; + rbuf_len = dev->max_block_size; } rbuf = get_memory(rbuf_len); mt_com.mt_op = MTFSF; mt_com.mt_count = 1; while (num-- && !(dev->state & ST_EOT)) { Dmsg0(100, "Doing read before fsf\n"); - if ((stat = read(dev->fd, (char *)rbuf, rbuf_len)) < 0) { - if (errno == ENOMEM) { /* tape record exceeds buf len */ - stat = rbuf_len; /* This is OK */ - } else { - berrno be; - dev->state |= ST_EOT; - clrerror_dev(dev, -1); + if ((stat = read(dev->fd, (char *)rbuf, rbuf_len)) < 0) { + if (errno == ENOMEM) { /* tape record exceeds buf len */ + stat = rbuf_len; /* This is OK */ + } else { + berrno be; + dev->state |= ST_EOT; + clrerror_dev(dev, -1); Dmsg2(100, "Set ST_EOT read errno=%d. ERR=%s\n", dev->dev_errno, - be.strerror()); + be.strerror()); Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + dev->print_name(), be.strerror()); Dmsg1(100, "%s", dev->errmsg); - break; - } - } - if (stat == 0) { /* EOF */ - update_pos_dev(dev); + break; + } + } + if (stat == 0) { /* EOF */ + update_pos_dev(dev); Dmsg1(100, "End of File mark from read. File=%d\n", dev->file+1); - /* Two reads of zero means end of tape */ - if (dev->state & ST_EOF) { - dev->state |= ST_EOT; + /* Two reads of zero means end of tape */ + if (dev->state & ST_EOF) { + dev->state |= ST_EOT; Dmsg0(100, "Set ST_EOT\n"); - break; - } else { - dev->set_eof(); - continue; - } - } else { /* Got data */ - dev->state &= ~(ST_EOF|ST_EOT); - } + break; + } else { + dev->set_eof(); + continue; + } + } else { /* Got data */ + dev->state &= ~(ST_EOF|ST_EOT); + } Dmsg0(100, "Doing MTFSF\n"); - stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com); - if (stat < 0) { /* error => EOT */ - berrno be; - dev->state |= ST_EOT; + stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com); + if (stat < 0) { /* error => EOT */ + berrno be; + dev->state |= ST_EOT; Dmsg0(100, "Set ST_EOT\n"); - clrerror_dev(dev, MTFSF); - Mmsg2(&dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + clrerror_dev(dev, MTFSF); + Mmsg2(dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"), + dev->print_name(), be.strerror()); Dmsg0(100, "Got < 0 for MTFSF\n"); Dmsg1(100, "%s", dev->errmsg); - } else { - dev->set_eof(); - } + } else { + dev->set_eof(); + } } free_memory(rbuf); @@ -1102,14 +1102,14 @@ fsf_dev(DEVICE *dev, int num) } else { Dmsg0(200, "Doing FSR for FSF\n"); while (num-- && !(dev->state & ST_EOT)) { - fsr_dev(dev, INT32_MAX); /* returns -1 on EOF or EOT */ + fsr_dev(dev, INT32_MAX); /* returns -1 on EOF or EOT */ } if (dev->state & ST_EOT) { - dev->dev_errno = 0; + dev->dev_errno = 0; Mmsg1(dev->errmsg, _("Device %s at End of Tape.\n"), dev->print_name()); - stat = -1; + stat = -1; } else { - stat = 0; + stat = 0; } } update_pos_dev(dev); @@ -1125,7 +1125,7 @@ fsf_dev(DEVICE *dev, int num) /* * Backward space a file * Returns: false on failure - * true on success + * true on success */ bool bsf_dev(DEVICE *dev, int num) @@ -1142,7 +1142,7 @@ bsf_dev(DEVICE *dev, int num) if (!dev->is_tape()) { Mmsg1(dev->errmsg, _("Device %s cannot BSF because it is not a tape.\n"), - dev->print_name()); + dev->print_name()); return false; } Dmsg0(29, "bsf_dev\n"); @@ -1157,7 +1157,7 @@ bsf_dev(DEVICE *dev, int num) berrno be; clrerror_dev(dev, MTBSF); Mmsg2(dev->errmsg, _("ioctl MTBSF error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + dev->print_name(), be.strerror()); } update_pos_dev(dev); return stat == 0; @@ -1167,7 +1167,7 @@ bsf_dev(DEVICE *dev, int num) /* * Foward space a record * Returns: false on failure - * true on success + * true on success */ bool fsr_dev(DEVICE *dev, int num) @@ -1204,18 +1204,18 @@ fsr_dev(DEVICE *dev, int num) Dmsg1(100, "FSF fail: ERR=%s\n", be.strerror()); if (dev_get_os_pos(dev, &mt_stat)) { Dmsg4(100, "Adjust from %d:%d to %d:%d\n", dev->file, - dev->block_num, mt_stat.mt_fileno, mt_stat.mt_blkno); - dev->file = mt_stat.mt_fileno; - dev->block_num = mt_stat.mt_blkno; + dev->block_num, mt_stat.mt_fileno, mt_stat.mt_blkno); + dev->file = mt_stat.mt_fileno; + dev->block_num = mt_stat.mt_blkno; } else { - if (dev->state & ST_EOF) { - dev->state |= ST_EOT; - } else { - dev->set_eof(); - } + if (dev->state & ST_EOF) { + dev->state |= ST_EOT; + } else { + dev->set_eof(); + } } Mmsg2(dev->errmsg, _("ioctl MTFSR error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + dev->print_name(), be.strerror()); } update_pos_dev(dev); return stat == 0; @@ -1224,7 +1224,7 @@ fsr_dev(DEVICE *dev, int num) /* * Backward space a record * Returns: false on failure - * true on success + * true on success */ bool bsr_dev(DEVICE *dev, int num) @@ -1258,7 +1258,7 @@ bsr_dev(DEVICE *dev, int num) berrno be; clrerror_dev(dev, MTBSR); Mmsg2(dev->errmsg, _("ioctl MTBSR error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + dev->print_name(), be.strerror()); } update_pos_dev(dev); return stat == 0; @@ -1267,7 +1267,7 @@ bsr_dev(DEVICE *dev, int num) /* * Reposition the device to file, block * Returns: false on failure - * true on success + * true on success */ bool reposition_dev(DEVICE *dev, uint32_t file, uint32_t block) @@ -1283,11 +1283,11 @@ reposition_dev(DEVICE *dev, uint32_t file, uint32_t block) off_t pos = (((off_t)file)<<32) + block; Dmsg1(100, "===== lseek_dev to %d\n", (int)pos); if (lseek_dev(dev, pos, SEEK_SET) == (off_t)-1) { - berrno be; - dev->dev_errno = errno; + berrno be; + dev->dev_errno = errno; Mmsg2(dev->errmsg, _("lseek_dev error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); - return false; + dev->print_name(), be.strerror()); + return false; } dev->file = file; dev->block_num = block; @@ -1299,14 +1299,14 @@ reposition_dev(DEVICE *dev, uint32_t file, uint32_t block) if (file < dev->file) { Dmsg0(100, "Rewind_dev\n"); if (!rewind_dev(dev)) { - return false; + return false; } } if (file > dev->file) { Dmsg1(100, "fsf %d\n", file-dev->file); if (!fsf_dev(dev, file-dev->file)) { Dmsg1(100, "fsf failed! ERR=%s\n", strerror_dev(dev)); - return false; + return false; } Dmsg2(100, "wanted_file=%d at_file=%d\n", file, dev->file); } @@ -1331,7 +1331,7 @@ reposition_dev(DEVICE *dev, uint32_t file, uint32_t block) /* * Write an end of file on the device * Returns: 0 on success - * non-zero on failure + * non-zero on failure */ int weof_dev(DEVICE *dev, int num) @@ -1370,7 +1370,7 @@ weof_dev(DEVICE *dev, int num) clrerror_dev(dev, MTWEOF); if (stat == -1) { Mmsg2(dev->errmsg, _("ioctl MTWEOF error on %s. ERR=%s.\n"), - dev->print_name(), be.strerror()); + dev->print_name(), be.strerror()); } } return stat; @@ -1400,7 +1400,7 @@ clrerror_dev(DEVICE *dev, int func) struct mtget mt_stat; char buf[100]; - dev->dev_errno = errno; /* save errno */ + dev->dev_errno = errno; /* save errno */ if (errno == EIO) { dev->VolCatInfo.VolCatErrors++; } @@ -1412,60 +1412,60 @@ clrerror_dev(DEVICE *dev, int func) switch (func) { case -1: Emsg0(M_ABORT, 0, "Got ENOTTY on read/write!\n"); - break; + break; case MTWEOF: msg = "WTWEOF"; - dev->capabilities &= ~CAP_EOF; /* turn off feature */ - break; + dev->capabilities &= ~CAP_EOF; /* turn off feature */ + break; #ifdef MTEOM case MTEOM: msg = "WTEOM"; - dev->capabilities &= ~CAP_EOM; /* turn off feature */ - break; + dev->capabilities &= ~CAP_EOM; /* turn off feature */ + break; #endif case MTFSF: msg = "MTFSF"; - dev->capabilities &= ~CAP_FSF; /* turn off feature */ - break; + dev->capabilities &= ~CAP_FSF; /* turn off feature */ + break; case MTBSF: msg = "MTBSF"; - dev->capabilities &= ~CAP_BSF; /* turn off feature */ - break; + dev->capabilities &= ~CAP_BSF; /* turn off feature */ + break; case MTFSR: msg = "MTFSR"; - dev->capabilities &= ~CAP_FSR; /* turn off feature */ - break; + dev->capabilities &= ~CAP_FSR; /* turn off feature */ + break; case MTBSR: msg = "MTBSR"; - dev->capabilities &= ~CAP_BSR; /* turn off feature */ - break; + dev->capabilities &= ~CAP_BSR; /* turn off feature */ + break; case MTREW: msg = "MTREW"; - break; + break; #ifdef MTSETBLK case MTSETBLK: msg = "MTSETBLK"; - break; + break; #endif #ifdef MTSETBSIZ case MTSETBSIZ: msg = "MTSETBSIZ"; - break; + break; #endif #ifdef MTSRSZ case MTSRSZ: msg = "MTSRSZ"; - break; + break; #endif default: bsnprintf(buf, sizeof(buf), "unknown func code %d", func); - msg = buf; - break; + msg = buf; + break; } if (msg != NULL) { - dev->dev_errno = ENOSYS; + dev->dev_errno = ENOSYS; Mmsg1(dev->errmsg, _("I/O function \"%s\" not supported on this device.\n"), msg); - Emsg0(M_ERROR, 0, dev->errmsg); + Emsg0(M_ERROR, 0, dev->errmsg); } } /* On some systems such as NetBSD, this clears all errors */ @@ -1536,7 +1536,7 @@ static void do_close(DEVICE *dev) get_filename(dev, dev->VolCatInfo.VolCatName, archive_name); /* Check that the part file is empty */ if ((stat(archive_name.c_str(), &statp) == 0) && (statp.st_size == 0)) { - unlink(archive_name.c_str()); + unlink(archive_name.c_str()); } } @@ -1567,7 +1567,7 @@ void close_dev(DEVICE *dev) { if (!dev) { - Mmsg0(&dev->errmsg, _("Bad call to close_dev. Device not open\n")); + Mmsg0(dev->errmsg, _("Bad call to close_dev. Device not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return; } @@ -1592,7 +1592,7 @@ close_dev(DEVICE *dev) void force_close_dev(DEVICE *dev) { if (!dev) { - Mmsg0(&dev->errmsg, _("Bad call to force_close_dev. Device not open\n")); + Mmsg0(dev->errmsg, _("Bad call to force_close_dev. Device not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return; } @@ -1617,26 +1617,19 @@ bool truncate_dev(DEVICE *dev) dev->num_parts = 0; dev->VolCatInfo.VolCatParts = 0; if (open_first_part(dev) < 0) { - berrno be; - Mmsg1(&dev->errmsg, "Unable to truncate device, because I'm unable to open the first part. ERR=%s\n", be.strerror()); + berrno be; + Mmsg1(dev->errmsg, "Unable to truncate device, because I'm unable to open the first part. ERR=%s\n", be.strerror()); } } if (ftruncate(dev->fd, 0) != 0) { berrno be; - Mmsg1(&dev->errmsg, _("Unable to truncate device. ERR=%s\n"), be.strerror()); + Mmsg1(dev->errmsg, _("Unable to truncate device. ERR=%s\n"), be.strerror()); return false; } return true; } -bool -dev_is_tape(DEVICE *dev) -{ - return dev->is_tape() ? true : false; -} - - /* * return 1 if the device is read for write, and 0 otherwise * This is meant for checking at the end of a job to see @@ -1686,7 +1679,7 @@ term_dev(DEVICE *dev) { if (!dev) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, _("Bad call to term_dev. Device not open\n")); + Mmsg0(dev->errmsg, _("Bad call to term_dev. Device not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return; } @@ -1729,7 +1722,7 @@ void init_device_wait_timers(DCR *dcr) /* ******FIXME******* put these on config variables */ dev->min_wait = 60 * 60; dev->max_wait = 24 * 60 * 60; - dev->max_num_wait = 9; /* 5 waits =~ 1 day, then 1 day at a time */ + dev->max_num_wait = 9; /* 5 waits =~ 1 day, then 1 day at a time */ dev->wait_sec = dev->min_wait; dev->rem_wait_sec = dev->wait_sec; dev->num_wait = 0; @@ -1738,7 +1731,7 @@ void init_device_wait_timers(DCR *dcr) jcr->min_wait = 60 * 60; jcr->max_wait = 24 * 60 * 60; - jcr->max_num_wait = 9; /* 5 waits =~ 1 day, then 1 day at a time */ + jcr->max_num_wait = 9; /* 5 waits =~ 1 day, then 1 day at a time */ jcr->wait_sec = jcr->min_wait; jcr->rem_wait_sec = jcr->wait_sec; jcr->num_wait = 0; @@ -1749,11 +1742,11 @@ void init_device_wait_timers(DCR *dcr) * The dev timers are used for waiting on a particular device * * Returns: true if time doubled - * false if max time expired + * false if max time expired */ bool double_dev_wait_time(DEVICE *dev) { - dev->wait_sec *= 2; /* double wait time */ + dev->wait_sec *= 2; /* double wait time */ if (dev->wait_sec > dev->max_wait) { /* but not longer than maxtime */ dev->wait_sec = dev->max_wait; } @@ -1775,18 +1768,18 @@ void set_os_device_parameters(DEVICE *dev) mt_com.mt_op = MTSETBLK; mt_com.mt_count = 0; if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { - clrerror_dev(dev, MTSETBLK); + clrerror_dev(dev, MTSETBLK); } mt_com.mt_op = MTSETDRVBUFFER; mt_com.mt_count = MT_ST_CLEARBOOLEANS; if (!dev_cap(dev, CAP_TWOEOF)) { - mt_com.mt_count |= MT_ST_TWO_FM; + mt_com.mt_count |= MT_ST_TWO_FM; } if (dev_cap(dev, CAP_EOM)) { - mt_com.mt_count |= MT_ST_FAST_MTEOM; + mt_com.mt_count |= MT_ST_FAST_MTEOM; } if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { - clrerror_dev(dev, MTSETBLK); + clrerror_dev(dev, MTSETBLK); } } return; @@ -1799,13 +1792,13 @@ void set_os_device_parameters(DEVICE *dev) mt_com.mt_op = MTSETBSIZ; mt_com.mt_count = 0; if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { - clrerror_dev(dev, MTSETBSIZ); + clrerror_dev(dev, MTSETBSIZ); } /* Get notified at logical end of tape */ mt_com.mt_op = MTEWARN; mt_com.mt_count = 1; if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { - clrerror_dev(dev, MTEWARN); + clrerror_dev(dev, MTEWARN); } } return; @@ -1818,7 +1811,7 @@ void set_os_device_parameters(DEVICE *dev) mt_com.mt_op = MTSETBSIZ; mt_com.mt_count = 0; if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { - clrerror_dev(dev, MTSETBSIZ); + clrerror_dev(dev, MTSETBSIZ); } } return; @@ -1831,7 +1824,7 @@ void set_os_device_parameters(DEVICE *dev) mt_com.mt_op = MTSRSZ; mt_com.mt_count = 0; if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { - clrerror_dev(dev, MTSRSZ); + clrerror_dev(dev, MTSRSZ); } } return; @@ -1841,6 +1834,6 @@ void set_os_device_parameters(DEVICE *dev) static bool dev_get_os_pos(DEVICE *dev, struct mtget *mt_stat) { return dev_cap(dev, CAP_MTIOCGET) && - ioctl(dev->fd, MTIOCGET, (char *)mt_stat) == 0 && - mt_stat->mt_fileno >= 0; + ioctl(dev->fd, MTIOCGET, (char *)mt_stat) == 0 && + mt_stat->mt_fileno >= 0; } diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 14715689bf..7653c2d6a3 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -6,11 +6,11 @@ * NOTE! In general, subroutines that have the word * "device" in the name do locking. Subroutines * that have the word "dev" in the name do not - * do locking. Thus if xxx_device() calls - * yyy_dev(), all is OK, but if xxx_device() - * calls yyy_device(), everything will hang. - * Obviously, no zzz_dev() is allowed to call - * a www_device() or everything falls apart. + * do locking. Thus if xxx_device() calls + * yyy_dev(), all is OK, but if xxx_device() + * calls yyy_device(), everything will hang. + * Obviously, no zzz_dev() is allowed to call + * a www_device() or everything falls apart. * * Concerning the routines lock_device() and block_device() * see the end of this module for details. In general, @@ -74,7 +74,7 @@ extern int debug_level; * Note, we are called only from one place in block.c * * Returns: true on success - * false on failure + * false on failure */ bool fixup_device_block_write_error(DCR *dcr) { @@ -108,18 +108,18 @@ bool fixup_device_block_write_error(DCR *dcr) /* Inform User about end of medium */ Jmsg(jcr, M_INFO, 0, _("End of medium on Volume \"%s\" Bytes=%s Blocks=%s at %s.\n"), - PrevVolName, edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1), - edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2), - bstrftime(dt, sizeof(dt), time(NULL))); + PrevVolName, edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1), + edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2), + bstrftime(dt, sizeof(dt), time(NULL))); if (!mount_next_write_volume(dcr, 1)) { free_block(label_blk); dcr->block = block; P(dev->mutex); unblock_device(dev); - return false; /* device locked */ + return false; /* device locked */ } - P(dev->mutex); /* lock again */ + P(dev->mutex); /* lock again */ Jmsg(jcr, M_INFO, 0, _("New volume \"%s\" mounted on device %s at %s.\n"), dcr->VolumeName, dev->print_name(), bstrftime(dt, sizeof(dt), time(NULL))); @@ -134,11 +134,11 @@ bool fixup_device_block_write_error(DCR *dcr) if (!write_block_to_dev(dcr)) { berrno be; Pmsg1(0, "write_block_to_device Volume label failed. ERR=%s", - be.strerror(dev->dev_errno)); + be.strerror(dev->dev_errno)); free_block(label_blk); dcr->block = block; unblock_device(dev); - return false; /* device locked */ + return false; /* device locked */ } free_block(label_blk); dcr->block = block; @@ -152,11 +152,11 @@ bool fixup_device_block_write_error(DCR *dcr) foreach_dlist(mdcr, dev->attached_dcrs) { JCR *mjcr = mdcr->jcr; if (mjcr->JobId == 0) { - continue; /* ignore console */ + continue; /* ignore console */ } mdcr->NewVol = true; if (jcr != mjcr) { - bstrncpy(mdcr->VolumeName, dcr->VolumeName, sizeof(mdcr->VolumeName)); + bstrncpy(mdcr->VolumeName, dcr->VolumeName, sizeof(mdcr->VolumeName)); } } @@ -171,13 +171,13 @@ bool fixup_device_block_write_error(DCR *dcr) if (!write_block_to_dev(dcr)) { berrno be; Pmsg1(0, "write_block_to_device overflow block failed. ERR=%s", - be.strerror(dev->dev_errno)); + be.strerror(dev->dev_errno)); unblock_device(dev); - return false; /* device locked */ + return false; /* device locked */ } unblock_device(dev); - return true; /* device locked */ + return true; /* device locked */ } /* @@ -246,7 +246,7 @@ void set_new_file_parameters(DCR *dcr) * a file is the directory only. * * Returns: false on failure - * true on success + * true on success */ bool first_open_device(DEVICE *dev) { @@ -258,7 +258,7 @@ bool first_open_device(DEVICE *dev) lock_device(dev); /* Defer opening files */ - if (!dev_is_tape(dev)) { + if (!dev->is_tape()) { Dmsg0(129, "Device is file, deferring open.\n"); unlock_device(dev); return true; @@ -267,17 +267,17 @@ bool first_open_device(DEVICE *dev) if (!dev->is_open()) { int mode; if (dev_cap(dev, CAP_STREAM)) { - mode = OPEN_WRITE_ONLY; + mode = OPEN_WRITE_ONLY; } else { - mode = OPEN_READ_WRITE; + mode = OPEN_READ_WRITE; } Dmsg0(129, "Opening device.\n"); dev->open_nowait = true; if (open_dev(dev, NULL, mode) < 0) { Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg); - dev->open_nowait = false; - unlock_device(dev); - return false; + dev->open_nowait = false; + unlock_device(dev); + return false; } } Dmsg1(129, "open_dev %s OK\n", dev->print_name()); @@ -296,19 +296,19 @@ bool open_device(DCR *dcr) if (!dev->is_open()) { int mode; if (dev_cap(dev, CAP_STREAM)) { - mode = OPEN_WRITE_ONLY; + mode = OPEN_WRITE_ONLY; } else { - mode = OPEN_READ_WRITE; + mode = OPEN_READ_WRITE; } if (open_dev(dev, dcr->VolCatInfo.VolCatName, mode) < 0) { - /* If polling, ignore the error */ - if (!dev->poll) { + /* If polling, ignore the error */ + if (!dev->poll) { Jmsg2(dcr->jcr, M_FATAL, 0, _("Unable to open device %s: ERR=%s\n"), - dev->print_name(), strerror_dev(dev)); + dev->print_name(), strerror_dev(dev)); Pmsg2(000, "Unable to open archive %s: ERR=%s\n", - dev->print_name(), strerror_dev(dev)); - } - return false; + dev->print_name(), strerror_dev(dev)); + } + return false; } } return true; @@ -341,15 +341,15 @@ void _lock_device(const char *file, int line, DEVICE *dev) Dmsg3(500, "lock %d from %s:%d\n", dev->dev_blocked, file, line); P(dev->mutex); if (dev->dev_blocked && !pthread_equal(dev->no_wait_id, pthread_self())) { - dev->num_waiting++; /* indicate that I am waiting */ + dev->num_waiting++; /* indicate that I am waiting */ while (dev->dev_blocked) { - if ((stat = pthread_cond_wait(&dev->wait, &dev->mutex)) != 0) { - V(dev->mutex); + if ((stat = pthread_cond_wait(&dev->wait, &dev->mutex)) != 0) { + V(dev->mutex); Emsg1(M_ABORT, 0, _("pthread_cond_wait failure. ERR=%s\n"), - strerror(stat)); - } + strerror(stat)); + } } - dev->num_waiting--; /* no longer waiting */ + dev->num_waiting--; /* no longer waiting */ } } @@ -361,7 +361,7 @@ bool device_is_unmounted(DEVICE *dev) bool stat; int blocked = dev->dev_blocked; stat = (blocked == BST_UNMOUNTED) || - (blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP); + (blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP); return stat; } @@ -405,7 +405,7 @@ void _block_device(const char *file, int line, DEVICE *dev, int state) { Dmsg3(500, "block set %d from %s:%d\n", state, file, line); ASSERT(dev->dev_blocked == BST_NOT_BLOCKED); - dev->dev_blocked = state; /* make other threads wait */ + dev->dev_blocked = state; /* make other threads wait */ dev->no_wait_id = pthread_self(); /* allow us to continue */ } diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 763f47fa4c..e00cc4fcdd 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -609,7 +609,7 @@ static bool mount_cmd(JCR *jcr) dev->print_name()); } } else { - if (!dev_is_tape(dev)) { + if (!dev->is_tape()) { bnet_fsend(dir, _("3906 cannot mount non-tape.\n")); break; } @@ -797,7 +797,7 @@ static bool autochanger_cmd(JCR *jcr) dcr = jcr->dcr; if (dev) { P(dev->mutex); /* Use P to avoid indefinite block */ - if (!dev_is_tape(dev)) { + if (!dev->is_tape()) { bnet_fsend(dir, _("3995 Device %s is not an autochanger.\n"), dev->print_name()); } else if (!dev->is_open()) { diff --git a/bacula/src/stored/match_bsr.c b/bacula/src/stored/match_bsr.c index df6087601f..eb3411d8bf 100755 --- a/bacula/src/stored/match_bsr.c +++ b/bacula/src/stored/match_bsr.c @@ -71,22 +71,22 @@ void position_bsr_block(BSR *bsr, DEV_BLOCK *block) * so can do fast rejection. * * returns: 1 if block may contain valid records - * 0 if block may be skipped (i.e. it contains no records of - * that can match the bsr). + * 0 if block may be skipped (i.e. it contains no records of + * that can match the bsr). * */ int match_bsr_block(BSR *bsr, DEV_BLOCK *block) { if (!bsr || !bsr->use_fast_rejection || (block->BlockVer < 2)) { - return 1; /* cannot fast reject */ + return 1; /* cannot fast reject */ } for ( ; bsr; bsr=bsr->next) { if (!match_block_sesstime(bsr, bsr->sesstime, block)) { - continue; + continue; } if (!match_block_sessid(bsr, bsr->sessid, block)) { - continue; + continue; } return 1; } @@ -96,7 +96,7 @@ int match_bsr_block(BSR *bsr, DEV_BLOCK *block) static int match_block_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_BLOCK *block) { if (!sesstime) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (sesstime->sesstime == block->VolSessionTime) { return 1; @@ -110,7 +110,7 @@ static int match_block_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_BLOCK *blo static int match_block_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_BLOCK *block) { if (!sessid) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (sessid->sessid <= block->VolSessionId && sessid->sessid2 >= block->VolSessionId) { return 1; @@ -124,11 +124,11 @@ static int match_block_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_BLOCK *block) /********************************************************************* * - * Match Bootstrap records - * returns 1 on match - * returns 0 no match and reposition is set if we should - * reposition the tape - * returns -1 no additional matches possible + * Match Bootstrap records + * returns 1 on match + * returns 0 no match and reposition is set if we should + * reposition the tape + * returns -1 no additional matches possible */ int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec) { @@ -136,8 +136,8 @@ int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *se /* * The bsr->reposition flag is set any time a bsr is done. - * In this case, we can probably reposition the - * tape to the next available bsr position. + * In this case, we can probably reposition the + * tape to the next available bsr position. */ if (bsr) { bsr->reposition = false; @@ -148,10 +148,10 @@ int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *se * found or if we cannot use positioning */ if (stat != 0 || !bsr->use_positioning) { - bsr->reposition = false; + bsr->reposition = false; } } else { - stat = 1; /* no bsr => match all */ + stat = 1; /* no bsr => match all */ } return stat; } @@ -166,7 +166,7 @@ BSR *find_next_bsr(BSR *root_bsr, DEVICE *dev) BSR *found_bsr = NULL; if (!root_bsr || !root_bsr->use_positioning || - !root_bsr->reposition || !dev_is_tape(dev)) { + !root_bsr->reposition /* || !dev->is_tape()*/) { Dmsg2(100, "No nxt_bsr use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition); return NULL; } @@ -174,12 +174,12 @@ BSR *find_next_bsr(BSR *root_bsr, DEVICE *dev) root_bsr->mount_next_volume = false; for (bsr=root_bsr; bsr; bsr=bsr->next) { if (bsr->done || !match_volume(bsr, bsr->volume, &dev->VolHdr, 1)) { - continue; + continue; } if (found_bsr == NULL) { - found_bsr = bsr; + found_bsr = bsr; } else { - found_bsr = find_smallest_volfile(found_bsr, bsr); + found_bsr = find_smallest_volfile(found_bsr, bsr); } } /* @@ -205,14 +205,14 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) found_bsr_sfile = vf->sfile; while ( (vf=vf->next) ) { if (vf->sfile < found_bsr_sfile) { - found_bsr_sfile = vf->sfile; + found_bsr_sfile = vf->sfile; } } vf = bsr->volfile; bsr_sfile = vf->sfile; while ( (vf=vf->next) ) { if (vf->sfile < bsr_sfile) { - bsr_sfile = vf->sfile; + bsr_sfile = vf->sfile; } } if (found_bsr_sfile > bsr_sfile) { @@ -222,19 +222,19 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) vb = found_bsr->volblock; found_bsr_sblock = vb->sblock; while ( (vb=vb->next) ) { - if (vb->sblock < found_bsr_sblock) { - found_bsr_sblock = vb->sblock; - } + if (vb->sblock < found_bsr_sblock) { + found_bsr_sblock = vb->sblock; + } } vb = bsr->volblock; bsr_sblock = vb->sblock; while ( (vb=vb->next) ) { - if (vb->sblock < bsr_sblock) { - bsr_sblock = vb->sblock; - } + if (vb->sblock < bsr_sblock) { + bsr_sblock = vb->sblock; + } } if (found_bsr_sblock > bsr_sblock) { - return_bsr = bsr; + return_bsr = bsr; } } @@ -248,7 +248,7 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) * for consistency with the other match calls. * * Returns: true if we should reposition - * : false otherwise. + * : false otherwise. */ bool match_set_eof(BSR *bsr, DEV_RECORD *rec) { @@ -263,7 +263,7 @@ bool match_set_eof(BSR *bsr, DEV_RECORD *rec) rbsr->done = true; rbsr->root->reposition = true; Dmsg2(100, "match_set_eof reposition count=%d found=%d\n", - rbsr->count, rbsr->found); + rbsr->count, rbsr->found); return true; } return false; @@ -276,7 +276,7 @@ bool match_set_eof(BSR *bsr, DEV_RECORD *rec) * returns -1 no additional matches possible */ static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, - SESSION_LABEL *sessrec, bool done) + SESSION_LABEL *sessrec, bool done) { if (bsr->done) { goto no_match; @@ -286,45 +286,45 @@ static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, } if (!match_volfile(bsr, bsr->volfile, rec, 1)) { Dmsg2(100, "Fail on file. bsr=%d rec=%d\n", bsr->volfile->efile, - rec->File); + rec->File); goto no_match; } if (!match_sesstime(bsr, bsr->sesstime, rec, 1)) { Dmsg2(100, "Fail on sesstime. bsr=%d rec=%d\n", - bsr->sesstime->sesstime, rec->VolSessionTime); + bsr->sesstime->sesstime, rec->VolSessionTime); goto no_match; } /* NOTE!! This test MUST come after the sesstime test */ if (!match_sessid(bsr, bsr->sessid, rec)) { Dmsg2(100, "Fail on sessid. bsr=%d rec=%d\n", - bsr->sessid->sessid, rec->VolSessionId); + bsr->sessid->sessid, rec->VolSessionId); goto no_match; } /* NOTE!! This test MUST come after sesstime and sessid tests */ if (!match_findex(bsr, bsr->FileIndex, rec, 1)) { Dmsg2(100, "Fail on findex. bsr=%d rec=%d\n", - bsr->FileIndex->findex2, rec->FileIndex); + bsr->FileIndex->findex2, rec->FileIndex); goto no_match; } /* * If a count was specified and we have a FileIndex, assume - * it is a Bacula created bsr (or the equivalent). We - * then save the bsr where the match occurred so that - * after processing the record or records, we can update - * the found count. I.e. rec->bsr points to the bsr that - * satisfied the match. + * it is a Bacula created bsr (or the equivalent). We + * then save the bsr where the match occurred so that + * after processing the record or records, we can update + * the found count. I.e. rec->bsr points to the bsr that + * satisfied the match. */ if (bsr->count && bsr->FileIndex) { rec->bsr = bsr; - return 1; /* this is a complete match */ + return 1; /* this is a complete match */ } /* * The selections below are not used by Bacula's * restore command, and don't work because of - * the rec->bsr = bsr optimization above. + * the rec->bsr = bsr optimization above. */ if (!match_jobid(bsr, bsr->JobId, sessrec, 1)) { goto no_match; @@ -360,7 +360,7 @@ no_match: static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, bool done) { if (!volume) { - return 0; /* Volume must match */ + return 0; /* Volume must match */ } if (strcmp(volume->VolumeName, volrec->VolName) == 0) { return 1; @@ -374,7 +374,7 @@ static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, bool static int match_client(BSR *bsr, BSR_CLIENT *client, SESSION_LABEL *sessrec, bool done) { if (!client) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (fnmatch(client->ClientName, sessrec->ClientName, 0) == 0) { return 1; @@ -388,7 +388,7 @@ static int match_client(BSR *bsr, BSR_CLIENT *client, SESSION_LABEL *sessrec, bo static int match_job(BSR *bsr, BSR_JOB *job, SESSION_LABEL *sessrec, bool done) { if (!job) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (fnmatch(job->Job, sessrec->Job, 0) == 0) { return 1; @@ -402,7 +402,7 @@ static int match_job(BSR *bsr, BSR_JOB *job, SESSION_LABEL *sessrec, bool done) static int match_job_type(BSR *bsr, BSR_JOBTYPE *job_type, SESSION_LABEL *sessrec, bool done) { if (!job_type) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (job_type->JobType == sessrec->JobType) { return 1; @@ -416,7 +416,7 @@ static int match_job_type(BSR *bsr, BSR_JOBTYPE *job_type, SESSION_LABEL *sessre static int match_job_level(BSR *bsr, BSR_JOBLEVEL *job_level, SESSION_LABEL *sessrec, bool done) { if (!job_level) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (job_level->JobLevel == sessrec->JobLevel) { return 1; @@ -430,7 +430,7 @@ static int match_job_level(BSR *bsr, BSR_JOBLEVEL *job_level, SESSION_LABEL *ses static int match_jobid(BSR *bsr, BSR_JOBID *jobid, SESSION_LABEL *sessrec, bool done) { if (!jobid) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (jobid->JobId <= sessrec->JobId && jobid->JobId2 >= sessrec->JobId) { return 1; @@ -444,20 +444,20 @@ static int match_jobid(BSR *bsr, BSR_JOBID *jobid, SESSION_LABEL *sessrec, bool static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool done) { if (!volfile) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } /* For the moment, these tests work only with tapes. */ if (!(rec->state & REC_ISTAPE)) { - return 1; /* All File records OK for this match */ + return 1; /* All File records OK for this match */ } // Dmsg3(100, "match_volfile: sfile=%d efile=%d recfile=%d\n", -// volfile->sfile, volfile->efile, rec->File); +// volfile->sfile, volfile->efile, rec->File); if (volfile->sfile <= rec->File && volfile->efile >= rec->File) { return 1; } /* Once we get past last efile, we are done */ if (rec->File > volfile->efile) { - volfile->done = true; /* set local done */ + volfile->done = true; /* set local done */ } if (volfile->next) { return match_volfile(bsr, volfile->next, rec, volfile->done && done); @@ -468,7 +468,7 @@ static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool d bsr->done = true; bsr->root->reposition = true; Dmsg2(100, "bsr done from volfile rec=%d volefile=%d\n", - rec->File, volfile->efile); + rec->File, volfile->efile); } return 0; } @@ -476,7 +476,7 @@ static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool d static int match_stream(BSR *bsr, BSR_STREAM *stream, DEV_RECORD *rec, bool done) { if (!stream) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (stream->stream == rec->Stream) { return 1; @@ -490,7 +490,7 @@ static int match_stream(BSR *bsr, BSR_STREAM *stream, DEV_RECORD *rec, bool done static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, bool done) { if (!sesstime) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (sesstime->sesstime == rec->VolSessionTime) { return 1; @@ -512,7 +512,7 @@ static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, boo static int match_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_RECORD *rec) { if (!sessid) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (sessid->sessid <= rec->VolSessionId && sessid->sessid2 >= rec->VolSessionId) { return 1; @@ -526,11 +526,17 @@ static int match_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_RECORD *rec) /* * When reading the Volume, the Volume Findex (rec->FileIndex) always * are found in sequential order. Thus we can make optimizations. + * + * ***FIXME*** optimizations + * We could optimize a lot here by removing the recursion, and + * stopping the search earlier -- say when rec->FileIndex > findex->findex2 + * and findex->next == NULL. Also, the current entry tests could be skipped + * if findex->done is set. */ static int match_findex(BSR *bsr, BSR_FINDEX *findex, DEV_RECORD *rec, bool done) { if (!findex) { - return 1; /* no specification matches all */ + return 1; /* no specification matches all */ } if (findex->findex <= rec->FileIndex && findex->findex2 >= rec->FileIndex) { return 1; diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 0cf2ce80a4..fb7723a614 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -68,8 +68,8 @@ mount_next_vol: dcr->VolCatInfo.Slot = 0; if (!dir_ask_sysop_to_mount_volume(dcr)) { Jmsg(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"), - dev->print_name()); - return false; + dev->print_name()); + return false; } } if (job_canceled(jcr)) { @@ -80,18 +80,18 @@ mount_next_vol: if (release) { Dmsg0(100, "mount_next_volume release=1\n"); release_volume(dcr); - ask = true; /* ask operator to mount tape */ + ask = true; /* ask operator to mount tape */ } /* * Get Director's idea of what tape we should have mounted. - * in dcr->VolCatInfo + * in dcr->VolCatInfo */ Dmsg0(200, "Before dir_find_next_appendable_volume.\n"); while (!dir_find_next_appendable_volume(dcr)) { Dmsg0(200, "not dir_find_next\n"); if (!dir_ask_sysop_to_create_appendable_volume(dcr)) { - return false; + return false; } Dmsg0(200, "Again dir_find_next_append...\n"); } @@ -99,7 +99,7 @@ mount_next_vol: return false; } Dmsg3(100, "After find_next_append. Vol=%s Slot=%d Parts=%d\n", - dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.Slot, dcr->VolCatInfo.VolCatParts); + dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.Slot, dcr->VolCatInfo.VolCatParts); dev->num_parts = dcr->VolCatInfo.VolCatParts; @@ -126,11 +126,11 @@ mount_next_vol: Dmsg1(100, "autoload_dev returns %d\n", autochanger); /* * If we autochanged to correct Volume or (we have not just - * released the Volume AND we can automount) we go ahead - * and read the label. If there is no tape in the drive, - * we will err, recurse and ask the operator the next time. + * released the Volume AND we can automount) we go ahead + * and read the label. If there is no tape in the drive, + * we will err, recurse and ask the operator the next time. */ - if (!release && dev_is_tape(dev) && dev_cap(dev, CAP_AUTOMOUNT)) { + if (!release && dev->is_tape() && dev_cap(dev, CAP_AUTOMOUNT)) { ask = false; /* don't ask SYSOP this time */ } /* Don't ask if not removable */ @@ -142,7 +142,7 @@ mount_next_vol: if (ask && !dir_ask_sysop_to_mount_volume(dcr)) { Dmsg0(100, "Error return ask_sysop ...\n"); - return false; /* error return */ + return false; /* error return */ } if (job_canceled(jcr)) { return false; @@ -160,17 +160,17 @@ mount_next_vol: */ if (!dev->is_dvd()) { if (!open_device(dcr)) { - if (dev->poll) { - goto mount_next_vol; - } else { - return false; - } + if (dev->poll) { + goto mount_next_vol; + } else { + return false; + } } } else { /* * Just copy the VolCatName in the device resource * (usually done by open_dev). - * It is necessary so we can open the real files later. + * It is necessary so we can open the real files later. */ bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatName, sizeof(dev->VolCatInfo.VolCatName)); } @@ -200,32 +200,32 @@ read_volume: dcr->VolCatInfo.VolCatStatus); /* * At this point, dev->VolCatInfo has what is in the drive, if anything, - * and dcr->VolCatInfo has what the Director wants. + * and dcr->VolCatInfo has what the Director wants. */ switch (vol_label_status) { case VOL_OK: Dmsg1(100, "Vol OK name=%s\n", dcr->VolumeName); memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); recycle = strcmp(dev->VolCatInfo.VolCatStatus, "Recycle") == 0; - break; /* got a Volume */ + break; /* got a Volume */ case VOL_NAME_ERROR: VOLUME_CAT_INFO VolCatInfo; /* If not removable, Volume is broken */ if (!dev_cap(dev, CAP_REM)) { Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"), - dcr->VolumeName, dev->print_name()); - mark_volume_in_error(dcr); - goto mount_next_vol; + dcr->VolumeName, dev->print_name()); + mark_volume_in_error(dcr); + goto mount_next_vol; } Dmsg1(100, "Vol NAME Error Name=%s\n", dcr->VolumeName); /* If polling and got a previous bad name, ignore it */ if (dev->poll && strcmp(dev->BadVolName, dev->VolHdr.VolName) == 0) { - ask = true; + ask = true; Dmsg1(200, "Vol Name error supress due to poll. Name=%s\n", - dcr->VolumeName); - goto mount_next_vol; + dcr->VolumeName); + goto mount_next_vol; } /* * OK, we got a different volume mounted. First save the @@ -237,21 +237,21 @@ read_volume: /* Check if this is a valid Volume in the pool */ bstrncpy(dcr->VolumeName, dev->VolHdr.VolName, sizeof(dcr->VolumeName)); if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE)) { - bstrncpy(dev->BadVolName, dev->VolHdr.VolName, sizeof(dev->BadVolName)); + bstrncpy(dev->BadVolName, dev->VolHdr.VolName, sizeof(dev->BadVolName)); Jmsg(jcr, M_WARNING, 0, _("Director wanted Volume \"%s\".\n" " Current Volume \"%s\" not acceptable because:\n" " %s"), - VolCatInfo.VolCatName, dev->VolHdr.VolName, - jcr->dir_bsock->msg); - /* Restore desired volume name, note device info out of sync */ - memcpy(&dcr->VolCatInfo, &VolCatInfo, sizeof(dcr->VolCatInfo)); - ask = true; - goto mount_next_vol; + VolCatInfo.VolCatName, dev->VolHdr.VolName, + jcr->dir_bsock->msg); + /* Restore desired volume name, note device info out of sync */ + memcpy(&dcr->VolCatInfo, &VolCatInfo, sizeof(dcr->VolCatInfo)); + ask = true; + goto mount_next_vol; } Dmsg1(100, "want new name=%s\n", dcr->VolumeName); memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); recycle = strcmp(dev->VolCatInfo.VolCatStatus, "Recycle") == 0; - break; /* got a Volume */ + break; /* got a Volume */ /* * At this point, we assume we have a blank tape mounted. */ @@ -269,34 +269,34 @@ read_volume: * previous tape (or nothing). */ if (dev_cap(dev, CAP_LABEL) && (dcr->VolCatInfo.VolCatBytes == 0 || - (!dev->is_tape() && strcmp(dcr->VolCatInfo.VolCatStatus, + (!dev->is_tape() && strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") == 0))) { Dmsg0(100, "Create volume label\n"); - /* Create a new Volume label and write it to the device */ - if (!write_new_volume_label_to_dev(dcr, dcr->VolumeName, - dcr->pool_name)) { + /* Create a new Volume label and write it to the device */ + if (!write_new_volume_label_to_dev(dcr, dcr->VolumeName, + dcr->pool_name)) { Dmsg0(100, "!write_vol_label\n"); - goto mount_next_vol; - } + goto mount_next_vol; + } Dmsg0(100, "dir_update_vol_info. Set Append\n"); /* Copy Director's info into the device info */ - memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); - if (!dir_update_volume_info(dcr, true)) { /* indicate tape labeled */ - return false; - } + memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); + if (!dir_update_volume_info(dcr, true)) { /* indicate tape labeled */ + return false; + } Jmsg(jcr, M_INFO, 0, _("Labeled new Volume \"%s\" on device %s.\n"), - dcr->VolumeName, dev->print_name()); - goto read_volume; /* read label we just wrote */ + dcr->VolumeName, dev->print_name()); + goto read_volume; /* read label we just wrote */ } /* If not removable, Volume is broken */ if (!dev_cap(dev, CAP_REM)) { Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"), - dcr->VolumeName, dev->print_name()); - mark_volume_in_error(dcr); - if (autochanger) { - mark_volume_not_inchanger(dcr); - } - goto mount_next_vol; + dcr->VolumeName, dev->print_name()); + mark_volume_in_error(dcr); + if (autochanger) { + mark_volume_not_inchanger(dcr); + } + goto mount_next_vol; } /* NOTE! Fall-through wanted. */ case VOL_NO_MEDIA: @@ -310,7 +310,7 @@ read_volume: ask = true; /* Needed, so the medium can be changed */ if (dev_cap(dev, CAP_REQMOUNT)) { - close_dev(dev); + close_dev(dev); } goto mount_next_vol; } @@ -322,7 +322,7 @@ read_volume: * but never written. If so, rewrite the label but set as * VOL_LABEL. We rewind and return the label (reconstructed) * in the block so that in the case of a new tape, data can - * be appended just after the block label. If we are writing + * be appended just after the block label. If we are writing * a second volume, the calling routine will write the label * before writing the overflow block. * @@ -330,7 +330,7 @@ read_volume: */ if (dev->VolHdr.LabelType == PRE_LABEL || recycle) { if (!rewrite_volume_label(dcr, recycle)) { - goto mount_next_vol; + goto mount_next_vol; } } else { /* @@ -340,37 +340,37 @@ read_volume: */ Dmsg0(200, "Device previously written, moving to end of data\n"); Jmsg(jcr, M_INFO, 0, _("Volume \"%s\" previously written, moving to end of data.\n"), - dcr->VolumeName); + dcr->VolumeName); if (!eod_dev(dev)) { Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data on device %s: ERR=%s\n"), - dev->print_name(), strerror_dev(dev)); - mark_volume_in_error(dcr); - goto mount_next_vol; + dev->print_name(), strerror_dev(dev)); + mark_volume_in_error(dcr); + goto mount_next_vol; } /* *****FIXME**** we should do some checking for files too */ - if (dev_is_tape(dev)) { - /* - * Check if we are positioned on the tape at the same place - * that the database says we should be. - */ - if (dev->VolCatInfo.VolCatFiles == dev_file(dev)) { + if (dev->is_tape()) { + /* + * Check if we are positioned on the tape at the same place + * that the database says we should be. + */ + if (dev->VolCatInfo.VolCatFiles == dev_file(dev)) { Jmsg(jcr, M_INFO, 0, _("Ready to append to end of Volume \"%s\" at file=%d.\n"), - dcr->VolumeName, dev_file(dev)); - } else { + dcr->VolumeName, dev_file(dev)); + } else { Jmsg(jcr, M_ERROR, 0, _("I cannot write on Volume \"%s\" because:\n" "The number of files mismatch! Volume=%u Catalog=%u\n"), - dcr->VolumeName, dev_file(dev), dev->VolCatInfo.VolCatFiles); - mark_volume_in_error(dcr); - goto mount_next_vol; - } + dcr->VolumeName, dev_file(dev), dev->VolCatInfo.VolCatFiles); + mark_volume_in_error(dcr); + goto mount_next_vol; + } } - dev->VolCatInfo.VolCatMounts++; /* Update mounts */ + dev->VolCatInfo.VolCatMounts++; /* Update mounts */ Dmsg1(100, "update volinfo mounts=%d\n", dev->VolCatInfo.VolCatMounts); if (!dir_update_volume_info(dcr, false)) { - return false; + return false; } /* Return an empty block */ - empty_block(block); /* we used it for reading so set for write */ + empty_block(block); /* we used it for reading so set for write */ } dev->set_append(); Dmsg0(100, "set APPEND, normal return from read_dev_for_append\n"); @@ -386,7 +386,7 @@ void mark_volume_in_error(DCR *dcr) { DEVICE *dev = dcr->dev; Jmsg(dcr->jcr, M_INFO, 0, _("Marking Volume \"%s\" in Error in Catalog.\n"), - dcr->VolumeName); + dcr->VolumeName); bstrncpy(dev->VolCatInfo.VolCatStatus, "Error", sizeof(dev->VolCatInfo.VolCatStatus)); Dmsg0(100, "dir_update_vol_info. Set Error.\n"); dir_update_volume_info(dcr, false); @@ -409,10 +409,10 @@ bool mount_next_read_volume(DCR *dcr) dev->clear_read(); if (!acquire_device_for_read(dcr)) { Jmsg2(jcr, M_FATAL, 0, "Cannot open Dev=%s, Vol=%s\n", dev->print_name(), - dcr->VolumeName); - return false; + dcr->VolumeName); + return false; } - return true; /* next volume mounted */ + return true; /* next volume mounted */ } Dmsg0(90, "End of Device reached.\n"); return false; diff --git a/bacula/src/stored/parse_bsr.c b/bacula/src/stored/parse_bsr.c index 654232632c..69df50cc4f 100755 --- a/bacula/src/stored/parse_bsr.c +++ b/bacula/src/stored/parse_bsr.c @@ -107,18 +107,18 @@ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...) if (jcr) { Jmsg(jcr, M_FATAL, 0, _("Bootstrap file error: %s\n" " : Line %d, col %d of file %s\n%s\n"), - buf, lc->line_no, lc->col_no, lc->fname, lc->line); + buf, lc->line_no, lc->col_no, lc->fname, lc->line); } else { e_msg(file, line, M_FATAL, 0, _("Bootstrap file error: %s\n" " : Line %d, col %d of file %s\n%s\n"), - buf, lc->line_no, lc->col_no, lc->fname, lc->line); + buf, lc->line_no, lc->col_no, lc->fname, lc->line); } } /********************************************************************* * - * Parse Bootstrap file + * Parse Bootstrap file * */ BSR *parse_bsr(JCR *jcr, char *fname) @@ -134,32 +134,32 @@ BSR *parse_bsr(JCR *jcr, char *fname) while ((token=lex_get_token(lc, T_ALL)) != T_EOF) { Dmsg1(200, "parse got token=%s\n", lex_tok_to_str(token)); if (token == T_EOL) { - continue; + continue; } for (i=0; items[i].name; i++) { - if (strcasecmp(items[i].name, lc->str) == 0) { - token = lex_get_token(lc, T_ALL); + if (strcasecmp(items[i].name, lc->str) == 0) { + token = lex_get_token(lc, T_ALL); Dmsg1 (200, "in T_IDENT got token=%s\n", lex_tok_to_str(token)); - if (token != T_EQUALS) { + if (token != T_EQUALS) { scan_err1(lc, "expected an equals, got: %s", lc->str); - bsr = NULL; - break; - } + bsr = NULL; + break; + } Dmsg1(200, "calling handler for %s\n", items[i].name); - /* Call item handler */ - bsr = items[i].handler(lc, bsr); - i = -1; - break; - } + /* Call item handler */ + bsr = items[i].handler(lc, bsr); + i = -1; + break; + } } if (i >= 0) { Dmsg1(200, "Keyword = %s\n", lc->str); scan_err1(lc, "Keyword %s not found", lc->str); - bsr = NULL; - break; + bsr = NULL; + break; } if (!bsr) { - break; + break; } } lc = lex_close_file(lc); @@ -185,11 +185,10 @@ static bool is_fast_rejection_ok(BSR *bsr) * all bsrs to have both sesstime and sessid set before * we do fast rejection. */ - if (!(bsr->sesstime && bsr->sessid)) { - return false; - } - if (bsr->next) { - return is_fast_rejection_ok(bsr->next); + for ( ; bsr; bsr=bsr->next) { + if (!(bsr->sesstime && bsr->sessid)) { + return false; + } } return true; } @@ -198,13 +197,12 @@ static bool is_positioning_ok(BSR *bsr) { /* * Every bsr should have a volfile entry and a volblock entry - * if we are going to use positioning + * if we are going to use positioning */ - if (!bsr->volfile || !bsr->volblock) { - return false; - } - if (bsr->next) { - return is_positioning_ok(bsr->next); + for ( ; bsr; bsr=bsr->next) { + if (!bsr->volfile || !bsr->volblock) { + return false; + } } return true; } @@ -230,19 +228,19 @@ static BSR *store_vol(LEX *lc, BSR *bsr) for (p=lc->str; p && *p; ) { n = strchr(p, '|'); if (n) { - *n++ = 0; + *n++ = 0; } volume = (BSR_VOLUME *)malloc(sizeof(BSR_VOLUME)); memset(volume, 0, sizeof(BSR_VOLUME)); bstrncpy(volume->VolumeName, p, sizeof(volume->VolumeName)); /* Add it to the end of the volume chain */ if (!bsr->volume) { - bsr->volume = volume; + bsr->volume = volume; } else { - BSR_VOLUME *bc = bsr->volume; - for ( ;bc->next; bc=bc->next) - { } - bc->next = volume; + BSR_VOLUME *bc = bsr->volume; + for ( ;bc->next; bc=bc->next) + { } + bc->next = volume; } p = n; } @@ -260,7 +258,7 @@ static BSR *store_mediatype(LEX *lc, BSR *bsr) } if (!bsr->volume) { Emsg1(M_ERROR,0, _("MediaType %s in bsr at inappropriate place.\n"), - lc->str); + lc->str); return bsr; } BSR_VOLUME *bv; @@ -279,23 +277,23 @@ static BSR *store_client(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_NAME); if (token == T_ERROR) { - return NULL; + return NULL; } client = (BSR_CLIENT *)malloc(sizeof(BSR_CLIENT)); memset(client, 0, sizeof(BSR_CLIENT)); bstrncpy(client->ClientName, lc->str, sizeof(client->ClientName)); /* Add it to the end of the client chain */ if (!bsr->client) { - bsr->client = client; + bsr->client = client; } else { - BSR_CLIENT *bc = bsr->client; - for ( ;bc->next; bc=bc->next) - { } - bc->next = client; + BSR_CLIENT *bc = bsr->client; + for ( ;bc->next; bc=bc->next) + { } + bc->next = client; } token = lex_get_token(lc, T_ALL); if (token != T_COMMA) { - break; + break; } } return bsr; @@ -309,24 +307,24 @@ static BSR *store_job(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_NAME); if (token == T_ERROR) { - return NULL; + return NULL; } job = (BSR_JOB *)malloc(sizeof(BSR_JOB)); memset(job, 0, sizeof(BSR_JOB)); bstrncpy(job->Job, lc->str, sizeof(job->Job)); /* Add it to the end of the client chain */ if (!bsr->job) { - bsr->job = job; + bsr->job = job; } else { - /* Add to end of chain */ - BSR_JOB *bc = bsr->job; - for ( ;bc->next; bc=bc->next) - { } - bc->next = job; + /* Add to end of chain */ + BSR_JOB *bc = bsr->job; + for ( ;bc->next; bc=bc->next) + { } + bc->next = job; } token = lex_get_token(lc, T_ALL); if (token != T_COMMA) { - break; + break; } } return bsr; @@ -340,7 +338,7 @@ static BSR *store_findex(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32_RANGE); if (token == T_ERROR) { - return NULL; + return NULL; } findex = (BSR_FINDEX *)malloc(sizeof(BSR_FINDEX)); memset(findex, 0, sizeof(BSR_FINDEX)); @@ -348,17 +346,17 @@ static BSR *store_findex(LEX *lc, BSR *bsr) findex->findex2 = lc->pint32_val2; /* Add it to the end of the chain */ if (!bsr->FileIndex) { - bsr->FileIndex = findex; + bsr->FileIndex = findex; } else { - /* Add to end of chain */ - BSR_FINDEX *bs = bsr->FileIndex; - for ( ;bs->next; bs=bs->next) - { } - bs->next = findex; + /* Add to end of chain */ + BSR_FINDEX *bs = bsr->FileIndex; + for ( ;bs->next; bs=bs->next) + { } + bs->next = findex; } token = lex_get_token(lc, T_ALL); if (token != T_COMMA) { - break; + break; } } return bsr; @@ -373,7 +371,7 @@ static BSR *store_jobid(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32_RANGE); if (token == T_ERROR) { - return NULL; + return NULL; } jobid = (BSR_JOBID *)malloc(sizeof(BSR_JOBID)); memset(jobid, 0, sizeof(BSR_JOBID)); @@ -381,17 +379,17 @@ static BSR *store_jobid(LEX *lc, BSR *bsr) jobid->JobId2 = lc->pint32_val2; /* Add it to the end of the chain */ if (!bsr->JobId) { - bsr->JobId = jobid; + bsr->JobId = jobid; } else { - /* Add to end of chain */ - BSR_JOBID *bs = bsr->JobId; - for ( ;bs->next; bs=bs->next) - { } - bs->next = jobid; + /* Add to end of chain */ + BSR_JOBID *bs = bsr->JobId; + for ( ;bs->next; bs=bs->next) + { } + bs->next = jobid; } token = lex_get_token(lc, T_ALL); if (token != T_COMMA) { - break; + break; } } return bsr; @@ -441,7 +439,7 @@ static BSR *store_volfile(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32_RANGE); if (token == T_ERROR) { - return NULL; + return NULL; } volfile = (BSR_VOLFILE *)malloc(sizeof(BSR_VOLFILE)); memset(volfile, 0, sizeof(BSR_VOLFILE)); @@ -449,17 +447,17 @@ static BSR *store_volfile(LEX *lc, BSR *bsr) volfile->efile = lc->pint32_val2; /* Add it to the end of the chain */ if (!bsr->volfile) { - bsr->volfile = volfile; + bsr->volfile = volfile; } else { - /* Add to end of chain */ - BSR_VOLFILE *bs = bsr->volfile; - for ( ;bs->next; bs=bs->next) - { } - bs->next = volfile; + /* Add to end of chain */ + BSR_VOLFILE *bs = bsr->volfile; + for ( ;bs->next; bs=bs->next) + { } + bs->next = volfile; } token = lex_get_token(lc, T_ALL); if (token != T_COMMA) { - break; + break; } } return bsr; @@ -477,7 +475,7 @@ static BSR *store_volblock(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32_RANGE); if (token == T_ERROR) { - return NULL; + return NULL; } volblock = (BSR_VOLBLOCK *)malloc(sizeof(BSR_VOLBLOCK)); memset(volblock, 0, sizeof(BSR_VOLBLOCK)); @@ -485,17 +483,17 @@ static BSR *store_volblock(LEX *lc, BSR *bsr) volblock->eblock = lc->pint32_val2; /* Add it to the end of the chain */ if (!bsr->volblock) { - bsr->volblock = volblock; + bsr->volblock = volblock; } else { - /* Add to end of chain */ - BSR_VOLBLOCK *bs = bsr->volblock; - for ( ;bs->next; bs=bs->next) - { } - bs->next = volblock; + /* Add to end of chain */ + BSR_VOLBLOCK *bs = bsr->volblock; + for ( ;bs->next; bs=bs->next) + { } + bs->next = volblock; } token = lex_get_token(lc, T_ALL); if (token != T_COMMA) { - break; + break; } } return bsr; @@ -510,7 +508,7 @@ static BSR *store_sessid(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32_RANGE); if (token == T_ERROR) { - return NULL; + return NULL; } sid = (BSR_SESSID *)malloc(sizeof(BSR_SESSID)); memset(sid, 0, sizeof(BSR_SESSID)); @@ -518,17 +516,17 @@ static BSR *store_sessid(LEX *lc, BSR *bsr) sid->sessid2 = lc->pint32_val2; /* Add it to the end of the chain */ if (!bsr->sessid) { - bsr->sessid = sid; + bsr->sessid = sid; } else { - /* Add to end of chain */ - BSR_SESSID *bs = bsr->sessid; - for ( ;bs->next; bs=bs->next) - { } - bs->next = sid; + /* Add to end of chain */ + BSR_SESSID *bs = bsr->sessid; + for ( ;bs->next; bs=bs->next) + { } + bs->next = sid; } token = lex_get_token(lc, T_ALL); if (token != T_COMMA) { - break; + break; } } return bsr; @@ -542,24 +540,24 @@ static BSR *store_sesstime(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32); if (token == T_ERROR) { - return NULL; + return NULL; } stime = (BSR_SESSTIME *)malloc(sizeof(BSR_SESSTIME)); memset(stime, 0, sizeof(BSR_SESSTIME)); stime->sesstime = lc->pint32_val; /* Add it to the end of the chain */ if (!bsr->sesstime) { - bsr->sesstime = stime; + bsr->sesstime = stime; } else { - /* Add to end of chain */ - BSR_SESSTIME *bs = bsr->sesstime; - for ( ;bs->next; bs=bs->next) - { } - bs->next = stime; + /* Add to end of chain */ + BSR_SESSTIME *bs = bsr->sesstime; + for ( ;bs->next; bs=bs->next) + { } + bs->next = stime; } token = lex_get_token(lc, T_ALL); if (token != T_COMMA) { - break; + break; } } return bsr; @@ -574,24 +572,24 @@ static BSR *store_stream(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_INT32); if (token == T_ERROR) { - return NULL; + return NULL; } stream = (BSR_STREAM *)malloc(sizeof(BSR_STREAM)); memset(stream, 0, sizeof(BSR_STREAM)); stream->stream = lc->int32_val; /* Add it to the end of the chain */ if (!bsr->stream) { - bsr->stream = stream; + bsr->stream = stream; } else { - /* Add to end of chain */ - BSR_STREAM *bs = bsr->stream; - for ( ;bs->next; bs=bs->next) - { } - bs->next = stream; + /* Add to end of chain */ + BSR_STREAM *bs = bsr->stream; + for ( ;bs->next; bs=bs->next) + { } + bs->next = stream; } token = lex_get_token(lc, T_ALL); if (token != T_COMMA) { - break; + break; } } return bsr; @@ -754,7 +752,7 @@ void dump_bsr(BSR *bsr, bool recurse) /********************************************************************* * - * Free bsr resources + * Free bsr resources */ static void free_bsr_item(BSR *bsr) @@ -801,30 +799,30 @@ VOL_LIST *new_vol() * is not already in the list. * * returns: 1 if volume added - * 0 if volume already in list + * 0 if volume already in list */ int add_vol(JCR *jcr, VOL_LIST *vol) { VOL_LIST *next = jcr->VolList; - if (!next) { /* list empty ? */ - jcr->VolList = vol; /* yes, add volume */ + if (!next) { /* list empty ? */ + jcr->VolList = vol; /* yes, add volume */ } else { for ( ; next->next; next=next->next) { - if (strcmp(vol->VolumeName, next->VolumeName) == 0) { - if (vol->start_file < next->start_file) { - next->start_file = vol->start_file; - } - return 0; /* already in list */ - } + if (strcmp(vol->VolumeName, next->VolumeName) == 0) { + if (vol->start_file < next->start_file) { + next->start_file = vol->start_file; + } + return 0; /* already in list */ + } } if (strcmp(vol->VolumeName, next->VolumeName) == 0) { - if (vol->start_file < next->start_file) { - next->start_file = vol->start_file; - } - return 0; /* already in list */ + if (vol->start_file < next->start_file) { + next->start_file = vol->start_file; + } + return 0; /* already in list */ } - next->next = vol; /* add volume */ + next->next = vol; /* add volume */ } return 1; } @@ -859,52 +857,52 @@ void create_vol_list(JCR *jcr) if (jcr->bsr) { BSR *bsr = jcr->bsr; if (!bsr->volume || !bsr->volume->VolumeName) { - return; + return; } for ( ; bsr; bsr=bsr->next) { - BSR_VOLUME *bsrvol; - BSR_VOLFILE *volfile; - uint32_t sfile = UINT32_MAX; - - /* Find minimum start file so that we can forward space to it */ - for (volfile = bsr->volfile; volfile; volfile=volfile->next) { - if (volfile->sfile < sfile) { - sfile = volfile->sfile; - } - } - /* Now add volumes for this bsr */ - for (bsrvol = bsr->volume; bsrvol; bsrvol=bsrvol->next) { - vol = new_vol(); - bstrncpy(vol->VolumeName, bsrvol->VolumeName, sizeof(vol->VolumeName)); - bstrncpy(vol->MediaType, bsrvol->MediaType, sizeof(vol->MediaType)); - vol->start_file = sfile; - if (add_vol(jcr, vol)) { - jcr->NumVolumes++; + BSR_VOLUME *bsrvol; + BSR_VOLFILE *volfile; + uint32_t sfile = UINT32_MAX; + + /* Find minimum start file so that we can forward space to it */ + for (volfile = bsr->volfile; volfile; volfile=volfile->next) { + if (volfile->sfile < sfile) { + sfile = volfile->sfile; + } + } + /* Now add volumes for this bsr */ + for (bsrvol = bsr->volume; bsrvol; bsrvol=bsrvol->next) { + vol = new_vol(); + bstrncpy(vol->VolumeName, bsrvol->VolumeName, sizeof(vol->VolumeName)); + bstrncpy(vol->MediaType, bsrvol->MediaType, sizeof(vol->MediaType)); + vol->start_file = sfile; + if (add_vol(jcr, vol)) { + jcr->NumVolumes++; Dmsg2(400, "Added volume=%s mediatype=%s\n", vol->VolumeName, - vol->MediaType); - } else { + vol->MediaType); + } else { Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName); - free((char *)vol); - } - sfile = 0; /* start at beginning of second volume */ - } + free((char *)vol); + } + sfile = 0; /* start at beginning of second volume */ + } } } else { /* This is the old way -- deprecated */ for (p = jcr->dcr->VolumeName; p && *p; ) { n = strchr(p, '|'); /* volume name separator */ - if (n) { - *n++ = 0; /* Terminate name */ - } - vol = new_vol(); - bstrncpy(vol->VolumeName, p, sizeof(vol->VolumeName)); - bstrncpy(vol->MediaType, jcr->dcr->media_type, sizeof(vol->MediaType)); - if (add_vol(jcr, vol)) { - jcr->NumVolumes++; - } else { - free((char *)vol); - } - p = n; + if (n) { + *n++ = 0; /* Terminate name */ + } + vol = new_vol(); + bstrncpy(vol->VolumeName, p, sizeof(vol->VolumeName)); + bstrncpy(vol->MediaType, jcr->dcr->media_type, sizeof(vol->MediaType)); + if (add_vol(jcr, vol)) { + jcr->NumVolumes++; + } else { + free((char *)vol); + } + p = n; } } } diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 784923a899..6c32549aaf 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -125,7 +125,6 @@ bool double_dev_wait_time(DEVICE *dev); char * dev_vol_name(DEVICE *dev); uint32_t dev_block(DEVICE *dev); uint32_t dev_file(DEVICE *dev); -bool dev_is_tape(DEVICE *dev); /* From dvd.c */ bool dvd_close_job(DCR *dcr); diff --git a/bacula/src/stored/read_record.c b/bacula/src/stored/read_record.c index 893e0ddf3f..0203b612ea 100644 --- a/bacula/src/stored/read_record.c +++ b/bacula/src/stored/read_record.c @@ -39,7 +39,7 @@ /* Forward referenced functions */ static void handle_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sessrec); static BSR *position_to_first_file(JCR *jcr, DEVICE *dev); -static int try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev); +static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev); #ifdef DEBUG static char *rec_state_to_str(DEV_RECORD *rec); #endif @@ -56,7 +56,7 @@ bool read_records(DCR *dcr, bool ok = true; bool done = false; SESSION_LABEL sessrec; - dlist *recs; /* linked list of rec packets open */ + dlist *recs; /* linked list of rec packets open */ recs = New(dlist(rec, &rec->link)); position_to_first_file(jcr, dev); @@ -64,78 +64,78 @@ bool read_records(DCR *dcr, for ( ; ok && !done; ) { if (job_canceled(jcr)) { - ok = false; - break; + ok = false; + break; } if (!read_block_from_device(dcr, CHECK_BLOCK_NUMBERS)) { - if (dev->at_eot()) { - DEV_RECORD *trec = new_record(); + if (dev->at_eot()) { + DEV_RECORD *trec = new_record(); Jmsg(jcr, M_INFO, 0, "End of Volume at file %u on device %s, Volume \"%s\"\n", - dev->file, dev->print_name(), dcr->VolumeName); - if (!mount_cb(dcr)) { + dev->file, dev->print_name(), dcr->VolumeName); + if (!mount_cb(dcr)) { Jmsg(jcr, M_INFO, 0, "End of all volumes.\n"); - ok = false; /* Stop everything */ - /* - * Create EOT Label so that Media record may - * be properly updated because this is the last - * tape. - */ - trec->FileIndex = EOT_LABEL; - trec->File = dev->file; - ok = record_cb(dcr, trec); - free_record(trec); - if (jcr->mount_next_volume) { - jcr->mount_next_volume = false; - dev->clear_eot(); - } - break; - } - jcr->mount_next_volume = false; - /* - * We just have a new tape up, now read the label (first record) - * and pass it off to the callback routine, then continue - * most likely reading the previous record. - */ - read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK); - read_record_from_block(block, trec); - handle_session_record(dev, trec, &sessrec); - ok = record_cb(dcr, trec); - free_record(trec); - position_to_first_file(jcr, dev); - /* After reading label, we must read first data block */ - continue; + ok = false; /* Stop everything */ + /* + * Create EOT Label so that Media record may + * be properly updated because this is the last + * tape. + */ + trec->FileIndex = EOT_LABEL; + trec->File = dev->file; + ok = record_cb(dcr, trec); + free_record(trec); + if (jcr->mount_next_volume) { + jcr->mount_next_volume = false; + dev->clear_eot(); + } + break; + } + jcr->mount_next_volume = false; + /* + * We just have a new tape up, now read the label (first record) + * and pass it off to the callback routine, then continue + * most likely reading the previous record. + */ + read_block_from_device(dcr, NO_BLOCK_NUMBER_CHECK); + read_record_from_block(block, trec); + handle_session_record(dev, trec, &sessrec); + ok = record_cb(dcr, trec); + free_record(trec); + position_to_first_file(jcr, dev); + /* After reading label, we must read first data block */ + continue; - } else if (dev->at_eof()) { - if (verbose) { + } else if (dev->at_eof()) { + if (verbose) { Jmsg(jcr, M_INFO, 0, "Got EOF at file %u on device %s, Volume \"%s\"\n", - dev->file, dev->print_name(), dcr->VolumeName); - } + dev->file, dev->print_name(), dcr->VolumeName); + } Dmsg3(200, "Got EOF at file %u on device %s, Volume \"%s\"\n", - dev->file, dev->print_name(), dcr->VolumeName); - continue; - } else if (dev_state(dev, ST_SHORT)) { + dev->file, dev->print_name(), dcr->VolumeName); + continue; + } else if (dev_state(dev, ST_SHORT)) { Jmsg1(jcr, M_ERROR, 0, "%s", dev->errmsg); - continue; - } else { - /* I/O error or strange end of tape */ - display_tape_error_status(jcr, dev); - if (forge_on || jcr->ignore_label_errors) { - fsr_dev(dev, 1); /* try skipping bad record */ + continue; + } else { + /* I/O error or strange end of tape */ + display_tape_error_status(jcr, dev); + if (forge_on || jcr->ignore_label_errors) { + fsr_dev(dev, 1); /* try skipping bad record */ Pmsg0(000, "Did fsr\n"); - continue; /* try to continue */ - } - ok = false; /* stop everything */ - break; - } + continue; /* try to continue */ + } + ok = false; /* stop everything */ + break; + } } - Dmsg2(300, "New block at position=(file:block) %d:%d\n", dev->file, dev->block_num); + Dmsg2(300, "New block at position=(file:block) %u:%u\n", dev->file, dev->block_num); #ifdef if_and_when_FAST_BLOCK_REJECTION_is_working /* this does not stop when file/block are too big */ if (!match_bsr_block(jcr->bsr, block)) { - if (try_repositioning(jcr, rec, dev)) { - break; /* get next volume */ - } - continue; /* skip this record */ + if (try_repositioning(jcr, rec, dev)) { + break; /* get next volume */ + } + continue; /* skip this record */ } #endif @@ -145,102 +145,102 @@ bool read_records(DCR *dcr, */ bool found = false; foreach_dlist(rec, recs) { - if (rec->VolSessionId == block->VolSessionId && - rec->VolSessionTime == block->VolSessionTime) { - found = true; - break; - } + if (rec->VolSessionId == block->VolSessionId && + rec->VolSessionTime == block->VolSessionTime) { + found = true; + break; + } } if (!found) { - rec = new_record(); - recs->prepend(rec); + rec = new_record(); + recs->prepend(rec); Dmsg2(300, "New record for SI=%d ST=%d\n", - block->VolSessionId, block->VolSessionTime); + block->VolSessionId, block->VolSessionTime); } Dmsg3(300, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec), - block->BlockNumber, rec->remainder); + block->BlockNumber, rec->remainder); record = 0; rec->state = 0; Dmsg1(300, "Block empty %d\n", is_block_empty(rec)); for (rec->state=0; !is_block_empty(rec); ) { - if (!read_record_from_block(block, rec)) { + if (!read_record_from_block(block, rec)) { Dmsg3(400, "!read-break. state=%s blk=%d rem=%d\n", rec_state_to_str(rec), - block->BlockNumber, rec->remainder); - break; - } - Dmsg5(300, "read-OK. state=%s blk=%d rem=%d file:block=%d:%d\n", - rec_state_to_str(rec), block->BlockNumber, rec->remainder, - dev->file, dev->block_num); - /* - * At this point, we have at least a record header. - * Now decide if we want this record or not, but remember - * before accessing the record, we may need to read again to - * get all the data. - */ - record++; + block->BlockNumber, rec->remainder); + break; + } + Dmsg5(300, "read-OK. state=%s blk=%d rem=%d file:block=%u:%u\n", + rec_state_to_str(rec), block->BlockNumber, rec->remainder, + dev->file, dev->block_num); + /* + * At this point, we have at least a record header. + * Now decide if we want this record or not, but remember + * before accessing the record, we may need to read again to + * get all the data. + */ + record++; Dmsg6(300, "recno=%d state=%s blk=%d SI=%d ST=%d FI=%d\n", record, - rec_state_to_str(rec), block->BlockNumber, - rec->VolSessionId, rec->VolSessionTime, rec->FileIndex); + rec_state_to_str(rec), block->BlockNumber, + rec->VolSessionId, rec->VolSessionTime, rec->FileIndex); - if (rec->FileIndex == EOM_LABEL) { /* end of tape? */ + if (rec->FileIndex == EOM_LABEL) { /* end of tape? */ Dmsg0(40, "Get EOM LABEL\n"); - break; /* yes, get out */ - } + break; /* yes, get out */ + } - /* Some sort of label? */ - if (rec->FileIndex < 0) { - handle_session_record(dev, rec, &sessrec); - ok = record_cb(dcr, rec); - if (rec->FileIndex == EOS_LABEL) { + /* Some sort of label? */ + if (rec->FileIndex < 0) { + handle_session_record(dev, rec, &sessrec); + ok = record_cb(dcr, rec); + if (rec->FileIndex == EOS_LABEL) { Dmsg2(300, "Remove rec. SI=%d ST=%d\n", rec->VolSessionId, - rec->VolSessionTime); - recs->remove(rec); - free_record(rec); - } - continue; - } /* end if label record */ + rec->VolSessionTime); + recs->remove(rec); + free_record(rec); + } + continue; + } /* end if label record */ - /* - * Apply BSR filter - */ - if (jcr->bsr) { - int stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec); - if (stat == -1) { /* no more possible matches */ - done = true; /* all items found, stop */ - Dmsg2(300, "All done=(file:block) %d:%d\n", dev->file, dev->block_num); - break; - } else if (stat == 0) { /* no match */ - Dmsg4(300, "Clear rem=%d FI=%d before set_eof pos %d:%d\n", - rec->remainder, rec->FileIndex, dev->file, dev->block_num); - rec->remainder = 0; - rec->state &= ~REC_PARTIAL_RECORD; - if (try_repositioning(jcr, rec, dev)) { - break; - } + /* + * Apply BSR filter + */ + if (jcr->bsr) { + int stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec); + if (stat == -1) { /* no more possible matches */ + done = true; /* all items found, stop */ + Dmsg2(300, "All done=(file:block) %u:%u\n", dev->file, dev->block_num); + break; + } else if (stat == 0) { /* no match */ + Dmsg4(300, "Clear rem=%d FI=%d before set_eof pos %u:%u\n", + rec->remainder, rec->FileIndex, dev->file, dev->block_num); + rec->remainder = 0; + rec->state &= ~REC_PARTIAL_RECORD; + if (try_repositioning(jcr, rec, dev)) { + break; + } continue; /* we don't want record, read next one */ - } - } - if (is_partial_record(rec)) { + } + } + if (is_partial_record(rec)) { Dmsg6(300, "Partial, break. recno=%d state=%s blk=%d SI=%d ST=%d FI=%d\n", record, - rec_state_to_str(rec), block->BlockNumber, - rec->VolSessionId, rec->VolSessionTime, rec->FileIndex); - break; /* read second part of record */ - } - ok = record_cb(dcr, rec); - if (rec->Stream == STREAM_MD5_SIGNATURE || rec->Stream == STREAM_SHA1_SIGNATURE) { - Dmsg3(300, "Done FI=%d before set_eof pos %d:%d\n", rec->FileIndex, - dev->file, dev->block_num); - if (match_set_eof(jcr->bsr, rec) && try_repositioning(jcr, rec, dev)) { - Dmsg2(300, "Break after match_set_eof pos %d:%d\n", - dev->file, dev->block_num); - break; - } - Dmsg2(300, "After set_eof pos %d:%d\n", dev->file, dev->block_num); - } + rec_state_to_str(rec), block->BlockNumber, + rec->VolSessionId, rec->VolSessionTime, rec->FileIndex); + break; /* read second part of record */ + } + ok = record_cb(dcr, rec); + if (rec->Stream == STREAM_MD5_SIGNATURE || rec->Stream == STREAM_SHA1_SIGNATURE) { + Dmsg3(300, "Done FI=%u before set_eof pos %u:%u\n", rec->FileIndex, + dev->file, dev->block_num); + if (match_set_eof(jcr->bsr, rec) && try_repositioning(jcr, rec, dev)) { + Dmsg2(300, "Break after match_set_eof pos %u:%u\n", + dev->file, dev->block_num); + break; + } + Dmsg2(300, "After set_eof pos %u:%u\n", dev->file, dev->block_num); + } } /* end for loop over records */ - Dmsg2(300, "After end records position=(file:block) %d:%d\n", dev->file, dev->block_num); + Dmsg2(300, "After end records position=(file:block) %u:%u\n", dev->file, dev->block_num); } /* end for loop over blocks */ -// Dmsg2(300, "Position=(file:block) %d:%d\n", dev->file, dev->block_num); +// Dmsg2(300, "Position=(file:block) %u:%u\n", dev->file, dev->block_num); /* Walk down list and free all remaining allocated recs */ while (!recs->empty()) { @@ -255,39 +255,39 @@ bool read_records(DCR *dcr, /* * See if we can reposition. - * Returns: 1 if at end of volume - * 0 otherwise + * Returns: true if at end of volume + * false otherwise */ -static int try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev) +static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev) { BSR *bsr; bsr = find_next_bsr(jcr->bsr, dev); if (bsr == NULL && jcr->bsr->mount_next_volume) { Dmsg0(300, "Would mount next volume here\n"); - Dmsg2(300, "Current postion (file:block) %d:%d\n", - dev->file, dev->block_num); + Dmsg2(300, "Current postion (file:block) %u:%u\n", + dev->file, dev->block_num); jcr->bsr->mount_next_volume = false; if (!dev->at_eot()) { - /* Set EOT flag to force mount of next Volume */ - jcr->mount_next_volume = true; - dev->state |= ST_EOT; + /* Set EOT flag to force mount of next Volume */ + jcr->mount_next_volume = true; + dev->state |= ST_EOT; } rec->Block = 0; - return 1; + return true; } if (bsr) { if (verbose) { - Jmsg(jcr, M_INFO, 0, "Reposition from (file:block) %d:%d to %d:%d\n", - dev->file, dev->block_num, bsr->volfile->sfile, - bsr->volblock->sblock); + Jmsg(jcr, M_INFO, 0, "Reposition from (file:block) %u:%u to %u:%u\n", + dev->file, dev->block_num, bsr->volfile->sfile, + bsr->volblock->sblock); } - Dmsg4(300, "Try_Reposition from (file:block) %d:%d to %d:%d\n", - dev->file, dev->block_num, bsr->volfile->sfile, - bsr->volblock->sblock); + Dmsg4(300, "Try_Reposition from (file:block) %u:%u to %u:%u\n", + dev->file, dev->block_num, bsr->volfile->sfile, + bsr->volblock->sblock); reposition_dev(dev, bsr->volfile->sfile, bsr->volblock->sblock); rec->Block = 0; } - return 0; + return false; } /* @@ -298,17 +298,17 @@ static BSR *position_to_first_file(JCR *jcr, DEVICE *dev) BSR *bsr = NULL; /* * Now find and position to first file and block - * on this tape. + * on this tape. */ if (jcr->bsr) { jcr->bsr->reposition = true; /* force repositioning */ bsr = find_next_bsr(jcr->bsr, dev); if (bsr && (bsr->volfile->sfile != 0 || bsr->volblock->sblock != 0)) { Jmsg(jcr, M_INFO, 0, _("Forward spacing to file:block %u:%u.\n"), - bsr->volfile->sfile, bsr->volblock->sblock); + bsr->volfile->sfile, bsr->volblock->sblock); Dmsg2(300, "Forward spacing to file:block %u:%u.\n", - bsr->volfile->sfile, bsr->volblock->sblock); - reposition_dev(dev, bsr->volfile->sfile, bsr->volblock->sblock); + bsr->volfile->sfile, bsr->volblock->sblock); + reposition_dev(dev, bsr->volfile->sfile, bsr->volblock->sblock); } } return bsr; @@ -345,7 +345,7 @@ static void handle_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *s break; } Dmsg5(300, "%s Record: VolSessionId=%d VolSessionTime=%d JobId=%d DataLen=%d\n", - rtype, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len); + rtype, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len); } #ifdef DEBUG -- 2.39.5