cregit-Linux how code gets into the kernel

Release 4.7 block/genhd.c

Directory: block
/*
 *  gendisk handling
 */

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/genhd.h>
#include <linux/kdev_t.h>
#include <linux/kernel.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/kmod.h>
#include <linux/kobj_map.h>
#include <linux/mutex.h>
#include <linux/idr.h>
#include <linux/log2.h>
#include <linux/pm_runtime.h>
#include <linux/badblocks.h>

#include "blk.h"

static DEFINE_MUTEX(block_class_lock);

struct kobject *block_depr;

/* for extended dynamic devt allocation, currently only one major is used */

#define NR_EXT_DEVT		(1 << MINORBITS)

/* For extended devt allocation.  ext_devt_lock prevents look up
 * results from going away underneath its user.
 */
static DEFINE_SPINLOCK(ext_devt_lock);
static DEFINE_IDR(ext_devt_idr);


static struct device_type disk_type;

static void disk_check_events(struct disk_events *ev,
			      unsigned int *clearing_ptr);
static void disk_alloc_events(struct gendisk *disk);
static void disk_add_events(struct gendisk *disk);
static void disk_del_events(struct gendisk *disk);
static void disk_release_events(struct gendisk *disk);

/**
 * disk_get_part - get partition
 * @disk: disk to look partition from
 * @partno: partition number
 *
 * Look for partition @partno from @disk.  If found, increment
 * reference count and return it.
 *
 * CONTEXT:
 * Don't care.
 *
 * RETURNS:
 * Pointer to the found partition on success, NULL if not found.
 */

struct hd_struct *disk_get_part(struct gendisk *disk, int partno) { struct hd_struct *part = NULL; struct disk_part_tbl *ptbl; if (unlikely(partno < 0)) return NULL; rcu_read_lock(); ptbl = rcu_dereference(disk->part_tbl); if (likely(partno < ptbl->len)) { part = rcu_dereference(ptbl->part[partno]); if (part) get_device(part_to_dev(part)); } rcu_read_unlock(); return part; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo94100.00%4100.00%
Total94100.00%4100.00%

EXPORT_SYMBOL_GPL(disk_get_part); /** * disk_part_iter_init - initialize partition iterator * @piter: iterator to initialize * @disk: disk to iterate over * @flags: DISK_PITER_* flags * * Initialize @piter so that it iterates over partitions of @disk. * * CONTEXT: * Don't care. */
void disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk, unsigned int flags) { struct disk_part_tbl *ptbl; rcu_read_lock(); ptbl = rcu_dereference(disk->part_tbl); piter->disk = disk; piter->part = NULL; if (flags & DISK_PITER_REVERSE) piter->idx = ptbl->len - 1; else if (flags & (DISK_PITER_INCL_PART0 | DISK_PITER_INCL_EMPTY_PART0)) piter->idx = 0; else piter->idx = 1; piter->flags = flags; rcu_read_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo97100.00%4100.00%
Total97100.00%4100.00%

EXPORT_SYMBOL_GPL(disk_part_iter_init); /** * disk_part_iter_next - proceed iterator to the next partition and return it * @piter: iterator of interest * * Proceed @piter to the next partition and return it. * * CONTEXT: * Don't care. */
struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter) { struct disk_part_tbl *ptbl; int inc, end; /* put the last partition */ disk_put_part(piter->part); piter->part = NULL; /* get part_tbl */ rcu_read_lock(); ptbl = rcu_dereference(piter->disk->part_tbl); /* determine iteration parameters */ if (piter->flags & DISK_PITER_REVERSE) { inc = -1; if (piter->flags & (DISK_PITER_INCL_PART0 | DISK_PITER_INCL_EMPTY_PART0)) end = -1; else end = 0; } else { inc = 1; end = ptbl->len; } /* iterate to the next partition */ for (; piter->idx != end; piter->idx += inc) { struct hd_struct *part; part = rcu_dereference(ptbl->part[piter->idx]); if (!part) continue; if (!part_nr_sects_read(part) && !(piter->flags & DISK_PITER_INCL_EMPTY) && !(piter->flags & DISK_PITER_INCL_EMPTY_PART0 && piter->idx == 0)) continue; get_device(part_to_dev(part)); piter->part = part; piter->idx += inc; break; } rcu_read_unlock(); return piter->part; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo20498.55%583.33%
vivek goyalvivek goyal31.45%116.67%
Total207100.00%6100.00%

EXPORT_SYMBOL_GPL(disk_part_iter_next); /** * disk_part_iter_exit - finish up partition iteration * @piter: iter of interest * * Called when iteration is over. Cleans up @piter. * * CONTEXT: * Don't care. */
void disk_part_iter_exit(struct disk_part_iter *piter) { disk_put_part(piter->part); piter->part = NULL; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo23100.00%1100.00%
Total23100.00%1100.00%

EXPORT_SYMBOL_GPL(disk_part_iter_exit);
static inline int sector_in_part(struct hd_struct *part, sector_t sector) { return part->start_sect <= sector && sector < part->start_sect + part_nr_sects_read(part); }

Contributors

PersonTokensPropCommitsCommitProp
jens axboejens axboe3090.91%150.00%
vivek goyalvivek goyal39.09%150.00%
Total33100.00%2100.00%

/** * disk_map_sector_rcu - map sector to partition * @disk: gendisk of interest * @sector: sector to map * * Find out which partition @sector maps to on @disk. This is * primarily used for stats accounting. * * CONTEXT: * RCU read locked. The returned partition pointer is valid only * while preemption is disabled. * * RETURNS: * Found partition on success, part0 is returned if no partition matches */
struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector) { struct disk_part_tbl *ptbl; struct hd_struct *part; int i; ptbl = rcu_dereference(disk->part_tbl); part = rcu_dereference(ptbl->last_lookup); if (part && sector_in_part(part, sector)) return part; for (i = 1; i < ptbl->len; i++) { part = rcu_dereference(ptbl->part[i]); if (part && sector_in_part(part, sector)) { rcu_assign_pointer(ptbl->last_lookup, part); return part; } } return &disk->part0; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo7663.33%480.00%
jens axboejens axboe4436.67%120.00%
Total120100.00%5100.00%

EXPORT_SYMBOL_GPL(disk_map_sector_rcu); /* * Can be deleted altogether. Later. * */ static struct blk_major_name { struct blk_major_name *next; int major; char name[16]; } *major_names[BLKDEV_MAJOR_HASH_SIZE]; /* index in the above - for now: assume no multimajor ranges */
static inline int major_to_index(unsigned major) { return major % BLKDEV_MAJOR_HASH_SIZE; }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton1386.67%133.33%
yang zhangyang zhang16.67%133.33%
joe kortyjoe korty16.67%133.33%
Total15100.00%3100.00%

#ifdef CONFIG_PROC_FS
void blkdev_show(struct seq_file *seqf, off_t offset) { struct blk_major_name *dp; if (offset < BLKDEV_MAJOR_HASH_SIZE) { mutex_lock(&block_class_lock); for (dp = major_names[offset]; dp; dp = dp->next) seq_printf(seqf, "%3d %s\n", dp->major, dp->name); mutex_unlock(&block_class_lock); } }

Contributors

PersonTokensPropCommitsCommitProp
joe kortyjoe korty3042.86%114.29%
andrew mortonandrew morton2738.57%114.29%
neil hormanneil horman68.57%114.29%
al viroal viro22.86%114.29%
tejun heotejun heo22.86%114.29%
kay sieverskay sievers22.86%114.29%
jes sorensenjes sorensen11.43%114.29%
Total70100.00%7100.00%

#endif /* CONFIG_PROC_FS */ /** * register_blkdev - register a new block device * * @major: the requested major device number [1..255]. If @major=0, try to * allocate any unused major number. * @name: the name of the new block device as a zero terminated string * * The @name must be unique within the system. * * The return value depends on the @major input parameter. * - if a major device number was requested in range [1..255] then the * function returns zero on success, or a negative error code * - if any unused major number was requested with @major=0 parameter * then the return value is the allocated major number in range * [1..255] or a negative error code otherwise */
int register_blkdev(unsigned int major, const char *name) { struct blk_major_name **n, *p; int index, ret = 0; mutex_lock(&block_class_lock); /* temporary */ if (major == 0) { for (index = ARRAY_SIZE(major_names)-1; index > 0; index--) { if (major_names[index] == NULL) break; } if (index == 0) { printk("register_blkdev: failed to get major for %s\n", name); ret = -EBUSY; goto out; } major = index; ret = major; } p = kmalloc(sizeof(struct blk_major_name), GFP_KERNEL); if (p == NULL) { ret = -ENOMEM; goto out; } p->major = major; strlcpy(p->name, name, sizeof(p->name)); p->next = NULL; index = major_to_index(major); for (n = &major_names[index]; *n; n = &(*n)->next) { if ((*n)->major == major) break; } if (!*n) *n = p; else ret = -EBUSY; if (ret < 0) { printk("register_blkdev: cannot get major %d for %s\n", major, name); kfree(p); } out: mutex_unlock(&block_class_lock); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton25197.67%342.86%
jes sorensenjes sorensen20.78%114.29%
kay sieverskay sievers20.78%114.29%
mika kukkonenmika kukkonen10.39%114.29%
ben collinsben collins10.39%114.29%
Total257100.00%7100.00%

EXPORT_SYMBOL(register_blkdev);
void unregister_blkdev(unsigned int major, const char *name) { struct blk_major_name **n; struct blk_major_name *p = NULL; int index = major_to_index(major); mutex_lock(&block_class_lock); for (n = &major_names[index]; *n; n = &(*n)->next) if ((*n)->major == major) break; if (!*n || strcmp((*n)->name, name)) { WARN_ON(1); } else { p = *n; *n = p->next; } mutex_unlock(&block_class_lock); kfree(p); }

Contributors

PersonTokensPropCommitsCommitProp
andrew mortonandrew morton11086.61%228.57%
akinobu mitaakinobu mita86.30%228.57%
christoph hellwigchristoph hellwig53.94%114.29%
jes sorensenjes sorensen21.57%114.29%
kay sieverskay sievers21.57%114.29%
Total127100.00%7100.00%

EXPORT_SYMBOL(unregister_blkdev); static struct kobj_map *bdev_map; /** * blk_mangle_minor - scatter minor numbers apart * @minor: minor number to mangle * * Scatter consecutively allocated @minor number apart if MANGLE_DEVT * is enabled. Mangling twice gives the original value. * * RETURNS: * Mangled value. * * CONTEXT: * Don't care. */
static int blk_mangle_minor(int minor) { #ifdef CONFIG_DEBUG_BLOCK_EXT_DEVT int i; for (i = 0; i < MINORBITS / 2; i++) { int low = minor & (1 << i); int high = minor & (1 << (MINORBITS - 1 - i)); int distance = MINORBITS - 1 - 2 * i; minor ^= low | high; /* clear both bits */ low <<= distance; /* swap the positions */ high >>= distance; minor |= low | high; /* and set */ } #endif return minor; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo99100.00%1100.00%
Total99100.00%1100.00%

/** * blk_alloc_devt - allocate a dev_t for a partition * @part: partition to allocate dev_t for * @devt: out parameter for resulting dev_t * * Allocate a dev_t for block device. * * RETURNS: * 0 on success, allocated dev_t is returned in *@devt. -errno on * failure. * * CONTEXT: * Might sleep. */
int blk_alloc_devt(struct hd_struct *part, dev_t *devt) { struct gendisk *disk = part_to_disk(part); int idx; /* in consecutive minor range? */ if (part->partno < disk->minors) { *devt = MKDEV(disk->major, disk->first_minor + part->partno); return 0; } /* allocate ext devt */ idr_preload(GFP_KERNEL); spin_lock_bh(&ext_devt_lock); idx = idr_alloc(&ext_devt_idr, part, 0, NR_EXT_DEVT, GFP_NOWAIT); spin_unlock_bh(&ext_devt_lock); idr_preload_end(); if (idx < 0) return idx == -ENOSPC ? -EBUSY : idx; *devt = MKDEV(BLOCK_EXT_MAJOR, blk_mangle_minor(idx)); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo11083.97%457.14%
keith buschkeith busch118.40%114.29%
tomas henzltomas henzl86.11%114.29%
dan williamsdan williams21.53%114.29%
Total131100.00%7100.00%

/** * blk_free_devt - free a dev_t * @devt: dev_t to free * * Free @devt which was allocated using blk_alloc_devt(). * * CONTEXT: * Might sleep. */
void blk_free_devt(dev_t devt) { if (devt == MKDEV(0, 0)) return; if (MAJOR(devt) == BLOCK_EXT_MAJOR) { spin_lock_bh(&ext_devt_lock); idr_remove(&ext_devt_idr, blk_mangle_minor(MINOR(devt))); spin_unlock_bh(&ext_devt_lock); } }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo5392.98%250.00%
keith buschkeith busch23.51%125.00%
dan williamsdan williams23.51%125.00%
Total57100.00%4100.00%


static char *bdevt_str(dev_t devt, char *buf) { if (MAJOR(devt) <= 0xff && MINOR(devt) <= 0xff) { char tbuf[BDEVT_SIZE]; snprintf(tbuf, BDEVT_SIZE, "%02x%02x", MAJOR(devt), MINOR(devt)); snprintf(buf, BDEVT_SIZE, "%-9s", tbuf); } else snprintf(buf, BDEVT_SIZE, "%03x:%05x", MAJOR(devt), MINOR(devt)); return buf; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo91100.00%1100.00%
Total91100.00%1100.00%

/* * Register device numbers dev..(dev+range-1) * range must be nonzero * The hash chain is sorted on range, so that subranges can override. */ void blk_register_region(dev_t devt, unsigned long range, struct module *module, struct kobject *(*probe)(dev_t, int *, void *), int (*lock)(dev_t, void *), void *data) { kobj_map(bdev_map, devt, range, module, probe, lock, data); } EXPORT_SYMBOL(blk_register_region);
void blk_unregister_region(dev_t devt, unsigned long range) { kobj_unmap(bdev_map, devt, range); }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro1990.48%266.67%
kay sieverskay sievers29.52%133.33%
Total21100.00%3100.00%

EXPORT_SYMBOL(blk_unregister_region);
static struct kobject *exact_match(dev_t devt, int *partno, void *data) { struct gendisk *p = data; return &disk_to_dev(p)->kobj; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro3085.71%457.14%
tejun heotejun heo411.43%228.57%
kay sieverskay sievers12.86%114.29%
Total35100.00%7100.00%


static int exact_lock(dev_t devt, void *data) { struct gendisk *p = data; if (!get_disk(p)) return -1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
al viroal viro3497.14%266.67%
kay sieverskay sievers12.86%133.33%
Total35100.00%3100.00%


static void register_disk(struct gendisk *disk) { struct device *ddev = disk_to_dev(disk); struct block_device *bdev; struct disk_part_iter piter; struct hd_struct *part; int err; ddev->parent = disk->driverfs_dev; dev_set_name(ddev, "%s", disk->disk_name); /* delay uevents, until we scanned partition table */ dev_set_uevent_suppress(ddev, 1); if (device_add(ddev)) return; if (!sysfs_deprecated) { err = sysfs_create_link(block_depr, &ddev->kobj, kobject_name(&ddev->kobj)); if (err) { device_del(ddev); return; } } /* * avoid probable deadlock caused by allocating memory with * GFP_KERNEL in runtime_resume callback of its all ancestor * devices */ pm_runtime_set_memalloc_noio(ddev, true); disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj); disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj); /* No minors to use for partitions */ if (!disk_part_scan_enabled(disk)) goto exit; /* No such device (e.g., media were just removed) */ if (!get_capacity(disk)) goto exit; bdev = bdget_disk(disk, 0); if (!bdev) goto exit; bdev->bd_invalidated = 1; err = blkdev_get(bdev, FMODE_READ, NULL); if (err < 0) goto exit; blkdev_put(bdev, FMODE_READ); exit: /* announce disk after possible partitions are created */ dev_set_uevent_suppress(ddev, 0); kobject_uevent(&ddev->kobj, KOBJ_ADD); /* announce possible partitions */ disk_part_iter_init(&piter, disk, 0); while ((part = disk_part_iter_next(&piter))) kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD); disk_part_iter_exit(&piter); }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo22277.62%423.53%
al viroal viro206.99%529.41%
peter zijlstrapeter zijlstra124.20%15.88%
linus torvaldslinus torvalds93.15%211.76%
ming leiming lei82.80%15.88%
jan karajan kara62.10%15.88%
greg kroah-hartmangreg kroah-hartman41.40%15.88%
jens axboejens axboe31.05%15.88%
kees cookkees cook20.70%15.88%
Total286100.00%17100.00%

/** * add_disk - add partitioning information to kernel list * @disk: per-device partitioning information * * This function registers the partitioning information in @disk * with the kernel. * * FIXME: error handling */
void add_disk(struct gendisk *disk) { struct backing_dev_info *bdi; dev_t devt; int retval; /* minors == 0 indicates to use ext devt from part0 and should * be accompanied with EXT_DEVT flag. Make sure all * parameters make sense. */ WARN_ON(disk->minors && !(disk->major || disk->first_minor)); WARN_ON(!disk->minors && !(disk->flags & GENHD_FL_EXT_DEVT)); disk->flags |= GENHD_FL_UP; retval = blk_alloc_devt(&disk->part0, &devt); if (retval) { WARN_ON(1); return; } disk_to_dev(disk)->devt = devt; /* ->major and ->first_minor aren't supposed to be * dereferenced from here on, but set them just in case. */ disk->major = MAJOR(devt); disk->first_minor = MINOR(devt); disk_alloc_events(disk); /* Register BDI before referencing it from bdev */ bdi = &disk->queue->backing_dev_info; bdi_register_dev(bdi, disk_devt(disk)); blk_register_region(disk_devt(disk), disk->minors, NULL, exact_match, exact_lock, disk); register_disk(disk); 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. */ WARN_ON_ONCE(!blk_get_queue(disk->queue)); retval = sysfs_create_link(&disk_to_dev(disk)->kobj, &bdi->dev->kobj, "bdi"); WARN_ON(retval); disk_add_events(disk); blk_integrity_add(disk); }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo11150.45%933.33%
al viroal viro3716.82%725.93%
peter zijlstrapeter zijlstra2410.91%13.70%
jan karajan kara146.36%13.70%
linus torvaldslinus torvalds94.09%27.41%
greg kroah-hartmangreg kroah-hartman73.18%13.70%
stanislaw gruszkastanislaw gruszka52.27%13.70%
martin k. petersenmartin k. petersen52.27%13.70%
jens axboejens axboe31.36%13.70%
kay sieverskay sievers20.91%13.70%
divyesh shahdivyesh shah20.91%13.70%
andrew mortonandrew morton10.45%13.70%
Total220100.00%27100.00%

EXPORT_SYMBOL(add_disk);
void del_gendisk(struct gendisk *disk) { struct disk_part_iter piter; struct hd_struct *part; blk_integrity_del(disk); disk_del_events(disk); /* invalidate stuff */ disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE); while ((part = disk_part_iter_next(&piter))) { invalidate_partition(disk, part->partno); delete_partition(disk, part->partno); } disk_part_iter_exit(&piter); invalidate_partition(disk, 0); set_capacity(disk, 0); disk->flags &= ~GENHD_FL_UP; sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi"); blk_unregister_queue(disk); blk_unregister_region(disk_devt(disk), disk->minors); part_stat_set_all(&disk->part0, 0); disk->part0.stamp = 0; kobject_put(disk->part0.holder_dir); kobject_put(disk->slave_dir); if (!sysfs_deprecated) sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk))); pm_runtime_set_memalloc_noio(disk_to_dev(disk), false); device_del(disk_to_dev(disk)); }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo12863.68%738.89%
david alan gilbertdavid alan gilbert2612.94%15.56%
ming leiming lei104.98%15.56%
will drewrywill drewry83.98%15.56%
peter zijlstrapeter zijlstra73.48%15.56%
martin k. petersenmartin k. petersen52.49%15.56%
al viroal viro52.49%15.56%
linus torvaldslinus torvalds52.49%211.11%
greg kroah-hartmangreg kroah-hartman31.49%15.56%
jens axboejens axboe31.49%15.56%
andrew mortonandrew morton10.50%15.56%
Total201100.00%18100.00%

EXPORT_SYMBOL(del_gendisk); /* sysfs access to bad-blocks list. */
static ssize_t disk_badblocks_show(struct device *dev, struct device_attribute *attr, char *page) { struct gendisk *disk = dev_to_disk(dev); if (!disk->bb) return sprintf(page, "\n"); return badblocks_show(disk->bb, page, 0); }

Contributors

PersonTokensPropCommitsCommitProp
vishal vermavishal verma57100.00%1100.00%
Total57100.00%1100.00%


static ssize_t disk_badblocks_store(struct device *dev, struct device_attribute *attr, const char *page, size_t len) { struct gendisk *disk = dev_to_disk(dev); if (!disk->bb) return -ENXIO; return badblocks_store(disk->bb, page, len, 0); }

Contributors

PersonTokensPropCommitsCommitProp
vishal vermavishal verma59100.00%1100.00%
Total59100.00%1100.00%

/** * get_gendisk - get partitioning information for a given device * @devt: device to get partitioning information for * @partno: returned partition index * * This function gets the structure containing partitioning * information for the given device @devt. */
struct gendisk *get_gendisk(dev_t devt, int *partno) { struct gendisk *disk = NULL; if (MAJOR(devt) != BLOCK_EXT_MAJOR) { struct kobject *kobj; kobj = kobj_lookup(bdev_map, devt, partno); if (kobj) disk = dev_to_disk(kobj_to_dev(kobj)); } else { struct hd_struct *part; spin_lock_bh(&ext_devt_lock); part = idr_find(&ext_devt_idr, blk_mangle_minor(MINOR(devt))); if (part && get_disk(part_to_disk(part))) { *partno = part->partno; disk = part_to_disk(part); } spin_unlock_bh(&ext_devt_lock); } return disk; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo8465.12%527.78%
greg kroah-hartmangreg kroah-hartman1511.63%211.11%
al viroal viro118.53%527.78%
kay sieverskay sievers75.43%15.56%
linus torvaldslinus torvalds43.10%15.56%
dave jonesdave jones32.33%15.56%
keith buschkeith busch21.55%15.56%
dan williamsdan williams21.55%15.56%
harvey harrisonharvey harrison10.78%15.56%
Total129100.00%18100.00%

EXPORT_SYMBOL(get_gendisk); /** * bdget_disk - do bdget() by gendisk and partition number * @disk: gendisk of interest * @partno: partition number * * Find partition @partno from @disk, do bdget() on it. * * CONTEXT: * Don't care. * * RETURNS: * Resulting block_device on success, NULL on failure. */
struct block_device *bdget_disk(struct gendisk *disk, int partno) { struct hd_struct *part; struct block_device *bdev = NULL; part = disk_get_part(disk, partno); if (part) bdev = bdget(part_devt(part)); disk_put_part(part); return bdev; }

Contributors

PersonTokensPropCommitsCommitProp
tejun heotejun heo3560.34%444.44%
kay sieverskay sievers915.52%222.22%
dave jonesdave jones712.07%111.11%
al viroal viro46.90%111.11%
greg kroah-hartmangreg kroah-hartman35.17%111.11%
Total58100.00%9100.00%

EXPORT_SYMBOL(bdget_disk); /* * print a full list of all partitions - intended for places where the root * filesystem can't be mounted and thus to give the victim some idea of what * went wrong */
void __init printk_all_partitions(void) { struct class_dev_iter iter; struct device *dev; class_dev_iter_init(&iter, &block_class, NULL, &disk_type); while ((dev = class_dev_iter_next(&iter))) { struct gendisk *disk = dev_to_disk