2012-08-13 10:33:54

by Yuanhan Liu

[permalink] [raw]
Subject: [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.

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(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 1e51919..5e796e58 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -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;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index aa11047..98ea89d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -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
--
1.7.7.6


2012-08-13 10:33:55

by Yuanhan Liu

[permalink] [raw]
Subject: [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.

Cc: Alexander Viro <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Andrew Morton <[email protected]>
Signed-off-by: Yuanhan Liu <[email protected]>
---
fs/buffer.c | 27 ++++++++-------------------
fs/super.c | 4 +---
2 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 9f6d2e4..79cec42 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -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;
diff --git a/fs/super.c b/fs/super.c
index 0902cfa..1b9c2fd 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -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) {
--
1.7.7.6

2012-08-22 09:28:41

by Yuanhan Liu

[permalink] [raw]
Subject: Re: [RFC PATCH 1/2] block: embed bdevname in struct block_device

On Mon, Aug 13, 2012 at 06:33:59PM +0800, Yuanhan Liu wrote:
> 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
>
> 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(-)
>
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 1e51919..5e796e58 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -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;
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index aa11047..98ea89d 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -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
> --
> 1.7.7.6