From: Christoph Hellwig <hch@lst.de>
To: Al Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>, Denis Efremov <efremov@linux.com>,
Josef Bacik <josef@toxicpanda.com>,
Stefan Haberland <sth@linux.ibm.com>,
Jan Hoeppner <hoeppner@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
"Darrick J . Wong" <djwong@kernel.org>, Chris Mason <clm@fb.com>,
David Sterba <dsterba@suse.com>,
linux-block@vger.kernel.org, nbd@other.debian.org,
linux-s390@vger.kernel.org, linux-btrfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 13/17] block: consolidate __invalidate_device and fsync_bdev
Date: Fri, 11 Aug 2023 12:08:24 +0200 [thread overview]
Message-ID: <20230811100828.1897174-14-hch@lst.de> (raw)
In-Reply-To: <20230811100828.1897174-1-hch@lst.de>
We currently have two interfaces that take a block_devices and the find
a mounted file systems to flush or invaldidate data on it. Both are a
bit problematic because they only work for the "main" block devices
that is used as s_dev for the super_block, and because they don't call
into the file system at all.
Merge the two into a new bdev_mark_dead helper that does both the
syncing and invalidation and which is properly documented. This is
in preparation of merging the functionality into the ->mark_dead
holder operation so that it will work on additional block devices
used by a file systems and give us a single entry point for invalidation
of dead devices or media.
Note that a single standalone fsync_bdev call for an obscure ioctl
remains for now, but that one will also be deal with in a bit.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/bdev.c | 33 ++++++++++++++++++++++++++++-----
block/disk-events.c | 4 ++--
block/genhd.c | 3 +--
block/partitions/core.c | 5 +----
drivers/s390/block/dasd.c | 6 ++----
fs/super.c | 4 ++--
include/linux/blkdev.h | 2 +-
7 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index 979e28a46b988e..b9ca947bd5e405 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -221,7 +221,6 @@ int fsync_bdev(struct block_device *bdev)
}
return sync_blockdev(bdev);
}
-EXPORT_SYMBOL(fsync_bdev);
/**
* freeze_bdev - lock a filesystem and force it into a consistent state
@@ -960,12 +959,27 @@ int lookup_bdev(const char *pathname, dev_t *dev)
}
EXPORT_SYMBOL(lookup_bdev);
-int __invalidate_device(struct block_device *bdev, bool kill_dirty)
+/**
+ * bdev_mark_dead - mark a block device as dead
+ * @bdev: block device to operate on
+ * @surprise: indicate a surprise removal
+ *
+ * Tell the file system that this devices or media is dead. If @surprise is set
+ * to %true the device or media is already gone, if not we are preparing for an
+ * orderly removal.
+ *
+ * This syncs out all dirty data and writes back inodes and then invalidates any
+ * cached data in the inodes on the file system, the inodes themselves and the
+ * block device mapping.
+ */
+void bdev_mark_dead(struct block_device *bdev, bool surprise)
{
struct super_block *sb = get_super(bdev);
int res = 0;
if (sb) {
+ if (!surprise)
+ sync_filesystem(sb);
/*
* no need to lock the super, get_super holds the
* read mutex so the filesystem cannot go away
@@ -973,13 +987,22 @@ int __invalidate_device(struct block_device *bdev, bool kill_dirty)
* hold).
*/
shrink_dcache_sb(sb);
- res = invalidate_inodes(sb, kill_dirty);
+ res = invalidate_inodes(sb, true);
drop_super(sb);
+ } else {
+ if (!surprise)
+ sync_blockdev(bdev);
}
invalidate_bdev(bdev);
- return res;
}
-EXPORT_SYMBOL(__invalidate_device);
+#ifdef CONFIG_DASD
+/*
+ * Drivers should not use this directly, but the DASD driver has historically
+ * had a shutdown to offline mode that doesn't actually remove the gendisk
+ * that otherwise looks a lot like a safe device removal.
+ */
+EXPORT_SYMBOL_GPL(bdev_mark_dead);
+#endif
void sync_bdevs(bool wait)
{
diff --git a/block/disk-events.c b/block/disk-events.c
index 6b858d3504772c..422db8292d0997 100644
--- a/block/disk-events.c
+++ b/block/disk-events.c
@@ -281,7 +281,7 @@ bool disk_check_media_change(struct gendisk *disk)
if (!(events & DISK_EVENT_MEDIA_CHANGE))
return false;
- __invalidate_device(disk->part0, true);
+ bdev_mark_dead(disk->part0, true);
set_bit(GD_NEED_PART_SCAN, &disk->state);
return true;
}
@@ -300,7 +300,7 @@ void disk_force_media_change(struct gendisk *disk)
{
disk_event_uevent(disk, DISK_EVENT_MEDIA_CHANGE);
inc_diskseq(disk);
- __invalidate_device(disk->part0, true);
+ bdev_mark_dead(disk->part0, true);
set_bit(GD_NEED_PART_SCAN, &disk->state);
}
EXPORT_SYMBOL_GPL(disk_force_media_change);
diff --git a/block/genhd.c b/block/genhd.c
index 3d287b32d50dfd..afc2cb09eb94b9 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -647,8 +647,7 @@ void del_gendisk(struct gendisk *disk)
mutex_lock(&disk->open_mutex);
xa_for_each(&disk->part_tbl, idx, part) {
remove_inode_hash(part->bd_inode);
- fsync_bdev(part);
- __invalidate_device(part, true);
+ bdev_mark_dead(part, false);
}
mutex_unlock(&disk->open_mutex);
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 13a7341299a913..e137a87f4db0d3 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -281,10 +281,7 @@ static void delete_partition(struct block_device *part)
* looked up any more even when openers still hold references.
*/
remove_inode_hash(part->bd_inode);
-
- fsync_bdev(part);
- __invalidate_device(part, true);
-
+ bdev_mark_dead(part, false);
drop_partition(part);
}
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 675b38ad00dc9e..1f642be840c3ef 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -3626,10 +3626,8 @@ int dasd_generic_set_offline(struct ccw_device *cdev)
* so sync bdev first and then wait for our queues to become
* empty
*/
- if (device->block) {
- fsync_bdev(device->block->bdev);
- __invalidate_device(device->block->bdev, true);
- }
+ if (device->block)
+ bdev_mark_dead(device->block->bdev, false);
dasd_schedule_device_bh(device);
rc = wait_event_interruptible(shutdown_waitq,
_wait_for_empty_queues(device));
diff --git a/fs/super.c b/fs/super.c
index 71fe297a7e90a9..bbce0fdebf7e52 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1359,7 +1359,7 @@ int get_tree_bdev(struct fs_context *fc,
/*
* We drop s_umount here because we need to open the bdev and
* bdev->open_mutex ranks above s_umount (blkdev_put() ->
- * __invalidate_device()). It is safe because we have active sb
+ * bdev_mark_dead()). It is safe because we have active sb
* reference and SB_BORN is not set yet.
*/
up_write(&s->s_umount);
@@ -1411,7 +1411,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
/*
* We drop s_umount here because we need to open the bdev and
* bdev->open_mutex ranks above s_umount (blkdev_put() ->
- * __invalidate_device()). It is safe because we have active sb
+ * bdev_mark_dead()). It is safe because we have active sb
* reference and SB_BORN is not set yet.
*/
up_write(&s->s_umount);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index c8eab6effc2267..6721595b9f9741 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -751,6 +751,7 @@ static inline int bdev_read_only(struct block_device *bdev)
bool set_capacity_and_notify(struct gendisk *disk, sector_t size);
void disk_force_media_change(struct gendisk *disk);
+void bdev_mark_dead(struct block_device *bdev, bool surprise);
void add_disk_randomness(struct gendisk *disk) __latent_entropy;
void rand_initialize_disk(struct gendisk *disk);
@@ -809,7 +810,6 @@ int __register_blkdev(unsigned int major, const char *name,
void unregister_blkdev(unsigned int major, const char *name);
bool disk_check_media_change(struct gendisk *disk);
-int __invalidate_device(struct block_device *bdev, bool kill_dirty);
void set_capacity(struct gendisk *disk, sector_t size);
#ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
--
2.39.2
next prev parent reply other threads:[~2023-08-11 10:10 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 10:08 remove get_super Christoph Hellwig
2023-08-11 10:08 ` [PATCH 01/17] FOLD: reverts part of "fs: use the super_block as holder when mounting file systems" Christoph Hellwig
2023-08-11 10:44 ` Christian Brauner
2023-08-11 10:08 ` [PATCH 02/17] btrfs: always open the device read-only in btrfs_scan_one_device Christoph Hellwig
2023-08-11 12:00 ` Christian Brauner
2023-08-11 10:08 ` [PATCH 03/17] btrfs: call btrfs_close_devices from ->kill_sb Christoph Hellwig
2023-08-11 12:03 ` Christian Brauner
2023-08-11 10:08 ` [PATCH 04/17] btrfs: split btrfs_fs_devices.opened Christoph Hellwig
2023-08-11 12:40 ` Christian Brauner
2023-08-11 10:08 ` [PATCH 05/17] btrfs: open block devices after superblock creation Christoph Hellwig
2023-08-11 12:44 ` Christian Brauner
2023-08-11 13:11 ` David Sterba
2023-08-17 13:24 ` David Sterba
2023-08-11 10:08 ` [PATCH 06/17] btrfs: use the super_block as holder when mounting file systems Christoph Hellwig
2023-08-11 12:45 ` Christian Brauner
2023-08-11 10:08 ` [PATCH 07/17] nbd: call blk_mark_disk_dead in nbd_clear_sock_ioctl Christoph Hellwig
2023-09-20 20:41 ` Samuel Holland
2023-09-25 7:48 ` Christoph Hellwig
2023-10-01 17:10 ` Wouter Verhelst
2023-10-02 6:21 ` Christoph Hellwig
2023-10-02 19:15 ` Samuel Holland
2023-08-11 10:08 ` [PATCH 08/17] block: simplify the disk_force_media_change interface Christoph Hellwig
2023-08-11 10:08 ` [PATCH 09/17] floppy: call disk_force_media_change when changing the format Christoph Hellwig
2023-08-11 10:08 ` [PATCH 10/17] amiflop: don't call fsync_bdev in FDFMTBEG Christoph Hellwig
2023-08-11 10:08 ` [PATCH 11/17] dasd: also call __invalidate_device when setting the device offline Christoph Hellwig
2023-08-11 10:08 ` [PATCH 12/17] block: drop the "busy inodes on changed media" log message Christoph Hellwig
2023-08-11 10:08 ` Christoph Hellwig [this message]
2023-08-12 10:51 ` [PATCH 13/17] block: consolidate __invalidate_device and fsync_bdev Christoph Hellwig
2023-08-12 17:04 ` Heiko Carstens
2023-08-12 17:28 ` Heiko Carstens
2023-08-12 20:43 ` Matthew Wilcox
2023-08-11 10:08 ` [PATCH 14/17] block: call into the file system for bdev_mark_dead Christoph Hellwig
2023-08-11 10:08 ` [PATCH 15/17] block: call into the file system for ioctl BLKFLSBUF Christoph Hellwig
2023-08-11 14:06 ` Josef Bacik
2023-08-11 10:08 ` [PATCH 16/17] fs: remove get_super Christoph Hellwig
2023-08-11 12:46 ` Christian Brauner
2023-08-11 10:08 ` [PATCH 17/17] fs: simplify invalidate_inodes Christoph Hellwig
2023-08-11 12:48 ` Christian Brauner
2023-08-11 13:58 ` remove get_super Josef Bacik
2023-08-11 19:05 ` Josef Bacik
2023-08-14 19:19 ` David Sterba
2023-09-12 17:42 ` David Sterba
2023-09-14 8:48 ` Jan Kara
2023-09-14 12:03 ` David Sterba
2023-09-14 12:54 ` Jan Kara
2023-09-15 17:28 ` Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230811100828.1897174-14-hch@lst.de \
--to=hch@lst.de \
--cc=agordeev@linux.ibm.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=clm@fb.com \
--cc=djwong@kernel.org \
--cc=dsterba@suse.com \
--cc=efremov@linux.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=hoeppner@linux.ibm.com \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=nbd@other.debian.org \
--cc=sth@linux.ibm.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).