… | |
… | |
28 | _set_sock (int dev, int fd) |
28 | _set_sock (int dev, int fd) |
29 | CODE: |
29 | CODE: |
30 | ioctl (dev, NBD_SET_SOCK, (unsigned long)fd); |
30 | ioctl (dev, NBD_SET_SOCK, (unsigned long)fd); |
31 | |
31 | |
32 | void |
32 | void |
33 | _doit (int dev, int doexit = 0) |
33 | _doit (int dev, int server = 0) |
34 | CODE: |
34 | CODE: |
|
|
35 | if (server) |
|
|
36 | for (server = 0; server < 4095; server++) |
|
|
37 | if (server != dev) |
|
|
38 | close (server); |
|
|
39 | |
35 | ioctl (dev, NBD_DO_IT); |
40 | ioctl (dev, NBD_DO_IT); |
36 | if (doexit) |
41 | |
|
|
42 | if (server) |
37 | _exit (0); |
43 | _exit (0); |
38 | |
44 | |
39 | void |
45 | void |
40 | _disconnect (int dev) |
46 | _disconnect (int dev) |
41 | CODE: |
47 | CODE: |
… | |
… | |
69 | MODULE = Linux::NBD PACKAGE = Linux::NBD::Server |
75 | MODULE = Linux::NBD PACKAGE = Linux::NBD::Server |
70 | |
76 | |
71 | void |
77 | void |
72 | _one_request (SV *obj, int fd) |
78 | _one_request (SV *obj, int fd) |
73 | CODE: |
79 | CODE: |
|
|
80 | { |
74 | struct nbd_request req; |
81 | struct nbd_request req; |
75 | |
82 | |
76 | if (read (fd, &req, sizeof (req)) == sizeof (req)) |
83 | if (read (fd, &req, sizeof (req)) == sizeof (req)) |
77 | { |
84 | { |
78 | if (req.magic == htonl (NBD_REQUEST_MAGIC)) |
85 | if (req.magic == htonl (NBD_REQUEST_MAGIC)) |
79 | { |
86 | { |
|
|
87 | req.type = htonl (req.type); |
|
|
88 | |
80 | if (req.type < 2) |
89 | if (req.type < 2) |
81 | { |
90 | { |
82 | u64 from = ntohll (req.from); |
91 | u64 from = ntohll (req.from); |
83 | |
92 | |
84 | PUSHMARK (SP); |
93 | PUSHMARK (SP); |
… | |
… | |
97 | } |
106 | } |
98 | } |
107 | } |
99 | } |
108 | } |
100 | |
109 | |
101 | XSRETURN_YES; |
110 | XSRETURN_YES; |
|
|
111 | } |
102 | |
112 | |
103 | SV * |
113 | SV * |
104 | _format_reply (SV *handle, unsigned int error = 0, SV *data = 0) |
114 | _format_reply (SV *handle, unsigned int error = 0, SV *data = 0) |
105 | CODE: |
115 | CODE: |
|
|
116 | { |
106 | struct nbd_reply rep; |
117 | struct nbd_reply rep; |
107 | STRLEN len; |
118 | STRLEN len; |
108 | char *h = SvPV (handle, len); |
119 | char *h = SvPV (handle, len); |
109 | |
120 | |
110 | if (len != sizeof (rep.handle)) |
121 | if (len != sizeof (rep.handle)) |
… | |
… | |
116 | |
127 | |
117 | RETVAL = newSVpvn ((char *)&rep, sizeof (rep)); |
128 | RETVAL = newSVpvn ((char *)&rep, sizeof (rep)); |
118 | |
129 | |
119 | if (data && !error) |
130 | if (data && !error) |
120 | sv_catsv (RETVAL, data); |
131 | sv_catsv (RETVAL, data); |
121 | |
132 | } |
122 | OUTPUT: |
133 | OUTPUT: |
123 | RETVAL |
134 | RETVAL |
124 | |
135 | |