add support for multiple csum algorithms
PATCH 1/1 add support for multiple csum algorithms
Hello,
This patch gives us the space we will need in order to have different csum algorithims at some point in the future. We save the csum algorithim type and the sectorsize in the superblock, and use those instead of define's. Tested with fs_mark to fill the entire disk, and then tar czf /dev/null ./ in the root dir of the fs. Thank you,
Signed-off-by Josef Bacik <[email protected]>
fs/btrfs/ctree.h +11 -1
@@ -109,8 +109,12 @@ struct btrfs_ordered_sum;/* 32 bytes in various csum fields */ #define BTRFS_CSUM_SIZE 32 + +/* csum types */ +#define BTRFS_CSUM_TYPE_CRC32 0 +/* four bytes for CRC32 */ -#define BTRFS_CRC32_SIZE 4 +//#define BTRFS_CRC32_SIZE 4 #define BTRFS_EMPTY_DIR_SIZE 0#define BTRFS_FT_UNKNOWN 0
@@ -308,6 +312,8 @@ struct btrfs_super_block {__le64 compat_flags;__le64 compat_ro_flags;__le64 incompat_flags; +__le16 csum_type; +__le16 csum_sectorsize;u8 root_level;u8 chunk_root_level;u8 log_root_level;
@@ -1524,6 +1530,10 @@ BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, compat_flags, 64); BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, incompat_flags,64 ); +BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, + csum_type,16 ); +BTRFS_SETGET_STACK_FUNCS(super_csum_sectorsize, struct btrfs_super_block, + csum_sectorsize,16 );static inline unsigned long btrfs_leaf_data (struct extent_buffer *l) {
fs/btrfs/disk-io.c +13 -5
@@ -175,7 +175,9 @@ void btrfs_csum_final(u32 crc, char *result)static int csum_tree_block (struct btrfs_root *root,struct extent_buffer *buf,int verify) { -char result[BTRFS_CRC32_SIZE ]; +u16 csum_sectorsize = +btrfs_super_csum_sectorsize (&root->fs_info->super_copy); +char *result;unsigned long len;unsigned long cur_len;unsigned long offset =BTRFS_CSUM_SIZE ;
@@ -203,25 +205,31 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, offset += cur_len;unmap_extent_buffer (buf, map_token,KM_USER0 ); } + result =kzalloc (csum_sectorsize *sizeof (char ),GFP_NOFS ); +if (!result) +return 1 ; +btrfs_csum_final (crc, result);if (verify) {/* FIXME, this is not good */ -if (memcmp_extent_buffer (buf, result,0 ,BTRFS_CRC32_SIZE )) { +if (memcmp_extent_buffer (buf, result,0 , csum_sectorsize)) {u32 val;u32 found =0 ; -memcpy (&found, result,BTRFS_CRC32_SIZE ); +memcpy (&found, result, csum_sectorsize); -read_extent_buffer (buf, &val,0 ,BTRFS_CRC32_SIZE ); +read_extent_buffer (buf, &val,0 , csum_sectorsize);printk ("btrfs: %s checksum verify failed on %llu " "wanted %X found %X level %d\n" , root->fs_info->sb->s_id, buf->start, val, found,btrfs_header_level (buf)); +kfree (result);return 1 ; } }else { -write_extent_buffer (buf, result,0 ,BTRFS_CRC32_SIZE ); +write_extent_buffer (buf, result,0 , csum_sectorsize); } +kfree (result);return 0 ; }
fs/btrfs/file-item.c +32 -24
174 lines not on this page · raw message
fs/btrfs/ioctl.c +5 -4
@@ -713,7 +713,8 @@ long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, u64 off,u64 len = olen;u64 bs = root->fs_info->sb->s_blocksize;u64 hint_byte; - +u16 csum_sectorsize = +btrfs_super_csum_sectorsize (&root->fs_info->super_copy);/* * TODO: * - split compressed inline extents. annoying: we need to
@@ -963,7 +964,7 @@ long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, u64 off,int coff, clen; size =btrfs_item_size_nr (leaf, slot); - coverslen = (size /BTRFS_CRC32_SIZE ) << + coverslen = (size / csum_sectorsize) << root->fs_info->sb->s_blocksize_bits;printk ("csums for %llu~%llu\n" , key.offset, coverslen);
@@ -980,12 +981,12 @@ long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, u64 off,if (off > key.offset) coff = ((off - key.offset) >> root->fs_info->sb->s_blocksize_bits) * -BTRFS_CRC32_SIZE ; + csum_sectorsize; clen = size - coff;if (key.offset + coverslen > off+len) clen -= ((key.offset+coverslen-off-len) >> root->fs_info->sb->s_blocksize_bits) * -BTRFS_CRC32_SIZE ; + csum_sectorsize;printk (" will dup %d~%d of %d\n" , coff, clen, size);
fs/btrfs/tree-log.c +6 -4
@@ -928,13 +928,15 @@ static noinline int replay_one_csum(struct btrfs_trans_handle *trans,int ret;u32 item_size =btrfs_item_size_nr (eb, slot);u64 cur_offset; +u16 csum_sectorsize = +btrfs_super_csum_sectorsize (&root->fs_info->super_copy);unsigned long file_bytes;struct btrfs_ordered_sum *sums;struct btrfs_sector_sum *sector_sum;struct inode *inode;unsigned long ptr; - file_bytes = (item_size /BTRFS_CRC32_SIZE ) * root->sectorsize; + file_bytes = (item_size / csum_sectorsize) * root->sectorsize; inode =read_one_inode (root, key->objectid);if (!inode) {return -EIO ;
@@ -958,10 +960,10 @@ static noinline int replay_one_csum(struct btrfs_trans_handle *trans, ptr =btrfs_item_ptr_offset (eb, slot);while (item_size >0 ) { sector_sum->offset = cur_offset; -read_extent_buffer (eb, §or_sum->sum, ptr,BTRFS_CRC32_SIZE ); +read_extent_buffer (eb, §or_sum->sum, ptr, csum_sectorsize); sector_sum++; - item_size -=BTRFS_CRC32_SIZE ; - ptr +=BTRFS_CRC32_SIZE ; + item_size -= csum_sectorsize; + ptr += csum_sectorsize; cur_offset += root->sectorsize; }