From: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>, Christoph Hellwig <hch@lst.de>
Cc: linux-fsdevel@vger.kernel.org, Christian Brauner <brauner@kernel.org>
Subject: [PATCH RFC 5/6] block: mark device as about to be released
Date: Tue, 24 Oct 2023 16:53:43 +0200 [thread overview]
Message-ID: <20231024-vfs-super-rework-v1-5-37a8aa697148@kernel.org> (raw)
In-Reply-To: <20231024-vfs-super-rework-v1-0-37a8aa697148@kernel.org>
Make it possible for the exclusive holder of a block device to mark it
as about to be closed and exclusive ownership given up. Any concurrent
opener trying to claim the device with the same holder ops can wait
until the device is free to be reclaimed. Requiring the same holder ops
makes it possible to easily define groups of openers that can wait for
each other.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
block/bdev.c | 20 ++++++++++++++++++++
include/linux/blk_types.h | 1 +
include/linux/blkdev.h | 1 +
3 files changed, 22 insertions(+)
diff --git a/block/bdev.c b/block/bdev.c
index 7d19e04a8df8..943c7a188bb3 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -469,6 +469,11 @@ static bool bd_may_claim(struct block_device *bdev, void *holder,
return false;
return true;
}
+
+ if ((whole->bd_claim == BD_CLAIM_YIELD) &&
+ (bdev->bd_holder_ops == hops))
+ return true;
+
return false;
}
@@ -608,6 +613,7 @@ static void bd_end_claim(struct block_device *bdev, void *holder)
mutex_unlock(&bdev->bd_holder_lock);
if (bdev->bd_write_holder)
unblock = true;
+ bd_clear_claiming(whole);
}
if (!whole->bd_holders)
whole->bd_holder = NULL;
@@ -954,6 +960,20 @@ void bdev_release(struct bdev_handle *handle)
}
EXPORT_SYMBOL(bdev_release);
+void bdev_yield(struct bdev_handle *handle)
+{
+ struct block_device *bdev = handle->bdev;
+ struct block_device *whole = bdev_whole(bdev);
+
+ mutex_lock(&bdev_lock);
+ WARN_ON_ONCE(bdev->bd_holders == 0);
+ WARN_ON_ONCE(bdev->bd_holder != handle->holder);
+ WARN_ON_ONCE(whole->bd_claim);
+ whole->bd_claim = BD_CLAIM_YIELD;
+ mutex_unlock(&bdev_lock);
+}
+EXPORT_SYMBOL(bdev_yield);
+
/**
* lookup_bdev() - Look up a struct block_device by name.
* @pathname: Name of the block device in the filesystem.
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index cbef041fd868..54cf274a436c 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -40,6 +40,7 @@ struct bio_crypt_ctx;
enum bd_claim {
BD_CLAIM_DEFAULT = 0,
BD_CLAIM_ACQUIRE = 1,
+ BD_CLAIM_YIELD = 2,
};
struct block_device {
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index abf71cce785c..b15129afcdbe 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1513,6 +1513,7 @@ 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, void *holder);
void bdev_release(struct bdev_handle *handle);
+void bdev_yield(struct bdev_handle *handle);
/* just for blk-cgroup, don't use elsewhere */
struct block_device *blkdev_get_no_open(dev_t dev);
--
2.34.1
next prev parent reply other threads:[~2023-10-24 14:54 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-24 14:53 [PATCH RFC 0/6] fs,block: yield devices Christian Brauner
2023-10-24 14:53 ` [PATCH RFC 1/6] fs: simplify setup_bdev_super() calls Christian Brauner
2023-10-25 15:29 ` Jan Kara
2023-10-27 6:42 ` Christoph Hellwig
2023-10-24 14:53 ` [PATCH RFC 2/6] xfs: simplify device handling Christian Brauner
2023-10-25 15:30 ` Jan Kara
2023-10-27 6:42 ` Christoph Hellwig
2023-10-24 14:53 ` [PATCH RFC 3/6] ext4: " Christian Brauner
2023-10-25 15:30 ` Jan Kara
2023-10-27 6:42 ` Christoph Hellwig
2023-10-24 14:53 ` [PATCH RFC 4/6] bdev: simplify waiting for concurrent claimers Christian Brauner
2023-10-25 15:54 ` Jan Kara
2023-10-27 7:21 ` Christoph Hellwig
2023-10-24 14:53 ` Christian Brauner [this message]
2023-10-24 14:53 ` [PATCH RFC 6/6] fs: add ->yield_devices() Christian Brauner
2023-10-25 17:20 ` [PATCH RFC 0/6] fs,block: yield devices Jan Kara
2023-10-25 20:46 ` Christian Brauner
2023-10-26 10:35 ` Jan Kara
2023-10-26 12:07 ` Christian Brauner
2023-10-26 13:04 ` Jan Kara
2023-10-26 15:08 ` Christian Brauner
2023-10-26 15:58 ` Jan Kara
2023-10-27 7:24 ` Christoph Hellwig
2023-10-26 11:50 ` (subset) " Christian Brauner
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=20231024-vfs-super-rework-v1-5-37a8aa697148@kernel.org \
--to=brauner@kernel.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
/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).