Corrupt counter improvement
cover Corrupt counter improvement
This series aims to make the device corrupt counter be incremented when we encounter checksum error. This stems from an upstream report at [0] that btrfs doesn't actually increment the corruption device stats counter. There's no good reason why this should be the case so here's a patchset rectifying this.
While looking around the code I thought the signature of the functions related to creating the failrec are somewhat quirky so the first 2 patches fix this.
Patch 3 introduces btrfs_device into btrfs_io_bio so that functions in the bio completion stack can use it.
Patch 4 removes a redundant check
Next 3 patches wire in increment of the CORRUPT counter in the respective read end io routines, namely compressed and ordinary reads.
Last patch creates a symlink of the private bdi that btrfs creates on mount which is used in an xfstest for this series.
[0] https://lore.kernel.org/linux-btrfs/4857863.FCrPRfMyHP@liv/
Nikolay Borisov (8):
btrfs: Make get_state_failrec return failrec directly
btrfs: Streamline btrfs_get_io_failure_record logic
btrfs: Record btrfs_device directly btrfs_io_bio
btrfs: Don't check for btrfs_device::bdev in btrfs_end_bio
btrfs: Increment device corruption error in case of checksum error
btrfs: Remove needless ASSERT
btrfs: Increment corrupt device counter during compressed read
btrfs: sysfs: Add bdi link to the fsid dir
fs/btrfs/compression.c | 10 ++- fs/btrfs/ctree.h | 2 + fs/btrfs/extent-io-tree.h | 6 +- fs/btrfs/extent_io.c | 152 +++++++++++++++++++------------------- fs/btrfs/inode.c | 3 + fs/btrfs/raid56.c | 1 + fs/btrfs/sysfs.c | 16 +++- fs/btrfs/volumes.c | 24 +++--- fs/btrfs/volumes.h | 2 +- 9 files changed, 114 insertions(+), 102 deletions(-)
--
2.17.1
PATCH 1/8 btrfs: Make get_state_failrec return failrec directly
Only failure that get_state_failrec can get is if there is no failurec for the given address. There is no reason why the function should return a status code and use a separate parameter for returning the actual failure rec (if one is found). Simplify it by making the return type a pointer and return ERR_PTR value in case of errors.
--- fs/btrfs/extent-io-tree.h | 4 ++-- fs/btrfs/extent_io.c | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-)
fs/btrfs/extent-io-tree.h +2 -2
@@ -233,8 +233,8 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, struct extent_state **cached_state);/* This should be reworked in the future and put elsewhere. */ -int get_state_failrec (struct extent_io_tree *tree,u64 start, -struct io_failure_record **failrec); +struct io_failure_record *get_state_failrec (struct extent_io_tree *tree, +u64 start);int set_state_failrec (struct extent_io_tree *tree,u64 start,struct io_failure_record *failrec); void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start,
fs/btrfs/extent_io.c +12 -11
@@ -2121,12 +2121,12 @@ int set_state_failrec(struct extent_io_tree *tree, u64 start,return ret; } -int get_state_failrec (struct extent_io_tree *tree,u64 start, -struct io_failure_record **failrec) +struct io_failure_record *get_state_failrec (struct extent_io_tree *tree, +u64 start) {struct rb_node *node;struct extent_state *state; -int ret =0 ; +struct io_failure_record *failrec;spin_lock (&tree->lock);/*
@@ -2135,18 +2135,19 @@ int get_state_failrec(struct extent_io_tree *tree, u64 start,*/ node =tree_search (tree, start);if (!node) { - ret = -ENOENT ; + failrec =ERR_PTR (-ENOENT ); goto out; } state = rb_entry(node, struct extent_state, rb_node);if (state->start != start) { - ret = -ENOENT ; + failrec =ERR_PTR (-ENOENT ); goto out; } - *failrec = state->failrec; + + failrec = state->failrec; out:spin_unlock (&tree->lock); -return ret; +return failrec; }/*
@@ -2376,8 +2377,8 @@ int clean_io_failure(struct btrfs_fs_info *fs_info,if (!ret)return 0 ; - ret =get_state_failrec (failure_tree, start, &failrec); -if (ret) + failrec =get_state_failrec (failure_tree, start); +if (IS_ERR (failrec))return 0 ;BUG_ON (!failrec->this_mirror);
@@ -2461,8 +2462,8 @@ int btrfs_get_io_failure_record(struct inode *inode, u64 start, u64 end,int ret;u64 logical; - ret =get_state_failrec (failure_tree, start, &failrec); -if (ret) { + failrec =get_state_failrec (failure_tree, start); +if (IS_ERR (failrec)) { failrec =kzalloc (sizeof (*failrec),GFP_NOFS );if (!failrec)return -ENOMEM ;
Signature · 1 line
2.17.1
Re: [PATCH 1/8] btrfs: Make get_state_failrec return failrec directly
Quoted 34 lines · Nikolay Borisov
Only failure that
get_state_failreccan get is if there is no failurec for the given address. There is no reason why the function should return a status code and use a separate parameter for returning the actual failure rec (if one is found). Simplify it by making the return type a pointer and returnERR_PTRvalue in case of errors.Signed-off-by Nikolay Borisov <[email protected]>--- fs/btrfs/extent-io-tree.h | 4 ++-- fs/btrfs/extent_io.c | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-)fs/btrfs/extent-io-tree.h +2
-2@@ -233,8 +233,8 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start, struct extent_state **cached_state);/* This should be reworked in the future and put elsewhere. */ -int get_state_failrec (struct extent_io_tree *tree,u64 start, -struct io_failure_record **failrec); +struct io_failure_record *get_state_failrec (struct extent_io_tree *tree, +u64 start);int set_state_failrec (struct extent_io_tree *tree,u64 start,struct io_failure_record *failrec); void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start,fs/btrfs/extent_io.c +0
-0@@ -2121,12 +2121,12 @@ int set_state_failrec(struct extent_io_tree *tree, u64 start,return ret; }
fs/btrfs/extent_io.c int set_state_failrec(struct extent_io_tree *tree, u64 start, · line 2129
Quoted 10 lines
fs/btrfs/extent_io.c +3
-3-int get_state_failrec (struct extent_io_tree *tree,u64 start, -struct io_failure_record **failrec) +struct io_failure_record *get_state_failrec (struct extent_io_tree *tree, +u64 start) {struct rb_node *node;struct extent_state *state; -int ret =0 ; +struct io_failure_record *failrec;
Seems we can just do
struct io_failure_record *failrec = ERR_PTR(-ENOENT);
here and avoid the extra stuff below, as we only ever return -ENOENT on failure.
Thanks,
Josef
Re: [PATCH 1/8] btrfs: Make get_state_failrec return failrec directly
Quoted 11 lines · Josef Bacik
fs/btrfs/extent_io.c int set_state_failrec(struct extent_io_tree *tree, u64 start, · line 2129
Quoted 7 lines · Nikolay Borisov
fs/btrfs/extent_io.c +3
-1+struct io_failure_record *get_state_failrec (struct extent_io_tree *tree, +u64 start) {struct rb_node *node;struct extent_state *state; -int ret =0 ; +struct io_failure_record *failrec;Seems we can just do
Quoted 3 lines
struct
io_failure_record*failrec =ERR_PTR(-ENOENT);here and avoid the extra stuff below, as we only ever return
-ENOENTon failure.
I'm not a fan of this pattern, setting the error code just before the label is IMHO more clear and one does not have to look up the initial value.
PATCH 2/8 btrfs: Streamline btrfs_get_io_failure_record logic
In reply to Nikolay BorisovMake the function directly return a pointer to a failure record and adjust callers to handle it. Also refactor the logic inside so that the case which allocates the failure record for the first time is not handled in an 'if' arm, saving us a level of indentation. Finally make the function static as it's not used outside of extent_io.c .
--- fs/btrfs/extent-io-tree.h | 2 - fs/btrfs/extent_io.c | 131 +++++++++++++++++++------------------- 2 files changed, 65 insertions(+), 68 deletions(-)
fs/btrfs/extent-io-tree.h +0 -2
@@ -239,8 +239,6 @@ int set_state_failrec(struct extent_io_tree *tree, u64 start, struct io_failure_record *failrec);void btrfs_free_io_failure_record (struct btrfs_inode *inode,u64 start,u64 end); -int btrfs_get_io_failure_record (struct inode *inode,u64 start,u64 end, -struct io_failure_record **failrec_ret);int free_io_failure (struct extent_io_tree *failure_tree,struct extent_io_tree *io_tree,struct io_failure_record *rec);
fs/btrfs/extent_io.c +65 -66
164 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 2/8] btrfs: Streamline btrfs_get_io_failure_record logic
Quoted 7 lines · Nikolay Borisov
Make the function directly return a pointer to a failure record and adjust callers to handle it. Also refactor the logic inside so that the case which allocates the failure record for the first time is not handled in an 'if' arm, saving us a level of indentation. Finally make the function static as it's not used outside of
extent_io.c.Signed-off-by Nikolay Borisov <[email protected]>
Thanks,
Josef
PATCH 3/8 btrfs: Record btrfs_device directly btrfs_io_bio
In reply to Nikolay BorisovInstead of recording stripe_index and using that to access correct btrfs_device from btrfs_bio::stripes record the btrfs_device in btrfs_io_bio. This will enable endio handlers to increment device error counters on checksum errors.
--- fs/btrfs/raid56.c | 1 + fs/btrfs/volumes.c | 9 ++------- fs/btrfs/volumes.h | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-)
fs/btrfs/raid56.c +1 -0
@@ -1117,6 +1117,7 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio,/* put a new bio on the list */ bio =btrfs_io_bio_alloc (bio_max_len >>PAGE_SHIFT ?:1 ); +btrfs_io_bio (bio)->dev = stripe->dev; bio->bi_iter.bi_size =0 ;bio_set_dev (bio, stripe->dev->bdev); bio->bi_iter.bi_sector = disk_start >>9 ;
fs/btrfs/volumes.c +2 -7
@@ -6261,12 +6261,7 @@ static void btrfs_end_bio(struct bio *bio)atomic_inc (&bbio->error);if (bio->bi_status ==BLK_STS_IOERR || bio->bi_status ==BLK_STS_TARGET ) { -unsigned int stripe_index = -btrfs_io_bio (bio)->stripe_index; -struct btrfs_device *dev; - -BUG_ON (stripe_index >= bbio->num_stripes); - dev = bbio->stripes[stripe_index].dev; +struct btrfs_device *dev =btrfs_io_bio (bio)->dev;if (dev->bdev) {if (bio_op (bio) ==REQ_OP_WRITE ) btrfs_dev_stat_inc_and_print(dev,
@@ -6319,7 +6314,7 @@ static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio,struct btrfs_fs_info *fs_info = bbio->fs_info; bio->bi_private = bbio; -btrfs_io_bio (bio)->stripe_index = dev_nr; +btrfs_io_bio (bio)->dev = dev; bio->bi_end_io = btrfs_end_bio; bio->bi_iter.bi_sector = physical >>9 ; btrfs_debug_in_rcu(fs_info,
fs/btrfs/volumes.h +1 -1
@@ -288,7 +288,7 @@ struct btrfs_fs_devices {*/ struct btrfs_io_bio {unsigned int mirror_num; -unsigned int stripe_index; +struct btrfs_device *dev;u64 logical;u8 *csum;u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE ];
Signature · 1 line
2.17.1
Re: [PATCH 3/8] btrfs: Record btrfs_device directly btrfs_io_bio
Quoted 6 lines · Nikolay Borisov
Instead of recording
stripe_indexand using that to access correctbtrfs_devicefrombtrfs_bio::stripesrecord thebtrfs_deviceinbtrfs_io_bio. This will enable endio handlers to increment device error counters on checksum errors.Signed-off-by Nikolay Borisov <[email protected]>
Thanks,
Josef
Re: [PATCH 3/8] btrfs: Record btrfs_device directly btrfs_io_bio
In reply to Nikolay Borisovfs/btrfs/volumes.c static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio, · line 6320
Quoted 9 lines · Nikolay Borisov
fs/btrfs/volumes.c +1
-1@@ -6319,7 +6314,7 @@ static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio,struct btrfs_fs_info *fs_info = bbio->fs_info; bio->bi_private = bbio; -btrfs_io_bio (bio)->stripe_index = dev_nr; +btrfs_io_bio (bio)->dev = dev; bio->bi_end_io = btrfs_end_bio; bio->bi_iter.bi_sector = physical >>9 ; btrfs_debug_in_rcu(fs_info,
Can't we just pass in a btrfs_device here (into submit_stripe_bio() that is) instead of dev_nr?
PATCH v2 1/1 btrfs: Record btrfs_device directly btrfs_io_bio
In reply to Nikolay BorisovInstead of recording stripe_index and using that to access correct btrfs_device from btrfs_bio::stripes record the btrfs_device in btrfs_io_bio. This will enable endio handlers to increment device error counters on checksum errors.
---
V2: Pass btrfs_device directly to submit_stripe_bio
fs/btrfs/raid56.c | 1 + fs/btrfs/volumes.c | 14 ++++---------- fs/btrfs/volumes.h | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-)
fs/btrfs/raid56.c +1 -0
@@ -1117,6 +1117,7 @@ static int rbio_add_io_page(struct btrfs_raid_bio *rbio,/* put a new bio on the list */ bio =btrfs_io_bio_alloc (bio_max_len >>PAGE_SHIFT ?:1 ); +btrfs_io_bio (bio)->dev = stripe->dev; bio->bi_iter.bi_size =0 ;bio_set_dev (bio, stripe->dev->bdev); bio->bi_iter.bi_sector = disk_start >>9 ;
fs/btrfs/volumes.c +4 -10
@@ -6261,12 +6261,7 @@ static void btrfs_end_bio(struct bio *bio)atomic_inc (&bbio->error);if (bio->bi_status ==BLK_STS_IOERR || bio->bi_status ==BLK_STS_TARGET ) { -unsigned int stripe_index = -btrfs_io_bio (bio)->stripe_index; -struct btrfs_device *dev; - -BUG_ON (stripe_index >= bbio->num_stripes); - dev = bbio->stripes[stripe_index].dev; +struct btrfs_device *dev =btrfs_io_bio (bio)->dev;if (dev->bdev) {if (bio_op (bio) ==REQ_OP_WRITE ) btrfs_dev_stat_inc_and_print(dev,
@@ -6313,13 +6308,12 @@ static void btrfs_end_bio(struct bio *bio) }static void submit_stripe_bio (struct btrfs_bio *bbio,struct bio *bio, -u64 physical,int dev_nr) +u64 physical,struct btrfs_device *dev) { -struct btrfs_device *dev = bbio->stripes[dev_nr].dev;struct btrfs_fs_info *fs_info = bbio->fs_info; bio->bi_private = bbio; -btrfs_io_bio (bio)->stripe_index = dev_nr; +btrfs_io_bio (bio)->dev = dev; bio->bi_end_io = btrfs_end_bio; bio->bi_iter.bi_sector = physical >>9 ; btrfs_debug_in_rcu(fs_info,
@@ -6421,7 +6415,7 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, bio = first_bio;submit_stripe_bio (bbio, bio, bbio->stripes[dev_nr].physical, - dev_nr); + dev); }btrfs_bio_counter_dec (fs_info);return BLK_STS_OK ;
fs/btrfs/volumes.h +1 -1
@@ -288,7 +288,7 @@ struct btrfs_fs_devices {*/ struct btrfs_io_bio {unsigned int mirror_num; -unsigned int stripe_index; +struct btrfs_device *dev;u64 logical;u8 *csum;u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE ];
--
2.17.1
Re: [PATCH v2] btrfs: Record btrfs_device directly btrfs_io_bio
Looks good,
PATCH 4/8 btrfs: Don't check for btrfs_device::bdev in btrfs_end_bio
In reply to Nikolay Borisovbtrfs_map_bio ensures that all submitted bios to devices have valid btrfs_device::bdev so this check can be removed from btrfs_end_bio. This check was added in june 2012 597a60fadedf ("Btrfs: don't count I/O statistic read errors for missing devices") but then in October of the same year another commit de1ee92ac3bc ("Btrfs: recheck bio against block device when we map the bio") started checking for the presence of btrfs_device::bdev before actually issuing the bio.
--- fs/btrfs/volumes.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
fs/btrfs/volumes.c +7 -8
@@ -6262,17 +6262,16 @@ static void btrfs_end_bio(struct bio *bio)if (bio->bi_status ==BLK_STS_IOERR || bio->bi_status ==BLK_STS_TARGET ) {struct btrfs_device *dev =btrfs_io_bio (bio)->dev; -if (dev->bdev) { -if (bio_op (bio) ==REQ_OP_WRITE ) -btrfs_dev_stat_inc_and_print (dev, +ASSERT (dev->bdev); +if (bio_op (bio) ==REQ_OP_WRITE ) +btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_WRITE_ERRS ); -else if (!(bio->bi_opf &REQ_RAHEAD )) -btrfs_dev_stat_inc_and_print (dev, +else if (!(bio->bi_opf &REQ_RAHEAD )) +btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_READ_ERRS ); -if (bio->bi_opf &REQ_PREFLUSH ) -btrfs_dev_stat_inc_and_print (dev, +if (bio->bi_opf &REQ_PREFLUSH ) +btrfs_dev_stat_inc_and_print (dev,BTRFS_DEV_STAT_FLUSH_ERRS ); - } } }
Signature · 1 line
2.17.1
Re: [PATCH 4/8] btrfs: Don't check for btrfs_device::bdev in btrfs_end_bio
Quoted 9 lines · Nikolay Borisov
btrfs_map_bioensures that all submitted bios to devices have validbtrfs_device::bdevso this check can be removed frombtrfs_end_bio. This check was added in june 2012597a60fadedf("Btrfs: don't count I/O statistic read errors for missing devices") but then in October of the same year another commitde1ee92ac3bc("Btrfs: recheck bio against block device when we map the bio") started checking for the presence ofbtrfs_device::bdevbefore actually issuing the bio.Signed-off-by Nikolay Borisov <[email protected]>
Thanks,
Josef
PATCH 5/8 btrfs: Increment device corruption error in case of checksum error
In reply to Nikolay BorisovNow that btrfs_io_bio have access to btrfs_device we can safely increment the device corruption counter on error. There is one notable exception - repair bios for raid. Since those don't go through the normal submit_stripe_bio callpath but through raid56_parity_recover thus repair bios won't have their device set.
--- fs/btrfs/inode.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/inode.c +3 -0
@@ -2822,6 +2822,9 @@ static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio, zeroit:btrfs_print_data_csum_error (BTRFS_I (inode), start, csum, csum_expected, io_bio->mirror_num); +if (io_bio->dev) +btrfs_dev_stat_inc_and_print (io_bio->dev, +BTRFS_DEV_STAT_CORRUPTION_ERRS );memset (kaddr + pgoff,1 , len);flush_dcache_page (page);kunmap_atomic (kaddr);
--
2.17.1
Re: [PATCH 5/8] btrfs: Increment device corruption error in case of checksum error
Quoted 27 lines · Nikolay Borisov
Now that
btrfs_io_biohave access tobtrfs_devicewe can safely increment the device corruption counter on error. There is one notable exception - repair bios for raid. Since those don't go through the normalsubmit_stripe_biocallpath but throughraid56_parity_recoverthus repair bios won't have their device set.Signed-off-by Nikolay Borisov <[email protected]>--- fs/btrfs/inode.c | 3 +++ 1 file changed, 3 insertions(+)fs/btrfs/inode.c +3
-1@@ -2822,6 +2822,9 @@ static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio, zeroit:btrfs_print_data_csum_error (BTRFS_I (inode), start, csum, csum_expected, io_bio->mirror_num); +if (io_bio->dev) +btrfs_dev_stat_inc_and_print (io_bio->dev, +BTRFS_DEV_STAT_CORRUPTION_ERRS );memset (kaddr + pgoff,1 , len);flush_dcache_page (page);kunmap_atomic (kaddr); --
Quoted 2 lines
2.17.1
I had to go look this up to see if we were double counting, but no, we only do BTRFS_DEV_STAT_CORRUPTION_ERRS for data with scrub, which goes through a different IO path than the normal reads. Just in case anybody else is as confused as I was
Thanks,
Josef
Re: [PATCH 5/8] btrfs: Increment device corruption error in case of checksum error
In reply to Nikolay BorisovQuoted 17 lines · Nikolay Borisov
Now that
btrfs_io_biohave access tobtrfs_devicewe can safely increment the device corruption counter on error. There is one notable exception - repair bios for raid. Since those don't go through the normalsubmit_stripe_biocallpath but throughraid56_parity_recoverthus repair bios won't have their device set.Signed-off-by Nikolay Borisov <[email protected]>--- fs/btrfs/inode.c | 3 +++ 1 file changed, 3 insertions(+)fs/btrfs/inode.c +0
-0
fs/btrfs/inode.c static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio, · line 2830
Quoted 9 lines
fs/btrfs/inode.c +3
-0@@ -2822,6 +2822,9 @@ static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio, zeroit:btrfs_print_data_csum_error (BTRFS_I (inode), start, csum, csum_expected, io_bio->mirror_num); +if (io_bio->dev) +btrfs_dev_stat_inc_and_print (io_bio->dev, +BTRFS_DEV_STAT_CORRUPTION_ERRS );memset (kaddr + pgoff,1 , len);flush_dcache_page (page);kunmap_atomic (kaddr);
Any chance you could do a follow up merging that weird zeroit label into the memset() block?
It kind of disturbs the reading flow of that function and in fact it doesn't even zero the data
Re: [PATCH 5/8] btrfs: Increment device corruption error in case of checksum error
Quoted 31 lines · Johannes Thumshirn
Quoted 17 lines · Nikolay Borisov
Now that
btrfs_io_biohave access tobtrfs_devicewe can safely increment the device corruption counter on error. There is one notable exception - repair bios for raid. Since those don't go through the normalsubmit_stripe_biocallpath but throughraid56_parity_recoverthus repair bios won't have their device set.Signed-off-by Nikolay Borisov <[email protected]>--- fs/btrfs/inode.c | 3 +++ 1 file changed, 3 insertions(+)fs/btrfs/inode.c +0
-0fs/btrfs/inode.c static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio, · line 2830
Quoted 9 lines
fs/btrfs/inode.c +3
-0@@ -2822,6 +2822,9 @@ static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio, zeroit:btrfs_print_data_csum_error (BTRFS_I (inode), start, csum, csum_expected, io_bio->mirror_num); +if (io_bio->dev) +btrfs_dev_stat_inc_and_print (io_bio->dev, +BTRFS_DEV_STAT_CORRUPTION_ERRS );memset (kaddr + pgoff,1 , len);flush_dcache_page (page);kunmap_atomic (kaddr);Any chance you could do a follow up merging that weird zeroit label into the
memset()block?
Quoted 3 lines
It kind of disturbs the reading flow of that function and in fact it doesn't even zero the data
Makes sense, it doesn't even look that bad at all in terms of line length.
PATCH 6/8 btrfs: Remove needless ASSERT
In reply to Nikolay Borisovcompressed_bio::orig_bio is always set in btrfs_submit_compressed_read before any bio submission is performed. Since that function is always called with a valid bio it renders the ASSERT unnecessary.
--- fs/btrfs/compression.c | 1 - 1 file changed, 1 deletion(-)
fs/btrfs/compression.c +0 -1
@@ -244,7 +244,6 @@ static void end_compressed_bio_read(struct bio *bio)* Record the correct mirror_num in cb->orig_bio so that * read-repair can work properly. */ -ASSERT (btrfs_io_bio (cb->orig_bio));btrfs_io_bio (cb->orig_bio)->mirror_num = mirror; cb->mirror_num = mirror;
Signature · 1 line
2.17.1
Re: [PATCH 6/8] btrfs: Remove needless ASSERT
Quoted 15 lines · Nikolay Borisov
compressed_bio::orig_biois always set inbtrfs_submit_compressed_readbefore any bio submission is performed. Since that function is always called with a valid bio it renders the ASSERT unnecessary.Signed-off-by Nikolay Borisov <[email protected]>--- fs/btrfs/compression.c | 1 - 1 file changed, 1 deletion(-)fs/btrfs/compression.c +0
-0
fs/btrfs/compression.c static void end_compressed_bio_read(struct bio *bio) · line 249
Quoted 7 lines
fs/btrfs/compression.c +0
-1@@ -244,7 +244,6 @@ static void end_compressed_bio_read(struct bio *bio)* Record the correct mirror_num in cb->orig_bio so that * read-repair can work properly. */ -ASSERT (btrfs_io_bio (cb->orig_bio));btrfs_io_bio (cb->orig_bio)->mirror_num = mirror; cb->mirror_num = mirror;
Thanks,
Josef
Re: [PATCH 6/8] btrfs: Remove needless ASSERT
In reply to Nikolay BorisovLooks good,
PATCH 7/8 btrfs: Increment corrupt device counter during compressed read
In reply to Nikolay BorisovIf a compressed read fails due to csum error only a line is printed to dmesg, device corrupt counter is not modified.
--- fs/btrfs/compression.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/btrfs/compression.c +6 -3
@@ -172,8 +172,7 @@ static inline int compressed_bio_size(struct btrfs_fs_info *fs_info, (DIV_ROUND_UP (disk_size, fs_info->sectorsize)) * csum_size; } -static int check_compressed_csum (struct btrfs_inode *inode, -struct compressed_bio *cb, +static int check_compressed_csum (struct btrfs_inode *inode,struct bio *bio,u64 disk_start) {struct btrfs_fs_info *fs_info = inode->root->fs_info;
@@ -184,6 +183,7 @@ static int check_compressed_csum(struct btrfs_inode *inode,unsigned long i;char *kaddr;u8 csum[BTRFS_CSUM_SIZE ]; +struct compressed_bio *cb = bio->bi_private;u8 *cb_sum = cb->sums;if (inode->flags &BTRFS_INODE_NODATASUM )
@@ -201,6 +201,9 @@ static int check_compressed_csum(struct btrfs_inode *inode,if (memcmp (&csum, cb_sum, csum_size)) {btrfs_print_data_csum_error (inode, disk_start, csum, cb_sum, cb->mirror_num); +if (btrfs_io_bio (bio)->dev) +btrfs_dev_stat_inc_and_print (btrfs_io_bio (bio)->dev, +BTRFS_DEV_STAT_CORRUPTION_ERRS ); ret = -EIO ; goto fail; }
@@ -255,7 +258,7 @@ static void end_compressed_bio_read(struct bio *bio) goto csum_failed; inode = cb->inode; - ret =check_compressed_csum (BTRFS_I (inode), cb, + ret =check_compressed_csum (BTRFS_I (inode), bio, (u64 )bio->bi_iter.bi_sector <<9 );if (ret) goto csum_failed;
Signature · 1 line
2.17.1
Re: [PATCH 7/8] btrfs: Increment corrupt device counter during compressed read
Quoted 4 lines · Nikolay Borisov
If a compressed read fails due to csum error only a line is printed to dmesg, device corrupt counter is not modified.
Signed-off-by Nikolay Borisov <[email protected]>
Thanks,
Josef
Re: [PATCH 7/8] btrfs: Increment corrupt device counter during compressed read
In reply to Nikolay BorisovLooks good,
PATCH 8/8 btrfs: sysfs: Add bdi link to the fsid dir
In reply to Nikolay BorisovSince BTRFS uses a private bdi it makes sense to create a link to this bdi under /sys/fs/btrfs/<UUID>/bdi. This allows size of read ahead to be controlled. Without this patch it's not possible to uniquely identify which bdi pertains to which btrfs filesystem in the fase of multiple btrfs filesystem.
--- fs/btrfs/ctree.h | 2 ++ fs/btrfs/sysfs.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +2 -0
@@ -928,6 +928,8 @@ struct btrfs_fs_info {u32 sectorsize;u32 stripesize; +bool bdi_link_created; +/* Block groups and devices containing active swapfiles. */ spinlock_t swapfile_pins_lock;struct rb_root swapfile_pins;
fs/btrfs/sysfs.c +14 -2
@@ -937,8 +937,13 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info) { +struct kobject *fsid_kobj = &fs_info->fs_devices->fsid_kobj; +btrfs_reset_fs_info_ptr (fs_info); +if (fs_info->bdi_link_created) +sysfs_remove_link (fsid_kobj,"bdi" ); +if (fs_info->space_info_kobj) {sysfs_remove_files (fs_info->space_info_kobj, allocation_attrs);kobject_del (fs_info->space_info_kobj);
@@ -958,8 +963,8 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info) }#endif addrm_unknown_feature_attrs (fs_info, false); -sysfs_remove_group (&fs_info->fs_devices->fsid_kobj, &btrfs_feature_attr_group); -sysfs_remove_files (&fs_info->fs_devices->fsid_kobj, btrfs_attrs); +sysfs_remove_group (fsid_kobj, &btrfs_feature_attr_group); +sysfs_remove_files (fsid_kobj, btrfs_attrs);btrfs_sysfs_remove_devices_dir (fs_info->fs_devices,NULL ); }
@@ -1410,6 +1415,13 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)if (error) goto failure; + error =sysfs_create_link (fsid_kobj, &fs_info->sb->s_bdi->dev->kobj, +"bdi" ); +if (error) + goto failure; + + fs_info->bdi_link_created = true; +#ifdef CONFIG_BTRFS_DEBUG fs_info->debug_kobj =kobject_create_and_add ("debug" , fsid_kobj);if (!fs_info->debug_kobj) {
Signature · 1 line
2.17.1
Re: [PATCH 8/8] btrfs: sysfs: Add bdi link to the fsid dir
Quoted 7 lines · Nikolay Borisov
Since BTRFS uses a private bdi it makes sense to create a link to this bdi under /sys/fs/btrfs/<UUID>/bdi. This allows size of read ahead to be controlled. Without this patch it's not possible to uniquely identify which bdi pertains to which btrfs filesystem in the fase of multiple btrfs filesystem.
Signed-off-by Nikolay Borisov <[email protected]>
Was confused why we needed to make sure the link existed before removing it, since other things sysfs is smart enough to figure out. Apparently it has a WARN_ON() if the parent isn't initialized, so the check is necessary, albeit annoying.
Thanks,
Josef
Re: [PATCH 8/8] btrfs: sysfs: Add bdi link to the fsid dir
Quoted 7 lines · Josef Bacik
Quoted 6 lines · Nikolay Borisov
Since BTRFS uses a private bdi it makes sense to create a link to this bdi under /sys/fs/btrfs/<UUID>/bdi. This allows size of read ahead to be controlled. Without this patch it's not possible to uniquely identify which bdi pertains to which btrfs filesystem in the fase of multiple btrfs filesystem.
Quoted 6 lines
Quoted 1 line
Signed-off-by Nikolay Borisov <[email protected]>Was confused why we needed to make sure the link existed before removing it, since other things sysfs is smart enough to figure out. Apparently it has a
WARN_ON()if the parent isn't initialized, so the check is necessary, albeit annoying.
There must be a better way, this is just too weird. We can check if objects have been initialized by peeking to kobject::state_initialized and we use that already for fsid_kobj in __btrfs_sysfs_remove_fsid or btrfs_sysfs_feature_update.
Re: [PATCH 8/8] btrfs: sysfs: Add bdi link to the fsid dir
Quoted 15 lines · David Sterba
Quoted 7 lines · Josef Bacik
Quoted 6 lines · Nikolay Borisov
Since BTRFS uses a private bdi it makes sense to create a link to this bdi under /sys/fs/btrfs/<UUID>/bdi. This allows size of read ahead to be controlled. Without this patch it's not possible to uniquely identify which bdi pertains to which btrfs filesystem in the fase of multiple btrfs filesystem.
Quoted 6 lines
Quoted 1 line
Signed-off-by Nikolay Borisov <[email protected]>Was confused why we needed to make sure the link existed before removing it, since other things sysfs is smart enough to figure out. Apparently it has a
WARN_ON()if the parent isn't initialized, so the check is necessary, albeit annoying.
Quoted 5 lines
There must be a better way, this is just too weird. We can check if objects have been initialized by peeking to
kobject::state_initializedand we use that already forfsid_kobjin__btrfs_sysfs_remove_fsidorbtrfs_sysfs_feature_update.
Awesome, will use this for v2.
PATCH v2 1/1 btrfs: sysfs: Add bdi link to the fsid dir
In reply to Nikolay BorisovSince BTRFS uses a private bdi it makes sense to create a link to this bdi under /sys/fs/btrfs/<UUID>/bdi. This allows size of read ahead to be controlled. Without this patch it's not possible to uniquely identify which bdi pertains to which btrfs filesystem in the fase of multiple btrfs filesystem.
It's fine to simply call sysfs_remove_link without checking if the link indeed has been created. The call path sysfs_remove_link
kernfs_remove_by_name
kernfs_remove_by_name_ns
Will simply return -ENOENT in case it doesn't exist.
---
V2: Remove variable signalling whether the 'bdi' symlinkn is created. Turns out it's not really neede for proper error handling.
fs/btrfs/sysfs.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
fs/btrfs/sysfs.c +11 -2
@@ -937,8 +937,12 @@ void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)void btrfs_sysfs_remove_mounted (struct btrfs_fs_info *fs_info) { +struct kobject *fsid_kobj = &fs_info->fs_devices->fsid_kobj; +btrfs_reset_fs_info_ptr (fs_info); +sysfs_remove_link (fsid_kobj,"bdi" ); +if (fs_info->space_info_kobj) {sysfs_remove_files (fs_info->space_info_kobj, allocation_attrs);kobject_del (fs_info->space_info_kobj);
@@ -958,8 +962,8 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info) }#endif addrm_unknown_feature_attrs (fs_info, false); -sysfs_remove_group (&fs_info->fs_devices->fsid_kobj, &btrfs_feature_attr_group); -sysfs_remove_files (&fs_info->fs_devices->fsid_kobj, btrfs_attrs); +sysfs_remove_group (fsid_kobj, &btrfs_feature_attr_group); +sysfs_remove_files (fsid_kobj, btrfs_attrs);btrfs_sysfs_remove_devices_dir (fs_info->fs_devices,NULL ); }
@@ -1439,6 +1443,11 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)if (error) goto failure; + error =sysfs_create_link (fsid_kobj, &fs_info->sb->s_bdi->dev->kobj, +"bdi" ); +if (error) + goto failure; + fs_info->space_info_kobj =kobject_create_and_add ("allocation" , fsid_kobj);if (!fs_info->space_info_kobj) {
--
2.17.1
Re: [PATCH v2] btrfs: sysfs: Add bdi link to the fsid dir
Quoted 4 lines · Nikolay Borisov
This series aims to make the device corrupt counter be incremented when we encounter checksum error. This stems from an upstream report at [0] that btrfs doesn't actually increment the corruption device stats counter. There's no good reason why this should be the case so here's a patchset rectifying this.
Yeah I think this was forgotten at the time the dev-stats were merged.
Quoted 16 lines
While looking around the code I thought the signature of the functions related to creating the failrec are somewhat quirky so the first 2 patches fix this.
Patch 3 introduces
btrfs_deviceintobtrfs_io_bioso that functions in the bio completion stack can use it.Patch 4 removes a redundant check
Next 3 patches wire in increment of the CORRUPT counter in the respective read end io routines, namely compressed and ordinary reads.
Last patch creates a symlink of the private bdi that btrfs creates on mount which is used in an xfstest for this series.
[0] https://lore.kernel.org/linux-btrfs/4857863.FCrPRfMyHP@liv/
Quoted 9 lines
Nikolay Borisov (8):
btrfs: Makeget_state_failrecreturn failrec directly
btrfs: Streamlinebtrfs_get_io_failure_recordlogic
btrfs: Recordbtrfs_devicedirectlybtrfs_io_bio
btrfs: Don't check forbtrfs_device::bdevinbtrfs_end_bio
btrfs: Increment device corruption error in case of checksum error
btrfs: Remove needless ASSERT
btrfs: Increment corrupt device counter during compressed read
btrfs: sysfs: Add bdi link to the fsid dir
This is pretty straightforward, thanks. I did some smallish changes like renaming the btrfs_io_bio::dev to device.
Updating the existing counter is in line with scrub so we don't have to change the on-disk stats.
Patchset is now in misc-next, I don't see any reason to keep it in a topic branch.