From 1cebc19414d2f92d52a140a02544b6db2817ae58 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 9 Dec 2002 17:18:09 +0000 Subject: [PATCH] Doc + last block check + seg fault fix in btape git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@235 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/ua_select.c | 3 --- bacula/src/stored/block.c | 53 ++++++++++++++++++++++++++++++++++--- bacula/src/stored/btape.c | 4 +-- bacula/src/stored/device.c | 4 +-- bacula/src/stored/label.c | 2 +- bacula/src/stored/mount.c | 4 ++- bacula/src/stored/protos.h | 2 +- bacula/src/version.h | 4 +-- 8 files changed, 60 insertions(+), 16 deletions(-) diff --git a/bacula/src/dird/ua_select.c b/bacula/src/dird/ua_select.c index 25aaa746c1..5b15d69f68 100644 --- a/bacula/src/dird/ua_select.c +++ b/bacula/src/dird/ua_select.c @@ -555,9 +555,6 @@ int get_job_dbr(UAContext *ua, JOB_DBR *jr) return jr->JobId; } - - - /* * Implement unique set of prompts */ diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index c28a7b944d..17dd3b7f70 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -275,7 +275,7 @@ int write_block_to_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) { int stat = 1; lock_device(dev); - if (!write_block_to_dev(dev, block)) { + if (!write_block_to_dev(jcr, dev, block)) { stat = fixup_device_block_write_error(jcr, dev, block); } unlock_device(dev); @@ -288,11 +288,12 @@ int write_block_to_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) * Returns: 1 on success or EOT * 0 on hard error */ -int write_block_to_dev(DEVICE *dev, DEV_BLOCK *block) +int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) { size_t stat = 0; uint32_t wlen; /* length to write */ int hit_max1, hit_max2; + int ok; #ifdef NO_TAPE_WRITE_TEST empty_block(block); @@ -354,7 +355,6 @@ int write_block_to_dev(DEVICE *dev, DEV_BLOCK *block) edit_uint64(dev->VolCatInfo.VolCatMaxBytes, ed1), dev->dev_name); } block->failed_write = TRUE; -/* ****FIXME**** write EOD record here */ weof_dev(dev, 1); /* end the tape */ weof_dev(dev, 1); /* write second eof */ return 0; @@ -370,7 +370,6 @@ int write_block_to_dev(DEVICE *dev, DEV_BLOCK *block) * conditions. In any case, we probably want to * simulate an End of Medium. */ -/***FIXME**** if we wrote a partial record, back up over it */ dev->state |= ST_EOF | ST_EOT | ST_WEOT; clrerror_dev(dev, -1); @@ -386,6 +385,52 @@ int write_block_to_dev(DEVICE *dev, DEV_BLOCK *block) block->failed_write = TRUE; weof_dev(dev, 1); /* end the tape */ weof_dev(dev, 1); /* write second eof */ + + ok = TRUE; +#define CHECK_LAST_BLOCK +#ifdef CHECK_LAST_BLOCK + /* + * If the device is a tape and it supports backspace record, + * we backspace over two eof marks and over the last record, + * then re-read it and verify that the block number is + * correct. + */ + if (dev->state & ST_TAPE && dev->capabilities & CAP_BSR) { + uint32_t file, block_num; + + file = dev->file; + block_num = dev->block_num; + + /* Now back up over what we wrote and read the last block */ + if (bsf_dev(dev, 1) != 0 || bsf_dev(dev, 1) != 0) { + ok = FALSE; + Jmsg(jcr, M_ERROR, 0, _("Back space file at EOT failed. ERR=%s\n"), strerror(dev->dev_errno)); + } + /* Backspace over record */ + if (ok && bsr_dev(dev, 1) != 0) { + ok = FALSE; + Jmsg(jcr, M_ERROR, 0, _("Back space record at EOT failed. ERR=%s\n"), strerror(dev->dev_errno)); + } + if (ok) { + DEV_BLOCK *lblock = new_block(dev); + /* Note, this can destroy dev->errmsg */ + if (!read_block_from_dev(dev, lblock)) { + Jmsg(jcr, M_ERROR, 0, _("Re-read last block at EOT failed. ERR=%s"), dev->errmsg); + } else { + if (lblock->BlockNumber+1 == block->BlockNumber) { + Jmsg(jcr, M_INFO, 0, _("Re-read of last block succeeded.\n")); + } else { + Jmsg(jcr, M_ERROR, 0, _( +"Re-read of last block failed. Last block=%u Current block=%u.\n"), + lblock->BlockNumber, block->BlockNumber); + } + } + free_block(lblock); + } + dev->file = file; + dev->block_num = block_num; + } +#endif return 0; } dev->VolCatInfo.VolCatBytes += block->binbuf; diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 28f769700c..bb8e3c51b8 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -655,7 +655,7 @@ static void wrcmd() Pmsg0(0, "Error writing record to block.\n"); goto bail_out; } - if (!write_block_to_dev(dev, block)) { + if (!write_block_to_dev(jcr, dev, block)) { Pmsg0(0, "Error writing block to device.\n"); goto bail_out; } else { @@ -1067,7 +1067,7 @@ static int flush_block(DEV_BLOCK *block, int dump) { char ec1[50]; lock_device(dev); - if (!write_block_to_dev(dev, block)) { + if (!write_block_to_dev(jcr, dev, block)) { Pmsg0(000, strerror_dev(dev)); Pmsg3(000, "Block not written: FileIndex=%u Block=%u Size=%u\n", (unsigned)file_index, block->BlockNumber, block->block_len); diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 794c321786..671748d4af 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -147,7 +147,7 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) * empty label_blk, and nothing will be written. */ Dmsg0(190, "write label block to dev\n"); - if (!write_block_to_dev(dev, label_blk)) { + if (!write_block_to_dev(jcr, dev, label_blk)) { Pmsg1(0, "write_block_to_device Volume label failed. ERR=%s", strerror_dev(dev)); free_block(label_blk); @@ -157,7 +157,7 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) /* Write overflow block to tape */ Dmsg0(190, "Write overflow block to dev\n"); - if (!write_block_to_dev(dev, block)) { + if (!write_block_to_dev(jcr, dev, block)) { Pmsg1(0, "write_block_to_device overflow block failed. ERR=%s", strerror_dev(dev)); free_block(label_blk); diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index df37be4018..4a2ab8bb6f 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -414,7 +414,7 @@ int write_volume_label_to_dev(JCR *jcr, DEVRES *device, char *VolName, char *Poo free_pool_memory(rec.data); Dmsg0(99, "Call write_block_to_device()\n"); - if (!write_block_to_dev(dev, block)) { + if (!write_block_to_dev(jcr, dev, block)) { Dmsg2(30, "Bad Label write on %s. ERR=%s\n", dev_name(dev), strerror_dev(dev)); stat = 9; } diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 1a88f1ea7d..31d3add420 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -249,7 +249,8 @@ mount_error: dev_name(dev), strerror_dev(dev)); } } - if (!write_block_to_dev(dev, block)) { + /* Attempt write to check write permission */ + if (!write_block_to_dev(jcr, dev, block)) { Jmsg2(jcr, M_ERROR, 0, _("Unable to write device %s. ERR=%s\n"), dev_name(dev), strerror_dev(dev)); goto mount_next_vol; @@ -259,6 +260,7 @@ mount_error: dev_name(dev), strerror_dev(dev)); goto mount_next_vol; } + /* Recreate a correct volume label and return it in the block */ write_volume_label_to_block(jcr, dev, block); /* Set or reset Volume statistics */ diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 2cd5c18202..bbd11998e5 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -53,7 +53,7 @@ void init_block_write(DEV_BLOCK *block); void empty_block(DEV_BLOCK *block); void free_block(DEV_BLOCK *block); int write_block_to_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); -int write_block_to_dev(DEVICE *dev, DEV_BLOCK *block); +int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); int read_block_from_device(DEVICE *dev, DEV_BLOCK *block); int read_block_from_dev(DEVICE *dev, DEV_BLOCK *block); diff --git a/bacula/src/version.h b/bacula/src/version.h index 3846672ee1..90d59c97bc 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.28" #define VSTRING "1" -#define DATE "4 December 2002" -#define LSMDATE "04Dec02" +#define DATE "9 December 2002" +#define LSMDATE "09Dec02" /* Debug flags */ #define DEBUG 1 -- 2.39.5