… | |
… | |
10 | #include <netinet/in.h> |
10 | #include <netinet/in.h> |
11 | #include <byteswap.h> |
11 | #include <byteswap.h> |
12 | |
12 | |
13 | typedef uint32_t u32; |
13 | typedef uint32_t u32; |
14 | typedef uint64_t u64; |
14 | typedef uint64_t u64; |
15 | #include <linux/nbd.h> |
15 | #include "nbd.h" |
16 | |
16 | |
17 | #if __BYTE_ORDER == __BIG_ENDIAN |
17 | #if __BYTE_ORDER == __BIG_ENDIAN |
18 | #define ntohll(netlong) (netlong) |
18 | #define ntohll(netlong) (netlong) |
19 | #elif __BYTE_ORDER == __LITTLE_ENDIAN |
19 | #elif __BYTE_ORDER == __LITTLE_ENDIAN |
20 | #define ntohll(netlong) __bswap_64(netlong) |
20 | #define ntohll(netlong) __bswap_64(netlong) |
… | |
… | |
55 | CODE: |
55 | CODE: |
56 | ioctl (dev, NBD_DISCONNECT); |
56 | ioctl (dev, NBD_DISCONNECT); |
57 | |
57 | |
58 | void |
58 | void |
59 | _clear_sock (int dev) |
59 | _clear_sock (int dev) |
|
|
60 | ALIAS: |
|
|
61 | _clear_sock = NBD_CLEAR_SOCK |
|
|
62 | _clear_que = NBD_CLEAR_QUE |
60 | CODE: |
63 | CODE: |
61 | ioctl (dev, NBD_CLEAR_SOCK); |
64 | ioctl (dev, ix); |
62 | |
65 | |
63 | void |
66 | void |
64 | _clear_que (int dev) |
|
|
65 | CODE: |
|
|
66 | ioctl (dev, NBD_CLEAR_QUE); |
|
|
67 | |
|
|
68 | void |
|
|
69 | _set_blksize (int dev, unsigned long blocksize) |
|
|
70 | CODE: |
|
|
71 | ioctl (dev, NBD_SET_BLKSIZE, blocksize); |
|
|
72 | |
|
|
73 | void |
|
|
74 | _set_size (int dev, unsigned long size) |
67 | _set_blksize (int dev, unsigned long arg) |
|
|
68 | ALIAS: |
|
|
69 | _set_blksize = NBD_SET_BLKSIZE |
|
|
70 | _set_size = NBD_SET_SIZE |
|
|
71 | _set_size_blocks = NBD_SET_SIZE_BLOCKS |
|
|
72 | _set_timeout = NBD_SET_TIMEOUT |
|
|
73 | _set_flags = NBD_SET_FLAGS |
75 | CODE: |
74 | CODE: |
76 | ioctl (dev, NBD_SET_SIZE, size); |
75 | ioctl (dev, ix, arg); |
77 | |
|
|
78 | void |
|
|
79 | _set_size_blocks (int dev, unsigned long nblocks) |
|
|
80 | CODE: |
|
|
81 | ioctl (dev, NBD_SET_SIZE_BLOCKS, nblocks); |
|
|
82 | |
|
|
83 | void |
|
|
84 | _set_timeout (int dev, unsigned long timeout) |
|
|
85 | CODE: |
|
|
86 | ioctl (dev, NBD_SET_TIMEOUT, timeout); |
|
|
87 | |
76 | |
88 | void |
77 | void |
89 | _print_debug (int dev) |
78 | _print_debug (int dev) |
90 | CODE: |
79 | CODE: |
91 | ioctl (dev, NBD_PRINT_DEBUG, 0); |
80 | ioctl (dev, NBD_PRINT_DEBUG, 0); |
… | |
… | |
98 | { |
87 | { |
99 | struct rstate *s; |
88 | struct rstate *s; |
100 | u64 from; |
89 | u64 from; |
101 | u32 len; |
90 | u32 len; |
102 | char *method; |
91 | char *method; |
|
|
92 | int cmd; |
103 | MAGIC *mg = mg_find (SvRV (obj), PERL_MAGIC_ext); |
93 | MAGIC *mg = mg_find (SvRV (obj), PERL_MAGIC_ext); |
104 | |
94 | |
105 | if (!mg) |
95 | if (!mg) |
106 | { |
96 | { |
107 | mg = sv_magicext (SvRV (obj), 0, PERL_MAGIC_ext, 0, 0, 0); |
97 | mg = sv_magicext (SvRV (obj), 0, PERL_MAGIC_ext, 0, 0, 0); |
… | |
… | |
134 | if (s->req.magic != htonl (NBD_REQUEST_MAGIC)) |
124 | if (s->req.magic != htonl (NBD_REQUEST_MAGIC)) |
135 | croak ("Linux::NBD::Server received illegal request magic %08lx - protocol error.\n", ntohl (s->req.magic)); |
125 | croak ("Linux::NBD::Server received illegal request magic %08lx - protocol error.\n", ntohl (s->req.magic)); |
136 | |
126 | |
137 | from = ntohll (s->req.from); |
127 | from = ntohll (s->req.from); |
138 | len = ntohl (s->req.len); |
128 | len = ntohl (s->req.len); |
|
|
129 | cmd = ntohl (s->req.type) & NBD_CMD_MASK_COMMAND; |
139 | |
130 | |
140 | switch (ntohl (s->req.type)) |
131 | switch (cmd) |
141 | { |
132 | { |
142 | case NBD_CMD_WRITE: |
133 | case NBD_CMD_WRITE: |
143 | if (!mg->mg_obj) |
134 | if (!mg->mg_obj) |
144 | { |
135 | { |
145 | mg->mg_flags |= MGf_REFCOUNTED; |
136 | mg->mg_flags |= MGf_REFCOUNTED; |
… | |
… | |
163 | XSRETURN_NO; |
154 | XSRETURN_NO; |
164 | } |
155 | } |
165 | |
156 | |
166 | /* fallthrough */ |
157 | /* fallthrough */ |
167 | case NBD_CMD_READ: |
158 | case NBD_CMD_READ: |
|
|
159 | case NBD_CMD_FLUSH: |
|
|
160 | case NBD_CMD_TRIM: |
|
|
161 | case NBD_CMD_WRITE_ZEROES: |
168 | s->req_read = 0; |
162 | s->req_read = 0; |
169 | |
163 | |
170 | PUSHMARK (SP); |
164 | PUSHMARK (SP); |
171 | EXTEND (SP, 4); |
165 | EXTEND (SP, 4); |
172 | PUSHs (obj); |
166 | PUSHs (obj); |
… | |
… | |
182 | method = "req_write"; |
176 | method = "req_write"; |
183 | } |
177 | } |
184 | else |
178 | else |
185 | { |
179 | { |
186 | PUSHs (sv_2mortal (newSVuv (len))); |
180 | PUSHs (sv_2mortal (newSVuv (len))); |
187 | method = "req_read"; |
181 | method = cmd == NBD_CMD_READ ? "req_read" |
|
|
182 | : cmd == NBD_CMD_FLUSH ? "req_flush" |
|
|
183 | : cmd == NBD_CMD_TRIM ? "req_trim" |
|
|
184 | : cmd == NBD_CMD_WRITE_ZEROES ? "req_write_zeroes" |
|
|
185 | : (abort (), ""); |
188 | } |
186 | } |
189 | |
187 | |
190 | break; |
188 | break; |
191 | |
189 | |
192 | case NBD_CMD_DISC: |
190 | case NBD_CMD_DISC: |
… | |
… | |
227 | |
225 | |
228 | RETVAL = newSVpvn ((char *)&rep, sizeof (rep)); |
226 | RETVAL = newSVpvn ((char *)&rep, sizeof (rep)); |
229 | |
227 | |
230 | if (data && !error) |
228 | if (data && !error) |
231 | sv_catsv (RETVAL, data); |
229 | sv_catsv (RETVAL, data); |
232 | } |
230 | } |
233 | OUTPUT: |
231 | OUTPUT: |
234 | RETVAL |
232 | RETVAL |
235 | |
233 | |