From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: "Stefan Haberland" <sth@linux.ibm.com>,
"Jan Hoeppner" <hoeppner@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
"Doug Gilbert" <dgilbert@interlog.com>,
"Kai Mäkisara" <Kai.Makisara@kolumbus.fi>,
"Luis Chamberlain" <mcgrof@kernel.org>,
linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org
Subject: [PATCH 8/9] block: hold a request_queue reference for the lifetime of struct gendisk
Date: Mon, 16 Aug 2021 15:19:09 +0200 [thread overview]
Message-ID: <20210816131910.615153-9-hch@lst.de> (raw)
In-Reply-To: <20210816131910.615153-1-hch@lst.de>
Acquire the queue ref dropped in disk_release in __blk_alloc_disk so any
allocate gendisk always has a queue reference.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 19 +++++++------------
include/linux/genhd.h | 1 -
2 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index f18122ee2778..6294517cebe6 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -551,15 +551,6 @@ void device_add_disk(struct device *parent, struct gendisk *disk,
register_disk(parent, disk, groups);
blk_register_queue(disk);
- /*
- * Take an extra ref on queue which will be put on disk_release()
- * so that it sticks around as long as @disk is there.
- */
- if (blk_get_queue(disk->queue))
- set_bit(GD_QUEUE_REF, &disk->state);
- else
- WARN_ON_ONCE(1);
-
disk_add_events(disk);
blk_integrity_add(disk);
}
@@ -1087,8 +1078,7 @@ static void disk_release(struct device *dev)
disk_release_events(disk);
kfree(disk->random);
xa_destroy(&disk->part_tbl);
- if (test_bit(GD_QUEUE_REF, &disk->state) && disk->queue)
- blk_put_queue(disk->queue);
+ blk_put_queue(disk->queue);
iput(disk->part0->bd_inode); /* frees the disk */
}
@@ -1259,9 +1249,12 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
{
struct gendisk *disk;
+ if (!blk_get_queue(q))
+ return NULL;
+
disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id);
if (!disk)
- return NULL;
+ goto out_put_queue;
disk->bdi = bdi_alloc(node_id);
if (!disk->bdi)
@@ -1296,6 +1289,8 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
bdi_put(disk->bdi);
out_free_disk:
kfree(disk);
+out_put_queue:
+ blk_put_queue(q);
return NULL;
}
EXPORT_SYMBOL(__alloc_disk_node);
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 13e90e6231d8..55acefdd8a20 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -149,7 +149,6 @@ struct gendisk {
unsigned long state;
#define GD_NEED_PART_SCAN 0
#define GD_READ_ONLY 1
-#define GD_QUEUE_REF 2
struct mutex open_mutex; /* open/close mutex */
unsigned open_partitions; /* number of open partitions */
--
2.30.2
next prev parent reply other threads:[~2021-08-16 13:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-16 13:19 ensure each gendisk always has a request_queue reference v2 Christoph Hellwig
2021-08-16 13:19 ` [PATCH 1/9] nvme: use blk_mq_alloc_disk Christoph Hellwig
2021-08-19 14:54 ` Keith Busch
2021-08-19 14:58 ` Keith Busch
2021-08-19 22:57 ` Luis Chamberlain
2021-08-20 4:06 ` Christoph Hellwig
2021-08-23 17:22 ` Sagi Grimberg
2021-08-16 13:19 ` [PATCH 2/9] st: do not allocate a gendisk Christoph Hellwig
2021-08-16 13:19 ` [PATCH 3/9] sg: " Christoph Hellwig
2021-08-19 21:33 ` Luis Chamberlain
2021-08-19 21:36 ` Luis Chamberlain
2021-08-20 4:05 ` Christoph Hellwig
2021-08-16 13:19 ` [PATCH 4/9] block: cleanup the lockdep handling in *alloc_disk Christoph Hellwig
2021-08-16 13:19 ` [PATCH 5/9] block: remove alloc_disk and alloc_disk_node Christoph Hellwig
2021-08-16 13:19 ` [PATCH 6/9] block: remove the minors argument to __alloc_disk_node Christoph Hellwig
2021-08-16 13:19 ` [PATCH 7/9] block: pass a request_queue to __blk_alloc_disk Christoph Hellwig
2021-08-16 13:19 ` Christoph Hellwig [this message]
2021-08-20 13:42 ` [PATCH 8/9] block: hold a request_queue reference for the lifetime of struct gendisk Ming Lei
2021-08-16 13:46 ` [PATCH 9/9] block: add an explicit ->disk backpointer to the request_queue Christoph Hellwig
2021-08-19 14:39 ` Sven Schnelle
2021-08-23 18:55 ` ensure each gendisk always has a request_queue reference v2 Jens Axboe
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=20210816131910.615153-9-hch@lst.de \
--to=hch@lst.de \
--cc=Kai.Makisara@kolumbus.fi \
--cc=axboe@kernel.dk \
--cc=dgilbert@interlog.com \
--cc=hoeppner@linux.ibm.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mcgrof@kernel.org \
--cc=sth@linux.ibm.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;
as well as URLs for NNTP newsgroup(s).