2 * QEMU Block driver for iSCSI images
4 * Copyright (c) 2010-2011 Ronnie Sahlberg <ronniesahlberg@gmail.com>
5 * Copyright (c) 2012-2014 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 "qemu/bitops.h"
34 #include "qemu/bitmap.h"
35 #include "block/block_int.h"
37 #include "block/scsi.h"
39 #include "sysemu/sysemu.h"
40 #include "qmp-commands.h"
42 #include <iscsi/iscsi.h>
43 #include <iscsi/scsi-lowlevel.h>
47 #include <block/scsi.h>
50 typedef struct IscsiLun
{
51 struct iscsi_context
*iscsi
;
52 AioContext
*aio_context
;
54 enum scsi_inquiry_peripheral_device_type type
;
61 uint8_t has_write_same
;
62 struct scsi_inquiry_logical_block_provisioning lbp
;
63 struct scsi_inquiry_block_limits bl
;
64 unsigned char *zeroblock
;
65 unsigned long *allocationmap
;
69 typedef struct IscsiTask
{
74 struct scsi_task
*task
;
80 typedef struct IscsiAIOCB
{
81 BlockDriverAIOCB common
;
85 struct scsi_task
*task
;
97 #define NOP_INTERVAL 5000
98 #define MAX_NOP_FAILURES 3
99 #define ISCSI_CMD_RETRIES 5
101 /* this threshhold is a trade-off knob to choose between
102 * the potential additional overhead of an extra GET_LBA_STATUS request
103 * vs. unnecessarily reading a lot of zero sectors over the wire.
104 * If a read request is greater or equal than ISCSI_CHECKALLOC_THRES
105 * sectors we check the allocation status of the area covered by the
106 * request first if the allocationmap indicates that the area might be
108 #define ISCSI_CHECKALLOC_THRES 64
115 qemu_bh_delete(acb
->bh
);
120 if (acb
->canceled
== 0) {
121 acb
->common
.cb(acb
->common
.opaque
, acb
->status
);
124 if (acb
->task
!= NULL
) {
125 scsi_free_scsi_task(acb
->task
);
129 qemu_aio_release(acb
);
133 iscsi_schedule_bh(IscsiAIOCB
*acb
)
138 acb
->bh
= aio_bh_new(acb
->iscsilun
->aio_context
, iscsi_bh_cb
, acb
);
139 qemu_bh_schedule(acb
->bh
);
142 static void iscsi_co_generic_bh_cb(void *opaque
)
144 struct IscsiTask
*iTask
= opaque
;
145 qemu_bh_delete(iTask
->bh
);
146 qemu_coroutine_enter(iTask
->co
, NULL
);
150 iscsi_co_generic_cb(struct iscsi_context
*iscsi
, int status
,
151 void *command_data
, void *opaque
)
153 struct IscsiTask
*iTask
= opaque
;
154 struct scsi_task
*task
= command_data
;
157 iTask
->status
= status
;
161 if (iTask
->retries
-- > 0 && status
== SCSI_STATUS_CHECK_CONDITION
162 && task
->sense
.key
== SCSI_SENSE_UNIT_ATTENTION
) {
163 error_report("iSCSI CheckCondition: %s", iscsi_get_error(iscsi
));
168 if (status
!= SCSI_STATUS_GOOD
) {
169 error_report("iSCSI Failure: %s", iscsi_get_error(iscsi
));
174 iTask
->bh
= aio_bh_new(iTask
->iscsilun
->aio_context
,
175 iscsi_co_generic_bh_cb
, iTask
);
176 qemu_bh_schedule(iTask
->bh
);
180 static void iscsi_co_init_iscsitask(IscsiLun
*iscsilun
, struct IscsiTask
*iTask
)
182 *iTask
= (struct IscsiTask
) {
183 .co
= qemu_coroutine_self(),
184 .retries
= ISCSI_CMD_RETRIES
,
185 .iscsilun
= iscsilun
,
190 iscsi_abort_task_cb(struct iscsi_context
*iscsi
, int status
, void *command_data
,
193 IscsiAIOCB
*acb
= private_data
;
195 acb
->status
= -ECANCELED
;
196 iscsi_schedule_bh(acb
);
200 iscsi_aio_cancel(BlockDriverAIOCB
*blockacb
)
202 IscsiAIOCB
*acb
= (IscsiAIOCB
*)blockacb
;
203 IscsiLun
*iscsilun
= acb
->iscsilun
;
205 if (acb
->status
!= -EINPROGRESS
) {
211 /* send a task mgmt call to the target to cancel the task on the target */
212 iscsi_task_mgmt_abort_task_async(iscsilun
->iscsi
, acb
->task
,
213 iscsi_abort_task_cb
, acb
);
215 while (acb
->status
== -EINPROGRESS
) {
216 aio_poll(iscsilun
->aio_context
, true);
220 static const AIOCBInfo iscsi_aiocb_info
= {
221 .aiocb_size
= sizeof(IscsiAIOCB
),
222 .cancel
= iscsi_aio_cancel
,
226 static void iscsi_process_read(void *arg
);
227 static void iscsi_process_write(void *arg
);
230 iscsi_set_events(IscsiLun
*iscsilun
)
232 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
235 /* We always register a read handler. */
237 ev
|= iscsi_which_events(iscsi
);
238 if (ev
!= iscsilun
->events
) {
239 aio_set_fd_handler(iscsilun
->aio_context
,
242 (ev
& POLLOUT
) ? iscsi_process_write
: NULL
,
247 iscsilun
->events
= ev
;
251 iscsi_process_read(void *arg
)
253 IscsiLun
*iscsilun
= arg
;
254 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
256 iscsi_service(iscsi
, POLLIN
);
257 iscsi_set_events(iscsilun
);
261 iscsi_process_write(void *arg
)
263 IscsiLun
*iscsilun
= arg
;
264 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
266 iscsi_service(iscsi
, POLLOUT
);
267 iscsi_set_events(iscsilun
);
270 static int64_t sector_lun2qemu(int64_t sector
, IscsiLun
*iscsilun
)
272 return sector
* iscsilun
->block_size
/ BDRV_SECTOR_SIZE
;
275 static int64_t sector_qemu2lun(int64_t sector
, IscsiLun
*iscsilun
)
277 return sector
* BDRV_SECTOR_SIZE
/ iscsilun
->block_size
;
280 static bool is_request_lun_aligned(int64_t sector_num
, int nb_sectors
,
283 if ((sector_num
* BDRV_SECTOR_SIZE
) % iscsilun
->block_size
||
284 (nb_sectors
* BDRV_SECTOR_SIZE
) % iscsilun
->block_size
) {
285 error_report("iSCSI misaligned request: "
286 "iscsilun->block_size %u, sector_num %" PRIi64
288 iscsilun
->block_size
, sector_num
, nb_sectors
);
294 static void iscsi_allocationmap_set(IscsiLun
*iscsilun
, int64_t sector_num
,
297 if (iscsilun
->allocationmap
== NULL
) {
300 bitmap_set(iscsilun
->allocationmap
,
301 sector_num
/ iscsilun
->cluster_sectors
,
302 DIV_ROUND_UP(nb_sectors
, iscsilun
->cluster_sectors
));
305 static void iscsi_allocationmap_clear(IscsiLun
*iscsilun
, int64_t sector_num
,
308 int64_t cluster_num
, nb_clusters
;
309 if (iscsilun
->allocationmap
== NULL
) {
312 cluster_num
= DIV_ROUND_UP(sector_num
, iscsilun
->cluster_sectors
);
313 nb_clusters
= (sector_num
+ nb_sectors
) / iscsilun
->cluster_sectors
315 if (nb_clusters
> 0) {
316 bitmap_clear(iscsilun
->allocationmap
, cluster_num
, nb_clusters
);
320 static int coroutine_fn
iscsi_co_writev(BlockDriverState
*bs
,
321 int64_t sector_num
, int nb_sectors
,
324 IscsiLun
*iscsilun
= bs
->opaque
;
325 struct IscsiTask iTask
;
327 uint32_t num_sectors
;
328 uint8_t *data
= NULL
;
331 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
335 lba
= sector_qemu2lun(sector_num
, iscsilun
);
336 num_sectors
= sector_qemu2lun(nb_sectors
, iscsilun
);
337 #if !defined(LIBISCSI_FEATURE_IOVECTOR)
338 /* if the iovec only contains one buffer we can pass it directly */
339 if (iov
->niov
== 1) {
340 data
= iov
->iov
[0].iov_base
;
342 size_t size
= MIN(nb_sectors
* BDRV_SECTOR_SIZE
, iov
->size
);
343 buf
= g_malloc(size
);
344 qemu_iovec_to_buf(iov
, 0, buf
, size
);
348 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
350 iTask
.task
= iscsi_write16_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
351 data
, num_sectors
* iscsilun
->block_size
,
352 iscsilun
->block_size
, 0, 0, 0, 0, 0,
353 iscsi_co_generic_cb
, &iTask
);
354 if (iTask
.task
== NULL
) {
358 #if defined(LIBISCSI_FEATURE_IOVECTOR)
359 scsi_task_set_iov_out(iTask
.task
, (struct scsi_iovec
*) iov
->iov
,
362 while (!iTask
.complete
) {
363 iscsi_set_events(iscsilun
);
364 qemu_coroutine_yield();
367 if (iTask
.task
!= NULL
) {
368 scsi_free_scsi_task(iTask
.task
);
372 if (iTask
.do_retry
) {
379 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
383 iscsi_allocationmap_set(iscsilun
, sector_num
, nb_sectors
);
389 #if defined(LIBISCSI_FEATURE_IOVECTOR)
390 static bool iscsi_allocationmap_is_allocated(IscsiLun
*iscsilun
,
391 int64_t sector_num
, int nb_sectors
)
394 if (iscsilun
->allocationmap
== NULL
) {
397 size
= DIV_ROUND_UP(sector_num
+ nb_sectors
, iscsilun
->cluster_sectors
);
398 return !(find_next_bit(iscsilun
->allocationmap
, size
,
399 sector_num
/ iscsilun
->cluster_sectors
) == size
);
402 static int64_t coroutine_fn
iscsi_co_get_block_status(BlockDriverState
*bs
,
404 int nb_sectors
, int *pnum
)
406 IscsiLun
*iscsilun
= bs
->opaque
;
407 struct scsi_get_lba_status
*lbas
= NULL
;
408 struct scsi_lba_status_descriptor
*lbasd
= NULL
;
409 struct IscsiTask iTask
;
412 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
414 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
419 /* default to all sectors allocated */
420 ret
= BDRV_BLOCK_DATA
;
421 ret
|= (sector_num
<< BDRV_SECTOR_BITS
) | BDRV_BLOCK_OFFSET_VALID
;
424 /* LUN does not support logical block provisioning */
425 if (iscsilun
->lbpme
== 0) {
430 if (iscsi_get_lba_status_task(iscsilun
->iscsi
, iscsilun
->lun
,
431 sector_qemu2lun(sector_num
, iscsilun
),
432 8 + 16, iscsi_co_generic_cb
,
438 while (!iTask
.complete
) {
439 iscsi_set_events(iscsilun
);
440 qemu_coroutine_yield();
443 if (iTask
.do_retry
) {
444 if (iTask
.task
!= NULL
) {
445 scsi_free_scsi_task(iTask
.task
);
452 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
453 /* in case the get_lba_status_callout fails (i.e.
454 * because the device is busy or the cmd is not
455 * supported) we pretend all blocks are allocated
456 * for backwards compatibility */
460 lbas
= scsi_datain_unmarshall(iTask
.task
);
466 lbasd
= &lbas
->descriptors
[0];
468 if (sector_qemu2lun(sector_num
, iscsilun
) != lbasd
->lba
) {
473 *pnum
= sector_lun2qemu(lbasd
->num_blocks
, iscsilun
);
475 if (lbasd
->provisioning
== SCSI_PROVISIONING_TYPE_DEALLOCATED
||
476 lbasd
->provisioning
== SCSI_PROVISIONING_TYPE_ANCHORED
) {
477 ret
&= ~BDRV_BLOCK_DATA
;
478 if (iscsilun
->lbprz
) {
479 ret
|= BDRV_BLOCK_ZERO
;
483 if (ret
& BDRV_BLOCK_ZERO
) {
484 iscsi_allocationmap_clear(iscsilun
, sector_num
, *pnum
);
486 iscsi_allocationmap_set(iscsilun
, sector_num
, *pnum
);
489 if (*pnum
> nb_sectors
) {
493 if (iTask
.task
!= NULL
) {
494 scsi_free_scsi_task(iTask
.task
);
499 #endif /* LIBISCSI_FEATURE_IOVECTOR */
502 static int coroutine_fn
iscsi_co_readv(BlockDriverState
*bs
,
503 int64_t sector_num
, int nb_sectors
,
506 IscsiLun
*iscsilun
= bs
->opaque
;
507 struct IscsiTask iTask
;
509 uint32_t num_sectors
;
510 #if !defined(LIBISCSI_FEATURE_IOVECTOR)
514 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
518 #if defined(LIBISCSI_FEATURE_IOVECTOR)
519 if (iscsilun
->lbprz
&& nb_sectors
>= ISCSI_CHECKALLOC_THRES
&&
520 !iscsi_allocationmap_is_allocated(iscsilun
, sector_num
, nb_sectors
)) {
523 ret
= iscsi_co_get_block_status(bs
, sector_num
, INT_MAX
, &pnum
);
527 if (ret
& BDRV_BLOCK_ZERO
&& pnum
>= nb_sectors
) {
528 qemu_iovec_memset(iov
, 0, 0x00, iov
->size
);
534 lba
= sector_qemu2lun(sector_num
, iscsilun
);
535 num_sectors
= sector_qemu2lun(nb_sectors
, iscsilun
);
537 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
539 switch (iscsilun
->type
) {
541 iTask
.task
= iscsi_read16_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
542 num_sectors
* iscsilun
->block_size
,
543 iscsilun
->block_size
, 0, 0, 0, 0, 0,
544 iscsi_co_generic_cb
, &iTask
);
547 iTask
.task
= iscsi_read10_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
548 num_sectors
* iscsilun
->block_size
,
549 iscsilun
->block_size
,
550 #if !defined(CONFIG_LIBISCSI_1_4) /* API change from 1.4.0 to 1.5.0 */
553 iscsi_co_generic_cb
, &iTask
);
556 if (iTask
.task
== NULL
) {
559 #if defined(LIBISCSI_FEATURE_IOVECTOR)
560 scsi_task_set_iov_in(iTask
.task
, (struct scsi_iovec
*) iov
->iov
, iov
->niov
);
562 for (i
= 0; i
< iov
->niov
; i
++) {
563 scsi_task_add_data_in_buffer(iTask
.task
,
565 iov
->iov
[i
].iov_base
);
569 while (!iTask
.complete
) {
570 iscsi_set_events(iscsilun
);
571 qemu_coroutine_yield();
574 if (iTask
.task
!= NULL
) {
575 scsi_free_scsi_task(iTask
.task
);
579 if (iTask
.do_retry
) {
584 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
591 static int coroutine_fn
iscsi_co_flush(BlockDriverState
*bs
)
593 IscsiLun
*iscsilun
= bs
->opaque
;
594 struct IscsiTask iTask
;
600 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
603 if (iscsi_synchronizecache10_task(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0, 0,
604 0, iscsi_co_generic_cb
, &iTask
) == NULL
) {
608 while (!iTask
.complete
) {
609 iscsi_set_events(iscsilun
);
610 qemu_coroutine_yield();
613 if (iTask
.task
!= NULL
) {
614 scsi_free_scsi_task(iTask
.task
);
618 if (iTask
.do_retry
) {
623 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
632 iscsi_aio_ioctl_cb(struct iscsi_context
*iscsi
, int status
,
633 void *command_data
, void *opaque
)
635 IscsiAIOCB
*acb
= opaque
;
640 if (acb
->canceled
!= 0) {
646 error_report("Failed to ioctl(SG_IO) to iSCSI lun. %s",
647 iscsi_get_error(iscsi
));
651 acb
->ioh
->driver_status
= 0;
652 acb
->ioh
->host_status
= 0;
655 #define SG_ERR_DRIVER_SENSE 0x08
657 if (status
== SCSI_STATUS_CHECK_CONDITION
&& acb
->task
->datain
.size
>= 2) {
660 acb
->ioh
->driver_status
|= SG_ERR_DRIVER_SENSE
;
662 acb
->ioh
->sb_len_wr
= acb
->task
->datain
.size
- 2;
663 ss
= (acb
->ioh
->mx_sb_len
>= acb
->ioh
->sb_len_wr
) ?
664 acb
->ioh
->mx_sb_len
: acb
->ioh
->sb_len_wr
;
665 memcpy(acb
->ioh
->sbp
, &acb
->task
->datain
.data
[2], ss
);
668 iscsi_schedule_bh(acb
);
671 static BlockDriverAIOCB
*iscsi_aio_ioctl(BlockDriverState
*bs
,
672 unsigned long int req
, void *buf
,
673 BlockDriverCompletionFunc
*cb
, void *opaque
)
675 IscsiLun
*iscsilun
= bs
->opaque
;
676 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
677 struct iscsi_data data
;
680 assert(req
== SG_IO
);
682 acb
= qemu_aio_get(&iscsi_aiocb_info
, bs
, cb
, opaque
);
684 acb
->iscsilun
= iscsilun
;
687 acb
->status
= -EINPROGRESS
;
691 acb
->task
= malloc(sizeof(struct scsi_task
));
692 if (acb
->task
== NULL
) {
693 error_report("iSCSI: Failed to allocate task for scsi command. %s",
694 iscsi_get_error(iscsi
));
695 qemu_aio_release(acb
);
698 memset(acb
->task
, 0, sizeof(struct scsi_task
));
700 switch (acb
->ioh
->dxfer_direction
) {
701 case SG_DXFER_TO_DEV
:
702 acb
->task
->xfer_dir
= SCSI_XFER_WRITE
;
704 case SG_DXFER_FROM_DEV
:
705 acb
->task
->xfer_dir
= SCSI_XFER_READ
;
708 acb
->task
->xfer_dir
= SCSI_XFER_NONE
;
712 acb
->task
->cdb_size
= acb
->ioh
->cmd_len
;
713 memcpy(&acb
->task
->cdb
[0], acb
->ioh
->cmdp
, acb
->ioh
->cmd_len
);
714 acb
->task
->expxferlen
= acb
->ioh
->dxfer_len
;
717 if (acb
->task
->xfer_dir
== SCSI_XFER_WRITE
) {
718 if (acb
->ioh
->iovec_count
== 0) {
719 data
.data
= acb
->ioh
->dxferp
;
720 data
.size
= acb
->ioh
->dxfer_len
;
722 #if defined(LIBISCSI_FEATURE_IOVECTOR)
723 scsi_task_set_iov_out(acb
->task
,
724 (struct scsi_iovec
*) acb
->ioh
->dxferp
,
725 acb
->ioh
->iovec_count
);
727 struct iovec
*iov
= (struct iovec
*)acb
->ioh
->dxferp
;
729 acb
->buf
= g_malloc(acb
->ioh
->dxfer_len
);
730 data
.data
= acb
->buf
;
731 data
.size
= iov_to_buf(iov
, acb
->ioh
->iovec_count
, 0,
732 acb
->buf
, acb
->ioh
->dxfer_len
);
737 if (iscsi_scsi_command_async(iscsi
, iscsilun
->lun
, acb
->task
,
739 (data
.size
> 0) ? &data
: NULL
,
741 scsi_free_scsi_task(acb
->task
);
742 qemu_aio_release(acb
);
746 /* tell libiscsi to read straight into the buffer we got from ioctl */
747 if (acb
->task
->xfer_dir
== SCSI_XFER_READ
) {
748 if (acb
->ioh
->iovec_count
== 0) {
749 scsi_task_add_data_in_buffer(acb
->task
,
753 #if defined(LIBISCSI_FEATURE_IOVECTOR)
754 scsi_task_set_iov_in(acb
->task
,
755 (struct scsi_iovec
*) acb
->ioh
->dxferp
,
756 acb
->ioh
->iovec_count
);
759 for (i
= 0; i
< acb
->ioh
->iovec_count
; i
++) {
760 struct iovec
*iov
= (struct iovec
*)acb
->ioh
->dxferp
;
762 scsi_task_add_data_in_buffer(acb
->task
,
770 iscsi_set_events(iscsilun
);
776 static void ioctl_cb(void *opaque
, int status
)
778 int *p_status
= opaque
;
782 static int iscsi_ioctl(BlockDriverState
*bs
, unsigned long int req
, void *buf
)
784 IscsiLun
*iscsilun
= bs
->opaque
;
788 case SG_GET_VERSION_NUM
:
792 ((struct sg_scsi_id
*)buf
)->scsi_type
= iscsilun
->type
;
795 status
= -EINPROGRESS
;
796 iscsi_aio_ioctl(bs
, req
, buf
, ioctl_cb
, &status
);
798 while (status
== -EINPROGRESS
) {
799 aio_poll(iscsilun
->aio_context
, true);
811 iscsi_getlength(BlockDriverState
*bs
)
813 IscsiLun
*iscsilun
= bs
->opaque
;
816 len
= iscsilun
->num_blocks
;
817 len
*= iscsilun
->block_size
;
823 coroutine_fn
iscsi_co_discard(BlockDriverState
*bs
, int64_t sector_num
,
826 IscsiLun
*iscsilun
= bs
->opaque
;
827 struct IscsiTask iTask
;
828 struct unmap_list list
;
830 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
834 if (!iscsilun
->lbp
.lbpu
) {
835 /* UNMAP is not supported by the target */
839 list
.lba
= sector_qemu2lun(sector_num
, iscsilun
);
840 list
.num
= sector_qemu2lun(nb_sectors
, iscsilun
);
842 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
844 if (iscsi_unmap_task(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0, &list
, 1,
845 iscsi_co_generic_cb
, &iTask
) == NULL
) {
849 while (!iTask
.complete
) {
850 iscsi_set_events(iscsilun
);
851 qemu_coroutine_yield();
854 if (iTask
.task
!= NULL
) {
855 scsi_free_scsi_task(iTask
.task
);
859 if (iTask
.do_retry
) {
864 if (iTask
.status
== SCSI_STATUS_CHECK_CONDITION
) {
865 /* the target might fail with a check condition if it
866 is not happy with the alignment of the UNMAP request
867 we silently fail in this case */
871 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
875 iscsi_allocationmap_clear(iscsilun
, sector_num
, nb_sectors
);
880 #if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED)
883 coroutine_fn
iscsi_co_write_zeroes(BlockDriverState
*bs
, int64_t sector_num
,
884 int nb_sectors
, BdrvRequestFlags flags
)
886 IscsiLun
*iscsilun
= bs
->opaque
;
887 struct IscsiTask iTask
;
891 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
895 if ((flags
& BDRV_REQ_MAY_UNMAP
) && !iscsilun
->lbp
.lbpws
) {
896 /* WRITE SAME with UNMAP is not supported by the target,
897 * fall back and try WRITE SAME without UNMAP */
898 flags
&= ~BDRV_REQ_MAY_UNMAP
;
901 if (!(flags
& BDRV_REQ_MAY_UNMAP
) && !iscsilun
->has_write_same
) {
902 /* WRITE SAME without UNMAP is not supported by the target */
906 lba
= sector_qemu2lun(sector_num
, iscsilun
);
907 nb_blocks
= sector_qemu2lun(nb_sectors
, iscsilun
);
909 if (iscsilun
->zeroblock
== NULL
) {
910 iscsilun
->zeroblock
= g_malloc0(iscsilun
->block_size
);
913 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
915 if (iscsi_writesame16_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
916 iscsilun
->zeroblock
, iscsilun
->block_size
,
917 nb_blocks
, 0, !!(flags
& BDRV_REQ_MAY_UNMAP
),
918 0, 0, iscsi_co_generic_cb
, &iTask
) == NULL
) {
922 while (!iTask
.complete
) {
923 iscsi_set_events(iscsilun
);
924 qemu_coroutine_yield();
927 if (iTask
.status
== SCSI_STATUS_CHECK_CONDITION
&&
928 iTask
.task
->sense
.key
== SCSI_SENSE_ILLEGAL_REQUEST
&&
929 (iTask
.task
->sense
.ascq
== SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE
||
930 iTask
.task
->sense
.ascq
== SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB
)) {
931 /* WRITE SAME is not supported by the target */
932 iscsilun
->has_write_same
= false;
933 scsi_free_scsi_task(iTask
.task
);
937 if (iTask
.task
!= NULL
) {
938 scsi_free_scsi_task(iTask
.task
);
942 if (iTask
.do_retry
) {
947 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
951 if (flags
& BDRV_REQ_MAY_UNMAP
) {
952 iscsi_allocationmap_clear(iscsilun
, sector_num
, nb_sectors
);
954 iscsi_allocationmap_set(iscsilun
, sector_num
, nb_sectors
);
960 #endif /* SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED */
962 static void parse_chap(struct iscsi_context
*iscsi
, const char *target
,
967 const char *user
= NULL
;
968 const char *password
= NULL
;
970 list
= qemu_find_opts("iscsi");
975 opts
= qemu_opts_find(list
, target
);
977 opts
= QTAILQ_FIRST(&list
->head
);
983 user
= qemu_opt_get(opts
, "user");
988 password
= qemu_opt_get(opts
, "password");
990 error_setg(errp
, "CHAP username specified but no password was given");
994 if (iscsi_set_initiator_username_pwd(iscsi
, user
, password
)) {
995 error_setg(errp
, "Failed to set initiator username and password");
999 static void parse_header_digest(struct iscsi_context
*iscsi
, const char *target
,
1004 const char *digest
= NULL
;
1006 list
= qemu_find_opts("iscsi");
1011 opts
= qemu_opts_find(list
, target
);
1013 opts
= QTAILQ_FIRST(&list
->head
);
1019 digest
= qemu_opt_get(opts
, "header-digest");
1024 if (!strcmp(digest
, "CRC32C")) {
1025 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_CRC32C
);
1026 } else if (!strcmp(digest
, "NONE")) {
1027 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_NONE
);
1028 } else if (!strcmp(digest
, "CRC32C-NONE")) {
1029 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_CRC32C_NONE
);
1030 } else if (!strcmp(digest
, "NONE-CRC32C")) {
1031 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_NONE_CRC32C
);
1033 error_setg(errp
, "Invalid header-digest setting : %s", digest
);
1037 static char *parse_initiator_name(const char *target
)
1043 UuidInfo
*uuid_info
;
1045 list
= qemu_find_opts("iscsi");
1047 opts
= qemu_opts_find(list
, target
);
1049 opts
= QTAILQ_FIRST(&list
->head
);
1052 name
= qemu_opt_get(opts
, "initiator-name");
1054 return g_strdup(name
);
1059 uuid_info
= qmp_query_uuid(NULL
);
1060 if (strcmp(uuid_info
->UUID
, UUID_NONE
) == 0) {
1061 name
= qemu_get_vm_name();
1063 name
= uuid_info
->UUID
;
1065 iscsi_name
= g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
1066 name
? ":" : "", name
? name
: "");
1067 qapi_free_UuidInfo(uuid_info
);
1071 #if defined(LIBISCSI_FEATURE_NOP_COUNTER)
1072 static void iscsi_nop_timed_event(void *opaque
)
1074 IscsiLun
*iscsilun
= opaque
;
1076 if (iscsi_get_nops_in_flight(iscsilun
->iscsi
) > MAX_NOP_FAILURES
) {
1077 error_report("iSCSI: NOP timeout. Reconnecting...");
1078 iscsi_reconnect(iscsilun
->iscsi
);
1081 if (iscsi_nop_out_async(iscsilun
->iscsi
, NULL
, NULL
, 0, NULL
) != 0) {
1082 error_report("iSCSI: failed to sent NOP-Out. Disabling NOP messages.");
1086 timer_mod(iscsilun
->nop_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + NOP_INTERVAL
);
1087 iscsi_set_events(iscsilun
);
1091 static void iscsi_readcapacity_sync(IscsiLun
*iscsilun
, Error
**errp
)
1093 struct scsi_task
*task
= NULL
;
1094 struct scsi_readcapacity10
*rc10
= NULL
;
1095 struct scsi_readcapacity16
*rc16
= NULL
;
1096 int retries
= ISCSI_CMD_RETRIES
;
1100 scsi_free_scsi_task(task
);
1104 switch (iscsilun
->type
) {
1106 task
= iscsi_readcapacity16_sync(iscsilun
->iscsi
, iscsilun
->lun
);
1107 if (task
!= NULL
&& task
->status
== SCSI_STATUS_GOOD
) {
1108 rc16
= scsi_datain_unmarshall(task
);
1110 error_setg(errp
, "iSCSI: Failed to unmarshall readcapacity16 data.");
1112 iscsilun
->block_size
= rc16
->block_length
;
1113 iscsilun
->num_blocks
= rc16
->returned_lba
+ 1;
1114 iscsilun
->lbpme
= rc16
->lbpme
;
1115 iscsilun
->lbprz
= rc16
->lbprz
;
1120 task
= iscsi_readcapacity10_sync(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0);
1121 if (task
!= NULL
&& task
->status
== SCSI_STATUS_GOOD
) {
1122 rc10
= scsi_datain_unmarshall(task
);
1124 error_setg(errp
, "iSCSI: Failed to unmarshall readcapacity10 data.");
1126 iscsilun
->block_size
= rc10
->block_size
;
1127 if (rc10
->lba
== 0) {
1128 /* blank disk loaded */
1129 iscsilun
->num_blocks
= 0;
1131 iscsilun
->num_blocks
= rc10
->lba
+ 1;
1139 } while (task
!= NULL
&& task
->status
== SCSI_STATUS_CHECK_CONDITION
1140 && task
->sense
.key
== SCSI_SENSE_UNIT_ATTENTION
1143 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1144 error_setg(errp
, "iSCSI: failed to send readcapacity10 command.");
1147 scsi_free_scsi_task(task
);
1151 /* TODO Convert to fine grained options */
1152 static QemuOptsList runtime_opts
= {
1154 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
1158 .type
= QEMU_OPT_STRING
,
1159 .help
= "URL to the iscsi image",
1161 { /* end of list */ }
1165 static struct scsi_task
*iscsi_do_inquiry(struct iscsi_context
*iscsi
, int lun
,
1166 int evpd
, int pc
, void **inq
, Error
**errp
)
1169 struct scsi_task
*task
= NULL
;
1170 task
= iscsi_inquiry_sync(iscsi
, lun
, evpd
, pc
, 64);
1171 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1174 full_size
= scsi_datain_getfullsize(task
);
1175 if (full_size
> task
->datain
.size
) {
1176 scsi_free_scsi_task(task
);
1178 /* we need more data for the full list */
1179 task
= iscsi_inquiry_sync(iscsi
, lun
, evpd
, pc
, full_size
);
1180 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1185 *inq
= scsi_datain_unmarshall(task
);
1187 error_setg(errp
, "iSCSI: failed to unmarshall inquiry datain blob");
1194 error_setg(errp
, "iSCSI: Inquiry command failed : %s",
1195 iscsi_get_error(iscsi
));
1198 scsi_free_scsi_task(task
);
1203 static void iscsi_detach_aio_context(BlockDriverState
*bs
)
1205 IscsiLun
*iscsilun
= bs
->opaque
;
1207 aio_set_fd_handler(iscsilun
->aio_context
,
1208 iscsi_get_fd(iscsilun
->iscsi
),
1210 iscsilun
->events
= 0;
1212 if (iscsilun
->nop_timer
) {
1213 timer_del(iscsilun
->nop_timer
);
1214 timer_free(iscsilun
->nop_timer
);
1215 iscsilun
->nop_timer
= NULL
;
1219 static void iscsi_attach_aio_context(BlockDriverState
*bs
,
1220 AioContext
*new_context
)
1222 IscsiLun
*iscsilun
= bs
->opaque
;
1224 iscsilun
->aio_context
= new_context
;
1225 iscsi_set_events(iscsilun
);
1227 #if defined(LIBISCSI_FEATURE_NOP_COUNTER)
1228 /* Set up a timer for sending out iSCSI NOPs */
1229 iscsilun
->nop_timer
= aio_timer_new(iscsilun
->aio_context
,
1230 QEMU_CLOCK_REALTIME
, SCALE_MS
,
1231 iscsi_nop_timed_event
, iscsilun
);
1232 timer_mod(iscsilun
->nop_timer
,
1233 qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + NOP_INTERVAL
);
1238 * We support iscsi url's on the form
1239 * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
1241 * Note: flags are currently not used by iscsi_open. If this function
1242 * is changed such that flags are used, please examine iscsi_reopen_prepare()
1243 * to see if needs to be changed as well.
1245 static int iscsi_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
1248 IscsiLun
*iscsilun
= bs
->opaque
;
1249 struct iscsi_context
*iscsi
= NULL
;
1250 struct iscsi_url
*iscsi_url
= NULL
;
1251 struct scsi_task
*task
= NULL
;
1252 struct scsi_inquiry_standard
*inq
= NULL
;
1253 struct scsi_inquiry_supported_pages
*inq_vpd
;
1254 char *initiator_name
= NULL
;
1256 Error
*local_err
= NULL
;
1257 const char *filename
;
1260 if ((BDRV_SECTOR_SIZE
% 512) != 0) {
1261 error_setg(errp
, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
1262 "BDRV_SECTOR_SIZE(%lld) is not a multiple "
1263 "of 512", BDRV_SECTOR_SIZE
);
1267 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
1268 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
1270 error_propagate(errp
, local_err
);
1275 filename
= qemu_opt_get(opts
, "filename");
1277 iscsi_url
= iscsi_parse_full_url(iscsi
, filename
);
1278 if (iscsi_url
== NULL
) {
1279 error_setg(errp
, "Failed to parse URL : %s", filename
);
1284 memset(iscsilun
, 0, sizeof(IscsiLun
));
1286 initiator_name
= parse_initiator_name(iscsi_url
->target
);
1288 iscsi
= iscsi_create_context(initiator_name
);
1289 if (iscsi
== NULL
) {
1290 error_setg(errp
, "iSCSI: Failed to create iSCSI context.");
1295 if (iscsi_set_targetname(iscsi
, iscsi_url
->target
)) {
1296 error_setg(errp
, "iSCSI: Failed to set target name.");
1301 if (iscsi_url
->user
!= NULL
) {
1302 ret
= iscsi_set_initiator_username_pwd(iscsi
, iscsi_url
->user
,
1305 error_setg(errp
, "Failed to set initiator username and password");
1311 /* check if we got CHAP username/password via the options */
1312 parse_chap(iscsi
, iscsi_url
->target
, &local_err
);
1313 if (local_err
!= NULL
) {
1314 error_propagate(errp
, local_err
);
1319 if (iscsi_set_session_type(iscsi
, ISCSI_SESSION_NORMAL
) != 0) {
1320 error_setg(errp
, "iSCSI: Failed to set session type to normal.");
1325 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_NONE_CRC32C
);
1327 /* check if we got HEADER_DIGEST via the options */
1328 parse_header_digest(iscsi
, iscsi_url
->target
, &local_err
);
1329 if (local_err
!= NULL
) {
1330 error_propagate(errp
, local_err
);
1335 if (iscsi_full_connect_sync(iscsi
, iscsi_url
->portal
, iscsi_url
->lun
) != 0) {
1336 error_setg(errp
, "iSCSI: Failed to connect to LUN : %s",
1337 iscsi_get_error(iscsi
));
1342 iscsilun
->iscsi
= iscsi
;
1343 iscsilun
->aio_context
= bdrv_get_aio_context(bs
);
1344 iscsilun
->lun
= iscsi_url
->lun
;
1345 iscsilun
->has_write_same
= true;
1347 task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0,
1348 (void **) &inq
, errp
);
1353 iscsilun
->type
= inq
->periperal_device_type
;
1354 scsi_free_scsi_task(task
);
1357 iscsi_readcapacity_sync(iscsilun
, &local_err
);
1358 if (local_err
!= NULL
) {
1359 error_propagate(errp
, local_err
);
1363 bs
->total_sectors
= sector_lun2qemu(iscsilun
->num_blocks
, iscsilun
);
1364 bs
->request_alignment
= iscsilun
->block_size
;
1366 /* We don't have any emulation for devices other than disks and CD-ROMs, so
1367 * this must be sg ioctl compatible. We force it to be sg, otherwise qemu
1368 * will try to read from the device to guess the image format.
1370 if (iscsilun
->type
!= TYPE_DISK
&& iscsilun
->type
!= TYPE_ROM
) {
1374 task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 1,
1375 SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES
,
1376 (void **) &inq_vpd
, errp
);
1381 for (i
= 0; i
< inq_vpd
->num_pages
; i
++) {
1382 struct scsi_task
*inq_task
;
1383 struct scsi_inquiry_logical_block_provisioning
*inq_lbp
;
1384 struct scsi_inquiry_block_limits
*inq_bl
;
1385 switch (inq_vpd
->pages
[i
]) {
1386 case SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING
:
1387 inq_task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 1,
1388 SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING
,
1389 (void **) &inq_lbp
, errp
);
1390 if (inq_task
== NULL
) {
1394 memcpy(&iscsilun
->lbp
, inq_lbp
,
1395 sizeof(struct scsi_inquiry_logical_block_provisioning
));
1396 scsi_free_scsi_task(inq_task
);
1398 case SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS
:
1399 inq_task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 1,
1400 SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS
,
1401 (void **) &inq_bl
, errp
);
1402 if (inq_task
== NULL
) {
1406 memcpy(&iscsilun
->bl
, inq_bl
,
1407 sizeof(struct scsi_inquiry_block_limits
));
1408 scsi_free_scsi_task(inq_task
);
1414 scsi_free_scsi_task(task
);
1417 iscsi_attach_aio_context(bs
, iscsilun
->aio_context
);
1419 /* Guess the internal cluster (page) size of the iscsi target by the means
1420 * of opt_unmap_gran. Transfer the unmap granularity only if it has a
1421 * reasonable size */
1422 if (iscsilun
->bl
.opt_unmap_gran
* iscsilun
->block_size
>= 4 * 1024 &&
1423 iscsilun
->bl
.opt_unmap_gran
* iscsilun
->block_size
<= 16 * 1024 * 1024) {
1424 iscsilun
->cluster_sectors
= (iscsilun
->bl
.opt_unmap_gran
*
1425 iscsilun
->block_size
) >> BDRV_SECTOR_BITS
;
1426 #if defined(LIBISCSI_FEATURE_IOVECTOR)
1427 if (iscsilun
->lbprz
&& !(bs
->open_flags
& BDRV_O_NOCACHE
)) {
1428 iscsilun
->allocationmap
=
1429 bitmap_new(DIV_ROUND_UP(bs
->total_sectors
,
1430 iscsilun
->cluster_sectors
));
1436 qemu_opts_del(opts
);
1437 g_free(initiator_name
);
1438 if (iscsi_url
!= NULL
) {
1439 iscsi_destroy_url(iscsi_url
);
1442 scsi_free_scsi_task(task
);
1446 if (iscsi
!= NULL
) {
1447 iscsi_destroy_context(iscsi
);
1449 memset(iscsilun
, 0, sizeof(IscsiLun
));
1454 static void iscsi_close(BlockDriverState
*bs
)
1456 IscsiLun
*iscsilun
= bs
->opaque
;
1457 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
1459 iscsi_detach_aio_context(bs
);
1460 iscsi_destroy_context(iscsi
);
1461 g_free(iscsilun
->zeroblock
);
1462 g_free(iscsilun
->allocationmap
);
1463 memset(iscsilun
, 0, sizeof(IscsiLun
));
1466 static int iscsi_refresh_limits(BlockDriverState
*bs
)
1468 IscsiLun
*iscsilun
= bs
->opaque
;
1470 /* We don't actually refresh here, but just return data queried in
1471 * iscsi_open(): iscsi targets don't change their limits. */
1472 if (iscsilun
->lbp
.lbpu
) {
1473 if (iscsilun
->bl
.max_unmap
< 0xffffffff) {
1474 bs
->bl
.max_discard
= sector_lun2qemu(iscsilun
->bl
.max_unmap
,
1477 bs
->bl
.discard_alignment
= sector_lun2qemu(iscsilun
->bl
.opt_unmap_gran
,
1481 if (iscsilun
->bl
.max_ws_len
< 0xffffffff) {
1482 bs
->bl
.max_write_zeroes
= sector_lun2qemu(iscsilun
->bl
.max_ws_len
,
1485 if (iscsilun
->lbp
.lbpws
) {
1486 bs
->bl
.write_zeroes_alignment
= sector_lun2qemu(iscsilun
->bl
.opt_unmap_gran
,
1489 bs
->bl
.opt_transfer_length
= sector_lun2qemu(iscsilun
->bl
.opt_xfer_len
,
1494 /* Since iscsi_open() ignores bdrv_flags, there is nothing to do here in
1495 * prepare. Note that this will not re-establish a connection with an iSCSI
1496 * target - it is effectively a NOP. */
1497 static int iscsi_reopen_prepare(BDRVReopenState
*state
,
1498 BlockReopenQueue
*queue
, Error
**errp
)
1504 static int iscsi_truncate(BlockDriverState
*bs
, int64_t offset
)
1506 IscsiLun
*iscsilun
= bs
->opaque
;
1507 Error
*local_err
= NULL
;
1509 if (iscsilun
->type
!= TYPE_DISK
) {
1513 iscsi_readcapacity_sync(iscsilun
, &local_err
);
1514 if (local_err
!= NULL
) {
1515 error_free(local_err
);
1519 if (offset
> iscsi_getlength(bs
)) {
1523 if (iscsilun
->allocationmap
!= NULL
) {
1524 g_free(iscsilun
->allocationmap
);
1525 iscsilun
->allocationmap
=
1526 bitmap_new(DIV_ROUND_UP(bs
->total_sectors
,
1527 iscsilun
->cluster_sectors
));
1533 static int iscsi_create(const char *filename
, QemuOpts
*opts
, Error
**errp
)
1536 int64_t total_size
= 0;
1537 BlockDriverState
*bs
;
1538 IscsiLun
*iscsilun
= NULL
;
1541 bs
= bdrv_new("", &error_abort
);
1543 /* Read out options */
1545 qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0) / 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 iscsi_detach_aio_context(bs
);
1558 if (iscsilun
->type
!= TYPE_DISK
) {
1562 if (bs
->total_sectors
< total_size
) {
1569 if (iscsilun
->iscsi
!= NULL
) {
1570 iscsi_destroy_context(iscsilun
->iscsi
);
1578 static int iscsi_get_info(BlockDriverState
*bs
, BlockDriverInfo
*bdi
)
1580 IscsiLun
*iscsilun
= bs
->opaque
;
1581 bdi
->unallocated_blocks_are_zero
= !!iscsilun
->lbprz
;
1582 bdi
->can_write_zeroes_with_unmap
= iscsilun
->lbprz
&& iscsilun
->lbp
.lbpws
;
1583 bdi
->cluster_size
= iscsilun
->cluster_sectors
* BDRV_SECTOR_SIZE
;
1587 static QemuOptsList iscsi_create_opts
= {
1588 .name
= "iscsi-create-opts",
1589 .head
= QTAILQ_HEAD_INITIALIZER(iscsi_create_opts
.head
),
1592 .name
= BLOCK_OPT_SIZE
,
1593 .type
= QEMU_OPT_SIZE
,
1594 .help
= "Virtual disk size"
1596 { /* end of list */ }
1600 static BlockDriver bdrv_iscsi
= {
1601 .format_name
= "iscsi",
1602 .protocol_name
= "iscsi",
1604 .instance_size
= sizeof(IscsiLun
),
1605 .bdrv_needs_filename
= true,
1606 .bdrv_file_open
= iscsi_open
,
1607 .bdrv_close
= iscsi_close
,
1608 .bdrv_create
= iscsi_create
,
1609 .create_opts
= &iscsi_create_opts
,
1610 .bdrv_reopen_prepare
= iscsi_reopen_prepare
,
1612 .bdrv_getlength
= iscsi_getlength
,
1613 .bdrv_get_info
= iscsi_get_info
,
1614 .bdrv_truncate
= iscsi_truncate
,
1615 .bdrv_refresh_limits
= iscsi_refresh_limits
,
1617 #if defined(LIBISCSI_FEATURE_IOVECTOR)
1618 .bdrv_co_get_block_status
= iscsi_co_get_block_status
,
1620 .bdrv_co_discard
= iscsi_co_discard
,
1621 #if defined(SCSI_SENSE_ASCQ_CAPACITY_DATA_HAS_CHANGED)
1622 .bdrv_co_write_zeroes
= iscsi_co_write_zeroes
,
1624 .bdrv_co_readv
= iscsi_co_readv
,
1625 .bdrv_co_writev
= iscsi_co_writev
,
1626 .bdrv_co_flush_to_disk
= iscsi_co_flush
,
1629 .bdrv_ioctl
= iscsi_ioctl
,
1630 .bdrv_aio_ioctl
= iscsi_aio_ioctl
,
1633 .bdrv_detach_aio_context
= iscsi_detach_aio_context
,
1634 .bdrv_attach_aio_context
= iscsi_attach_aio_context
,
1637 static QemuOptsList qemu_iscsi_opts
= {
1639 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
1643 .type
= QEMU_OPT_STRING
,
1644 .help
= "username for CHAP authentication to target",
1647 .type
= QEMU_OPT_STRING
,
1648 .help
= "password for CHAP authentication to target",
1650 .name
= "header-digest",
1651 .type
= QEMU_OPT_STRING
,
1652 .help
= "HeaderDigest setting. "
1653 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
1655 .name
= "initiator-name",
1656 .type
= QEMU_OPT_STRING
,
1657 .help
= "Initiator iqn name to use when connecting",
1659 { /* end of list */ }
1663 static void iscsi_block_init(void)
1665 bdrv_register(&bdrv_iscsi
);
1666 qemu_add_opts(&qemu_iscsi_opts
);
1669 block_init(iscsi_block_init
);