From f688630cf8bcc2f347e0d1f5da599c4e52c87d09 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 26 May 2003 16:18:23 +0000 Subject: [PATCH] Fix reading second volume git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@549 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/block.c | 6 +++- bacula/src/stored/bls.c | 15 ++++----- bacula/src/stored/read.c | 56 +++++++++++++++++---------------- bacula/src/stored/read_record.c | 18 +++++------ 4 files changed, 51 insertions(+), 44 deletions(-) diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 5e81ce5b87..a7ca9e0980 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -498,6 +498,7 @@ int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_bloc ssize_t stat; int looping; uint32_t BlockNumber; + int retry = 0; looping = 0; Dmsg1(100, "Full read() in read_block_from_device() len=%d\n", @@ -510,7 +511,10 @@ reread: block->read_len = 0; return 0; } - if ((stat=read(dev->fd, block->buf, (size_t)block->buf_len)) < 0) { + do { + stat = read(dev->fd, block->buf, (size_t)block->buf_len); + } while (stat == -1 && (errno == EINTR || errno == EIO) && retry++ < 6); + if (stat < 0) { Dmsg1(90, "Read device got: ERR=%s\n", strerror(errno)); clrerror_dev(dev, -1); block->read_len = 0; diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 7a33c3b1f7..cdb642de8e 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -242,6 +242,7 @@ static void do_blocks(char *infname) printf("End of File on device\n"); break; } + /* Read and discard Volume label */ DEV_RECORD *record; record = new_record(); read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK); @@ -249,19 +250,19 @@ static void do_blocks(char *infname) get_session_record(dev, record, &sessrec); free_record(record); printf("Volume %s mounted.\n", jcr->VolumeName); - continue; - } - if (dev->state & ST_EOF) { + + } else if (dev->state & ST_EOF) { Jmsg(jcr, M_INFO, 0, "Got EOF on device %s\n", dev_name(dev)); Dmsg0(20, "read_record got eof. try again\n"); continue; - } - if (dev->state & ST_SHORT) { + } else if (dev->state & ST_SHORT) { Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg); continue; + } else { + /* I/O error */ + display_tape_error_status(jcr, dev); + break; } - display_tape_error_status(jcr, dev); - break; } Dmsg5(100, "Blk=%u blen=%u bVer=%d SessId=%u SessTim=%u\n", block->BlockNumber, block->block_len, block->BlockVer, diff --git a/bacula/src/stored/read.c b/bacula/src/stored/read.c index b26cf7d00a..332125d7dd 100644 --- a/bacula/src/stored/read.c +++ b/bacula/src/stored/read.c @@ -134,17 +134,19 @@ int do_read_data(JCR *jcr) read_record_from_block(block, record); get_session_record(dev, record, &sessrec); free_record(record); - } - if (dev->state & ST_EOF) { + /* Now, continue to read the records on this volume */ + + } else if (dev->state & ST_EOF) { Dmsg0(90, "Got End of File. Trying again ...\n"); continue; /* End of File */ - } - if (dev->state & ST_SHORT) { + } else if (dev->state & ST_SHORT) { continue; + } else { + /* I/O error -- or non-standard end of tape */ + Dmsg0(000, "I/O error, bailing out.\n"); + ok = FALSE; + break; } - /* I/O error -- or non-standard end of tape */ - ok = FALSE; - break; } for (rec->state=0; !is_block_empty(rec); ) { @@ -253,26 +255,26 @@ static void get_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sess char *rtype; memset(sessrec, 0, sizeof(sessrec)); switch (rec->FileIndex) { - case PRE_LABEL: - rtype = "Fresh Volume Label"; - break; - case VOL_LABEL: - rtype = "Volume Label"; - unser_volume_label(dev, rec); - break; - case SOS_LABEL: - rtype = "Begin Session"; - unser_session_label(sessrec, rec); - break; - case EOS_LABEL: - rtype = "End Session"; - break; - case EOM_LABEL: - rtype = "End of Media"; - break; - default: - rtype = "Unknown"; - break; + case PRE_LABEL: + rtype = "Fresh Volume Label"; + break; + case VOL_LABEL: + rtype = "Volume Label"; + unser_volume_label(dev, rec); + break; + case SOS_LABEL: + rtype = "Begin Session"; + unser_session_label(sessrec, rec); + break; + case EOS_LABEL: + rtype = "End Session"; + break; + case EOM_LABEL: + rtype = "End of Media"; + break; + default: + rtype = "Unknown"; + break; } Dmsg5(10, "%s Record: VolSessionId=%d VolSessionTime=%d JobId=%d DataLen=%d\n", rtype, rec->VolSessionId, rec->VolSessionTime, rec->Stream, rec->data_len); diff --git a/bacula/src/stored/read_record.c b/bacula/src/stored/read_record.c index ed1ed3f5f5..323b05d918 100644 --- a/bacula/src/stored/read_record.c +++ b/bacula/src/stored/read_record.c @@ -91,22 +91,22 @@ int read_records(JCR *jcr, DEVICE *dev, get_session_record(dev, trec, &sessrec); record_cb(jcr, dev, block, trec); free_record(trec); - goto next_record; - } - if (dev->state & ST_EOF) { + goto next_record; /* go read new tape */ + + } else if (dev->state & ST_EOF) { Jmsg(jcr, M_INFO, 0, "Got EOF on device %s, Volume \"%s\"\n", dev_name(dev), jcr->VolumeName); Dmsg0(20, "read_record got eof. try again\n"); continue; - } - if (dev->state & ST_SHORT) { + } else if (dev->state & ST_SHORT) { Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg); continue; + } else { + /* I/O error or strange end of tape */ + display_tape_error_status(jcr, dev); + ok = FALSE; + break; } - /* I/O error or strange end of tape */ - display_tape_error_status(jcr, dev); - ok = FALSE; - break; } if (verbose) { Dmsg2(10, "Block: %d blen=%d\n", block->BlockNumber, block->block_len); -- 2.39.5