From 65e5b5ac6dc5e85849f39292e6233a2bcbe2c7dd Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 4 Sep 2009 15:46:33 +0200 Subject: [PATCH] Implement BlockChecksum in Device --- bacula/src/stored/block.c | 12 +++++++----- bacula/src/stored/dev.h | 2 ++ bacula/src/stored/stored_conf.c | 3 +-- bacula/src/version.h | 4 ++-- bacula/technotes | 3 +++ 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index abb53c25c3..7899621399 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -189,7 +189,7 @@ void empty_block(DEV_BLOCK *block) * in the buffer should have already been reserved by * init_block. */ -void ser_block_header(DEV_BLOCK *block) +static void ser_block_header(DEV_BLOCK *block, bool do_checksum) { ser_declare; uint32_t CheckSum = 0; @@ -207,8 +207,10 @@ void ser_block_header(DEV_BLOCK *block) } /* Checksum whole block except for the checksum */ - CheckSum = bcrc32((uint8_t *)block->buf+BLKHDR_CS_LENGTH, - block_len-BLKHDR_CS_LENGTH); + if (do_checksum) { + CheckSum = bcrc32((uint8_t *)block->buf+BLKHDR_CS_LENGTH, + block_len-BLKHDR_CS_LENGTH); + } Dmsg1(1390, "ser_bloc_header: checksum=%x\n", CheckSum); ser_begin(block->buf, BLKHDR2_LENGTH); ser_uint32(CheckSum); /* now add checksum to block header */ @@ -307,7 +309,7 @@ static bool unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) block->BlockNumber = BlockNumber; Dmsg3(390, "Read binbuf = %d %d block_len=%d\n", block->binbuf, bhl, block_len); - if (block_len <= block->read_len) { + if (block_len <= block->read_len && dev->do_checksum()) { BlockCheckSum = bcrc32((uint8_t *)block->buf+BLKHDR_CS_LENGTH, block_len-BLKHDR_CS_LENGTH); if (BlockCheckSum != CheckSum) { @@ -466,7 +468,7 @@ bool write_block_to_dev(DCR *dcr) } } - ser_block_header(block); + ser_block_header(block, dev->do_checksum()); /* Limit maximum Volume size to value specified by user */ hit_max1 = (dev->max_volume_size > 0) && diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 22734bb805..f77c18f0d3 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -136,6 +136,7 @@ enum { #define CAP_MTIOCGET (1<<20) /* Basic support for fileno and blkno */ #define CAP_REQMOUNT (1<<21) /* Require mount to read files back (typically: DVD) */ #define CAP_CHECKLABELS (1<<22) /* Check for ANSI/IBM labels */ +#define CAP_BLOCKCHECKSUM (1<<23) /* Create/test block checksum */ /* Test state */ #define dev_state(dev, st_state) ((dev)->state & (st_state)) @@ -307,6 +308,7 @@ public: int has_cap(int cap) const { return capabilities & cap; } void clear_cap(int cap) { capabilities &= ~cap; } void set_cap(int cap) { capabilities |= cap; } + bool do_checksum() const { return (capabilities & CAP_BLOCKCHECKSUM) != 0; } int is_autochanger() const { return capabilities & CAP_AUTOCHANGER; } int requires_mount() const { return capabilities & CAP_REQMOUNT; } int is_removable() const { return capabilities & CAP_REM; } diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index 19bfec3720..a2080234a8 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -29,8 +29,6 @@ * Configuration file parser for Bacula Storage daemon * * Kern Sibbald, March MM - * - * Version $Id$ */ #include "bacula.h" @@ -142,6 +140,7 @@ static RES_ITEM dev_items[] = { {"checklabels", store_bit, ITEM(res_dev.cap_bits), CAP_CHECKLABELS, ITEM_DEFAULT, 0}, {"requiresmount", store_bit, ITEM(res_dev.cap_bits), CAP_REQMOUNT, ITEM_DEFAULT, 0}, {"offlineonunmount", store_bit, ITEM(res_dev.cap_bits), CAP_OFFLINEUNMOUNT, ITEM_DEFAULT, 0}, + {"blockchecksum", store_bit, ITEM(res_dev.cap_bits), CAP_BLOCKCHECKSUM, ITEM_DEFAULT, 1}, {"autoselect", store_bool, ITEM(res_dev.autoselect), 1, ITEM_DEFAULT, 1}, {"changerdevice", store_strname,ITEM(res_dev.changer_name), 0, 0, 0}, {"changercommand", store_strname,ITEM(res_dev.changer_command), 0, 0, 0}, diff --git a/bacula/src/version.h b/bacula/src/version.h index 2dcac1e48c..faa1016baa 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "3.0.3" -#define BDATE "28 August 2009" -#define LSMDATE "28Aug09" +#define BDATE "04 September 2009" +#define LSMDATE "04Sep09" #define PROG_COPYRIGHT "Copyright (C) %d-2009 Free Software Foundation Europe e.V.\n" #define BYEAR "2009" /* year for copyright messages in progs */ diff --git a/bacula/technotes b/bacula/technotes index fc0fe514cc..bd61638160 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -2,6 +2,9 @@ General: +04Sep09 +kes Implement BlockChecksum in Device to be able to turn off checksum + for performance reasons 03Sep09 ebl Use MaxFileSize device configuration in btape ebl Make less tweaks in random buffer in btape -- 2.39.5