public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Valentin Kleibel <valentin@vrvis.at>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
	Justin Sanders <justin@coraid.com>,
	linux-block@vger.kernel.org
Subject: [PATCH v2 1/2] block: add blk_alloc_disk and blk_cleanup_disk APIs
Date: Thu, 31 Mar 2022 12:00:08 +0200	[thread overview]
Message-ID: <ab7167b6-8ea5-fd4a-66ea-b8aa93f68ee2@vrvis.at> (raw)
In-Reply-To: <b19953f8-2097-6962-eceb-5d41f4639ce4@vrvis.at>

Add two new APIs to allocate and free a gendisk including the
request_queue for use with BIO based drivers.  This is to avoid
boilerplate code in drivers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20210521055116.1053587-6-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
(cherry picked from commit f525464a8000f092c20b00eead3eaa9d849c599e)
Fixes: 3582dd291788 (aoe: convert aoeblk to blk-mq)
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215647
Signed-off-by: Valentin Kleibel <valentin@vrvis.at>
---
  block/genhd.c         | 15 +++++++++++++++
  include/linux/genhd.h |  1 +
  2 files changed, 16 insertions(+)

diff --git a/block/genhd.c b/block/genhd.c
index 796baf761202..421cad085502 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1836,6 +1836,21 @@ void put_disk_and_module(struct gendisk *disk)
         }
  }
  EXPORT_SYMBOL(put_disk_and_module);
+/**
+ * blk_cleanup_disk - shutdown a gendisk allocated by blk_alloc_disk
+ * @disk: gendisk to shutdown
+ *
+ * Mark the queue hanging off @disk DYING, drain all pending requests, 
then mark
+ * the queue DEAD, destroy and put it and the gendisk structure.
+ *
+ * Context: can sleep
+ */
+void blk_cleanup_disk(struct gendisk *disk)
+{
+       blk_cleanup_queue(disk->queue);
+       put_disk(disk);
+}
+EXPORT_SYMBOL(blk_cleanup_disk);

  static void set_disk_ro_uevent(struct gendisk *gd, int ro)
  {
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 03da3f603d30..b7b180d3734a 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -369,6 +369,7 @@ extern void blk_unregister_region(dev_t devt, 
unsigned long range);
  #define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE)

  int register_blkdev(unsigned int major, const char *name);
+void blk_cleanup_disk(struct gendisk *disk);
  void unregister_blkdev(unsigned int major, const char *name);

  void revalidate_disk_size(struct gendisk *disk, bool verbose);

  reply	other threads:[~2022-03-31 10:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10 11:53 [PATCH] block: aoe: fix page fault in freedev() Valentin Kleibel
2022-03-10 12:03 ` Greg Kroah-Hartman
2022-03-10 12:24   ` Valentin Kleibel
2022-03-10 12:26     ` Greg Kroah-Hartman
2022-03-10 12:55       ` Valentin Kleibel
2022-03-14 11:12         ` Greg Kroah-Hartman
2022-03-31  9:58           ` [PATCH v2 0/2] " Valentin Kleibel
2022-03-31 10:00             ` Valentin Kleibel [this message]
2022-04-11 14:43               ` [PATCH v2 1/2] block: add blk_alloc_disk and blk_cleanup_disk APIs Greg Kroah-Hartman
2022-03-31 10:01             ` [PATCH v2 2/2] aoe: use blk_mq_alloc_disk and blk_cleanup_disk Valentin Kleibel

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=ab7167b6-8ea5-fd4a-66ea-b8aa93f68ee2@vrvis.at \
    --to=valentin@vrvis.at \
    --cc=axboe@kernel.dk \
    --cc=gregkh@linuxfoundation.org \
    --cc=justin@coraid.com \
    --cc=linux-block@vger.kernel.org \
    --cc=stable@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