[3rd time] Network block device update

Pavel Machek (pavel@bug.ucw.cz)
Sun, 16 Aug 1998 18:47:34 +0200


Hi!

I know you announced code freeze, but as this is pretty important (we
want to have protocol right in first stable release, do we?) and as
I'm sending it 3rd time (no reply from you so far), I think it should
go in.

Please note that older code is limited to 32bits, which is bad
think. If this goes into stable kernel, it will be hard to change
later. (It should be pretty easy to change now, as there are not too
many users... yet.)

Pavel

--- clean//include/linux/nbd.h Sun Nov 30 23:24:06 1997
+++ linux/include/linux/nbd.h Wed Jul 29 00:07:03 1998
@@ -1,16 +1,13 @@
#ifndef LINUX_NBD_H
#define LINUX_NBD_H

-#include <linux/ioctl.h>
-#include <asm/types.h>
-
-#define NBD_SET_SOCK _IO( 0xab, 0 )
-#define NBD_SET_BLKSIZE _IO( 0xab, 1 )
-#define NBD_SET_SIZE _IO( 0xab, 2 )
-#define NBD_DO_IT _IO( 0xab, 3 )
-#define NBD_CLEAR_SOCK _IO( 0xab, 4 )
-#define NBD_CLEAR_QUE _IO( 0xab, 5 )
-#define NBD_PRINT_DEBUG _IO( 0xab, 6 )
+#define NBD_SET_SOCK _IO( 0xab, 0 )
+#define NBD_SET_BLKSIZE _IO( 0xab, 1 )
+#define NBD_SET_SIZE _IO( 0xab, 2 )
+#define NBD_DO_IT _IO( 0xab, 3 )
+#define NBD_CLEAR_SOCK _IO( 0xab, 4 )
+#define NBD_CLEAR_QUE _IO( 0xab, 5 )
+#define NBD_PRINT_DEBUG _IO( 0xab, 6 )

#ifdef MAJOR_NR

@@ -54,21 +51,23 @@

/* This now IS in some kind of include file... */

-#define NBD_REQUEST_MAGIC 0x12560953
-#define NBD_REPLY_MAGIC 0x96744668
-#define LO_MAGIC 0x68797548
+/* These are send over network in request/reply magic field */
+
+#define NBD_REQUEST_MAGIC 0x25609513
+#define NBD_REPLY_MAGIC 0x67446698
+/* Do *not* use magics: 0x12560953 0x96744668. */

struct nbd_request {
- __u32 magic;
- __u32 from;
- __u32 len;
+ u32 magic;
+ u32 type; /* == READ || == WRITE */
char handle[8];
- __u32 type; /* == READ || == WRITE */
+ u64 from;
+ u32 len;
};

struct nbd_reply {
- __u32 magic;
+ u32 magic;
+ u32 error; /* 0 = ok, else error */
char handle[8]; /* handle you got from request */
- __u32 error; /* 0 = ok, else error */
};
#endif
--- clean//drivers/block/nbd.c Tue Jun 9 22:34:40 1998
+++ linux/drivers/block/nbd.c Sat Jul 25 15:11:57 1998
@@ -16,6 +16,7 @@
* once to be processed
* 97-4-11 Making protocol independent of endianity etc.
* 97-9-13 Cosmetic changes
+ * 98-5-13 Attempt to make 64-bit-clean on 64-bit machines
*
* 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
@@ -24,18 +25,24 @@

#define PARANOIA
#include <linux/major.h>
-#define MAJOR_NR NBD_MAJOR
-#include <linux/nbd.h>

#include <linux/module.h>

+#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/errno.h>
#include <linux/file.h>
+#include <linux/ioctl.h>

#include <asm/segment.h>
#include <asm/uaccess.h>
+#include <asm/types.h>
+
+#define MAJOR_NR NBD_MAJOR
+#include <linux/nbd.h>
+
+#define LO_MAGIC 0x68797548

static int nbd_blksizes[MAX_NBD] = {1024, 1024,};
static int nbd_sizes[MAX_NBD] = {0x7fffffff, 0x7fffffff,};
@@ -68,8 +75,7 @@
/*
* Send or receive packet.
*/
-static
-int nbd_xmit(int send, struct socket *sock, char *buf, int size)
+static int nbd_xmit(int send, struct socket *sock, char *buf, int size)
{
mm_segment_t oldfs;
int result;
@@ -132,7 +138,7 @@
DEBUG("NBD: sending control, ");
request.magic = htonl(NBD_REQUEST_MAGIC);
request.type = htonl(req->cmd);
- request.from = htonl(req->sector * 512);
+ request.from = cpu_to_be64( (u64) req->sector * (u64) 512);
request.len = htonl(req->current_nr_sectors << 9);
memcpy(request.handle, &req, sizeof(req));

@@ -153,8 +159,8 @@
}

#define HARDFAIL( s ) { printk( KERN_ERR "NBD: " s "(result %d)\n", result ); lo->harderror = result; return NULL; }
-struct request * /* NULL returned = something went wrong, inform userspace */
- nbd_read_stat(struct nbd_device *lo)
+struct request *nbd_read_stat(struct nbd_device *lo)
+ /* NULL returned = something went wrong, inform userspace */
{
int result;
struct nbd_reply reply;
@@ -425,8 +431,8 @@
{
int i;

- if (sizeof(struct nbd_request) != 24) {
- printk(KERN_CRIT "Sizeof nbd_request needs to be 24 in order to work!\n" );
+ if (sizeof(struct nbd_request) != 28) {
+ printk(KERN_CRIT "Sizeof nbd_request needs to be 28 in order to work!\n" );
return -EIO;
}

-- 
I'm really pavel@atrey.karlin.mff.cuni.cz. 	   Pavel
Look at http://atrey.karlin.mff.cuni.cz/~pavel/ ;-).

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html