introduce bdev holder ops and a file system shutdown method
Subsystems (28)
Christoph Hellwig
maintainerHi all,
this series fixes the long standing problem that we never had a good way to communicate block device events to the user of the block device.
It fixes this by introducing a new set of holder ops registered at blkdev_get_by_* time for the exclusive holder, and then wire that up to a shutdown super operation to report the block device remove to the file systems.
Diffstat:
block/bdev.c | 106 ++++++++++++++++++++---------------- block/fops.c | 2 block/genhd.c | 57 +++++++++++++------ block/ioctl.c | 3 - drivers/block/drbd/drbd_nl.c | 3 - drivers/block/pktcdvd.c | 5 + drivers/block/rnbd/rnbd-srv.c | 2 drivers/block/xen-blkback/xenbus.c | 2 drivers/block/zram/zram_drv.c | 2 drivers/md/bcache/super.c | 2 drivers/md/dm.c | 2 drivers/md/md.c | 2 drivers/mtd/devices/block2mtd.c | 4 - drivers/nvme/target/io-cmd-bdev.c | 2 drivers/s390/block/dasd_genhd.c | 2 drivers/target/target_core_iblock.c | 2 drivers/target/target_core_pscsi.c | 3 - fs/btrfs/dev-replace.c | 2 fs/btrfs/volumes.c | 6 +- fs/erofs/super.c | 2 fs/ext4/super.c | 3 - fs/f2fs/super.c | 4 - fs/jfs/jfs_logmgr.c | 2 fs/nfs/blocklayout/dev.c | 5 + fs/nilfs2/super.c | 2 fs/ocfs2/cluster/heartbeat.c | 2 fs/reiserfs/journal.c | 5 + fs/super.c | 21 ++++++- fs/xfs/xfs_fsops.c | 3 + fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_super.c | 21 ++++++- include/linux/blk_types.h | 2 include/linux/blkdev.h | 9 ++- include/linux/fs.h | 1 kernel/power/swap.c | 4 - mm/swapfile.c | 3 - 36 files changed, 196 insertions(+), 103 deletions(-)
Christoph Hellwig
maintainerPATCH 1/9 block: consolidate the shutdown logic in blk_mark_disk_dead and del_gendisk
blk_mark_disk_dead does very similar work a a section of del_gendisk:
- set the GD_DEAD flag
- set the capacity to zero
- start a queue drain
but del_gendisk also sets QUEUE_FLAG_DYING on the queue if it is owned by the disk, sets the capacity to zero before starting the drain, and both with sending a uevent and kernel message for this fake capacity change.
Move the exact logic from the more heavily used del_gendisk into blk_mark_disk_dead and then call blk_mark_disk_dead from del_gendisk.
--- block/genhd.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
block/genhd.c +12 -14
@@ -583,13 +583,22 @@ EXPORT_SYMBOL(device_add_disk);*/ void blk_mark_disk_dead (struct gendisk *disk) { +/* +* Fail any new I/O. +*/ set_bit (GD_DEAD , &disk->state); -blk_queue_start_drain (disk->queue); +if (test_bit (GD_OWNS_QUEUE , &disk->state)) +blk_queue_flag_set (QUEUE_FLAG_DYING , disk->queue);/* * Stop buffered writers from dirtying pages that can't be written out. */ -set_capacity_and_notify (disk,0 ); +set_capacity (disk,0 ); + +/* +* Prevent new I/O from crossing bio_queue_enter(). +*/ +blk_queue_start_drain (disk->queue); }EXPORT_SYMBOL_GPL (blk_mark_disk_dead);
@@ -632,18 +641,7 @@ void del_gendisk(struct gendisk *disk)fsync_bdev (disk->part0);__invalidate_device (disk->part0, true); -/* -* Fail any new I/O. -*/ -set_bit (GD_DEAD , &disk->state); -if (test_bit (GD_OWNS_QUEUE , &disk->state)) -blk_queue_flag_set (QUEUE_FLAG_DYING , q); -set_capacity (disk,0 ); - -/* -* Prevent new I/O from crossing bio_queue_enter(). -*/ -blk_queue_start_drain (q); +blk_mark_disk_dead (disk);if (!(disk->flags &GENHD_FL_HIDDEN )) {sysfs_remove_link (&disk_to_dev (disk)->kobj,"bdi" );
Signature · 1 line
2.39.2
Jan Kara
reviewerRe: [PATCH 1/9] block: consolidate the shutdown logic in blk_mark_disk_dead and del_gendisk
Quoted 6 lines · Christoph Hellwig
blk_mark_disk_deaddoes very similar work a a section ofdel_gendisk:- set the
GD_DEADflag
- set the capacity to zero
- start a queue drain
Quoted 8 lines
but
del_gendiskalso setsQUEUE_FLAG_DYINGon the queue if it is owned by the disk, sets the capacity to zero before starting the drain, and both with sending a uevent and kernel message for this fake capacity change.Move the exact logic from the more heavily used
del_gendiskintoblk_mark_disk_deadand then callblk_mark_disk_deadfromdel_gendisk.Signed-off-by Christoph Hellwig <[email protected]>
I'm somewhat wondering about the lost notification from blk_mark_disk_dead(). E.g. DM uses blk_mark_disk_dead() so if some udev script depends on the event when DM device gets destroyed, we would break it?
Honza
Quoted 56 lines
--- block/genhd.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)block/genhd.c +12
-14@@ -583,13 +583,22 @@ EXPORT_SYMBOL(device_add_disk);*/ void blk_mark_disk_dead (struct gendisk *disk) { +/* +* Fail any new I/O. +*/ set_bit (GD_DEAD , &disk->state); -blk_queue_start_drain (disk->queue); +if (test_bit (GD_OWNS_QUEUE , &disk->state)) +blk_queue_flag_set (QUEUE_FLAG_DYING , disk->queue);/* * Stop buffered writers from dirtying pages that can't be written out. */ -set_capacity_and_notify (disk,0 ); +set_capacity (disk,0 ); + +/* +* Prevent new I/O from crossing bio_queue_enter(). +*/ +blk_queue_start_drain (disk->queue); }EXPORT_SYMBOL_GPL (blk_mark_disk_dead);@@ -632,18 +641,7 @@ void del_gendisk(struct gendisk *disk)fsync_bdev (disk->part0);__invalidate_device (disk->part0, true); -/* -* Fail any new I/O. -*/ -set_bit (GD_DEAD , &disk->state); -if (test_bit (GD_OWNS_QUEUE , &disk->state)) -blk_queue_flag_set (QUEUE_FLAG_DYING , q); -set_capacity (disk,0 ); - -/* -* Prevent new I/O from crossing bio_queue_enter(). -*/ -blk_queue_start_drain (q); +blk_mark_disk_dead (disk);if (!(disk->flags &GENHD_FL_HIDDEN )) {sysfs_remove_link (&disk_to_dev (disk)->kobj,"bdi" );Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 1/9] block: consolidate the shutdown logic in blk_mark_disk_dead and del_gendisk
Quoted 4 lines · Jan Kara
I'm somewhat wondering about the lost notification from
blk_mark_disk_dead(). E.g. DM usesblk_mark_disk_dead()so if some udev script depends on the event when DM device gets destroyed, we would break it?
Maybe. We'll probably find out..
Christoph Hellwig
maintainerPATCH 2/9 block: avoid repeated work in blk_mark_disk_dead
In reply to Christoph HellwigCheck if GD_DEAD is already set in blk_mark_disk_dead, and don't duplicate the work already done.
--- block/genhd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/genhd.c +3 -1
@@ -586,7 +586,9 @@ void blk_mark_disk_dead(struct gendisk *disk)/* * Fail any new I/O. */ -set_bit (GD_DEAD , &disk->state); +if (test_and_set_bit (GD_DEAD , &disk->state)) +return ; +if (test_bit (GD_OWNS_QUEUE , &disk->state))blk_queue_flag_set (QUEUE_FLAG_DYING , disk->queue);
Signature · 1 line
2.39.2
Re: [PATCH 2/9] block: avoid repeated work in blk_mark_disk_dead
Quoted 4 lines · Christoph Hellwig
Check if
GD_DEADis already set inblk_mark_disk_dead, and don't duplicate the work already done.Signed-off-by Christoph Hellwig <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 22 lines
--- block/genhd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)block/genhd.c +3
-1@@ -586,7 +586,9 @@ void blk_mark_disk_dead(struct gendisk *disk)/* * Fail any new I/O. */ -set_bit (GD_DEAD , &disk->state); +if (test_and_set_bit (GD_DEAD , &disk->state)) +return ; +if (test_bit (GD_OWNS_QUEUE , &disk->state))blk_queue_flag_set (QUEUE_FLAG_DYING , disk->queue);Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 2/9] block: avoid repeated work in blk_mark_disk_dead
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
Check if
GD_DEADis already set inblk_mark_disk_dead, and don't duplicate the work already done.Signed-off-by Christoph Hellwig <[email protected]>---
Christoph Hellwig
maintainerPATCH 3/9 block: factor out a bd_end_claim helper from blkdev_put
In reply to Christoph HellwigMove all the logic to release an exclusive claim into a helper.
--- block/bdev.c | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-)
block/bdev.c +33 -30
@@ -578,6 +578,37 @@ void bd_abort_claiming(struct block_device *bdev, void *holder) }EXPORT_SYMBOL (bd_abort_claiming); +static void bd_end_claim (struct block_device *bdev) +{ +struct block_device *whole =bdev_whole (bdev); +bool unblock = false; + +/* +* Release a claim on the device. The holder fields are protected with +* bdev_lock. open_mutex is used to synchronize disk_holder unlinking. +*/ +spin_lock (&bdev_lock); +WARN_ON_ONCE (--bdev->bd_holders <0 ); +WARN_ON_ONCE (--whole->bd_holders <0 ); +if (!bdev->bd_holders) { + bdev->bd_holder =NULL ; +if (bdev->bd_write_holder) + unblock = true; + } +if (!whole->bd_holders) + whole->bd_holder =NULL ; +spin_unlock (&bdev_lock); + +/* +* If this was the last claim, remove holder link and unblock evpoll if +* it was a write holder. +*/ +if (unblock) { +disk_unblock_events (bdev->bd_disk); + bdev->bd_write_holder = false; + } +} +static void blkdev_flush_mapping (struct block_device *bdev) {WARN_ON_ONCE (bdev->bd_holders);
@@ -832,36 +863,8 @@ void blkdev_put(struct block_device *bdev, fmode_t mode)sync_blockdev (bdev);mutex_lock (&disk->open_mutex); -if (mode &FMODE_EXCL ) { -struct block_device *whole =bdev_whole (bdev); -bool bdev_free; - -/* -* Release a claim on the device. The holder fields -* are protected with bdev_lock. open_mutex is to -* synchronize disk_holder unlinking. -*/ -spin_lock (&bdev_lock); - -WARN_ON_ONCE (--bdev->bd_holders <0 ); -WARN_ON_ONCE (--whole->bd_holders <0 ); - -if ((bdev_free = !bdev->bd_holders)) - bdev->bd_holder =NULL ; -if (!whole->bd_holders) - whole->bd_holder =NULL ; - -spin_unlock (&bdev_lock); - -/* -* If this was the last claim, remove holder link and -* unblock evpoll if it was a write holder. -*/ -if (bdev_free && bdev->bd_write_holder) { -disk_unblock_events (disk); - bdev->bd_write_holder = false; - } - } +if (mode &FMODE_EXCL ) +bd_end_claim (bdev);/* * Trigger event checking and tell drivers to flush MEDIA_CHANGE
Signature · 1 line
2.39.2
Re: [PATCH 3/9] block: factor out a bd_end_claim helper from blkdev_put
Quoted 3 lines · Christoph Hellwig
Move all the logic to release an exclusive claim into a helper.
Signed-off-by Christoph Hellwig <[email protected]>
Nice. Feel free to add:
Honza
Quoted 88 lines
--- block/bdev.c | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-)block/bdev.c +33
-30@@ -578,6 +578,37 @@ void bd_abort_claiming(struct block_device *bdev, void *holder) }EXPORT_SYMBOL (bd_abort_claiming); +static void bd_end_claim (struct block_device *bdev) +{ +struct block_device *whole =bdev_whole (bdev); +bool unblock = false; + +/* +* Release a claim on the device. The holder fields are protected with +* bdev_lock. open_mutex is used to synchronize disk_holder unlinking. +*/ +spin_lock (&bdev_lock); +WARN_ON_ONCE (--bdev->bd_holders <0 ); +WARN_ON_ONCE (--whole->bd_holders <0 ); +if (!bdev->bd_holders) { + bdev->bd_holder =NULL ; +if (bdev->bd_write_holder) + unblock = true; + } +if (!whole->bd_holders) + whole->bd_holder =NULL ; +spin_unlock (&bdev_lock); + +/* +* If this was the last claim, remove holder link and unblock evpoll if +* it was a write holder. +*/ +if (unblock) { +disk_unblock_events (bdev->bd_disk); + bdev->bd_write_holder = false; + } +} +static void blkdev_flush_mapping (struct block_device *bdev) {WARN_ON_ONCE (bdev->bd_holders);@@ -832,36 +863,8 @@ void blkdev_put(struct block_device *bdev, fmode_t mode)sync_blockdev (bdev);mutex_lock (&disk->open_mutex); -if (mode &FMODE_EXCL ) { -struct block_device *whole =bdev_whole (bdev); -bool bdev_free; - -/* -* Release a claim on the device. The holder fields -* are protected with bdev_lock. open_mutex is to -* synchronize disk_holder unlinking. -*/ -spin_lock (&bdev_lock); - -WARN_ON_ONCE (--bdev->bd_holders <0 ); -WARN_ON_ONCE (--whole->bd_holders <0 ); - -if ((bdev_free = !bdev->bd_holders)) - bdev->bd_holder =NULL ; -if (!whole->bd_holders) - whole->bd_holder =NULL ; - -spin_unlock (&bdev_lock); - -/* -* If this was the last claim, remove holder link and -* unblock evpoll if it was a write holder. -*/ -if (bdev_free && bdev->bd_write_holder) { -disk_unblock_events (disk); - bdev->bd_write_holder = false; - } - } +if (mode &FMODE_EXCL ) +bd_end_claim (bdev);/* * Trigger event checking and tell drivers to flush MEDIA_CHANGE Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 3/9] block: factor out a bd_end_claim helper from blkdev_put
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Move all the logic to release an exclusive claim into a helper.
Signed-off-by Christoph Hellwig <[email protected]>---
Christoph Hellwig
maintainerPATCH 4/9 block: turn bdev_lock into a mutex
In reply to Christoph HellwigThere is no reason for this lock to spin, and being able to sleep under it will come in handy soon.
--- block/bdev.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
block/bdev.c +13 -14
@@ -308,7 +308,7 @@ EXPORT_SYMBOL(thaw_bdev);* pseudo-fs */ -static __cacheline_aligned_in_smp DEFINE_SPINLOCK (bdev_lock ); +static __cacheline_aligned_in_smp DEFINE_MUTEX (bdev_lock );static struct kmem_cache * bdev_cachep__read_mostly ;static struct inode *bdev_alloc_inode (struct super_block *sb)
@@ -457,15 +457,14 @@ long nr_blockdev_pages(void)* * Test whether @bdev can be claimed by @holder. * -* CONTEXT: -* spin_lock(&bdev_lock). -* * RETURNS: * %true if @bdev can be claimed, %false otherwise. */ static bool bd_may_claim (struct block_device *bdev,struct block_device *whole,void *holder) { +lockdep_assert_held (&bdev_lock); +if (bdev->bd_holder == holder)return true;/* already a holder */ else if (bdev->bd_holder !=NULL )
@@ -500,10 +499,10 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder)if (WARN_ON_ONCE (!holder))return -EINVAL ; retry: -spin_lock (&bdev_lock); +mutex_lock (&bdev_lock);/* if someone else claimed, fail */ if (!bd_may_claim (bdev, whole, holder)) { -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock);return -EBUSY ; }
@@ -513,7 +512,7 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder)DEFINE_WAIT (wait);prepare_to_wait (wq, &wait,TASK_UNINTERRUPTIBLE ); -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock);schedule ();finish_wait (wq, &wait); goto retry;
@@ -521,7 +520,7 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder)/* yay, all mine */ whole->bd_claiming = holder; -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock);return 0 ; }EXPORT_SYMBOL_GPL (bd_prepare_to_claim);/* only for the loop driver */
@@ -547,7 +546,7 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) {struct block_device *whole =bdev_whole (bdev); -spin_lock (&bdev_lock); +mutex_lock (&bdev_lock);BUG_ON (!bd_may_claim (bdev, whole, holder));/* * Note that for a whole device bd_holders will be incremented twice,
@@ -558,7 +557,7 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) bdev->bd_holders++; bdev->bd_holder = holder;bd_clear_claiming (whole, holder); -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock); }/**
@@ -572,9 +571,9 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder)*/ void bd_abort_claiming (struct block_device *bdev,void *holder) { -spin_lock (&bdev_lock); +mutex_lock (&bdev_lock);bd_clear_claiming (bdev_whole (bdev), holder); -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock); }EXPORT_SYMBOL (bd_abort_claiming);
@@ -587,7 +586,7 @@ static void bd_end_claim(struct block_device *bdev)* Release a claim on the device. The holder fields are protected with * bdev_lock. open_mutex is used to synchronize disk_holder unlinking. */ -spin_lock (&bdev_lock); +mutex_lock (&bdev_lock);WARN_ON_ONCE (--bdev->bd_holders <0 );WARN_ON_ONCE (--whole->bd_holders <0 );if (!bdev->bd_holders) {
@@ -597,7 +596,7 @@ static void bd_end_claim(struct block_device *bdev) }if (!whole->bd_holders) whole->bd_holder =NULL ; -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock);/* * If this was the last claim, remove holder link and unblock evpoll if
Signature · 1 line
2.39.2
Re: [PATCH 4/9] block: turn bdev_lock into a mutex
Quoted 4 lines · Christoph Hellwig
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 <[email protected]>
Makes sense. Feel free to add:
Honza
Quoted 117 lines
--- block/bdev.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)block/bdev.c +13
-14@@ -308,7 +308,7 @@ EXPORT_SYMBOL(thaw_bdev);* pseudo-fs */ -static __cacheline_aligned_in_smp DEFINE_SPINLOCK (bdev_lock ); +static __cacheline_aligned_in_smp DEFINE_MUTEX (bdev_lock );static struct kmem_cache * bdev_cachep__read_mostly ;static struct inode *bdev_alloc_inode (struct super_block *sb)@@ -457,15 +457,14 @@ long nr_blockdev_pages(void)* * Test whether @bdev can be claimed by @holder. * -* CONTEXT: -* spin_lock(&bdev_lock). -* * RETURNS: * %true if @bdev can be claimed, %false otherwise. */ static bool bd_may_claim (struct block_device *bdev,struct block_device *whole,void *holder) { +lockdep_assert_held (&bdev_lock); +if (bdev->bd_holder == holder)return true;/* already a holder */ else if (bdev->bd_holder !=NULL )@@ -500,10 +499,10 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder)if (WARN_ON_ONCE (!holder))return -EINVAL ; retry: -spin_lock (&bdev_lock); +mutex_lock (&bdev_lock);/* if someone else claimed, fail */ if (!bd_may_claim (bdev, whole, holder)) { -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock);return -EBUSY ; }@@ -513,7 +512,7 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder)DEFINE_WAIT (wait);prepare_to_wait (wq, &wait,TASK_UNINTERRUPTIBLE ); -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock);schedule ();finish_wait (wq, &wait); goto retry;@@ -521,7 +520,7 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder)/* yay, all mine */ whole->bd_claiming = holder; -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock);return 0 ; }EXPORT_SYMBOL_GPL (bd_prepare_to_claim);/* only for the loop driver */ @@ -547,7 +546,7 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) {struct block_device *whole =bdev_whole (bdev); -spin_lock (&bdev_lock); +mutex_lock (&bdev_lock);BUG_ON (!bd_may_claim (bdev, whole, holder));/* * Note that for a whole device bd_holders will be incremented twice, @@ -558,7 +557,7 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) bdev->bd_holders++; bdev->bd_holder = holder;bd_clear_claiming (whole, holder); -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock); }/** @@ -572,9 +571,9 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder)*/ void bd_abort_claiming (struct block_device *bdev,void *holder) { -spin_lock (&bdev_lock); +mutex_lock (&bdev_lock);bd_clear_claiming (bdev_whole (bdev), holder); -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock); }EXPORT_SYMBOL (bd_abort_claiming);@@ -587,7 +586,7 @@ static void bd_end_claim(struct block_device *bdev)* Release a claim on the device. The holder fields are protected with * bdev_lock. open_mutex is used to synchronize disk_holder unlinking. */ -spin_lock (&bdev_lock); +mutex_lock (&bdev_lock);WARN_ON_ONCE (--bdev->bd_holders <0 );WARN_ON_ONCE (--whole->bd_holders <0 );if (!bdev->bd_holders) {@@ -597,7 +596,7 @@ static void bd_end_claim(struct block_device *bdev) }if (!whole->bd_holders) whole->bd_holder =NULL ; -spin_unlock (&bdev_lock); +mutex_unlock (&bdev_lock);/* * If this was the last claim, remove holder link and unblock evpoll if Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 4/9] block: turn bdev_lock into a mutex
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
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 <[email protected]>---
Christoph Hellwig
maintainerPATCH 5/9 block: introduce holder ops
In reply to Christoph HellwigAdd a new blk_holder_ops structure, which is passed to blkdev_get_by_* and installed in the block_device for exclusive claims. It will be used to allow the block layer to call back into the user of the block device for thing like notification of a removed device or a device resize.
--- block/bdev.c | 20 +++++++++++++++----- block/fops.c | 2 +- block/genhd.c | 3 ++- block/ioctl.c | 3 ++- drivers/block/drbd/drbd_nl.c | 3 ++- drivers/block/pktcdvd.c | 5 +++-- drivers/block/rnbd/rnbd-srv.c | 2 +- drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/zram/zram_drv.c | 2 +- drivers/md/bcache/super.c | 2 +- drivers/md/dm.c | 2 +- drivers/md/md.c | 2 +- drivers/mtd/devices/block2mtd.c | 4 ++-- drivers/nvme/target/io-cmd-bdev.c | 2 +- drivers/s390/block/dasd_genhd.c | 2 +- drivers/target/target_core_iblock.c | 2 +- drivers/target/target_core_pscsi.c | 3 ++- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/volumes.c | 6 +++--- fs/erofs/super.c | 2 +- fs/ext4/super.c | 3 ++- fs/f2fs/super.c | 4 ++-- fs/jfs/jfs_logmgr.c | 2 +- fs/nfs/blocklayout/dev.c | 5 +++-- fs/nilfs2/super.c | 2 +- fs/ocfs2/cluster/heartbeat.c | 2 +- fs/reiserfs/journal.c | 5 +++-- fs/super.c | 4 ++-- fs/xfs/xfs_super.c | 2 +- include/linux/blk_types.h | 2 ++ include/linux/blkdev.h | 8 ++++++-- kernel/power/swap.c | 4 ++-- mm/swapfile.c | 3 ++- 33 files changed, 71 insertions(+), 46 deletions(-)
block/bdev.c +15 -5
@@ -415,6 +415,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) bdev =I_BDEV (inode);mutex_init (&bdev->bd_fsfreeze_mutex);spin_lock_init (&bdev->bd_size_lock); +mutex_init (&bdev->bd_holder_lock); bdev->bd_partno = partno; bdev->bd_inode = inode; bdev->bd_queue = disk->queue;
@@ -542,7 +543,8 @@ static void bd_clear_claiming(struct block_device *whole, void *holder)* Finish exclusive open of a block device. Mark the device as exlusively * open by the holder and wake up all waiters for exclusive open to finish. */ -static void bd_finish_claiming (struct block_device *bdev,void *holder) +static void bd_finish_claiming (struct block_device *bdev,void *holder, +const struct blk_holder_ops *hops) {struct block_device *whole =bdev_whole (bdev);
@@ -555,7 +557,10 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) whole->bd_holders++; whole->bd_holder = bd_may_claim; bdev->bd_holders++; +mutex_lock (&bdev->bd_holder_lock); bdev->bd_holder = holder; + bdev->bd_holder_ops = hops; +mutex_unlock (&bdev->bd_holder_lock);bd_clear_claiming (whole, holder);mutex_unlock (&bdev_lock); }
@@ -590,7 +595,10 @@ static void bd_end_claim(struct block_device *bdev)WARN_ON_ONCE (--bdev->bd_holders <0 );WARN_ON_ONCE (--whole->bd_holders <0 );if (!bdev->bd_holders) { +mutex_lock (&bdev->bd_holder_lock); bdev->bd_holder =NULL ; + bdev->bd_holder_ops =NULL ; +mutex_unlock (&bdev->bd_holder_lock);if (bdev->bd_write_holder) unblock = true; }
@@ -720,6 +728,7 @@ void blkdev_put_no_open(struct block_device *bdev)* @dev: device number of block device to open * @mode: FMODE_* mask * @holder: exclusive holder identifier +* @hops: holder operations * * Open the block device described by device number @dev. If @mode includes * %FMODE_EXCL, the block device is opened with exclusive access. Specifying
@@ -736,7 +745,8 @@ void blkdev_put_no_open(struct block_device *bdev)* RETURNS: * Reference to the block_device on success, ERR_PTR(-errno) on failure. */ -struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder) +struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder, +const struct blk_holder_ops *hops) {bool unblock_events = true;struct block_device *bdev;
@@ -776,7 +786,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)if (ret) goto put_module;if (mode &FMODE_EXCL ) { -bd_finish_claiming (bdev, holder); +bd_finish_claiming (bdev, holder, hops);/* * Block event polling for write claims if requested. Any write
@@ -827,7 +837,7 @@ EXPORT_SYMBOL(blkdev_get_by_dev);* Reference to the block_device on success, ERR_PTR(-errno) on failure. */ struct block_device *blkdev_get_by_path (const char *path,fmode_t mode, -void *holder) +void *holder,const struct blk_holder_ops *hops) {struct block_device *bdev;dev_t dev;
@@ -837,7 +847,7 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,if (error)return ERR_PTR (error); - bdev =blkdev_get_by_dev (dev, mode, holder); + bdev =blkdev_get_by_dev (dev, mode, holder, hops);if (!IS_ERR (bdev) && (mode &FMODE_WRITE ) &&bdev_read_only (bdev)) {blkdev_put (bdev, mode);return ERR_PTR (-EACCES );
block/fops.c +1 -1
@@ -490,7 +490,7 @@ static int blkdev_open(struct inode *inode, struct file *filp)if ((filp->f_flags &O_ACCMODE ) ==3 ) filp->f_mode |=FMODE_WRITE_IOCTL ; - bdev =blkdev_get_by_dev (inode->i_rdev, filp->f_mode, filp); + bdev =blkdev_get_by_dev (inode->i_rdev, filp->f_mode, filp,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev);
block/genhd.c +2 -1
@@ -381,7 +381,8 @@ int disk_scan_partitions(struct gendisk *disk, fmode_t mode) }set_bit (GD_NEED_PART_SCAN , &disk->state); - bdev =blkdev_get_by_dev (disk_devt (disk), mode & ~FMODE_EXCL ,NULL ); + bdev =blkdev_get_by_dev (disk_devt (disk), mode & ~FMODE_EXCL ,NULL , +NULL );if (IS_ERR (bdev)) ret =PTR_ERR (bdev);else
block/ioctl.c +2 -1
@@ -454,7 +454,8 @@ static int blkdev_bszset(struct block_device *bdev, fmode_t mode,if (mode &FMODE_EXCL )return set_blocksize (bdev, n); -if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev))) +if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev, +NULL )))return -EBUSY ; ret =set_blocksize (bdev, n);blkdev_put (bdev, mode |FMODE_EXCL );
drivers/block/drbd/drbd_nl.c +2 -1
@@ -1641,7 +1641,8 @@ static struct block_device *open_backing_dev(struct drbd_device *device,int err =0 ; bdev =blkdev_get_by_path (bdev_path, -FMODE_READ |FMODE_WRITE |FMODE_EXCL , claim_ptr); +FMODE_READ |FMODE_WRITE |FMODE_EXCL , + claim_ptr,NULL );if (IS_ERR (bdev)) {drbd_err (device,"open(\"%s\") failed with %ld\n" , bdev_path,PTR_ERR (bdev));
drivers/block/pktcdvd.c +3 -2
@@ -2125,7 +2125,8 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)* to read/write from/to it. It is already opened in O_NONBLOCK mode * so open should not fail. */ - bdev =blkdev_get_by_dev (pd->bdev->bd_dev,FMODE_READ |FMODE_EXCL , pd); + bdev =blkdev_get_by_dev (pd->bdev->bd_dev,FMODE_READ |FMODE_EXCL , pd, +NULL );if (IS_ERR (bdev)) { ret =PTR_ERR (bdev); goto out;
@@ -2530,7 +2531,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) } } - bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_NDELAY ,NULL ); + bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_NDELAY ,NULL ,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev); sdev =scsi_device_from_queue (bdev->bd_disk->queue);
drivers/block/rnbd/rnbd-srv.c +1 -1
@@ -719,7 +719,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, goto reject; } - bdev =blkdev_get_by_path (full_path, open_flags,THIS_MODULE ); + bdev =blkdev_get_by_path (full_path, open_flags,THIS_MODULE ,NULL );if (IS_ERR (bdev)) { ret =PTR_ERR (bdev); pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %d\n",
drivers/block/xen-blkback/xenbus.c +1 -1
@@ -492,7 +492,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, vbd->pdevice =MKDEV (major, minor); bdev =blkdev_get_by_dev (vbd->pdevice, vbd->readonly ? -FMODE_READ :FMODE_WRITE ,NULL ); +FMODE_READ :FMODE_WRITE ,NULL ,NULL );if (IS_ERR (bdev)) { pr_warn("xen_vbd_create: device %08x could not be opened\n",
drivers/block/zram/zram_drv.c +1 -1
@@ -508,7 +508,7 @@ static ssize_t backing_dev_store(struct device *dev, } bdev =blkdev_get_by_dev (inode->i_rdev, -FMODE_READ |FMODE_WRITE |FMODE_EXCL , zram); +FMODE_READ |FMODE_WRITE |FMODE_EXCL , zram,NULL );if (IS_ERR (bdev)) { err =PTR_ERR (bdev); bdev =NULL ;
drivers/md/bcache/super.c +1 -1
@@ -2561,7 +2561,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, err ="failed to open device" ; bdev =blkdev_get_by_path (strim (path),FMODE_READ |FMODE_WRITE |FMODE_EXCL , - sb); + sb,NULL );if (IS_ERR (bdev)) {if (bdev ==ERR_PTR (-EBUSY )) {dev_t dev;
drivers/md/dm.c +1 -1
@@ -746,7 +746,7 @@ static struct table_device *open_table_device(struct mapped_device *md,return ERR_PTR (-ENOMEM );refcount_set (&td->count,1 ); - bdev =blkdev_get_by_dev (dev, mode |FMODE_EXCL , _dm_claim_ptr); + bdev =blkdev_get_by_dev (dev, mode |FMODE_EXCL , _dm_claim_ptr,NULL );if (IS_ERR (bdev)) { r =PTR_ERR (bdev); goto out_free_td;
drivers/md/md.c +1 -1
@@ -3642,7 +3642,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe rdev->bdev =blkdev_get_by_dev (newdev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - super_format ==-2 ? &claim_rdev : rdev); + super_format ==-2 ? &claim_rdev : rdev,NULL );if (IS_ERR (rdev->bdev)) {pr_warn ("md: could not open device unknown-block(%u,%u).\n" ,MAJOR (newdev),MINOR (newdev));
drivers/mtd/devices/block2mtd.c +2 -2
@@ -235,7 +235,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,return NULL ;/* Get a handle on the device */ - bdev =blkdev_get_by_path (devname, mode, dev); + bdev =blkdev_get_by_path (devname, mode, dev,NULL );#ifndef MODULE /*
@@ -257,7 +257,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, devt =name_to_dev_t (devname);if (!devt)continue ; - bdev = blkdev_get_by_dev(devt, mode, dev); + bdev = blkdev_get_by_dev(devt, mode, dev, NULL); }#endif
drivers/nvme/target/io-cmd-bdev.c +1 -1
@@ -85,7 +85,7 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)return -ENOTBLK ; ns->bdev =blkdev_get_by_path (ns->device_path, -FMODE_READ |FMODE_WRITE ,NULL ); +FMODE_READ |FMODE_WRITE ,NULL ,NULL );if (IS_ERR (ns->bdev)) { ret =PTR_ERR (ns->bdev);if (ret != -ENOTBLK ) {
drivers/s390/block/dasd_genhd.c +1 -1
@@ -130,7 +130,7 @@ int dasd_scan_partitions(struct dasd_block *block)struct block_device *bdev;int rc; - bdev =blkdev_get_by_dev (disk_devt (block->gdp),FMODE_READ ,NULL ); + bdev =blkdev_get_by_dev (disk_devt (block->gdp),FMODE_READ ,NULL ,NULL );if (IS_ERR (bdev)) { DBF_DEV_EVENT(DBF_ERR, block->base, "scan partitions error, blkdev_get returned %ld",
drivers/target/target_core_iblock.c +1 -1
@@ -114,7 +114,7 @@ static int iblock_configure_device(struct se_device *dev)else dev->dev_flags |=DF_READ_ONLY ; - bd =blkdev_get_by_path (ib_dev->ibd_udev_path, mode, ib_dev); + bd =blkdev_get_by_path (ib_dev->ibd_udev_path, mode, ib_dev,NULL );if (IS_ERR (bd)) { ret =PTR_ERR (bd); goto out_free_bioset;
drivers/target/target_core_pscsi.c +2 -1
@@ -367,7 +367,8 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd)* for TYPE_DISK and TYPE_ZBC using supplied udev_path */ bd =blkdev_get_by_path (dev->udev_path, -FMODE_WRITE |FMODE_READ |FMODE_EXCL , pdv); +FMODE_WRITE |FMODE_READ |FMODE_EXCL , pdv, +NULL );if (IS_ERR (bd)) {pr_err ("pSCSI: blkdev_get_by_path() failed\n" );scsi_device_put (sd);
fs/btrfs/dev-replace.c +1 -1
@@ -258,7 +258,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, } bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + fs_info->bdev_holder,NULL );if (IS_ERR (bdev)) {btrfs_err (fs_info,"target device %s is invalid!" , device_path);return PTR_ERR (bdev);
fs/btrfs/volumes.c +3 -3
@@ -495,7 +495,7 @@ btrfs_get_bdev_and_sb(const char *device_path, fmode_t flags, void *holder, {int ret; - *bdev =blkdev_get_by_path (device_path, flags, holder); + *bdev =blkdev_get_by_path (device_path, flags, holder,NULL );if (IS_ERR (*bdev)) { ret =PTR_ERR (*bdev);
@@ -1376,7 +1376,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, fmode_t flags,* values temporarily, as the device paths of the fsid are the only * required information for assembling the volume. */ - bdev =blkdev_get_by_path (path, flags, holder); + bdev =blkdev_get_by_path (path, flags, holder,NULL );if (IS_ERR (bdev))return ERR_CAST (bdev);
@@ -2628,7 +2628,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathreturn -EROFS ; bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + fs_info->bdev_holder,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev);
fs/erofs/super.c +1 -1
@@ -254,7 +254,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, dif->fscache = fscache; }else if (!sbi->devs->flatdev) { bdev =blkdev_get_by_path (dif->path,FMODE_READ |FMODE_EXCL , - sb->s_type); + sb->s_type,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev); dif->bdev = bdev;
fs/ext4/super.c +2 -1
@@ -1101,7 +1101,8 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb) {struct block_device *bdev; - bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , sb); + bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , sb, +NULL );if (IS_ERR (bdev)) goto fail;return bdev;
fs/f2fs/super.c +2 -2
@@ -4025,7 +4025,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)/* Single zoned block device mount */ FDEV (0 ).bdev =blkdev_get_by_dev (sbi->sb->s_bdev->bd_dev, - sbi->sb->s_mode, sbi->sb->s_type); + sbi->sb->s_mode, sbi->sb->s_type,NULL ); }else {/* Multi-device mount */ memcpy (FDEV (i).path,RDEV (i).path,MAX_PATH_LEN );
@@ -4044,7 +4044,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) sbi->log_blocks_per_seg) - 1; }FDEV (i).bdev =blkdev_get_by_path (FDEV (i).path, - sbi->sb->s_mode, sbi->sb->s_type); + sbi->sb->s_mode, sbi->sb->s_type,NULL ); }if (IS_ERR (FDEV (i).bdev))return PTR_ERR (FDEV (i).bdev);
fs/jfs/jfs_logmgr.c +1 -1
@@ -1101,7 +1101,7 @@ int lmLogOpen(struct super_block *sb)*/ bdev =blkdev_get_by_dev (sbi->logdev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - log); + log,NULL );if (IS_ERR (bdev)) { rc =PTR_ERR (bdev); goto free;
fs/nfs/blocklayout/dev.c +3 -2
@@ -243,7 +243,7 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,if (!dev)return -EIO ; - bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE ,NULL ); + bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE ,NULL ,NULL );if (IS_ERR (bdev)) {printk (KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n" ,MAJOR (dev),MINOR (dev),PTR_ERR (bdev));
@@ -312,7 +312,8 @@ bl_open_path(struct pnfs_block_volume *v, const char *prefix)if (!devname)return ERR_PTR (-ENOMEM ); - bdev =blkdev_get_by_path (devname,FMODE_READ |FMODE_WRITE ,NULL ); + bdev =blkdev_get_by_path (devname,FMODE_READ |FMODE_WRITE ,NULL , +NULL );if (IS_ERR (bdev)) {pr_warn ("pNFS: failed to open device %s (%ld)\n" , devname,PTR_ERR (bdev));
fs/nilfs2/super.c +1 -1
@@ -1285,7 +1285,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,if (!(flags &SB_RDONLY )) mode |=FMODE_WRITE ; - sd.bdev =blkdev_get_by_path (dev_name, mode, fs_type); + sd.bdev =blkdev_get_by_path (dev_name, mode, fs_type,NULL );if (IS_ERR (sd.bdev))return ERR_CAST (sd.bdev);
fs/ocfs2/cluster/heartbeat.c +1 -1
@@ -1786,7 +1786,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, goto out2; reg->hr_bdev =blkdev_get_by_dev (f.file->f_mapping->host->i_rdev, -FMODE_WRITE |FMODE_READ ,NULL ); +FMODE_WRITE |FMODE_READ ,NULL ,NULL );if (IS_ERR (reg->hr_bdev)) { ret =PTR_ERR (reg->hr_bdev); reg->hr_bdev =NULL ;
fs/reiserfs/journal.c +3 -2
@@ -2616,7 +2616,7 @@ static int journal_init_dev(struct super_block *super,if (jdev == super->s_dev) blkdev_mode &= ~FMODE_EXCL ; journal->j_dev_bd =blkdev_get_by_dev (jdev, blkdev_mode, - journal); + journal,NULL ); journal->j_dev_mode = blkdev_mode;if (IS_ERR (journal->j_dev_bd)) { result =PTR_ERR (journal->j_dev_bd);
@@ -2632,7 +2632,8 @@ static int journal_init_dev(struct super_block *super, } journal->j_dev_mode = blkdev_mode; - journal->j_dev_bd =blkdev_get_by_path (jdev_name, blkdev_mode, journal); + journal->j_dev_bd =blkdev_get_by_path (jdev_name, blkdev_mode, journal, +NULL );if (IS_ERR (journal->j_dev_bd)) { result =PTR_ERR (journal->j_dev_bd); journal->j_dev_bd =NULL ;
fs/super.c +2 -2
@@ -1248,7 +1248,7 @@ int get_tree_bdev(struct fs_context *fc,if (!fc->source)return invalf (fc,"No source specified" ); - bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type); + bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type,NULL );if (IS_ERR (bdev)) {errorf (fc,"%s: Can't open blockdev" , fc->source);return PTR_ERR (bdev);
@@ -1333,7 +1333,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,if (!(flags &SB_RDONLY )) mode |=FMODE_WRITE ; - bdev =blkdev_get_by_path (dev_name, mode, fs_type); + bdev =blkdev_get_by_path (dev_name, mode, fs_type,NULL );if (IS_ERR (bdev))return ERR_CAST (bdev);
fs/xfs/xfs_super.c +1 -1
@@ -386,7 +386,7 @@ xfs_blkdev_get(int error =0 ; *bdevp =blkdev_get_by_path (name,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - mp); + mp,NULL );if (IS_ERR (*bdevp)) { error =PTR_ERR (*bdevp);xfs_warn (mp,"Invalid device [%s], error=%d" , name, error);
include/linux/blk_types.h +2 -0
@@ -55,6 +55,8 @@ struct block_device {struct super_block * bd_super;void * bd_claiming;void * bd_holder; +const struct blk_holder_ops *bd_holder_ops; +struct mutex bd_holder_lock;/* The counter of freeze processes */ int bd_fsfreeze_count;int bd_holders;
include/linux/blkdev.h +6 -2
@@ -1468,9 +1468,13 @@ void blkdev_show(struct seq_file *seqf, off_t offset);#define BLKDEV_MAJOR_MAX 0#endif +struct blk_holder_ops { +}; + +struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder, +const struct blk_holder_ops *hops);struct block_device *blkdev_get_by_path (const char *path,fmode_t mode, -void *holder); -struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder); +void *holder,const struct blk_holder_ops *hops);int bd_prepare_to_claim (struct block_device *bdev,void *holder);void bd_abort_claiming (struct block_device *bdev,void *holder);void blkdev_put (struct block_device *bdev,fmode_t mode);
kernel/power/swap.c +2 -2
@@ -357,7 +357,7 @@ static int swsusp_swap_check(void) root_swap = res; hib_resume_bdev =blkdev_get_by_dev (swsusp_resume_device,FMODE_WRITE , -NULL ); +NULL ,NULL );if (IS_ERR (hib_resume_bdev))return PTR_ERR (hib_resume_bdev);
@@ -1524,7 +1524,7 @@ int swsusp_check(void) mode |=FMODE_EXCL ; hib_resume_bdev =blkdev_get_by_dev (swsusp_resume_device, - mode, &holder); + mode, &holder,NULL );if (!IS_ERR (hib_resume_bdev)) {set_blocksize (hib_resume_bdev,PAGE_SIZE );clear_page (swsusp_header);
mm/swapfile.c +2 -1
@@ -2770,7 +2770,8 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)if (S_ISBLK (inode->i_mode)) { p->bdev =blkdev_get_by_dev (inode->i_rdev, -FMODE_READ |FMODE_WRITE |FMODE_EXCL , p); +FMODE_READ |FMODE_WRITE |FMODE_EXCL , p, +NULL );if (IS_ERR (p->bdev)) { error =PTR_ERR (p->bdev); p->bdev =NULL ;
Signature · 1 line
2.39.2
Re: [PATCH 5/9] block: introduce holder ops
Quoted 32 lines · Christoph Hellwig
Add a new
blk_holder_opsstructure, which is passed to blkdev_get_by_* and installed in theblock_devicefor exclusive claims. It will be used to allow the block layer to call back into the user of the block device for thing like notification of a removed device or a device resize.Signed-off-by Christoph Hellwig <[email protected]>--- block/bdev.c | 20 +++++++++++++++----- block/fops.c | 2 +- block/genhd.c | 3 ++- block/ioctl.c | 3 ++- drivers/block/drbd/drbd_nl.c | 3 ++- drivers/block/pktcdvd.c | 5 +++-- drivers/block/rnbd/rnbd-srv.c | 2 +- drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/zram/zram_drv.c | 2 +- drivers/md/bcache/super.c | 2 +- drivers/md/dm.c | 2 +- drivers/md/md.c | 2 +- drivers/mtd/devices/block2mtd.c | 4 ++-- drivers/nvme/target/io-cmd-bdev.c | 2 +- drivers/s390/block/dasd_genhd.c | 2 +- drivers/target/target_core_iblock.c | 2 +- drivers/target/target_core_pscsi.c | 3 ++- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/volumes.c | 6 +++--- fs/erofs/super.c | 2 +- fs/ext4/super.c | 3 ++- fs/f2fs/super.c | 4 ++-- fs/jfs/jfs_logmgr.c | 2 +- fs/nfs/blocklayout/dev.c | 5 +++-- fs/nilfs2/super.c | 2 +-
Quoted 8 lines
fs/ocfs2/cluster/heartbeat.c | 2 +- fs/reiserfs/journal.c | 5 +++-- fs/super.c | 4 ++-- fs/xfs/xfs_super.c | 2 +- include/linux/blk_types.h | 2 ++ include/linux/blkdev.h | 8 ++++++-- kernel/power/swap.c | 4 ++-- mm/swapfile.c | 3 ++-
Fun question: What happens when the swap disk falls off the bus?
Quoted 123 lines
33 files changed, 71 insertions(+), 46 deletions(-)block/bdev.c +15
-5@@ -415,6 +415,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) bdev =I_BDEV (inode);mutex_init (&bdev->bd_fsfreeze_mutex);spin_lock_init (&bdev->bd_size_lock); +mutex_init (&bdev->bd_holder_lock); bdev->bd_partno = partno; bdev->bd_inode = inode; bdev->bd_queue = disk->queue;@@ -542,7 +543,8 @@ static void bd_clear_claiming(struct block_device *whole, void *holder)* Finish exclusive open of a block device. Mark the device as exlusively * open by the holder and wake up all waiters for exclusive open to finish. */ -static void bd_finish_claiming (struct block_device *bdev,void *holder) +static void bd_finish_claiming (struct block_device *bdev,void *holder, +const struct blk_holder_ops *hops) {struct block_device *whole =bdev_whole (bdev);@@ -555,7 +557,10 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) whole->bd_holders++; whole->bd_holder = bd_may_claim; bdev->bd_holders++; +mutex_lock (&bdev->bd_holder_lock); bdev->bd_holder = holder; + bdev->bd_holder_ops = hops; +mutex_unlock (&bdev->bd_holder_lock);bd_clear_claiming (whole, holder);mutex_unlock (&bdev_lock); }@@ -590,7 +595,10 @@ static void bd_end_claim(struct block_device *bdev)WARN_ON_ONCE (--bdev->bd_holders <0 );WARN_ON_ONCE (--whole->bd_holders <0 );if (!bdev->bd_holders) { +mutex_lock (&bdev->bd_holder_lock); bdev->bd_holder =NULL ; + bdev->bd_holder_ops =NULL ; +mutex_unlock (&bdev->bd_holder_lock);if (bdev->bd_write_holder) unblock = true; }@@ -720,6 +728,7 @@ void blkdev_put_no_open(struct block_device *bdev)* @dev: device number of block device to open * @mode: FMODE_* mask * @holder: exclusive holder identifier +* @hops: holder operations * * Open the block device described by device number @dev. If @mode includes * %FMODE_EXCL, the block device is opened with exclusive access. Specifying @@ -736,7 +745,8 @@ void blkdev_put_no_open(struct block_device *bdev)* RETURNS: * Reference to the block_device on success, ERR_PTR(-errno) on failure. */ -struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder) +struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder, +const struct blk_holder_ops *hops) {bool unblock_events = true;struct block_device *bdev;@@ -776,7 +786,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)if (ret) goto put_module;if (mode &FMODE_EXCL ) { -bd_finish_claiming (bdev, holder); +bd_finish_claiming (bdev, holder, hops);/* * Block event polling for write claims if requested. Any write @@ -827,7 +837,7 @@ EXPORT_SYMBOL(blkdev_get_by_dev);* Reference to the block_device on success, ERR_PTR(-errno) on failure. */ struct block_device *blkdev_get_by_path (const char *path,fmode_t mode, -void *holder) +void *holder,const struct blk_holder_ops *hops) {struct block_device *bdev;dev_t dev;@@ -837,7 +847,7 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,if (error)return ERR_PTR (error); - bdev =blkdev_get_by_dev (dev, mode, holder); + bdev =blkdev_get_by_dev (dev, mode, holder, hops);if (!IS_ERR (bdev) && (mode &FMODE_WRITE ) &&bdev_read_only (bdev)) {blkdev_put (bdev, mode);return ERR_PTR (-EACCES );block/fops.c +1
-1@@ -490,7 +490,7 @@ static int blkdev_open(struct inode *inode, struct file *filp)if ((filp->f_flags &O_ACCMODE ) ==3 ) filp->f_mode |=FMODE_WRITE_IOCTL ; - bdev =blkdev_get_by_dev (inode->i_rdev, filp->f_mode, filp); + bdev =blkdev_get_by_dev (inode->i_rdev, filp->f_mode, filp,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev);block/genhd.c +2
-1@@ -381,7 +381,8 @@ int disk_scan_partitions(struct gendisk *disk, fmode_t mode) }set_bit (GD_NEED_PART_SCAN , &disk->state); - bdev =blkdev_get_by_dev (disk_devt (disk), mode & ~FMODE_EXCL ,NULL ); + bdev =blkdev_get_by_dev (disk_devt (disk), mode & ~FMODE_EXCL ,NULL , +NULL );if (IS_ERR (bdev)) ret =PTR_ERR (bdev);else block/ioctl.c +0
-0
block/ioctl.c static int blkdev_bszset(struct block_device *bdev, fmode_t mode, · line 461
Quoted 9 lines
block/ioctl.c +2
-1@@ -454,7 +454,8 @@ static int blkdev_bszset(struct block_device *bdev, fmode_t mode,if (mode &FMODE_EXCL )return set_blocksize (bdev, n); -if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev))) +if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev, +NULL )))return -EBUSY ; ret =set_blocksize (bdev, n);blkdev_put (bdev, mode |FMODE_EXCL );
Somewhat related question: Should we allow userspace to initiate a fs shutdown through the block device? Let's say you're preparing to yank /dev/sda and want to kill anything attached to it or its partitions? Without having to walk through however many mount namespaces there are to find the mountpoints?
<skip down to the xfs changes>
Quoted 395 lines
drivers/block/drbd/drbd_nl.c +2
-1@@ -1641,7 +1641,8 @@ static struct block_device *open_backing_dev(struct drbd_device *device,int err =0 ; bdev =blkdev_get_by_path (bdev_path, -FMODE_READ |FMODE_WRITE |FMODE_EXCL , claim_ptr); +FMODE_READ |FMODE_WRITE |FMODE_EXCL , + claim_ptr,NULL );if (IS_ERR (bdev)) {drbd_err (device,"open(\"%s\") failed with %ld\n" , bdev_path,PTR_ERR (bdev));drivers/block/pktcdvd.c +3
-2@@ -2125,7 +2125,8 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)* to read/write from/to it. It is already opened in O_NONBLOCK mode * so open should not fail. */ - bdev =blkdev_get_by_dev (pd->bdev->bd_dev,FMODE_READ |FMODE_EXCL , pd); + bdev =blkdev_get_by_dev (pd->bdev->bd_dev,FMODE_READ |FMODE_EXCL , pd, +NULL );if (IS_ERR (bdev)) { ret =PTR_ERR (bdev); goto out;@@ -2530,7 +2531,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) } } - bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_NDELAY ,NULL ); + bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_NDELAY ,NULL ,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev); sdev =scsi_device_from_queue (bdev->bd_disk->queue);drivers/block/rnbd/rnbd-srv.c +1
-1@@ -719,7 +719,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, goto reject; } - bdev =blkdev_get_by_path (full_path, open_flags,THIS_MODULE ); + bdev =blkdev_get_by_path (full_path, open_flags,THIS_MODULE ,NULL );if (IS_ERR (bdev)) { ret =PTR_ERR (bdev); pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %d\n",drivers/block/xen-blkback/xenbus.c +1
-1@@ -492,7 +492,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, vbd->pdevice =MKDEV (major, minor); bdev =blkdev_get_by_dev (vbd->pdevice, vbd->readonly ? -FMODE_READ :FMODE_WRITE ,NULL ); +FMODE_READ :FMODE_WRITE ,NULL ,NULL );if (IS_ERR (bdev)) { pr_warn("xen_vbd_create: device %08x could not be opened\n",drivers/block/zram/zram_drv.c +1
-1@@ -508,7 +508,7 @@ static ssize_t backing_dev_store(struct device *dev, } bdev =blkdev_get_by_dev (inode->i_rdev, -FMODE_READ |FMODE_WRITE |FMODE_EXCL , zram); +FMODE_READ |FMODE_WRITE |FMODE_EXCL , zram,NULL );if (IS_ERR (bdev)) { err =PTR_ERR (bdev); bdev =NULL ;drivers/md/bcache/super.c +1
-1@@ -2561,7 +2561,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, err ="failed to open device" ; bdev =blkdev_get_by_path (strim (path),FMODE_READ |FMODE_WRITE |FMODE_EXCL , - sb); + sb,NULL );if (IS_ERR (bdev)) {if (bdev ==ERR_PTR (-EBUSY )) {dev_t dev;drivers/md/dm.c +1
-1@@ -746,7 +746,7 @@ static struct table_device *open_table_device(struct mapped_device *md,return ERR_PTR (-ENOMEM );refcount_set (&td->count,1 ); - bdev =blkdev_get_by_dev (dev, mode |FMODE_EXCL , _dm_claim_ptr); + bdev =blkdev_get_by_dev (dev, mode |FMODE_EXCL , _dm_claim_ptr,NULL );if (IS_ERR (bdev)) { r =PTR_ERR (bdev); goto out_free_td;drivers/md/md.c +1
-1@@ -3642,7 +3642,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe rdev->bdev =blkdev_get_by_dev (newdev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - super_format ==-2 ? &claim_rdev : rdev); + super_format ==-2 ? &claim_rdev : rdev,NULL );if (IS_ERR (rdev->bdev)) {pr_warn ("md: could not open device unknown-block(%u,%u).\n" ,MAJOR (newdev),MINOR (newdev));drivers/mtd/devices/block2mtd.c +2
-2@@ -235,7 +235,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,return NULL ;/* Get a handle on the device */ - bdev =blkdev_get_by_path (devname, mode, dev); + bdev =blkdev_get_by_path (devname, mode, dev,NULL );#ifndef MODULE /* @@ -257,7 +257,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, devt =name_to_dev_t (devname);if (!devt)continue ; - bdev = blkdev_get_by_dev(devt, mode, dev); + bdev = blkdev_get_by_dev(devt, mode, dev, NULL); }#endif drivers/nvme/target/io-cmd-bdev.c +1
-1@@ -85,7 +85,7 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)return -ENOTBLK ; ns->bdev =blkdev_get_by_path (ns->device_path, -FMODE_READ |FMODE_WRITE ,NULL ); +FMODE_READ |FMODE_WRITE ,NULL ,NULL );if (IS_ERR (ns->bdev)) { ret =PTR_ERR (ns->bdev);if (ret != -ENOTBLK ) {drivers/s390/block/dasd_genhd.c +1
-1@@ -130,7 +130,7 @@ int dasd_scan_partitions(struct dasd_block *block)struct block_device *bdev;int rc; - bdev =blkdev_get_by_dev (disk_devt (block->gdp),FMODE_READ ,NULL ); + bdev =blkdev_get_by_dev (disk_devt (block->gdp),FMODE_READ ,NULL ,NULL );if (IS_ERR (bdev)) { DBF_DEV_EVENT(DBF_ERR, block->base, "scan partitions error, blkdev_get returned %ld",drivers/target/target_core_iblock.c +1
-1@@ -114,7 +114,7 @@ static int iblock_configure_device(struct se_device *dev)else dev->dev_flags |=DF_READ_ONLY ; - bd =blkdev_get_by_path (ib_dev->ibd_udev_path, mode, ib_dev); + bd =blkdev_get_by_path (ib_dev->ibd_udev_path, mode, ib_dev,NULL );if (IS_ERR (bd)) { ret =PTR_ERR (bd); goto out_free_bioset;drivers/target/target_core_pscsi.c +2
-1@@ -367,7 +367,8 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd)* for TYPE_DISK and TYPE_ZBC using supplied udev_path */ bd =blkdev_get_by_path (dev->udev_path, -FMODE_WRITE |FMODE_READ |FMODE_EXCL , pdv); +FMODE_WRITE |FMODE_READ |FMODE_EXCL , pdv, +NULL );if (IS_ERR (bd)) {pr_err ("pSCSI: blkdev_get_by_path() failed\n" );scsi_device_put (sd);fs/btrfs/dev-replace.c +1
-1@@ -258,7 +258,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, } bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + fs_info->bdev_holder,NULL );if (IS_ERR (bdev)) {btrfs_err (fs_info,"target device %s is invalid!" , device_path);return PTR_ERR (bdev);fs/btrfs/volumes.c +3
-3@@ -495,7 +495,7 @@ btrfs_get_bdev_and_sb(const char *device_path, fmode_t flags, void *holder, {int ret; - *bdev =blkdev_get_by_path (device_path, flags, holder); + *bdev =blkdev_get_by_path (device_path, flags, holder,NULL );if (IS_ERR (*bdev)) { ret =PTR_ERR (*bdev);@@ -1376,7 +1376,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, fmode_t flags,* values temporarily, as the device paths of the fsid are the only * required information for assembling the volume. */ - bdev =blkdev_get_by_path (path, flags, holder); + bdev =blkdev_get_by_path (path, flags, holder,NULL );if (IS_ERR (bdev))return ERR_CAST (bdev);@@ -2628,7 +2628,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathreturn -EROFS ; bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + fs_info->bdev_holder,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev);fs/erofs/super.c +1
-1@@ -254,7 +254,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, dif->fscache = fscache; }else if (!sbi->devs->flatdev) { bdev =blkdev_get_by_path (dif->path,FMODE_READ |FMODE_EXCL , - sb->s_type); + sb->s_type,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev); dif->bdev = bdev;fs/ext4/super.c +2
-1@@ -1101,7 +1101,8 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb) {struct block_device *bdev; - bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , sb); + bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , sb, +NULL );if (IS_ERR (bdev)) goto fail;return bdev;fs/f2fs/super.c +2
-2@@ -4025,7 +4025,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)/* Single zoned block device mount */ FDEV (0 ).bdev =blkdev_get_by_dev (sbi->sb->s_bdev->bd_dev, - sbi->sb->s_mode, sbi->sb->s_type); + sbi->sb->s_mode, sbi->sb->s_type,NULL ); }else {/* Multi-device mount */ memcpy (FDEV (i).path,RDEV (i).path,MAX_PATH_LEN );@@ -4044,7 +4044,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) sbi->log_blocks_per_seg) - 1; }FDEV (i).bdev =blkdev_get_by_path (FDEV (i).path, - sbi->sb->s_mode, sbi->sb->s_type); + sbi->sb->s_mode, sbi->sb->s_type,NULL ); }if (IS_ERR (FDEV (i).bdev))return PTR_ERR (FDEV (i).bdev);fs/jfs/jfs_logmgr.c +1
-1@@ -1101,7 +1101,7 @@ int lmLogOpen(struct super_block *sb)*/ bdev =blkdev_get_by_dev (sbi->logdev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - log); + log,NULL );if (IS_ERR (bdev)) { rc =PTR_ERR (bdev); goto free;fs/nfs/blocklayout/dev.c +3
-2@@ -243,7 +243,7 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,if (!dev)return -EIO ; - bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE ,NULL ); + bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE ,NULL ,NULL );if (IS_ERR (bdev)) {printk (KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n" ,MAJOR (dev),MINOR (dev),PTR_ERR (bdev));@@ -312,7 +312,8 @@ bl_open_path(struct pnfs_block_volume *v, const char *prefix)if (!devname)return ERR_PTR (-ENOMEM ); - bdev =blkdev_get_by_path (devname,FMODE_READ |FMODE_WRITE ,NULL ); + bdev =blkdev_get_by_path (devname,FMODE_READ |FMODE_WRITE ,NULL , +NULL );if (IS_ERR (bdev)) {pr_warn ("pNFS: failed to open device %s (%ld)\n" , devname,PTR_ERR (bdev));fs/nilfs2/super.c +1
-1@@ -1285,7 +1285,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,if (!(flags &SB_RDONLY )) mode |=FMODE_WRITE ; - sd.bdev =blkdev_get_by_path (dev_name, mode, fs_type); + sd.bdev =blkdev_get_by_path (dev_name, mode, fs_type,NULL );if (IS_ERR (sd.bdev))return ERR_CAST (sd.bdev);fs/ocfs2/cluster/heartbeat.c +1
-1@@ -1786,7 +1786,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, goto out2; reg->hr_bdev =blkdev_get_by_dev (f.file->f_mapping->host->i_rdev, -FMODE_WRITE |FMODE_READ ,NULL ); +FMODE_WRITE |FMODE_READ ,NULL ,NULL );if (IS_ERR (reg->hr_bdev)) { ret =PTR_ERR (reg->hr_bdev); reg->hr_bdev =NULL ;fs/reiserfs/journal.c +3
-2@@ -2616,7 +2616,7 @@ static int journal_init_dev(struct super_block *super,if (jdev == super->s_dev) blkdev_mode &= ~FMODE_EXCL ; journal->j_dev_bd =blkdev_get_by_dev (jdev, blkdev_mode, - journal); + journal,NULL ); journal->j_dev_mode = blkdev_mode;if (IS_ERR (journal->j_dev_bd)) { result =PTR_ERR (journal->j_dev_bd);@@ -2632,7 +2632,8 @@ static int journal_init_dev(struct super_block *super, } journal->j_dev_mode = blkdev_mode; - journal->j_dev_bd =blkdev_get_by_path (jdev_name, blkdev_mode, journal); + journal->j_dev_bd =blkdev_get_by_path (jdev_name, blkdev_mode, journal, +NULL );if (IS_ERR (journal->j_dev_bd)) { result =PTR_ERR (journal->j_dev_bd); journal->j_dev_bd =NULL ;fs/super.c +2
-2@@ -1248,7 +1248,7 @@ int get_tree_bdev(struct fs_context *fc,if (!fc->source)return invalf (fc,"No source specified" ); - bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type); + bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type,NULL );if (IS_ERR (bdev)) {errorf (fc,"%s: Can't open blockdev" , fc->source);return PTR_ERR (bdev);@@ -1333,7 +1333,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,if (!(flags &SB_RDONLY )) mode |=FMODE_WRITE ; - bdev =blkdev_get_by_path (dev_name, mode, fs_type); + bdev =blkdev_get_by_path (dev_name, mode, fs_type,NULL );if (IS_ERR (bdev))return ERR_CAST (bdev);fs/xfs/xfs_super.c +0
-0
fs/xfs/xfs_super.c xfs_blkdev_get( · line 392
Quoted 8 lines
fs/xfs/xfs_super.c +1
-1@@ -386,7 +386,7 @@ xfs_blkdev_get(int error =0 ; *bdevp =blkdev_get_by_path (name,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - mp); + mp,NULL );if (IS_ERR (*bdevp)) { error =PTR_ERR (*bdevp);xfs_warn (mp,"Invalid device [%s], error=%d" , name, error);
I only looked at fs/xfs/, fs/*.c, and the block layer changes. For those parts,
(I didn't see anything obviously wrong in the rest of the patch, but I'm no pktcdvd expert...)
--D
Quoted 72 lines
include/linux/blk_types.h +2
-0@@ -55,6 +55,8 @@ struct block_device {struct super_block * bd_super;void * bd_claiming;void * bd_holder; +const struct blk_holder_ops *bd_holder_ops; +struct mutex bd_holder_lock;/* The counter of freeze processes */ int bd_fsfreeze_count;int bd_holders;include/linux/blkdev.h +6
-2@@ -1468,9 +1468,13 @@ void blkdev_show(struct seq_file *seqf, off_t offset);#define BLKDEV_MAJOR_MAX 0#endif +struct blk_holder_ops { +}; + +struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder, +const struct blk_holder_ops *hops);struct block_device *blkdev_get_by_path (const char *path,fmode_t mode, -void *holder); -struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder); +void *holder,const struct blk_holder_ops *hops);int bd_prepare_to_claim (struct block_device *bdev,void *holder);void bd_abort_claiming (struct block_device *bdev,void *holder);void blkdev_put (struct block_device *bdev,fmode_t mode);kernel/power/swap.c +2
-2@@ -357,7 +357,7 @@ static int swsusp_swap_check(void) root_swap = res; hib_resume_bdev =blkdev_get_by_dev (swsusp_resume_device,FMODE_WRITE , -NULL ); +NULL ,NULL );if (IS_ERR (hib_resume_bdev))return PTR_ERR (hib_resume_bdev);@@ -1524,7 +1524,7 @@ int swsusp_check(void) mode |=FMODE_EXCL ; hib_resume_bdev =blkdev_get_by_dev (swsusp_resume_device, - mode, &holder); + mode, &holder,NULL );if (!IS_ERR (hib_resume_bdev)) {set_blocksize (hib_resume_bdev,PAGE_SIZE );clear_page (swsusp_header);mm/swapfile.c +2
-1@@ -2770,7 +2770,8 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)if (S_ISBLK (inode->i_mode)) { p->bdev =blkdev_get_by_dev (inode->i_rdev, -FMODE_READ |FMODE_WRITE |FMODE_EXCL , p); +FMODE_READ |FMODE_WRITE |FMODE_EXCL , p, +NULL );if (IS_ERR (p->bdev)) { error =PTR_ERR (p->bdev); p->bdev =NULL ;Signature · 1 line
2.39.2
Christoph Hellwig
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 1 line · Darrick J. Wong
Fun question: What happens when the swap disk falls off the bus?
Your system is toast.
Quoted 4 lines
Quoted 4 lines
block/ioctl.c +2
-1-if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev))) +if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev, +NULL )))return -EBUSY ;
Quoted 8 lines
block/ioctl.c static int blkdev_bszset(struct block_device *bdev, fmode_t mode, · line 461
Quoted 2 lines
block/ioctl.c +0
-0ret =set_blocksize (bdev, n);blkdev_put (bdev, mode |FMODE_EXCL );Somewhat related question: Should we allow userspace to initiate a fs shutdown through the block device? Let's say you're preparing to yank
/dev/sdaand want to kill anything attached to it or its partitions? Without having to walk through however many mount namespaces there are to find the mountpoints?
That's kinda what we're doing here. Or do you mean even more advanced notice by having another callout before stopping I/O so that we could write out all log buffers? It's probably doable, but I'm not convinced that this use case is worth maintaining and testing the kernel code for it.
Re: [PATCH 5/9] block: introduce holder ops
Quoted 18 lines · Christoph Hellwig
Quoted 1 line · Darrick J. Wong
Fun question: What happens when the swap disk falls off the bus?
Your system is toast.
Quoted 4 lines
Quoted 4 lines
block/ioctl.c +2
-1-if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev))) +if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev, +NULL )))return -EBUSY ;Quoted 8 lines
block/ioctl.c static int blkdev_bszset(struct block_device *bdev, fmode_t mode, · line 461
Quoted 2 lines
block/ioctl.c +0
-0ret =set_blocksize (bdev, n);blkdev_put (bdev, mode |FMODE_EXCL );Somewhat related question: Should we allow userspace to initiate a fs shutdown through the block device? Let's say you're preparing to yank
/dev/sdaand want to kill anything attached to it or its partitions? Without having to walk through however many mount namespaces there are to find the mountpoints?
Quoted 5 lines
That's kinda what we're doing here. Or do you mean even more advanced notice by having another callout before stopping I/O so that we could write out all log buffers? It's probably doable, but I'm not convinced that this use case is worth maintaining and testing the kernel code for it.
The userspace shutdown code already does this by default - it actually calls freeze_bdev() to cause the filesystem to be made consistent on the block device before it executes the shutdown. So, in effect, we already have the "shutdown before turning off block device" paths in the filesystems and extremely well tested.
Indeed, if the device is being removed, why not call freeze_bdev() before doing anything else? It guarantees that applications will be quiesced and the filesystem will stabilise and not try to change anything until the shutdown occurs when the device is pulled...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 5/9] block: introduce holder ops
Quoted 31 lines · Dave Chinner
Quoted 18 lines · Christoph Hellwig
Quoted 1 line · Darrick J. Wong
Fun question: What happens when the swap disk falls off the bus?
Your system is toast.
Quoted 4 lines
Quoted 4 lines
block/ioctl.c +2
-1-if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev))) +if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev, +NULL )))return -EBUSY ;Quoted 8 lines
block/ioctl.c static int blkdev_bszset(struct block_device *bdev, fmode_t mode, · line 461
Quoted 2 lines
block/ioctl.c +0
-0ret =set_blocksize (bdev, n);blkdev_put (bdev, mode |FMODE_EXCL );Somewhat related question: Should we allow userspace to initiate a fs shutdown through the block device? Let's say you're preparing to yank
/dev/sdaand want to kill anything attached to it or its partitions? Without having to walk through however many mount namespaces there are to find the mountpoints?Quoted 5 lines
That's kinda what we're doing here. Or do you mean even more advanced notice by having another callout before stopping I/O so that we could write out all log buffers? It's probably doable, but I'm not convinced that this use case is worth maintaining and testing the kernel code for it.
The userspace shutdown code already does this by default - it actually calls
freeze_bdev()to cause the filesystem to be made consistent on the block device before it executes the shutdown. So, in effect, we already have the "shutdown before turning off block device" paths in the filesystems and extremely well tested.
Quoted 4 lines
Indeed, if the device is being removed, why not call
freeze_bdev()before doing anything else? It guarantees that applications will be quiesced and the filesystem will stabilise and not try to change anything until the shutdown occurs when the device is pulled...
I think I want everything -- I want freeze_bdev on a device /before/ we pull it out so that we can try to flush dirty everything to the disk; I want that to work for the log/rt devices; and I want a final shutdown notification when the kernel drops the bdev so that we can offline the fs and shortcut/start returning EIO.
--D
Quoted 6 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Christoph Hellwig
maintainerRe: [PATCH 5/9] block: introduce holder ops
In reply to Dave ChinnerQuoted 5 lines · Dave Chinner
The userspace shutdown code already does this by default - it actually calls
freeze_bdev()to cause the filesystem to be made consistent on the block device before it executes the shutdown. So, in effect, we already have the "shutdown before turning off block device" paths in the filesystems and extremely well tested.
Yes.
Quoted 4 lines
Indeed, if the device is being removed, why not call
freeze_bdev()before doing anything else? It guarantees that applications will be quiesced and the filesystem will stabilise and not try to change anything until the shutdown occurs when the device is pulled...
Because the primary use case of using sysfs to yank a block device out under a live fs is testing the shutdown path. Changing behavior here will not improve any actual user live, because no user actually intentially does this, but at the same time we add new odd code we need to test, while breaking existing tests.
Re: [PATCH 5/9] block: introduce holder ops
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig
Add a new
blk_holder_opsstructure, which is passed to blkdev_get_by_* and installed in theblock_devicefor exclusive claims. It will be used to allow the block layer to call back into the user of the block device for thing like notification of a removed device or a device resize.Signed-off-by Christoph Hellwig <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 641 lines
--- block/bdev.c | 20 +++++++++++++++----- block/fops.c | 2 +- block/genhd.c | 3 ++- block/ioctl.c | 3 ++- drivers/block/drbd/drbd_nl.c | 3 ++- drivers/block/pktcdvd.c | 5 +++-- drivers/block/rnbd/rnbd-srv.c | 2 +- drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/zram/zram_drv.c | 2 +- drivers/md/bcache/super.c | 2 +- drivers/md/dm.c | 2 +- drivers/md/md.c | 2 +- drivers/mtd/devices/block2mtd.c | 4 ++-- drivers/nvme/target/io-cmd-bdev.c | 2 +- drivers/s390/block/dasd_genhd.c | 2 +- drivers/target/target_core_iblock.c | 2 +- drivers/target/target_core_pscsi.c | 3 ++- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/volumes.c | 6 +++--- fs/erofs/super.c | 2 +- fs/ext4/super.c | 3 ++- fs/f2fs/super.c | 4 ++-- fs/jfs/jfs_logmgr.c | 2 +- fs/nfs/blocklayout/dev.c | 5 +++-- fs/nilfs2/super.c | 2 +- fs/ocfs2/cluster/heartbeat.c | 2 +- fs/reiserfs/journal.c | 5 +++-- fs/super.c | 4 ++-- fs/xfs/xfs_super.c | 2 +- include/linux/blk_types.h | 2 ++ include/linux/blkdev.h | 8 ++++++-- kernel/power/swap.c | 4 ++-- mm/swapfile.c | 3 ++- 33 files changed, 71 insertions(+), 46 deletions(-)block/bdev.c +15
-5@@ -415,6 +415,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) bdev =I_BDEV (inode);mutex_init (&bdev->bd_fsfreeze_mutex);spin_lock_init (&bdev->bd_size_lock); +mutex_init (&bdev->bd_holder_lock); bdev->bd_partno = partno; bdev->bd_inode = inode; bdev->bd_queue = disk->queue;@@ -542,7 +543,8 @@ static void bd_clear_claiming(struct block_device *whole, void *holder)* Finish exclusive open of a block device. Mark the device as exlusively * open by the holder and wake up all waiters for exclusive open to finish. */ -static void bd_finish_claiming (struct block_device *bdev,void *holder) +static void bd_finish_claiming (struct block_device *bdev,void *holder, +const struct blk_holder_ops *hops) {struct block_device *whole =bdev_whole (bdev);@@ -555,7 +557,10 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) whole->bd_holders++; whole->bd_holder = bd_may_claim; bdev->bd_holders++; +mutex_lock (&bdev->bd_holder_lock); bdev->bd_holder = holder; + bdev->bd_holder_ops = hops; +mutex_unlock (&bdev->bd_holder_lock);bd_clear_claiming (whole, holder);mutex_unlock (&bdev_lock); }@@ -590,7 +595,10 @@ static void bd_end_claim(struct block_device *bdev)WARN_ON_ONCE (--bdev->bd_holders <0 );WARN_ON_ONCE (--whole->bd_holders <0 );if (!bdev->bd_holders) { +mutex_lock (&bdev->bd_holder_lock); bdev->bd_holder =NULL ; + bdev->bd_holder_ops =NULL ; +mutex_unlock (&bdev->bd_holder_lock);if (bdev->bd_write_holder) unblock = true; }@@ -720,6 +728,7 @@ void blkdev_put_no_open(struct block_device *bdev)* @dev: device number of block device to open * @mode: FMODE_* mask * @holder: exclusive holder identifier +* @hops: holder operations * * Open the block device described by device number @dev. If @mode includes * %FMODE_EXCL, the block device is opened with exclusive access. Specifying @@ -736,7 +745,8 @@ void blkdev_put_no_open(struct block_device *bdev)* RETURNS: * Reference to the block_device on success, ERR_PTR(-errno) on failure. */ -struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder) +struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder, +const struct blk_holder_ops *hops) {bool unblock_events = true;struct block_device *bdev;@@ -776,7 +786,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)if (ret) goto put_module;if (mode &FMODE_EXCL ) { -bd_finish_claiming (bdev, holder); +bd_finish_claiming (bdev, holder, hops);/* * Block event polling for write claims if requested. Any write @@ -827,7 +837,7 @@ EXPORT_SYMBOL(blkdev_get_by_dev);* Reference to the block_device on success, ERR_PTR(-errno) on failure. */ struct block_device *blkdev_get_by_path (const char *path,fmode_t mode, -void *holder) +void *holder,const struct blk_holder_ops *hops) {struct block_device *bdev;dev_t dev;@@ -837,7 +847,7 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,if (error)return ERR_PTR (error); - bdev =blkdev_get_by_dev (dev, mode, holder); + bdev =blkdev_get_by_dev (dev, mode, holder, hops);if (!IS_ERR (bdev) && (mode &FMODE_WRITE ) &&bdev_read_only (bdev)) {blkdev_put (bdev, mode);return ERR_PTR (-EACCES );block/fops.c +1
-1@@ -490,7 +490,7 @@ static int blkdev_open(struct inode *inode, struct file *filp)if ((filp->f_flags &O_ACCMODE ) ==3 ) filp->f_mode |=FMODE_WRITE_IOCTL ; - bdev =blkdev_get_by_dev (inode->i_rdev, filp->f_mode, filp); + bdev =blkdev_get_by_dev (inode->i_rdev, filp->f_mode, filp,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev);block/genhd.c +2
-1@@ -381,7 +381,8 @@ int disk_scan_partitions(struct gendisk *disk, fmode_t mode) }set_bit (GD_NEED_PART_SCAN , &disk->state); - bdev =blkdev_get_by_dev (disk_devt (disk), mode & ~FMODE_EXCL ,NULL ); + bdev =blkdev_get_by_dev (disk_devt (disk), mode & ~FMODE_EXCL ,NULL , +NULL );if (IS_ERR (bdev)) ret =PTR_ERR (bdev);else block/ioctl.c +2
-1@@ -454,7 +454,8 @@ static int blkdev_bszset(struct block_device *bdev, fmode_t mode,if (mode &FMODE_EXCL )return set_blocksize (bdev, n); -if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev))) +if (IS_ERR (blkdev_get_by_dev (bdev->bd_dev, mode |FMODE_EXCL , &bdev, +NULL )))return -EBUSY ; ret =set_blocksize (bdev, n);blkdev_put (bdev, mode |FMODE_EXCL );drivers/block/drbd/drbd_nl.c +2
-1@@ -1641,7 +1641,8 @@ static struct block_device *open_backing_dev(struct drbd_device *device,int err =0 ; bdev =blkdev_get_by_path (bdev_path, -FMODE_READ |FMODE_WRITE |FMODE_EXCL , claim_ptr); +FMODE_READ |FMODE_WRITE |FMODE_EXCL , + claim_ptr,NULL );if (IS_ERR (bdev)) {drbd_err (device,"open(\"%s\") failed with %ld\n" , bdev_path,PTR_ERR (bdev));drivers/block/pktcdvd.c +3
-2@@ -2125,7 +2125,8 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)* to read/write from/to it. It is already opened in O_NONBLOCK mode * so open should not fail. */ - bdev =blkdev_get_by_dev (pd->bdev->bd_dev,FMODE_READ |FMODE_EXCL , pd); + bdev =blkdev_get_by_dev (pd->bdev->bd_dev,FMODE_READ |FMODE_EXCL , pd, +NULL );if (IS_ERR (bdev)) { ret =PTR_ERR (bdev); goto out;@@ -2530,7 +2531,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) } } - bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_NDELAY ,NULL ); + bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_NDELAY ,NULL ,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev); sdev =scsi_device_from_queue (bdev->bd_disk->queue);drivers/block/rnbd/rnbd-srv.c +1
-1@@ -719,7 +719,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, goto reject; } - bdev =blkdev_get_by_path (full_path, open_flags,THIS_MODULE ); + bdev =blkdev_get_by_path (full_path, open_flags,THIS_MODULE ,NULL );if (IS_ERR (bdev)) { ret =PTR_ERR (bdev); pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %d\n",drivers/block/xen-blkback/xenbus.c +1
-1@@ -492,7 +492,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, vbd->pdevice =MKDEV (major, minor); bdev =blkdev_get_by_dev (vbd->pdevice, vbd->readonly ? -FMODE_READ :FMODE_WRITE ,NULL ); +FMODE_READ :FMODE_WRITE ,NULL ,NULL );if (IS_ERR (bdev)) { pr_warn("xen_vbd_create: device %08x could not be opened\n",drivers/block/zram/zram_drv.c +1
-1@@ -508,7 +508,7 @@ static ssize_t backing_dev_store(struct device *dev, } bdev =blkdev_get_by_dev (inode->i_rdev, -FMODE_READ |FMODE_WRITE |FMODE_EXCL , zram); +FMODE_READ |FMODE_WRITE |FMODE_EXCL , zram,NULL );if (IS_ERR (bdev)) { err =PTR_ERR (bdev); bdev =NULL ;drivers/md/bcache/super.c +1
-1@@ -2561,7 +2561,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, err ="failed to open device" ; bdev =blkdev_get_by_path (strim (path),FMODE_READ |FMODE_WRITE |FMODE_EXCL , - sb); + sb,NULL );if (IS_ERR (bdev)) {if (bdev ==ERR_PTR (-EBUSY )) {dev_t dev;drivers/md/dm.c +1
-1@@ -746,7 +746,7 @@ static struct table_device *open_table_device(struct mapped_device *md,return ERR_PTR (-ENOMEM );refcount_set (&td->count,1 ); - bdev =blkdev_get_by_dev (dev, mode |FMODE_EXCL , _dm_claim_ptr); + bdev =blkdev_get_by_dev (dev, mode |FMODE_EXCL , _dm_claim_ptr,NULL );if (IS_ERR (bdev)) { r =PTR_ERR (bdev); goto out_free_td;drivers/md/md.c +1
-1@@ -3642,7 +3642,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe rdev->bdev =blkdev_get_by_dev (newdev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - super_format ==-2 ? &claim_rdev : rdev); + super_format ==-2 ? &claim_rdev : rdev,NULL );if (IS_ERR (rdev->bdev)) {pr_warn ("md: could not open device unknown-block(%u,%u).\n" ,MAJOR (newdev),MINOR (newdev));drivers/mtd/devices/block2mtd.c +2
-2@@ -235,7 +235,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,return NULL ;/* Get a handle on the device */ - bdev =blkdev_get_by_path (devname, mode, dev); + bdev =blkdev_get_by_path (devname, mode, dev,NULL );#ifndef MODULE /* @@ -257,7 +257,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, devt =name_to_dev_t (devname);if (!devt)continue ; - bdev = blkdev_get_by_dev(devt, mode, dev); + bdev = blkdev_get_by_dev(devt, mode, dev, NULL); }#endif drivers/nvme/target/io-cmd-bdev.c +1
-1@@ -85,7 +85,7 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns)return -ENOTBLK ; ns->bdev =blkdev_get_by_path (ns->device_path, -FMODE_READ |FMODE_WRITE ,NULL ); +FMODE_READ |FMODE_WRITE ,NULL ,NULL );if (IS_ERR (ns->bdev)) { ret =PTR_ERR (ns->bdev);if (ret != -ENOTBLK ) {drivers/s390/block/dasd_genhd.c +1
-1@@ -130,7 +130,7 @@ int dasd_scan_partitions(struct dasd_block *block)struct block_device *bdev;int rc; - bdev =blkdev_get_by_dev (disk_devt (block->gdp),FMODE_READ ,NULL ); + bdev =blkdev_get_by_dev (disk_devt (block->gdp),FMODE_READ ,NULL ,NULL );if (IS_ERR (bdev)) { DBF_DEV_EVENT(DBF_ERR, block->base, "scan partitions error, blkdev_get returned %ld",drivers/target/target_core_iblock.c +1
-1@@ -114,7 +114,7 @@ static int iblock_configure_device(struct se_device *dev)else dev->dev_flags |=DF_READ_ONLY ; - bd =blkdev_get_by_path (ib_dev->ibd_udev_path, mode, ib_dev); + bd =blkdev_get_by_path (ib_dev->ibd_udev_path, mode, ib_dev,NULL );if (IS_ERR (bd)) { ret =PTR_ERR (bd); goto out_free_bioset;drivers/target/target_core_pscsi.c +2
-1@@ -367,7 +367,8 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd)* for TYPE_DISK and TYPE_ZBC using supplied udev_path */ bd =blkdev_get_by_path (dev->udev_path, -FMODE_WRITE |FMODE_READ |FMODE_EXCL , pdv); +FMODE_WRITE |FMODE_READ |FMODE_EXCL , pdv, +NULL );if (IS_ERR (bd)) {pr_err ("pSCSI: blkdev_get_by_path() failed\n" );scsi_device_put (sd);fs/btrfs/dev-replace.c +1
-1@@ -258,7 +258,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, } bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + fs_info->bdev_holder,NULL );if (IS_ERR (bdev)) {btrfs_err (fs_info,"target device %s is invalid!" , device_path);return PTR_ERR (bdev);fs/btrfs/volumes.c +3
-3@@ -495,7 +495,7 @@ btrfs_get_bdev_and_sb(const char *device_path, fmode_t flags, void *holder, {int ret; - *bdev =blkdev_get_by_path (device_path, flags, holder); + *bdev =blkdev_get_by_path (device_path, flags, holder,NULL );if (IS_ERR (*bdev)) { ret =PTR_ERR (*bdev);@@ -1376,7 +1376,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, fmode_t flags,* values temporarily, as the device paths of the fsid are the only * required information for assembling the volume. */ - bdev =blkdev_get_by_path (path, flags, holder); + bdev =blkdev_get_by_path (path, flags, holder,NULL );if (IS_ERR (bdev))return ERR_CAST (bdev);@@ -2628,7 +2628,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathreturn -EROFS ; bdev =blkdev_get_by_path (device_path,FMODE_WRITE |FMODE_EXCL , - fs_info->bdev_holder); + fs_info->bdev_holder,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev);fs/erofs/super.c +1
-1@@ -254,7 +254,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, dif->fscache = fscache; }else if (!sbi->devs->flatdev) { bdev =blkdev_get_by_path (dif->path,FMODE_READ |FMODE_EXCL , - sb->s_type); + sb->s_type,NULL );if (IS_ERR (bdev))return PTR_ERR (bdev); dif->bdev = bdev;fs/ext4/super.c +2
-1@@ -1101,7 +1101,8 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb) {struct block_device *bdev; - bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , sb); + bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , sb, +NULL );if (IS_ERR (bdev)) goto fail;return bdev;fs/f2fs/super.c +2
-2@@ -4025,7 +4025,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)/* Single zoned block device mount */ FDEV (0 ).bdev =blkdev_get_by_dev (sbi->sb->s_bdev->bd_dev, - sbi->sb->s_mode, sbi->sb->s_type); + sbi->sb->s_mode, sbi->sb->s_type,NULL ); }else {/* Multi-device mount */ memcpy (FDEV (i).path,RDEV (i).path,MAX_PATH_LEN );@@ -4044,7 +4044,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) sbi->log_blocks_per_seg) - 1; }FDEV (i).bdev =blkdev_get_by_path (FDEV (i).path, - sbi->sb->s_mode, sbi->sb->s_type); + sbi->sb->s_mode, sbi->sb->s_type,NULL ); }if (IS_ERR (FDEV (i).bdev))return PTR_ERR (FDEV (i).bdev);fs/jfs/jfs_logmgr.c +1
-1@@ -1101,7 +1101,7 @@ int lmLogOpen(struct super_block *sb)*/ bdev =blkdev_get_by_dev (sbi->logdev,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - log); + log,NULL );if (IS_ERR (bdev)) { rc =PTR_ERR (bdev); goto free;fs/nfs/blocklayout/dev.c +3
-2@@ -243,7 +243,7 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d,if (!dev)return -EIO ; - bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE ,NULL ); + bdev =blkdev_get_by_dev (dev,FMODE_READ |FMODE_WRITE ,NULL ,NULL );if (IS_ERR (bdev)) {printk (KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n" ,MAJOR (dev),MINOR (dev),PTR_ERR (bdev));@@ -312,7 +312,8 @@ bl_open_path(struct pnfs_block_volume *v, const char *prefix)if (!devname)return ERR_PTR (-ENOMEM ); - bdev =blkdev_get_by_path (devname,FMODE_READ |FMODE_WRITE ,NULL ); + bdev =blkdev_get_by_path (devname,FMODE_READ |FMODE_WRITE ,NULL , +NULL );if (IS_ERR (bdev)) {pr_warn ("pNFS: failed to open device %s (%ld)\n" , devname,PTR_ERR (bdev));fs/nilfs2/super.c +1
-1@@ -1285,7 +1285,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,if (!(flags &SB_RDONLY )) mode |=FMODE_WRITE ; - sd.bdev =blkdev_get_by_path (dev_name, mode, fs_type); + sd.bdev =blkdev_get_by_path (dev_name, mode, fs_type,NULL );if (IS_ERR (sd.bdev))return ERR_CAST (sd.bdev);fs/ocfs2/cluster/heartbeat.c +1
-1@@ -1786,7 +1786,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, goto out2; reg->hr_bdev =blkdev_get_by_dev (f.file->f_mapping->host->i_rdev, -FMODE_WRITE |FMODE_READ ,NULL ); +FMODE_WRITE |FMODE_READ ,NULL ,NULL );if (IS_ERR (reg->hr_bdev)) { ret =PTR_ERR (reg->hr_bdev); reg->hr_bdev =NULL ;fs/reiserfs/journal.c +3
-2@@ -2616,7 +2616,7 @@ static int journal_init_dev(struct super_block *super,if (jdev == super->s_dev) blkdev_mode &= ~FMODE_EXCL ; journal->j_dev_bd =blkdev_get_by_dev (jdev, blkdev_mode, - journal); + journal,NULL ); journal->j_dev_mode = blkdev_mode;if (IS_ERR (journal->j_dev_bd)) { result =PTR_ERR (journal->j_dev_bd);@@ -2632,7 +2632,8 @@ static int journal_init_dev(struct super_block *super, } journal->j_dev_mode = blkdev_mode; - journal->j_dev_bd =blkdev_get_by_path (jdev_name, blkdev_mode, journal); + journal->j_dev_bd =blkdev_get_by_path (jdev_name, blkdev_mode, journal, +NULL );if (IS_ERR (journal->j_dev_bd)) { result =PTR_ERR (journal->j_dev_bd); journal->j_dev_bd =NULL ;fs/super.c +2
-2@@ -1248,7 +1248,7 @@ int get_tree_bdev(struct fs_context *fc,if (!fc->source)return invalf (fc,"No source specified" ); - bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type); + bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type,NULL );if (IS_ERR (bdev)) {errorf (fc,"%s: Can't open blockdev" , fc->source);return PTR_ERR (bdev);@@ -1333,7 +1333,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,if (!(flags &SB_RDONLY )) mode |=FMODE_WRITE ; - bdev =blkdev_get_by_path (dev_name, mode, fs_type); + bdev =blkdev_get_by_path (dev_name, mode, fs_type,NULL );if (IS_ERR (bdev))return ERR_CAST (bdev);fs/xfs/xfs_super.c +1
-1@@ -386,7 +386,7 @@ xfs_blkdev_get(int error =0 ; *bdevp =blkdev_get_by_path (name,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - mp); + mp,NULL );if (IS_ERR (*bdevp)) { error =PTR_ERR (*bdevp);xfs_warn (mp,"Invalid device [%s], error=%d" , name, error);include/linux/blk_types.h +2
-0@@ -55,6 +55,8 @@ struct block_device {struct super_block * bd_super;void * bd_claiming;void * bd_holder; +const struct blk_holder_ops *bd_holder_ops; +struct mutex bd_holder_lock;/* The counter of freeze processes */ int bd_fsfreeze_count;int bd_holders;include/linux/blkdev.h +6
-2@@ -1468,9 +1468,13 @@ void blkdev_show(struct seq_file *seqf, off_t offset);#define BLKDEV_MAJOR_MAX 0#endif +struct blk_holder_ops { +}; + +struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder, +const struct blk_holder_ops *hops);struct block_device *blkdev_get_by_path (const char *path,fmode_t mode, -void *holder); -struct block_device *blkdev_get_by_dev (dev_t dev,fmode_t mode,void *holder); +void *holder,const struct blk_holder_ops *hops);int bd_prepare_to_claim (struct block_device *bdev,void *holder);void bd_abort_claiming (struct block_device *bdev,void *holder);void blkdev_put (struct block_device *bdev,fmode_t mode);kernel/power/swap.c +2
-2@@ -357,7 +357,7 @@ static int swsusp_swap_check(void) root_swap = res; hib_resume_bdev =blkdev_get_by_dev (swsusp_resume_device,FMODE_WRITE , -NULL ); +NULL ,NULL );if (IS_ERR (hib_resume_bdev))return PTR_ERR (hib_resume_bdev);@@ -1524,7 +1524,7 @@ int swsusp_check(void) mode |=FMODE_EXCL ; hib_resume_bdev =blkdev_get_by_dev (swsusp_resume_device, - mode, &holder); + mode, &holder,NULL );if (!IS_ERR (hib_resume_bdev)) {set_blocksize (hib_resume_bdev,PAGE_SIZE );clear_page (swsusp_header);mm/swapfile.c +2
-1@@ -2770,7 +2770,8 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)if (S_ISBLK (inode->i_mode)) { p->bdev =blkdev_get_by_dev (inode->i_rdev, -FMODE_READ |FMODE_WRITE |FMODE_EXCL , p); +FMODE_READ |FMODE_WRITE |FMODE_EXCL , p, +NULL );if (IS_ERR (p->bdev)) { error =PTR_ERR (p->bdev); p->bdev =NULL ;Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 5/9] block: introduce holder ops
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Add a new
blk_holder_opsstructure, which is passed to blkdev_get_by_* and installed in theblock_devicefor exclusive claims. It will be used to allow the block layer to call back into the user of the block device for thing like notification of a removed device or a device resize.Signed-off-by Christoph Hellwig <[email protected]>---
...
Quoted 11 lines
block/bdev.c +2
-1@@ -542,7 +543,8 @@ static void bd_clear_claiming(struct block_device *whole, void *holder)* Finish exclusive open of a block device. Mark the device as exlusively * open by the holder and wake up all waiters for exclusive open to finish. */ -static void bd_finish_claiming (struct block_device *bdev,void *holder) +static void bd_finish_claiming (struct block_device *bdev,void *holder, +const struct blk_holder_ops *hops) {struct block_device *whole =bdev_whole (bdev);
block/bdev.c static void bd_finish_claiming(struct block_device *bdev, void *holder) · line 566
Quoted 10 lines
block/bdev.c +3
-0@@ -555,7 +557,10 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) whole->bd_holders++; whole->bd_holder = bd_may_claim; bdev->bd_holders++; +mutex_lock (&bdev->bd_holder_lock); bdev->bd_holder = holder; + bdev->bd_holder_ops = hops; +mutex_unlock (&bdev->bd_holder_lock);bd_clear_claiming (whole, holder);mutex_unlock (&bdev_lock); }
I guess the holder ops may be override in case of multiple claim, can this be one problem from the holder ops user viewpoint? Or warn_on_once(bdev->bd_holder_ops && bdev->bd_holder_ops != hops) is needed here?
Thanks,
Ming
Re: [PATCH 5/9] block: introduce holder ops
Quoted 21 lines · Ming Lei
Quoted 7 lines · Christoph Hellwig
Add a new
blk_holder_opsstructure, which is passed to blkdev_get_by_* and installed in theblock_devicefor exclusive claims. It will be used to allow the block layer to call back into the user of the block device for thing like notification of a removed device or a device resize.Signed-off-by Christoph Hellwig <[email protected]>---
...
Quoted 10 lines
block/bdev.c +2
-1@@ -542,7 +543,8 @@ static void bd_clear_claiming(struct block_device *whole, void *holder)* Finish exclusive open of a block device. Mark the device as exlusively * open by the holder and wake up all waiters for exclusive open to finish. */ -static void bd_finish_claiming (struct block_device *bdev,void *holder) +static void bd_finish_claiming (struct block_device *bdev,void *holder, +const struct blk_holder_ops *hops) {struct block_device *whole =bdev_whole (bdev);
Quoted 15 lines
block/bdev.c static void bd_finish_claiming(struct block_device *bdev, void *holder) · line 566
Quoted 11 lines
block/bdev.c +3
-0@@ -555,7 +557,10 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) whole->bd_holders++; whole->bd_holder = bd_may_claim; bdev->bd_holders++; +mutex_lock (&bdev->bd_holder_lock); bdev->bd_holder = holder; + bdev->bd_holder_ops = hops; +mutex_unlock (&bdev->bd_holder_lock);bd_clear_claiming (whole, holder);mutex_unlock (&bdev_lock); }I guess the holder ops may be override in case of multiple claim, can this be one problem from the holder ops user viewpoint? Or
warn_on_once(bdev->bd_holder_ops && bdev->bd_holder_ops != hops)is needed here?
<shrug> I'd have thought bd_may_claim would suffice for detecting multiple claims based on its "bd_holder != NULL" test?
Though I suppose an explicit test for bd_holder_ops != NULL would prevent multiple claims if all the claims had NULL holders.
--D
Quoted 4 lines
Thanks,
Ming
Christoph Hellwig
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 12 lines · Darrick J. Wong
Quoted 11 lines
block/bdev.c static void bd_finish_claiming(struct block_device *bdev, void *holder) · line 566
Quoted 7 lines
block/bdev.c +3
-0+mutex_lock (&bdev->bd_holder_lock); bdev->bd_holder = holder; + bdev->bd_holder_ops = hops; +mutex_unlock (&bdev->bd_holder_lock);bd_clear_claiming (whole, holder);mutex_unlock (&bdev_lock); }I guess the holder ops may be override in case of multiple claim, can this be one problem from the holder ops user viewpoint? Or
warn_on_once(bdev->bd_holder_ops && bdev->bd_holder_ops != hops)is needed here?
Quoted 5 lines
<shrug> I'd have thought
bd_may_claimwould suffice for detecting multiple claims based on its "bd_holder!= NULL" test?Though I suppose an explicit test for
bd_holder_ops!= NULL would prevent multiple claims if all the claims had NULL holders.
bd_may_claim allows re-claims as long as the same holder is set. I think we'll want to add an extra check that the holder_ops don't change for this case. They aren't with the current holders, but this is a place where a belt and suspenders might be a good idea..
Quoted 7 lines
--D
Quoted 4 lines
Thanks,
Ming
---end quoted text---
Re: [PATCH 5/9] block: introduce holder ops
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Add a new
blk_holder_opsstructure, which is passed to blkdev_get_by_* and installed in theblock_devicefor exclusive claims. It will be used to allow the block layer to call back into the user of the block device for thing like notification of a removed device or a device resize.Signed-off-by Christoph Hellwig <[email protected]>---
Looks good to me,
Looking at this code reminds me that we'll need a block dev lookup function that takes a diskseq argument so we can lookup a block device and check it against the diskseq number we provided so we can detect "media" changes (images on a loop device etc). Idea being to pass diskseq numbers via fsconfig().
Christoph Hellwig
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 5 lines · Christian Brauner
Looking at this code reminds me that we'll need a block dev lookup function that takes a diskseq argument so we can lookup a block device and check it against the diskseq number we provided so we can detect "media" changes (images on a loop device etc). Idea being to pass diskseq numbers via
fsconfig().
You can already do this by checking right after opening but before using it. In theory we could pass the seq down, and handle it further down, but I'm not sure this really solves anything.
The main work here really is in the mount code.
Christian Brauner
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Christian Brauner
Looking at this code reminds me that we'll need a block dev lookup function that takes a diskseq argument so we can lookup a block device and check it against the diskseq number we provided so we can detect "media" changes (images on a loop device etc). Idea being to pass diskseq numbers via
fsconfig().You can already do this by checking right after opening but before using it. In theory we could pass the seq down, and handle it further down, but I'm not sure this really solves anything.
BTW, why is there no code to lookup a bdev by O_PATH fd? It seems weird that a lot of ioctls pass the device path to the kernel (btrfs comes to mind). I can see certain things that would make this potentially a bit tricky e.g., you'd not have access to the path/name of the device if you want to show it somewhere such as in mountinfo but nothing that makes it impossible afaict.
Quoted 2 lines
The main work here really is in the mount code.
Yeah, I'll get to this soon. Josef has mentioned that he'll convert btrfs to the new mount api this cycle and we have that recorded on video. And I think that otherwise all block device based filesystems might have already been converted.
Christoph Hellwig
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 6 lines · Christian Brauner
BTW, why is there no code to lookup a bdev by
O_PATHfd? It seems weird that a lot of ioctls pass the device path to the kernel (btrfs comes to mind). I can see certain things that would make this potentially a bit tricky e.g., you'd not have access to the path/name of the device if you want to show it somewhere such as in mountinfo but nothing that makes it impossible afaict.
As far as I can tell you should be able to hold a reference to a block
device file descriptor with an O_PATH fd. Or did I miss something
that specifically prohibits that?
Quoted 4 lines
Yeah, I'll get to this soon. Josef has mentioned that he'll convert btrfs to the new mount api this cycle and we have that recorded on video. And I think that otherwise all block device based filesystems might have already been converted.
Btrfs is the last "big" file system, but there plenty more. A quick grep for mount_bdev fills more than a page on my terminal..
Christian Brauner
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Christian Brauner
BTW, why is there no code to lookup a bdev by
O_PATHfd? It seems weird that a lot of ioctls pass the device path to the kernel (btrfs comes to mind). I can see certain things that would make this potentially a bit tricky e.g., you'd not have access to the path/name of the device if you want to show it somewhere such as in mountinfo but nothing that makes it impossible afaict.As far as I can tell you should be able to hold a reference to a block
device file descriptor with anO_PATHfd. Or did I miss something
that specifically prohibits that?
So with an O_PATH fd the device wouldn't really be opened at all we'd just hold a reference to a struct file with f->f_op set to empty_fops. (See the FMODE_PATH code in fs/open.c:do_dentry_open().)
So blkdev_open() is never called for O_PATH fds. Consequently an O_PATH fd to a block device would only be useful if the intention is to later lookup the block device based on inode->i_rdev.
So my earlier question should have been why there's no method to lookup a block device purely by non-O_PATH fd since that way you do actually pin the block device which is probably what you almost always want to do.
I'm asking because it would be nice if we could allow callers to specify the source of a filesystem mount as an fd and not just as a string as the mount api currently does. That's probably not super straightforward but might be really worth it.
Christoph Hellwig
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 7 lines · Christian Brauner
So with an
O_PATHfd the device wouldn't really be opened at all we'd just hold a reference to a struct file withf->f_opset toempty_fops. (See theFMODE_PATHcode in fs/open.c:do_dentry_open().)So
blkdev_open()is never called forO_PATHfds. Consequently anO_PATHfd to a block device would only be useful if the intention is to later lookup the block device based oninode->i_rdev.
Yes. That's pretty much the definition of O_PATH..
Quoted 3 lines
So my earlier question should have been why there's no method to lookup a block device purely by non-O_PATH fd since that way you do actually pin the block device which is probably what you almost always want to do.
Why would we want to pin it? That just means the device is open and you're have a non-O_PATH mount.
Quoted 4 lines
I'm asking because it would be nice if we could allow callers to specify the source of a filesystem mount as an fd and not just as a string as the mount api currently does. That's probably not super straightforward but might be really worth it.
What you seem to want is a way to convert an O_PATH fs into a non-O_PATH one. Which seems generally useful, but isn't really anything block device specific.
Christian Brauner
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Christian Brauner
So with an
O_PATHfd the device wouldn't really be opened at all we'd just hold a reference to a struct file withf->f_opset toempty_fops. (See theFMODE_PATHcode in fs/open.c:do_dentry_open().)So
blkdev_open()is never called forO_PATHfds. Consequently anO_PATHfd to a block device would only be useful if the intention is to later lookup the block device based oninode->i_rdev.
Quoted 8 lines
Yes. That's pretty much the definition of
O_PATH..Quoted 3 lines
So my earlier question should have been why there's no method to lookup a block device purely by non-O_PATH fd since that way you do actually pin the block device which is probably what you almost always want to do.
Why would we want to pin it? That just means the device is open and you're have a non-O_PATH mount.
I think we're talking past each other. Both an O_PATH fd and a regular fd would work. But its often desirable to pass a regular fd. If userspace uses an O_PATH fd then the block device could be looked up later during mounting via blkdev_open().
But when you use a regular fd blkdev_open() will be called and the device resolved right at open time and we'll hold a reference to it.
So that way userspace can immediately know whether the device can be opened/found. That's usually preferable. That's all I meant to say.
Quoted 9 lines
Quoted 5 lines
I'm asking because it would be nice if we could allow callers to specify the source of a filesystem mount as an fd and not just as a string as the mount api currently does. That's probably not super straightforward but might be really worth it.
What you seem to want is a way to convert an
O_PATHfs into a non-O_PATH one. Which seems generally useful, but isn't really anything block device specific.
That already exists, indirectly. You can reopen an O_PATH fd via /proc/$pid/$nr. And Aleksa is working on O_EMPTYPATH to make this a first class API including restrictions for how an O_PATH fd can be reopened. We discussed that during LSFMM.
Christoph Hellwig
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 8 lines · Christian Brauner
Quoted 2 lines
Why would we want to pin it? That just means the device is open and you're have a non-O_PATH mount.
I think we're talking past each other. Both an
O_PATHfd and a regular fd would work. But its often desirable to pass a regular fd. If userspace uses anO_PATHfd then the block device could be looked up later during mounting viablkdev_open().
Quoted 5 lines
But when you use a regular fd
blkdev_open()will be called and the device resolved right at open time and we'll hold a reference to it.So that way userspace can immediately know whether the device can be opened/found. That's usually preferable. That's all I meant to say.
I know what you mean. But based on the concept of how O_PATH and block devices work it really doesn't make any sense to have a block device handle for an O_PATH fd, except for the actual fd itself.
Christian Brauner
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Christian Brauner
Quoted 2 lines
Why would we want to pin it? That just means the device is open and you're have a non-O_PATH mount.
I think we're talking past each other. Both an
O_PATHfd and a regular fd would work. But its often desirable to pass a regular fd. If userspace uses anO_PATHfd then the block device could be looked up later during mounting viablkdev_open().But when you use a regular fd
blkdev_open()will be called and the device resolved right at open time and we'll hold a reference to it.
Quoted 6 lines
Quoted 2 lines
So that way userspace can immediately know whether the device can be opened/found. That's usually preferable. That's all I meant to say.
I know what you mean. But based on the concept of how
O_PATHand block devices work it really doesn't make any sense to have a block device handle for anO_PATHfd, except for the actual fd itself.
Fwiw, I didn't mean to have a special device handler for an O_PATH fd. I really just tried to figure out whether it would make sense to have an fd-based block device lookup function because right now we only have blkdev_get_by_path() and we'd be passing blkdev fds through the mount api. But I understand now how I'd likely do it. So now just finding time to actually implement it.
Christoph Hellwig
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 6 lines · Christian Brauner
Fwiw, I didn't mean to have a special device handler for an
O_PATHfd. I really just tried to figure out whether it would make sense to have an fd-based block device lookup function because right now we only haveblkdev_get_by_path()and we'd be passing blkdev fds through the mount api. But I understand now how I'd likely do it. So now just finding time to actually implement it.
What's wrong with blkdev_get_by_dev(file_inode(file)->i_rdev) after the sanity checks from lookup_bdev (S_ISBLK and may_open_dev)?
Christoph Hellwig
maintainerRe: [PATCH 5/9] block: introduce holder ops
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Christian Brauner
Fwiw, I didn't mean to have a special device handler for an
O_PATHfd. I really just tried to figure out whether it would make sense to have an fd-based block device lookup function because right now we only haveblkdev_get_by_path()and we'd be passing blkdev fds through the mount api. But I understand now how I'd likely do it. So now just finding time to actually implement it.What's wrong with blkdev_get_by_dev(file_inode(file)->i_rdev) after the sanity checks from
lookup_bdev(S_ISBLKandmay_open_dev)?
s/i_rdev/i_dev/
Christian Brauner
maintainerRe: [PATCH 5/9] block: introduce holder ops
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
Quoted 6 lines · Christian Brauner
Fwiw, I didn't mean to have a special device handler for an
O_PATHfd. I really just tried to figure out whether it would make sense to have an fd-based block device lookup function because right now we only haveblkdev_get_by_path()and we'd be passing blkdev fds through the mount api. But I understand now how I'd likely do it. So now just finding time to actually implement it.What's wrong with blkdev_get_by_dev(file_inode(file)->i_rdev) after the sanity checks from
lookup_bdev(S_ISBLKandmay_open_dev)?
Yeah, that's what I realized could work fine. I just need to check all fses how they currently do this and how to do this cleanly.
Christoph Hellwig
maintainerPATCH 6/9 block: add a mark_dead holder operation
In reply to Christoph HellwigAdd a mark_dead method to blk_holder_ops that is called from blk_mark_disk_dead to notify the holder that the block device it is using has been marked dead.
--- block/genhd.c | 24 ++++++++++++++++++++++++ include/linux/blkdev.h | 1 + 2 files changed, 25 insertions(+)
block/genhd.c +24 -0
@@ -575,6 +575,28 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, }EXPORT_SYMBOL (device_add_disk); +static void blk_report_disk_dead (struct gendisk *disk) +{ +struct block_device *bdev; +unsigned long idx; + +rcu_read_lock (); +xa_for_each (&disk->part_tbl, idx, bdev) { +if (!kobject_get_unless_zero (&bdev->bd_device.kobj)) +continue ; +rcu_read_unlock (); + +mutex_lock (&bdev->bd_holder_lock); +if (bdev->bd_holder_ops && bdev->bd_holder_ops->mark_dead) + bdev->bd_holder_ops->mark_dead (bdev); +mutex_unlock (&bdev->bd_holder_lock); + +put_device (&bdev->bd_device); +rcu_read_lock (); + } +rcu_read_unlock (); +} +/** * blk_mark_disk_dead - mark a disk as dead * @disk: disk to mark as dead
@@ -602,6 +624,8 @@ void blk_mark_disk_dead(struct gendisk *disk)* Prevent new I/O from crossing bio_queue_enter(). */ blk_queue_start_drain (disk->queue); + +blk_report_disk_dead (disk); }EXPORT_SYMBOL_GPL (blk_mark_disk_dead);
include/linux/blkdev.h +1 -0
@@ -1469,6 +1469,7 @@ void blkdev_show(struct seq_file *seqf, off_t offset);#endif struct blk_holder_ops { +void (*mark_dead)(struct block_device *bdev); }; struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder,
Signature · 1 line
2.39.2
Re: [PATCH 6/9] block: add a mark_dead holder operation
Quoted 56 lines · Christoph Hellwig
Add a
mark_deadmethod toblk_holder_opsthat is called fromblk_mark_disk_deadto notify the holder that the block device it is using has been marked dead.Signed-off-by Christoph Hellwig <[email protected]>--- block/genhd.c | 24 ++++++++++++++++++++++++ include/linux/blkdev.h | 1 + 2 files changed, 25 insertions(+)block/genhd.c +24
-0@@ -575,6 +575,28 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, }EXPORT_SYMBOL (device_add_disk); +static void blk_report_disk_dead (struct gendisk *disk) +{ +struct block_device *bdev; +unsigned long idx; + +rcu_read_lock (); +xa_for_each (&disk->part_tbl, idx, bdev) { +if (!kobject_get_unless_zero (&bdev->bd_device.kobj)) +continue ; +rcu_read_unlock (); + +mutex_lock (&bdev->bd_holder_lock); +if (bdev->bd_holder_ops && bdev->bd_holder_ops->mark_dead) + bdev->bd_holder_ops->mark_dead (bdev); +mutex_unlock (&bdev->bd_holder_lock); + +put_device (&bdev->bd_device); +rcu_read_lock (); + } +rcu_read_unlock (); +} +/** * blk_mark_disk_dead - mark a disk as dead * @disk: disk to mark as dead @@ -602,6 +624,8 @@ void blk_mark_disk_dead(struct gendisk *disk)* Prevent new I/O from crossing bio_queue_enter(). */ blk_queue_start_drain (disk->queue); + +blk_report_disk_dead (disk); }EXPORT_SYMBOL_GPL (blk_mark_disk_dead);include/linux/blkdev.h +0
-0
include/linux/blkdev.h void blkdev_show(struct seq_file *seqf, off_t offset); · line 1472
Quoted 4 lines
include/linux/blkdev.h +1
-0@@ -1469,6 +1469,7 @@ void blkdev_show(struct seq_file *seqf, off_t offset);#endif struct blk_holder_ops { +void (*mark_dead)(struct block_device *bdev);
Now that we have blockdev callbacks, can we add a pair for freeze_bdev and thaw_bdev so that LVM snapshotting an xfs log device can actually quiesce the filesystem?
This patch itself looks ok,
--D
Quoted 6 lines
include/linux/blkdev.h +0
-0}; struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder,Signature · 1 line
2.39.2
Christoph Hellwig
maintainerRe: [PATCH 6/9] block: add a mark_dead holder operation
Quoted 3 lines · Darrick J. Wong
Now that we have blockdev callbacks, can we add a pair for
freeze_bdevandthaw_bdevso that LVM snapshotting an xfs log device can actually quiesce the filesystem?
Probably. Assuming we're not creating any really weird locking dependency that way.
Jan Kara
reviewerRe: [PATCH 6/9] block: add a mark_dead holder operation
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Add a
mark_deadmethod toblk_holder_opsthat is called fromblk_mark_disk_deadto notify the holder that the block device it is using has been marked dead.Signed-off-by Christoph Hellwig <[email protected]>
One question below:
Quoted 39 lines
--- block/genhd.c | 24 ++++++++++++++++++++++++ include/linux/blkdev.h | 1 + 2 files changed, 25 insertions(+)block/genhd.c +22
-0@@ -575,6 +575,28 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, }EXPORT_SYMBOL (device_add_disk); +static void blk_report_disk_dead (struct gendisk *disk) +{ +struct block_device *bdev; +unsigned long idx; + +rcu_read_lock (); +xa_for_each (&disk->part_tbl, idx, bdev) { +if (!kobject_get_unless_zero (&bdev->bd_device.kobj)) +continue ; +rcu_read_unlock (); + +mutex_lock (&bdev->bd_holder_lock); +if (bdev->bd_holder_ops && bdev->bd_holder_ops->mark_dead) + bdev->bd_holder_ops->mark_dead (bdev); +mutex_unlock (&bdev->bd_holder_lock); + +put_device (&bdev->bd_device); +rcu_read_lock (); + } +rcu_read_unlock (); +} +/** * blk_mark_disk_dead - mark a disk as dead * @disk: disk to mark as dead
block/genhd.c void blk_mark_disk_dead(struct gendisk *disk) · line 628
Quoted 5 lines
block/genhd.c +2
-0@@ -602,6 +624,8 @@ void blk_mark_disk_dead(struct gendisk *disk)* Prevent new I/O from crossing bio_queue_enter(). */ blk_queue_start_drain (disk->queue); + +blk_report_disk_dead (disk);
Hum, but this gets called from del_gendisk() after blk_drop_partitions() happens. So how is this going to be able to iterate anything?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christoph Hellwig
maintainerRe: [PATCH 6/9] block: add a mark_dead holder operation
Quoted 9 lines · Jan Kara
block/genhd.c void blk_mark_disk_dead(struct gendisk *disk) · line 628
Quoted 6 lines
block/genhd.c +2
-0@@ -602,6 +624,8 @@ void blk_mark_disk_dead(struct gendisk *disk)* Prevent new I/O from crossing bio_queue_enter(). */ blk_queue_start_drain (disk->queue); + +blk_report_disk_dead (disk);Hum, but this gets called from
del_gendisk()afterblk_drop_partitions()happens. So how is this going to be able to iterate anything?
It isn't, and doesn't work for partitions right now. I guess del_gendisk needs a bit of refacoring that we do two pases over the inode and/or move the ->mark_deal call for partitions into blk_drop_partitions.
Re: [PATCH 6/9] block: add a mark_dead holder operation
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Jan Kara
block/genhd.c void blk_mark_disk_dead(struct gendisk *disk) · line 628
Quoted 6 lines
block/genhd.c +2
-0@@ -602,6 +624,8 @@ void blk_mark_disk_dead(struct gendisk *disk)* Prevent new I/O from crossing bio_queue_enter(). */ blk_queue_start_drain (disk->queue); + +blk_report_disk_dead (disk);Hum, but this gets called from
del_gendisk()afterblk_drop_partitions()happens. So how is this going to be able to iterate anything?
Quoted 3 lines
It isn't, and doesn't work for partitions right now. I guess
del_gendiskneeds a bit of refacoring that we do two pases over the inode and/or move the ->mark_deal call for partitions intoblk_drop_partitions.
Might be worth a comment. Otherwise looks good to me,
Christoph Hellwig
maintainerPATCH 7/9 fs: add a method to shut down the file system
In reply to Christoph HellwigAdd a new ->shutdown super operation that can be used to tell the file system to shut down, and call it from newly created holder ops when the block device under a file system shuts down.
This only covers the main block device for "simple" file systems using get_tree_bdev / mount_bdev. File systems their own get_tree method or opening additional devices will need to set up their own blk_holder_ops.
--- fs/super.c | 21 +++++++++++++++++++-- include/linux/fs.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-)
fs/super.c +19 -2
@@ -1206,6 +1206,22 @@ int get_tree_keyed(struct fs_context *fc,EXPORT_SYMBOL (get_tree_keyed);#ifdef CONFIG_BLOCK +static void fs_mark_dead (struct block_device *bdev) +{ +struct super_block *sb; + + sb =get_super (bdev); +if (!sb) +return ; + +if (sb->s_op->shutdown) + sb->s_op->shutdown (sb); +drop_super (sb); +} + +static const struct blk_holder_ops fs_holder_ops = { + .mark_dead = fs_mark_dead, +};static int set_bdev_super (struct super_block *s,void *data) {
@@ -1248,7 +1264,8 @@ int get_tree_bdev(struct fs_context *fc,if (!fc->source)return invalf (fc,"No source specified" ); - bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type,NULL ); + bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type, + &fs_holder_ops);if (IS_ERR (bdev)) {errorf (fc,"%s: Can't open blockdev" , fc->source);return PTR_ERR (bdev);
@@ -1333,7 +1350,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,if (!(flags &SB_RDONLY )) mode |=FMODE_WRITE ; - bdev =blkdev_get_by_path (dev_name, mode, fs_type,NULL ); + bdev =blkdev_get_by_path (dev_name, mode, fs_type, &fs_holder_ops);if (IS_ERR (bdev))return ERR_CAST (bdev);
include/linux/fs.h +1 -0
@@ -1932,6 +1932,7 @@ struct super_operations { struct shrink_control *);long (*free_cached_objects)(struct super_block *,struct shrink_control *); +void (*shutdown)(struct super_block *sb); };/*
Signature · 1 line
2.39.2
Re: [PATCH 7/9] fs: add a method to shut down the file system
Quoted 10 lines · Christoph Hellwig
Add a new ->shutdown super operation that can be used to tell the file system to shut down, and call it from newly created holder ops when the block device under a file system shuts down.
This only covers the main block device for "simple" file systems using
get_tree_bdev/mount_bdev. File systems their ownget_treemethod or opening additional devices will need to set up their ownblk_holder_ops.Signed-off-by Christoph Hellwig <[email protected]>
Looks good,
--D
include/linux/fs.h struct super_operations {
Quoted 56 lines
--- fs/super.c | 21 +++++++++++++++++++-- include/linux/fs.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-)fs/super.c +19
-2@@ -1206,6 +1206,22 @@ int get_tree_keyed(struct fs_context *fc,EXPORT_SYMBOL (get_tree_keyed);#ifdef CONFIG_BLOCK +static void fs_mark_dead (struct block_device *bdev) +{ +struct super_block *sb; + + sb =get_super (bdev); +if (!sb) +return ; + +if (sb->s_op->shutdown) + sb->s_op->shutdown (sb); +drop_super (sb); +} + +static const struct blk_holder_ops fs_holder_ops = { + .mark_dead = fs_mark_dead, +};static int set_bdev_super (struct super_block *s,void *data) {@@ -1248,7 +1264,8 @@ int get_tree_bdev(struct fs_context *fc,if (!fc->source)return invalf (fc,"No source specified" ); - bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type,NULL ); + bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type, + &fs_holder_ops);if (IS_ERR (bdev)) {errorf (fc,"%s: Can't open blockdev" , fc->source);return PTR_ERR (bdev);@@ -1333,7 +1350,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,if (!(flags &SB_RDONLY )) mode |=FMODE_WRITE ; - bdev =blkdev_get_by_path (dev_name, mode, fs_type,NULL ); + bdev =blkdev_get_by_path (dev_name, mode, fs_type, &fs_holder_ops);if (IS_ERR (bdev))return ERR_CAST (bdev);include/linux/fs.h +0
-0@@ -1932,6 +1932,7 @@ struct super_operations {
struct shrink_control *);
Quoted 9 lines
include/linux/fs.h +1
-0long (*free_cached_objects)(struct super_block *,struct shrink_control *); +void (*shutdown)(struct super_block *sb); };/* Signature · 1 line
2.39.2
Re: [PATCH 7/9] fs: add a method to shut down the file system
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
Add a new ->shutdown super operation that can be used to tell the file system to shut down, and call it from newly created holder ops when the block device under a file system shuts down.
This only covers the main block device for "simple" file systems using
get_tree_bdev/mount_bdev. File systems their ownget_treemethod or opening additional devices will need to set up their ownblk_holder_ops.Signed-off-by Christoph Hellwig <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 66 lines
--- fs/super.c | 21 +++++++++++++++++++-- include/linux/fs.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-)fs/super.c +19
-2@@ -1206,6 +1206,22 @@ int get_tree_keyed(struct fs_context *fc,EXPORT_SYMBOL (get_tree_keyed);#ifdef CONFIG_BLOCK +static void fs_mark_dead (struct block_device *bdev) +{ +struct super_block *sb; + + sb =get_super (bdev); +if (!sb) +return ; + +if (sb->s_op->shutdown) + sb->s_op->shutdown (sb); +drop_super (sb); +} + +static const struct blk_holder_ops fs_holder_ops = { + .mark_dead = fs_mark_dead, +};static int set_bdev_super (struct super_block *s,void *data) {@@ -1248,7 +1264,8 @@ int get_tree_bdev(struct fs_context *fc,if (!fc->source)return invalf (fc,"No source specified" ); - bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type,NULL ); + bdev =blkdev_get_by_path (fc->source, mode, fc->fs_type, + &fs_holder_ops);if (IS_ERR (bdev)) {errorf (fc,"%s: Can't open blockdev" , fc->source);return PTR_ERR (bdev);@@ -1333,7 +1350,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,if (!(flags &SB_RDONLY )) mode |=FMODE_WRITE ; - bdev =blkdev_get_by_path (dev_name, mode, fs_type,NULL ); + bdev =blkdev_get_by_path (dev_name, mode, fs_type, &fs_holder_ops);if (IS_ERR (bdev))return ERR_CAST (bdev);include/linux/fs.h +1
-0@@ -1932,6 +1932,7 @@ struct super_operations { struct shrink_control *);long (*free_cached_objects)(struct super_block *,struct shrink_control *); +void (*shutdown)(struct super_block *sb); };/* Signature · 1 line
2.39.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 7/9] fs: add a method to shut down the file system
In reply to Christoph HellwigQuoted 11 lines · Christoph Hellwig
Add a new ->shutdown super operation that can be used to tell the file system to shut down, and call it from newly created holder ops when the block device under a file system shuts down.
This only covers the main block device for "simple" file systems using
get_tree_bdev/mount_bdev. File systems their ownget_treemethod or opening additional devices will need to set up their ownblk_holder_ops.Signed-off-by Christoph Hellwig <[email protected]>---
Do you want the fs infra and block infra merged together or separately? Looks good to me,
Christoph Hellwig
maintainerRe: [PATCH 7/9] fs: add a method to shut down the file system
Quoted 1 line · Christian Brauner
Do you want the fs infra and block infra merged together or separately?
Yes, splitting this up doesn't really make a lot of sense.
Christoph Hellwig
maintainerPATCH 8/9 xfs: wire up sops->shutdown
In reply to Christoph HellwigWire up the shutdown method to shut down the file system when the underlying block device is marked dead. Add a new message to clearly distinguish this shutdown reason from other shutdowns.
--- fs/xfs/xfs_fsops.c | 3 +++ fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_super.c | 8 ++++++++ 3 files changed, 12 insertions(+)
fs/xfs/xfs_fsops.c +3 -0
@@ -534,6 +534,9 @@ xfs_do_force_shutdown( }else if (flags &SHUTDOWN_CORRUPT_ONDISK ) { tag =XFS_PTAG_SHUTDOWN_CORRUPT ; why ="Corruption of on-disk metadata" ; + }else if (flags &SHUTDOWN_DEVICE_REMOVED ) { + tag =XFS_PTAG_SHUTDOWN_IOERROR ; + why ="Block device removal" ; }else { tag =XFS_PTAG_SHUTDOWN_IOERROR ; why ="Metadata I/O Error" ;
fs/xfs/xfs_mount.h +1 -0
@@ -454,6 +454,7 @@ void xfs_do_force_shutdown(struct xfs_mount *mp, uint32_t flags, char *fname,#define SHUTDOWN_FORCE_UMOUNT (1u << 2)/* shutdown from a forced unmount */ #define SHUTDOWN_CORRUPT_INCORE (1u << 3)/* corrupt in-memory structures */ #define SHUTDOWN_CORRUPT_ONDISK (1u << 4)/* corrupt metadata on device */ +#define SHUTDOWN_DEVICE_REMOVED (1u << 5)/* device removed underneath us */ #define XFS_SHUTDOWN_STRINGS \ { SHUTDOWN_META_IO_ERROR, "metadata_io" }, \
fs/xfs/xfs_super.c +8 -0
@@ -1156,6 +1156,13 @@ xfs_fs_free_cached_objects(return xfs_reclaim_inodes_nr (XFS_M (sb), sc->nr_to_scan); } +static void +xfs_fs_shutdown ( +struct super_block *sb) +{ +xfs_force_shutdown (XFS_M (sb),SHUTDOWN_DEVICE_REMOVED ); +} +static const struct super_operations xfs_super_operations = { .alloc_inode = xfs_fs_alloc_inode, .destroy_inode = xfs_fs_destroy_inode,
@@ -1169,6 +1176,7 @@ static const struct super_operations xfs_super_operations = { .show_options = xfs_fs_show_options, .nr_cached_objects = xfs_fs_nr_cached_objects, .free_cached_objects = xfs_fs_free_cached_objects, + .shutdown = xfs_fs_shutdown, }; static int
Signature · 1 line
2.39.2
Re: [PATCH 8/9] xfs: wire up sops->shutdown
Quoted 30 lines · Christoph Hellwig
Wire up the shutdown method to shut down the file system when the underlying block device is marked dead. Add a new message to clearly distinguish this shutdown reason from other shutdowns.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_fsops.c | 3 +++ fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_super.c | 8 ++++++++ 3 files changed, 12 insertions(+)fs/xfs/xfs_fsops.c +3
-0@@ -534,6 +534,9 @@ xfs_do_force_shutdown( }else if (flags &SHUTDOWN_CORRUPT_ONDISK ) { tag =XFS_PTAG_SHUTDOWN_CORRUPT ; why ="Corruption of on-disk metadata" ; + }else if (flags &SHUTDOWN_DEVICE_REMOVED ) { + tag =XFS_PTAG_SHUTDOWN_IOERROR ; + why ="Block device removal" ; }else { tag =XFS_PTAG_SHUTDOWN_IOERROR ; why ="Metadata I/O Error" ;fs/xfs/xfs_mount.h +0
-0
fs/xfs/xfs_mount.h void xfs_do_force_shutdown(struct xfs_mount *mp, uint32_t flags, char *fname, · line 459
Quoted 6 lines
fs/xfs/xfs_mount.h +1
-0@@ -454,6 +454,7 @@ void xfs_do_force_shutdown(struct xfs_mount *mp, uint32_t flags, char *fname,#define SHUTDOWN_FORCE_UMOUNT (1u << 2)/* shutdown from a forced unmount */ #define SHUTDOWN_CORRUPT_INCORE (1u << 3)/* corrupt in-memory structures */ #define SHUTDOWN_CORRUPT_ONDISK (1u << 4)/* corrupt metadata on device */ +#define SHUTDOWN_DEVICE_REMOVED (1u << 5)/* device removed underneath us */ #define XFS_SHUTDOWN_STRINGS \
Could you add SHUTDOWN_DEVICE_REMOVED to XFS_SHUTDOWN_STRINGS so the tracepoint data will decode that flag?
(Everything else in here looks fine to me)
--D
Quoted 30 lines
fs/xfs/xfs_mount.h +0
-0{ SHUTDOWN_META_IO_ERROR, "metadata_io" }, \fs/xfs/xfs_super.c +8
-0@@ -1156,6 +1156,13 @@ xfs_fs_free_cached_objects(return xfs_reclaim_inodes_nr (XFS_M (sb), sc->nr_to_scan); } +static void +xfs_fs_shutdown ( +struct super_block *sb) +{ +xfs_force_shutdown (XFS_M (sb),SHUTDOWN_DEVICE_REMOVED ); +} +static const struct super_operations xfs_super_operations = { .alloc_inode = xfs_fs_alloc_inode, .destroy_inode = xfs_fs_destroy_inode,@@ -1169,6 +1176,7 @@ static const struct super_operations xfs_super_operations = { .show_options = xfs_fs_show_options, .nr_cached_objects = xfs_fs_nr_cached_objects, .free_cached_objects = xfs_fs_free_cached_objects, + .shutdown = xfs_fs_shutdown, }; static intSignature · 1 line
2.39.2
Christoph Hellwig
maintainerRe: [PATCH 8/9] xfs: wire up sops->shutdown
Quoted 2 lines · Darrick J. Wong
Could you add
SHUTDOWN_DEVICE_REMOVEDtoXFS_SHUTDOWN_STRINGSso the tracepoint data will decode that flag?
Sure.
Christoph Hellwig
maintainerPATCH 9/9 xfs: wire up the ->mark_dead holder operation for log and RT devices
In reply to Christoph HellwigImplement a set of holder_ops that shut down the file system when the block device used as log or RT device is removed undeneath the file system.
--- fs/xfs/xfs_super.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
fs/xfs/xfs_super.c +12 -1
@@ -377,6 +377,17 @@ xfs_setup_dax_always(return 0 ; } +static void +xfs_hop_mark_dead ( +struct block_device *bdev) +{ +xfs_force_shutdown (bdev->bd_holder,SHUTDOWN_DEVICE_REMOVED ); +} + +static const struct blk_holder_ops xfs_holder_ops = { + .mark_dead = xfs_hop_mark_dead, +}; + STATIC int xfs_blkdev_get( xfs_mount_t *mp,
@@ -386,7 +397,7 @@ xfs_blkdev_get(int error =0 ; *bdevp =blkdev_get_by_path (name,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - mp,NULL ); + mp, &xfs_holder_ops);if (IS_ERR (*bdevp)) { error =PTR_ERR (*bdevp);xfs_warn (mp,"Invalid device [%s], error=%d" , name, error);
Signature · 1 line
2.39.2
Re: [PATCH 9/9] xfs: wire up the ->mark_dead holder operation for log and RT devices
Quoted 14 lines · Christoph Hellwig
Implement a set of
holder_opsthat shut down the file system when the block device used as log or RT device is removed undeneath the file system.Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_super.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)fs/xfs/xfs_super.c +0
-0
fs/xfs/xfs_super.c xfs_setup_dax_always( · line 384
Quoted 8 lines
fs/xfs/xfs_super.c +5
-0@@ -377,6 +377,17 @@ xfs_setup_dax_always(return 0 ; } +static void +xfs_hop_mark_dead ( +struct block_device *bdev) +{ +xfs_force_shutdown (bdev->bd_holder,SHUTDOWN_DEVICE_REMOVED );
/me wonders if this should be xfs_bdev_mark_dead, but eh that's mostly stylistic.
--D
Quoted 21 lines
fs/xfs/xfs_super.c +7
-1+} + +static const struct blk_holder_ops xfs_holder_ops = { + .mark_dead = xfs_hop_mark_dead, +}; + STATIC int xfs_blkdev_get( xfs_mount_t *mp,@@ -386,7 +397,7 @@ xfs_blkdev_get(int error =0 ; *bdevp =blkdev_get_by_path (name,FMODE_READ |FMODE_WRITE |FMODE_EXCL , - mp,NULL ); + mp, &xfs_holder_ops);if (IS_ERR (*bdevp)) { error =PTR_ERR (*bdevp);xfs_warn (mp,"Invalid device [%s], error=%d" , name, error);Signature · 1 line
2.39.2
Christoph Hellwig
maintainerAs I got asked last night what tree this actually applies to, and the answer is "whatever was in Linus' tree three days ago", I have just pushed out the branch here:
git://git.infradead.org/users/hch/block.git blk_holder_ops
Gitweb:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/blk_holder_ops