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: turn bdev_lock into a mutex

There is no reason for this lock to spin, and being able to sleep under
it will come in handy soon.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Acked-by: Christian Brauner <brauner@kernel.org>
Acked-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Link: https://lore.kernel.org/r/20230601094459.1350643-4-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
74e6464a ae5f855e

+13 -14
+13 -14
block/bdev.c
··· 308 308 * pseudo-fs 309 309 */ 310 310 311 - static __cacheline_aligned_in_smp DEFINE_SPINLOCK(bdev_lock); 311 + static __cacheline_aligned_in_smp DEFINE_MUTEX(bdev_lock); 312 312 static struct kmem_cache * bdev_cachep __read_mostly; 313 313 314 314 static struct inode *bdev_alloc_inode(struct super_block *sb) ··· 467 467 * 468 468 * Test whether @bdev can be claimed by @holder. 469 469 * 470 - * CONTEXT: 471 - * spin_lock(&bdev_lock). 472 - * 473 470 * RETURNS: 474 471 * %true if @bdev can be claimed, %false otherwise. 475 472 */ 476 473 static bool bd_may_claim(struct block_device *bdev, void *holder) 477 474 { 478 475 struct block_device *whole = bdev_whole(bdev); 476 + 477 + lockdep_assert_held(&bdev_lock); 479 478 480 479 if (bdev->bd_holder) { 481 480 /* ··· 514 515 if (WARN_ON_ONCE(!holder)) 515 516 return -EINVAL; 516 517 retry: 517 - spin_lock(&bdev_lock); 518 + mutex_lock(&bdev_lock); 518 519 /* if someone else claimed, fail */ 519 520 if (!bd_may_claim(bdev, holder)) { 520 - spin_unlock(&bdev_lock); 521 + mutex_unlock(&bdev_lock); 521 522 return -EBUSY; 522 523 } 523 524 ··· 527 528 DEFINE_WAIT(wait); 528 529 529 530 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE); 530 - spin_unlock(&bdev_lock); 531 + mutex_unlock(&bdev_lock); 531 532 schedule(); 532 533 finish_wait(wq, &wait); 533 534 goto retry; ··· 535 536 536 537 /* yay, all mine */ 537 538 whole->bd_claiming = holder; 538 - spin_unlock(&bdev_lock); 539 + mutex_unlock(&bdev_lock); 539 540 return 0; 540 541 } 541 542 EXPORT_SYMBOL_GPL(bd_prepare_to_claim); /* only for the loop driver */ ··· 561 562 { 562 563 struct block_device *whole = bdev_whole(bdev); 563 564 564 - spin_lock(&bdev_lock); 565 + mutex_lock(&bdev_lock); 565 566 BUG_ON(!bd_may_claim(bdev, holder)); 566 567 /* 567 568 * Note that for a whole device bd_holders will be incremented twice, ··· 572 573 bdev->bd_holders++; 573 574 bdev->bd_holder = holder; 574 575 bd_clear_claiming(whole, holder); 575 - spin_unlock(&bdev_lock); 576 + mutex_unlock(&bdev_lock); 576 577 } 577 578 578 579 /** ··· 586 587 */ 587 588 void bd_abort_claiming(struct block_device *bdev, void *holder) 588 589 { 589 - spin_lock(&bdev_lock); 590 + mutex_lock(&bdev_lock); 590 591 bd_clear_claiming(bdev_whole(bdev), holder); 591 - spin_unlock(&bdev_lock); 592 + mutex_unlock(&bdev_lock); 592 593 } 593 594 EXPORT_SYMBOL(bd_abort_claiming); 594 595 ··· 601 602 * Release a claim on the device. The holder fields are protected with 602 603 * bdev_lock. open_mutex is used to synchronize disk_holder unlinking. 603 604 */ 604 - spin_lock(&bdev_lock); 605 + mutex_lock(&bdev_lock); 605 606 WARN_ON_ONCE(--bdev->bd_holders < 0); 606 607 WARN_ON_ONCE(--whole->bd_holders < 0); 607 608 if (!bdev->bd_holders) { ··· 611 612 } 612 613 if (!whole->bd_holders) 613 614 whole->bd_holder = NULL; 614 - spin_unlock(&bdev_lock); 615 + mutex_unlock(&bdev_lock); 615 616 616 617 /* 617 618 * If this was the last claim, remove holder link and unblock evpoll if