Skip to contentSkip to conversation

nbd : fix might sleep warning and checkpatch errors.

PATCH Superseded Pranay Kr. Srivastava 1 participant 18 messages May 6, 2016

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover nbd : fix might sleep warning and checkpatch errors.

Changes in v3
- Split checkpatch changes into single patch per change.

Changes in v2
- add checkpatch changes in a single patch.

Changes in v1
- fix might_sleep warning on xmit_timeout.

Pranay Kr. Srivastava (17):
nbd: Fix might_sleep warning on xmit timeout
nbd: fix checkpatch trailing space warning.
nbd: fix checkpatch warning use linux/uaccess.h
nbd : fix checkpatch pointer declaration warning
nbd: fix checkpatch warning no newline after decleration.
nbd: fix checkpatch warning no newline after decleration.
nbd: fix checkpatch split string warning.
nbd : fix checkpatch line over 80 char warning
nbd: fix checkpatch trailing whitespace warning.
nbd: fix checkpatch trailing whitespace warning.
nbd : fix checkpatch structure declaration braces on next line
warning.
nbd : fix checkpatch trailing whitespace warning
nbd : fix checkpatch printk warning
nbd: fix checkpatch no extra line after decleration warning
nbd: fix checkpatch printk warning to pr_info
nbd: fix checkpatch no new line after decleration warning
nbd: fix checkpatch printk warning to pr_info

 drivers/block/nbd.c | 93 +++++++++++++++++++++++++++++++----------------------
 1 file changed, 54 insertions(+), 39 deletions(-)
Signature · 1 line
2.6.2
#1 lore raw

PATCH v3 1/17 nbd: Fix might_sleep warning on xmit timeout

This patch fixes the warning generated when a timeout occurs on the request and socket is closed from a non-sleep context by

1. Moving the socket closing on a timeout to nbd_thread_send

2. Make sock lock to be a mutex instead of a spin lock, since nbd_xmit_timeout doesn't need to hold it anymore.

---
 drivers/block/nbd.c | 65 ++++++++++++++++++++++++++++++++---------------------
 1 file changed, 39 insertions(+), 26 deletions(-)
drivers/block/nbd.c +39 -26
index 31e73a7..c79bcd7 100644
@@ -57,12 +57,12 @@ struct nbd_device {
 	int blksize;
 	loff_t bytesize;
 	int xmit_timeout;
-	bool timedout;
+	atomic_t timedout;
 	bool disconnect; /* a disconnect has been requested by user */
 
 	struct timer_list timeout_timer;
 	/* protects initialization and shutdown of the socket */
-	spinlock_t sock_lock;
+	struct mutex sock_lock;
 	struct task_struct *task_recv;
 	struct task_struct *task_send;
 
@@ -172,10 +172,9 @@ static void nbd_end_request(struct nbd_device *nbd, struct request *req)
  */
 static void sock_shutdown(struct nbd_device *nbd)
 {
-	spin_lock_irq(&nbd->sock_lock);
-
+	mutex_lock(&nbd->sock_lock);
 	if (!nbd->sock) {
-		spin_unlock_irq(&nbd->sock_lock);
+		mutex_unlock(&nbd->sock_lock);
 		return;
 	}
 
@@ -183,27 +182,19 @@ static void sock_shutdown(struct nbd_device *nbd)
 	kernel_sock_shutdown(nbd->sock, SHUT_RDWR);
 	sockfd_put(nbd->sock);
 	nbd->sock = NULL;
-	spin_unlock_irq(&nbd->sock_lock);
-
+	mutex_unlock(&nbd->sock_lock);
 	del_timer(&nbd->timeout_timer);
 }
 
 static void nbd_xmit_timeout(unsigned long arg)
 {
 	struct nbd_device *nbd = (struct nbd_device *)arg;
-	unsigned long flags;
 
 	if (list_empty(&nbd->queue_head))
 		return;
 
-	spin_lock_irqsave(&nbd->sock_lock, flags);
-
-	nbd->timedout = true;
-
-	if (nbd->sock)
-		kernel_sock_shutdown(nbd->sock, SHUT_RDWR);
-
-	spin_unlock_irqrestore(&nbd->sock_lock, flags);
+	atomic_inc(&nbd->timedout);
+	wake_up(&nbd->waiting_wq);
 
 	dev_err(nbd_to_dev(nbd), "Connection timed out, shutting down connection\n");
 }
@@ -579,7 +570,27 @@ static int nbd_thread_send(void *data)
 		/* wait for something to do */
 		wait_event_interruptible(nbd->waiting_wq,
 					 kthread_should_stop() ||
-					 !list_empty(&nbd->waiting_queue));
+					 !list_empty(&nbd->waiting_queue) ||
+					 atomic_read(&nbd->timedout));
+
+		if (atomic_read(&nbd->timedout)) {
+			mutex_lock(&nbd->sock_lock);
+			if (nbd->sock) {
+				struct request sreq;
+
+				blk_rq_init(NULL, &sreq);
+				sreq.cmd_type = REQ_TYPE_DRV_PRIV;
+				mutex_lock(&nbd->tx_lock);
+				nbd->disconnect = true;
+				nbd_send_req(nbd, &sreq);
+				mutex_unlock(&nbd->tx_lock);
+				dev_err(disk_to_dev(nbd->disk),
+					"Device Timeout occured.Shutting down"
+					" socket.");
+			}
+			mutex_unlock(&nbd->sock_lock);
+			sock_shutdown(nbd);
+		}
 
 		/* extract request */
 		if (list_empty(&nbd->waiting_queue))
@@ -592,7 +603,11 @@ static int nbd_thread_send(void *data)
 		spin_unlock_irq(&nbd->queue_lock);
 
 		/* handle request */
-		nbd_handle_req(nbd, req);
+		if (atomic_read(&nbd->timedout)) {
+			req->errors++;
+			nbd_end_request(nbd, req);
+		} else
+			nbd_handle_req(nbd, req);
 	}
 
 	nbd->task_send = NULL;
@@ -647,7 +662,7 @@ static int nbd_set_socket(struct nbd_device *nbd, struct socket *sock)
 {
 	int ret = 0;
 
-	spin_lock_irq(&nbd->sock_lock);
+	mutex_lock(&nbd->sock_lock);
 
 	if (nbd->sock) {
 		ret = -EBUSY;
@@ -657,7 +672,7 @@ static int nbd_set_socket(struct nbd_device *nbd, struct socket *sock)
 	nbd->sock = sock;
 
 out:
-	spin_unlock_irq(&nbd->sock_lock);
+	mutex_unlock(&nbd->sock_lock);
 
 	return ret;
 }
@@ -666,7 +681,7 @@ out:
 static void nbd_reset(struct nbd_device *nbd)
 {
 	nbd->disconnect = false;
-	nbd->timedout = false;
+	atomic_set(&nbd->timedout, 0);
 	nbd->blksize = 1024;
 	nbd->bytesize = 0;
 	set_capacity(nbd->disk, 0);
@@ -803,17 +818,15 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
 		error = nbd_thread_recv(nbd, bdev);
 		nbd_dev_dbg_close(nbd);
 		kthread_stop(thread);
-
-		mutex_lock(&nbd->tx_lock);
-
 		sock_shutdown(nbd);
+		mutex_lock(&nbd->tx_lock);
 		nbd_clear_que(nbd);
 		kill_bdev(bdev);
 		nbd_bdev_reset(bdev);
 
 		if (nbd->disconnect) /* user requested, ignore socket errors */
 			error = 0;
-		if (nbd->timedout)
+		if (atomic_read(&nbd->timedout))
 			error = -ETIMEDOUT;
 
 		nbd_reset(nbd);
@@ -1075,7 +1088,7 @@ static int __init nbd_init(void)
 		nbd_dev[i].magic = NBD_MAGIC;
 		INIT_LIST_HEAD(&nbd_dev[i].waiting_queue);
 		spin_lock_init(&nbd_dev[i].queue_lock);
-		spin_lock_init(&nbd_dev[i].sock_lock);
+		mutex_init(&nbd_dev[i].sock_lock);
 		INIT_LIST_HEAD(&nbd_dev[i].queue_head);
 		mutex_init(&nbd_dev[i].tx_lock);
 		init_timer(&nbd_dev[i].timeout_timer);
Signature · 1 line
2.6.2
#2 lore raw

PATCH v3 2/17 nbd: fix checkpatch trailing space warning.

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index c79bcd7..82aac42 100644
@@ -3,7 +3,7 @@
  *
  * Note that you can not swap over this thing, yet. Seems to work but
  * deadlocks sometimes - you can not swap over TCP in general.
- * 
+ *
  * Copyright 1997-2000, 2008 Pavel Machek <[email protected]>
  * Parts copyright 2001 Steven Whitehouse <[email protected]>
  *
Signature · 1 line
2.6.2
#3 lore raw

PATCH v3 3/17 nbd: fix checkpatch warning use linux/uaccess.h

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index 82aac42..c7ccde7 100644
@@ -35,7 +35,7 @@
 #include <linux/types.h>
 #include <linux/debugfs.h>
 
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <asm/types.h>
 
 #include <linux/nbd.h>
Signature · 1 line
2.6.2
#4 lore raw

PATCH v3 4/17 nbd : fix checkpatch pointer declaration warning

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index c7ccde7..786aaac 100644
@@ -42,7 +42,7 @@
 
 struct nbd_device {
 	u32 flags;
-	struct socket * sock;	/* If == NULL, device is not ready, yet	*/
+	struct socket *sock;	/* If == NULL, device is not ready, yet	*/
 	int magic;
 
 	spinlock_t queue_lock;
Signature · 1 line
2.6.2
#5 lore raw

PATCH v3 5/17 nbd: fix checkpatch warning no newline after decleration.

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/block/nbd.c +1 -0
index 786aaac..2192c0e 100644
@@ -257,6 +257,7 @@ static inline int sock_send_bvec(struct nbd_device *nbd, struct bio_vec *bvec,
 {
 	int result;
 	void *kaddr = kmap(bvec->bv_page);
+
 	result = sock_xmit(nbd, 1, kaddr + bvec->bv_offset,
 			   bvec->bv_len, flags);
 	kunmap(bvec->bv_page);
Signature · 1 line
2.6.2
#6 lore raw

PATCH v3 6/17 nbd: fix checkpatch warning no newline after decleration.

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/block/nbd.c +1 -0
index 2192c0e..6a4dc3a 100644
@@ -355,6 +355,7 @@ static inline int sock_recv_bvec(struct nbd_device *nbd, struct bio_vec *bvec)
 {
 	int result;
 	void *kaddr = kmap(bvec->bv_page);
+
 	result = sock_xmit(nbd, 0, kaddr + bvec->bv_offset, bvec->bv_len,
 			MSG_WAITALL);
 	kunmap(bvec->bv_page);
Signature · 1 line
2.6.2
#7 lore raw

PATCH v3 7/17 nbd: fix checkpatch split string warning.

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/nbd.c +1 -2
index 6a4dc3a..7a5b8ef 100644
@@ -587,8 +587,7 @@ static int nbd_thread_send(void *data)
 				nbd_send_req(nbd, &sreq);
 				mutex_unlock(&nbd->tx_lock);
 				dev_err(disk_to_dev(nbd->disk),
-					"Device Timeout occured.Shutting down"
-					" socket.");
+				"Device Timeout occured.Shutting down socket.");
 			}
 			mutex_unlock(&nbd->sock_lock);
 			sock_shutdown(nbd);
Signature · 1 line
2.6.2
#8 lore raw

PATCH v3 8/17 nbd : fix checkpatch line over 80 char warning

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/nbd.c +2 -2
index 7a5b8ef..224b44eb 100644
@@ -617,8 +617,8 @@ static int nbd_thread_send(void *data)
 }
 
 /*
- * We always wait for result of write, for now. It would be nice to make it optional
- * in future
+ * We always wait for result of write, for now. It would be nice to make it
+ * optional in future
  * if ((rq_data_dir(req) == WRITE) && (nbd->flags & NBD_WRITE_NOCHK))
  *   { printk( "Warning: Ignoring result!\n"); nbd_end_request( req ); }
  */
Signature · 1 line
2.6.2
#9 lore raw

PATCH v3 9/17 nbd: fix checkpatch trailing whitespace warning.

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index 224b44eb..2f1e5d0 100644
@@ -627,7 +627,7 @@ static void nbd_request_handler(struct request_queue *q)
 		__releases(q->queue_lock) __acquires(q->queue_lock)
 {
 	struct request *req;
-	
+
 	while ((req = blk_fetch_request(q)) != NULL) {
 		struct nbd_device *nbd;
 
Signature · 1 line
2.6.2
#10 lore raw

PATCH v3 10/17 nbd: fix checkpatch trailing whitespace warning.

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index 2f1e5d0..0bc73dd 100644
@@ -745,7 +745,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
 		nbd_send_req(nbd, &sreq);
 		return 0;
 	}
- 
+
 	case NBD_CLEAR_SOCK:
 		sock_shutdown(nbd);
 		nbd_clear_que(nbd);
Signature · 1 line
2.6.2
#11 lore raw

PATCH v3 11/17 nbd : fix checkpatch structure declaration braces on next line warning.

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/nbd.c +1 -2
index 0bc73dd..a6f11c3 100644
@@ -870,8 +870,7 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
 	return error;
 }
 
-static const struct block_device_operations nbd_fops =
-{
+static const struct block_device_operations nbd_fops = {
 	.owner =	THIS_MODULE,
 	.ioctl =	nbd_ioctl,
 	.compat_ioctl =	nbd_ioctl,
Signature · 1 line
2.6.2
#12 lore raw

PATCH v3 12/17 nbd : fix checkpatch trailing whitespace warning

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index a6f11c3..4fd3016 100644
@@ -1005,7 +1005,7 @@ static void nbd_dbg_close(void)
 #endif
 
 /*
- * And here should be modules and kernel interface 
+ * And here should be modules and kernel interface
  *  (Just smiley confuses emacs :-)
  */
 
Signature · 1 line
2.6.2
#13 lore raw

PATCH v3 13/17 nbd : fix checkpatch printk warning

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index 4fd3016..690e734 100644
@@ -1018,7 +1018,7 @@ static int __init nbd_init(void)
 	BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
 
 	if (max_part < 0) {
-		printk(KERN_ERR "nbd: max_part must be >= 0\n");
+		pr_err("nbd: max_part must be >= 0\n");
 		return -EINVAL;
 	}
 
Signature · 1 line
2.6.2
#14 lore raw

PATCH v3 14/17 nbd: fix checkpatch no extra line after decleration warning

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/block/nbd.c +1 -0
index 690e734..6633ab2 100644
@@ -1049,6 +1049,7 @@ static int __init nbd_init(void)
 
 	for (i = 0; i < nbds_max; i++) {
 		struct gendisk *disk = alloc_disk(1 << part_shift);
+
 		if (!disk)
 			goto out;
 		nbd_dev[i].disk = disk;
Signature · 1 line
2.6.2
#15 lore raw

PATCH v3 15/17 nbd: fix checkpatch printk warning to pr_info

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index 6633ab2..9ce350b 100644
@@ -1080,7 +1080,7 @@ static int __init nbd_init(void)
 		goto out;
 	}
 
-	printk(KERN_INFO "nbd: registered device at major %d\n", NBD_MAJOR);
+	pr_info("nbd: registered device at major %d\n", NBD_MAJOR);
 
 	nbd_dbg_init();
 
Signature · 1 line
2.6.2
#16 lore raw

PATCH v3 16/17 nbd: fix checkpatch no new line after decleration warning

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/block/nbd.c +1 -0
index 9ce350b..e308f8b 100644
@@ -1086,6 +1086,7 @@ static int __init nbd_init(void)
 
 	for (i = 0; i < nbds_max; i++) {
 		struct gendisk *disk = nbd_dev[i].disk;
+
 		nbd_dev[i].magic = NBD_MAGIC;
 		INIT_LIST_HEAD(&nbd_dev[i].waiting_queue);
 		spin_lock_init(&nbd_dev[i].queue_lock);
Signature · 1 line
2.6.2
#17 lore raw

PATCH v3 17/17 nbd: fix checkpatch printk warning to pr_info

In reply to Pranay Kr. Srivastava
---
 drivers/block/nbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/nbd.c +1 -1
index e308f8b..482a3c0 100644
@@ -1134,7 +1134,7 @@ static void __exit nbd_cleanup(void)
 	}
 	unregister_blkdev(NBD_MAJOR, "nbd");
 	kfree(nbd_dev);
-	printk(KERN_INFO "nbd: unregistered device at major %d\n", NBD_MAJOR);
+	pr_info("nbd: unregistered device at major %d\n", NBD_MAJOR);
 }
 
 module_init(nbd_init);
Signature · 1 line
2.6.2