linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Clements <kernel@steeleye.com>
To: Pavel Machek <pavel@suse.cz>
Cc: Paul.Clements@steeleye.com,
	Edward Muller <emuller@learningpatterns.com>,
	linux-kernel@vger.kernel.org, james.bottomley@steeleye.com
Subject: [PATCH] Re: Current NBD 'stuff'
Date: Thu, 6 Dec 2001 17:13:12 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.10.10112061655190.17617-200000@clements.sc.steeleye.com> (raw)
In-Reply-To: <20011206130220.B49@toy.ucw.cz>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 488 bytes --]

Pavel,

Here is the patch against 2.4.16. Please consider for
inclusion in 2.4 series kernel. We've been running this 
code for several months now and it is working very well.


On Thu, 6 Dec 2001, Pavel Machek wrote:

> Do not comment code by //. Kill if it you want to.
> 
> You added clean way to stop nbd. Good.
> 
> DO NOT USE ALL CAPITALS not even in printks().
> 
> Fix those and patch looks ike good idea for 2.5.

OK, done. 

Thanks,

--
Paul Clements
Paul.Clements@SteelEye.com

[-- Attachment #2: nbd patch --]
[-- Type: TEXT/PLAIN, Size: 4157 bytes --]

--- linux-2.4.16/drivers/block/nbd.c.orig	Fri Oct 26 18:39:02 2001
+++ linux-2.4.16/drivers/block/nbd.c	Thu Dec  6 17:50:32 2001
@@ -24,7 +24,9 @@
  * 01-3-11 Make nbd work with new Linux block layer code. It now supports
  *   plugging like all the other block devices. Also added in MSG_MORE to
  *   reduce number of partial TCP segments sent. <steve@chygwyn.com>
- *
+ * 01-12-06 Make nbd cleanly killable; fix some locking issues; acknowledge
+ *   and log network errors; make default device size 2TB.
+ *   <James.Bottomley@SteelEye.com> <Paul.Clements@SteelEye.com>
  * possible FIXME: make set_sock / set_blksize / set_size / do_it one syscall
  * why not: would need verify_area and friends, would share yet another 
  *          structure with userland
@@ -94,18 +96,10 @@
 	int result;
 	struct msghdr msg;
 	struct iovec iov;
-	unsigned long flags;
-	sigset_t oldset;
 
 	oldfs = get_fs();
 	set_fs(get_ds());
 
-	spin_lock_irqsave(&current->sigmask_lock, flags);
-	oldset = current->blocked;
-	sigfillset(&current->blocked);
-	recalc_sigpending(current);
-	spin_unlock_irqrestore(&current->sigmask_lock, flags);
-
 
 	do {
 		sock->sk->allocation = GFP_NOIO;
@@ -125,6 +119,12 @@
 		else
 			result = sock_recvmsg(sock, &msg, size, 0);
 
+		if(signal_pending(current)) {
+			printk(KERN_WARNING "NBD caught signal\n");
+			result = -EINTR;
+			break;
+		}
+
 		if (result <= 0) {
 #ifdef PARANOIA
 			printk(KERN_ERR "NBD: %s - sock=%ld at buf=%ld, size=%d returned %d.\n",
@@ -136,11 +136,6 @@
 		buf += result;
 	} while (size > 0);
 
-	spin_lock_irqsave(&current->sigmask_lock, flags);
-	current->blocked = oldset;
-	recalc_sigpending(current);
-	spin_unlock_irqrestore(&current->sigmask_lock, flags);
-
 	set_fs(oldfs);
 	return result;
 }
@@ -336,8 +331,27 @@
 		spin_unlock_irq(&io_request_lock);
 
 		down (&lo->queue_lock);
+		if(!lo->file) {
+			up(&lo->queue_lock);
+			spin_lock_irq(&io_request_lock);
+			printk(KERN_ERR "NBD: fail between accept and semaphore, file lost\n");
+			req->errors++;
+			nbd_end_request(req);
+			continue;
+		}
+		
 		list_add(&req->queue, &lo->queue_head);
 		nbd_send_req(lo->sock, req);	/* Why does this block?         */
+		if(req->errors) {
+			printk(KERN_ERR "NBD: nbd_send_req failed\n");
+			list_del(&req->queue);
+
+			up(&lo->queue_lock);
+			spin_lock_irq(&io_request_lock);
+			nbd_end_request(req);
+
+			continue;
+		}
 		up (&lo->queue_lock);
 
 		spin_lock_irq(&io_request_lock);
@@ -387,12 +401,14 @@
 			printk(KERN_ERR "nbd: Some requests are in progress -> can not turn off.\n");
 			return -EBUSY;
 		}
-		up(&lo->queue_lock);
 		file = lo->file;
-		if (!file)
+		if (!file) {
+			up(&lo->queue_lock);
 			return -EINVAL;
+		}
 		lo->file = NULL;
 		lo->sock = NULL;
+		up(&lo->queue_lock);
 		fput(file);
 		return 0;
 	case NBD_SET_SOCK:
@@ -433,9 +449,29 @@
 		if (!lo->file)
 			return -EINVAL;
 		nbd_do_it(lo);
+		/* on return tidy up in case we have a signal */
+		printk(KERN_WARNING "NBD: nbd_do_it returned\n");
+		/* Forcibly shutdown the socket causing all listeners
+		 * to error
+		 *
+		 * FIXME: This code is duplicated from sys_shutdown, but
+		 * there should be a more generic interface rather than
+		 * calling socket ops directly here */
+		lo->sock->ops->shutdown(lo->sock, 2);
+		down(&lo->queue_lock);
+		printk(KERN_WARNING "NBD: lock acquired\n");
+		nbd_clear_que(lo);
+		file = lo->file;
+		lo->file = NULL;
+		lo->sock = NULL;
+		up(&lo->queue_lock);
+		if(file)
+			fput(file);
 		return lo->harderror;
 	case NBD_CLEAR_QUE:
+		down(&lo->queue_lock);
 		nbd_clear_que(lo);
+		up(&lo->queue_lock);
 		return 0;
 #ifdef PARANOIA
 	case NBD_PRINT_DEBUG:
@@ -512,7 +548,7 @@
 		init_MUTEX(&nbd_dev[i].queue_lock);
 		nbd_blksizes[i] = 1024;
 		nbd_blksize_bits[i] = 10;
-		nbd_bytesizes[i] = 0x7ffffc00; /* 2GB */
+		nbd_bytesizes[i] = ((u64)0x7ffffc00) << 10; /* 2TB */
 		nbd_sizes[i] = nbd_bytesizes[i] >> BLOCK_SIZE_BITS;
 		register_disk(NULL, MKDEV(MAJOR_NR,i), 1, &nbd_fops,
 				nbd_bytesizes[i]>>9);

  reply	other threads:[~2001-12-06 22:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-03 18:02 Current NBD 'stuff' Edward Muller
2001-12-04 22:26 ` Paul Clements
2001-12-04 23:12   ` Edward Muller
2001-12-05 16:14     ` Paul Clements
2001-12-05 16:44       ` Peter T. Breuer
2001-12-05 21:02       ` Peter T. Breuer
2001-12-05 22:30         ` Paul Clements
2001-12-06 13:02   ` Pavel Machek
2001-12-06 22:13     ` Paul Clements [this message]
2001-12-22 19:48     ` David Chow
2001-12-06 12:54 ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.10.10112061655190.17617-200000@clements.sc.steeleye.com \
    --to=kernel@steeleye.com \
    --cc=Paul.Clements@steeleye.com \
    --cc=emuller@learningpatterns.com \
    --cc=james.bottomley@steeleye.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).