diff options
author | Joern Engel <joern@logfs.org> | 2013-12-26 21:18:40 -0800 |
---|---|---|
committer | Joern Engel <joern@logfs.org> | 2013-12-26 21:18:40 -0800 |
commit | 2735accf504210605168f5207ac06db357192eaf (patch) | |
tree | 04a3aa0aeb36ab2603be0a6a510bd126f0681aaf | |
parent | 2f431d22c5b140d6241da32ce56a367b8302941c (diff) | |
download | bcon2-2735accf504210605168f5207ac06db357192eaf.tar.gz |
bcon: pass devices by dev_t, not name
Simplifies the code a bit.
Signed-off-by: Joern Engel <joern@logfs.org>
-rw-r--r-- | block/partition-generic.c | 3 | ||||
-rw-r--r-- | block/partitions/check.c | 1 | ||||
-rw-r--r-- | drivers/block/blockconsole.c | 57 | ||||
-rw-r--r-- | include/linux/blockconsole.h | 4 |
4 files changed, 22 insertions, 43 deletions
diff --git a/block/partition-generic.c b/block/partition-generic.c index 4df36c1dcaa52f..7ed399036b89bf 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c @@ -431,6 +431,7 @@ rescan: disk->fops->revalidate_disk(disk); check_disk_size_change(disk, bdev); bdev->bd_invalidated = 0; + bcon_add(bdev->bd_dev); if (!get_capacity(disk) || !(state = check_partition(disk, bdev))) return 0; if (IS_ERR(state)) { @@ -521,7 +522,7 @@ rescan: disk->disk_name, p, -PTR_ERR(part)); continue; } - bcon_add(dev_name(part_to_dev(part))); + bcon_add(part_to_dev(part)->devt); #ifdef CONFIG_BLK_DEV_MD if (state->parts[p].flags & ADDPART_FLAG_RAID) md_autodetect_dev(part_to_dev(part)->devt); diff --git a/block/partitions/check.c b/block/partitions/check.c index ae1b990502e503..9ea36bb82f1775 100644 --- a/block/partitions/check.c +++ b/block/partitions/check.c @@ -149,7 +149,6 @@ check_partition(struct gendisk *hd, struct block_device *bdev) free_page((unsigned long)state->pp_buf); return state; } - bcon_add(state->name); if (state->access_beyond_eod) err = -ENOSPC; if (err) diff --git a/drivers/block/blockconsole.c b/drivers/block/blockconsole.c index 91bf1cf47f326c..b68218dd290b44 100644 --- a/drivers/block/blockconsole.c +++ b/drivers/block/blockconsole.c @@ -68,6 +68,8 @@ #include <linux/workqueue.h> #include <linux/sched.h> #include <linux/ctype.h> +#include <linux/device.h> +#include <linux/genhd.h> #define BLOCKCONSOLE_MAGIC "\nLinux blockconsole version 1.1\n" #define BCON_UUID_OFS (32) @@ -565,7 +567,7 @@ static int blockconsole_panic(struct notifier_block *this, unsigned long event, return NOTIFY_DONE; } -static int bcon_create(const char *devname) +static int bcon_create(dev_t devt) { const fmode_t mode = FMODE_READ | FMODE_WRITE; struct blockconsole *bc; @@ -574,22 +576,18 @@ static int bcon_create(const char *devname) bc = kzalloc(sizeof(*bc), GFP_KERNEL); if (!bc) return -ENOMEM; - memset(bc->devname, ' ', sizeof(bc->devname)); - strlcpy(bc->devname, devname, sizeof(bc->devname)); spin_lock_init(&bc->end_io_lock); strcpy(bc->console.name, "bcon"); bc->console.flags = CON_PRINTBUFFER | CON_ENABLED | CON_ALLDATA; bc->console.write = bcon_write; - bc->bdev = blkdev_get_by_path(devname, mode, NULL); -#ifndef MODULE - if (IS_ERR(bc->bdev)) { - dev_t devt = name_to_dev_t(devname); - if (devt) - bc->bdev = blkdev_get_by_dev(devt, mode, NULL); - } -#endif + + bc->bdev = blkdev_get_by_dev(devt, mode, NULL); if (IS_ERR(bc->bdev)) goto out; + + memset(bc->devname, ' ', sizeof(bc->devname)); + strlcpy(bc->devname, dev_name(part_to_dev(bc->bdev->bd_part)), + sizeof(bc->devname)); bc->pages = alloc_pages(GFP_KERNEL, 8); if (!bc->pages) goto out; @@ -605,7 +603,7 @@ static int bcon_create(const char *devname) goto out2; kref_init(&bc->kref); /* This reference gets freed on errors */ bc->writeback_thread = kthread_run(bcon_writeback, bc, "bcon_%s", - devname); + bc->devname); if (IS_ERR(bc->writeback_thread)) goto out2; INIT_WORK(&bc->unregister_work, bcon_unregister); @@ -614,7 +612,7 @@ static int bcon_create(const char *devname) bc->panic_block.notifier_call = blockconsole_panic; bc->panic_block.priority = INT_MAX; atomic_notifier_chain_register(&panic_notifier_list, &bc->panic_block); - pr_info("now logging to %s at %llx\n", devname, + pr_info("now logging to %s at %llx\n", bc->devname, atomic64_read(&bc->console_bytes) >> 20); return 0; @@ -628,31 +626,14 @@ out: return -ENOMEM; } -static void bcon_create_fuzzy(const char *name) -{ - char *longname; - int err; - - err = bcon_create(name); - if (err) { - longname = kzalloc(strlen(name) + 6, GFP_KERNEL); - if (!longname) - return; - strcpy(longname, "/dev/"); - strcat(longname, name); - bcon_create(longname); - kfree(longname); - } -} - struct bcon_candidate { struct work_struct work; - char name[0]; + dev_t devt; }; /* - * Calling bcon_create_fuzzy directly would cause a deadlock. __blkdev_get - * will take bdev->bd_mutex, which is already held by the partitioning code. + * Calling bcon_create directly would cause a deadlock. __blkdev_get will + * take bdev->bd_mutex, which is already held by the partitioning code. * Hence go through the indirection of a work queue. */ static void bcon_do_add(struct work_struct *work) @@ -660,20 +641,18 @@ static void bcon_do_add(struct work_struct *work) struct bcon_candidate *cand = container_of(work, struct bcon_candidate, work); - bcon_create_fuzzy(cand->name); + bcon_create(cand->devt); kfree(cand); } -void bcon_add(const char *name) +void bcon_add(dev_t devt) { struct bcon_candidate *cand; - size_t len; - len = strlen(name) + 1; - cand = kmalloc(sizeof(cand) + len, GFP_KERNEL); + cand = kmalloc(sizeof(cand), GFP_KERNEL); if (!cand) return; - memcpy(cand->name, name, len); + cand->devt = devt; INIT_WORK(&cand->work, bcon_do_add); schedule_work(&cand->work); } diff --git a/include/linux/blockconsole.h b/include/linux/blockconsole.h index 4c852a20ef0a72..7f77e16bd27661 100644 --- a/include/linux/blockconsole.h +++ b/include/linux/blockconsole.h @@ -2,9 +2,9 @@ #define LINUX_BLOCKCONSOLE_H #ifdef CONFIG_BLOCKCONSOLE -void bcon_add(const char *name); +void bcon_add(dev_t devt); #else -static inline void bcon_add(const char *name) {} +static inline void bcon_add(dev_t devt) {} #endif #endif |