block: make variable and argument names more consistent

In hd_struct, @partno is used to denote partition number and a number
of other places use @part to denote hd_struct.  Functions use @part
and @index instead.  This causes confusion and makes it difficult to
use consistent variable names for hd_struct.  Always use @partno if a
variable represents partition number.

Also, print out functions use @f or @part for seq_file argument.  Use
@seqf uniformly instead.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
This commit is contained in:
Tejun Heo 2008-09-03 09:01:09 +02:00 committed by Jens Axboe
parent 310a2c1012
commit cf771cb5a7
5 changed files with 60 additions and 62 deletions

View file

@ -43,14 +43,14 @@ static inline int major_to_index(int major)
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
void blkdev_show(struct seq_file *f, off_t offset) void blkdev_show(struct seq_file *seqf, off_t offset)
{ {
struct blk_major_name *dp; struct blk_major_name *dp;
if (offset < BLKDEV_MAJOR_HASH_SIZE) { if (offset < BLKDEV_MAJOR_HASH_SIZE) {
mutex_lock(&block_class_lock); mutex_lock(&block_class_lock);
for (dp = major_names[offset]; dp; dp = dp->next) for (dp = major_names[offset]; dp; dp = dp->next)
seq_printf(f, "%3d %s\n", dp->major, dp->name); seq_printf(seqf, "%3d %s\n", dp->major, dp->name);
mutex_unlock(&block_class_lock); mutex_unlock(&block_class_lock);
} }
} }
@ -157,7 +157,7 @@ void blk_unregister_region(dev_t devt, unsigned long range)
EXPORT_SYMBOL(blk_unregister_region); EXPORT_SYMBOL(blk_unregister_region);
static struct kobject *exact_match(dev_t devt, int *part, void *data) static struct kobject *exact_match(dev_t devt, int *partno, void *data)
{ {
struct gendisk *p = data; struct gendisk *p = data;
@ -217,9 +217,9 @@ void unlink_gendisk(struct gendisk *disk)
* This function gets the structure containing partitioning * This function gets the structure containing partitioning
* information for the given device @devt. * information for the given device @devt.
*/ */
struct gendisk *get_gendisk(dev_t devt, int *part) struct gendisk *get_gendisk(dev_t devt, int *partno)
{ {
struct kobject *kobj = kobj_lookup(bdev_map, devt, part); struct kobject *kobj = kobj_lookup(bdev_map, devt, partno);
struct device *dev = kobj_to_dev(kobj); struct device *dev = kobj_to_dev(kobj);
return kobj ? dev_to_disk(dev) : NULL; return kobj ? dev_to_disk(dev) : NULL;
@ -336,23 +336,12 @@ static void *show_partition_start(struct seq_file *seqf, loff_t *pos)
return p; return p;
} }
static int show_partition(struct seq_file *part, void *v) static int show_partition(struct seq_file *seqf, void *v)
{ {
struct gendisk *sgp = v; struct gendisk *sgp = v;
int n; int n;
char buf[BDEVNAME_SIZE]; char buf[BDEVNAME_SIZE];
/*
* Print header if start told us to do. This is to preserve
* the original behavior of not printing header if no
* partition exists. This hackery will be removed later with
* class iteration clean up.
*/
if (part->private) {
seq_puts(part, "major minor #blocks name\n\n");
part->private = NULL;
}
/* Don't show non-partitionable removeable devices or empty devices */ /* Don't show non-partitionable removeable devices or empty devices */
if (!get_capacity(sgp) || if (!get_capacity(sgp) ||
(sgp->minors == 1 && (sgp->flags & GENHD_FL_REMOVABLE))) (sgp->minors == 1 && (sgp->flags & GENHD_FL_REMOVABLE)))
@ -361,7 +350,7 @@ static int show_partition(struct seq_file *part, void *v)
return 0; return 0;
/* show the full disk and all non-0 size partitions of it */ /* show the full disk and all non-0 size partitions of it */
seq_printf(part, "%4d %4d %10llu %s\n", seq_printf(seqf, "%4d %4d %10llu %s\n",
sgp->major, sgp->first_minor, sgp->major, sgp->first_minor,
(unsigned long long)get_capacity(sgp) >> 1, (unsigned long long)get_capacity(sgp) >> 1,
disk_name(sgp, 0, buf)); disk_name(sgp, 0, buf));
@ -370,7 +359,7 @@ static int show_partition(struct seq_file *part, void *v)
continue; continue;
if (sgp->part[n]->nr_sects == 0) if (sgp->part[n]->nr_sects == 0)
continue; continue;
seq_printf(part, "%4d %4d %10llu %s\n", seq_printf(seqf, "%4d %4d %10llu %s\n",
sgp->major, n + 1 + sgp->first_minor, sgp->major, n + 1 + sgp->first_minor,
(unsigned long long)sgp->part[n]->nr_sects >> 1 , (unsigned long long)sgp->part[n]->nr_sects >> 1 ,
disk_name(sgp, n + 1, buf)); disk_name(sgp, n + 1, buf));
@ -388,7 +377,7 @@ const struct seq_operations partitions_op = {
#endif #endif
static struct kobject *base_probe(dev_t devt, int *part, void *data) static struct kobject *base_probe(dev_t devt, int *partno, void *data)
{ {
if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0) if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0)
/* Make old-style 2.4 aliases work */ /* Make old-style 2.4 aliases work */
@ -564,7 +553,14 @@ static struct device_type disk_type = {
}; };
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int diskstats_show(struct seq_file *s, void *v) /*
* aggregate disk stat collector. Uses the same stats that the sysfs
* entries do, above, but makes them available through one seq_file.
*
* The output looks suspiciously like /proc/partitions with a bunch of
* extra fields.
*/
static int diskstats_show(struct seq_file *seqf, void *v)
{ {
struct gendisk *gp = v; struct gendisk *gp = v;
char buf[BDEVNAME_SIZE]; char buf[BDEVNAME_SIZE];
@ -572,7 +568,7 @@ static int diskstats_show(struct seq_file *s, void *v)
/* /*
if (&gp->dev.kobj.entry == block_class.devices.next) if (&gp->dev.kobj.entry == block_class.devices.next)
seq_puts(s, "major minor name" seq_puts(seqf, "major minor name"
" rio rmerge rsect ruse wio wmerge " " rio rmerge rsect ruse wio wmerge "
"wsect wuse running use aveq" "wsect wuse running use aveq"
"\n\n"); "\n\n");
@ -581,7 +577,7 @@ static int diskstats_show(struct seq_file *s, void *v)
preempt_disable(); preempt_disable();
disk_round_stats(gp); disk_round_stats(gp);
preempt_enable(); preempt_enable();
seq_printf(s, "%4d %4d %s %lu %lu %llu %u %lu %lu %llu %u %u %u %u\n", seq_printf(seqf, "%4d %4d %s %lu %lu %llu %u %lu %lu %llu %u %u %u %u\n",
gp->major, gp->first_minor, disk_name(gp, 0, buf), gp->major, gp->first_minor, disk_name(gp, 0, buf),
disk_stat_read(gp, ios[0]), disk_stat_read(gp, merges[0]), disk_stat_read(gp, ios[0]), disk_stat_read(gp, merges[0]),
(unsigned long long)disk_stat_read(gp, sectors[0]), (unsigned long long)disk_stat_read(gp, sectors[0]),
@ -603,7 +599,7 @@ static int diskstats_show(struct seq_file *s, void *v)
preempt_disable(); preempt_disable();
part_round_stats(hd); part_round_stats(hd);
preempt_enable(); preempt_enable();
seq_printf(s, "%4d %4d %s %lu %lu %llu " seq_printf(seqf, "%4d %4d %s %lu %lu %llu "
"%u %lu %lu %llu %u %u %u %u\n", "%u %lu %lu %llu %u %u %u %u\n",
gp->major, n + gp->first_minor + 1, gp->major, n + gp->first_minor + 1,
disk_name(gp, n + 1, buf), disk_name(gp, n + 1, buf),
@ -655,7 +651,7 @@ void genhd_media_change_notify(struct gendisk *disk)
EXPORT_SYMBOL_GPL(genhd_media_change_notify); EXPORT_SYMBOL_GPL(genhd_media_change_notify);
#endif /* 0 */ #endif /* 0 */
dev_t blk_lookup_devt(const char *name, int part) dev_t blk_lookup_devt(const char *name, int partno)
{ {
dev_t devt = MKDEV(0, 0); dev_t devt = MKDEV(0, 0);
struct class_dev_iter iter; struct class_dev_iter iter;
@ -665,9 +661,9 @@ dev_t blk_lookup_devt(const char *name, int part)
while ((dev = class_dev_iter_next(&iter))) { while ((dev = class_dev_iter_next(&iter))) {
struct gendisk *disk = dev_to_disk(dev); struct gendisk *disk = dev_to_disk(dev);
if (!strcmp(dev->bus_id, name) && part < disk->minors) { if (!strcmp(dev->bus_id, name) && partno < disk->minors) {
devt = MKDEV(MAJOR(dev->devt), devt = MKDEV(MAJOR(dev->devt),
MINOR(dev->devt) + part); MINOR(dev->devt) + partno);
break; break;
} }
} }
@ -777,10 +773,10 @@ int bdev_read_only(struct block_device *bdev)
EXPORT_SYMBOL(bdev_read_only); EXPORT_SYMBOL(bdev_read_only);
int invalidate_partition(struct gendisk *disk, int index) int invalidate_partition(struct gendisk *disk, int partno)
{ {
int res = 0; int res = 0;
struct block_device *bdev = bdget_disk(disk, index); struct block_device *bdev = bdget_disk(disk, partno);
if (bdev) { if (bdev) {
fsync_bdev(bdev); fsync_bdev(bdev);
res = __invalidate_device(bdev); res = __invalidate_device(bdev);

View file

@ -15,7 +15,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
struct blkpg_ioctl_arg a; struct blkpg_ioctl_arg a;
struct blkpg_partition p; struct blkpg_partition p;
long long start, length; long long start, length;
int part; int partno;
int i; int i;
int err; int err;
@ -28,8 +28,8 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
disk = bdev->bd_disk; disk = bdev->bd_disk;
if (bdev != bdev->bd_contains) if (bdev != bdev->bd_contains)
return -EINVAL; return -EINVAL;
part = p.pno; partno = p.pno;
if (part <= 0 || part >= disk->minors) if (partno <= 0 || partno >= disk->minors)
return -EINVAL; return -EINVAL;
switch (a.op) { switch (a.op) {
case BLKPG_ADD_PARTITION: case BLKPG_ADD_PARTITION:
@ -59,13 +59,14 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
} }
} }
/* all seems OK */ /* all seems OK */
err = add_partition(disk, part, start, length, ADDPART_FLAG_NONE); err = add_partition(disk, partno, start, length,
ADDPART_FLAG_NONE);
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
return err; return err;
case BLKPG_DEL_PARTITION: case BLKPG_DEL_PARTITION:
if (!disk->part[part-1]) if (!disk->part[partno - 1])
return -ENXIO; return -ENXIO;
bdevp = bdget_disk(disk, part); bdevp = bdget_disk(disk, partno);
if (!bdevp) if (!bdevp)
return -ENOMEM; return -ENOMEM;
mutex_lock(&bdevp->bd_mutex); mutex_lock(&bdevp->bd_mutex);
@ -79,7 +80,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
invalidate_bdev(bdevp); invalidate_bdev(bdevp);
mutex_lock_nested(&bdev->bd_mutex, 1); mutex_lock_nested(&bdev->bd_mutex, 1);
delete_partition(disk, part); delete_partition(disk, partno);
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
mutex_unlock(&bdevp->bd_mutex); mutex_unlock(&bdevp->bd_mutex);
bdput(bdevp); bdput(bdevp);

View file

@ -930,7 +930,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
struct module *owner = NULL; struct module *owner = NULL;
struct gendisk *disk; struct gendisk *disk;
int ret; int ret;
int part; int partno;
int perm = 0; int perm = 0;
if (file->f_mode & FMODE_READ) if (file->f_mode & FMODE_READ)
@ -949,7 +949,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
ret = -ENXIO; ret = -ENXIO;
file->f_mapping = bdev->bd_inode->i_mapping; file->f_mapping = bdev->bd_inode->i_mapping;
lock_kernel(); lock_kernel();
disk = get_gendisk(bdev->bd_dev, &part); disk = get_gendisk(bdev->bd_dev, &partno);
if (!disk) { if (!disk) {
unlock_kernel(); unlock_kernel();
bdput(bdev); bdput(bdev);
@ -961,7 +961,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
if (!bdev->bd_openers) { if (!bdev->bd_openers) {
bdev->bd_disk = disk; bdev->bd_disk = disk;
bdev->bd_contains = bdev; bdev->bd_contains = bdev;
if (!part) { if (!partno) {
struct backing_dev_info *bdi; struct backing_dev_info *bdi;
if (disk->fops->open) { if (disk->fops->open) {
ret = disk->fops->open(bdev->bd_inode, file); ret = disk->fops->open(bdev->bd_inode, file);
@ -989,7 +989,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
if (ret) if (ret)
goto out_first; goto out_first;
bdev->bd_contains = whole; bdev->bd_contains = whole;
p = disk->part[part - 1]; p = disk->part[partno - 1];
bdev->bd_inode->i_data.backing_dev_info = bdev->bd_inode->i_data.backing_dev_info =
whole->bd_inode->i_data.backing_dev_info; whole->bd_inode->i_data.backing_dev_info;
if (!(disk->flags & GENHD_FL_UP) || !p || !p->nr_sects) { if (!(disk->flags & GENHD_FL_UP) || !p || !p->nr_sects) {

View file

@ -120,22 +120,22 @@ static int (*check_part[])(struct parsed_partitions *, struct block_device *) =
* a pointer to that same buffer (for convenience). * a pointer to that same buffer (for convenience).
*/ */
char *disk_name(struct gendisk *hd, int part, char *buf) char *disk_name(struct gendisk *hd, int partno, char *buf)
{ {
if (!part) if (!partno)
snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name); snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, part); snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, partno);
else else
snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, part); snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, partno);
return buf; return buf;
} }
const char *bdevname(struct block_device *bdev, char *buf) const char *bdevname(struct block_device *bdev, char *buf)
{ {
int part = MINOR(bdev->bd_dev) - bdev->bd_disk->first_minor; int partno = MINOR(bdev->bd_dev) - bdev->bd_disk->first_minor;
return disk_name(bdev->bd_disk, part, buf); return disk_name(bdev->bd_disk, partno, buf);
} }
EXPORT_SYMBOL(bdevname); EXPORT_SYMBOL(bdevname);
@ -310,13 +310,13 @@ static inline void disk_sysfs_add_subdirs(struct gendisk *disk)
kobject_put(k); kobject_put(k);
} }
void delete_partition(struct gendisk *disk, int part) void delete_partition(struct gendisk *disk, int partno)
{ {
struct hd_struct *p = disk->part[part-1]; struct hd_struct *p = disk->part[partno - 1];
if (!p) if (!p)
return; return;
disk->part[part-1] = NULL; disk->part[partno - 1] = NULL;
p->start_sect = 0; p->start_sect = 0;
p->nr_sects = 0; p->nr_sects = 0;
part_stat_set_all(p, 0); part_stat_set_all(p, 0);
@ -333,12 +333,13 @@ static ssize_t whole_disk_show(struct device *dev,
static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH, static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH,
whole_disk_show, NULL); whole_disk_show, NULL);
int add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags) int add_partition(struct gendisk *disk, int partno,
sector_t start, sector_t len, int flags)
{ {
struct hd_struct *p; struct hd_struct *p;
int err; int err;
if (disk->part[part - 1]) if (disk->part[partno - 1])
return -EBUSY; return -EBUSY;
p = kzalloc(sizeof(*p), GFP_KERNEL); p = kzalloc(sizeof(*p), GFP_KERNEL);
@ -351,18 +352,18 @@ int add_partition(struct gendisk *disk, int part, sector_t start, sector_t len,
} }
p->start_sect = start; p->start_sect = start;
p->nr_sects = len; p->nr_sects = len;
p->partno = part; p->partno = partno;
p->policy = disk->policy; p->policy = disk->policy;
if (isdigit(disk->dev.bus_id[strlen(disk->dev.bus_id)-1])) if (isdigit(disk->dev.bus_id[strlen(disk->dev.bus_id)-1]))
snprintf(p->dev.bus_id, BUS_ID_SIZE, snprintf(p->dev.bus_id, BUS_ID_SIZE,
"%sp%d", disk->dev.bus_id, part); "%sp%d", disk->dev.bus_id, partno);
else else
snprintf(p->dev.bus_id, BUS_ID_SIZE, snprintf(p->dev.bus_id, BUS_ID_SIZE,
"%s%d", disk->dev.bus_id, part); "%s%d", disk->dev.bus_id, partno);
device_initialize(&p->dev); device_initialize(&p->dev);
p->dev.devt = MKDEV(disk->major, disk->first_minor + part); p->dev.devt = MKDEV(disk->major, disk->first_minor + partno);
p->dev.class = &block_class; p->dev.class = &block_class;
p->dev.type = &part_type; p->dev.type = &part_type;
p->dev.parent = &disk->dev; p->dev.parent = &disk->dev;
@ -386,7 +387,7 @@ int add_partition(struct gendisk *disk, int part, sector_t start, sector_t len,
} }
/* everything is up and running, commence */ /* everything is up and running, commence */
disk->part[part - 1] = p; disk->part[partno - 1] = p;
/* suppress uevent if the disk supresses it */ /* suppress uevent if the disk supresses it */
if (!disk->dev.uevent_suppress) if (!disk->dev.uevent_suppress)

View file

@ -365,7 +365,7 @@ extern int get_blkdev_list(char *, int);
extern void add_disk(struct gendisk *disk); extern void add_disk(struct gendisk *disk);
extern void del_gendisk(struct gendisk *gp); extern void del_gendisk(struct gendisk *gp);
extern void unlink_gendisk(struct gendisk *gp); extern void unlink_gendisk(struct gendisk *gp);
extern struct gendisk *get_gendisk(dev_t dev, int *part); extern struct gendisk *get_gendisk(dev_t dev, int *partno);
extern void set_device_ro(struct block_device *bdev, int flag); extern void set_device_ro(struct block_device *bdev, int flag);
extern void set_disk_ro(struct gendisk *disk, int flag); extern void set_disk_ro(struct gendisk *disk, int flag);
@ -534,8 +534,8 @@ struct unixware_disklabel {
#define ADDPART_FLAG_RAID 1 #define ADDPART_FLAG_RAID 1
#define ADDPART_FLAG_WHOLEDISK 2 #define ADDPART_FLAG_WHOLEDISK 2
extern dev_t blk_lookup_devt(const char *name, int part); extern dev_t blk_lookup_devt(const char *name, int partno);
extern char *disk_name (struct gendisk *hd, int part, char *buf); extern char *disk_name (struct gendisk *hd, int partno, char *buf);
extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev); extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
extern int __must_check add_partition(struct gendisk *, int, sector_t, sector_t, int); extern int __must_check add_partition(struct gendisk *, int, sector_t, sector_t, int);
@ -553,16 +553,16 @@ extern void blk_register_region(dev_t devt, unsigned long range,
void *data); void *data);
extern void blk_unregister_region(dev_t devt, unsigned long range); extern void blk_unregister_region(dev_t devt, unsigned long range);
static inline struct block_device *bdget_disk(struct gendisk *disk, int index) static inline struct block_device *bdget_disk(struct gendisk *disk, int partno)
{ {
return bdget(MKDEV(disk->major, disk->first_minor) + index); return bdget(MKDEV(disk->major, disk->first_minor) + partno);
} }
#else /* CONFIG_BLOCK */ #else /* CONFIG_BLOCK */
static inline void printk_all_partitions(void) { } static inline void printk_all_partitions(void) { }
static inline dev_t blk_lookup_devt(const char *name, int part) static inline dev_t blk_lookup_devt(const char *name, int partno)
{ {
dev_t devt = MKDEV(0, 0); dev_t devt = MKDEV(0, 0);
return devt; return devt;