Index: linux/2.4/drivers/block/nbd.c diff -u linux/2.4/drivers/block/nbd.c:1.1.1.9 linux/2.4/drivers/block/nbd.c:1.1.1.9.4.3 --- linux/2.4/drivers/block/nbd.c:1.1.1.9 Fri Jun 29 16:31:25 2001 +++ linux/2.4/drivers/block/nbd.c Tue Oct 2 13:34:03 2001 @@ -91,17 +91,18 @@ int result; struct msghdr msg; struct iovec iov; - unsigned long flags; - sigset_t oldset; + //unsigned long flags; + //sigset_t oldset; oldfs = get_fs(); set_fs(get_ds()); - spin_lock_irqsave(¤t->sigmask_lock, flags); - oldset = current->blocked; - sigfillset(¤t->blocked); - recalc_sigpending(current); - spin_unlock_irqrestore(¤t->sigmask_lock, flags); + // JEJB: Allow signal interception + //spin_lock_irqsave(¤t->sigmask_lock, flags); + //oldset = current->blocked; + //sigfillset(¤t->blocked); + //recalc_sigpending(current); + //spin_unlock_irqrestore(¤t->sigmask_lock, flags); do { @@ -122,6 +123,13 @@ else result = sock_recvmsg(sock, &msg, size, 0); + // JEJB: Detect signal issue here + 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", @@ -133,10 +141,11 @@ buf += result; } while (size > 0); - spin_lock_irqsave(¤t->sigmask_lock, flags); - current->blocked = oldset; - recalc_sigpending(current); - spin_unlock_irqrestore(¤t->sigmask_lock, flags); + //JEJB: didn't modify signal mask, so no need to restore it + //spin_lock_irqsave(¤t->sigmask_lock, flags); + //current->blocked = oldset; + //recalc_sigpending(current); + //spin_unlock_irqrestore(¤t->sigmask_lock, flags); set_fs(oldfs); return result; @@ -333,8 +342,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); @@ -384,12 +412,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: @@ -430,9 +460,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: @@ -492,7 +542,7 @@ return -EIO; } #ifdef MODULE - printk("nbd: registered device at major %d\n", MAJOR_NR); + printk("nbd: (version Steeleye-8) registered device at major %d\n", MAJOR_NR); #endif blksize_size[MAJOR_NR] = nbd_blksizes; blk_size[MAJOR_NR] = nbd_sizes; @@ -507,7 +557,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);