1 /* 2 * 1999 Copyright (C) Pavel Machek, pavel@ucw.cz. This code is GPL. 3 * 1999/11/04 Copyright (C) 1999 VMware, Inc. (Regis "HPReg" Duchesne) 4 * Made nbd_end_request() use the io_request_lock 5 * 2001 Copyright (C) Steven Whitehouse 6 * New nbd_end_request() for compatibility with new linux block 7 * layer code. 8 */ 9 10 #ifndef LINUX_NBD_H 11 #define LINUX_NBD_H 12 13 #define NBD_SET_SOCK _IO( 0xab, 0 ) 14 #define NBD_SET_BLKSIZE _IO( 0xab, 1 ) 15 #define NBD_SET_SIZE _IO( 0xab, 2 ) 16 #define NBD_DO_IT _IO( 0xab, 3 ) 17 #define NBD_CLEAR_SOCK _IO( 0xab, 4 ) 18 #define NBD_CLEAR_QUE _IO( 0xab, 5 ) 19 #define NBD_PRINT_DEBUG _IO( 0xab, 6 ) 20 #define NBD_SET_SIZE_BLOCKS _IO( 0xab, 7 ) 21 #define NBD_DISCONNECT _IO( 0xab, 8 ) 22 23 #ifdef MAJOR_NR 24 25 #include <linux/locks.h> 26 #include <asm/semaphore.h> 27 28 #define LOCAL_END_REQUEST 29 30 #include <linux/blk.h> 31 32 #define MAX_NBD 128 33 34 struct nbd_device { 35 int refcnt; 36 int flags; 37 int harderror; /* Code of hard error */ 38 #define NBD_READ_ONLY 0x0001 39 #define NBD_WRITE_NOCHK 0x0002 40 struct socket * sock; 41 struct file * file; /* If == NULL, device is not ready, yet */ 42 int magic; /* FIXME: not if debugging is off */ 43 spinlock_t queue_lock; 44 struct list_head queue_head; /* Requests are added here... */ 45 struct semaphore tx_lock; 46 }; 47 #endif 48 49 /* This now IS in some kind of include file... */ 50 51 /* These are send over network in request/reply magic field */ 52 53 #define NBD_REQUEST_MAGIC 0x25609513 54 #define NBD_REPLY_MAGIC 0x67446698 55 /* Do *not* use magics: 0x12560953 0x96744668. */ 56 57 /* 58 * This is packet used for communication between client and 59 * server. All data are in network byte order. 60 */ 61 struct nbd_request { 62 u32 magic; 63 u32 type; /* == READ || == WRITE */ 64 char handle[8]; 65 u64 from; 66 u32 len; 67 } 68 #ifdef __GNUC__ 69 __attribute__ ((packed)) 70 #endif 71 ; 72 73 struct nbd_reply { 74 u32 magic; 75 u32 error; /* 0 = ok, else error */ 76 char handle[8]; /* handle you got from request */ 77 }; 78 #endif 79