nbd: some trivial improvements
Subsystems (2)
PATCH 1/1 nbd: some trivial improvements
This patch 1) uses task_pid_nr(current) to get the pid of current process,
2) replaces sysfs_create_file() with device_create_file(), 3) lower
the loglevel of an error message.
---
drivers/block/nbd.c +5 -5
@@ -405,10 +405,10 @@ static int nbd_do_it(struct nbd_device *lo)BUG_ON (lo->magic !=LO_MAGIC ); - lo->pid = current->pid; - ret =sysfs_create_file (&disk_to_dev (lo->disk)->kobj, &pid_attr.attr); + lo->pid =task_pid_nr (current); + ret =device_create_file (disk_to_dev (lo->disk), &pid_attr);if (ret) { -printk (KERN_ERR "nbd: sysfs_create_file failed!" ); +printk (KERN_ERR "nbd: device_create_file failed!" ); lo->pid =0 ;return ret; }
@@ -416,7 +416,7 @@ static int nbd_do_it(struct nbd_device *lo)while ((req =nbd_read_stat (lo)) !=NULL )nbd_end_request (req); -sysfs_remove_file (&disk_to_dev (lo->disk)->kobj, &pid_attr.attr); +device_remove_file (disk_to_dev (lo->disk), &pid_attr); lo->pid =0 ;return 0 ; }
@@ -745,7 +745,7 @@ static int __init nbd_init(void)BUILD_BUG_ON (sizeof (struct nbd_request ) !=28 );if (max_part <0 ) { -printk (KERN_CRIT "nbd: max_part must be >= 0\n" ); +printk (KERN_ERR "nbd: max_part must be >= 0\n" );return -EINVAL ; }
Quoted 3 lines · Amerigo Wang
This patch 1) uses
task_pid_nr(current)to get the pid of current process,
2) replacessysfs_create_file()withdevice_create_file(), 3) lower
the loglevel of an error message.
Just trivia:
drivers/block/nbd.c
Quoted 1 line
drivers/block/nbd.c +0
-0
[]
drivers/block/nbd.c static int nbd_do_it(struct nbd_device *lo) · line 411
Quoted 11 lines
drivers/block/nbd.c +3
-3@@ -405,10 +405,10 @@ static int nbd_do_it(struct nbd_device *lo)BUG_ON (lo->magic !=LO_MAGIC ); - lo->pid = current->pid; - ret =sysfs_create_file (&disk_to_dev (lo->disk)->kobj, &pid_attr.attr); + lo->pid =task_pid_nr (current); + ret =device_create_file (disk_to_dev (lo->disk), &pid_attr);if (ret) { -printk (KERN_ERR "nbd: sysfs_create_file failed!" ); +printk (KERN_ERR "nbd: device_create_file failed!" );
Missing "\n".
Quoted 3 lines · Amerigo Wang
This patch 1) uses
task_pid_nr(current)to get the pid of current process,
2) replacessysfs_create_file()withdevice_create_file(), 3) lower
the loglevel of an error message.
As you are doing 3 different things, please make this 3 different patches (remember, one patch per logical thing being done.)
Quoted 11 lines
Cc Greg Kroah-Hartman <[email protected]>Cc Paul Clements <[email protected]>Signed-off-by WANG Cong <[email protected]>---
drivers/block/nbd.c +0
-0
drivers/block/nbd.c static int nbd_do_it(struct nbd_device *lo) · line 411
Quoted 10 lines
drivers/block/nbd.c +3
-3@@ -405,10 +405,10 @@ static int nbd_do_it(struct nbd_device *lo)BUG_ON (lo->magic !=LO_MAGIC ); - lo->pid = current->pid; - ret =sysfs_create_file (&disk_to_dev (lo->disk)->kobj, &pid_attr.attr); + lo->pid =task_pid_nr (current); + ret =device_create_file (disk_to_dev (lo->disk), &pid_attr);if (ret) { -printk (KERN_ERR "nbd: sysfs_create_file failed!" ); +printk (KERN_ERR "nbd: device_create_file failed!" );
Use dev_err() instead please.
Quoted 13 lines
drivers/block/nbd.c +1
-1lo->pid =0 ;return ret; }@@ -416,7 +416,7 @@ static int nbd_do_it(struct nbd_device *lo)while ((req =nbd_read_stat (lo)) !=NULL )nbd_end_request (req); -sysfs_remove_file (&disk_to_dev (lo->disk)->kobj, &pid_attr.attr); +device_remove_file (disk_to_dev (lo->disk), &pid_attr); lo->pid =0 ;return 0 ; }
drivers/block/nbd.c static int __init nbd_init(void) · line 748
Quoted 5 lines
drivers/block/nbd.c +1
-1@@ -745,7 +745,7 @@ static int __init nbd_init(void)BUILD_BUG_ON (sizeof (struct nbd_request ) !=28 );if (max_part <0 ) { -printk (KERN_CRIT "nbd: max_part must be >= 0\n" ); +printk (KERN_ERR "nbd: max_part must be >= 0\n" );
Again, dev_err() please. That properly identifies exactly which device had problems.
thanks,
greg k-h
Quoted 13 lines · Joe Perches
Quoted 3 lines · Amerigo Wang
This patch 1) uses
task_pid_nr(current)to get the pid of current process,
2) replacessysfs_create_file()withdevice_create_file(), 3) lower
the loglevel of an error message.Just trivia:
drivers/block/nbd.c
Quoted 1 line
drivers/block/nbd.c +0
-0[]
Quoted 4 lines
drivers/block/nbd.c +0
-0@@ -405,10 +405,10 @@ static int nbd_do_it(struct nbd_device *lo)BUG_ON (lo->magic !=LO_MAGIC );
Quoted 10 lines
drivers/block/nbd.c static int nbd_do_it(struct nbd_device *lo) · line 411
Quoted 7 lines
drivers/block/nbd.c +3
-3- lo->pid = current->pid; - ret =sysfs_create_file (&disk_to_dev (lo->disk)->kobj,&pid_attr.attr); + lo->pid =task_pid_nr (current); + ret =device_create_file (disk_to_dev (lo->disk),&pid_attr);if (ret) { -printk (KERN_ERR "nbd: sysfs_create_file failed!" ); +printk (KERN_ERR "nbd: device_create_file failed!" );Missing "\n".
Ok, I didn't notice this, will fix it.
Thanks.
Quoted 7 lines · Greg KH
Quoted 3 lines · Amerigo Wang
This patch 1) uses
task_pid_nr(current)to get the pid of current process,
2) replacessysfs_create_file()withdevice_create_file(), 3) lower
the loglevel of an error message.As you are doing 3 different things, please make this 3 different patches (remember, one patch per logical thing being done.)
Since you insist, will do.
Quoted 9 lines
Review
Quoted 5 lines
if (max_part< 0) {(quoted diff) +1
-1- printk(KERN_CRIT "nbd: max_part must be>= 0\n"); + printk(KERN_ERR "nbd: max_part must be>= 0\n");Again,
dev_err()please. That properly identifies exactly which device had problems.
Ok, thanks for pointing this out!