From: "Stephen M. Cameron" <scameron@beardog.cce.hp.com>
To: axboe@kernel.dk, neilb@suse.de, hch@infradead.org,
jmoyer@redhat.com, hare@suse.de, tj@kernel.org,
shaohua.li@intel.com, vgoyal@redhat.com
Cc: stephenmcameron@gmail.com, linux-kernel@vger.kernel.org,
lsorense@csclub.uwaterloo.ca
Subject: [RFC PATCH] block: Add new generic block device naming interface
Date: Thu, 25 Apr 2013 15:22:15 -0500 [thread overview]
Message-ID: <20130425202215.20557.75283.stgit@beardog.cce.hp.com> (raw)
From: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Currently, when adding a new block device driver, if grub support is needed,
then grub needs to be modified to know about this new driver.
See this thread:
https://lists.gnu.org/archive/html/grub-devel/2013-03/msg00049.html
If block drivers could (optionally) share a common device namespace then
grub could be taught about this common namespace once, and any new block
device drivers could take advantage of this namespace and grub would
automatically work with them.
The idea is that instead of each new block driver manually setting the
gendisk's disk_name field (though legacy drivers could still do that) they
would call blk_get_new_disk_name(struct gendisk *disk), and the block layer
hands out a name. When removing a device, blk_put_disk_name() releases the
device name.
The scheme implemented in this patch is to name the devices /dev/bdn, with n
being an integer starting at zero that counts up, so you'd get device names
like /dev/bd0, /dev/bd1, /dev/bd2, etc.
Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
---
block/genhd.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/genhd.h | 2 ++
2 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index 3c001fb..d4f1588 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -568,6 +568,58 @@ exit:
disk_part_iter_exit(&piter);
}
+static DEFINE_SPINLOCK(bd_index_lock);
+static DEFINE_IDA(bd_index_ida);
+char *blk_get_disk_name(struct gendisk *disk)
+{
+ int index, error;
+ char name[DISK_NAME_LEN + 1];
+
+ do {
+ if (!ida_pre_get(&bd_index_ida, GFP_KERNEL))
+ goto out;
+
+ spin_lock(&bd_index_lock);
+ error = ida_get_new(&bd_index_ida, &index);
+ spin_unlock(&bd_index_lock);
+ } while (error == -EAGAIN);
+
+ if (error) {
+ pr_warn("blk_get_disk_name: memory exhausted\n");
+ goto out;
+ }
+
+ snprintf(name, DISK_NAME_LEN, "bd%d", index);
+ if (strlen(name) > DISK_NAME_LEN - 1) {
+ pr_warn("block disk (bd) name length exceeded.\n");
+ goto out_free_index;
+ }
+ strncpy(disk->disk_name, name, DISK_NAME_LEN - 1);
+ return disk->disk_name;
+
+out_free_index:
+ spin_lock(&bd_index_lock);
+ ida_remove(&bd_index_ida, index);
+ spin_unlock(&bd_index_lock);
+out:
+ return NULL;
+}
+EXPORT_SYMBOL(blk_get_disk_name);
+
+int blk_put_disk_name(char *name)
+{
+ int index;
+
+ if (sscanf(name, "bd%d", &index) != 1)
+ return -EINVAL;
+
+ spin_lock(&bd_index_lock);
+ ida_remove(&bd_index_ida, index);
+ spin_unlock(&bd_index_lock);
+ return 0;
+}
+EXPORT_SYMBOL(blk_put_disk_name);
+
/**
* add_disk - add partitioning information to kernel list
* @disk: per-device partitioning information
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 9f3c275..fddb41d 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -602,6 +602,8 @@ extern int blk_alloc_devt(struct hd_struct *part, dev_t *devt);
extern void blk_free_devt(dev_t devt);
extern dev_t blk_lookup_devt(const char *name, int partno);
extern char *disk_name (struct gendisk *hd, int partno, char *buf);
+extern char *blk_get_disk_name(struct gendisk *disk);
+extern int blk_put_disk_name(char *name);
extern int disk_expand_part_tbl(struct gendisk *disk, int target);
extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
next reply other threads:[~2013-04-25 20:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-25 20:22 Stephen M. Cameron [this message]
2013-04-25 20:40 ` Tejun Heo
2013-04-25 21:07 ` scameron
2013-04-25 21:14 ` Tejun Heo
2013-04-25 22:12 ` scameron
2013-04-26 19:03 ` Tejun Heo
2013-04-29 14:56 ` Hannes Reinecke
2013-04-29 15:17 ` Vivek Goyal
2013-04-29 16:06 ` Tejun Heo
-- strict thread matches above, loose matches on Subject: below --
2013-03-28 16:18 Stephen M. Cameron
2013-03-11 19:00 Stephen M. Cameron
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=20130425202215.20557.75283.stgit@beardog.cce.hp.com \
--to=scameron@beardog.cce.hp.com \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=hch@infradead.org \
--cc=jmoyer@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lsorense@csclub.uwaterloo.ca \
--cc=neilb@suse.de \
--cc=shaohua.li@intel.com \
--cc=stephenmcameron@gmail.com \
--cc=tj@kernel.org \
--cc=vgoyal@redhat.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
Powered by JetHome