block: embed bdevname in struct block_device
RFC PATCH 1/2 block: embed bdevname in struct block_device
Embed block device name in struct block_device, thus we can replace the following code:
char b[BDEVNAME_SIZE]; printk(KERN_XXX "...%s..\n", bdevname(bdev, b);
with a much simpler and less stack usage version:
printk(KERN_XXX "...%s..\n", bdev->bd_name);
This is a RFC version, which I just included one sample with this change appiled. If this patch makes sense to you, I will file more patches to apply this change.
--- fs/block_dev.c | 2 ++ include/linux/fs.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletions(-)
fs/block_dev.c +2 -0
@@ -1213,6 +1213,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) }bd_set_size (bdev, (loff_t )bdev->bd_part->nr_sects <<9 ); } + +disk_name (bdev->bd_disk, bdev->bd_part->partno, bdev->bd_name); }else {if (bdev->bd_contains == bdev) { ret =0 ;
include/linux/fs.h +2 -1
@@ -689,6 +689,7 @@ struct address_space {*/ struct request_queue ; +#define BDEVNAME_SIZE 32/* Largest string for a blockdev identifier */ struct block_device {dev_t bd_dev;/* not a kdev_t - it's a search key */ int bd_openers;
@@ -724,6 +725,7 @@ struct block_device {int bd_fsfreeze_count;/* Mutex for freeze */ struct mutex bd_fsfreeze_mutex; +char bd_name[BDEVNAME_SIZE ]; };/*
@@ -2323,7 +2325,6 @@ static inline void unregister_chrdev(unsigned int major, const char *name) }/* fs/block_dev.c */ -#define BDEVNAME_SIZE 32/* Largest string for a blockdev identifier */ #define BDEVT_SIZE 10/* Largest string for MAJ:MIN for blkdev */ #ifdef CONFIG_BLOCK
Signature · 1 line
1.7.7.6
RFC PATCH 2/2 vfs: replace bdevname(bdev, b) with bdev->bd_name
Since we embeded block device name into struct block_device, we don't need call a function bdevname() to get the name any more.
Here this patch replace all the code using bdevname() in vfs layer to bdev->bd_name.
This patch servers as an example of using embeded block device name. It makes the code a little cleaner and a bit smaller stack usage. If this change is OK to you, I will file more patches to apply this change to all other codes.
--- fs/buffer.c | 27 ++++++++------------------- fs/super.c | 4 +--- 2 files changed, 9 insertions(+), 22 deletions(-)
fs/buffer.c +8 -19
@@ -105,9 +105,8 @@ static int quiet_error(struct buffer_head *bh)static void buffer_io_error (struct buffer_head *bh) { -char b[BDEVNAME_SIZE ];printk (KERN_ERR "Buffer I/O error on device %s, logical block %Lu\n" , -bdevname (bh->b_bdev, b), + bh->b_bdev->bd_name, (unsigned long long )bh->b_blocknr); }
@@ -143,16 +142,13 @@ EXPORT_SYMBOL(end_buffer_read_sync);void end_buffer_write_sync (struct buffer_head *bh,int uptodate) { -char b[BDEVNAME_SIZE ]; -if (uptodate) {set_buffer_uptodate (bh); }else {if (!quiet_error (bh)) {buffer_io_error (bh); -printk (KERN_WARNING "lost page write due to " -"I/O error on %s\n" , -bdevname (bh->b_bdev, b)); +printk (KERN_WARNING "lost page write due to I/O error " +"on %s\n" , bh->b_bdev->bd_name); }set_buffer_write_io_error (bh);clear_buffer_uptodate (bh);
@@ -212,15 +208,13 @@ __find_get_block_slow(struct block_device *bdev, sector_t block)* elsewhere, don't buffer_error if we had some unmapped buffers */ if (all_mapped) { -char b[BDEVNAME_SIZE ]; -printk ("__find_get_block_slow() failed. " "block=%llu, b_blocknr=%llu\n" , (unsigned long long )block, (unsigned long long )bh->b_blocknr);printk ("b_state=0x%08lx, b_size=%zu\n" , bh->b_state, bh->b_size); -printk ("device %s blocksize: %d\n" ,bdevname (bdev, b), +printk ("device %s blocksize: %d\n" , bdev->bd_name,1 << bd_inode->i_blkbits); } out_unlock:
@@ -319,7 +313,6 @@ still_busy:*/ void end_buffer_async_write (struct buffer_head *bh,int uptodate) { -char b[BDEVNAME_SIZE ];unsigned long flags;struct buffer_head *first;struct buffer_head *tmp;
@@ -333,9 +326,8 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) }else {if (!quiet_error (bh)) {buffer_io_error (bh); -printk (KERN_WARNING "lost page write due to " -"I/O error on %s\n" , -bdevname (bh->b_bdev, b)); +printk (KERN_WARNING "lost page write due to I/O error " +"on %s\n" , bh->b_bdev->bd_name); }set_bit (AS_EIO , &page->mapping->flags);set_buffer_write_io_error (bh);
@@ -513,10 +505,9 @@ repeat:static void do_thaw_one (struct super_block *sb,void *unused) { -char b[BDEVNAME_SIZE ];while (sb->s_bdev && !thaw_bdev (sb->s_bdev, sb))printk (KERN_WARNING "Emergency Thaw on %s\n" , -bdevname (sb->s_bdev, b)); + sb->s_bdev->bd_name); }static void do_thaw_all (struct work_struct *work)
@@ -1015,12 +1006,10 @@ grow_buffers(struct block_device *bdev, sector_t block, int size)* pagecache index. (this comparison is done using sector_t types). */ if (unlikely (index != block >> sizebits)) { -char b[BDEVNAME_SIZE ]; -printk (KERN_ERR "%s: requested out-of-range block %llu for " "device %s\n" , __func__, (unsigned long long )block, -bdevname (bdev, b)); + bdev->bd_name);return -EIO ; } block = index << sizebits;
fs/super.c +1 -3
@@ -1029,10 +1029,8 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,blkdev_put (bdev, mode);down_write (&s->s_umount); }else { -char b[BDEVNAME_SIZE ]; - s->s_mode = mode; -strlcpy (s->s_id,bdevname (bdev, b),sizeof (s->s_id)); +strlcpy (s->s_id, bdev->bd_name,sizeof (s->s_id));sb_set_blocksize (s,block_size (bdev)); error =fill_super (s, data, flags &MS_SILENT ?1 :0 );if (error) {
Signature · 1 line
1.7.7.6
Quoted 11 lines · Yuanhan Liu
Embed block device name in struct
block_device, thus we can replace the following code:char b[BDEVNAME_SIZE]; printk(KERN_XXX "...%s..\n", bdevname(bdev, b);with a much simpler and less stack usage version:
printk(KERN_XXX "...%s..\n", bdev->bd_name);This is a RFC version, which I just included one sample with this change appiled. If this patch makes sense to you, I will file more patches to apply this change.
ping... (though it's a trivial RFC patch)
Thanks,
Yuanhan Liu
Quoted 53 lines
Cc Alexander Viro <[email protected]>Cc Jens Axboe <[email protected]>Cc Andrew Morton <[email protected]>Signed-off-by Yuanhan Liu <[email protected]>--- fs/block_dev.c | 2 ++ include/linux/fs.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletions(-)fs/block_dev.c +2
-0@@ -1213,6 +1213,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) }bd_set_size (bdev, (loff_t )bdev->bd_part->nr_sects <<9 ); } + +disk_name (bdev->bd_disk, bdev->bd_part->partno, bdev->bd_name); }else {if (bdev->bd_contains == bdev) { ret =0 ;include/linux/fs.h +2
-1@@ -689,6 +689,7 @@ struct address_space {*/ struct request_queue ; +#define BDEVNAME_SIZE 32/* Largest string for a blockdev identifier */ struct block_device {dev_t bd_dev;/* not a kdev_t - it's a search key */ int bd_openers;@@ -724,6 +725,7 @@ struct block_device {int bd_fsfreeze_count;/* Mutex for freeze */ struct mutex bd_fsfreeze_mutex; +char bd_name[BDEVNAME_SIZE ]; };/* @@ -2323,7 +2325,6 @@ static inline void unregister_chrdev(unsigned int major, const char *name) }/* fs/block_dev.c */ -#define BDEVNAME_SIZE 32/* Largest string for a blockdev identifier */ #define BDEVT_SIZE 10/* Largest string for MAJ:MIN for blkdev */ #ifdef CONFIG_BLOCK Signature · 1 line
1.7.7.6