]> git.sur5r.net Git - bacula/bacula/commitdiff
Implement Pmsg() and block number checking
authorKern Sibbald <kern@sibbald.com>
Sun, 25 May 2003 20:06:35 +0000 (20:06 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 25 May 2003 20:06:35 +0000 (20:06 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@542 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kernstodo
bacula/src/baconfig.h
bacula/src/lib/message.c
bacula/src/stored/block.c
bacula/src/stored/bls.c
bacula/src/stored/btape.c
bacula/src/stored/dev.c
bacula/src/stored/label.c
bacula/src/stored/protos.h
bacula/src/stored/read.c
bacula/src/stored/read_record.c

index fab141914f1c7f70aba18487c37c67c9631125ae..7b242d2c939b22706783acf7497dd01e454b48b1 100644 (file)
@@ -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.
index ee58dbf3c028c52f18269f4f5b73e96219c5ba42..94652b6dd872ab540f01364347e8af9e99828170 100644 (file)
@@ -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,...);
index 05ea5008461773491c82d9aa3d5213f4af505c2a..80676ef253e4950c73c5e731215ab7aba451c300 100755 (executable)
@@ -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
index bace8368a2e68b6930c5bedeb801ea270457962c..77aa363f070558641df8d0bf30bb4a7140749583 100644 (file)
@@ -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,
index 6166a501c825514a41a51c3377b777a1cfb2a304..1784f6c4541d55e0d8ab7f6661d7b89acebb3668 100644 (file)
@@ -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);
index cdd2ab9a9e31a3c1fe35e0bf135f5d03c33a818c..c46b5626dc5dd8cb590cba3174473fa1e6401af8 100644 (file)
@@ -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;
index 259c1869501f5801edb351f63a20f179a1929d1d..091382b6da2424e1d9d744c2e4079424726d9505 100644 (file)
@@ -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;
index ec936ea22b2d679a35b724d85890ceb54aea128c..74ea5157b2d3d8653f208a3458c8894c07e43f02 100644 (file)
@@ -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)) {
index 7d01baebce39f1fada6c26cec1f3aa8021070e0c..6a95c82c9e4f929d4d99349f543be7b8cdfb2c1b 100644 (file)
@@ -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);
index 216a3e2bf1b9ffa1f73c32143c3585055760b1c8..2659d99d866f91498d41380cb7a40471f9199ade 100644 (file)
@@ -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);
index 6ee833fef7e42fd67f2cbb6e2129f92d52cb6a60..46721bb18ee1250ba5fc45aa888e9958b9c5fbe2 100644 (file)
@@ -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);