From e778d7aa1d7802f55e2c3e7cae1ff127586c36a2 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 9 Oct 2003 09:58:24 +0000 Subject: [PATCH] Correct return code handling for bsf_dev and bsr_dev git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@737 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 1 + bacula/src/stored/block.c | 8 ++++---- bacula/src/stored/btape.c | 25 +++++++++++-------------- bacula/src/stored/dev.c | 17 ++++++++++++----- bacula/src/stored/read_record.c | 1 + bacula/src/version.h | 8 ++++---- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index c21fbecea0..d563ae8468 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -35,6 +35,7 @@ For 1.33 Testing/Documentation: SuSE. For 1.33 +- Implement .consolerc for Console - I want to restore by file to some date. - Implement fast block rejection. - Is it really important to make Job name the same to find the diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index bbdc478ed6..358ff6ec99 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -491,12 +491,12 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) if (dev->state & ST_TAPE && dev_cap(dev, CAP_BSR)) { /* Now back up over what we wrote and read the last block */ - if (bsf_dev(dev, 1) != 0 || bsf_dev(dev, 1) != 0) { + if (!bsf_dev(dev, 1) || !bsf_dev(dev, 1)) { ok = false; Jmsg(jcr, M_ERROR, 0, _("Backspace file at EOT failed. ERR=%s\n"), strerror(dev->dev_errno)); } /* Backspace over record */ - if (ok && bsr_dev(dev, 1) != 0) { + if (ok && !bsr_dev(dev, 1)) { ok = false; Jmsg(jcr, M_ERROR, 0, _("Backspace record at EOT failed. ERR=%s\n"), strerror(dev->dev_errno)); /* @@ -668,8 +668,8 @@ reread: /* Attempt to reposition to re-read the block */ if (dev->state & ST_TAPE) { Dmsg0(100, "Backspace record for reread.\n"); - if (bsr_dev(dev, 1) != 0) { - Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); + if (!bsr_dev(dev, 1)) { + Jmsg(jcr, M_ERROR, 0, "%s", strerror_dev(dev)); block->read_len = 0; return 0; } diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index d81f177f97..ee3a24a1f3 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -414,7 +414,7 @@ static void weofcmd() static void eomcmd() { if (!eod_dev(dev)) { - Pmsg1(0, _("Bad status from MTEOD. ERR=%s\n"), strerror_dev(dev)); + Pmsg1(0, "%s", strerror_dev(dev)); return; } else { Pmsg0(0, _("Moved to end of medium.\n")); @@ -435,10 +435,9 @@ static void eodcmd() */ static void bsfcmd() { - int stat; - if ((stat=bsf_dev(dev, 1)) < 0) { - Pmsg1(0, _("Bad status from bsf. ERR=%s\n"), strerror(errno)); + if (!bsf_dev(dev, 1)) { + Pmsg1(0, _("Bad status from bsf. ERR=%s\n"), strerror_dev(dev)); } else { Pmsg0(0, _("Backspaced one file.\n")); } @@ -449,10 +448,8 @@ static void bsfcmd() */ static void bsrcmd() { - int stat; - - if ((stat=bsr_dev(dev, 1)) < 0) { - Pmsg1(0, _("Bad status from bsr. ERR=%s\n"), strerror(errno)); + if (!bsr_dev(dev, 1)) { + Pmsg1(0, _("Bad status from bsr. ERR=%s\n"), strerror_dev(dev)); } else { Pmsg0(0, _("Backspaced one record.\n")); } @@ -613,17 +610,17 @@ static int re_read_block_test() } weofcmd(); weofcmd(); - if (bsf_dev(dev, 1) != 0) { - Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror(dev->dev_errno)); + if (!bsf_dev(dev, 1)) { + Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev)); goto bail_out; } - if (bsf_dev(dev, 1) != 0) { - Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror(dev->dev_errno)); + if (!bsf_dev(dev, 1)) { + Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev)); goto bail_out; } Pmsg0(0, "Backspaced over two EOFs OK.\n"); - if (bsr_dev(dev, 1) != 0) { - Pmsg1(0, _("Backspace record failed! ERR=%s\n"), strerror(dev->dev_errno)); + if (!bsr_dev(dev, 1)) { + Pmsg1(0, _("Backspace record failed! ERR=%s\n"), strerror_dev(dev)); goto bail_out; } Pmsg0(0, "Backspace record OK.\n"); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index dfde94eba2..78fe85ef63 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -418,6 +418,9 @@ eod_dev(DEVICE *dev) dev->state |= ST_EOT; return 1; } + dev->dev_errno = errno; + Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"), + dev->dev_name, strerror(dev->dev_errno)); return 0; } #ifdef MTEOM @@ -465,7 +468,7 @@ eod_dev(DEVICE *dev) * the second EOF. */ if (dev_cap(dev, CAP_BSFATEOM)) { - stat = (bsf_dev(dev, 1) == 0); + stat = bsf_dev(dev, 1); dev->file++; /* keep same file */ } else { update_pos_dev(dev); /* update position */ @@ -830,12 +833,14 @@ bsf_dev(DEVICE *dev, int num) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, _("Bad call to bsf_dev. Archive not open\n")); + Mmsg0(&dev->errmsg, _("Bad call to bsf_dev. Archive device not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return 0; } if (!(dev_state(dev, ST_TAPE))) { + Mmsg1(&dev->errmsg, _("Device %s cannot BSF because it is not a tape.\n"), + dev->dev_name); return 0; } Dmsg0(29, "bsf_dev\n"); @@ -1002,7 +1007,7 @@ weof_dev(DEVICE *dev, int num) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, _("Bad call to weof_dev. Archive not open\n")); + Mmsg0(&dev->errmsg, _("Bad call to weof_dev. Archive drive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return -1; } @@ -1021,8 +1026,10 @@ weof_dev(DEVICE *dev, int num) dev->file_addr = 0; } else { clrerror_dev(dev, MTWEOF); - Mmsg2(&dev->errmsg, _("ioctl MTWEOF error on %s. ERR=%s.\n"), - dev->dev_name, strerror(dev->dev_errno)); + if (stat == -1) { + Mmsg2(&dev->errmsg, _("ioctl MTWEOF error on %s. ERR=%s.\n"), + dev->dev_name, strerror(dev->dev_errno)); + } } return stat; } diff --git a/bacula/src/stored/read_record.c b/bacula/src/stored/read_record.c index 9528a920db..7a8b3c26a4 100644 --- a/bacula/src/stored/read_record.c +++ b/bacula/src/stored/read_record.c @@ -115,6 +115,7 @@ int read_records(JCR *jcr, DEVICE *dev, } } Dmsg2(100, "New block at position=(file:block) %d:%d\n", dev->file, dev->block_num); +#define FAST_BLOCK_REJECTION #ifdef FAST_BLOCK_REJECTION /* this does not stop when file/block are too big */ if (!match_bsr_block(jcr->bsr, block)) { diff --git a/bacula/src/version.h b/bacula/src/version.h index 8839fef867..977a839edb 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,12 +1,12 @@ /* */ -#undef VERSION +#undef VERSION #define VERSION "1.32b" #define VSTRING "1" -#define BDATE "08 Oct 2003" -#define LSMDATE "08Oct03" +#define BDATE "09 Oct 2003" +#define LSMDATE "09Oct03" /* Debug flags */ -#undef DEBUG +#undef DEBUG #define DEBUG 1 #define TRACEBACK 1 #define SMCHECK -- 2.39.5