Commit 4d273aae authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] nbd: remove PARANOIA and other cleanups

From: Paul Clements <Paul.Clements@SteelEye.com>

This patch removes the PARANOIA define (it was always defined anyway).  It
also removes the requests_in/out counters (which weren't always accurate,
and are superfluous anyway, since the block layer keeps its own in_flight
counter).  Also some minor cleanup of comments.
parent 07172aea
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
* 03-06-24 Remove unneeded blksize_bits field from nbd_device struct. * 03-06-24 Remove unneeded blksize_bits field from nbd_device struct.
* <ldl@aros.net> * <ldl@aros.net>
* 03-06-24 Cleanup PARANOIA usage & code. <ldl@aros.net> * 03-06-24 Cleanup PARANOIA usage & code. <ldl@aros.net>
* * 04-02-19 Remove PARANOIA, plus various cleanups (Paul Clements)
* possible FIXME: make set_sock / set_blksize / set_size / do_it one syscall * 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 * why not: would need verify_area and friends, would share yet another
* structure with userland * structure with userland
...@@ -61,12 +61,9 @@ ...@@ -61,12 +61,9 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/types.h> #include <asm/types.h>
/* Define PARANOIA in linux/nbd.h to turn on extra sanity checking */
#include <linux/nbd.h> #include <linux/nbd.h>
#ifdef PARANOIA
#define LO_MAGIC 0x68797548 #define LO_MAGIC 0x68797548
#endif
#ifdef NDEBUG #ifdef NDEBUG
#define dprintk(flags, fmt...) #define dprintk(flags, fmt...)
...@@ -97,11 +94,6 @@ static struct nbd_device nbd_dev[MAX_NBD]; ...@@ -97,11 +94,6 @@ static struct nbd_device nbd_dev[MAX_NBD];
*/ */
static spinlock_t nbd_lock = SPIN_LOCK_UNLOCKED; static spinlock_t nbd_lock = SPIN_LOCK_UNLOCKED;
#ifdef PARANOIA
static int requests_in;
static int requests_out;
#endif
#ifndef NDEBUG #ifndef NDEBUG
static const char *ioctl_cmd_to_ascii(int cmd) static const char *ioctl_cmd_to_ascii(int cmd)
{ {
...@@ -153,9 +145,6 @@ static void nbd_end_request(struct request *req) ...@@ -153,9 +145,6 @@ static void nbd_end_request(struct request *req)
} }
spin_unlock(&lo->queue_lock); spin_unlock(&lo->queue_lock);
#ifdef PARANOIA
requests_out++;
#endif
spin_lock_irqsave(q->queue_lock, flags); spin_lock_irqsave(q->queue_lock, flags);
if (!end_that_request_first(req, uptodate, req->nr_sectors)) { if (!end_that_request_first(req, uptodate, req->nr_sectors)) {
end_that_request_last(req); end_that_request_last(req);
...@@ -217,10 +206,6 @@ static int sock_xmit(struct socket *sock, int send, void *buf, int size, ...@@ -217,10 +206,6 @@ static int sock_xmit(struct socket *sock, int send, void *buf, int size,
} }
if (result <= 0) { if (result <= 0) {
#ifdef PARANOIA
printk(KERN_ERR "nbd: %s - sock=%p at buf=%p, size=%d returned %d.\n",
send? "send": "receive", sock, buf, size, result);
#endif
if (result == 0) if (result == 0)
result = -EPIPE; /* short read */ result = -EPIPE; /* short read */
break; break;
...@@ -414,9 +399,8 @@ void nbd_do_it(struct nbd_device *lo) ...@@ -414,9 +399,8 @@ void nbd_do_it(struct nbd_device *lo)
{ {
struct request *req; struct request *req;
#ifdef PARANOIA
BUG_ON(lo->magic != LO_MAGIC); BUG_ON(lo->magic != LO_MAGIC);
#endif
while ((req = nbd_read_stat(lo)) != NULL) while ((req = nbd_read_stat(lo)) != NULL)
nbd_end_request(req); nbd_end_request(req);
return; return;
...@@ -426,9 +410,7 @@ void nbd_clear_que(struct nbd_device *lo) ...@@ -426,9 +410,7 @@ void nbd_clear_que(struct nbd_device *lo)
{ {
struct request *req; struct request *req;
#ifdef PARANOIA
BUG_ON(lo->magic != LO_MAGIC); BUG_ON(lo->magic != LO_MAGIC);
#endif
do { do {
req = NULL; req = NULL;
...@@ -467,9 +449,9 @@ static void do_nbd_request(request_queue_t * q) ...@@ -467,9 +449,9 @@ static void do_nbd_request(request_queue_t * q)
goto error_out; goto error_out;
lo = req->rq_disk->private_data; lo = req->rq_disk->private_data;
#ifdef PARANOIA
BUG_ON(lo->magic != LO_MAGIC); BUG_ON(lo->magic != LO_MAGIC);
#endif
if (!lo->file) { if (!lo->file) {
printk(KERN_ERR "%s: Request when not-ready\n", printk(KERN_ERR "%s: Request when not-ready\n",
lo->disk->disk_name); lo->disk->disk_name);
...@@ -484,9 +466,6 @@ static void do_nbd_request(request_queue_t * q) ...@@ -484,9 +466,6 @@ static void do_nbd_request(request_queue_t * q)
goto error_out; goto error_out;
} }
} }
#ifdef PARANOIA
requests_in++;
#endif
req->errors = 0; req->errors = 0;
spin_unlock_irq(q->queue_lock); spin_unlock_irq(q->queue_lock);
...@@ -527,7 +506,7 @@ static void do_nbd_request(request_queue_t * q) ...@@ -527,7 +506,7 @@ static void do_nbd_request(request_queue_t * q)
spin_lock_irq(q->queue_lock); spin_lock_irq(q->queue_lock);
continue; continue;
error_out: error_out:
req->errors++; req->errors++;
spin_unlock(q->queue_lock); spin_unlock(q->queue_lock);
nbd_end_request(req); nbd_end_request(req);
...@@ -545,9 +524,9 @@ static int nbd_ioctl(struct inode *inode, struct file *file, ...@@ -545,9 +524,9 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
#ifdef PARANOIA
BUG_ON(lo->magic != LO_MAGIC); BUG_ON(lo->magic != LO_MAGIC);
#endif
/* Anyone capable of this syscall can do *real bad* things */ /* Anyone capable of this syscall can do *real bad* things */
dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n", dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n",
lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg); lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg);
...@@ -663,15 +642,10 @@ static int nbd_ioctl(struct inode *inode, struct file *file, ...@@ -663,15 +642,10 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
nbd_clear_que(lo); nbd_clear_que(lo);
return 0; return 0;
case NBD_PRINT_DEBUG: case NBD_PRINT_DEBUG:
#ifdef PARANOIA printk(KERN_INFO "%s: next = %p, prev = %p, head = %p\n",
printk(KERN_INFO "%s: next = %p, prev = %p. Global: in %d, out %d\n",
inode->i_bdev->bd_disk->disk_name, lo->queue_head.next,
lo->queue_head.prev, requests_in, requests_out);
#else
printk(KERN_INFO "%s: next = %p, prev = %p\n",
inode->i_bdev->bd_disk->disk_name, inode->i_bdev->bd_disk->disk_name,
lo->queue_head.next, lo->queue_head.prev); lo->queue_head.next, lo->queue_head.prev,
#endif &lo->queue_head);
return 0; return 0;
} }
return -EINVAL; return -EINVAL;
...@@ -693,12 +667,10 @@ static int __init nbd_init(void) ...@@ -693,12 +667,10 @@ static int __init nbd_init(void)
int err = -ENOMEM; int err = -ENOMEM;
int i; int i;
#ifdef PARANOIA
if (sizeof(struct nbd_request) != 28) { if (sizeof(struct nbd_request) != 28) {
printk(KERN_CRIT "nbd: Sizeof nbd_request needs to be 28 in order to work!\n" ); printk(KERN_CRIT "nbd: sizeof nbd_request needs to be 28 in order to work!\n" );
return -EIO; return -EIO;
} }
#endif
for (i = 0; i < MAX_NBD; i++) { for (i = 0; i < MAX_NBD; i++) {
struct gendisk *disk = alloc_disk(1); struct gendisk *disk = alloc_disk(1);
...@@ -729,9 +701,7 @@ static int __init nbd_init(void) ...@@ -729,9 +701,7 @@ static int __init nbd_init(void)
for (i = 0; i < MAX_NBD; i++) { for (i = 0; i < MAX_NBD; i++) {
struct gendisk *disk = nbd_dev[i].disk; struct gendisk *disk = nbd_dev[i].disk;
nbd_dev[i].file = NULL; nbd_dev[i].file = NULL;
#ifdef PARANOIA
nbd_dev[i].magic = LO_MAGIC; nbd_dev[i].magic = LO_MAGIC;
#endif
nbd_dev[i].flags = 0; nbd_dev[i].flags = 0;
spin_lock_init(&nbd_dev[i].queue_lock); spin_lock_init(&nbd_dev[i].queue_lock);
INIT_LIST_HEAD(&nbd_dev[i].queue_head); INIT_LIST_HEAD(&nbd_dev[i].queue_head);
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
* 2003/06/24 Louis D. Langholtz <ldl@aros.net> * 2003/06/24 Louis D. Langholtz <ldl@aros.net>
* Removed unneeded blksize_bits field from nbd_device struct. * Removed unneeded blksize_bits field from nbd_device struct.
* Cleanup PARANOIA usage & code. * Cleanup PARANOIA usage & code.
* 2004/02/19 Paul Clements
* Removed PARANOIA, plus various cleanup and comments
*/ */
#ifndef LINUX_NBD_H #ifndef LINUX_NBD_H
...@@ -32,22 +34,19 @@ enum { ...@@ -32,22 +34,19 @@ enum {
#define nbd_cmd(req) ((req)->cmd[0]) #define nbd_cmd(req) ((req)->cmd[0])
#define MAX_NBD 128 #define MAX_NBD 128
/* Define PARANOIA to include extra sanity checking code in here & driver */
#define PARANOIA
/* userspace doesn't need the nbd_device structure */ /* userspace doesn't need the nbd_device structure */
#ifdef __KERNEL__ #ifdef __KERNEL__
/* values for flags field */
#define NBD_READ_ONLY 0x0001
#define NBD_WRITE_NOCHK 0x0002
struct nbd_device { struct nbd_device {
int flags; int flags;
int harderror; /* Code of hard error */ int harderror; /* Code of hard error */
#define NBD_READ_ONLY 0x0001
#define NBD_WRITE_NOCHK 0x0002
struct socket * sock; struct socket * sock;
struct file * file; /* If == NULL, device is not ready, yet */ struct file * file; /* If == NULL, device is not ready, yet */
#ifdef PARANOIA int magic;
int magic; /* FIXME: not if debugging is off */
#endif
spinlock_t queue_lock; spinlock_t queue_lock;
struct list_head queue_head;/* Requests are added here... */ struct list_head queue_head;/* Requests are added here... */
struct semaphore tx_lock; struct semaphore tx_lock;
...@@ -58,16 +57,14 @@ struct nbd_device { ...@@ -58,16 +57,14 @@ struct nbd_device {
#endif #endif
/* This now IS in some kind of include file... */ /* These are sent over the network in the request/reply magic fields */
/* These are send over network in request/reply magic field */
#define NBD_REQUEST_MAGIC 0x25609513 #define NBD_REQUEST_MAGIC 0x25609513
#define NBD_REPLY_MAGIC 0x67446698 #define NBD_REPLY_MAGIC 0x67446698
/* Do *not* use magics: 0x12560953 0x96744668. */ /* Do *not* use magics: 0x12560953 0x96744668. */
/* /*
* This is packet used for communication between client and * This is the packet used for communication between client and
* server. All data are in network byte order. * server. All data are in network byte order.
*/ */
struct nbd_request { struct nbd_request {
...@@ -82,6 +79,10 @@ struct nbd_request { ...@@ -82,6 +79,10 @@ struct nbd_request {
#endif #endif
; ;
/*
* This is the reply packet that nbd-server sends back to the client after
* it has completed an I/O request (or an error occurs).
*/
struct nbd_reply { struct nbd_reply {
u32 magic; u32 magic;
u32 error; /* 0 = ok, else error */ u32 error; /* 0 = ok, else error */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment