Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: rename and simplify disk_get_and_lock_zone_wplug()

disk_get_and_lock_zone_wplug() always returns a zone write plug with the
plug lock held. This is unnecessary since this function does not look at
the fields of existing plugs, and new plugs need to be locked only after
their insertion in the disk hash table, when they are being used.

Remove the zone write plug locking from disk_get_and_lock_zone_wplug()
and rename this function disk_get_or_alloc_zone_wplug().
blk_zone_wplug_handle_write() is modified to add locking of the zone
write plug after calling disk_get_or_alloc_zone_wplug() and before
starting to use the plug. This change also simplifies
blk_revalidate_seq_zone() as unlocking the plug becomes unnecessary.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Damien Le Moal and committed by
Jens Axboe
1084e41d 0a8b8af8

+10 -16
+10 -16
block/blk-zoned.c
··· 631 631 static void blk_zone_wplug_bio_work(struct work_struct *work); 632 632 633 633 /* 634 - * Get a reference on the write plug for the zone containing @sector. 635 - * If the plug does not exist, it is allocated and hashed. 636 - * Return a pointer to the zone write plug with the plug spinlock held. 634 + * Get a zone write plug for the zone containing @sector. 635 + * If the plug does not exist, it is allocated and inserted in the disk hash 636 + * table. 637 637 */ 638 - static struct blk_zone_wplug *disk_get_and_lock_zone_wplug(struct gendisk *disk, 639 - sector_t sector, gfp_t gfp_mask, 640 - unsigned long *flags) 638 + static struct blk_zone_wplug *disk_get_or_alloc_zone_wplug(struct gendisk *disk, 639 + sector_t sector, gfp_t gfp_mask) 641 640 { 642 641 unsigned int zno = disk_zone_no(disk, sector); 643 642 struct blk_zone_wplug *zwplug; 644 643 645 644 again: 646 645 zwplug = disk_get_zone_wplug(disk, sector); 647 - if (zwplug) { 648 - spin_lock_irqsave(&zwplug->lock, *flags); 646 + if (zwplug) 649 647 return zwplug; 650 - } 651 648 652 649 /* 653 650 * Allocate and initialize a zone write plug with an extra reference ··· 665 668 INIT_WORK(&zwplug->bio_work, blk_zone_wplug_bio_work); 666 669 zwplug->disk = disk; 667 670 668 - spin_lock_irqsave(&zwplug->lock, *flags); 669 - 670 671 /* 671 672 * Insert the new zone write plug in the hash table. This can fail only 672 673 * if another context already inserted a plug. Retry from the beginning 673 674 * in such case. 674 675 */ 675 676 if (!disk_insert_zone_wplug(disk, zwplug)) { 676 - spin_unlock_irqrestore(&zwplug->lock, *flags); 677 677 mempool_free(zwplug, disk->zone_wplugs_pool); 678 678 goto again; 679 679 } ··· 1392 1398 if (bio->bi_opf & REQ_NOWAIT) 1393 1399 gfp_mask = GFP_NOWAIT; 1394 1400 1395 - zwplug = disk_get_and_lock_zone_wplug(disk, sector, gfp_mask, &flags); 1401 + zwplug = disk_get_or_alloc_zone_wplug(disk, sector, gfp_mask); 1396 1402 if (!zwplug) { 1397 1403 if (bio->bi_opf & REQ_NOWAIT) 1398 1404 bio_wouldblock_error(bio); ··· 1400 1406 bio_io_error(bio); 1401 1407 return true; 1402 1408 } 1409 + 1410 + spin_lock_irqsave(&zwplug->lock, flags); 1403 1411 1404 1412 /* 1405 1413 * If we got a zone write plug marked as dead, then the user is issuing ··· 2041 2045 struct gendisk *disk = args->disk; 2042 2046 struct blk_zone_wplug *zwplug; 2043 2047 unsigned int wp_offset; 2044 - unsigned long flags; 2045 2048 2046 2049 /* 2047 2050 * Remember the capacity of the first sequential zone and check ··· 2070 2075 if (!wp_offset || wp_offset >= zone->capacity) 2071 2076 return 0; 2072 2077 2073 - zwplug = disk_get_and_lock_zone_wplug(disk, zone->wp, GFP_NOIO, &flags); 2078 + zwplug = disk_get_or_alloc_zone_wplug(disk, zone->wp, GFP_NOIO); 2074 2079 if (!zwplug) 2075 2080 return -ENOMEM; 2076 - spin_unlock_irqrestore(&zwplug->lock, flags); 2077 2081 disk_put_zone_wplug(zwplug); 2078 2082 2079 2083 return 0;