]>
Commit | Line | Data |
---|---|---|
c589b249 RS |
1 | /* |
2 | * QEMU Block driver for iSCSI images | |
3 | * | |
4 | * Copyright (c) 2010-2011 Ronnie Sahlberg <ronniesahlberg@gmail.com> | |
2af8a1a7 | 5 | * Copyright (c) 2012-2013 Peter Lieven <pl@kamp.de> |
c589b249 RS |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
23 | * THE SOFTWARE. | |
24 | */ | |
25 | ||
26 | #include "config-host.h" | |
27 | ||
28 | #include <poll.h> | |
f4dfa67f | 29 | #include <arpa/inet.h> |
c589b249 | 30 | #include "qemu-common.h" |
1de7afc9 PB |
31 | #include "qemu/config-file.h" |
32 | #include "qemu/error-report.h" | |
737e150e | 33 | #include "block/block_int.h" |
c589b249 | 34 | #include "trace.h" |
0d09e41a | 35 | #include "block/scsi.h" |
0a53f010 | 36 | #include "qemu/iov.h" |
5accc840 PB |
37 | #include "sysemu/sysemu.h" |
38 | #include "qmp-commands.h" | |
c589b249 RS |
39 | |
40 | #include <iscsi/iscsi.h> | |
41 | #include <iscsi/scsi-lowlevel.h> | |
42 | ||
98392453 RS |
43 | #ifdef __linux__ |
44 | #include <scsi/sg.h> | |
0d09e41a | 45 | #include <block/scsi.h> |
98392453 | 46 | #endif |
c589b249 RS |
47 | |
48 | typedef struct IscsiLun { | |
49 | struct iscsi_context *iscsi; | |
50 | int lun; | |
dbfff6d7 | 51 | enum scsi_inquiry_peripheral_device_type type; |
c589b249 | 52 | int block_size; |
c7b4a952 | 53 | uint64_t num_blocks; |
c9b9f682 | 54 | int events; |
5b5d34ec | 55 | QEMUTimer *nop_timer; |
f18a7cbb PL |
56 | uint8_t lbpme; |
57 | uint8_t lbprz; | |
fa6252b0 | 58 | uint8_t has_write_same; |
f18a7cbb PL |
59 | struct scsi_inquiry_logical_block_provisioning lbp; |
60 | struct scsi_inquiry_block_limits bl; | |
d4cd9615 | 61 | unsigned char *zeroblock; |
c589b249 RS |
62 | } IscsiLun; |
63 | ||
54a5c1d5 PL |
64 | typedef struct IscsiTask { |
65 | int status; | |
66 | int complete; | |
67 | int retries; | |
68 | int do_retry; | |
69 | struct scsi_task *task; | |
70 | Coroutine *co; | |
8b9dfe90 | 71 | QEMUBH *bh; |
54a5c1d5 PL |
72 | } IscsiTask; |
73 | ||
c589b249 RS |
74 | typedef struct IscsiAIOCB { |
75 | BlockDriverAIOCB common; | |
76 | QEMUIOVector *qiov; | |
77 | QEMUBH *bh; | |
78 | IscsiLun *iscsilun; | |
79 | struct scsi_task *task; | |
80 | uint8_t *buf; | |
81 | int status; | |
82 | int canceled; | |
1dde716e | 83 | int retries; |
1dde716e PL |
84 | int64_t sector_num; |
85 | int nb_sectors; | |
98392453 RS |
86 | #ifdef __linux__ |
87 | sg_io_hdr_t *ioh; | |
88 | #endif | |
c589b249 RS |
89 | } IscsiAIOCB; |
90 | ||
5b5d34ec PL |
91 | #define NOP_INTERVAL 5000 |
92 | #define MAX_NOP_FAILURES 3 | |
1dde716e | 93 | #define ISCSI_CMD_RETRIES 5 |
5b5d34ec | 94 | |
27cbd828 | 95 | static void |
cfb3f506 | 96 | iscsi_bh_cb(void *p) |
27cbd828 PB |
97 | { |
98 | IscsiAIOCB *acb = p; | |
99 | ||
100 | qemu_bh_delete(acb->bh); | |
101 | ||
4790b03d PB |
102 | g_free(acb->buf); |
103 | acb->buf = NULL; | |
104 | ||
27cbd828 PB |
105 | if (acb->canceled == 0) { |
106 | acb->common.cb(acb->common.opaque, acb->status); | |
107 | } | |
108 | ||
1bd075f2 PB |
109 | if (acb->task != NULL) { |
110 | scsi_free_scsi_task(acb->task); | |
111 | acb->task = NULL; | |
112 | } | |
113 | ||
27cbd828 PB |
114 | qemu_aio_release(acb); |
115 | } | |
116 | ||
cfb3f506 PB |
117 | static void |
118 | iscsi_schedule_bh(IscsiAIOCB *acb) | |
27cbd828 | 119 | { |
1bd075f2 PB |
120 | if (acb->bh) { |
121 | return; | |
122 | } | |
cfb3f506 | 123 | acb->bh = qemu_bh_new(iscsi_bh_cb, acb); |
27cbd828 | 124 | qemu_bh_schedule(acb->bh); |
27cbd828 PB |
125 | } |
126 | ||
8b9dfe90 PL |
127 | static void iscsi_co_generic_bh_cb(void *opaque) |
128 | { | |
129 | struct IscsiTask *iTask = opaque; | |
130 | qemu_bh_delete(iTask->bh); | |
131 | qemu_coroutine_enter(iTask->co, NULL); | |
132 | } | |
133 | ||
54a5c1d5 PL |
134 | static void |
135 | iscsi_co_generic_cb(struct iscsi_context *iscsi, int status, | |
136 | void *command_data, void *opaque) | |
137 | { | |
138 | struct IscsiTask *iTask = opaque; | |
139 | struct scsi_task *task = command_data; | |
140 | ||
141 | iTask->complete = 1; | |
142 | iTask->status = status; | |
143 | iTask->do_retry = 0; | |
144 | iTask->task = task; | |
145 | ||
146 | if (iTask->retries-- > 0 && status == SCSI_STATUS_CHECK_CONDITION | |
147 | && task->sense.key == SCSI_SENSE_UNIT_ATTENTION) { | |
837c3901 | 148 | error_report("iSCSI CheckCondition: %s", iscsi_get_error(iscsi)); |
54a5c1d5 PL |
149 | iTask->do_retry = 1; |
150 | goto out; | |
151 | } | |
152 | ||
153 | if (status != SCSI_STATUS_GOOD) { | |
837c3901 | 154 | error_report("iSCSI Failure: %s", iscsi_get_error(iscsi)); |
54a5c1d5 PL |
155 | } |
156 | ||
157 | out: | |
158 | if (iTask->co) { | |
8b9dfe90 PL |
159 | iTask->bh = qemu_bh_new(iscsi_co_generic_bh_cb, iTask); |
160 | qemu_bh_schedule(iTask->bh); | |
54a5c1d5 PL |
161 | } |
162 | } | |
163 | ||
164 | static void iscsi_co_init_iscsitask(IscsiLun *iscsilun, struct IscsiTask *iTask) | |
165 | { | |
166 | *iTask = (struct IscsiTask) { | |
167 | .co = qemu_coroutine_self(), | |
168 | .retries = ISCSI_CMD_RETRIES, | |
169 | }; | |
170 | } | |
27cbd828 | 171 | |
c589b249 RS |
172 | static void |
173 | iscsi_abort_task_cb(struct iscsi_context *iscsi, int status, void *command_data, | |
174 | void *private_data) | |
175 | { | |
1bd075f2 PB |
176 | IscsiAIOCB *acb = private_data; |
177 | ||
178 | acb->status = -ECANCELED; | |
179 | iscsi_schedule_bh(acb); | |
c589b249 RS |
180 | } |
181 | ||
182 | static void | |
183 | iscsi_aio_cancel(BlockDriverAIOCB *blockacb) | |
184 | { | |
185 | IscsiAIOCB *acb = (IscsiAIOCB *)blockacb; | |
186 | IscsiLun *iscsilun = acb->iscsilun; | |
187 | ||
1bd075f2 PB |
188 | if (acb->status != -EINPROGRESS) { |
189 | return; | |
190 | } | |
191 | ||
b2090919 | 192 | acb->canceled = 1; |
c589b249 | 193 | |
b2090919 | 194 | /* send a task mgmt call to the target to cancel the task on the target */ |
64e69e80 | 195 | iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task, |
1bd075f2 | 196 | iscsi_abort_task_cb, acb); |
b2090919 | 197 | |
1bd075f2 PB |
198 | while (acb->status == -EINPROGRESS) { |
199 | qemu_aio_wait(); | |
200 | } | |
c589b249 RS |
201 | } |
202 | ||
d7331bed | 203 | static const AIOCBInfo iscsi_aiocb_info = { |
c589b249 RS |
204 | .aiocb_size = sizeof(IscsiAIOCB), |
205 | .cancel = iscsi_aio_cancel, | |
206 | }; | |
207 | ||
208 | ||
209 | static void iscsi_process_read(void *arg); | |
210 | static void iscsi_process_write(void *arg); | |
211 | ||
c589b249 RS |
212 | static void |
213 | iscsi_set_events(IscsiLun *iscsilun) | |
214 | { | |
215 | struct iscsi_context *iscsi = iscsilun->iscsi; | |
c9b9f682 RS |
216 | int ev; |
217 | ||
218 | /* We always register a read handler. */ | |
219 | ev = POLLIN; | |
220 | ev |= iscsi_which_events(iscsi); | |
221 | if (ev != iscsilun->events) { | |
222 | qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), | |
223 | iscsi_process_read, | |
224 | (ev & POLLOUT) ? iscsi_process_write : NULL, | |
c9b9f682 RS |
225 | iscsilun); |
226 | ||
227 | } | |
228 | ||
c9b9f682 | 229 | iscsilun->events = ev; |
c589b249 RS |
230 | } |
231 | ||
232 | static void | |
233 | iscsi_process_read(void *arg) | |
234 | { | |
235 | IscsiLun *iscsilun = arg; | |
236 | struct iscsi_context *iscsi = iscsilun->iscsi; | |
237 | ||
238 | iscsi_service(iscsi, POLLIN); | |
239 | iscsi_set_events(iscsilun); | |
240 | } | |
241 | ||
242 | static void | |
243 | iscsi_process_write(void *arg) | |
244 | { | |
245 | IscsiLun *iscsilun = arg; | |
246 | struct iscsi_context *iscsi = iscsilun->iscsi; | |
247 | ||
248 | iscsi_service(iscsi, POLLOUT); | |
249 | iscsi_set_events(iscsilun); | |
250 | } | |
251 | ||
0777b5dd PL |
252 | static int64_t sector_lun2qemu(int64_t sector, IscsiLun *iscsilun) |
253 | { | |
254 | return sector * iscsilun->block_size / BDRV_SECTOR_SIZE; | |
255 | } | |
256 | ||
c589b249 RS |
257 | static int64_t sector_qemu2lun(int64_t sector, IscsiLun *iscsilun) |
258 | { | |
259 | return sector * BDRV_SECTOR_SIZE / iscsilun->block_size; | |
260 | } | |
261 | ||
91bea4e2 PL |
262 | static bool is_request_lun_aligned(int64_t sector_num, int nb_sectors, |
263 | IscsiLun *iscsilun) | |
264 | { | |
265 | if ((sector_num * BDRV_SECTOR_SIZE) % iscsilun->block_size || | |
266 | (nb_sectors * BDRV_SECTOR_SIZE) % iscsilun->block_size) { | |
f5075224 RJ |
267 | error_report("iSCSI misaligned request: " |
268 | "iscsilun->block_size %u, sector_num %" PRIi64 | |
269 | ", nb_sectors %d", | |
91bea4e2 PL |
270 | iscsilun->block_size, sector_num, nb_sectors); |
271 | return 0; | |
272 | } | |
273 | return 1; | |
274 | } | |
275 | ||
063c3378 PL |
276 | static int coroutine_fn iscsi_co_writev(BlockDriverState *bs, |
277 | int64_t sector_num, int nb_sectors, | |
278 | QEMUIOVector *iov) | |
c589b249 | 279 | { |
063c3378 PL |
280 | IscsiLun *iscsilun = bs->opaque; |
281 | struct IscsiTask iTask; | |
f4dfa67f | 282 | uint64_t lba; |
063c3378 PL |
283 | uint32_t num_sectors; |
284 | uint8_t *data = NULL; | |
285 | uint8_t *buf = NULL; | |
c589b249 | 286 | |
063c3378 PL |
287 | if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) { |
288 | return -EINVAL; | |
289 | } | |
7371d56f | 290 | |
063c3378 PL |
291 | lba = sector_qemu2lun(sector_num, iscsilun); |
292 | num_sectors = sector_qemu2lun(nb_sectors, iscsilun); | |
7371d56f | 293 | #if !defined(LIBISCSI_FEATURE_IOVECTOR) |
4cc841b5 | 294 | /* if the iovec only contains one buffer we can pass it directly */ |
063c3378 PL |
295 | if (iov->niov == 1) { |
296 | data = iov->iov[0].iov_base; | |
4cc841b5 | 297 | } else { |
063c3378 PL |
298 | size_t size = MIN(nb_sectors * BDRV_SECTOR_SIZE, iov->size); |
299 | buf = g_malloc(size); | |
300 | qemu_iovec_to_buf(iov, 0, buf, size); | |
301 | data = buf; | |
4cc841b5 | 302 | } |
7371d56f | 303 | #endif |
063c3378 PL |
304 | iscsi_co_init_iscsitask(iscsilun, &iTask); |
305 | retry: | |
306 | iTask.task = iscsi_write16_task(iscsilun->iscsi, iscsilun->lun, lba, | |
307 | data, num_sectors * iscsilun->block_size, | |
308 | iscsilun->block_size, 0, 0, 0, 0, 0, | |
309 | iscsi_co_generic_cb, &iTask); | |
310 | if (iTask.task == NULL) { | |
311 | g_free(buf); | |
92397116 | 312 | return -ENOMEM; |
f4dfa67f | 313 | } |
7371d56f | 314 | #if defined(LIBISCSI_FEATURE_IOVECTOR) |
063c3378 PL |
315 | scsi_task_set_iov_out(iTask.task, (struct scsi_iovec *) iov->iov, |
316 | iov->niov); | |
7371d56f | 317 | #endif |
063c3378 PL |
318 | while (!iTask.complete) { |
319 | iscsi_set_events(iscsilun); | |
320 | qemu_coroutine_yield(); | |
c589b249 RS |
321 | } |
322 | ||
063c3378 PL |
323 | if (iTask.task != NULL) { |
324 | scsi_free_scsi_task(iTask.task); | |
325 | iTask.task = NULL; | |
91bea4e2 PL |
326 | } |
327 | ||
063c3378 | 328 | if (iTask.do_retry) { |
837c3901 | 329 | iTask.complete = 0; |
063c3378 | 330 | goto retry; |
1dde716e PL |
331 | } |
332 | ||
063c3378 | 333 | g_free(buf); |
c589b249 | 334 | |
063c3378 PL |
335 | if (iTask.status != SCSI_STATUS_GOOD) { |
336 | return -EIO; | |
c589b249 RS |
337 | } |
338 | ||
063c3378 | 339 | return 0; |
c589b249 RS |
340 | } |
341 | ||
063c3378 PL |
342 | static int coroutine_fn iscsi_co_readv(BlockDriverState *bs, |
343 | int64_t sector_num, int nb_sectors, | |
344 | QEMUIOVector *iov) | |
c589b249 | 345 | { |
063c3378 PL |
346 | IscsiLun *iscsilun = bs->opaque; |
347 | struct IscsiTask iTask; | |
1dde716e PL |
348 | uint64_t lba; |
349 | uint32_t num_sectors; | |
7371d56f | 350 | #if !defined(LIBISCSI_FEATURE_IOVECTOR) |
c589b249 | 351 | int i; |
7371d56f | 352 | #endif |
c589b249 | 353 | |
063c3378 PL |
354 | if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) { |
355 | return -EINVAL; | |
f4dfa67f | 356 | } |
f4dfa67f | 357 | |
063c3378 PL |
358 | lba = sector_qemu2lun(sector_num, iscsilun); |
359 | num_sectors = sector_qemu2lun(nb_sectors, iscsilun); | |
f4dfa67f | 360 | |
063c3378 PL |
361 | iscsi_co_init_iscsitask(iscsilun, &iTask); |
362 | retry: | |
363 | switch (iscsilun->type) { | |
f4dfa67f | 364 | case TYPE_DISK: |
063c3378 PL |
365 | iTask.task = iscsi_read16_task(iscsilun->iscsi, iscsilun->lun, lba, |
366 | num_sectors * iscsilun->block_size, | |
367 | iscsilun->block_size, 0, 0, 0, 0, 0, | |
368 | iscsi_co_generic_cb, &iTask); | |
f4dfa67f RS |
369 | break; |
370 | default: | |
063c3378 PL |
371 | iTask.task = iscsi_read10_task(iscsilun->iscsi, iscsilun->lun, lba, |
372 | num_sectors * iscsilun->block_size, | |
219c2521 SW |
373 | iscsilun->block_size, |
374 | #if !defined(CONFIG_LIBISCSI_1_4) /* API change from 1.4.0 to 1.5.0 */ | |
375 | 0, 0, 0, 0, 0, | |
376 | #endif | |
063c3378 | 377 | iscsi_co_generic_cb, &iTask); |
f4dfa67f RS |
378 | break; |
379 | } | |
063c3378 | 380 | if (iTask.task == NULL) { |
92397116 | 381 | return -ENOMEM; |
c589b249 | 382 | } |
7371d56f | 383 | #if defined(LIBISCSI_FEATURE_IOVECTOR) |
063c3378 | 384 | scsi_task_set_iov_in(iTask.task, (struct scsi_iovec *) iov->iov, iov->niov); |
7371d56f | 385 | #else |
063c3378 PL |
386 | for (i = 0; i < iov->niov; i++) { |
387 | scsi_task_add_data_in_buffer(iTask.task, | |
388 | iov->iov[i].iov_len, | |
389 | iov->iov[i].iov_base); | |
c589b249 | 390 | } |
7371d56f | 391 | #endif |
91bea4e2 | 392 | |
063c3378 PL |
393 | while (!iTask.complete) { |
394 | iscsi_set_events(iscsilun); | |
395 | qemu_coroutine_yield(); | |
1dde716e | 396 | } |
c589b249 | 397 | |
063c3378 PL |
398 | if (iTask.task != NULL) { |
399 | scsi_free_scsi_task(iTask.task); | |
400 | iTask.task = NULL; | |
c589b249 RS |
401 | } |
402 | ||
063c3378 | 403 | if (iTask.do_retry) { |
837c3901 | 404 | iTask.complete = 0; |
063c3378 | 405 | goto retry; |
c589b249 RS |
406 | } |
407 | ||
063c3378 PL |
408 | if (iTask.status != SCSI_STATUS_GOOD) { |
409 | return -EIO; | |
1dde716e PL |
410 | } |
411 | ||
412 | return 0; | |
413 | } | |
414 | ||
063c3378 | 415 | static int coroutine_fn iscsi_co_flush(BlockDriverState *bs) |
1dde716e PL |
416 | { |
417 | IscsiLun *iscsilun = bs->opaque; | |
063c3378 | 418 | struct IscsiTask iTask; |
1dde716e | 419 | |
063c3378 | 420 | iscsi_co_init_iscsitask(iscsilun, &iTask); |
1dde716e | 421 | |
063c3378 PL |
422 | retry: |
423 | if (iscsi_synchronizecache10_task(iscsilun->iscsi, iscsilun->lun, 0, 0, 0, | |
424 | 0, iscsi_co_generic_cb, &iTask) == NULL) { | |
92397116 | 425 | return -ENOMEM; |
063c3378 | 426 | } |
1dde716e | 427 | |
063c3378 PL |
428 | while (!iTask.complete) { |
429 | iscsi_set_events(iscsilun); | |
430 | qemu_coroutine_yield(); | |
431 | } | |
1dde716e | 432 | |
063c3378 PL |
433 | if (iTask.task != NULL) { |
434 | scsi_free_scsi_task(iTask.task); | |
435 | iTask.task = NULL; | |
c589b249 RS |
436 | } |
437 | ||
063c3378 | 438 | if (iTask.do_retry) { |
837c3901 | 439 | iTask.complete = 0; |
063c3378 PL |
440 | goto retry; |
441 | } | |
c589b249 | 442 | |
063c3378 PL |
443 | if (iTask.status != SCSI_STATUS_GOOD) { |
444 | return -EIO; | |
445 | } | |
446 | ||
447 | return 0; | |
c589b249 RS |
448 | } |
449 | ||
98392453 RS |
450 | #ifdef __linux__ |
451 | static void | |
452 | iscsi_aio_ioctl_cb(struct iscsi_context *iscsi, int status, | |
453 | void *command_data, void *opaque) | |
454 | { | |
455 | IscsiAIOCB *acb = opaque; | |
456 | ||
0a53f010 RS |
457 | g_free(acb->buf); |
458 | acb->buf = NULL; | |
459 | ||
b2090919 | 460 | if (acb->canceled != 0) { |
98392453 RS |
461 | return; |
462 | } | |
463 | ||
464 | acb->status = 0; | |
465 | if (status < 0) { | |
466 | error_report("Failed to ioctl(SG_IO) to iSCSI lun. %s", | |
467 | iscsi_get_error(iscsi)); | |
468 | acb->status = -EIO; | |
469 | } | |
470 | ||
471 | acb->ioh->driver_status = 0; | |
472 | acb->ioh->host_status = 0; | |
473 | acb->ioh->resid = 0; | |
474 | ||
475 | #define SG_ERR_DRIVER_SENSE 0x08 | |
476 | ||
477 | if (status == SCSI_STATUS_CHECK_CONDITION && acb->task->datain.size >= 2) { | |
478 | int ss; | |
479 | ||
480 | acb->ioh->driver_status |= SG_ERR_DRIVER_SENSE; | |
481 | ||
482 | acb->ioh->sb_len_wr = acb->task->datain.size - 2; | |
483 | ss = (acb->ioh->mx_sb_len >= acb->ioh->sb_len_wr) ? | |
484 | acb->ioh->mx_sb_len : acb->ioh->sb_len_wr; | |
485 | memcpy(acb->ioh->sbp, &acb->task->datain.data[2], ss); | |
486 | } | |
487 | ||
cfb3f506 | 488 | iscsi_schedule_bh(acb); |
98392453 RS |
489 | } |
490 | ||
491 | static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, | |
492 | unsigned long int req, void *buf, | |
493 | BlockDriverCompletionFunc *cb, void *opaque) | |
494 | { | |
495 | IscsiLun *iscsilun = bs->opaque; | |
496 | struct iscsi_context *iscsi = iscsilun->iscsi; | |
497 | struct iscsi_data data; | |
498 | IscsiAIOCB *acb; | |
499 | ||
500 | assert(req == SG_IO); | |
501 | ||
d7331bed | 502 | acb = qemu_aio_get(&iscsi_aiocb_info, bs, cb, opaque); |
98392453 RS |
503 | |
504 | acb->iscsilun = iscsilun; | |
505 | acb->canceled = 0; | |
1bd075f2 PB |
506 | acb->bh = NULL; |
507 | acb->status = -EINPROGRESS; | |
98392453 RS |
508 | acb->buf = NULL; |
509 | acb->ioh = buf; | |
510 | ||
511 | acb->task = malloc(sizeof(struct scsi_task)); | |
512 | if (acb->task == NULL) { | |
513 | error_report("iSCSI: Failed to allocate task for scsi command. %s", | |
514 | iscsi_get_error(iscsi)); | |
515 | qemu_aio_release(acb); | |
516 | return NULL; | |
517 | } | |
518 | memset(acb->task, 0, sizeof(struct scsi_task)); | |
519 | ||
520 | switch (acb->ioh->dxfer_direction) { | |
521 | case SG_DXFER_TO_DEV: | |
522 | acb->task->xfer_dir = SCSI_XFER_WRITE; | |
523 | break; | |
524 | case SG_DXFER_FROM_DEV: | |
525 | acb->task->xfer_dir = SCSI_XFER_READ; | |
526 | break; | |
527 | default: | |
528 | acb->task->xfer_dir = SCSI_XFER_NONE; | |
529 | break; | |
530 | } | |
531 | ||
532 | acb->task->cdb_size = acb->ioh->cmd_len; | |
533 | memcpy(&acb->task->cdb[0], acb->ioh->cmdp, acb->ioh->cmd_len); | |
534 | acb->task->expxferlen = acb->ioh->dxfer_len; | |
535 | ||
0a53f010 | 536 | data.size = 0; |
98392453 | 537 | if (acb->task->xfer_dir == SCSI_XFER_WRITE) { |
0a53f010 RS |
538 | if (acb->ioh->iovec_count == 0) { |
539 | data.data = acb->ioh->dxferp; | |
540 | data.size = acb->ioh->dxfer_len; | |
541 | } else { | |
542 | #if defined(LIBISCSI_FEATURE_IOVECTOR) | |
543 | scsi_task_set_iov_out(acb->task, | |
544 | (struct scsi_iovec *) acb->ioh->dxferp, | |
545 | acb->ioh->iovec_count); | |
546 | #else | |
547 | struct iovec *iov = (struct iovec *)acb->ioh->dxferp; | |
548 | ||
549 | acb->buf = g_malloc(acb->ioh->dxfer_len); | |
550 | data.data = acb->buf; | |
551 | data.size = iov_to_buf(iov, acb->ioh->iovec_count, 0, | |
552 | acb->buf, acb->ioh->dxfer_len); | |
553 | #endif | |
554 | } | |
98392453 | 555 | } |
0a53f010 | 556 | |
98392453 RS |
557 | if (iscsi_scsi_command_async(iscsi, iscsilun->lun, acb->task, |
558 | iscsi_aio_ioctl_cb, | |
0a53f010 | 559 | (data.size > 0) ? &data : NULL, |
98392453 RS |
560 | acb) != 0) { |
561 | scsi_free_scsi_task(acb->task); | |
562 | qemu_aio_release(acb); | |
563 | return NULL; | |
564 | } | |
565 | ||
566 | /* tell libiscsi to read straight into the buffer we got from ioctl */ | |
567 | if (acb->task->xfer_dir == SCSI_XFER_READ) { | |
0a53f010 RS |
568 | if (acb->ioh->iovec_count == 0) { |
569 | scsi_task_add_data_in_buffer(acb->task, | |
570 | acb->ioh->dxfer_len, | |
571 | acb->ioh->dxferp); | |
572 | } else { | |
573 | #if defined(LIBISCSI_FEATURE_IOVECTOR) | |
574 | scsi_task_set_iov_in(acb->task, | |
575 | (struct scsi_iovec *) acb->ioh->dxferp, | |
576 | acb->ioh->iovec_count); | |
577 | #else | |
578 | int i; | |
579 | for (i = 0; i < acb->ioh->iovec_count; i++) { | |
580 | struct iovec *iov = (struct iovec *)acb->ioh->dxferp; | |
581 | ||
582 | scsi_task_add_data_in_buffer(acb->task, | |
583 | iov[i].iov_len, | |
584 | iov[i].iov_base); | |
585 | } | |
586 | #endif | |
587 | } | |
98392453 RS |
588 | } |
589 | ||
590 | iscsi_set_events(iscsilun); | |
591 | ||
592 | return &acb->common; | |
593 | } | |
594 | ||
f1a12821 RS |
595 | |
596 | static void ioctl_cb(void *opaque, int status) | |
597 | { | |
598 | int *p_status = opaque; | |
599 | *p_status = status; | |
600 | } | |
601 | ||
98392453 RS |
602 | static int iscsi_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) |
603 | { | |
604 | IscsiLun *iscsilun = bs->opaque; | |
f1a12821 | 605 | int status; |
98392453 RS |
606 | |
607 | switch (req) { | |
608 | case SG_GET_VERSION_NUM: | |
609 | *(int *)buf = 30000; | |
610 | break; | |
611 | case SG_GET_SCSI_ID: | |
612 | ((struct sg_scsi_id *)buf)->scsi_type = iscsilun->type; | |
613 | break; | |
f1a12821 RS |
614 | case SG_IO: |
615 | status = -EINPROGRESS; | |
616 | iscsi_aio_ioctl(bs, req, buf, ioctl_cb, &status); | |
617 | ||
618 | while (status == -EINPROGRESS) { | |
619 | qemu_aio_wait(); | |
620 | } | |
621 | ||
622 | return 0; | |
98392453 RS |
623 | default: |
624 | return -1; | |
625 | } | |
626 | return 0; | |
627 | } | |
628 | #endif | |
629 | ||
c589b249 RS |
630 | static int64_t |
631 | iscsi_getlength(BlockDriverState *bs) | |
632 | { | |
633 | IscsiLun *iscsilun = bs->opaque; | |
634 | int64_t len; | |
635 | ||
636 | len = iscsilun->num_blocks; | |
637 | len *= iscsilun->block_size; | |
638 | ||
639 | return len; | |
640 | } | |
641 | ||
24c7608a | 642 | #if defined(LIBISCSI_FEATURE_IOVECTOR) |
f35c934a | 643 | |
54a5c1d5 PL |
644 | static int64_t coroutine_fn iscsi_co_get_block_status(BlockDriverState *bs, |
645 | int64_t sector_num, | |
646 | int nb_sectors, int *pnum) | |
647 | { | |
648 | IscsiLun *iscsilun = bs->opaque; | |
649 | struct scsi_get_lba_status *lbas = NULL; | |
650 | struct scsi_lba_status_descriptor *lbasd = NULL; | |
651 | struct IscsiTask iTask; | |
652 | int64_t ret; | |
653 | ||
654 | iscsi_co_init_iscsitask(iscsilun, &iTask); | |
655 | ||
656 | if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) { | |
657 | ret = -EINVAL; | |
658 | goto out; | |
659 | } | |
660 | ||
661 | /* default to all sectors allocated */ | |
662 | ret = BDRV_BLOCK_DATA; | |
663 | ret |= (sector_num << BDRV_SECTOR_BITS) | BDRV_BLOCK_OFFSET_VALID; | |
664 | *pnum = nb_sectors; | |
665 | ||
666 | /* LUN does not support logical block provisioning */ | |
667 | if (iscsilun->lbpme == 0) { | |
668 | goto out; | |
669 | } | |
670 | ||
671 | retry: | |
672 | if (iscsi_get_lba_status_task(iscsilun->iscsi, iscsilun->lun, | |
673 | sector_qemu2lun(sector_num, iscsilun), | |
674 | 8 + 16, iscsi_co_generic_cb, | |
675 | &iTask) == NULL) { | |
92397116 | 676 | ret = -ENOMEM; |
54a5c1d5 PL |
677 | goto out; |
678 | } | |
679 | ||
680 | while (!iTask.complete) { | |
681 | iscsi_set_events(iscsilun); | |
682 | qemu_coroutine_yield(); | |
683 | } | |
684 | ||
685 | if (iTask.do_retry) { | |
686 | if (iTask.task != NULL) { | |
687 | scsi_free_scsi_task(iTask.task); | |
688 | iTask.task = NULL; | |
689 | } | |
837c3901 | 690 | iTask.complete = 0; |
54a5c1d5 PL |
691 | goto retry; |
692 | } | |
693 | ||
694 | if (iTask.status != SCSI_STATUS_GOOD) { | |
695 | /* in case the get_lba_status_callout fails (i.e. | |
696 | * because the device is busy or the cmd is not | |
697 | * supported) we pretend all blocks are allocated | |
73f395fa | 698 | * for backwards compatibility */ |
54a5c1d5 PL |
699 | goto out; |
700 | } | |
701 | ||
702 | lbas = scsi_datain_unmarshall(iTask.task); | |
703 | if (lbas == NULL) { | |
704 | ret = -EIO; | |
705 | goto out; | |
706 | } | |
707 | ||
708 | lbasd = &lbas->descriptors[0]; | |
709 | ||
710 | if (sector_qemu2lun(sector_num, iscsilun) != lbasd->lba) { | |
711 | ret = -EIO; | |
712 | goto out; | |
713 | } | |
714 | ||
715 | *pnum = sector_lun2qemu(lbasd->num_blocks, iscsilun); | |
716 | if (*pnum > nb_sectors) { | |
717 | *pnum = nb_sectors; | |
718 | } | |
719 | ||
720 | if (lbasd->provisioning == SCSI_PROVISIONING_TYPE_DEALLOCATED || | |
721 | lbasd->provisioning == SCSI_PROVISIONING_TYPE_ANCHORED) { | |
722 | ret &= ~BDRV_BLOCK_DATA; | |
723 | if (iscsilun->lbprz) { | |
724 | ret |= BDRV_BLOCK_ZERO; | |
725 | } | |
726 | } | |
727 | ||
728 | out: | |
729 | if (iTask.task != NULL) { | |
730 | scsi_free_scsi_task(iTask.task); | |
731 | } | |
732 | return ret; | |
733 | } | |
734 | ||
24c7608a | 735 | #endif /* LIBISCSI_FEATURE_IOVECTOR */ |
f35c934a | 736 | |
65f3e339 PL |
737 | static int |
738 | coroutine_fn iscsi_co_discard(BlockDriverState *bs, int64_t sector_num, | |
739 | int nb_sectors) | |
740 | { | |
741 | IscsiLun *iscsilun = bs->opaque; | |
742 | struct IscsiTask iTask; | |
743 | struct unmap_list list; | |
65f3e339 PL |
744 | |
745 | if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) { | |
746 | return -EINVAL; | |
747 | } | |
748 | ||
749 | if (!iscsilun->lbp.lbpu) { | |
750 | /* UNMAP is not supported by the target */ | |
751 | return 0; | |
752 | } | |
753 | ||
754 | list.lba = sector_qemu2lun(sector_num, iscsilun); | |
01a6a238 | 755 | list.num = sector_qemu2lun(nb_sectors, iscsilun); |
65f3e339 | 756 | |
01a6a238 | 757 | iscsi_co_init_iscsitask(iscsilun, &iTask); |
65f3e339 | 758 | retry: |
01a6a238 PL |
759 | if (iscsi_unmap_task(iscsilun->iscsi, iscsilun->lun, 0, 0, &list, 1, |
760 | iscsi_co_generic_cb, &iTask) == NULL) { | |
92397116 | 761 | return -ENOMEM; |
01a6a238 | 762 | } |
65f3e339 | 763 | |
01a6a238 PL |
764 | while (!iTask.complete) { |
765 | iscsi_set_events(iscsilun); | |
766 | qemu_coroutine_yield(); | |
767 | } | |
65f3e339 | 768 | |
01a6a238 PL |
769 | if (iTask.task != NULL) { |
770 | scsi_free_scsi_task(iTask.task); | |
771 | iTask.task = NULL; | |
772 | } | |
65f3e339 | 773 | |
01a6a238 | 774 | if (iTask.do_retry) { |
837c3901 | 775 | iTask.complete = 0; |
01a6a238 PL |
776 | goto retry; |
777 | } | |
65f3e339 | 778 | |
01a6a238 PL |
779 | if (iTask.status == SCSI_STATUS_CHECK_CONDITION) { |
780 | /* the target might fail with a check condition if it | |
781 | is not happy with the alignment of the UNMAP request | |
782 | we silently fail in this case */ | |
783 | return 0; | |
784 | } | |
65f3e339 | 785 | |
01a6a238 PL |
786 | if (iTask.status != SCSI_STATUS_GOOD) { |
787 | return -EIO; | |
65f3e339 PL |
788 | } |
789 | ||
790 | return 0; | |
791 | } | |
792 | ||
d4cd9615 PL |
793 | #if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED) |
794 | ||
795 | static int | |
796 | coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num, | |
797 | int nb_sectors, BdrvRequestFlags flags) | |
798 | { | |
799 | IscsiLun *iscsilun = bs->opaque; | |
800 | struct IscsiTask iTask; | |
801 | uint64_t lba; | |
802 | uint32_t nb_blocks; | |
803 | ||
804 | if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) { | |
805 | return -EINVAL; | |
806 | } | |
807 | ||
fa6252b0 PB |
808 | if (!(flags & BDRV_REQ_MAY_UNMAP) && !iscsilun->has_write_same) { |
809 | /* WRITE SAME without UNMAP is not supported by the target */ | |
810 | return -ENOTSUP; | |
811 | } | |
812 | ||
813 | if ((flags & BDRV_REQ_MAY_UNMAP) && !iscsilun->lbp.lbpws) { | |
814 | /* WRITE SAME with UNMAP is not supported by the target */ | |
d4cd9615 PL |
815 | return -ENOTSUP; |
816 | } | |
817 | ||
818 | lba = sector_qemu2lun(sector_num, iscsilun); | |
819 | nb_blocks = sector_qemu2lun(nb_sectors, iscsilun); | |
820 | ||
821 | if (iscsilun->zeroblock == NULL) { | |
822 | iscsilun->zeroblock = g_malloc0(iscsilun->block_size); | |
823 | } | |
824 | ||
825 | iscsi_co_init_iscsitask(iscsilun, &iTask); | |
826 | retry: | |
827 | if (iscsi_writesame16_task(iscsilun->iscsi, iscsilun->lun, lba, | |
828 | iscsilun->zeroblock, iscsilun->block_size, | |
829 | nb_blocks, 0, !!(flags & BDRV_REQ_MAY_UNMAP), | |
830 | 0, 0, iscsi_co_generic_cb, &iTask) == NULL) { | |
92397116 | 831 | return -ENOMEM; |
d4cd9615 PL |
832 | } |
833 | ||
834 | while (!iTask.complete) { | |
835 | iscsi_set_events(iscsilun); | |
836 | qemu_coroutine_yield(); | |
837 | } | |
838 | ||
839 | if (iTask.task != NULL) { | |
840 | scsi_free_scsi_task(iTask.task); | |
841 | iTask.task = NULL; | |
842 | } | |
843 | ||
844 | if (iTask.do_retry) { | |
837c3901 | 845 | iTask.complete = 0; |
d4cd9615 PL |
846 | goto retry; |
847 | } | |
848 | ||
849 | if (iTask.status != SCSI_STATUS_GOOD) { | |
fa6252b0 PB |
850 | if (iTask.status == SCSI_STATUS_CHECK_CONDITION && |
851 | iTask.task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST && | |
852 | iTask.task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { | |
853 | /* WRITE SAME is not supported by the target */ | |
854 | iscsilun->has_write_same = false; | |
855 | return -ENOTSUP; | |
856 | } | |
857 | ||
d4cd9615 PL |
858 | return -EIO; |
859 | } | |
860 | ||
861 | return 0; | |
862 | } | |
863 | ||
864 | #endif /* SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED */ | |
865 | ||
f2917853 PB |
866 | static void parse_chap(struct iscsi_context *iscsi, const char *target, |
867 | Error **errp) | |
f9dadc98 RS |
868 | { |
869 | QemuOptsList *list; | |
870 | QemuOpts *opts; | |
871 | const char *user = NULL; | |
872 | const char *password = NULL; | |
873 | ||
874 | list = qemu_find_opts("iscsi"); | |
875 | if (!list) { | |
f2917853 | 876 | return; |
f9dadc98 RS |
877 | } |
878 | ||
879 | opts = qemu_opts_find(list, target); | |
880 | if (opts == NULL) { | |
881 | opts = QTAILQ_FIRST(&list->head); | |
882 | if (!opts) { | |
f2917853 | 883 | return; |
f9dadc98 RS |
884 | } |
885 | } | |
886 | ||
887 | user = qemu_opt_get(opts, "user"); | |
888 | if (!user) { | |
f2917853 | 889 | return; |
f9dadc98 RS |
890 | } |
891 | ||
892 | password = qemu_opt_get(opts, "password"); | |
893 | if (!password) { | |
f2917853 PB |
894 | error_setg(errp, "CHAP username specified but no password was given"); |
895 | return; | |
f9dadc98 RS |
896 | } |
897 | ||
898 | if (iscsi_set_initiator_username_pwd(iscsi, user, password)) { | |
f2917853 | 899 | error_setg(errp, "Failed to set initiator username and password"); |
f9dadc98 | 900 | } |
f9dadc98 RS |
901 | } |
902 | ||
f2917853 PB |
903 | static void parse_header_digest(struct iscsi_context *iscsi, const char *target, |
904 | Error **errp) | |
f9dadc98 RS |
905 | { |
906 | QemuOptsList *list; | |
907 | QemuOpts *opts; | |
908 | const char *digest = NULL; | |
909 | ||
910 | list = qemu_find_opts("iscsi"); | |
911 | if (!list) { | |
912 | return; | |
913 | } | |
914 | ||
915 | opts = qemu_opts_find(list, target); | |
916 | if (opts == NULL) { | |
917 | opts = QTAILQ_FIRST(&list->head); | |
918 | if (!opts) { | |
919 | return; | |
920 | } | |
921 | } | |
922 | ||
923 | digest = qemu_opt_get(opts, "header-digest"); | |
924 | if (!digest) { | |
925 | return; | |
926 | } | |
927 | ||
928 | if (!strcmp(digest, "CRC32C")) { | |
929 | iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_CRC32C); | |
930 | } else if (!strcmp(digest, "NONE")) { | |
931 | iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE); | |
932 | } else if (!strcmp(digest, "CRC32C-NONE")) { | |
933 | iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_CRC32C_NONE); | |
934 | } else if (!strcmp(digest, "NONE-CRC32C")) { | |
935 | iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C); | |
936 | } else { | |
f2917853 | 937 | error_setg(errp, "Invalid header-digest setting : %s", digest); |
f9dadc98 RS |
938 | } |
939 | } | |
940 | ||
941 | static char *parse_initiator_name(const char *target) | |
942 | { | |
943 | QemuOptsList *list; | |
944 | QemuOpts *opts; | |
5accc840 PB |
945 | const char *name; |
946 | char *iscsi_name; | |
947 | UuidInfo *uuid_info; | |
f9dadc98 RS |
948 | |
949 | list = qemu_find_opts("iscsi"); | |
f2ef4a6d PB |
950 | if (list) { |
951 | opts = qemu_opts_find(list, target); | |
f9dadc98 | 952 | if (!opts) { |
f2ef4a6d PB |
953 | opts = QTAILQ_FIRST(&list->head); |
954 | } | |
955 | if (opts) { | |
956 | name = qemu_opt_get(opts, "initiator-name"); | |
5accc840 PB |
957 | if (name) { |
958 | return g_strdup(name); | |
959 | } | |
f9dadc98 RS |
960 | } |
961 | } | |
962 | ||
5accc840 PB |
963 | uuid_info = qmp_query_uuid(NULL); |
964 | if (strcmp(uuid_info->UUID, UUID_NONE) == 0) { | |
965 | name = qemu_get_vm_name(); | |
f2ef4a6d | 966 | } else { |
5accc840 | 967 | name = uuid_info->UUID; |
f9dadc98 | 968 | } |
5accc840 PB |
969 | iscsi_name = g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s", |
970 | name ? ":" : "", name ? name : ""); | |
971 | qapi_free_UuidInfo(uuid_info); | |
972 | return iscsi_name; | |
f9dadc98 RS |
973 | } |
974 | ||
5b5d34ec PL |
975 | #if defined(LIBISCSI_FEATURE_NOP_COUNTER) |
976 | static void iscsi_nop_timed_event(void *opaque) | |
977 | { | |
978 | IscsiLun *iscsilun = opaque; | |
979 | ||
980 | if (iscsi_get_nops_in_flight(iscsilun->iscsi) > MAX_NOP_FAILURES) { | |
981 | error_report("iSCSI: NOP timeout. Reconnecting..."); | |
982 | iscsi_reconnect(iscsilun->iscsi); | |
983 | } | |
984 | ||
985 | if (iscsi_nop_out_async(iscsilun->iscsi, NULL, NULL, 0, NULL) != 0) { | |
986 | error_report("iSCSI: failed to sent NOP-Out. Disabling NOP messages."); | |
987 | return; | |
988 | } | |
989 | ||
bc72ad67 | 990 | timer_mod(iscsilun->nop_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + NOP_INTERVAL); |
5b5d34ec PL |
991 | iscsi_set_events(iscsilun); |
992 | } | |
993 | #endif | |
994 | ||
f2917853 | 995 | static void iscsi_readcapacity_sync(IscsiLun *iscsilun, Error **errp) |
cb1b83e7 PL |
996 | { |
997 | struct scsi_task *task = NULL; | |
998 | struct scsi_readcapacity10 *rc10 = NULL; | |
999 | struct scsi_readcapacity16 *rc16 = NULL; | |
cb1b83e7 PL |
1000 | int retries = ISCSI_CMD_RETRIES; |
1001 | ||
1288844e PB |
1002 | do { |
1003 | if (task != NULL) { | |
1004 | scsi_free_scsi_task(task); | |
1005 | task = NULL; | |
cb1b83e7 | 1006 | } |
1288844e PB |
1007 | |
1008 | switch (iscsilun->type) { | |
1009 | case TYPE_DISK: | |
1010 | task = iscsi_readcapacity16_sync(iscsilun->iscsi, iscsilun->lun); | |
1011 | if (task != NULL && task->status == SCSI_STATUS_GOOD) { | |
1012 | rc16 = scsi_datain_unmarshall(task); | |
1013 | if (rc16 == NULL) { | |
f2917853 | 1014 | error_setg(errp, "iSCSI: Failed to unmarshall readcapacity16 data."); |
1288844e PB |
1015 | } else { |
1016 | iscsilun->block_size = rc16->block_length; | |
1017 | iscsilun->num_blocks = rc16->returned_lba + 1; | |
f18a7cbb PL |
1018 | iscsilun->lbpme = rc16->lbpme; |
1019 | iscsilun->lbprz = rc16->lbprz; | |
1288844e PB |
1020 | } |
1021 | } | |
1022 | break; | |
1023 | case TYPE_ROM: | |
1024 | task = iscsi_readcapacity10_sync(iscsilun->iscsi, iscsilun->lun, 0, 0); | |
1025 | if (task != NULL && task->status == SCSI_STATUS_GOOD) { | |
1026 | rc10 = scsi_datain_unmarshall(task); | |
1027 | if (rc10 == NULL) { | |
f2917853 | 1028 | error_setg(errp, "iSCSI: Failed to unmarshall readcapacity10 data."); |
1288844e PB |
1029 | } else { |
1030 | iscsilun->block_size = rc10->block_size; | |
1031 | if (rc10->lba == 0) { | |
1032 | /* blank disk loaded */ | |
1033 | iscsilun->num_blocks = 0; | |
1034 | } else { | |
1035 | iscsilun->num_blocks = rc10->lba + 1; | |
1036 | } | |
1037 | } | |
1038 | } | |
1039 | break; | |
1040 | default: | |
f2917853 | 1041 | return; |
cb1b83e7 | 1042 | } |
1288844e PB |
1043 | } while (task != NULL && task->status == SCSI_STATUS_CHECK_CONDITION |
1044 | && task->sense.key == SCSI_SENSE_UNIT_ATTENTION | |
1045 | && retries-- > 0); | |
cb1b83e7 | 1046 | |
1288844e | 1047 | if (task == NULL || task->status != SCSI_STATUS_GOOD) { |
f2917853 | 1048 | error_setg(errp, "iSCSI: failed to send readcapacity10 command."); |
1288844e | 1049 | } |
cb1b83e7 PL |
1050 | if (task) { |
1051 | scsi_free_scsi_task(task); | |
1052 | } | |
cb1b83e7 PL |
1053 | } |
1054 | ||
60beb341 KW |
1055 | /* TODO Convert to fine grained options */ |
1056 | static QemuOptsList runtime_opts = { | |
1057 | .name = "iscsi", | |
1058 | .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), | |
1059 | .desc = { | |
1060 | { | |
1061 | .name = "filename", | |
1062 | .type = QEMU_OPT_STRING, | |
1063 | .help = "URL to the iscsi image", | |
1064 | }, | |
1065 | { /* end of list */ } | |
1066 | }, | |
1067 | }; | |
1068 | ||
35cb1748 | 1069 | static struct scsi_task *iscsi_do_inquiry(struct iscsi_context *iscsi, int lun, |
f2917853 | 1070 | int evpd, int pc, Error **errp) |
35cb1748 PB |
1071 | { |
1072 | int full_size; | |
1073 | struct scsi_task *task = NULL; | |
1074 | task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, 64); | |
1075 | if (task == NULL || task->status != SCSI_STATUS_GOOD) { | |
1076 | goto fail; | |
1077 | } | |
1078 | full_size = scsi_datain_getfullsize(task); | |
1079 | if (full_size > task->datain.size) { | |
1080 | scsi_free_scsi_task(task); | |
1081 | ||
1082 | /* we need more data for the full list */ | |
1083 | task = iscsi_inquiry_sync(iscsi, lun, evpd, pc, full_size); | |
f18a7cbb PL |
1084 | if (task == NULL || task->status != SCSI_STATUS_GOOD) { |
1085 | goto fail; | |
1086 | } | |
35cb1748 | 1087 | } |
f18a7cbb | 1088 | |
35cb1748 | 1089 | return task; |
f18a7cbb PL |
1090 | |
1091 | fail: | |
f2917853 PB |
1092 | error_setg(errp, "iSCSI: Inquiry command failed : %s", |
1093 | iscsi_get_error(iscsi)); | |
35cb1748 PB |
1094 | if (task) { |
1095 | scsi_free_scsi_task(task); | |
f18a7cbb | 1096 | return NULL; |
35cb1748 PB |
1097 | } |
1098 | return NULL; | |
f18a7cbb PL |
1099 | } |
1100 | ||
c589b249 RS |
1101 | /* |
1102 | * We support iscsi url's on the form | |
1103 | * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun> | |
28f106af JC |
1104 | * |
1105 | * Note: flags are currently not used by iscsi_open. If this function | |
1106 | * is changed such that flags are used, please examine iscsi_reopen_prepare() | |
1107 | * to see if needs to be changed as well. | |
c589b249 | 1108 | */ |
015a1036 HR |
1109 | static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, |
1110 | Error **errp) | |
c589b249 RS |
1111 | { |
1112 | IscsiLun *iscsilun = bs->opaque; | |
1113 | struct iscsi_context *iscsi = NULL; | |
1114 | struct iscsi_url *iscsi_url = NULL; | |
e829b0bb PL |
1115 | struct scsi_task *task = NULL; |
1116 | struct scsi_inquiry_standard *inq = NULL; | |
f9dadc98 | 1117 | char *initiator_name = NULL; |
60beb341 KW |
1118 | QemuOpts *opts; |
1119 | Error *local_err = NULL; | |
1120 | const char *filename; | |
c589b249 RS |
1121 | int ret; |
1122 | ||
1123 | if ((BDRV_SECTOR_SIZE % 512) != 0) { | |
f2917853 PB |
1124 | error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. " |
1125 | "BDRV_SECTOR_SIZE(%lld) is not a multiple " | |
1126 | "of 512", BDRV_SECTOR_SIZE); | |
c589b249 RS |
1127 | return -EINVAL; |
1128 | } | |
1129 | ||
87ea75d5 | 1130 | opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); |
60beb341 | 1131 | qemu_opts_absorb_qdict(opts, options, &local_err); |
84d18f06 | 1132 | if (local_err) { |
f2917853 | 1133 | error_propagate(errp, local_err); |
60beb341 KW |
1134 | ret = -EINVAL; |
1135 | goto out; | |
1136 | } | |
1137 | ||
1138 | filename = qemu_opt_get(opts, "filename"); | |
1139 | ||
c589b249 RS |
1140 | iscsi_url = iscsi_parse_full_url(iscsi, filename); |
1141 | if (iscsi_url == NULL) { | |
f2917853 | 1142 | error_setg(errp, "Failed to parse URL : %s", filename); |
c589b249 | 1143 | ret = -EINVAL; |
b93c94f7 | 1144 | goto out; |
c589b249 RS |
1145 | } |
1146 | ||
f9dadc98 RS |
1147 | memset(iscsilun, 0, sizeof(IscsiLun)); |
1148 | ||
1149 | initiator_name = parse_initiator_name(iscsi_url->target); | |
1150 | ||
1151 | iscsi = iscsi_create_context(initiator_name); | |
1152 | if (iscsi == NULL) { | |
f2917853 | 1153 | error_setg(errp, "iSCSI: Failed to create iSCSI context."); |
f9dadc98 | 1154 | ret = -ENOMEM; |
b93c94f7 | 1155 | goto out; |
f9dadc98 RS |
1156 | } |
1157 | ||
c589b249 | 1158 | if (iscsi_set_targetname(iscsi, iscsi_url->target)) { |
f2917853 | 1159 | error_setg(errp, "iSCSI: Failed to set target name."); |
c589b249 | 1160 | ret = -EINVAL; |
b93c94f7 | 1161 | goto out; |
c589b249 RS |
1162 | } |
1163 | ||
1164 | if (iscsi_url->user != NULL) { | |
1165 | ret = iscsi_set_initiator_username_pwd(iscsi, iscsi_url->user, | |
1166 | iscsi_url->passwd); | |
1167 | if (ret != 0) { | |
f2917853 | 1168 | error_setg(errp, "Failed to set initiator username and password"); |
c589b249 | 1169 | ret = -EINVAL; |
b93c94f7 | 1170 | goto out; |
c589b249 RS |
1171 | } |
1172 | } | |
f9dadc98 RS |
1173 | |
1174 | /* check if we got CHAP username/password via the options */ | |
f2917853 PB |
1175 | parse_chap(iscsi, iscsi_url->target, &local_err); |
1176 | if (local_err != NULL) { | |
1177 | error_propagate(errp, local_err); | |
f9dadc98 | 1178 | ret = -EINVAL; |
b93c94f7 | 1179 | goto out; |
f9dadc98 RS |
1180 | } |
1181 | ||
c589b249 | 1182 | if (iscsi_set_session_type(iscsi, ISCSI_SESSION_NORMAL) != 0) { |
f2917853 | 1183 | error_setg(errp, "iSCSI: Failed to set session type to normal."); |
c589b249 | 1184 | ret = -EINVAL; |
b93c94f7 | 1185 | goto out; |
c589b249 RS |
1186 | } |
1187 | ||
1188 | iscsi_set_header_digest(iscsi, ISCSI_HEADER_DIGEST_NONE_CRC32C); | |
1189 | ||
f9dadc98 | 1190 | /* check if we got HEADER_DIGEST via the options */ |
f2917853 PB |
1191 | parse_header_digest(iscsi, iscsi_url->target, &local_err); |
1192 | if (local_err != NULL) { | |
1193 | error_propagate(errp, local_err); | |
1194 | ret = -EINVAL; | |
1195 | goto out; | |
1196 | } | |
f9dadc98 | 1197 | |
e829b0bb | 1198 | if (iscsi_full_connect_sync(iscsi, iscsi_url->portal, iscsi_url->lun) != 0) { |
f2917853 | 1199 | error_setg(errp, "iSCSI: Failed to connect to LUN : %s", |
e829b0bb PL |
1200 | iscsi_get_error(iscsi)); |
1201 | ret = -EINVAL; | |
1202 | goto out; | |
1203 | } | |
c589b249 RS |
1204 | |
1205 | iscsilun->iscsi = iscsi; | |
1206 | iscsilun->lun = iscsi_url->lun; | |
1207 | ||
e829b0bb PL |
1208 | task = iscsi_inquiry_sync(iscsi, iscsilun->lun, 0, 0, 36); |
1209 | ||
1210 | if (task == NULL || task->status != SCSI_STATUS_GOOD) { | |
f2917853 | 1211 | error_setg(errp, "iSCSI: failed to send inquiry command."); |
c589b249 | 1212 | ret = -EINVAL; |
b93c94f7 | 1213 | goto out; |
c589b249 RS |
1214 | } |
1215 | ||
e829b0bb PL |
1216 | inq = scsi_datain_unmarshall(task); |
1217 | if (inq == NULL) { | |
f2917853 | 1218 | error_setg(errp, "iSCSI: Failed to unmarshall inquiry data."); |
c589b249 | 1219 | ret = -EINVAL; |
b93c94f7 | 1220 | goto out; |
c589b249 | 1221 | } |
622695a4 | 1222 | |
e829b0bb | 1223 | iscsilun->type = inq->periperal_device_type; |
fa6252b0 | 1224 | iscsilun->has_write_same = true; |
e829b0bb | 1225 | |
f2917853 PB |
1226 | iscsi_readcapacity_sync(iscsilun, &local_err); |
1227 | if (local_err != NULL) { | |
1228 | error_propagate(errp, local_err); | |
cb1b83e7 | 1229 | goto out; |
e829b0bb | 1230 | } |
0777b5dd | 1231 | bs->total_sectors = sector_lun2qemu(iscsilun->num_blocks, iscsilun); |
2c9880c4 | 1232 | bs->request_alignment = iscsilun->block_size; |
e829b0bb | 1233 | |
622695a4 RS |
1234 | /* Medium changer or tape. We dont have any emulation for this so this must |
1235 | * be sg ioctl compatible. We force it to be sg, otherwise qemu will try | |
1236 | * to read from the device to guess the image format. | |
1237 | */ | |
1238 | if (iscsilun->type == TYPE_MEDIUM_CHANGER || | |
1239 | iscsilun->type == TYPE_TAPE) { | |
1240 | bs->sg = 1; | |
1241 | } | |
1242 | ||
f18a7cbb PL |
1243 | if (iscsilun->lbpme) { |
1244 | struct scsi_inquiry_logical_block_provisioning *inq_lbp; | |
1245 | task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1, | |
f2917853 PB |
1246 | SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, |
1247 | errp); | |
f18a7cbb PL |
1248 | if (task == NULL) { |
1249 | ret = -EINVAL; | |
1250 | goto out; | |
1251 | } | |
1252 | inq_lbp = scsi_datain_unmarshall(task); | |
1253 | if (inq_lbp == NULL) { | |
f2917853 | 1254 | error_setg(errp, "iSCSI: failed to unmarshall inquiry datain blob"); |
f18a7cbb PL |
1255 | ret = -EINVAL; |
1256 | goto out; | |
1257 | } | |
1258 | memcpy(&iscsilun->lbp, inq_lbp, | |
1259 | sizeof(struct scsi_inquiry_logical_block_provisioning)); | |
1260 | scsi_free_scsi_task(task); | |
1261 | task = NULL; | |
1262 | } | |
1263 | ||
1264 | if (iscsilun->lbp.lbpu || iscsilun->lbp.lbpws) { | |
1265 | struct scsi_inquiry_block_limits *inq_bl; | |
1266 | task = iscsi_do_inquiry(iscsilun->iscsi, iscsilun->lun, 1, | |
f2917853 | 1267 | SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, errp); |
f18a7cbb PL |
1268 | if (task == NULL) { |
1269 | ret = -EINVAL; | |
1270 | goto out; | |
1271 | } | |
1272 | inq_bl = scsi_datain_unmarshall(task); | |
1273 | if (inq_bl == NULL) { | |
f2917853 | 1274 | error_setg(errp, "iSCSI: failed to unmarshall inquiry datain blob"); |
f18a7cbb PL |
1275 | ret = -EINVAL; |
1276 | goto out; | |
1277 | } | |
1278 | memcpy(&iscsilun->bl, inq_bl, | |
1279 | sizeof(struct scsi_inquiry_block_limits)); | |
1280 | scsi_free_scsi_task(task); | |
1281 | task = NULL; | |
1282 | } | |
1283 | ||
5b5d34ec PL |
1284 | #if defined(LIBISCSI_FEATURE_NOP_COUNTER) |
1285 | /* Set up a timer for sending out iSCSI NOPs */ | |
bc72ad67 AB |
1286 | iscsilun->nop_timer = timer_new_ms(QEMU_CLOCK_REALTIME, iscsi_nop_timed_event, iscsilun); |
1287 | timer_mod(iscsilun->nop_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + NOP_INTERVAL); | |
5b5d34ec PL |
1288 | #endif |
1289 | ||
b93c94f7 | 1290 | out: |
60beb341 | 1291 | qemu_opts_del(opts); |
f9dadc98 RS |
1292 | if (initiator_name != NULL) { |
1293 | g_free(initiator_name); | |
1294 | } | |
c589b249 RS |
1295 | if (iscsi_url != NULL) { |
1296 | iscsi_destroy_url(iscsi_url); | |
1297 | } | |
e829b0bb PL |
1298 | if (task != NULL) { |
1299 | scsi_free_scsi_task(task); | |
1300 | } | |
b93c94f7 PB |
1301 | |
1302 | if (ret) { | |
1303 | if (iscsi != NULL) { | |
1304 | iscsi_destroy_context(iscsi); | |
1305 | } | |
1306 | memset(iscsilun, 0, sizeof(IscsiLun)); | |
c589b249 | 1307 | } |
c589b249 RS |
1308 | return ret; |
1309 | } | |
1310 | ||
1311 | static void iscsi_close(BlockDriverState *bs) | |
1312 | { | |
1313 | IscsiLun *iscsilun = bs->opaque; | |
1314 | struct iscsi_context *iscsi = iscsilun->iscsi; | |
1315 | ||
5b5d34ec | 1316 | if (iscsilun->nop_timer) { |
bc72ad67 AB |
1317 | timer_del(iscsilun->nop_timer); |
1318 | timer_free(iscsilun->nop_timer); | |
5b5d34ec | 1319 | } |
f2e5dca4 | 1320 | qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), NULL, NULL, NULL); |
c589b249 | 1321 | iscsi_destroy_context(iscsi); |
d4cd9615 | 1322 | g_free(iscsilun->zeroblock); |
c589b249 RS |
1323 | memset(iscsilun, 0, sizeof(IscsiLun)); |
1324 | } | |
1325 | ||
d34682cd KW |
1326 | static int iscsi_refresh_limits(BlockDriverState *bs) |
1327 | { | |
1328 | IscsiLun *iscsilun = bs->opaque; | |
1329 | ||
1330 | /* We don't actually refresh here, but just return data queried in | |
1331 | * iscsi_open(): iscsi targets don't change their limits. */ | |
1332 | if (iscsilun->lbp.lbpu || iscsilun->lbp.lbpws) { | |
1333 | if (iscsilun->bl.max_unmap < 0xffffffff) { | |
1334 | bs->bl.max_discard = sector_lun2qemu(iscsilun->bl.max_unmap, | |
1335 | iscsilun); | |
1336 | } | |
1337 | bs->bl.discard_alignment = sector_lun2qemu(iscsilun->bl.opt_unmap_gran, | |
1338 | iscsilun); | |
1339 | ||
1340 | if (iscsilun->bl.max_ws_len < 0xffffffff) { | |
1341 | bs->bl.max_write_zeroes = sector_lun2qemu(iscsilun->bl.max_ws_len, | |
1342 | iscsilun); | |
1343 | } | |
1344 | bs->bl.write_zeroes_alignment = sector_lun2qemu(iscsilun->bl.opt_unmap_gran, | |
1345 | iscsilun); | |
d34682cd | 1346 | } |
5d259fc7 PL |
1347 | bs->bl.opt_transfer_length = sector_lun2qemu(iscsilun->bl.opt_xfer_len, |
1348 | iscsilun); | |
e9f526ab AL |
1349 | return 0; |
1350 | } | |
d34682cd | 1351 | |
28f106af JC |
1352 | /* Since iscsi_open() ignores bdrv_flags, there is nothing to do here in |
1353 | * prepare. Note that this will not re-establish a connection with an iSCSI | |
1354 | * target - it is effectively a NOP. */ | |
dc6afb99 JC |
1355 | static int iscsi_reopen_prepare(BDRVReopenState *state, |
1356 | BlockReopenQueue *queue, Error **errp) | |
1357 | { | |
28f106af | 1358 | /* NOP */ |
d34682cd KW |
1359 | return 0; |
1360 | } | |
1361 | ||
cb1b83e7 PL |
1362 | static int iscsi_truncate(BlockDriverState *bs, int64_t offset) |
1363 | { | |
1364 | IscsiLun *iscsilun = bs->opaque; | |
f2917853 | 1365 | Error *local_err = NULL; |
cb1b83e7 PL |
1366 | |
1367 | if (iscsilun->type != TYPE_DISK) { | |
1368 | return -ENOTSUP; | |
1369 | } | |
1370 | ||
f2917853 PB |
1371 | iscsi_readcapacity_sync(iscsilun, &local_err); |
1372 | if (local_err != NULL) { | |
1373 | error_free(local_err); | |
1374 | return -EIO; | |
cb1b83e7 PL |
1375 | } |
1376 | ||
1377 | if (offset > iscsi_getlength(bs)) { | |
1378 | return -EINVAL; | |
1379 | } | |
1380 | ||
1381 | return 0; | |
1382 | } | |
1383 | ||
d5124c00 HR |
1384 | static int iscsi_create(const char *filename, QEMUOptionParameter *options, |
1385 | Error **errp) | |
de8864e5 PL |
1386 | { |
1387 | int ret = 0; | |
1388 | int64_t total_size = 0; | |
13c91cb7 | 1389 | BlockDriverState *bs; |
de8864e5 | 1390 | IscsiLun *iscsilun = NULL; |
60beb341 | 1391 | QDict *bs_options; |
de8864e5 | 1392 | |
13c91cb7 | 1393 | bs = bdrv_new(""); |
de8864e5 PL |
1394 | |
1395 | /* Read out options */ | |
1396 | while (options && options->name) { | |
1397 | if (!strcmp(options->name, "size")) { | |
1398 | total_size = options->value.n / BDRV_SECTOR_SIZE; | |
1399 | } | |
1400 | options++; | |
1401 | } | |
1402 | ||
13c91cb7 FZ |
1403 | bs->opaque = g_malloc0(sizeof(struct IscsiLun)); |
1404 | iscsilun = bs->opaque; | |
de8864e5 | 1405 | |
60beb341 KW |
1406 | bs_options = qdict_new(); |
1407 | qdict_put(bs_options, "filename", qstring_from_str(filename)); | |
015a1036 | 1408 | ret = iscsi_open(bs, bs_options, 0, NULL); |
60beb341 KW |
1409 | QDECREF(bs_options); |
1410 | ||
de8864e5 PL |
1411 | if (ret != 0) { |
1412 | goto out; | |
1413 | } | |
5b5d34ec | 1414 | if (iscsilun->nop_timer) { |
bc72ad67 AB |
1415 | timer_del(iscsilun->nop_timer); |
1416 | timer_free(iscsilun->nop_timer); | |
5b5d34ec | 1417 | } |
de8864e5 PL |
1418 | if (iscsilun->type != TYPE_DISK) { |
1419 | ret = -ENODEV; | |
1420 | goto out; | |
1421 | } | |
13c91cb7 | 1422 | if (bs->total_sectors < total_size) { |
de8864e5 | 1423 | ret = -ENOSPC; |
d3bda7bc | 1424 | goto out; |
de8864e5 PL |
1425 | } |
1426 | ||
1427 | ret = 0; | |
1428 | out: | |
1429 | if (iscsilun->iscsi != NULL) { | |
1430 | iscsi_destroy_context(iscsilun->iscsi); | |
1431 | } | |
13c91cb7 FZ |
1432 | g_free(bs->opaque); |
1433 | bs->opaque = NULL; | |
4f6fd349 | 1434 | bdrv_unref(bs); |
de8864e5 PL |
1435 | return ret; |
1436 | } | |
1437 | ||
186d4f2b PL |
1438 | static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) |
1439 | { | |
1440 | IscsiLun *iscsilun = bs->opaque; | |
1441 | bdi->unallocated_blocks_are_zero = !!iscsilun->lbprz; | |
1442 | bdi->can_write_zeroes_with_unmap = iscsilun->lbprz && iscsilun->lbp.lbpws; | |
1c0704a5 PL |
1443 | /* Guess the internal cluster (page) size of the iscsi target by the means |
1444 | * of opt_unmap_gran. Transfer the unmap granularity only if it has a | |
1445 | * reasonable size for bdi->cluster_size */ | |
1446 | if (iscsilun->bl.opt_unmap_gran * iscsilun->block_size >= 64 * 1024 && | |
1447 | iscsilun->bl.opt_unmap_gran * iscsilun->block_size <= 16 * 1024 * 1024) { | |
1448 | bdi->cluster_size = iscsilun->bl.opt_unmap_gran * iscsilun->block_size; | |
1449 | } | |
186d4f2b PL |
1450 | return 0; |
1451 | } | |
1452 | ||
de8864e5 PL |
1453 | static QEMUOptionParameter iscsi_create_options[] = { |
1454 | { | |
1455 | .name = BLOCK_OPT_SIZE, | |
1456 | .type = OPT_SIZE, | |
1457 | .help = "Virtual disk size" | |
1458 | }, | |
1459 | { NULL } | |
1460 | }; | |
1461 | ||
c589b249 RS |
1462 | static BlockDriver bdrv_iscsi = { |
1463 | .format_name = "iscsi", | |
1464 | .protocol_name = "iscsi", | |
1465 | ||
1466 | .instance_size = sizeof(IscsiLun), | |
030be321 | 1467 | .bdrv_needs_filename = true, |
c589b249 RS |
1468 | .bdrv_file_open = iscsi_open, |
1469 | .bdrv_close = iscsi_close, | |
de8864e5 PL |
1470 | .bdrv_create = iscsi_create, |
1471 | .create_options = iscsi_create_options, | |
dc6afb99 | 1472 | .bdrv_reopen_prepare = iscsi_reopen_prepare, |
c589b249 RS |
1473 | |
1474 | .bdrv_getlength = iscsi_getlength, | |
186d4f2b | 1475 | .bdrv_get_info = iscsi_get_info, |
cb1b83e7 | 1476 | .bdrv_truncate = iscsi_truncate, |
d34682cd | 1477 | .bdrv_refresh_limits = iscsi_refresh_limits, |
c589b249 | 1478 | |
24c7608a | 1479 | #if defined(LIBISCSI_FEATURE_IOVECTOR) |
54a5c1d5 | 1480 | .bdrv_co_get_block_status = iscsi_co_get_block_status, |
f35c934a | 1481 | #endif |
65f3e339 | 1482 | .bdrv_co_discard = iscsi_co_discard, |
d4cd9615 PL |
1483 | #if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED) |
1484 | .bdrv_co_write_zeroes = iscsi_co_write_zeroes, | |
1485 | #endif | |
063c3378 PL |
1486 | .bdrv_co_readv = iscsi_co_readv, |
1487 | .bdrv_co_writev = iscsi_co_writev, | |
1488 | .bdrv_co_flush_to_disk = iscsi_co_flush, | |
fa6acb0c | 1489 | |
98392453 RS |
1490 | #ifdef __linux__ |
1491 | .bdrv_ioctl = iscsi_ioctl, | |
1492 | .bdrv_aio_ioctl = iscsi_aio_ioctl, | |
1493 | #endif | |
c589b249 RS |
1494 | }; |
1495 | ||
4d454574 PB |
1496 | static QemuOptsList qemu_iscsi_opts = { |
1497 | .name = "iscsi", | |
1498 | .head = QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts.head), | |
1499 | .desc = { | |
1500 | { | |
1501 | .name = "user", | |
1502 | .type = QEMU_OPT_STRING, | |
1503 | .help = "username for CHAP authentication to target", | |
1504 | },{ | |
1505 | .name = "password", | |
1506 | .type = QEMU_OPT_STRING, | |
1507 | .help = "password for CHAP authentication to target", | |
1508 | },{ | |
1509 | .name = "header-digest", | |
1510 | .type = QEMU_OPT_STRING, | |
1511 | .help = "HeaderDigest setting. " | |
1512 | "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}", | |
1513 | },{ | |
1514 | .name = "initiator-name", | |
1515 | .type = QEMU_OPT_STRING, | |
1516 | .help = "Initiator iqn name to use when connecting", | |
1517 | }, | |
1518 | { /* end of list */ } | |
1519 | }, | |
1520 | }; | |
1521 | ||
c589b249 RS |
1522 | static void iscsi_block_init(void) |
1523 | { | |
1524 | bdrv_register(&bdrv_iscsi); | |
4d454574 | 1525 | qemu_add_opts(&qemu_iscsi_opts); |
c589b249 RS |
1526 | } |
1527 | ||
1528 | block_init(iscsi_block_init); |