From: Kern Sibbald Date: Sat, 18 Jan 2003 16:09:31 +0000 (+0000) Subject: Allow restore from stream device X-Git-Tag: Release-1.29~14 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6588f39be0deb303610f0a16f743158a2641b50d;p=bacula%2Fbacula Allow restore from stream device git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@306 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 53dfe824ec..43b349ee0f 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -501,10 +501,12 @@ reread: Mmsg1(&dev->errmsg, _("Read zero bytes on device %s.\n"), dev->dev_name); if (dev->state & ST_EOF) { /* EOF alread read? */ dev->state |= ST_EOT; /* yes, 2 EOFs => EOT */ + block->read_len = 0; return 0; } dev->file++; /* increment file */ dev->state |= ST_EOF; /* set EOF read */ + block->read_len = 0; return 0; /* return eof */ } /* Continue here for successful read */ @@ -518,6 +520,7 @@ reread: } if (!unser_block_header(dev, block)) { + block->read_len = 0; return 0; } @@ -536,6 +539,7 @@ reread: Dmsg0(100, "Backspace record for reread.\n"); if (bsf_dev(dev, 1) != 0) { Emsg0(M_ERROR, 0, dev->errmsg); + block->read_len = 0; return 0; } } else { diff --git a/bacula/src/stored/block.h b/bacula/src/stored/block.h index bb9e72a9d9..2ff4cf826b 100644 --- a/bacula/src/stored/block.h +++ b/bacula/src/stored/block.h @@ -93,7 +93,7 @@ typedef struct s_dev_block { uint32_t block_len; /* length of current block read */ uint32_t buf_len; /* max/default block length */ uint32_t BlockNumber; /* sequential block number */ - uint32_t read_len; /* bytes read into buffer */ + uint32_t read_len; /* bytes read into buffer, if zero, block empty */ uint32_t VolSessionId; /* */ uint32_t VolSessionTime; /* */ int BlockVer; /* block version 1 or 2 */ @@ -104,4 +104,6 @@ typedef struct s_dev_block { */ } DEV_BLOCK; +#define block_is_empty(block) !((block)->read_len) + #endif diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 60505c4fe0..87feb01013 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -117,8 +117,11 @@ because:\n %s"), dev_name(dev), strerror_dev(dev)); } free_record(record); - empty_block(block); - rewind_dev(dev); + /* If we are a streaming device, we only get one chance to read */ + if (!dev_cap(dev, CAP_STREAM)) { + empty_block(block); + rewind_dev(dev); + } if (dev->VolHdr.VerNum != BaculaTapeVersion && dev->VolHdr.VerNum != OldCompatibleBaculaTapeVersion1 && diff --git a/bacula/src/stored/read.c b/bacula/src/stored/read.c index 34cbd58d1c..2b020b43ef 100644 --- a/bacula/src/stored/read.c +++ b/bacula/src/stored/read.c @@ -121,7 +121,7 @@ int do_read_data(JCR *jcr) /* Read Record */ Dmsg1(500, "Main read_record. rem=%d\n", rec->remainder); - if (!read_block_from_device(dev, block)) { + if (block_is_empty(block) && !read_block_from_device(dev, block)) { Dmsg1(500, "Main read record failed. rem=%d\n", rec->remainder); if (dev->state & ST_EOT) { DEV_RECORD *record; diff --git a/bacula/src/stored/record.c b/bacula/src/stored/record.c index 9a68849af2..9637493572 100644 --- a/bacula/src/stored/record.c +++ b/bacula/src/stored/record.c @@ -448,6 +448,7 @@ remlen=%d data_len=%d\n", } #endif rec->state |= (REC_NO_HEADER | REC_BLOCK_EMPTY); + empty_block(block); /* mark block empty */ return 0; }