diff options
author | Chris Mason <chris.mason@oracle.com> | 2008-12-08 16:58:54 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-12-08 16:58:54 -0500 |
commit | d20f7043fa65659136c1a7c3c456eeeb5c6f431f (patch) | |
tree | 05d1031cadec6d440a97221e3a32adb504a51699 /fs/btrfs/ordered-data.c | |
parent | c99e905c945c462085c6d64646dc5af0c0a16815 (diff) |
Btrfs: move data checksumming into a dedicated tree
Btrfs stores checksums for each data block. Until now, they have
been stored in the subvolume trees, indexed by the inode that is
referencing the data block. This means that when we read the inode,
we've probably read in at least some checksums as well.
But, this has a few problems:
* The checksums are indexed by logical offset in the file. When
compression is on, this means we have to do the expensive checksumming
on the uncompressed data. It would be faster if we could checksum
the compressed data instead.
* If we implement encryption, we'll be checksumming the plain text and
storing that on disk. This is significantly less secure.
* For either compression or encryption, we have to get the plain text
back before we can verify the checksum as correct. This makes the raid
layer balancing and extent moving much more expensive.
* It makes the front end caching code more complex, as we have touch
the subvolume and inodes as we cache extents.
* There is potentitally one copy of the checksum in each subvolume
referencing an extent.
The solution used here is to store the extent checksums in a dedicated
tree. This allows us to index the checksums by phyiscal extent
start and length. It means:
* The checksum is against the data stored on disk, after any compression
or encryption is done.
* The checksum is stored in a central location, and can be verified without
following back references, or reading inodes.
This makes compression significantly faster by reducing the amount of
data that needs to be checksummed. It will also allow much faster
raid management code in general.
The checksums are indexed by a key with a fixed objectid (a magic value
in ctree.h) and offset set to the starting byte of the extent. This
allows us to copy the checksum items into the fsync log tree directly (or
any other tree), without having to invent a second format for them.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ordered-data.c')
-rw-r--r-- | fs/btrfs/ordered-data.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 027ad6b3839e..d9e232227da4 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c | |||
@@ -610,7 +610,8 @@ out: | |||
610 | * try to find a checksum. This is used because we allow pages to | 610 | * try to find a checksum. This is used because we allow pages to |
611 | * be reclaimed before their checksum is actually put into the btree | 611 | * be reclaimed before their checksum is actually put into the btree |
612 | */ | 612 | */ |
613 | int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u32 *sum) | 613 | int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, |
614 | u32 *sum) | ||
614 | { | 615 | { |
615 | struct btrfs_ordered_sum *ordered_sum; | 616 | struct btrfs_ordered_sum *ordered_sum; |
616 | struct btrfs_sector_sum *sector_sums; | 617 | struct btrfs_sector_sum *sector_sums; |
@@ -629,11 +630,11 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u32 *sum) | |||
629 | mutex_lock(&tree->mutex); | 630 | mutex_lock(&tree->mutex); |
630 | list_for_each_prev(cur, &ordered->list) { | 631 | list_for_each_prev(cur, &ordered->list) { |
631 | ordered_sum = list_entry(cur, struct btrfs_ordered_sum, list); | 632 | ordered_sum = list_entry(cur, struct btrfs_ordered_sum, list); |
632 | if (offset >= ordered_sum->file_offset) { | 633 | if (disk_bytenr >= ordered_sum->bytenr) { |
633 | num_sectors = ordered_sum->len / sectorsize; | 634 | num_sectors = ordered_sum->len / sectorsize; |
634 | sector_sums = ordered_sum->sums; | 635 | sector_sums = ordered_sum->sums; |
635 | for (i = 0; i < num_sectors; i++) { | 636 | for (i = 0; i < num_sectors; i++) { |
636 | if (sector_sums[i].offset == offset) { | 637 | if (sector_sums[i].bytenr == disk_bytenr) { |
637 | *sum = sector_sums[i].sum; | 638 | *sum = sector_sums[i].sum; |
638 | ret = 0; | 639 | ret = 0; |
639 | goto out; | 640 | goto out; |