From: Christoph Hellwig <hch@lst.de> To: Jens Axboe <axboe@kernel.dk> Cc: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Stefan Hajnoczi <stefanha@redhat.com>, Maxim Levitsky <maximlevitsky@gmail.com>, Alex Dubov <oakad@yahoo.com>, Ulf Hansson <ulf.hansson@linaro.org>, linux-block@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-mmc@vger.kernel.org Subject: [PATCH 1/5] block: add a ->free_disk method Date: Wed, 9 Feb 2022 09:21:16 +0100 [thread overview] Message-ID: <20220209082121.2628452-2-hch@lst.de> (raw) In-Reply-To: <20220209082121.2628452-1-hch@lst.de> Add a method to notify the driver that the gendisk is about to be freed. This allows drivers to tie the lifetime of their private data to that of the gendisk and thus deal with device removal races without expensive synchronization and boilerplate code. Signed-off-by: Christoph Hellwig <hch@lst.de> --- block/genhd.c | 4 ++++ include/linux/blkdev.h | 1 + 2 files changed, 5 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 9589d1d59afab..1a650c55d7626 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1119,6 +1119,10 @@ static void disk_release(struct device *dev) xa_destroy(&disk->part_tbl); disk->queue->disk = NULL; blk_put_queue(disk->queue); + + if (disk->fops->free_disk) + disk->fops->free_disk(disk); + iput(disk->part0->bd_inode); /* frees the disk */ } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 3bfc75a2a4509..a8f8aa4671037 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1464,6 +1464,7 @@ struct block_device_operations { void (*unlock_native_capacity) (struct gendisk *); int (*getgeo)(struct block_device *, struct hd_geometry *); int (*set_read_only)(struct block_device *bdev, bool ro); + void (*free_disk)(struct gendisk *disk); /* this callback is with swap_lock and sometimes page table lock held */ void (*swap_slot_free_notify) (struct block_device *, unsigned long); int (*report_zones)(struct gendisk *, sector_t sector, -- 2.30.2
WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de> To: Jens Axboe <axboe@kernel.dk> Cc: Maxim Levitsky <maximlevitsky@gmail.com>, Alex Dubov <oakad@yahoo.com>, "Michael S. Tsirkin" <mst@redhat.com>, linux-mmc@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-block@vger.kernel.org, Stefan Hajnoczi <stefanha@redhat.com>, Paolo Bonzini <pbonzini@redhat.com> Subject: [PATCH 1/5] block: add a ->free_disk method Date: Wed, 9 Feb 2022 09:21:16 +0100 [thread overview] Message-ID: <20220209082121.2628452-2-hch@lst.de> (raw) In-Reply-To: <20220209082121.2628452-1-hch@lst.de> Add a method to notify the driver that the gendisk is about to be freed. This allows drivers to tie the lifetime of their private data to that of the gendisk and thus deal with device removal races without expensive synchronization and boilerplate code. Signed-off-by: Christoph Hellwig <hch@lst.de> --- block/genhd.c | 4 ++++ include/linux/blkdev.h | 1 + 2 files changed, 5 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 9589d1d59afab..1a650c55d7626 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1119,6 +1119,10 @@ static void disk_release(struct device *dev) xa_destroy(&disk->part_tbl); disk->queue->disk = NULL; blk_put_queue(disk->queue); + + if (disk->fops->free_disk) + disk->fops->free_disk(disk); + iput(disk->part0->bd_inode); /* frees the disk */ } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 3bfc75a2a4509..a8f8aa4671037 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1464,6 +1464,7 @@ struct block_device_operations { void (*unlock_native_capacity) (struct gendisk *); int (*getgeo)(struct block_device *, struct hd_geometry *); int (*set_read_only)(struct block_device *bdev, bool ro); + void (*free_disk)(struct gendisk *disk); /* this callback is with swap_lock and sometimes page table lock held */ void (*swap_slot_free_notify) (struct block_device *, unsigned long); int (*report_zones)(struct gendisk *, sector_t sector, -- 2.30.2 _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2022-02-09 8:21 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-09 8:21 add a ->free_disk block_device_operation v2 Christoph Hellwig 2022-02-09 8:21 ` Christoph Hellwig 2022-02-09 8:21 ` Christoph Hellwig [this message] 2022-02-09 8:21 ` [PATCH 1/5] block: add a ->free_disk method Christoph Hellwig 2022-02-09 8:21 ` [PATCH 2/5] memstick/ms_block: simplify refcounting Christoph Hellwig 2022-02-09 8:21 ` Christoph Hellwig 2022-02-11 2:35 ` Ming Lei 2022-02-11 2:35 ` Ming Lei 2022-02-09 8:21 ` [PATCH 3/5] memstick/mspro_block: fix handling of read-only devices Christoph Hellwig 2022-02-09 8:21 ` Christoph Hellwig 2022-02-09 8:21 ` [PATCH 4/5] memstick/mspro_block: simplify refcounting Christoph Hellwig 2022-02-09 8:21 ` Christoph Hellwig 2022-02-09 8:21 ` [PATCH 5/5] virtio_blk: " Christoph Hellwig 2022-02-09 8:21 ` Christoph Hellwig 2022-02-09 8:27 ` Michael S. Tsirkin 2022-02-09 8:27 ` Michael S. Tsirkin 2022-02-09 9:38 ` Stefan Hajnoczi 2022-02-09 9:38 ` Stefan Hajnoczi -- strict thread matches above, loose matches on Subject: below -- 2022-02-15 9:45 add a ->free_disk block_device_operation v3 Christoph Hellwig 2022-02-15 9:45 ` [PATCH 1/5] block: add a ->free_disk method Christoph Hellwig 2022-02-15 9:45 ` Christoph Hellwig 2022-02-02 15:56 add a ->free_disk block_device_operation Christoph Hellwig 2022-02-02 15:56 ` [PATCH 1/5] block: add a ->free_disk method Christoph Hellwig 2022-02-02 15:56 ` Christoph Hellwig
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=20220209082121.2628452-2-hch@lst.de \ --to=hch@lst.de \ --cc=axboe@kernel.dk \ --cc=jasowang@redhat.com \ --cc=linux-block@vger.kernel.org \ --cc=linux-mmc@vger.kernel.org \ --cc=maximlevitsky@gmail.com \ --cc=mst@redhat.com \ --cc=oakad@yahoo.com \ --cc=pbonzini@redhat.com \ --cc=stefanha@redhat.com \ --cc=ulf.hansson@linaro.org \ --cc=virtualization@lists.linux-foundation.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.