Zone write plugging fixes and cleanup
Subsystems (3)
Damien Le Moal
maintainercover Zone write plugging fixes and cleanup
Jens, Mike,
With more testing of zone write plugging on more device setups, including weird/test setups (with scsi debug and null_blk), several issues were identified. This patch series addresses them and cleanup the code a little to try to make it more obvious.
The first patch is a DM modification to not expose zoned devices composed solely of conventional zones as zoned block devices. The second patch is a fix partly related to this to expose a correct max open zones limit for devices with no limits (which DM devices are as the max open/active limit is not propagated to the mapped device as there is no easy way to do that).
Patches 3 to 9 are bug fixes. The most serious problem among theses was detected with tests using scsi_debug zoned devices and is fixed in patch 7.
Patches 10 to 13 improve and cleanup the code.
Damien Le Moal (13):
dm: Check that a zoned table leads to a valid mapped device
block: Exclude conventional zones when faking max open limit
block: Fix zone write plug initialization from blk_revalidate_zone_cb()
block: Fix reference counting for zone write plugs in error state
block: Hold a reference on zone write plugs to schedule submission
block: Unhash a zone write plug only if needed
block: Do not remove zone write plugs still in use
block: Fix flush request sector restore
block: Fix handling of non-empty flush write requests to zones
block: Improve blk_zone_write_plug_bio_merged()
block: Improve zone write request completion handling
block: Simplify blk_zone_write_plug_bio_endio()
block: Simplify zone write plug BIO abort
block/blk-flush.c | 3 +- block/blk-mq.c | 12 +- block/blk-zoned.c | 269 +++++++++++++++++++++++++++--------------- block/blk.h | 12 +- drivers/md/dm-table.c | 3 +- drivers/md/dm-zone.c | 53 +++++++++ 6 files changed, 243 insertions(+), 109 deletions(-)
Signature · 1 line
2.44.0
Damien Le Moal
maintainerPATCH 1/13 dm: Check that a zoned table leads to a valid mapped device
Using targets such as dm-linear, a mapped device can be created to contain only conventional zones. Such device should not be treated as zoned as it does not contain any mandatory sequential write required zone. Since such device can be randomly written, we can modify dm_set_zones_restrictions() to set the mapped device zoned queue limit to false to expose it as a regular block device. The function dm_check_zoned() does this after counting the number of conventional zones of the mapped device and comparing it to the total number of zones reported. The special dm_check_zoned_cb() report zones callback function is used to count conventional zones.
--- drivers/md/dm-table.c | 3 ++- drivers/md/dm-zone.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-)
drivers/md/dm-table.c +2 -1
@@ -2042,7 +2042,8 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, r =dm_set_zones_restrictions (t, q);if (r)return r; -if (!static_key_enabled (&zoned_enabled.key)) +if (blk_queue_is_zoned (q) && + !static_key_enabled (&zoned_enabled.key))static_branch_enable (&zoned_enabled); }
drivers/md/dm-zone.c +53 -0
71 lines not on this page · raw message
Signature · 1 line
2.44.0
Damien Le Moal
maintainerPATCH 2/13 block: Exclude conventional zones when faking max open limit
In reply to Damien Le MoalFor a device that has no limits for the maximum number of open and active zones, we default to using the number of zones, limited to BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE (128), for the maximum number of open zones indicated to the user. However, for a device that has conventional zones and less zones than BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE, we should not account conventional zones and set the limit to the number of sequential write required zones. Furthermore, for cases where the limit is equal to the number of sequential write required zones, we can advertize a limit of 0 to indicate "no limits".
Fix this by moving the zone write plug mempool resizing from disk_revalidate_zone_resources() to disk_update_zone_resources() where we can safely compute the number of conventional zones and update the limits.
--- block/blk-zoned.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-)
block/blk-zoned.c +31 -11
@@ -1513,10 +1513,6 @@ static int disk_revalidate_zone_resources(struct gendisk *disk,if (!disk->zone_wplugs_hash)return disk_alloc_zone_resources (disk, pool_size); -/* Resize the zone write plug memory pool if needed. */ -if (disk->zone_wplugs_pool->min_nr != pool_size) -return mempool_resize (disk->zone_wplugs_pool, pool_size); -return 0 ; }
@@ -1536,27 +1532,51 @@ static int disk_update_zone_resources(struct gendisk *disk, struct blk_revalidate_zone_args *args) {struct request_queue *q = disk->queue; +unsigned int nr_seq_zones, nr_conv_zones =0 ; +unsigned int pool_size;struct queue_limits lim; disk->nr_zones = args->nr_zones; disk->zone_capacity = args->zone_capacity;swap (disk->conv_zones_bitmap, args->conv_zones_bitmap); +if (disk->conv_zones_bitmap) + nr_conv_zones =bitmap_weight (disk->conv_zones_bitmap, + disk->nr_zones); +if (nr_conv_zones >= disk->nr_zones) { +pr_warn ("%s: Invalid number of conventional zones %u / %u\n" , + disk->disk_name, nr_conv_zones, disk->nr_zones); +return -ENODEV ; + } + +if (!disk->zone_wplugs_pool) +return 0 ;/* -* If the device has no limit on the maximum number of open and active +* If the device has no limits on the maximum number of open and active * zones, set its max open zone limit to the mempool size to indicate * to the user that there is a potential performance impact due to * dynamic zone write plug allocation when simultaneously writing to * more zones than the size of the mempool. */ -if (disk->zone_wplugs_pool) { - lim =queue_limits_start_update (q); -if (!lim.max_open_zones && !lim.max_active_zones) - lim.max_open_zones = disk->zone_wplugs_pool->min_nr; -return queue_limits_commit_update (q, &lim); + lim =queue_limits_start_update (q); + + nr_seq_zones = disk->nr_zones - nr_conv_zones; + pool_size =max (lim.max_open_zones, lim.max_active_zones); +if (!pool_size) + pool_size =min (BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE , nr_seq_zones); + +/* Resize the zone write plug memory pool if needed. */ +if (disk->zone_wplugs_pool->min_nr != pool_size) +mempool_resize (disk->zone_wplugs_pool, pool_size); + +if (!lim.max_open_zones && !lim.max_active_zones) { +if (pool_size < nr_seq_zones) + lim.max_open_zones = pool_size; +else + lim.max_open_zones =0 ; } -return 0 ; +return queue_limits_commit_update (q, &lim); }/*
Signature · 1 line
2.44.0
Re: [PATCH 02/13] block: Exclude conventional zones when faking max open limit
block/blk-zoned.c static int disk_update_zone_resources(struct gendisk *disk, · line 1570
Quoted 3 lines · Damien Le Moal
block/blk-zoned.c +3
-0+/* Resize the zone write plug memory pool if needed. */ +if (disk->zone_wplugs_pool->min_nr != pool_size) +mempool_resize (disk->zone_wplugs_pool, pool_size);
No need for the if here, mempool_resize is a no-op if called for the current value.
Otherwise looks good:
Jens Axboe
maintainerRe: [PATCH 02/13] block: Exclude conventional zones when faking max open limit
Quoted 7 lines · Christoph Hellwig
block/blk-zoned.c static int disk_update_zone_resources(struct gendisk *disk, · line 1570
Quoted 3 lines · Damien Le Moal
block/blk-zoned.c +3
-0+/* Resize the zone write plug memory pool if needed. */ +if (disk->zone_wplugs_pool->min_nr != pool_size) +mempool_resize (disk->zone_wplugs_pool, pool_size);No need for the if here,
mempool_resizeis a no-op if called for the current value.
Still cheaper than the function call though, so I think that's the right way to do it.
Signature · 1 line
Jens Axboe
Re: [PATCH 02/13] block: Exclude conventional zones when faking max open limit
Quoted 11 lines · Jens Axboe
Quoted 7 lines · Christoph Hellwig
block/blk-zoned.c static int disk_update_zone_resources(struct gendisk *disk, · line 1570
Quoted 3 lines · Damien Le Moal
block/blk-zoned.c +3
-0+/* Resize the zone write plug memory pool if needed. */ +if (disk->zone_wplugs_pool->min_nr != pool_size) +mempool_resize (disk->zone_wplugs_pool, pool_size);No need for the if here,
mempool_resizeis a no-op if called for the current value.Still cheaper than the function call though, so I think that's the right way to do it.
It is only called during device probing and resize. Try to avoid the call and spinlock there is the poster definition of premature micro-optimization..
Damien Le Moal
maintainerPATCH 3/13 block: Fix zone write plug initialization from blk_revalidate_zone_cb()
In reply to Damien Le MoalWhen revalidating the zones of a zoned block device, blk_revalidate_zone_cb() must allocate a zone write plug for any sequential write required zone that is not empty nor full. However, the current code tests the latter case by comparing the zone write pointer offset to the zone size instead of the zone capacity. Furthermore, disk_get_and_lock_zone_wplug() is called with a sector argument equal to the zone start instead of the current zone write pointer position. This commit fixes both issues by calling disk_get_and_lock_zone_wplug() for a zone that is not empty and with a write pointer offset lower than the zone capacity and use the zone capacity sector as the sector argument for disk_get_and_lock_zone_wplug().
--- block/blk-zoned.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
block/blk-zoned.c +4 -3
@@ -1666,10 +1666,11 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx,* empty nor full. So make sure we have a zone write plug for * such zone if the device has a zone write plug hash table. */ +if (!disk->zone_wplugs_hash) +break ; wp_offset =blk_zone_wp_offset (zone); -if (disk->zone_wplugs_hash && - wp_offset && wp_offset < zone_sectors) { - zwplug =disk_get_and_lock_zone_wplug (disk, zone->start, +if (wp_offset && wp_offset < zone->capacity) { + zwplug =disk_get_and_lock_zone_wplug (disk, zone->wp,GFP_NOIO , &flags);if (!zwplug)return -ENOMEM ;
Signature · 1 line
2.44.0
Re: [PATCH 03/13] block: Fix zone write plug initialization from blk_revalidate_zone_cb()
Looks good:
Although I suspect that at some point blk_revalidate_zone_cb should grow separate helpers for the conventional and sequential required cases as the amount of code in that switch statement is getting a bit out of bounds..
Damien Le Moal
maintainerRe: [PATCH 03/13] block: Fix zone write plug initialization from blk_revalidate_zone_cb()
Quoted 8 lines · Christoph Hellwig
Looks good:
Reviewed-by Christoph Hellwig <[email protected]>Although I suspect that at some point
blk_revalidate_zone_cbshould grow separate helpers for the conventional and sequential required cases as the amount of code in that switch statement is getting a bit out of bounds..
Yep, will clean that up later (next cycle).
Signature · 2 lines
Damien Le Moal Western Digital Research
Damien Le Moal
maintainerRe: [PATCH 03/13] block: Fix zone write plug initialization from blk_revalidate_zone_cb()
Quoted 11 lines · Damien Le Moal
Quoted 8 lines · Christoph Hellwig
Looks good:
Reviewed-by Christoph Hellwig <[email protected]>Although I suspect that at some point
blk_revalidate_zone_cbshould grow separate helpers for the conventional and sequential required cases as the amount of code in that switch statement is getting a bit out of bounds..Yep, will clean that up later (next cycle).
I did it now. It is a nice cleanup. I added a patch to the series for that.
Signature · 2 lines
Damien Le Moal Western Digital Research
Damien Le Moal
maintainerPATCH 4/13 block: Fix reference counting for zone write plugs in error state
In reply to Damien Le MoalWhen zone is reset or finished, disk_zone_wplug_set_wp_offset() is called to update the zone write plug write pointer offset and to clear the zone error state (BLK_ZONE_WPLUG_ERROR flag) if it is set. However, this processing is missing dropping the reference to the zone write plug that was taken in disk_zone_wplug_set_error() when the error flag was first set. Furthermore, the error state handling must release the zone write plug lock to first execute a report zones command. When the report zone races with a reset or finish operation that clears the error, we can end up decrementing the zone write plug reference count
twice: once in disk_zone_wplug_set_wp_offset() for the reset/finish operation and one more time in disk_zone_wplugs_work() once disk_zone_wplug_handle_error() completes.
Fix this by introducing disk_zone_wplug_clear_error() as the symmetric function of disk_zone_wplug_set_error(). disk_zone_wplug_clear_error() decrements the zone write plug reference count obtained in disk_zone_wplug_set_error() only if the error handling has not started yet, that is, only if disk_zone_wplugs_work() has not yet taken the zone write plug off the error list. This ensure that either disk_zone_wplug_clear_error() or disk_zone_wplugs_work() drop the zone write plug reference count.
--- block/blk-zoned.c | 74 ++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 26 deletions(-)
block/blk-zoned.c +48 -26
@@ -658,6 +658,53 @@ static void disk_zone_wplug_abort_unaligned(struct gendisk *disk,bio_list_merge (&zwplug->bio_list, &bl); } +static inline void disk_zone_wplug_set_error (struct gendisk *disk, +struct blk_zone_wplug *zwplug) +{ +if (!(zwplug->flags &BLK_ZONE_WPLUG_ERROR )) { +unsigned long flags; + +/* +* At this point, we already have a reference on the zone write +* plug. However, since we are going to add the plug to the disk +* zone write plugs work list, increase its reference count. +* This reference will be dropped in disk_zone_wplugs_work() +* once the error state is handled, or +* in disk_zone_wplug_clear_error() if the zone is reset or +* finished. +*/ + zwplug->flags |=BLK_ZONE_WPLUG_ERROR ; +atomic_inc (&zwplug->ref); + +spin_lock_irqsave (&disk->zone_wplugs_lock, flags); +list_add_tail (&zwplug->link, &disk->zone_wplugs_err_list); +spin_unlock_irqrestore (&disk->zone_wplugs_lock, flags); + } +} + +static inline void disk_zone_wplug_clear_error (struct gendisk *disk, +struct blk_zone_wplug *zwplug) +{ +if (zwplug->flags &BLK_ZONE_WPLUG_ERROR ) { +unsigned long flags; + +/* +* We are racing with the error handling work which drops +* the reference on the zone write plug after handling the error +* state. So remove the plug from the error list and drop its +* reference count only if the error handling has not yet +* started, that is, if the zone write plug is still listed. +*/ +spin_lock_irqsave (&disk->zone_wplugs_lock, flags); +if (!list_empty (&zwplug->link)) { +list_del_init (&zwplug->link); + zwplug->flags &= ~BLK_ZONE_WPLUG_ERROR ; +disk_put_zone_wplug (zwplug); + } +spin_unlock_irqrestore (&disk->zone_wplugs_lock, flags); + } +} +/* * Set a zone write plug write pointer offset to either 0 (zone reset case) * or to the zone size (zone finish case). This aborts all plugged BIOs, which
@@ -691,12 +738,7 @@ static void disk_zone_wplug_set_wp_offset(struct gendisk *disk,* in a good state. So clear the error flag and decrement the * error count if we were in error state. */ -if (zwplug->flags &BLK_ZONE_WPLUG_ERROR ) { - zwplug->flags &= ~BLK_ZONE_WPLUG_ERROR ; -spin_lock (&disk->zone_wplugs_lock); -list_del_init (&zwplug->link); -spin_unlock (&disk->zone_wplugs_lock); - } +disk_zone_wplug_clear_error (disk, zwplug);/* * The zone write plug now has no BIO plugged: remove it from the
@@ -885,26 +927,6 @@ void blk_zone_write_plug_attempt_merge(struct request *req)spin_unlock_irqrestore (&zwplug->lock, flags); } -static inline void disk_zone_wplug_set_error (struct gendisk *disk, -struct blk_zone_wplug *zwplug) -{ -if (!(zwplug->flags &BLK_ZONE_WPLUG_ERROR )) { -unsigned long flags; - -/* -* Increase the plug reference count. The reference will be -* dropped in disk_zone_wplugs_work() once the error state -* is handled. -*/ - zwplug->flags |=BLK_ZONE_WPLUG_ERROR ; -atomic_inc (&zwplug->ref); - -spin_lock_irqsave (&disk->zone_wplugs_lock, flags); -list_add_tail (&zwplug->link, &disk->zone_wplugs_err_list); -spin_unlock_irqrestore (&disk->zone_wplugs_lock, flags); - } -} -/* * Check and prepare a BIO for submission by incrementing the write pointer * offset of its zone write plug and changing zone append operations into
Signature · 1 line
2.44.0
Re: [PATCH 04/13] block: Fix reference counting for zone write plugs in error state
block/blk-zoned.c static void disk_zone_wplug_abort_unaligned(struct gendisk *disk, · line 664
Quoted 5 lines
block/blk-zoned.c +4
-0+static inline void disk_zone_wplug_set_error (struct gendisk *disk, +struct blk_zone_wplug *zwplug) +{ +if (!(zwplug->flags &BLK_ZONE_WPLUG_ERROR )) {
Can you just do an early return if the flag is not set instead of all the extra indentation?
block/blk-zoned.c static void disk_zone_wplug_abort_unaligned(struct gendisk *disk, · line 688
Quoted 4 lines
block/blk-zoned.c +4
-0+static inline void disk_zone_wplug_clear_error (struct gendisk *disk, +struct blk_zone_wplug *zwplug) +{ +if (zwplug->flags &BLK_ZONE_WPLUG_ERROR ) {
Same here.
Otherwise looks good:
Damien Le Moal
maintainerPATCH 5/13 block: Hold a reference on zone write plugs to schedule submission
In reply to Damien Le MoalSince a zone write plug BIO work is a field of struct blk_zone_wplug, we must ensure that a zone write plug is never freed when its BIO submission work is queued or running. Do this by holding a reference on the zone write plug when the submission work is scheduled for execution with queue_work() and releasing the reference at the end of the execution of the work function blk_zone_wplug_bio_work(). The helper function disk_zone_wplug_schedule_bio_work() is introduced to get a reference on a zone write plug and queue its work. This helper is used in disk_zone_wplug_unplug_bio() and disk_zone_wplug_handle_error().
--- block/blk-zoned.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
block/blk-zoned.c +21 -5
@@ -1131,6 +1131,19 @@ bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs) }EXPORT_SYMBOL_GPL (blk_zone_plug_bio); +static void disk_zone_wplug_schedule_bio_work (struct gendisk *disk, +struct blk_zone_wplug *zwplug) +{ +/* +* Take a reference on the zone write plug and schedule the submission +* of the next plugged BIO. blk_zone_wplug_bio_work() will release the +* reference we take here. +*/ +WARN_ON_ONCE (!(zwplug->flags &BLK_ZONE_WPLUG_PLUGGED )); +atomic_inc (&zwplug->ref); +queue_work (disk->zone_wplugs_wq, &zwplug->bio_work); +} +static void disk_zone_wplug_unplug_bio (struct gendisk *disk,struct blk_zone_wplug *zwplug) {
@@ -1150,8 +1163,8 @@ static void disk_zone_wplug_unplug_bio(struct gendisk *disk,/* Schedule submission of the next plugged BIO if we have one. */ if (!bio_list_empty (&zwplug->bio_list)) { +disk_zone_wplug_schedule_bio_work (disk, zwplug);spin_unlock_irqrestore (&zwplug->lock, flags); -queue_work (disk->zone_wplugs_wq, &zwplug->bio_work);return ; }
@@ -1251,14 +1264,14 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)if (!bio) { zwplug->flags &= ~BLK_ZONE_WPLUG_PLUGGED ;spin_unlock_irqrestore (&zwplug->lock, flags); -return ; + goto put_zwplug; }if (!blk_zone_wplug_prepare_bio (zwplug, bio)) {/* Error recovery will decide what to do with the BIO. */ bio_list_add_head (&zwplug->bio_list, bio);spin_unlock_irqrestore (&zwplug->lock, flags); -return ; + goto put_zwplug; }spin_unlock_irqrestore (&zwplug->lock, flags);
@@ -1274,6 +1287,10 @@ static void blk_zone_wplug_bio_work(struct work_struct *work)*/ if (bdev->bd_has_submit_bio)blk_queue_exit (bdev->bd_disk->queue); + +put_zwplug: +/* Drop the reference we took in disk_zone_wplug_schedule_bio_work(). */ +disk_put_zone_wplug (zwplug); }static unsigned int blk_zone_wp_offset (struct blk_zone *zone)
@@ -1353,8 +1370,7 @@ static void disk_zone_wplug_handle_error(struct gendisk *disk,/* Restart BIO submission if we still have any BIO left. */ if (!bio_list_empty (&zwplug->bio_list)) { -WARN_ON_ONCE (!(zwplug->flags &BLK_ZONE_WPLUG_PLUGGED )); -queue_work (disk->zone_wplugs_wq, &zwplug->bio_work); +disk_zone_wplug_schedule_bio_work (disk, zwplug); goto unlock; }
Signature · 1 line
2.44.0
Re: [PATCH 05/13] block: Hold a reference on zone write plugs to schedule submission
Looks good:
Damien Le Moal
maintainerPATCH 6/13 block: Unhash a zone write plug only if needed
In reply to Damien Le MoalFix disk_remove_zone_wplug() to ensure that a zone write plug already removed from a disk hash table of zone write plugs is not removed again. Do this by checking the BLK_ZONE_WPLUG_UNHASHED flag of the plug and calling hlist_del_init_rcu() only if the flag is not set.
Furthermore, since BIO completions can happen at any time, that is, decrementing of the zone write plug reference count can happen at any time, make sure to use disk_put_zone_wplug() instead of atomic_dec() to ensure that the zone write plug is freed when its last reference is dropped. In order to do this, disk_remove_zone_wplug() is moved after the definition of disk_put_zone_wplug(). disk_should_remove_zone_wplug() is moved as well to keep it together with disk_remove_zone_wplug().
To be consistent with this change, add a check in disk_put_zone_wplug() to ensure that a zone write plug being freed was already removed from the disk hash table.
--- block/blk-zoned.c | 54 +++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 23 deletions(-)
block/blk-zoned.c +31 -23
@@ -476,29 +476,6 @@ static bool disk_insert_zone_wplug(struct gendisk *disk,return true; } -static void disk_remove_zone_wplug (struct gendisk *disk, -struct blk_zone_wplug *zwplug) -{ -unsigned long flags; - -spin_lock_irqsave (&disk->zone_wplugs_lock, flags); - zwplug->flags |=BLK_ZONE_WPLUG_UNHASHED ; -atomic_dec (&zwplug->ref); -hlist_del_init_rcu (&zwplug->node); -spin_unlock_irqrestore (&disk->zone_wplugs_lock, flags); -} - -static inline bool disk_should_remove_zone_wplug (struct gendisk *disk, -struct blk_zone_wplug *zwplug) -{ -/* If the zone is still busy, the plug cannot be removed. */ -if (zwplug->flags &BLK_ZONE_WPLUG_BUSY ) -return false; - -/* We can remove zone write plugs for zones that are empty or full. */ -return !zwplug->wp_offset || zwplug->wp_offset >= disk->zone_capacity; -} -static struct blk_zone_wplug *disk_get_zone_wplug (struct gendisk *disk,sector_t sector) {
@@ -534,11 +511,42 @@ static inline void disk_put_zone_wplug(struct blk_zone_wplug *zwplug)if (atomic_dec_and_test (&zwplug->ref)) {WARN_ON_ONCE (!bio_list_empty (&zwplug->bio_list));WARN_ON_ONCE (!list_empty (&zwplug->link)); +WARN_ON_ONCE (!(zwplug->flags &BLK_ZONE_WPLUG_UNHASHED ));call_rcu (&zwplug->rcu_head, disk_free_zone_wplug_rcu); } } +static inline bool disk_should_remove_zone_wplug (struct gendisk *disk, +struct blk_zone_wplug *zwplug) +{ +/* If the zone is still busy, the plug cannot be removed. */ +if (zwplug->flags &BLK_ZONE_WPLUG_BUSY ) +return false; + +/* We can remove zone write plugs for zones that are empty or full. */ +return !zwplug->wp_offset || zwplug->wp_offset >= disk->zone_capacity; +} + +static void disk_remove_zone_wplug (struct gendisk *disk, +struct blk_zone_wplug *zwplug) +{ +if (!(zwplug->flags &BLK_ZONE_WPLUG_UNHASHED )) { +unsigned long flags; + +/* +* Mark the zone write plug as unhashed and drop the extra +* reference we took when the plug was inserted in the hash +* table. +*/ + zwplug->flags |=BLK_ZONE_WPLUG_UNHASHED ; +spin_lock_irqsave (&disk->zone_wplugs_lock, flags); +hlist_del_init_rcu (&zwplug->node); +spin_unlock_irqrestore (&disk->zone_wplugs_lock, flags); +disk_put_zone_wplug (zwplug); + } +} +static void blk_zone_wplug_bio_work (struct work_struct *work);/*
Signature · 1 line
2.44.0
Re: [PATCH 06/13] block: Unhash a zone write plug only if needed
Looks good:
Damien Le Moal
maintainerPATCH 7/13 block: Do not remove zone write plugs still in use
In reply to Damien Le MoalLarge write BIOs that span a zone boundary are split in blk_mq_submit_bio() before being passed to blk_zone_plug_bio() for zone write plugging. Such split BIO will be chained with one fragment targeting one zone and the remainder of the BIO tergetting the next zone. The two BIOs can be executed in parallel, without a predetermine order relative to eachother and their completion may be reversed: the remainder first completing and the first fragment then completing. In such case, bio_endio() will not immediately execute blk_zone_write_plug_bio_endio() for the parent BIO (the remainder of the split BIO) as the BIOs are chained. blk_zone_write_plug_bio_endio() for the parent BIO will be executed only once the first fragment completes.
In the case of a device with small zones and very large BIOs, uch completion pattern can lead to disk_should_remove_zone_wplug() to return true for the zone of the parent BIO when the parent BIO request completes and blk_zone_write_plug_complete_request() is executed. This triggers the removal of the zone write plug from the hash table using disk_remove_zone_wplug(). With the zone write plug of the parent BIO missing, the call to disk_get_zone_wplug() in blk_zone_write_plug_bio_endio() returns NULL and triggers a warning.
This patterns can be recreated fairly easily using a scsi_debug device with small zone and btrfs. E.g.
modprobe scsi_debug delay=0 dev_size_mb=1024 sector_size=4096 \
zbc=host-managed zone_cap_mb=3 zone_nr_conv=0 zone_size_mb=4
mkfs.btrfs -f -O zoned /dev/sda
mount -t btrfs /dev/sda /mnt
fio --name=wrtest --rw=randwrite --direct=1 --ioengine=libaio \ --bs=4k --iodepth=16 --size=1M --directory=/mnt --time_based \ --runtime=10
umount /dev/sda
Will result in the warning:
[ 29.035538] WARNING: CPU: 3 PID: 37 at block/blk-zoned.c:1207 blk_zone_write_plug_bio_endio+0xee/0x1e0 ... [ 29.058682] Call Trace: [ 29.059095] <TASK> [ 29.059473] ? __warn+0x80/0x120 [ 29.059983] ? blk_zone_write_plug_bio_endio+0xee/0x1e0 [ 29.060728] ? report_bug+0x160/0x190 [ 29.061283] ? handle_bug+0x36/0x70 [ 29.061830] ? exc_invalid_op+0x17/0x60 [ 29.062399] ? asm_exc_invalid_op+0x1a/0x20 [ 29.063025] ? blk_zone_write_plug_bio_endio+0xee/0x1e0 [ 29.063760] bio_endio+0xb7/0x150 [ 29.064280] btrfs_clone_write_end_io+0x2b/0x60 [btrfs] [ 29.065049] blk_update_request+0x17c/0x500 [ 29.065666] scsi_end_request+0x27/0x1a0 [scsi_mod] [ 29.066356] scsi_io_completion+0x5b/0x690 [scsi_mod] [ 29.067077] blk_complete_reqs+0x3a/0x50 [ 29.067692] __do_softirq+0xcf/0x2b3 [ 29.068248] ? sort_range+0x20/0x20 [ 29.068791] run_ksoftirqd+0x1c/0x30 [ 29.069339] smpboot_thread_fn+0xcc/0x1b0 [ 29.069936] kthread+0xcf/0x100 [ 29.070438] ? kthread_complete_and_exit+0x20/0x20 [ 29.071314] ret_from_fork+0x31/0x50 [ 29.071873] ? kthread_complete_and_exit+0x20/0x20 [ 29.072563] ret_from_fork_asm+0x11/0x20 [ 29.073146] </TASK>
either when fio executes or when unmount is executed.
Fix this by modifying disk_should_remove_zone_wplug() to check that the reference count to a zone write plug is not larger than 2, that is, that the only references left on the zone are the caller held reference (blk_zone_write_plug_complete_request()) and the initial extra reference for the zone write plug taken when it was initialized (and that is dropped when the zone write plug is removed from the hash table).
To be consistent with this change, make sure to drop the request or BIO held reference to the zone write plug before calling disk_zone_wplug_unplug_bio(). All references are also dropped using disk_put_zone_wplug() instead of atomic_dec() to ensure that the zone write plug is freed if it needs to be.
Comments are also improved to clarify zone write plugs reference handling.
--- block/blk-zoned.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
block/blk-zoned.c +15 -9
@@ -520,8 +520,9 @@ static inline void disk_put_zone_wplug(struct blk_zone_wplug *zwplug)static inline bool disk_should_remove_zone_wplug (struct gendisk *disk,struct blk_zone_wplug *zwplug) { -/* If the zone is still busy, the plug cannot be removed. */ -if (zwplug->flags &BLK_ZONE_WPLUG_BUSY ) +/* If the zone write plug is still busy, it cannot be removed. */ +if ((zwplug->flags &BLK_ZONE_WPLUG_BUSY ) || +atomic_read (&zwplug->ref) >2 )return false;/* We can remove zone write plugs for zones that are empty or full. */
@@ -891,8 +892,9 @@ void blk_zone_write_plug_attempt_merge(struct request *req)struct bio *bio;/* -* Completion of this request needs to be handled with -* blk_zone_write_plug_complete_request(). +* Indicate that completion of this request needs to be handled with +* blk_zone_write_plug_complete_request(), which will drop the reference +* on the zone write plug we took above on entry to this function. */ req->rq_flags |=RQF_ZONE_WRITE_PLUGGING ;
@@ -1221,6 +1223,9 @@ void blk_zone_write_plug_bio_endio(struct bio *bio)spin_unlock_irqrestore (&zwplug->lock, flags); } +/* Drop the reference we took when the BIO was issued. */ +disk_put_zone_wplug (zwplug); +/* * For BIO-based devices, blk_zone_write_plug_complete_request() * is not called. So we need to schedule execution of the next
@@ -1229,8 +1234,7 @@ void blk_zone_write_plug_bio_endio(struct bio *bio)if (bio->bi_bdev->bd_has_submit_bio)disk_zone_wplug_unplug_bio (disk, zwplug); -/* Drop the reference we took when the BIO was issued. */ -atomic_dec (&zwplug->ref); +/* Drop the reference we took when entering this function. */ disk_put_zone_wplug (zwplug); }
@@ -1244,13 +1248,15 @@ void blk_zone_write_plug_complete_request(struct request *req) req->rq_flags &= ~RQF_ZONE_WRITE_PLUGGING ; -disk_zone_wplug_unplug_bio (disk, zwplug); -/* * Drop the reference we took when the request was initialized in * blk_zone_write_plug_attempt_merge(). */ -atomic_dec (&zwplug->ref); +disk_put_zone_wplug (zwplug); + +disk_zone_wplug_unplug_bio (disk, zwplug); + +/* Drop the reference we took when entering this function. */ disk_put_zone_wplug (zwplug); }
Signature · 1 line
2.44.0
Re: [PATCH 07/13] block: Do not remove zone write plugs still in use
Quoted 4 lines · Damien Le Moal
Large write BIOs that span a zone boundary are split in
blk_mq_submit_bio()before being passed toblk_zone_plug_bio()for zone write plugging. Such split BIO will be chained with one fragment targeting one zone and the remainder of the BIO tergetting the next
s/tergetting/targetting/
Quoted 6 lines
Fix this by modifying
disk_should_remove_zone_wplug()to check that the reference count to a zone write plug is not larger than 2, that is, that the only references left on the zone are the caller held reference (blk_zone_write_plug_complete_request()) and the initial extra reference for the zone write plug taken when it was initialized (and that is dropped when the zone write plug is removed from the hash table).
How is this atomic_read() based check not racy?
Damien Le Moal
maintainerRe: [PATCH 07/13] block: Do not remove zone write plugs still in use
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines
Fix this by modifying
disk_should_remove_zone_wplug()to check that the reference count to a zone write plug is not larger than 2, that is, that the only references left on the zone are the caller held reference (blk_zone_write_plug_complete_request()) and the initial extra reference for the zone write plug taken when it was initialized (and that is dropped when the zone write plug is removed from the hash table).How is this
atomic_read()based check not racy?
Because of how references work:
1) A valid and unused zone write plug has a ref count of 1
2) A function using a write plug always has a reference on it, so if the plug is valid and unused, the ref count is always 2
3) Any plugged BIO and in-flight BIOs and requests hold a reference on the plug. So if the plug is used for BIOs, the reference count is always at least 2, and when a function is using the plug the refcount is always at least 3
Based on this, all callers of disk_should_remove_zone_wplug() will always see a refcount of 2 if the plug is unused, or more than 2 if the plug is being used to handle BIOs. Most of the time, checking for the BUSY (PLUGGED) flag catches the later case. But as explained in the commit message, chained BIOs due to splits can lead to bio_endio() execution order to change and to calls to blk_zone_write_plug_bio_endio() to be done after blk_zone_write_plug_finish_request() calls disk_zone_wplug_unplug_bio(). Checking that the plug refcount is not more than 2 tells us reliably that BIOs are still holding references on the plug and that the plug should not be removed until all BIOs completions are handled.
Does this answer your question ?
Signature · 2 lines
Damien Le Moal Western Digital Research
Damien Le Moal
maintainerRe: [PATCH 07/13] block: Do not remove zone write plugs still in use
Quoted 29 lines · Damien Le Moal
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines
Fix this by modifying
disk_should_remove_zone_wplug()to check that the reference count to a zone write plug is not larger than 2, that is, that the only references left on the zone are the caller held reference (blk_zone_write_plug_complete_request()) and the initial extra reference for the zone write plug taken when it was initialized (and that is dropped when the zone write plug is removed from the hash table).How is this
atomic_read()based check not racy?Because of how references work:
1) A valid and unused zone write plug has a ref count of 1
2) A function using a write plug always has a reference on it, so if the plug is valid and unused, the ref count is always 2
3) Any plugged BIO and in-flight BIOs and requests hold a reference on the plug. So if the plug is used for BIOs, the reference count is always at least 2, and when a function is using the plug the refcount is always at least 3Based on this, all callers of
disk_should_remove_zone_wplug()will always see a refcount of 2 if the plug is unused, or more than 2 if the plug is being used to handle BIOs. Most of the time, checking for the BUSY (PLUGGED) flag catches the later case. But as explained in the commit message, chained BIOs due to splits can lead tobio_endio()execution order to change and to calls toblk_zone_write_plug_bio_endio()to be done afterblk_zone_write_plug_finish_request()callsdisk_zone_wplug_unplug_bio(). Checking that the plug refcount is not more than 2 tells us reliably that BIOs are still holding references on the plug and that the plug should not be removed until all BIOs completions are handled.
Quoted 1 line
Does this answer your question ?
I modified the patch to add a comment in disk_should_remove_zone_wplug() explaining the above.
Signature · 2 lines
Damien Le Moal Western Digital Research
Damien Le Moal
maintainerPATCH 8/13 block: Fix flush request sector restore
In reply to Damien Le MoalMake sure that a request bio is not NULL before trying to restore the request start sector.
--- block/blk-flush.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/blk-flush.c +2 -1
@@ -130,7 +130,8 @@ static void blk_flush_restore_request(struct request *rq)* original @rq->bio. Restore it. */ rq->bio = rq->biotail; - rq->__sector = rq->bio->bi_iter.bi_sector; +if (rq->bio) + rq->__sector = rq->bio->bi_iter.bi_sector;/* make @rq a normal request */ rq->rq_flags &= ~RQF_FLUSH_SEQ ;
Signature · 1 line
2.44.0
Re: [PATCH 08/13] block: Fix flush request sector restore
Quoted 2 lines · Damien Le Moal
Make sure that a request bio is not NULL before trying to restore the request start sector.
Looks good:
Damien Le Moal
maintainerPATCH 9/13 block: Fix handling of non-empty flush write requests to zones
In reply to Damien Le MoalZone write plugging ignores empty (no data) flush operations but handles flush BIOs that have data to ensure that the flush machinery generated write is processed in order. However, the call to blk_zone_write_plug_attempt_merge() which sets a request RQF_ZONE_WRITE_PLUGGING flag is called after blk_insert_flush(), thus missing indicating that a non empty flush request completion needs handling by zone write plugging.
Fix this by moving the call to blk_zone_write_plug_attempt_merge() before blk_insert_flush(). And while at it, rename that function as blk_zone_write_plug_init_request() to be clear that it is not just about merging plugged BIOs in the request. While at it, also add a WARN_ONCE() check that the zone write plug for the request is not NULL.
--- block/blk-mq.c | 6 +++--- block/blk-zoned.c | 12 ++++++++---- block/blk.h | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-)
block/blk-mq.c +3 -3
@@ -3001,12 +3001,12 @@ void blk_mq_submit_bio(struct bio *bio)return ; } +if (bio_zone_write_plugging (bio)) +blk_zone_write_plug_init_request (rq); +if (op_is_flush (bio->bi_opf) &&blk_insert_flush (rq))return ; -if (bio_zone_write_plugging (bio)) -blk_zone_write_plug_attempt_merge (rq); -if (plug) {blk_add_rq_to_plug (plug, rq);return ;
block/blk-zoned.c +8 -4
@@ -855,8 +855,9 @@ void blk_zone_write_plug_bio_merged(struct bio *bio)/* * If the BIO was already plugged, then we were called through -* blk_zone_write_plug_attempt_merge() -> blk_attempt_bio_merge(). -* For this case, blk_zone_write_plug_attempt_merge() will handle the +* blk_zone_write_plug_init_request() -> blk_attempt_bio_merge(). +* For this case, we already hold a reference on the zone write plug for +* the BIO and blk_zone_write_plug_init_request() will handle the * zone write pointer offset update. */ if (bio_flagged (bio,BIO_ZONE_WRITE_PLUGGING ))
@@ -880,7 +881,7 @@ void blk_zone_write_plug_bio_merged(struct bio *bio)* already went through zone write plugging (either a new BIO or one that was * unplugged). */ -void blk_zone_write_plug_attempt_merge (struct request *req) +void blk_zone_write_plug_init_request (struct request *req) {sector_t req_back_sector =blk_rq_pos (req) +blk_rq_sectors (req);struct request_queue *q = req->q;
@@ -891,6 +892,9 @@ void blk_zone_write_plug_attempt_merge(struct request *req)unsigned long flags;struct bio *bio; +if (WARN_ON_ONCE (!zwplug)) +return ; +/* * Indicate that completion of this request needs to be handled with * blk_zone_write_plug_complete_request(), which will drop the reference
@@ -1250,7 +1254,7 @@ void blk_zone_write_plug_complete_request(struct request *req)/* * Drop the reference we took when the request was initialized in -* blk_zone_write_plug_attempt_merge(). +* blk_zone_write_plug_init_request(). */ disk_put_zone_wplug (zwplug);
block/blk.h +2 -2
@@ -427,7 +427,7 @@ static inline bool bio_is_zone_append(struct bio *bio)bio_flagged (bio,BIO_EMULATES_ZONE_APPEND ); }void blk_zone_write_plug_bio_merged (struct bio *bio); -void blk_zone_write_plug_attempt_merge (struct request *rq); +void blk_zone_write_plug_init_request (struct request *rq);static inline void blk_zone_update_request_bio (struct request *rq,struct bio *bio) {
@@ -481,7 +481,7 @@ static inline bool bio_is_zone_append(struct bio *bio)static inline void blk_zone_write_plug_bio_merged (struct bio *bio) { } -static inline void blk_zone_write_plug_attempt_merge (struct request *rq) +static inline void blk_zone_write_plug_init_request (struct request *rq) { } static inline void blk_zone_update_request_bio(struct request *rq,
Signature · 1 line
2.44.0
Re: [PATCH 09/13] block: Fix handling of non-empty flush write requests to zones
Looks good:
Damien Le Moal
maintainerPATCH 10/13 block: Improve blk_zone_write_plug_bio_merged()
In reply to Damien Le MoalImprove blk_zone_write_plug_bio_merged() to check that we succefully get a reference on the zone write plugi of the merged BIO, as expected since for a merge we already have at least one request and one BIO referencing the zone write plug. Comments in this function are also improved to better explain the references to the BIO zone write plug.
--- block/blk-zoned.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
block/blk-zoned.c +7 -2
@@ -866,11 +866,16 @@ void blk_zone_write_plug_bio_merged(struct bio *bio)bio_set_flag (bio,BIO_ZONE_WRITE_PLUGGING );/* -* Increase the plug reference count and advance the zone write -* pointer offset. +* Get a reference on the zone write plug of the target zone and advance +* the zone write pointer offset. Given that this is a merge, we already +* have at least one request and one BIO referencing the zone write +* plug. So this should not fail. */ zwplug =disk_get_zone_wplug (bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector); +if (WARN_ON_ONCE (!zwplug)) +return ; +spin_lock_irqsave (&zwplug->lock, flags); zwplug->wp_offset +=bio_sectors (bio);spin_unlock_irqrestore (&zwplug->lock, flags);
Signature · 1 line
2.44.0
Re: [PATCH 10/13] block: Improve blk_zone_write_plug_bio_merged()
Quoted 2 lines · Damien Le Moal
Improve
blk_zone_write_plug_bio_merged()to check that we succefully get a reference on the zone write plugi of the merged BIO, as expected since
s/plug/plug/ ?
Otherwise looks good:
Damien Le Moal
maintainerPATCH 11/13 block: Improve zone write request completion handling
In reply to Damien Le Moalblk_zone_complete_request() must be called to handle the completion of a zone write request handled with zone write plugging. This function is called from blk_complete_request(), blk_update_request() and also in blk_mq_submit_bio() error path. Improve this by moving this function call into blk_mq_finish_request() as all requests are processed with this function when they complete as well as when they are freed without being executed. This also improves blk_update_request() used by scsi devices as these may repeatedly call this function to handle partial completions.
To be consistent with this change, blk_zone_complete_request() is renamed to blk_zone_finish_request() and blk_zone_write_plug_complete_request() is renamed to blk_zone_write_plug_finish_request().
--- block/blk-mq.c | 6 ++---- block/blk-zoned.c | 9 +++++---- block/blk.h | 8 ++++---- 3 files changed, 11 insertions(+), 12 deletions(-)
block/blk-mq.c +2 -4
@@ -691,6 +691,8 @@ static void blk_mq_finish_request(struct request *rq) {struct request_queue *q = rq->q; +blk_zone_finish_request (rq); +if (rq->rq_flags &RQF_USE_SCHED ) { q->elevator->type->ops.finish_request (rq);/*
@@ -828,8 +830,6 @@ static void blk_complete_request(struct request *req) bio = next; }while (bio); -blk_zone_complete_request (req); -/* * Reset counters so that the request stacking driver * can find how many bytes remain in the request
@@ -940,7 +940,6 @@ bool blk_update_request(struct request *req, blk_status_t error,* completely done */ if (!req->bio) { -blk_zone_complete_request (req);/* * Reset counters so that the request stacking driver * can find how many bytes remain in the request
@@ -2996,7 +2995,6 @@ void blk_mq_submit_bio(struct bio *bio)if (ret !=BLK_STS_OK ) { bio->bi_status = ret;bio_endio (bio); -blk_zone_complete_request (rq);blk_mq_free_request (rq);return ; }
block/blk-zoned.c +5 -4
@@ -902,7 +902,7 @@ void blk_zone_write_plug_init_request(struct request *req)/* * Indicate that completion of this request needs to be handled with -* blk_zone_write_plug_complete_request(), which will drop the reference +* blk_zone_write_plug_finish_request(), which will drop the reference * on the zone write plug we took above on entry to this function. */ req->rq_flags |=RQF_ZONE_WRITE_PLUGGING ;
@@ -1236,7 +1236,7 @@ void blk_zone_write_plug_bio_endio(struct bio *bio)disk_put_zone_wplug (zwplug);/* -* For BIO-based devices, blk_zone_write_plug_complete_request() +* For BIO-based devices, blk_zone_write_plug_finish_request() * is not called. So we need to schedule execution of the next * plugged BIO here. */
@@ -1247,11 +1247,12 @@ void blk_zone_write_plug_bio_endio(struct bio *bio)disk_put_zone_wplug (zwplug); } -void blk_zone_write_plug_complete_request (struct request *req) +void blk_zone_write_plug_finish_request (struct request *req) {struct gendisk *disk = req->q->disk; -struct blk_zone_wplug *zwplug =disk_get_zone_wplug (disk, req->__sector); +struct blk_zone_wplug *zwplug; + zwplug =disk_get_zone_wplug (disk, req->__sector);if (WARN_ON_ONCE (!zwplug))return ;
block/blk.h +4 -4
@@ -453,11 +453,11 @@ static inline void blk_zone_bio_endio(struct bio *bio)blk_zone_write_plug_bio_endio (bio); } -void blk_zone_write_plug_complete_request (struct request *rq); -static inline void blk_zone_complete_request (struct request *rq) +void blk_zone_write_plug_finish_request (struct request *rq); +static inline void blk_zone_finish_request (struct request *rq) {if (rq->rq_flags &RQF_ZONE_WRITE_PLUGGING ) -blk_zone_write_plug_complete_request (rq); +blk_zone_write_plug_finish_request (rq); }int blkdev_report_zones_ioctl (struct block_device *bdev,unsigned int cmd,unsigned long arg);
@@ -491,7 +491,7 @@ static inline void blk_zone_update_request_bio(struct request *rq,static inline void blk_zone_bio_endio (struct bio *bio) { } -static inline void blk_zone_complete_request (struct request *rq) +static inline void blk_zone_finish_request (struct request *rq) { } static inline int blkdev_report_zones_ioctl(struct block_device *bdev,
Signature · 1 line
2.44.0
Re: [PATCH 11/13] block: Improve zone write request completion handling
Looks good:
Damien Le Moal
maintainerPATCH 12/13 block: Simplify blk_zone_write_plug_bio_endio()
In reply to Damien Le MoalWe already have the disk variable obtained from the bio when calling disk_get_zone_wplug(). So use that variable instead of dereferencing the bio bdev again for the disk argument of disk_get_zone_wplug().
--- block/blk-zoned.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-zoned.c +1 -2
@@ -1203,8 +1203,7 @@ void blk_zone_write_plug_bio_endio(struct bio *bio) {struct gendisk *disk = bio->bi_bdev->bd_disk;struct blk_zone_wplug *zwplug = -disk_get_zone_wplug (bio->bi_bdev->bd_disk, - bio->bi_iter.bi_sector); +disk_get_zone_wplug (disk, bio->bi_iter.bi_sector);unsigned long flags;if (WARN_ON_ONCE (!zwplug))
Signature · 1 line
2.44.0
Re: [PATCH 12/13] block: Simplify blk_zone_write_plug_bio_endio()
Quoted 3 lines · Damien Le Moal
We already have the disk variable obtained from the bio when calling
disk_get_zone_wplug(). So use that variable instead of dereferencing the bio bdev again for the disk argument ofdisk_get_zone_wplug().
Looks good:
Damien Le Moal
maintainerPATCH 13/13 block: Simplify zone write plug BIO abort
In reply to Damien Le MoalWhen BIOs plugged in a zone write plug are aborted, blk_zone_wplug_bio_io_error() clears the BIO BIO_ZONE_WRITE_PLUGGING flag so that bio_io_error(bio) does not end up calling blk_zone_write_plug_bio_endio() and we thus need to manually drop the reference on the zone write plug held by the aborted BIO.
Move the call to disk_put_zone_wplug() that is alwasy following the call to blk_zone_wplug_bio_io_error() inside that function to simplify the code.
--- block/blk-zoned.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
block/blk-zoned.c +7 -8
@@ -616,12 +616,14 @@ static struct blk_zone_wplug *disk_get_and_lock_zone_wplug(struct gendisk *disk,return zwplug; } -static inline void blk_zone_wplug_bio_io_error (struct bio *bio) +static inline void blk_zone_wplug_bio_io_error (struct blk_zone_wplug *zwplug, +struct bio *bio) { -struct request_queue *q = bio->bi_bdev->bd_disk->queue; +struct request_queue *q = zwplug->disk->queue;bio_clear_flag (bio,BIO_ZONE_WRITE_PLUGGING );bio_io_error (bio); +disk_put_zone_wplug (zwplug);blk_queue_exit (q); }
@@ -632,10 +634,8 @@ static void disk_zone_wplug_abort(struct blk_zone_wplug *zwplug) {struct bio *bio; -while ((bio =bio_list_pop (&zwplug->bio_list))) { -blk_zone_wplug_bio_io_error (bio); -disk_put_zone_wplug (zwplug); - } +while ((bio =bio_list_pop (&zwplug->bio_list))) +blk_zone_wplug_bio_io_error (zwplug, bio); }/*
@@ -655,8 +655,7 @@ static void disk_zone_wplug_abort_unaligned(struct gendisk *disk,if (wp_offset >= zone_capacity || (bio_op (bio) !=REQ_OP_ZONE_APPEND &&bio_offset_from_zone_start (bio) != wp_offset)) { -blk_zone_wplug_bio_io_error (bio); -disk_put_zone_wplug (zwplug); +blk_zone_wplug_bio_io_error (zwplug, bio);continue ; }
Signature · 1 line
2.44.0
Re: [PATCH 13/13] block: Simplify zone write plug BIO abort
Looks good:
Apart from Christoph's comments: