Rust for Linux List
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	Jens Axboe <axboe@kernel.dk>, Christoph Hellwig <hch@lst.de>,
	Jan Kara <jack@suse.cz>,
	linux-block <linux-block@vger.kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Brian Foster <bfoster@redhat.com>,
	Damien Le Moal <dlemoal@kernel.org>,
	Hillf Danton <hdanton@sina.com>,
	Markus Elfring <Markus.Elfring@web.de>,
	Ming Lei <tom.leiming@gmail.com>, Qu Wenruo <wqu@suse.com>,
	Tao Cui <cui.tao@linux.dev>, kernel test robot <lkp@intel.com>,
	rust-for-linux@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Nilay Shroff <nilay@linux.ibm.com>
Subject: Re: [PATCH v4 1/2] block: Add run_todo() operation
Date: Tue, 22 Sep 2026 11:09:53 -0700	[thread overview]
Message-ID: <ac1d3825-8a10-42e1-9eaa-f2ba51216660@acm.org> (raw)
In-Reply-To: <24ef93b9-7385-4dda-8912-f7c78f9705d1@I-love.SAKURA.ne.jp>

On 9/21/26 10:08 PM, Tetsuo Handa wrote:
> I think post_release() is misleading because post_release() is also called
> when disk->fops->open() in blkdev_get_whole() failed (and therefore
> bdev->bd_disk->fops->release() in blkdev_put_whole() from blkdev_get_whole()
> was not called).

Has it been considered to call the new callback only if fops->release()
has been invoked? Here is an (untested) example of how this could be
implemented:

diff --git a/block/bdev.c b/block/bdev.c
index cd8323083740..82be4812a7a0 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -766,7 +766,8 @@ static void blkdev_put_whole(struct block_device *bdev)
  		bdev->bd_disk->fops->release(bdev->bd_disk);
  }

-static int blkdev_get_whole(struct block_device *bdev, blk_mode_t mode)
+static int blkdev_get_whole(struct block_device *bdev, blk_mode_t mode,
+			    bool *called_release)
  {
  	struct gendisk *disk = bdev->bd_disk;
  	int ret;
@@ -793,18 +794,20 @@ static int blkdev_get_whole(struct block_device 
*bdev, blk_mode_t mode)
  		ret = bdev_disk_changed(disk, false);
  		if (ret && (mode & BLK_OPEN_STRICT_SCAN)) {
  			blkdev_put_whole(bdev);
+			*called_release = true;
  			return ret;
  		}
  	}
  	return 0;
  }

-static int blkdev_get_part(struct block_device *part, blk_mode_t mode)
+static int blkdev_get_part(struct block_device *part, blk_mode_t mode,
+			   bool *called_release)
  {
  	struct gendisk *disk = part->bd_disk;
  	int ret;

-	ret = blkdev_get_whole(bdev_whole(part), mode);
+	ret = blkdev_get_whole(bdev_whole(part), mode, called_release);
  	if (ret)
  		return ret;

@@ -821,6 +824,7 @@ static int blkdev_get_part(struct block_device 
*part, blk_mode_t mode)

  out_blkdev_put:
  	blkdev_put_whole(bdev_whole(part));
+	*called_release = true;
  	return ret;
  }

@@ -973,6 +977,7 @@ int bdev_open(struct block_device *bdev, blk_mode_t 
mode, void *holder,
  {
  	bool unblock_events = true;
  	struct gendisk *disk = bdev->bd_disk;
+	bool called_release = false;
  	int ret;

  	if (holder) {
@@ -997,9 +1002,9 @@ int bdev_open(struct block_device *bdev, blk_mode_t 
mode, void *holder,
  	if (!bdev_may_open(bdev, mode))
  		goto put_module;
  	if (bdev_is_partition(bdev))
-		ret = blkdev_get_part(bdev, mode);
+		ret = blkdev_get_part(bdev, mode, &called_release);
  	else
-		ret = blkdev_get_whole(bdev, mode);
+		ret = blkdev_get_whole(bdev, mode, &called_release);
  	if (ret)
  		goto put_module;
  	bdev_claim_write_access(bdev, mode);
@@ -1037,7 +1042,14 @@ int bdev_open(struct block_device *bdev, 
blk_mode_t mode, void *holder,

  	return 0;
  put_module:
+	if (holder)
+		bd_abort_claiming(bdev, holder);
+	mutex_unlock(&disk->open_mutex);
+	if (called_release && disk->fops->post_release)
+		disk->fops->post_release(disk);
+	disk_unblock_events(disk);
  	module_put(disk->fops->owner);
+	return ret;
  abort_claiming:
  	if (holder)
  		bd_abort_claiming(bdev, holder);
@@ -1189,6 +1201,9 @@ void bdev_release(struct file *bdev_file)
  		blkdev_put_whole(bdev);
  	mutex_unlock(&disk->open_mutex);

+	if (disk->fops->post_release)
+		disk->fops->post_release(disk);
+
  	module_put(disk->fops->owner);
  put_no_open:
  	blkdev_put_no_open(bdev);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 4f7905c3412b..f2a2f70a9582 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1577,6 +1577,7 @@ struct block_device_operations {
  			unsigned int flags);
  	int (*open)(struct gendisk *disk, blk_mode_t mode);
  	void (*release)(struct gendisk *disk);
+	void (*post_release)(struct gendisk *disk);
  	int (*ioctl)(struct block_device *bdev, blk_mode_t mode,
  			unsigned cmd, unsigned long arg);
  	int (*compat_ioctl)(struct block_device *bdev, blk_mode_t mode,

Thanks,

Bart.

  reply	other threads:[~2026-09-22 18:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19 10:50 [PATCH v4 1/2] block: Add run_todo() operation Tetsuo Handa
2026-09-19 10:51 ` [PATCH v4 2/2] loop: Perform __loop_clr_fd() from run_todo callback Tetsuo Handa
2026-09-21 17:30   ` Bart Van Assche
2026-09-21 17:27 ` [PATCH v4 1/2] block: Add run_todo() operation Bart Van Assche
2026-09-22  5:08   ` Tetsuo Handa
2026-09-22 18:09     ` Bart Van Assche [this message]
2026-09-23  5:26       ` Tetsuo Handa
2026-09-23 17:05         ` Bart Van Assche

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=ac1d3825-8a10-42e1-9eaa-f2ba51216660@acm.org \
    --to=bvanassche@acm.org \
    --cc=Markus.Elfring@web.de \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=bfoster@redhat.com \
    --cc=cui.tao@linux.dev \
    --cc=dlemoal@kernel.org \
    --cc=hch@lst.de \
    --cc=hdanton@sina.com \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=nilay@linux.ibm.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tom.leiming@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wqu@suse.com \
    /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