From: Kern Sibbald Date: Sun, 25 May 2003 20:06:35 +0000 (+0000) Subject: Implement Pmsg() and block number checking X-Git-Tag: Release-1.31~114 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=9b55e4750f531be9349e26198c3d0984bd5fcf53;p=bacula%2Fbacula Implement Pmsg() and block number checking git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@542 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index fab141914f..7b242d2c93 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -25,6 +25,14 @@ Testing to do: (painful) - Figure out how to use ssh or stunnel to protect Bacula communications. For 1.31 release: +- If bootstrap is non-zero for restore, do not show JobId in the + OK to run? (yes/mod/no): list. +- If you enter the userid by hand for restore, you get: + Enter JobId(s), comma separated, to restore: 74 + You have selected the following JobId: 74 + Building directory tree for JobId 74 ... + 134645140 items inserted into the tree and marked for extraction. + - The bsr for Dan's job has file indexes covering the whole range rather than only the range contained on the volume. Constrain FileIndex to be within range for Volume. diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index ee58dbf3c0..94652b6dd8 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -283,21 +283,21 @@ extern void _v(char *file, int line, pthread_mutex_t *m); /* Messages that are printed (uses d_msg) */ -#define Pmsg0(lvl, msg) d_msg(__FILE__, __LINE__, lvl, msg) -#define Pmsg1(lvl, msg, a1) d_msg(__FILE__, __LINE__, lvl, msg, a1) -#define Pmsg2(lvl, msg, a1, a2) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2) -#define Pmsg3(lvl, msg, a1, a2, a3) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3) -#define Pmsg4(lvl, msg, arg1, arg2, arg3, arg4) d_msg(__FILE__, __LINE__, lvl, msg, arg1, arg2, arg3, arg4) -#define Pmsg5(lvl, msg, a1, a2, a3, a4, a5) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5) -#define Pmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6) -#define Pmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7) -#define Pmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) -#define Pmsg9(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9) -#define Pmsg10(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) -#define Pmsg11(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) -#define Pmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) -#define Pmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) -#define Pmsg14(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14) +#define Pmsg0(lvl, msg) p_msg(__FILE__, __LINE__, lvl, msg) +#define Pmsg1(lvl, msg, a1) p_msg(__FILE__, __LINE__, lvl, msg, a1) +#define Pmsg2(lvl, msg, a1, a2) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2) +#define Pmsg3(lvl, msg, a1, a2, a3) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3) +#define Pmsg4(lvl, msg, arg1, arg2, arg3, arg4) p_msg(__FILE__, __LINE__, lvl, msg, arg1, arg2, arg3, arg4) +#define Pmsg5(lvl, msg, a1, a2, a3, a4, a5) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5) +#define Pmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6) +#define Pmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7) +#define Pmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) +#define Pmsg9(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9) +#define Pmsg10(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) +#define Pmsg11(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) +#define Pmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) +#define Pmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) +#define Pmsg14(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14) /* Daemon Error Messages that are delivered according to the message resource */ @@ -338,6 +338,7 @@ int Mmsg(char **msgbuf, char *fmt,...); struct JCR; void d_msg(char *file, int line, int level, char *fmt,...); +void p_msg(char *file, int line, int level, char *fmt,...); void e_msg(char *file, int line, int type, int level, char *fmt,...); void j_msg(char *file, int line, JCR *jcr, int type, int level, char *fmt,...); int m_msg(char *file, int line, char **msgbuf, char *fmt,...); diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 05ea500846..80676ef253 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -677,7 +677,7 @@ void dispatch_message(JCR *jcr, int type, int level, char *msg) /********************************************************************* * - * subroutine prints a debug message if the level number + * This subroutine prints a debug message if the level number * is less than or equal the debug_level. File and line numbers * are included for more detail if desired, but not currently * printed. @@ -695,8 +695,7 @@ d_msg(char *file, int line, int level, char *fmt,...) if (level < 0) { details = FALSE; -// level = -level; - level = 0; + level = -level; } if (level <= debug_level) { @@ -712,7 +711,7 @@ d_msg(char *file, int line, int level, char *fmt,...) #endif #ifdef FULL_LOCATION if (details) { - len= sprintf(buf, "%s: %s:%d ", my_name, file, line); + len = sprintf(buf, "%s: %s:%d ", my_name, file, line); } else { len = 0; } @@ -733,6 +732,36 @@ d_msg(char *file, int line, int level, char *fmt,...) } +/********************************************************************* + * + * This subroutine prints a message regardless of the debug level + * + * If the level is negative, the details of file and line number + * are not printed. + */ +void +p_msg(char *file, int line, int level, char *fmt,...) +{ + char buf[5000]; + int len; + va_list arg_ptr; + +#ifdef FULL_LOCATION + if (level >= 0) { + len = sprintf(buf, "%s: %s:%d ", my_name, file, line); + } else { + len = 0; + } +#else + len = 0; +#endif + va_start(arg_ptr, fmt); + bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr); + va_end(arg_ptr); + fputs(buf, stdout); +} + + /********************************************************************* * * subroutine writes a debug message to the trace file if the level number diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index bace8368a2..77aa363f07 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -441,7 +441,7 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) if (ok) { DEV_BLOCK *lblock = new_block(dev); /* Note, this can destroy dev->errmsg */ - if (!read_block_from_dev(jcr, dev, lblock)) { + if (!read_block_from_dev(jcr, dev, lblock, NO_BLOCK_NUMBER_CHECK)) { Jmsg(jcr, M_ERROR, 0, _("Re-read last block at EOT failed. ERR=%s"), dev->errmsg); } else { if (lblock->BlockNumber+1 == block->BlockNumber) { @@ -477,12 +477,12 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) * Read block with locking * */ -int read_block_from_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) +int read_block_from_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_block_numbers) { int stat; Dmsg0(90, "Enter read_block_from_device\n"); lock_device(dev); - stat = read_block_from_dev(jcr, dev, block); + stat = read_block_from_dev(jcr, dev, block, check_block_numbers); unlock_device(dev); Dmsg0(90, "Leave read_block_from_device\n"); return stat; @@ -493,10 +493,11 @@ int read_block_from_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) * the block header. For a file, the block may be partially * or completely in the current buffer. */ -int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) +int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_block_numbers) { ssize_t stat; int looping; + uint32_t BlockNumber; looping = 0; Dmsg1(100, "Full read() in read_block_from_device() len=%d\n", @@ -543,11 +544,21 @@ reread: return 0; /* return error */ } + BlockNumber = block->BlockNumber + 1; if (!unser_block_header(dev, block)) { block->read_len = 0; return 0; } +#ifdef somehow_working + if (check_block_numbers) { + if (BlockNumber != block->BlockNumber) { + Jmsg(jcr, M_ERROR, 0, _("Incorrect block sequence number. Expected %u, got %u\n"), + BlockNumber, block->BlockNumber); + } + } +#endif + /* * If the block is bigger than the buffer, we reposition for * re-reading the block, allocate a buffer of the correct size, diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 6166a501c8..1784f6c454 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -235,7 +235,7 @@ static void do_blocks(char *infname) rec = new_record(); } for ( ;; ) { - if (!read_block_from_device(jcr, dev, block)) { + if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev)); if (dev->state & ST_EOT) { if (!mount_next_read_volume(jcr, dev, block)) { @@ -244,7 +244,7 @@ static void do_blocks(char *infname) } DEV_RECORD *record; record = new_record(); - read_block_from_device(jcr, dev, block); + read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK); read_record_from_block(block, record); get_session_record(dev, record, &sessrec); free_record(record); diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index cdd2ab9a9e..c46b5626dc 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -634,7 +634,7 @@ static int re_read_block_test() goto bail_out; } Pmsg0(0, "Backspace record OK.\n"); - if (!read_block_from_dev(jcr, dev, block)) { + if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno)); goto bail_out; } @@ -982,7 +982,7 @@ static void scan_blocks() update_pos_dev(dev); tot_files = dev->file; for (;;) { - if (!read_block_from_device(jcr, dev, block)) { + if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev)); if (dev->state & ST_EOT) { if (blocks > 0) { @@ -1313,7 +1313,7 @@ static void unfillcmd() last_file); Pmsg1(-1, _("Now reading to block %u.\n"), last_block_num); for (uint32_t i= 0; i < last_block_num; i++) { - if (!read_block_from_device(jcr, dev, block)) { + if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { Pmsg1(-1, _("Error reading blocks: ERR=%s\n"), strerror_dev(dev)); Pmsg2(-1, _("Wanted block %u error at block %u\n"), last_block_num, i); goto bail_out; diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 259c186950..091382b6da 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -521,7 +521,7 @@ status_dev(DEVICE *dev, uint32_t *status) if (dev->state & (ST_EOT | ST_WEOT)) { stat |= BMT_EOD; - Dmsg0(-20, " EOD-"); + Dmsg0(-20, " EOD"); } if (dev->state & ST_EOF) { stat |= BMT_EOF; @@ -558,7 +558,7 @@ status_dev(DEVICE *dev, uint32_t *status) } if (GMT_EOD(mt_stat.mt_gstat)) { stat |= BMT_EOD; - Dmsg0(-20, " EOD+"); + Dmsg0(-20, " EOD"); } if (GMT_WR_PROT(mt_stat.mt_gstat)) { stat |= BMT_WR_PROT; diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index ec936ea22b..74ea5157b2 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -92,10 +92,10 @@ int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) } strcpy(dev->VolHdr.Id, "**error**"); - /* Read the device label block */ + /* Read the Volume label block */ record = new_record(); Dmsg0(90, "Big if statement in read_volume_label\n"); - if (!read_block_from_dev(jcr, dev, block)) { + if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { Mmsg(&jcr->errmsg, _("Volume on %s is not a Bacula labeled Volume, \ because:\n %s"), dev_name(dev), strerror_dev(dev)); } else if (!read_record_from_block(block, record)) { diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 7d01baebce..6a95c82c9e 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -54,8 +54,11 @@ 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(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); -int read_block_from_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); -int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); + +#define CHECK_BLOCK_NUMBERS true +#define NO_BLOCK_NUMBER_CHECK false +int read_block_from_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_block_numbers); +int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_block_numbers); /* From butil.c -- utilities for SD tool programs */ void print_ls_output(char *fname, char *link, int type, struct stat *statp); diff --git a/bacula/src/stored/read.c b/bacula/src/stored/read.c index 216a3e2bf1..2659d99d86 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 (block_is_empty(block) && !read_block_from_device(jcr, dev, block)) { + if (block_is_empty(block) && !read_block_from_device(jcr, dev, block, CHECK_BLOCK_NUMBERS)) { Dmsg1(500, "Main read record failed. rem=%d\n", rec->remainder); if (dev->state & ST_EOT) { DEV_RECORD *record; @@ -129,7 +129,7 @@ int do_read_data(JCR *jcr) break; } record = new_record(); - read_block_from_device(jcr, dev, block); + read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK); read_record_from_block(block, record); get_session_record(dev, record, &sessrec); free_record(record); diff --git a/bacula/src/stored/read_record.c b/bacula/src/stored/read_record.c index 6ee833fef7..46721bb18e 100644 --- a/bacula/src/stored/read_record.c +++ b/bacula/src/stored/read_record.c @@ -6,6 +6,8 @@ * as well as a callback for mounting the next tape. It takes * care of reading blocks, applying the bsr, ... * + * Kern E. Sibbald, August MMII + * * Version $Id$ */ /* @@ -54,7 +56,7 @@ int read_records(JCR *jcr, DEVICE *dev, ok = FALSE; break; } - if (!read_block_from_device(jcr, dev, block)) { + if (!read_block_from_device(jcr, dev, block, CHECK_BLOCK_NUMBERS)) { Dmsg0(20, "!read_record()\n"); if (dev->state & ST_EOT) { DEV_RECORD *trec = new_record(); @@ -84,7 +86,7 @@ int read_records(JCR *jcr, DEVICE *dev, * and pass it off to the callback routine, then continue * most likely reading the previous record. */ - read_block_from_device(jcr, dev, block); + read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK); read_record_from_block(block, trec); get_session_record(dev, trec, &sessrec); record_cb(jcr, dev, block, trec);