2 * QEMU Block driver for iSCSI images
4 * Copyright (c) 2010-2011 Ronnie Sahlberg <ronniesahlberg@gmail.com>
5 * Copyright (c) 2012-2013 Peter Lieven <pl@kamp.de>
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
26 #include "config-host.h"
29 #include <arpa/inet.h>
30 #include "qemu-common.h"
31 #include "qemu/config-file.h"
32 #include "qemu/error-report.h"
33 #include "block/block_int.h"
35 #include "block/scsi.h"
37 #include "sysemu/sysemu.h"
38 #include "qmp-commands.h"
40 #include <iscsi/iscsi.h>
41 #include <iscsi/scsi-lowlevel.h>
45 #include <block/scsi.h>
48 typedef struct IscsiLun
{
49 struct iscsi_context
*iscsi
;
51 enum scsi_inquiry_peripheral_device_type type
;
58 uint8_t has_write_same
;
59 struct scsi_inquiry_logical_block_provisioning lbp
;
60 struct scsi_inquiry_block_limits bl
;
61 unsigned char *zeroblock
;
64 typedef struct IscsiTask
{
69 struct scsi_task
*task
;
73 typedef struct IscsiAIOCB
{
74 BlockDriverAIOCB common
;
78 struct scsi_task
*task
;
90 #define NOP_INTERVAL 5000
91 #define MAX_NOP_FAILURES 3
92 #define ISCSI_CMD_RETRIES 5
99 qemu_bh_delete(acb
->bh
);
104 if (acb
->canceled
== 0) {
105 acb
->common
.cb(acb
->common
.opaque
, acb
->status
);
108 if (acb
->task
!= NULL
) {
109 scsi_free_scsi_task(acb
->task
);
113 qemu_aio_release(acb
);
117 iscsi_schedule_bh(IscsiAIOCB
*acb
)
122 acb
->bh
= qemu_bh_new(iscsi_bh_cb
, acb
);
123 qemu_bh_schedule(acb
->bh
);
127 iscsi_co_generic_cb(struct iscsi_context
*iscsi
, int status
,
128 void *command_data
, void *opaque
)
130 struct IscsiTask
*iTask
= opaque
;
131 struct scsi_task
*task
= command_data
;
134 iTask
->status
= status
;
138 if (iTask
->retries
-- > 0 && status
== SCSI_STATUS_CHECK_CONDITION
139 && task
->sense
.key
== SCSI_SENSE_UNIT_ATTENTION
) {
144 if (status
!= SCSI_STATUS_GOOD
) {
145 error_report("iSCSI: Failure. %s", iscsi_get_error(iscsi
));
150 qemu_coroutine_enter(iTask
->co
, NULL
);
154 static void iscsi_co_init_iscsitask(IscsiLun
*iscsilun
, struct IscsiTask
*iTask
)
156 *iTask
= (struct IscsiTask
) {
157 .co
= qemu_coroutine_self(),
158 .retries
= ISCSI_CMD_RETRIES
,
163 iscsi_abort_task_cb(struct iscsi_context
*iscsi
, int status
, void *command_data
,
166 IscsiAIOCB
*acb
= private_data
;
168 acb
->status
= -ECANCELED
;
169 iscsi_schedule_bh(acb
);
173 iscsi_aio_cancel(BlockDriverAIOCB
*blockacb
)
175 IscsiAIOCB
*acb
= (IscsiAIOCB
*)blockacb
;
176 IscsiLun
*iscsilun
= acb
->iscsilun
;
178 if (acb
->status
!= -EINPROGRESS
) {
184 /* send a task mgmt call to the target to cancel the task on the target */
185 iscsi_task_mgmt_abort_task_async(iscsilun
->iscsi
, acb
->task
,
186 iscsi_abort_task_cb
, acb
);
188 while (acb
->status
== -EINPROGRESS
) {
193 static const AIOCBInfo iscsi_aiocb_info
= {
194 .aiocb_size
= sizeof(IscsiAIOCB
),
195 .cancel
= iscsi_aio_cancel
,
199 static void iscsi_process_read(void *arg
);
200 static void iscsi_process_write(void *arg
);
203 iscsi_set_events(IscsiLun
*iscsilun
)
205 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
208 /* We always register a read handler. */
210 ev
|= iscsi_which_events(iscsi
);
211 if (ev
!= iscsilun
->events
) {
212 qemu_aio_set_fd_handler(iscsi_get_fd(iscsi
),
214 (ev
& POLLOUT
) ? iscsi_process_write
: NULL
,
219 iscsilun
->events
= ev
;
223 iscsi_process_read(void *arg
)
225 IscsiLun
*iscsilun
= arg
;
226 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
228 iscsi_service(iscsi
, POLLIN
);
229 iscsi_set_events(iscsilun
);
233 iscsi_process_write(void *arg
)
235 IscsiLun
*iscsilun
= arg
;
236 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
238 iscsi_service(iscsi
, POLLOUT
);
239 iscsi_set_events(iscsilun
);
243 iscsi_aio_writev_acb(IscsiAIOCB
*acb
);
246 iscsi_aio_write16_cb(struct iscsi_context
*iscsi
, int status
,
247 void *command_data
, void *opaque
)
249 IscsiAIOCB
*acb
= opaque
;
251 trace_iscsi_aio_write16_cb(iscsi
, status
, acb
, acb
->canceled
);
256 if (acb
->canceled
!= 0) {
262 if (status
== SCSI_STATUS_CHECK_CONDITION
263 && acb
->task
->sense
.key
== SCSI_SENSE_UNIT_ATTENTION
264 && acb
->retries
-- > 0) {
265 scsi_free_scsi_task(acb
->task
);
267 if (iscsi_aio_writev_acb(acb
) == 0) {
268 iscsi_set_events(acb
->iscsilun
);
272 error_report("Failed to write16 data to iSCSI lun. %s",
273 iscsi_get_error(iscsi
));
277 iscsi_schedule_bh(acb
);
280 static int64_t sector_lun2qemu(int64_t sector
, IscsiLun
*iscsilun
)
282 return sector
* iscsilun
->block_size
/ BDRV_SECTOR_SIZE
;
285 static int64_t sector_qemu2lun(int64_t sector
, IscsiLun
*iscsilun
)
287 return sector
* BDRV_SECTOR_SIZE
/ iscsilun
->block_size
;
290 static bool is_request_lun_aligned(int64_t sector_num
, int nb_sectors
,
293 if ((sector_num
* BDRV_SECTOR_SIZE
) % iscsilun
->block_size
||
294 (nb_sectors
* BDRV_SECTOR_SIZE
) % iscsilun
->block_size
) {
295 error_report("iSCSI misaligned request: "
296 "iscsilun->block_size %u, sector_num %" PRIi64
298 iscsilun
->block_size
, sector_num
, nb_sectors
);
305 iscsi_aio_writev_acb(IscsiAIOCB
*acb
)
307 struct iscsi_context
*iscsi
= acb
->iscsilun
->iscsi
;
309 uint32_t num_sectors
;
311 #if !defined(LIBISCSI_FEATURE_IOVECTOR)
312 struct iscsi_data data
;
318 acb
->status
= -EINPROGRESS
;
321 /* this will allow us to get rid of 'buf' completely */
322 size
= acb
->nb_sectors
* BDRV_SECTOR_SIZE
;
324 #if !defined(LIBISCSI_FEATURE_IOVECTOR)
325 data
.size
= MIN(size
, acb
->qiov
->size
);
327 /* if the iovec only contains one buffer we can pass it directly */
328 if (acb
->qiov
->niov
== 1) {
329 data
.data
= acb
->qiov
->iov
[0].iov_base
;
331 acb
->buf
= g_malloc(data
.size
);
332 qemu_iovec_to_buf(acb
->qiov
, 0, acb
->buf
, data
.size
);
333 data
.data
= acb
->buf
;
337 acb
->task
= malloc(sizeof(struct scsi_task
));
338 if (acb
->task
== NULL
) {
339 error_report("iSCSI: Failed to allocate task for scsi WRITE16 "
340 "command. %s", iscsi_get_error(iscsi
));
343 memset(acb
->task
, 0, sizeof(struct scsi_task
));
345 acb
->task
->xfer_dir
= SCSI_XFER_WRITE
;
346 acb
->task
->cdb_size
= 16;
347 acb
->task
->cdb
[0] = 0x8a;
348 lba
= sector_qemu2lun(acb
->sector_num
, acb
->iscsilun
);
349 *(uint32_t *)&acb
->task
->cdb
[2] = htonl(lba
>> 32);
350 *(uint32_t *)&acb
->task
->cdb
[6] = htonl(lba
& 0xffffffff);
351 num_sectors
= sector_qemu2lun(acb
->nb_sectors
, acb
->iscsilun
);
352 *(uint32_t *)&acb
->task
->cdb
[10] = htonl(num_sectors
);
353 acb
->task
->expxferlen
= size
;
355 #if defined(LIBISCSI_FEATURE_IOVECTOR)
356 ret
= iscsi_scsi_command_async(iscsi
, acb
->iscsilun
->lun
, acb
->task
,
357 iscsi_aio_write16_cb
,
361 ret
= iscsi_scsi_command_async(iscsi
, acb
->iscsilun
->lun
, acb
->task
,
362 iscsi_aio_write16_cb
,
367 scsi_free_scsi_task(acb
->task
);
372 #if defined(LIBISCSI_FEATURE_IOVECTOR)
373 scsi_task_set_iov_out(acb
->task
, (struct scsi_iovec
*) acb
->qiov
->iov
, acb
->qiov
->niov
);
379 static BlockDriverAIOCB
*
380 iscsi_aio_writev(BlockDriverState
*bs
, int64_t sector_num
,
381 QEMUIOVector
*qiov
, int nb_sectors
,
382 BlockDriverCompletionFunc
*cb
,
385 IscsiLun
*iscsilun
= bs
->opaque
;
388 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
392 acb
= qemu_aio_get(&iscsi_aiocb_info
, bs
, cb
, opaque
);
393 trace_iscsi_aio_writev(iscsilun
->iscsi
, sector_num
, nb_sectors
, opaque
, acb
);
395 acb
->iscsilun
= iscsilun
;
397 acb
->nb_sectors
= nb_sectors
;
398 acb
->sector_num
= sector_num
;
399 acb
->retries
= ISCSI_CMD_RETRIES
;
401 if (iscsi_aio_writev_acb(acb
) != 0) {
402 qemu_aio_release(acb
);
406 iscsi_set_events(iscsilun
);
411 iscsi_aio_readv_acb(IscsiAIOCB
*acb
);
414 iscsi_aio_read16_cb(struct iscsi_context
*iscsi
, int status
,
415 void *command_data
, void *opaque
)
417 IscsiAIOCB
*acb
= opaque
;
419 trace_iscsi_aio_read16_cb(iscsi
, status
, acb
, acb
->canceled
);
421 if (acb
->canceled
!= 0) {
427 if (status
== SCSI_STATUS_CHECK_CONDITION
428 && acb
->task
->sense
.key
== SCSI_SENSE_UNIT_ATTENTION
429 && acb
->retries
-- > 0) {
430 scsi_free_scsi_task(acb
->task
);
432 if (iscsi_aio_readv_acb(acb
) == 0) {
433 iscsi_set_events(acb
->iscsilun
);
437 error_report("Failed to read16 data from iSCSI lun. %s",
438 iscsi_get_error(iscsi
));
442 iscsi_schedule_bh(acb
);
446 iscsi_aio_readv_acb(IscsiAIOCB
*acb
)
448 struct iscsi_context
*iscsi
= acb
->iscsilun
->iscsi
;
451 uint32_t num_sectors
;
453 #if !defined(LIBISCSI_FEATURE_IOVECTOR)
459 acb
->status
= -EINPROGRESS
;
462 size
= acb
->nb_sectors
* BDRV_SECTOR_SIZE
;
464 acb
->task
= malloc(sizeof(struct scsi_task
));
465 if (acb
->task
== NULL
) {
466 error_report("iSCSI: Failed to allocate task for scsi READ16 "
467 "command. %s", iscsi_get_error(iscsi
));
470 memset(acb
->task
, 0, sizeof(struct scsi_task
));
472 acb
->task
->xfer_dir
= SCSI_XFER_READ
;
473 acb
->task
->expxferlen
= size
;
474 lba
= sector_qemu2lun(acb
->sector_num
, acb
->iscsilun
);
475 num_sectors
= sector_qemu2lun(acb
->nb_sectors
, acb
->iscsilun
);
477 switch (acb
->iscsilun
->type
) {
479 acb
->task
->cdb_size
= 16;
480 acb
->task
->cdb
[0] = 0x88;
481 *(uint32_t *)&acb
->task
->cdb
[2] = htonl(lba
>> 32);
482 *(uint32_t *)&acb
->task
->cdb
[6] = htonl(lba
& 0xffffffff);
483 *(uint32_t *)&acb
->task
->cdb
[10] = htonl(num_sectors
);
486 acb
->task
->cdb_size
= 10;
487 acb
->task
->cdb
[0] = 0x28;
488 *(uint32_t *)&acb
->task
->cdb
[2] = htonl(lba
);
489 *(uint16_t *)&acb
->task
->cdb
[7] = htons(num_sectors
);
493 ret
= iscsi_scsi_command_async(iscsi
, acb
->iscsilun
->lun
, acb
->task
,
498 scsi_free_scsi_task(acb
->task
);
502 #if defined(LIBISCSI_FEATURE_IOVECTOR)
503 scsi_task_set_iov_in(acb
->task
, (struct scsi_iovec
*) acb
->qiov
->iov
, acb
->qiov
->niov
);
505 for (i
= 0; i
< acb
->qiov
->niov
; i
++) {
506 scsi_task_add_data_in_buffer(acb
->task
,
507 acb
->qiov
->iov
[i
].iov_len
,
508 acb
->qiov
->iov
[i
].iov_base
);
514 static BlockDriverAIOCB
*
515 iscsi_aio_readv(BlockDriverState
*bs
, int64_t sector_num
,
516 QEMUIOVector
*qiov
, int nb_sectors
,
517 BlockDriverCompletionFunc
*cb
,
520 IscsiLun
*iscsilun
= bs
->opaque
;
523 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
527 acb
= qemu_aio_get(&iscsi_aiocb_info
, bs
, cb
, opaque
);
528 trace_iscsi_aio_readv(iscsilun
->iscsi
, sector_num
, nb_sectors
, opaque
, acb
);
530 acb
->nb_sectors
= nb_sectors
;
531 acb
->sector_num
= sector_num
;
532 acb
->iscsilun
= iscsilun
;
534 acb
->retries
= ISCSI_CMD_RETRIES
;
536 if (iscsi_aio_readv_acb(acb
) != 0) {
537 qemu_aio_release(acb
);
541 iscsi_set_events(iscsilun
);
546 iscsi_aio_flush_acb(IscsiAIOCB
*acb
);
549 iscsi_synccache10_cb(struct iscsi_context
*iscsi
, int status
,
550 void *command_data
, void *opaque
)
552 IscsiAIOCB
*acb
= opaque
;
554 if (acb
->canceled
!= 0) {
560 if (status
== SCSI_STATUS_CHECK_CONDITION
561 && acb
->task
->sense
.key
== SCSI_SENSE_UNIT_ATTENTION
562 && acb
->retries
-- > 0) {
563 scsi_free_scsi_task(acb
->task
);
565 if (iscsi_aio_flush_acb(acb
) == 0) {
566 iscsi_set_events(acb
->iscsilun
);
570 error_report("Failed to sync10 data on iSCSI lun. %s",
571 iscsi_get_error(iscsi
));
575 iscsi_schedule_bh(acb
);
579 iscsi_aio_flush_acb(IscsiAIOCB
*acb
)
581 struct iscsi_context
*iscsi
= acb
->iscsilun
->iscsi
;
585 acb
->status
= -EINPROGRESS
;
588 acb
->task
= iscsi_synchronizecache10_task(iscsi
, acb
->iscsilun
->lun
,
590 iscsi_synccache10_cb
,
592 if (acb
->task
== NULL
) {
593 error_report("iSCSI: Failed to send synchronizecache10 command. %s",
594 iscsi_get_error(iscsi
));
601 static BlockDriverAIOCB
*
602 iscsi_aio_flush(BlockDriverState
*bs
,
603 BlockDriverCompletionFunc
*cb
, void *opaque
)
605 IscsiLun
*iscsilun
= bs
->opaque
;
609 acb
= qemu_aio_get(&iscsi_aiocb_info
, bs
, cb
, opaque
);
611 acb
->iscsilun
= iscsilun
;
612 acb
->retries
= ISCSI_CMD_RETRIES
;
614 if (iscsi_aio_flush_acb(acb
) != 0) {
615 qemu_aio_release(acb
);
619 iscsi_set_events(iscsilun
);
626 iscsi_aio_ioctl_cb(struct iscsi_context
*iscsi
, int status
,
627 void *command_data
, void *opaque
)
629 IscsiAIOCB
*acb
= opaque
;
634 if (acb
->canceled
!= 0) {
640 error_report("Failed to ioctl(SG_IO) to iSCSI lun. %s",
641 iscsi_get_error(iscsi
));
645 acb
->ioh
->driver_status
= 0;
646 acb
->ioh
->host_status
= 0;
649 #define SG_ERR_DRIVER_SENSE 0x08
651 if (status
== SCSI_STATUS_CHECK_CONDITION
&& acb
->task
->datain
.size
>= 2) {
654 acb
->ioh
->driver_status
|= SG_ERR_DRIVER_SENSE
;
656 acb
->ioh
->sb_len_wr
= acb
->task
->datain
.size
- 2;
657 ss
= (acb
->ioh
->mx_sb_len
>= acb
->ioh
->sb_len_wr
) ?
658 acb
->ioh
->mx_sb_len
: acb
->ioh
->sb_len_wr
;
659 memcpy(acb
->ioh
->sbp
, &acb
->task
->datain
.data
[2], ss
);
662 iscsi_schedule_bh(acb
);
665 static BlockDriverAIOCB
*iscsi_aio_ioctl(BlockDriverState
*bs
,
666 unsigned long int req
, void *buf
,
667 BlockDriverCompletionFunc
*cb
, void *opaque
)
669 IscsiLun
*iscsilun
= bs
->opaque
;
670 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
671 struct iscsi_data data
;
674 assert(req
== SG_IO
);
676 acb
= qemu_aio_get(&iscsi_aiocb_info
, bs
, cb
, opaque
);
678 acb
->iscsilun
= iscsilun
;
681 acb
->status
= -EINPROGRESS
;
685 acb
->task
= malloc(sizeof(struct scsi_task
));
686 if (acb
->task
== NULL
) {
687 error_report("iSCSI: Failed to allocate task for scsi command. %s",
688 iscsi_get_error(iscsi
));
689 qemu_aio_release(acb
);
692 memset(acb
->task
, 0, sizeof(struct scsi_task
));
694 switch (acb
->ioh
->dxfer_direction
) {
695 case SG_DXFER_TO_DEV
:
696 acb
->task
->xfer_dir
= SCSI_XFER_WRITE
;
698 case SG_DXFER_FROM_DEV
:
699 acb
->task
->xfer_dir
= SCSI_XFER_READ
;
702 acb
->task
->xfer_dir
= SCSI_XFER_NONE
;
706 acb
->task
->cdb_size
= acb
->ioh
->cmd_len
;
707 memcpy(&acb
->task
->cdb
[0], acb
->ioh
->cmdp
, acb
->ioh
->cmd_len
);
708 acb
->task
->expxferlen
= acb
->ioh
->dxfer_len
;
711 if (acb
->task
->xfer_dir
== SCSI_XFER_WRITE
) {
712 if (acb
->ioh
->iovec_count
== 0) {
713 data
.data
= acb
->ioh
->dxferp
;
714 data
.size
= acb
->ioh
->dxfer_len
;
716 #if defined(LIBISCSI_FEATURE_IOVECTOR)
717 scsi_task_set_iov_out(acb
->task
,
718 (struct scsi_iovec
*) acb
->ioh
->dxferp
,
719 acb
->ioh
->iovec_count
);
721 struct iovec
*iov
= (struct iovec
*)acb
->ioh
->dxferp
;
723 acb
->buf
= g_malloc(acb
->ioh
->dxfer_len
);
724 data
.data
= acb
->buf
;
725 data
.size
= iov_to_buf(iov
, acb
->ioh
->iovec_count
, 0,
726 acb
->buf
, acb
->ioh
->dxfer_len
);
731 if (iscsi_scsi_command_async(iscsi
, iscsilun
->lun
, acb
->task
,
733 (data
.size
> 0) ? &data
: NULL
,
735 scsi_free_scsi_task(acb
->task
);
736 qemu_aio_release(acb
);
740 /* tell libiscsi to read straight into the buffer we got from ioctl */
741 if (acb
->task
->xfer_dir
== SCSI_XFER_READ
) {
742 if (acb
->ioh
->iovec_count
== 0) {
743 scsi_task_add_data_in_buffer(acb
->task
,
747 #if defined(LIBISCSI_FEATURE_IOVECTOR)
748 scsi_task_set_iov_in(acb
->task
,
749 (struct scsi_iovec
*) acb
->ioh
->dxferp
,
750 acb
->ioh
->iovec_count
);
753 for (i
= 0; i
< acb
->ioh
->iovec_count
; i
++) {
754 struct iovec
*iov
= (struct iovec
*)acb
->ioh
->dxferp
;
756 scsi_task_add_data_in_buffer(acb
->task
,
764 iscsi_set_events(iscsilun
);
770 static void ioctl_cb(void *opaque
, int status
)
772 int *p_status
= opaque
;
776 static int iscsi_ioctl(BlockDriverState
*bs
, unsigned long int req
, void *buf
)
778 IscsiLun
*iscsilun
= bs
->opaque
;
782 case SG_GET_VERSION_NUM
:
786 ((struct sg_scsi_id
*)buf
)->scsi_type
= iscsilun
->type
;
789 status
= -EINPROGRESS
;
790 iscsi_aio_ioctl(bs
, req
, buf
, ioctl_cb
, &status
);
792 while (status
== -EINPROGRESS
) {
805 iscsi_getlength(BlockDriverState
*bs
)
807 IscsiLun
*iscsilun
= bs
->opaque
;
810 len
= iscsilun
->num_blocks
;
811 len
*= iscsilun
->block_size
;
816 #if defined(LIBISCSI_FEATURE_IOVECTOR)
818 static int64_t coroutine_fn
iscsi_co_get_block_status(BlockDriverState
*bs
,
820 int nb_sectors
, int *pnum
)
822 IscsiLun
*iscsilun
= bs
->opaque
;
823 struct scsi_get_lba_status
*lbas
= NULL
;
824 struct scsi_lba_status_descriptor
*lbasd
= NULL
;
825 struct IscsiTask iTask
;
828 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
830 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
835 /* default to all sectors allocated */
836 ret
= BDRV_BLOCK_DATA
;
837 ret
|= (sector_num
<< BDRV_SECTOR_BITS
) | BDRV_BLOCK_OFFSET_VALID
;
840 /* LUN does not support logical block provisioning */
841 if (iscsilun
->lbpme
== 0) {
846 if (iscsi_get_lba_status_task(iscsilun
->iscsi
, iscsilun
->lun
,
847 sector_qemu2lun(sector_num
, iscsilun
),
848 8 + 16, iscsi_co_generic_cb
,
854 while (!iTask
.complete
) {
855 iscsi_set_events(iscsilun
);
856 qemu_coroutine_yield();
859 if (iTask
.do_retry
) {
860 if (iTask
.task
!= NULL
) {
861 scsi_free_scsi_task(iTask
.task
);
867 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
868 /* in case the get_lba_status_callout fails (i.e.
869 * because the device is busy or the cmd is not
870 * supported) we pretend all blocks are allocated
871 * for backwards compatibility */
875 lbas
= scsi_datain_unmarshall(iTask
.task
);
881 lbasd
= &lbas
->descriptors
[0];
883 if (sector_qemu2lun(sector_num
, iscsilun
) != lbasd
->lba
) {
888 *pnum
= sector_lun2qemu(lbasd
->num_blocks
, iscsilun
);
889 if (*pnum
> nb_sectors
) {
893 if (lbasd
->provisioning
== SCSI_PROVISIONING_TYPE_DEALLOCATED
||
894 lbasd
->provisioning
== SCSI_PROVISIONING_TYPE_ANCHORED
) {
895 ret
&= ~BDRV_BLOCK_DATA
;
896 if (iscsilun
->lbprz
) {
897 ret
|= BDRV_BLOCK_ZERO
;
902 if (iTask
.task
!= NULL
) {
903 scsi_free_scsi_task(iTask
.task
);
908 #endif /* LIBISCSI_FEATURE_IOVECTOR */
911 coroutine_fn
iscsi_co_discard(BlockDriverState
*bs
, int64_t sector_num
,
914 IscsiLun
*iscsilun
= bs
->opaque
;
915 struct IscsiTask iTask
;
916 struct unmap_list list
;
918 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
922 if (!iscsilun
->lbp
.lbpu
) {
923 /* UNMAP is not supported by the target */
927 list
.lba
= sector_qemu2lun(sector_num
, iscsilun
);
928 list
.num
= sector_qemu2lun(nb_sectors
, iscsilun
);
930 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
932 if (iscsi_unmap_task(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0, &list
, 1,
933 iscsi_co_generic_cb
, &iTask
) == NULL
) {
937 while (!iTask
.complete
) {
938 iscsi_set_events(iscsilun
);
939 qemu_coroutine_yield();
942 if (iTask
.task
!= NULL
) {
943 scsi_free_scsi_task(iTask
.task
);
947 if (iTask
.do_retry
) {
951 if (iTask
.status
== SCSI_STATUS_CHECK_CONDITION
) {
952 /* the target might fail with a check condition if it
953 is not happy with the alignment of the UNMAP request
954 we silently fail in this case */
958 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
965 #if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED)
968 coroutine_fn
iscsi_co_write_zeroes(BlockDriverState
*bs
, int64_t sector_num
,
969 int nb_sectors
, BdrvRequestFlags flags
)
971 IscsiLun
*iscsilun
= bs
->opaque
;
972 struct IscsiTask iTask
;
976 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
980 if (!(flags
& BDRV_REQ_MAY_UNMAP
) && !iscsilun
->has_write_same
) {
981 /* WRITE SAME without UNMAP is not supported by the target */
985 if ((flags
& BDRV_REQ_MAY_UNMAP
) && !iscsilun
->lbp
.lbpws
) {
986 /* WRITE SAME with UNMAP is not supported by the target */
990 lba
= sector_qemu2lun(sector_num
, iscsilun
);
991 nb_blocks
= sector_qemu2lun(nb_sectors
, iscsilun
);
993 if (iscsilun
->zeroblock
== NULL
) {
994 iscsilun
->zeroblock
= g_malloc0(iscsilun
->block_size
);
997 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
999 if (iscsi_writesame16_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
1000 iscsilun
->zeroblock
, iscsilun
->block_size
,
1001 nb_blocks
, 0, !!(flags
& BDRV_REQ_MAY_UNMAP
),
1002 0, 0, iscsi_co_generic_cb
, &iTask
) == NULL
) {
1006 while (!iTask
.complete
) {
1007 iscsi_set_events(iscsilun
);
1008 qemu_coroutine_yield();
1011 if (iTask
.task
!= NULL
) {
1012 scsi_free_scsi_task(iTask
.task
);
1016 if (iTask
.do_retry
) {
1020 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
1021 if (iTask
.status
== SCSI_STATUS_CHECK_CONDITION
&&
1022 iTask
.task
->sense
.key
== SCSI_SENSE_ILLEGAL_REQUEST
&&
1023 iTask
.task
->sense
.ascq
== SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE
) {
1024 /* WRITE SAME is not supported by the target */
1025 iscsilun
->has_write_same
= false;
1035 #endif /* SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED */
1037 static int parse_chap(struct iscsi_context
*iscsi
, const char *target
)
1041 const char *user
= NULL
;
1042 const char *password
= NULL
;
1044 list
= qemu_find_opts("iscsi");
1049 opts
= qemu_opts_find(list
, target
);
1051 opts
= QTAILQ_FIRST(&list
->head
);
1057 user
= qemu_opt_get(opts
, "user");
1062 password
= qemu_opt_get(opts
, "password");
1064 error_report("CHAP username specified but no password was given");
1068 if (iscsi_set_initiator_username_pwd(iscsi
, user
, password
)) {
1069 error_report("Failed to set initiator username and password");
1076 static void parse_header_digest(struct iscsi_context
*iscsi
, const char *target
)
1080 const char *digest
= NULL
;
1082 list
= qemu_find_opts("iscsi");
1087 opts
= qemu_opts_find(list
, target
);
1089 opts
= QTAILQ_FIRST(&list
->head
);
1095 digest
= qemu_opt_get(opts
, "header-digest");
1100 if (!strcmp(digest
, "CRC32C")) {
1101 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_CRC32C
);
1102 } else if (!strcmp(digest
, "NONE")) {
1103 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_NONE
);
1104 } else if (!strcmp(digest
, "CRC32C-NONE")) {
1105 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_CRC32C_NONE
);
1106 } else if (!strcmp(digest
, "NONE-CRC32C")) {
1107 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_NONE_CRC32C
);
1109 error_report("Invalid header-digest setting : %s", digest
);
1113 static char *parse_initiator_name(const char *target
)
1119 UuidInfo
*uuid_info
;
1121 list
= qemu_find_opts("iscsi");
1123 opts
= qemu_opts_find(list
, target
);
1125 opts
= QTAILQ_FIRST(&list
->head
);
1128 name
= qemu_opt_get(opts
, "initiator-name");
1130 return g_strdup(name
);
1135 uuid_info
= qmp_query_uuid(NULL
);
1136 if (strcmp(uuid_info
->UUID
, UUID_NONE
) == 0) {
1137 name
= qemu_get_vm_name();
1139 name
= uuid_info
->UUID
;
1141 iscsi_name
= g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
1142 name
? ":" : "", name
? name
: "");
1143 qapi_free_UuidInfo(uuid_info
);
1147 #if defined(LIBISCSI_FEATURE_NOP_COUNTER)
1148 static void iscsi_nop_timed_event(void *opaque
)
1150 IscsiLun
*iscsilun
= opaque
;
1152 if (iscsi_get_nops_in_flight(iscsilun
->iscsi
) > MAX_NOP_FAILURES
) {
1153 error_report("iSCSI: NOP timeout. Reconnecting...");
1154 iscsi_reconnect(iscsilun
->iscsi
);
1157 if (iscsi_nop_out_async(iscsilun
->iscsi
, NULL
, NULL
, 0, NULL
) != 0) {
1158 error_report("iSCSI: failed to sent NOP-Out. Disabling NOP messages.");
1162 timer_mod(iscsilun
->nop_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + NOP_INTERVAL
);
1163 iscsi_set_events(iscsilun
);
1167 static int iscsi_readcapacity_sync(IscsiLun
*iscsilun
)
1169 struct scsi_task
*task
= NULL
;
1170 struct scsi_readcapacity10
*rc10
= NULL
;
1171 struct scsi_readcapacity16
*rc16
= NULL
;
1173 int retries
= ISCSI_CMD_RETRIES
;
1177 scsi_free_scsi_task(task
);
1181 switch (iscsilun
->type
) {
1183 task
= iscsi_readcapacity16_sync(iscsilun
->iscsi
, iscsilun
->lun
);
1184 if (task
!= NULL
&& task
->status
== SCSI_STATUS_GOOD
) {
1185 rc16
= scsi_datain_unmarshall(task
);
1187 error_report("iSCSI: Failed to unmarshall readcapacity16 data.");
1190 iscsilun
->block_size
= rc16
->block_length
;
1191 iscsilun
->num_blocks
= rc16
->returned_lba
+ 1;
1192 iscsilun
->lbpme
= rc16
->lbpme
;
1193 iscsilun
->lbprz
= rc16
->lbprz
;
1198 task
= iscsi_readcapacity10_sync(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0);
1199 if (task
!= NULL
&& task
->status
== SCSI_STATUS_GOOD
) {
1200 rc10
= scsi_datain_unmarshall(task
);
1202 error_report("iSCSI: Failed to unmarshall readcapacity10 data.");
1205 iscsilun
->block_size
= rc10
->block_size
;
1206 if (rc10
->lba
== 0) {
1207 /* blank disk loaded */
1208 iscsilun
->num_blocks
= 0;
1210 iscsilun
->num_blocks
= rc10
->lba
+ 1;
1218 } while (task
!= NULL
&& task
->status
== SCSI_STATUS_CHECK_CONDITION
1219 && task
->sense
.key
== SCSI_SENSE_UNIT_ATTENTION
1222 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1223 error_report("iSCSI: failed to send readcapacity10 command.");
1227 scsi_free_scsi_task(task
);
1232 /* TODO Convert to fine grained options */
1233 static QemuOptsList runtime_opts
= {
1235 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
1239 .type
= QEMU_OPT_STRING
,
1240 .help
= "URL to the iscsi image",
1242 { /* end of list */ }
1246 static struct scsi_task
*iscsi_do_inquiry(struct iscsi_context
*iscsi
,
1247 int lun
, int evpd
, int pc
) {
1249 struct scsi_task
*task
= NULL
;
1250 task
= iscsi_inquiry_sync(iscsi
, lun
, evpd
, pc
, 64);
1251 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1254 full_size
= scsi_datain_getfullsize(task
);
1255 if (full_size
> task
->datain
.size
) {
1256 scsi_free_scsi_task(task
);
1258 /* we need more data for the full list */
1259 task
= iscsi_inquiry_sync(iscsi
, lun
, evpd
, pc
, full_size
);
1260 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1268 error_report("iSCSI: Inquiry command failed : %s",
1269 iscsi_get_error(iscsi
));
1271 scsi_free_scsi_task(task
);
1278 * We support iscsi url's on the form
1279 * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
1281 static int iscsi_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
1284 IscsiLun
*iscsilun
= bs
->opaque
;
1285 struct iscsi_context
*iscsi
= NULL
;
1286 struct iscsi_url
*iscsi_url
= NULL
;
1287 struct scsi_task
*task
= NULL
;
1288 struct scsi_inquiry_standard
*inq
= NULL
;
1289 char *initiator_name
= NULL
;
1291 Error
*local_err
= NULL
;
1292 const char *filename
;
1295 if ((BDRV_SECTOR_SIZE
% 512) != 0) {
1296 error_report("iSCSI: Invalid BDRV_SECTOR_SIZE. "
1297 "BDRV_SECTOR_SIZE(%lld) is not a multiple "
1298 "of 512", BDRV_SECTOR_SIZE
);
1302 opts
= qemu_opts_create_nofail(&runtime_opts
);
1303 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
1304 if (error_is_set(&local_err
)) {
1305 qerror_report_err(local_err
);
1306 error_free(local_err
);
1311 filename
= qemu_opt_get(opts
, "filename");
1314 iscsi_url
= iscsi_parse_full_url(iscsi
, filename
);
1315 if (iscsi_url
== NULL
) {
1316 error_report("Failed to parse URL : %s", filename
);
1321 memset(iscsilun
, 0, sizeof(IscsiLun
));
1323 initiator_name
= parse_initiator_name(iscsi_url
->target
);
1325 iscsi
= iscsi_create_context(initiator_name
);
1326 if (iscsi
== NULL
) {
1327 error_report("iSCSI: Failed to create iSCSI context.");
1332 if (iscsi_set_targetname(iscsi
, iscsi_url
->target
)) {
1333 error_report("iSCSI: Failed to set target name.");
1338 if (iscsi_url
->user
!= NULL
) {
1339 ret
= iscsi_set_initiator_username_pwd(iscsi
, iscsi_url
->user
,
1342 error_report("Failed to set initiator username and password");
1348 /* check if we got CHAP username/password via the options */
1349 if (parse_chap(iscsi
, iscsi_url
->target
) != 0) {
1350 error_report("iSCSI: Failed to set CHAP user/password");
1355 if (iscsi_set_session_type(iscsi
, ISCSI_SESSION_NORMAL
) != 0) {
1356 error_report("iSCSI: Failed to set session type to normal.");
1361 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_NONE_CRC32C
);
1363 /* check if we got HEADER_DIGEST via the options */
1364 parse_header_digest(iscsi
, iscsi_url
->target
);
1366 if (iscsi_full_connect_sync(iscsi
, iscsi_url
->portal
, iscsi_url
->lun
) != 0) {
1367 error_report("iSCSI: Failed to connect to LUN : %s",
1368 iscsi_get_error(iscsi
));
1373 iscsilun
->iscsi
= iscsi
;
1374 iscsilun
->lun
= iscsi_url
->lun
;
1376 task
= iscsi_inquiry_sync(iscsi
, iscsilun
->lun
, 0, 0, 36);
1378 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1379 error_report("iSCSI: failed to send inquiry command.");
1384 inq
= scsi_datain_unmarshall(task
);
1386 error_report("iSCSI: Failed to unmarshall inquiry data.");
1391 iscsilun
->type
= inq
->periperal_device_type
;
1392 iscsilun
->has_write_same
= true;
1394 if ((ret
= iscsi_readcapacity_sync(iscsilun
)) != 0) {
1397 bs
->total_sectors
= sector_lun2qemu(iscsilun
->num_blocks
, iscsilun
);
1399 /* Medium changer or tape. We dont have any emulation for this so this must
1400 * be sg ioctl compatible. We force it to be sg, otherwise qemu will try
1401 * to read from the device to guess the image format.
1403 if (iscsilun
->type
== TYPE_MEDIUM_CHANGER
||
1404 iscsilun
->type
== TYPE_TAPE
) {
1408 if (iscsilun
->lbpme
) {
1409 struct scsi_inquiry_logical_block_provisioning
*inq_lbp
;
1410 task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 1,
1411 SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING
);
1416 inq_lbp
= scsi_datain_unmarshall(task
);
1417 if (inq_lbp
== NULL
) {
1418 error_report("iSCSI: failed to unmarshall inquiry datain blob");
1422 memcpy(&iscsilun
->lbp
, inq_lbp
,
1423 sizeof(struct scsi_inquiry_logical_block_provisioning
));
1424 scsi_free_scsi_task(task
);
1428 if (iscsilun
->lbp
.lbpu
|| iscsilun
->lbp
.lbpws
) {
1429 struct scsi_inquiry_block_limits
*inq_bl
;
1430 task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 1,
1431 SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS
);
1436 inq_bl
= scsi_datain_unmarshall(task
);
1437 if (inq_bl
== NULL
) {
1438 error_report("iSCSI: failed to unmarshall inquiry datain blob");
1442 memcpy(&iscsilun
->bl
, inq_bl
,
1443 sizeof(struct scsi_inquiry_block_limits
));
1444 scsi_free_scsi_task(task
);
1447 if (iscsilun
->bl
.max_unmap
< 0xffffffff) {
1448 bs
->bl
.max_discard
= sector_lun2qemu(iscsilun
->bl
.max_unmap
,
1451 bs
->bl
.discard_alignment
= sector_lun2qemu(iscsilun
->bl
.opt_unmap_gran
,
1454 if (iscsilun
->bl
.max_ws_len
< 0xffffffff) {
1455 bs
->bl
.max_write_zeroes
= sector_lun2qemu(iscsilun
->bl
.max_ws_len
,
1458 bs
->bl
.write_zeroes_alignment
= sector_lun2qemu(iscsilun
->bl
.opt_unmap_gran
,
1461 bs
->bl
.opt_transfer_length
= sector_lun2qemu(iscsilun
->bl
.opt_xfer_len
,
1465 #if defined(LIBISCSI_FEATURE_NOP_COUNTER)
1466 /* Set up a timer for sending out iSCSI NOPs */
1467 iscsilun
->nop_timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, iscsi_nop_timed_event
, iscsilun
);
1468 timer_mod(iscsilun
->nop_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + NOP_INTERVAL
);
1472 qemu_opts_del(opts
);
1473 if (initiator_name
!= NULL
) {
1474 g_free(initiator_name
);
1476 if (iscsi_url
!= NULL
) {
1477 iscsi_destroy_url(iscsi_url
);
1480 scsi_free_scsi_task(task
);
1484 if (iscsi
!= NULL
) {
1485 iscsi_destroy_context(iscsi
);
1487 memset(iscsilun
, 0, sizeof(IscsiLun
));
1492 static void iscsi_close(BlockDriverState
*bs
)
1494 IscsiLun
*iscsilun
= bs
->opaque
;
1495 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
1497 if (iscsilun
->nop_timer
) {
1498 timer_del(iscsilun
->nop_timer
);
1499 timer_free(iscsilun
->nop_timer
);
1501 qemu_aio_set_fd_handler(iscsi_get_fd(iscsi
), NULL
, NULL
, NULL
);
1502 iscsi_destroy_context(iscsi
);
1503 g_free(iscsilun
->zeroblock
);
1504 memset(iscsilun
, 0, sizeof(IscsiLun
));
1507 static int iscsi_truncate(BlockDriverState
*bs
, int64_t offset
)
1509 IscsiLun
*iscsilun
= bs
->opaque
;
1512 if (iscsilun
->type
!= TYPE_DISK
) {
1516 if ((ret
= iscsi_readcapacity_sync(iscsilun
)) != 0) {
1520 if (offset
> iscsi_getlength(bs
)) {
1527 static int iscsi_create(const char *filename
, QEMUOptionParameter
*options
,
1531 int64_t total_size
= 0;
1532 BlockDriverState
*bs
;
1533 IscsiLun
*iscsilun
= NULL
;
1538 /* Read out options */
1539 while (options
&& options
->name
) {
1540 if (!strcmp(options
->name
, "size")) {
1541 total_size
= options
->value
.n
/ BDRV_SECTOR_SIZE
;
1546 bs
->opaque
= g_malloc0(sizeof(struct IscsiLun
));
1547 iscsilun
= bs
->opaque
;
1549 bs_options
= qdict_new();
1550 qdict_put(bs_options
, "filename", qstring_from_str(filename
));
1551 ret
= iscsi_open(bs
, bs_options
, 0, NULL
);
1552 QDECREF(bs_options
);
1557 if (iscsilun
->nop_timer
) {
1558 timer_del(iscsilun
->nop_timer
);
1559 timer_free(iscsilun
->nop_timer
);
1561 if (iscsilun
->type
!= TYPE_DISK
) {
1565 if (bs
->total_sectors
< total_size
) {
1572 if (iscsilun
->iscsi
!= NULL
) {
1573 iscsi_destroy_context(iscsilun
->iscsi
);
1581 static int iscsi_get_info(BlockDriverState
*bs
, BlockDriverInfo
*bdi
)
1583 IscsiLun
*iscsilun
= bs
->opaque
;
1584 bdi
->unallocated_blocks_are_zero
= !!iscsilun
->lbprz
;
1585 bdi
->can_write_zeroes_with_unmap
= iscsilun
->lbprz
&& iscsilun
->lbp
.lbpws
;
1586 /* Guess the internal cluster (page) size of the iscsi target by the means
1587 * of opt_unmap_gran. Transfer the unmap granularity only if it has a
1588 * reasonable size for bdi->cluster_size */
1589 if (iscsilun
->bl
.opt_unmap_gran
* iscsilun
->block_size
>= 64 * 1024 &&
1590 iscsilun
->bl
.opt_unmap_gran
* iscsilun
->block_size
<= 16 * 1024 * 1024) {
1591 bdi
->cluster_size
= iscsilun
->bl
.opt_unmap_gran
* iscsilun
->block_size
;
1596 static QEMUOptionParameter iscsi_create_options
[] = {
1598 .name
= BLOCK_OPT_SIZE
,
1600 .help
= "Virtual disk size"
1605 static BlockDriver bdrv_iscsi
= {
1606 .format_name
= "iscsi",
1607 .protocol_name
= "iscsi",
1609 .instance_size
= sizeof(IscsiLun
),
1610 .bdrv_needs_filename
= true,
1611 .bdrv_file_open
= iscsi_open
,
1612 .bdrv_close
= iscsi_close
,
1613 .bdrv_create
= iscsi_create
,
1614 .create_options
= iscsi_create_options
,
1616 .bdrv_getlength
= iscsi_getlength
,
1617 .bdrv_get_info
= iscsi_get_info
,
1618 .bdrv_truncate
= iscsi_truncate
,
1620 #if defined(LIBISCSI_FEATURE_IOVECTOR)
1621 .bdrv_co_get_block_status
= iscsi_co_get_block_status
,
1623 .bdrv_co_discard
= iscsi_co_discard
,
1624 #if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED)
1625 .bdrv_co_write_zeroes
= iscsi_co_write_zeroes
,
1628 .bdrv_aio_readv
= iscsi_aio_readv
,
1629 .bdrv_aio_writev
= iscsi_aio_writev
,
1630 .bdrv_aio_flush
= iscsi_aio_flush
,
1633 .bdrv_ioctl
= iscsi_ioctl
,
1634 .bdrv_aio_ioctl
= iscsi_aio_ioctl
,
1638 static QemuOptsList qemu_iscsi_opts
= {
1640 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
1644 .type
= QEMU_OPT_STRING
,
1645 .help
= "username for CHAP authentication to target",
1648 .type
= QEMU_OPT_STRING
,
1649 .help
= "password for CHAP authentication to target",
1651 .name
= "header-digest",
1652 .type
= QEMU_OPT_STRING
,
1653 .help
= "HeaderDigest setting. "
1654 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
1656 .name
= "initiator-name",
1657 .type
= QEMU_OPT_STRING
,
1658 .help
= "Initiator iqn name to use when connecting",
1660 { /* end of list */ }
1664 static void iscsi_block_init(void)
1666 bdrv_register(&bdrv_iscsi
);
1667 qemu_add_opts(&qemu_iscsi_opts
);
1670 block_init(iscsi_block_init
);