From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org, cem@kernel.org, axboe@kernel.dk
Cc: shinichiro.kawasaki@wdc.com, linux-mm@kvack.org,
mcgrof@kernel.org, linux-fsdevel@vger.kernel.org,
linux-xfs@vger.kernel.org, willy@infradead.org,
hch@infradead.org, linux-block@vger.kernel.org
Subject: [PATCH 2/3] block: hoist block size validation code to a separate function
Date: Mon, 21 Apr 2025 10:19:07 -0700 [thread overview]
Message-ID: <174525589069.2138337.10477679176303850629.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <174525589013.2138337.16473045486118778580.stgit@frogsfrogsfrogs>
From: Darrick J. Wong <djwong@kernel.org>
Hoist the block size validation code to bdev_validate_blocksize so that
we can call it from filesystems that don't care about the bdev pagecache
manipulations of set_blocksize.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
include/linux/blkdev.h | 1 +
block/bdev.c | 33 +++++++++++++++++++++++++++------
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 294bbae415aa09..462e23a1e8b261 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1618,6 +1618,7 @@ static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time)
return bio_end_io_acct_remapped(bio, start_time, bio->bi_bdev);
}
+int bdev_validate_blocksize(struct block_device *bdev, int block_size);
int set_blocksize(struct file *file, int size);
int lookup_bdev(const char *pathname, dev_t *dev);
diff --git a/block/bdev.c b/block/bdev.c
index 24984ec13e7cb2..1588f96e4f0a35 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -152,17 +152,38 @@ static void set_init_blocksize(struct block_device *bdev)
get_order(bsize), get_order(bsize));
}
+/**
+ * bdev_validate_blocksize - check that this block size is acceptable
+ * @bdev: blockdevice to check
+ * @block_size: block size to check
+ *
+ * For block device users that do not use buffer heads or the block device
+ * page cache, make sure that this block size can be used with the device.
+ *
+ * Return: On success zero is returned, negative error code on failure.
+ */
+int bdev_validate_blocksize(struct block_device *bdev, int block_size)
+{
+ if (blk_validate_block_size(block_size))
+ return -EINVAL;
+
+ /* Size cannot be smaller than the size supported by the device */
+ if (block_size < bdev_logical_block_size(bdev))
+ return -EINVAL;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(bdev_validate_blocksize);
+
int set_blocksize(struct file *file, int size)
{
struct inode *inode = file->f_mapping->host;
struct block_device *bdev = I_BDEV(inode);
+ int ret;
- if (blk_validate_block_size(size))
- return -EINVAL;
-
- /* Size cannot be smaller than the size supported by the device */
- if (size < bdev_logical_block_size(bdev))
- return -EINVAL;
+ ret = bdev_validate_blocksize(bdev, size);
+ if (ret)
+ return ret;
if (!file->private_data)
return -EINVAL;
next prev parent reply other threads:[~2025-04-21 17:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-21 17:18 [PATCHSET V2] block/xfs: bdev page cache bug fixes for 6.15 Darrick J. Wong
2025-04-21 17:18 ` [PATCH 1/3] block: fix race between set_blocksize and read paths Darrick J. Wong
2025-04-21 17:19 ` Darrick J. Wong [this message]
2025-04-21 17:19 ` [PATCH 3/3] xfs: stop using set_blocksize Darrick J. Wong
2025-04-21 20:24 ` [PATCHSET V2] block/xfs: bdev page cache bug fixes for 6.15 Jens Axboe
2025-04-21 20:26 ` Jens Axboe
2025-04-21 20:51 ` Darrick J. Wong
2025-04-21 20:53 ` Jens Axboe
2025-04-22 1:19 ` Darrick J. Wong
2025-04-21 20:57 ` Luis Chamberlain
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=174525589069.2138337.10477679176303850629.stgit@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=axboe@kernel.dk \
--cc=cem@kernel.org \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=shinichiro.kawasaki@wdc.com \
--cc=willy@infradead.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