diff options
Diffstat (limited to 'fs/btrfs/file-item.c')
-rw-r--r-- | fs/btrfs/file-item.c | 114 |
1 files changed, 60 insertions, 54 deletions
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 5349e8e9bbaa..672a36554363 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -90,13 +90,14 @@ btrfs_lookup_csum(struct btrfs_trans_handle *trans, struct btrfs_path *path, u64 bytenr, int cow) { + struct btrfs_fs_info *fs_info = root->fs_info; int ret; struct btrfs_key file_key; struct btrfs_key found_key; struct btrfs_csum_item *item; struct extent_buffer *leaf; u64 csum_offset = 0; - u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); + u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); int csums_in_item; file_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; @@ -116,7 +117,7 @@ btrfs_lookup_csum(struct btrfs_trans_handle *trans, goto fail; csum_offset = (bytenr - found_key.offset) >> - root->fs_info->sb->s_blocksize_bits; + fs_info->sb->s_blocksize_bits; csums_in_item = btrfs_item_size_nr(leaf, path->slots[0]); csums_in_item /= csum_size; @@ -163,6 +164,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, struct inode *inode, struct bio *bio, u64 logical_offset, u32 *dst, int dio) { + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct bio_vec *bvec; struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio); struct btrfs_csum_item *item = NULL; @@ -177,7 +179,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, u32 diff; int nblocks; int count = 0, i; - u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); + u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); path = btrfs_alloc_path(); if (!path) @@ -241,7 +243,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, if (item) btrfs_release_path(path); - item = btrfs_lookup_csum(NULL, root->fs_info->csum_root, + item = btrfs_lookup_csum(NULL, fs_info->csum_root, path, disk_bytenr, 0); if (IS_ERR(item)) { count = 1; @@ -249,10 +251,10 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, if (BTRFS_I(inode)->root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID) { set_extent_bits(io_tree, offset, - offset + root->fs_info->sectorsize - 1, + offset + fs_info->sectorsize - 1, EXTENT_NODATASUM); } else { - btrfs_info_rl(BTRFS_I(inode)->root->fs_info, + btrfs_info_rl(fs_info, "no csum found for inode %llu start %llu", btrfs_ino(inode), offset); } @@ -268,7 +270,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, path->slots[0]); item_last_offset = item_start_offset + (item_size / csum_size) * - root->fs_info->sectorsize; + fs_info->sectorsize; item = btrfs_item_ptr(path->nodes[0], path->slots[0], struct btrfs_csum_item); } @@ -277,7 +279,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, * a single leaf so it will also fit inside a u32 */ diff = disk_bytenr - item_start_offset; - diff = diff / root->fs_info->sectorsize; + diff = diff / fs_info->sectorsize; diff = diff * csum_size; count = min_t(int, nblocks, (item_last_offset - disk_bytenr) >> inode->i_sb->s_blocksize_bits); @@ -289,9 +291,9 @@ found: nblocks -= count; next: while (count--) { - disk_bytenr += root->fs_info->sectorsize; - offset += root->fs_info->sectorsize; - page_bytes_left -= root->fs_info->sectorsize; + disk_bytenr += fs_info->sectorsize; + offset += fs_info->sectorsize; + page_bytes_left -= fs_info->sectorsize; if (!page_bytes_left) break; /* move to next bio */ } @@ -317,6 +319,7 @@ int btrfs_lookup_bio_sums_dio(struct btrfs_root *root, struct inode *inode, int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, struct list_head *list, int search_commit) { + struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_key key; struct btrfs_path *path; struct extent_buffer *leaf; @@ -327,10 +330,10 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, int ret; size_t size; u64 csum_end; - u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); + u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); - ASSERT(IS_ALIGNED(start, root->fs_info->sectorsize) && - IS_ALIGNED(end + 1, root->fs_info->sectorsize)); + ASSERT(IS_ALIGNED(start, fs_info->sectorsize) && + IS_ALIGNED(end + 1, fs_info->sectorsize)); path = btrfs_alloc_path(); if (!path) @@ -355,7 +358,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, if (key.objectid == BTRFS_EXTENT_CSUM_OBJECTID && key.type == BTRFS_EXTENT_CSUM_KEY) { offset = (start - key.offset) >> - root->fs_info->sb->s_blocksize_bits; + fs_info->sb->s_blocksize_bits; if (offset * csum_size < btrfs_item_size_nr(leaf, path->slots[0] - 1)) path->slots[0]--; @@ -383,7 +386,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, start = key.offset; size = btrfs_item_size_nr(leaf, path->slots[0]); - csum_end = key.offset + (size / csum_size) * root->fs_info->sectorsize; + csum_end = key.offset + (size / csum_size) * fs_info->sectorsize; if (csum_end <= start) { path->slots[0]++; continue; @@ -394,9 +397,8 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, struct btrfs_csum_item); while (start < csum_end) { size = min_t(size_t, csum_end - start, - MAX_ORDERED_SUM_BYTES(root->fs_info)); - sums = kzalloc(btrfs_ordered_sum_size(root->fs_info, - size), + MAX_ORDERED_SUM_BYTES(fs_info)); + sums = kzalloc(btrfs_ordered_sum_size(fs_info, size), GFP_NOFS); if (!sums) { ret = -ENOMEM; @@ -407,16 +409,16 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, sums->len = (int)size; offset = (start - key.offset) >> - root->fs_info->sb->s_blocksize_bits; + fs_info->sb->s_blocksize_bits; offset *= csum_size; - size >>= root->fs_info->sb->s_blocksize_bits; + size >>= fs_info->sb->s_blocksize_bits; read_extent_buffer(path->nodes[0], sums->sums, ((unsigned long)item) + offset, csum_size * size); - start += root->fs_info->sectorsize * size; + start += fs_info->sectorsize * size; list_add_tail(&sums->list, &tmplist); } path->slots[0]++; @@ -437,6 +439,7 @@ fail: int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, struct bio *bio, u64 file_start, int contig) { + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_ordered_sum *sums; struct btrfs_ordered_extent *ordered = NULL; char *data; @@ -449,8 +452,7 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, u64 offset; WARN_ON(bio->bi_vcnt <= 0); - sums = kzalloc(btrfs_ordered_sum_size(root->fs_info, - bio->bi_iter.bi_size), + sums = kzalloc(btrfs_ordered_sum_size(fs_info, bio->bi_iter.bi_size), GFP_NOFS); if (!sums) return -ENOMEM; @@ -477,9 +479,9 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, data = kmap_atomic(bvec->bv_page); - nr_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info, - bvec->bv_len + root->fs_info->sectorsize - - 1); + nr_sectors = BTRFS_BYTES_TO_BLKS(fs_info, + bvec->bv_len + fs_info->sectorsize + - 1); for (i = 0; i < nr_sectors; i++) { if (offset >= ordered->file_offset + ordered->len || @@ -494,8 +496,8 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, bytes_left = bio->bi_iter.bi_size - total_bytes; - sums = kzalloc(btrfs_ordered_sum_size(root->fs_info, bytes_left), - GFP_NOFS); + sums = kzalloc(btrfs_ordered_sum_size(fs_info, bytes_left), + GFP_NOFS); BUG_ON(!sums); /* -ENOMEM */ sums->len = bytes_left; ordered = btrfs_lookup_ordered_extent(inode, @@ -511,15 +513,15 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, sums->sums[index] = ~(u32)0; sums->sums[index] = btrfs_csum_data(data + bvec->bv_offset - + (i * root->fs_info->sectorsize), + + (i * fs_info->sectorsize), sums->sums[index], - root->fs_info->sectorsize); + fs_info->sectorsize); btrfs_csum_final(sums->sums[index], (char *)(sums->sums + index)); index++; - offset += root->fs_info->sectorsize; - this_sum_bytes += root->fs_info->sectorsize; - total_bytes += root->fs_info->sectorsize; + offset += fs_info->sectorsize; + this_sum_bytes += fs_info->sectorsize; + total_bytes += fs_info->sectorsize; } kunmap_atomic(data); @@ -546,15 +548,16 @@ static noinline void truncate_one_csum(struct btrfs_root *root, struct btrfs_key *key, u64 bytenr, u64 len) { + struct btrfs_fs_info *fs_info = root->fs_info; struct extent_buffer *leaf; - u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); + u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); u64 csum_end; u64 end_byte = bytenr + len; - u32 blocksize_bits = root->fs_info->sb->s_blocksize_bits; + u32 blocksize_bits = fs_info->sb->s_blocksize_bits; leaf = path->nodes[0]; csum_end = btrfs_item_size_nr(leaf, path->slots[0]) / csum_size; - csum_end <<= root->fs_info->sb->s_blocksize_bits; + csum_end <<= fs_info->sb->s_blocksize_bits; csum_end += key->offset; if (key->offset < bytenr && csum_end <= end_byte) { @@ -581,7 +584,7 @@ static noinline void truncate_one_csum(struct btrfs_root *root, btrfs_truncate_item(root, path, new_size, 0); key->offset = end_byte; - btrfs_set_item_key_safe(root->fs_info, path, key); + btrfs_set_item_key_safe(fs_info, path, key); } else { BUG(); } @@ -601,8 +604,8 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 csum_end; struct extent_buffer *leaf; int ret; - u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); - int blocksize_bits = root->fs_info->sb->s_blocksize_bits; + u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); + int blocksize_bits = fs_info->sb->s_blocksize_bits; path = btrfs_alloc_path(); if (!path) @@ -711,6 +714,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_ordered_sum *sums) { + struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_key file_key; struct btrfs_key found_key; struct btrfs_path *path; @@ -726,7 +730,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, int index = 0; int found_next; int ret; - u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); + u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); path = btrfs_alloc_path(); if (!path) @@ -759,7 +763,7 @@ again: leaf = path->nodes[0]; item_size = btrfs_item_size_nr(leaf, path->slots[0]); if ((item_size / csum_size) >= - MAX_CSUM_ITEMS(root->fs_info, csum_size)) { + MAX_CSUM_ITEMS(fs_info, csum_size)) { /* already at max size, make a new one */ goto insert; } @@ -805,11 +809,11 @@ again: leaf = path->nodes[0]; btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); csum_offset = (bytenr - found_key.offset) >> - root->fs_info->sb->s_blocksize_bits; + fs_info->sb->s_blocksize_bits; if (found_key.type != BTRFS_EXTENT_CSUM_KEY || found_key.objectid != BTRFS_EXTENT_CSUM_OBJECTID || - csum_offset >= MAX_CSUM_ITEMS(root->fs_info, csum_size)) { + csum_offset >= MAX_CSUM_ITEMS(fs_info, csum_size)) { goto insert; } @@ -827,12 +831,13 @@ again: free_space = btrfs_leaf_free_space(root, leaf) - sizeof(struct btrfs_item) - csum_size; tmp = sums->len - total_bytes; - tmp >>= root->fs_info->sb->s_blocksize_bits; + tmp >>= fs_info->sb->s_blocksize_bits; WARN_ON(tmp < 1); extend_nr = max_t(int, 1, (int)tmp); diff = (csum_offset + extend_nr) * csum_size; - diff = min(diff, MAX_CSUM_ITEMS(root->fs_info, csum_size) * csum_size); + diff = min(diff, + MAX_CSUM_ITEMS(fs_info, csum_size) * csum_size); diff = diff - btrfs_item_size_nr(leaf, path->slots[0]); diff = min(free_space, diff); @@ -851,12 +856,12 @@ insert: u64 tmp; tmp = sums->len - total_bytes; - tmp >>= root->fs_info->sb->s_blocksize_bits; + tmp >>= fs_info->sb->s_blocksize_bits; tmp = min(tmp, (next_offset - file_key.offset) >> - root->fs_info->sb->s_blocksize_bits); + fs_info->sb->s_blocksize_bits); tmp = max((u64)1, tmp); - tmp = min(tmp, (u64)MAX_CSUM_ITEMS(root->fs_info, csum_size)); + tmp = min(tmp, (u64)MAX_CSUM_ITEMS(fs_info, csum_size)); ins_size = csum_size * tmp; } else { ins_size = csum_size; @@ -878,7 +883,7 @@ csum: csum_offset * csum_size); found: ins_size = (u32)(sums->len - total_bytes) >> - root->fs_info->sb->s_blocksize_bits; + fs_info->sb->s_blocksize_bits; ins_size *= csum_size; ins_size = min_t(u32, (unsigned long)item_end - (unsigned long)item, ins_size); @@ -886,7 +891,7 @@ found: ins_size); ins_size /= csum_size; - total_bytes += ins_size * root->fs_info->sectorsize; + total_bytes += ins_size * fs_info->sectorsize; index += ins_size; btrfs_mark_buffer_dirty(path->nodes[0]); @@ -909,6 +914,7 @@ void btrfs_extent_item_to_extent_map(struct inode *inode, const bool new_inline, struct extent_map *em) { + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_root *root = BTRFS_I(inode)->root; struct extent_buffer *leaf = path->nodes[0]; const int slot = path->slots[0]; @@ -918,7 +924,7 @@ void btrfs_extent_item_to_extent_map(struct inode *inode, u8 type = btrfs_file_extent_type(leaf, fi); int compress_type = btrfs_file_extent_compression(leaf, fi); - em->bdev = root->fs_info->fs_devices->latest_bdev; + em->bdev = fs_info->fs_devices->latest_bdev; btrfs_item_key_to_cpu(leaf, &key, slot); extent_start = key.offset; @@ -930,7 +936,7 @@ void btrfs_extent_item_to_extent_map(struct inode *inode, size_t size; size = btrfs_file_extent_inline_len(leaf, slot, fi); extent_end = ALIGN(extent_start + size, - root->fs_info->sectorsize); + fs_info->sectorsize); } em->ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi); @@ -973,7 +979,7 @@ void btrfs_extent_item_to_extent_map(struct inode *inode, em->compress_type = compress_type; } } else { - btrfs_err(root->fs_info, + btrfs_err(fs_info, "unknown file extent item type %d, inode %llu, offset %llu, root %llu", type, btrfs_ino(inode), extent_start, root->root_key.objectid); |