Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow storing compression level per extent #6

Open
wants to merge 47 commits into
base: misc-next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
69766a5
Btrfs: fix missing hole after hole punching and fsync when using NO_H…
fdmanana Nov 19, 2019
1bbbde1
btrfs: use raid_attr table in calc_stripe_length for nparity
kdave May 13, 2019
bee1249
btrfs: fill ncopies for all raid table entries
kdave Nov 25, 2019
722bd06
btrfs: sysfs, rename devices kobject holder to devices_kobj
asj Nov 21, 2019
61fa4d7
btrfs: sysfs, btrfs_sysfs_add_fsid() drop unused argument parent
asj Nov 21, 2019
3d852c8
btrfs: sysfs, rename btrfs_sysfs_add_device()
asj Nov 21, 2019
7fc36f2
btrfs: sysfs, merge btrfs_sysfs_add devices_kobj and fsid
asj Nov 21, 2019
d31055a
btrfs: qgroup: remove one-time use variables for quota_root checks
marcosps Nov 26, 2019
90cf1de
btrfs: qgroup: return ENOTCONN instead of EINVAL when quotas are not …
marcosps Nov 26, 2019
a48967b
btrfs: Don't discard unwritten extents
lorddoskias Nov 21, 2019
6a37672
btrfs: Open code __btrfs_free_reserved_extent in btrfs_free_reserved_…
lorddoskias Nov 21, 2019
1da8bc0
btrfs: Rename __btrfs_free_reserved_extent to btrfs_pin_reserved_extent
lorddoskias Nov 21, 2019
42d84f0
btrfs: Remove WARN_ON in walk_log_tree
lorddoskias Dec 2, 2019
aaa8e35
btrfs: Remove redundant WARN_ON in walk_down_log_tree
lorddoskias Dec 2, 2019
52434fe
btrfs: remove unused condition check in btrfs_page_mkwrite()
yeyunfeng-dev Dec 3, 2019
502f9ba
btrfs: relocation: Output current relocation stage at btrfs_relocate_…
adam900710 Nov 29, 2019
a922659
btrfs: Opencode ordered_data_tree_panic
lorddoskias Nov 29, 2019
bfac80d
btrfs: don't pass system_chunk into can_overcommit
josefbacik Nov 26, 2019
3a0b0b4
btrfs: kill min_allocable_bytes in inc_block_group_ro
josefbacik Nov 26, 2019
92c886f
btrfs: fix possible NULL-pointer dereference in integrity checks
morbidrsa Dec 5, 2019
20ced90
btrfs: remove superfluous BUG_ON() in integrity checks
morbidrsa Dec 5, 2019
f74c8f6
btrfs: remove impossible WARN_ON in btrfs_destroy_dev_replace_tgtdev()
morbidrsa Dec 5, 2019
937a79d
btrfs: use simple_dir_inode_operations for placeholder subvolume dire…
osandov Dec 5, 2019
16c3a76
btrfs: decrement number of open devices after closing the device not …
Nov 26, 2019
2ca855b
btrfs: reset device back to allocation state when removing
Dec 4, 2019
b9e4db5
btrfs: get rid of trivial __btrfs_lookup_bio_sums() wrappers
osandov Dec 3, 2019
2092e01
btrfs: get rid of at_offset parameter to btrfs_lookup_bio_sums()
osandov Dec 10, 2019
b1b7009
btrfs: remove dead snapshot-aware defrag code
osandov Dec 3, 2019
807c41c
btrfs: make btrfs_ordered_extent naming consistent with btrfs_file_ex…
osandov Dec 3, 2019
3facc99
btrfs: remove unnecessary pg_offset assignments in __extent_writepage()
osandov Dec 3, 2019
54f358c
btrfs: remove trivial goto label in __extent_writepage()
osandov Dec 3, 2019
a92bcc2
btrfs: remove redundant i_size check in __extent_writepage_io()
osandov Dec 3, 2019
931bb7f
btrfs: drop create parameter to btrfs_get_extent()
osandov Dec 3, 2019
f19d3a0
btrfs: simplify compressed/inline check in __extent_writepage_io()
osandov Dec 3, 2019
fceadba
btrfs: remove struct find_free_extent.ram_bytes
osandov Dec 3, 2019
dccad8b
btrfs: punt all bios created in btrfs_submit_compressed_write()
dennisszhou Dec 12, 2019
e089b2f
btrfs: fix compressed write bio blkcg attribution
dennisszhou Dec 11, 2019
fe8510c
Btrfs: fix infinite loop during nocow writeback due to race
fdmanana Dec 11, 2019
4eb110d
btrfs: Remove unneeded semicolon
zhengbin13 Dec 19, 2019
51f2e54
btrfs: tree-checker: Check leaf chunk item size
adam900710 Dec 17, 2019
21b1a8e
btrfs: tree-checker: Clean up fs_info parameter from error message wr…
adam900710 Dec 9, 2019
a02b5c6
btrfs: tree-checker: Refactor inode key check into seperate function
adam900710 Dec 9, 2019
44de088
btrfs: tree-checker: Refactor root key check into separate function
adam900710 Dec 9, 2019
a9183d7
btrfs: tree-checker: Verify location key for DIR_ITEM/DIR_INDEX
adam900710 Dec 9, 2019
9c120e4
btrfs: Allow storing compression level per extent
qwerty123443 Jan 4, 2020
b8998e5
Update inode.c
qwerty123443 Apr 11, 2020
4c6f10d
Update tree-checker.c
qwerty123443 Apr 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions fs/btrfs/block-group.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,21 +1185,8 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, int force)
struct btrfs_space_info *sinfo = cache->space_info;
u64 num_bytes;
u64 sinfo_used;
u64 min_allocable_bytes;
int ret = -ENOSPC;

/*
* We need some metadata space and system metadata space for
* allocating chunks in some corner cases until we force to set
* it to be readonly.
*/
if ((sinfo->flags &
(BTRFS_BLOCK_GROUP_SYSTEM | BTRFS_BLOCK_GROUP_METADATA)) &&
!force)
min_allocable_bytes = SZ_1M;
else
min_allocable_bytes = 0;

spin_lock(&sinfo->lock);
spin_lock(&cache->lock);

Expand All @@ -1217,10 +1204,9 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, int force)
* sinfo_used + num_bytes should always <= sinfo->total_bytes.
*
* Here we make sure if we mark this bg RO, we still have enough
* free space as buffer (if min_allocable_bytes is not 0).
* free space as buffer.
*/
if (sinfo_used + num_bytes + min_allocable_bytes <=
sinfo->total_bytes) {
if (sinfo_used + num_bytes <= sinfo->total_bytes) {
sinfo->bytes_readonly += num_bytes;
cache->ro++;
list_add_tail(&cache->ro_list, &sinfo->ro_bgs);
Expand All @@ -1233,8 +1219,8 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, int force)
btrfs_info(cache->fs_info,
"unable to make block group %llu ro", cache->start);
btrfs_info(cache->fs_info,
"sinfo_used=%llu bg_num_bytes=%llu min_allocable=%llu",
sinfo_used, num_bytes, min_allocable_bytes);
"sinfo_used=%llu bg_num_bytes=%llu",
sinfo_used, num_bytes);
btrfs_dump_space_info(cache->fs_info, cache->space_info, 0, 0);
}
return ret;
Expand Down
4 changes: 1 addition & 3 deletions fs/btrfs/check-integrity.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,15 +629,13 @@ static struct btrfsic_dev_state *btrfsic_dev_state_hashtable_lookup(dev_t dev,
static int btrfsic_process_superblock(struct btrfsic_state *state,
struct btrfs_fs_devices *fs_devices)
{
struct btrfs_fs_info *fs_info = state->fs_info;
struct btrfs_super_block *selected_super;
struct list_head *dev_head = &fs_devices->devices;
struct btrfs_device *device;
struct btrfsic_dev_state *selected_dev_state = NULL;
int ret = 0;
int pass;

BUG_ON(NULL == state);
selected_super = kzalloc(sizeof(*selected_super), GFP_NOFS);
if (NULL == selected_super) {
pr_info("btrfsic: error, kmalloc failed!\n");
Expand Down Expand Up @@ -700,7 +698,7 @@ static int btrfsic_process_superblock(struct btrfsic_state *state,
break;
}

num_copies = btrfs_num_copies(fs_info, next_bytenr,
num_copies = btrfs_num_copies(state->fs_info, next_bytenr,
state->metablock_size);
if (state->print_mask & BTRFSIC_PRINT_MASK_NUM_COPIES)
pr_info("num_copies(log_bytenr=%llu) = %d\n",
Expand Down
15 changes: 10 additions & 5 deletions fs/btrfs/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,

if (blkcg_css) {
bio->bi_opf |= REQ_CGROUP_PUNT;
bio_associate_blkg_from_css(bio, blkcg_css);
kthread_associate_blkcg(blkcg_css);
}
refcount_set(&cb->pending_bios, 1);

Expand Down Expand Up @@ -491,6 +491,8 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
bio->bi_opf = REQ_OP_WRITE | write_flags;
bio->bi_private = cb;
bio->bi_end_io = end_compressed_bio_write;
if (blkcg_css)
bio->bi_opf |= REQ_CGROUP_PUNT;
bio_add_page(bio, page, PAGE_SIZE, 0);
}
if (bytes_left < PAGE_SIZE) {
Expand All @@ -517,6 +519,9 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
bio_endio(bio);
}

if (blkcg_css)
kthread_associate_blkcg(NULL);

return 0;
}

Expand Down Expand Up @@ -758,7 +763,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,

if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) {
ret = btrfs_lookup_bio_sums(inode, comp_bio,
sums);
(u64)-1, sums);
BUG_ON(ret); /* -ENOMEM */
}

Expand Down Expand Up @@ -786,7 +791,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
BUG_ON(ret); /* -ENOMEM */

if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) {
ret = btrfs_lookup_bio_sums(inode, comp_bio, sums);
ret = btrfs_lookup_bio_sums(inode, comp_bio, (u64)-1, sums);
BUG_ON(ret); /* -ENOMEM */
}

Expand Down Expand Up @@ -1196,7 +1201,7 @@ static int btrfs_decompress_bio(struct compressed_bio *cb)
{
struct list_head *workspace;
int ret;
int type = cb->compress_type;
int type = cb->compress_type & 0xF;

workspace = get_workspace(type, 0);
ret = compression_decompress_bio(type, workspace, cb);
Expand All @@ -1215,7 +1220,7 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
{
struct list_head *workspace;
int ret;

type = type & 0xF;
workspace = get_workspace(type, 0);
ret = compression_decompress(type, workspace, data_in, dest_page,
start_byte, srclen, destlen);
Expand Down
10 changes: 4 additions & 6 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2449,8 +2449,8 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);

int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
u64 start, u64 len, int delalloc);
int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info,
u64 start, u64 len);
int btrfs_pin_reserved_extent(struct btrfs_fs_info *fs_info, u64 start,
u64 len);
void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info);
int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
Expand Down Expand Up @@ -2789,9 +2789,7 @@ struct btrfs_dio_private;
int btrfs_del_csums(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 bytenr, u64 len);
blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
u8 *dst);
blk_status_t btrfs_lookup_bio_sums_dio(struct inode *inode, struct bio *bio,
u64 logical_offset);
u64 offset, u8 *dst);
int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 objectid, u64 pos,
Expand Down Expand Up @@ -2877,7 +2875,7 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
struct btrfs_root *root);
struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
struct page *page, size_t pg_offset,
u64 start, u64 end, int create);
u64 start, u64 end);
int btrfs_update_inode(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct inode *inode);
Expand Down
13 changes: 3 additions & 10 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb,
* that covers the entire device
*/
struct extent_map *btree_get_extent(struct btrfs_inode *inode,
struct page *page, size_t pg_offset, u64 start, u64 len,
int create)
struct page *page, size_t pg_offset,
u64 start, u64 len)
{
struct extent_map_tree *em_tree = &inode->extent_tree;
struct extent_map *em;
Expand Down Expand Up @@ -3082,20 +3082,13 @@ int __cold open_ctree(struct super_block *sb,

btrfs_free_extra_devids(fs_devices, 1);

ret = btrfs_sysfs_add_fsid(fs_devices, NULL);
ret = btrfs_sysfs_add_fsid(fs_devices);
if (ret) {
btrfs_err(fs_info, "failed to init sysfs fsid interface: %d",
ret);
goto fail_block_groups;
}

ret = btrfs_sysfs_add_device(fs_devices);
if (ret) {
btrfs_err(fs_info, "failed to init sysfs device interface: %d",
ret);
goto fail_fsdev_sysfs;
}

ret = btrfs_sysfs_add_mounted(fs_info);
if (ret) {
btrfs_err(fs_info, "failed to init sysfs interface: %d", ret);
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/disk-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
int btree_lock_page_hook(struct page *page, void *data,
void (*flush_fn)(void *));
struct extent_map *btree_get_extent(struct btrfs_inode *inode,
struct page *page, size_t pg_offset, u64 start, u64 len,
int create);
struct page *page, size_t pg_offset,
u64 start, u64 len);
int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags);
int __init btrfs_end_io_wq_init(void);
void __cold btrfs_end_io_wq_exit(void);
Expand Down
42 changes: 18 additions & 24 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3438,7 +3438,6 @@ btrfs_release_block_group(struct btrfs_block_group *cache,
*/
struct find_free_extent_ctl {
/* Basic allocation info */
u64 ram_bytes;
u64 num_bytes;
u64 empty_size;
u64 flags;
Expand Down Expand Up @@ -3810,7 +3809,6 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info,

WARN_ON(num_bytes < fs_info->sectorsize);

ffe_ctl.ram_bytes = ram_bytes;
ffe_ctl.num_bytes = num_bytes;
ffe_ctl.empty_size = empty_size;
ffe_ctl.flags = flags;
Expand Down Expand Up @@ -4165,12 +4163,10 @@ int btrfs_reserve_extent(struct btrfs_root *root, u64 ram_bytes,
return ret;
}

static int __btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
u64 start, u64 len,
int pin, int delalloc)
int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
u64 start, u64 len, int delalloc)
{
struct btrfs_block_group *cache;
int ret = 0;

cache = btrfs_lookup_block_group(fs_info, start);
if (!cache) {
Expand All @@ -4179,30 +4175,28 @@ static int __btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
return -ENOSPC;
}

if (pin)
pin_down_extent(cache, start, len, 1);
else {
if (btrfs_test_opt(fs_info, DISCARD))
ret = btrfs_discard_extent(fs_info, start, len, NULL);
btrfs_add_free_space(cache, start, len);
btrfs_free_reserved_bytes(cache, len, delalloc);
trace_btrfs_reserved_extent_free(fs_info, start, len);
}
btrfs_add_free_space(cache, start, len);
btrfs_free_reserved_bytes(cache, len, delalloc);
trace_btrfs_reserved_extent_free(fs_info, start, len);

btrfs_put_block_group(cache);
return ret;
return 0;
}

int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
u64 start, u64 len, int delalloc)
int btrfs_pin_reserved_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len)
{
return __btrfs_free_reserved_extent(fs_info, start, len, 0, delalloc);
}
struct btrfs_block_group *cache;
int ret = 0;

int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info,
u64 start, u64 len)
{
return __btrfs_free_reserved_extent(fs_info, start, len, 1, 0);
cache = btrfs_lookup_block_group(fs_info, start);
if (!cache) {
btrfs_err(fs_info, "unable to find block group for %llu", start);
return -ENOSPC;
}

ret = pin_down_extent(cache, start, len, 1);
btrfs_put_block_group(cache);
return ret;
}

static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
Expand Down
42 changes: 10 additions & 32 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -3043,7 +3043,7 @@ __get_extent_map(struct inode *inode, struct page *page, size_t pg_offset,
*em_cached = NULL;
}

em = get_extent(BTRFS_I(inode), page, pg_offset, start, len, 0);
em = get_extent(BTRFS_I(inode), page, pg_offset, start, len);
if (em_cached && !IS_ERR_OR_NULL(em)) {
BUG_ON(*em_cached);
refcount_inc(&em->refs);
Expand Down Expand Up @@ -3455,11 +3455,6 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,
update_nr_written(wbc, nr_written + 1);

end = page_end;
if (i_size <= start) {
btrfs_writepage_endio_finish_ordered(page, start, page_end, 1);
goto done;
}

blocksize = inode->i_sb->s_blocksize;

while (cur <= end) {
Expand All @@ -3471,8 +3466,8 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,
page_end, 1);
break;
}
em = btrfs_get_extent(BTRFS_I(inode), page, pg_offset, cur,
end - cur + 1, 1);
em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, cur,
end - cur + 1);
if (IS_ERR_OR_NULL(em)) {
SetPageError(page);
ret = PTR_ERR_OR_ZERO(em);
Expand All @@ -3497,22 +3492,11 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,
*/
if (compressed || block_start == EXTENT_MAP_HOLE ||
block_start == EXTENT_MAP_INLINE) {
/*
* end_io notification does not happen here for
* compressed extents
*/
if (!compressed)
btrfs_writepage_endio_finish_ordered(page, cur,
cur + iosize - 1,
1);
else if (compressed) {
/* we don't want to end_page_writeback on
* a compressed extent. this happens
* elsewhere
*/
if (compressed)
nr++;
}

else
btrfs_writepage_endio_finish_ordered(page, cur,
cur + iosize - 1, 1);
cur += iosize;
pg_offset += iosize;
continue;
Expand Down Expand Up @@ -3540,7 +3524,6 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,
pg_offset += iosize;
nr++;
}
done:
*nr_ret = nr;
return ret;
}
Expand All @@ -3562,7 +3545,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,
u64 page_end = start + PAGE_SIZE - 1;
int ret;
int nr = 0;
size_t pg_offset = 0;
size_t pg_offset;
loff_t i_size = i_size_read(inode);
unsigned long end_index = i_size >> PAGE_SHIFT;
unsigned long nr_written = 0;
Expand Down Expand Up @@ -3591,22 +3574,20 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,
flush_dcache_page(page);
}

pg_offset = 0;

set_page_extent_mapped(page);

if (!epd->extent_locked) {
ret = writepage_delalloc(inode, page, wbc, start, &nr_written);
if (ret == 1)
goto done_unlocked;
return 0;
if (ret)
goto done;
}

ret = __extent_writepage_io(inode, page, wbc, epd,
i_size, nr_written, &nr);
if (ret == 1)
goto done_unlocked;
return 0;

done:
if (nr == 0) {
Expand All @@ -3621,9 +3602,6 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,
unlock_page(page);
ASSERT(ret <= 0);
return ret;

done_unlocked:
return 0;
}

void wait_on_extent_buffer_writeback(struct extent_buffer *eb)
Expand Down
Loading