- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / include / linux / nbd.h
blobc981a6911edd90ab10eb6d0cdbd421764209fbbe
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 */
7 #ifndef LINUX_NBD_H
8 #define LINUX_NBD_H
10 #define NBD_SET_SOCK _IO( 0xab, 0 )
11 #define NBD_SET_BLKSIZE _IO( 0xab, 1 )
12 #define NBD_SET_SIZE _IO( 0xab, 2 )
13 #define NBD_DO_IT _IO( 0xab, 3 )
14 #define NBD_CLEAR_SOCK _IO( 0xab, 4 )
15 #define NBD_CLEAR_QUE _IO( 0xab, 5 )
16 #define NBD_PRINT_DEBUG _IO( 0xab, 6 )
17 #define NBD_SET_SIZE_BLOCKS _IO( 0xab, 7 )
18 #define NBD_DISCONNECT _IO( 0xab, 8 )
20 #ifdef MAJOR_NR
22 #include <linux/locks.h>
23 #include <asm/semaphore.h>
25 #define LOCAL_END_REQUEST
27 #include <linux/blk.h>
29 #ifdef PARANOIA
30 extern int requests_in;
31 extern int requests_out;
32 #endif
34 static int
35 nbd_end_request(struct request *req)
37 unsigned long flags;
38 int ret = 0;
40 #ifdef PARANOIA
41 requests_out++;
42 #endif
44 * This is a very dirty hack that we have to do to handle
45 * merged requests because end_request stuff is a bit
46 * broken. The fact we have to do this only if there
47 * aren't errors looks even more silly.
49 if (!req->errors) {
50 req->sector += req->current_nr_sectors;
51 req->nr_sectors -= req->current_nr_sectors;
54 spin_lock_irqsave(&io_request_lock, flags);
55 if (end_that_request_first( req, !req->errors, "nbd" ))
56 goto out;
57 ret = 1;
58 end_that_request_last( req );
60 out:
61 spin_unlock_irqrestore(&io_request_lock, flags);
62 return ret;
65 #define MAX_NBD 128
67 struct nbd_device {
68 int refcnt;
69 int flags;
70 int harderror; /* Code of hard error */
71 #define NBD_READ_ONLY 0x0001
72 #define NBD_WRITE_NOCHK 0x0002
73 struct socket * sock;
74 struct file * file; /* If == NULL, device is not ready, yet */
75 int magic; /* FIXME: not if debugging is off */
76 struct list_head queue_head; /* Requests are added here... */
77 struct semaphore queue_lock;
79 #endif
81 /* This now IS in some kind of include file... */
83 /* These are send over network in request/reply magic field */
85 #define NBD_REQUEST_MAGIC 0x25609513
86 #define NBD_REPLY_MAGIC 0x67446698
87 /* Do *not* use magics: 0x12560953 0x96744668. */
90 * This is packet used for communication between client and
91 * server. All data are in network byte order.
93 struct nbd_request {
94 u32 magic;
95 u32 type; /* == READ || == WRITE */
96 char handle[8];
97 u64 from;
98 u32 len;
100 #ifdef __GNUC__
101 __attribute__ ((packed))
102 #endif
105 struct nbd_reply {
106 u32 magic;
107 u32 error; /* 0 = ok, else error */
108 char handle[8]; /* handle you got from request */
110 #endif