Skip to contentSkip to conversation

nbd: some trivial improvements

PATCH In review Amerigo Wang 3 participants 5 messages Aug 8, 2011 – Aug 9, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Cc Greg Kroah-Hartman <[email protected]>
Cc Paul Clements <[email protected]>

---

drivers/block/nbd.c +5 -5
index f533f33..07cad4b 100644
@@ -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;
 	}
 
#1 lore raw
Quoted 3 lines · Amerigo Wang

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.

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".

#3 lore raw
In reply to Amerigo Wang
Quoted 3 lines · Amerigo Wang

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.

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]>

---

drivers/block/nbd.c +0 -0
index f533f33..07cad4b 100644

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 -1
 		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;
 }

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

author
#2 lore raw
In reply to Joe Perches
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) replaces sysfs_create_file() with device_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.

author
#4 lore raw
In reply to Greg KH
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) replaces sysfs_create_file() with device_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!