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"
30 #include <arpa/inet.h>
31 #include "qemu-common.h"
32 #include "qemu/config-file.h"
33 #include "qemu/error-report.h"
34 #include "qemu/bitops.h"
35 #include "qemu/bitmap.h"
36 #include "block/block_int.h"
38 #include "block/scsi.h"
40 #include "sysemu/sysemu.h"
41 #include "qmp-commands.h"
43 #include <iscsi/iscsi.h>
44 #include <iscsi/scsi-lowlevel.h>
48 #include <block/scsi.h>
51 typedef struct IscsiLun
{
52 struct iscsi_context
*iscsi
;
53 AioContext
*aio_context
;
55 enum scsi_inquiry_peripheral_device_type type
;
62 uint8_t has_write_same
;
63 struct scsi_inquiry_logical_block_provisioning lbp
;
64 struct scsi_inquiry_block_limits bl
;
65 unsigned char *zeroblock
;
66 unsigned long *allocationmap
;
71 typedef struct IscsiTask
{
76 struct scsi_task
*task
;
80 QEMUTimer retry_timer
;
83 typedef struct IscsiAIOCB
{
84 BlockDriverAIOCB common
;
88 struct scsi_task
*task
;
99 #define NOP_INTERVAL 5000
100 #define MAX_NOP_FAILURES 3
101 #define ISCSI_CMD_RETRIES ARRAY_SIZE(iscsi_retry_times)
102 static const unsigned iscsi_retry_times
[] = {8, 32, 128, 512, 2048};
104 /* this threshhold is a trade-off knob to choose between
105 * the potential additional overhead of an extra GET_LBA_STATUS request
106 * vs. unnecessarily reading a lot of zero sectors over the wire.
107 * If a read request is greater or equal than ISCSI_CHECKALLOC_THRES
108 * sectors we check the allocation status of the area covered by the
109 * request first if the allocationmap indicates that the area might be
111 #define ISCSI_CHECKALLOC_THRES 64
118 qemu_bh_delete(acb
->bh
);
123 if (acb
->canceled
== 0) {
124 acb
->common
.cb(acb
->common
.opaque
, acb
->status
);
127 if (acb
->task
!= NULL
) {
128 scsi_free_scsi_task(acb
->task
);
132 qemu_aio_release(acb
);
136 iscsi_schedule_bh(IscsiAIOCB
*acb
)
141 acb
->bh
= aio_bh_new(acb
->iscsilun
->aio_context
, iscsi_bh_cb
, acb
);
142 qemu_bh_schedule(acb
->bh
);
145 static void iscsi_co_generic_bh_cb(void *opaque
)
147 struct IscsiTask
*iTask
= opaque
;
149 qemu_bh_delete(iTask
->bh
);
150 qemu_coroutine_enter(iTask
->co
, NULL
);
153 static void iscsi_retry_timer_expired(void *opaque
)
155 struct IscsiTask
*iTask
= opaque
;
158 qemu_coroutine_enter(iTask
->co
, NULL
);
162 static inline unsigned exp_random(double mean
)
164 return -mean
* log((double)rand() / RAND_MAX
);
168 iscsi_co_generic_cb(struct iscsi_context
*iscsi
, int status
,
169 void *command_data
, void *opaque
)
171 struct IscsiTask
*iTask
= opaque
;
172 struct scsi_task
*task
= command_data
;
174 iTask
->status
= status
;
178 if (status
!= SCSI_STATUS_GOOD
) {
179 if (iTask
->retries
++ < ISCSI_CMD_RETRIES
) {
180 if (status
== SCSI_STATUS_CHECK_CONDITION
181 && task
->sense
.key
== SCSI_SENSE_UNIT_ATTENTION
) {
182 error_report("iSCSI CheckCondition: %s",
183 iscsi_get_error(iscsi
));
187 if (status
== SCSI_STATUS_BUSY
) {
188 unsigned retry_time
=
189 exp_random(iscsi_retry_times
[iTask
->retries
- 1]);
190 error_report("iSCSI Busy (retry #%u in %u ms): %s",
191 iTask
->retries
, retry_time
,
192 iscsi_get_error(iscsi
));
193 aio_timer_init(iTask
->iscsilun
->aio_context
,
194 &iTask
->retry_timer
, QEMU_CLOCK_REALTIME
,
195 SCALE_MS
, iscsi_retry_timer_expired
, iTask
);
196 timer_mod(&iTask
->retry_timer
,
197 qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + retry_time
);
202 error_report("iSCSI Failure: %s", iscsi_get_error(iscsi
));
207 iTask
->bh
= aio_bh_new(iTask
->iscsilun
->aio_context
,
208 iscsi_co_generic_bh_cb
, iTask
);
209 qemu_bh_schedule(iTask
->bh
);
215 static void iscsi_co_init_iscsitask(IscsiLun
*iscsilun
, struct IscsiTask
*iTask
)
217 *iTask
= (struct IscsiTask
) {
218 .co
= qemu_coroutine_self(),
219 .retries
= ISCSI_CMD_RETRIES
,
220 .iscsilun
= iscsilun
,
225 iscsi_abort_task_cb(struct iscsi_context
*iscsi
, int status
, void *command_data
,
228 IscsiAIOCB
*acb
= private_data
;
230 acb
->status
= -ECANCELED
;
231 iscsi_schedule_bh(acb
);
235 iscsi_aio_cancel(BlockDriverAIOCB
*blockacb
)
237 IscsiAIOCB
*acb
= (IscsiAIOCB
*)blockacb
;
238 IscsiLun
*iscsilun
= acb
->iscsilun
;
240 if (acb
->status
!= -EINPROGRESS
) {
246 /* send a task mgmt call to the target to cancel the task on the target */
247 iscsi_task_mgmt_abort_task_async(iscsilun
->iscsi
, acb
->task
,
248 iscsi_abort_task_cb
, acb
);
250 while (acb
->status
== -EINPROGRESS
) {
251 aio_poll(iscsilun
->aio_context
, true);
255 static const AIOCBInfo iscsi_aiocb_info
= {
256 .aiocb_size
= sizeof(IscsiAIOCB
),
257 .cancel
= iscsi_aio_cancel
,
261 static void iscsi_process_read(void *arg
);
262 static void iscsi_process_write(void *arg
);
265 iscsi_set_events(IscsiLun
*iscsilun
)
267 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
270 /* We always register a read handler. */
272 ev
|= iscsi_which_events(iscsi
);
273 if (ev
!= iscsilun
->events
) {
274 aio_set_fd_handler(iscsilun
->aio_context
,
277 (ev
& POLLOUT
) ? iscsi_process_write
: NULL
,
282 iscsilun
->events
= ev
;
286 iscsi_process_read(void *arg
)
288 IscsiLun
*iscsilun
= arg
;
289 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
291 iscsi_service(iscsi
, POLLIN
);
292 iscsi_set_events(iscsilun
);
296 iscsi_process_write(void *arg
)
298 IscsiLun
*iscsilun
= arg
;
299 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
301 iscsi_service(iscsi
, POLLOUT
);
302 iscsi_set_events(iscsilun
);
305 static int64_t sector_lun2qemu(int64_t sector
, IscsiLun
*iscsilun
)
307 return sector
* iscsilun
->block_size
/ BDRV_SECTOR_SIZE
;
310 static int64_t sector_qemu2lun(int64_t sector
, IscsiLun
*iscsilun
)
312 return sector
* BDRV_SECTOR_SIZE
/ iscsilun
->block_size
;
315 static bool is_request_lun_aligned(int64_t sector_num
, int nb_sectors
,
318 if ((sector_num
* BDRV_SECTOR_SIZE
) % iscsilun
->block_size
||
319 (nb_sectors
* BDRV_SECTOR_SIZE
) % iscsilun
->block_size
) {
320 error_report("iSCSI misaligned request: "
321 "iscsilun->block_size %u, sector_num %" PRIi64
323 iscsilun
->block_size
, sector_num
, nb_sectors
);
329 static void iscsi_allocationmap_set(IscsiLun
*iscsilun
, int64_t sector_num
,
332 if (iscsilun
->allocationmap
== NULL
) {
335 bitmap_set(iscsilun
->allocationmap
,
336 sector_num
/ iscsilun
->cluster_sectors
,
337 DIV_ROUND_UP(nb_sectors
, iscsilun
->cluster_sectors
));
340 static void iscsi_allocationmap_clear(IscsiLun
*iscsilun
, int64_t sector_num
,
343 int64_t cluster_num
, nb_clusters
;
344 if (iscsilun
->allocationmap
== NULL
) {
347 cluster_num
= DIV_ROUND_UP(sector_num
, iscsilun
->cluster_sectors
);
348 nb_clusters
= (sector_num
+ nb_sectors
) / iscsilun
->cluster_sectors
350 if (nb_clusters
> 0) {
351 bitmap_clear(iscsilun
->allocationmap
, cluster_num
, nb_clusters
);
355 static int coroutine_fn
iscsi_co_writev(BlockDriverState
*bs
,
356 int64_t sector_num
, int nb_sectors
,
359 IscsiLun
*iscsilun
= bs
->opaque
;
360 struct IscsiTask iTask
;
362 uint32_t num_sectors
;
363 uint8_t *data
= NULL
;
366 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
370 lba
= sector_qemu2lun(sector_num
, iscsilun
);
371 num_sectors
= sector_qemu2lun(nb_sectors
, iscsilun
);
372 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
374 if (iscsilun
->use_16_for_rw
) {
375 iTask
.task
= iscsi_write16_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
376 data
, num_sectors
* iscsilun
->block_size
,
377 iscsilun
->block_size
, 0, 0, 0, 0, 0,
378 iscsi_co_generic_cb
, &iTask
);
380 iTask
.task
= iscsi_write10_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
381 data
, num_sectors
* iscsilun
->block_size
,
382 iscsilun
->block_size
, 0, 0, 0, 0, 0,
383 iscsi_co_generic_cb
, &iTask
);
385 if (iTask
.task
== NULL
) {
389 scsi_task_set_iov_out(iTask
.task
, (struct scsi_iovec
*) iov
->iov
,
391 while (!iTask
.complete
) {
392 iscsi_set_events(iscsilun
);
393 qemu_coroutine_yield();
396 if (iTask
.task
!= NULL
) {
397 scsi_free_scsi_task(iTask
.task
);
401 if (iTask
.do_retry
) {
408 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
412 iscsi_allocationmap_set(iscsilun
, sector_num
, nb_sectors
);
418 static bool iscsi_allocationmap_is_allocated(IscsiLun
*iscsilun
,
419 int64_t sector_num
, int nb_sectors
)
422 if (iscsilun
->allocationmap
== NULL
) {
425 size
= DIV_ROUND_UP(sector_num
+ nb_sectors
, iscsilun
->cluster_sectors
);
426 return !(find_next_bit(iscsilun
->allocationmap
, size
,
427 sector_num
/ iscsilun
->cluster_sectors
) == size
);
430 static int64_t coroutine_fn
iscsi_co_get_block_status(BlockDriverState
*bs
,
432 int nb_sectors
, int *pnum
)
434 IscsiLun
*iscsilun
= bs
->opaque
;
435 struct scsi_get_lba_status
*lbas
= NULL
;
436 struct scsi_lba_status_descriptor
*lbasd
= NULL
;
437 struct IscsiTask iTask
;
440 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
442 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
447 /* default to all sectors allocated */
448 ret
= BDRV_BLOCK_DATA
;
449 ret
|= (sector_num
<< BDRV_SECTOR_BITS
) | BDRV_BLOCK_OFFSET_VALID
;
452 /* LUN does not support logical block provisioning */
453 if (iscsilun
->lbpme
== 0) {
458 if (iscsi_get_lba_status_task(iscsilun
->iscsi
, iscsilun
->lun
,
459 sector_qemu2lun(sector_num
, iscsilun
),
460 8 + 16, iscsi_co_generic_cb
,
466 while (!iTask
.complete
) {
467 iscsi_set_events(iscsilun
);
468 qemu_coroutine_yield();
471 if (iTask
.do_retry
) {
472 if (iTask
.task
!= NULL
) {
473 scsi_free_scsi_task(iTask
.task
);
480 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
481 /* in case the get_lba_status_callout fails (i.e.
482 * because the device is busy or the cmd is not
483 * supported) we pretend all blocks are allocated
484 * for backwards compatibility */
488 lbas
= scsi_datain_unmarshall(iTask
.task
);
494 lbasd
= &lbas
->descriptors
[0];
496 if (sector_qemu2lun(sector_num
, iscsilun
) != lbasd
->lba
) {
501 *pnum
= sector_lun2qemu(lbasd
->num_blocks
, iscsilun
);
503 if (lbasd
->provisioning
== SCSI_PROVISIONING_TYPE_DEALLOCATED
||
504 lbasd
->provisioning
== SCSI_PROVISIONING_TYPE_ANCHORED
) {
505 ret
&= ~BDRV_BLOCK_DATA
;
506 if (iscsilun
->lbprz
) {
507 ret
|= BDRV_BLOCK_ZERO
;
511 if (ret
& BDRV_BLOCK_ZERO
) {
512 iscsi_allocationmap_clear(iscsilun
, sector_num
, *pnum
);
514 iscsi_allocationmap_set(iscsilun
, sector_num
, *pnum
);
517 if (*pnum
> nb_sectors
) {
521 if (iTask
.task
!= NULL
) {
522 scsi_free_scsi_task(iTask
.task
);
527 static int coroutine_fn
iscsi_co_readv(BlockDriverState
*bs
,
528 int64_t sector_num
, int nb_sectors
,
531 IscsiLun
*iscsilun
= bs
->opaque
;
532 struct IscsiTask iTask
;
534 uint32_t num_sectors
;
536 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
540 if (iscsilun
->lbprz
&& nb_sectors
>= ISCSI_CHECKALLOC_THRES
&&
541 !iscsi_allocationmap_is_allocated(iscsilun
, sector_num
, nb_sectors
)) {
544 ret
= iscsi_co_get_block_status(bs
, sector_num
, INT_MAX
, &pnum
);
548 if (ret
& BDRV_BLOCK_ZERO
&& pnum
>= nb_sectors
) {
549 qemu_iovec_memset(iov
, 0, 0x00, iov
->size
);
554 lba
= sector_qemu2lun(sector_num
, iscsilun
);
555 num_sectors
= sector_qemu2lun(nb_sectors
, iscsilun
);
557 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
559 if (iscsilun
->use_16_for_rw
) {
560 iTask
.task
= iscsi_read16_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
561 num_sectors
* iscsilun
->block_size
,
562 iscsilun
->block_size
, 0, 0, 0, 0, 0,
563 iscsi_co_generic_cb
, &iTask
);
565 iTask
.task
= iscsi_read10_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
566 num_sectors
* iscsilun
->block_size
,
567 iscsilun
->block_size
,
569 iscsi_co_generic_cb
, &iTask
);
571 if (iTask
.task
== NULL
) {
574 scsi_task_set_iov_in(iTask
.task
, (struct scsi_iovec
*) iov
->iov
, iov
->niov
);
576 while (!iTask
.complete
) {
577 iscsi_set_events(iscsilun
);
578 qemu_coroutine_yield();
581 if (iTask
.task
!= NULL
) {
582 scsi_free_scsi_task(iTask
.task
);
586 if (iTask
.do_retry
) {
591 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
598 static int coroutine_fn
iscsi_co_flush(BlockDriverState
*bs
)
600 IscsiLun
*iscsilun
= bs
->opaque
;
601 struct IscsiTask iTask
;
607 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
610 if (iscsi_synchronizecache10_task(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0, 0,
611 0, iscsi_co_generic_cb
, &iTask
) == NULL
) {
615 while (!iTask
.complete
) {
616 iscsi_set_events(iscsilun
);
617 qemu_coroutine_yield();
620 if (iTask
.task
!= NULL
) {
621 scsi_free_scsi_task(iTask
.task
);
625 if (iTask
.do_retry
) {
630 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
639 iscsi_aio_ioctl_cb(struct iscsi_context
*iscsi
, int status
,
640 void *command_data
, void *opaque
)
642 IscsiAIOCB
*acb
= opaque
;
647 if (acb
->canceled
!= 0) {
653 error_report("Failed to ioctl(SG_IO) to iSCSI lun. %s",
654 iscsi_get_error(iscsi
));
658 acb
->ioh
->driver_status
= 0;
659 acb
->ioh
->host_status
= 0;
662 #define SG_ERR_DRIVER_SENSE 0x08
664 if (status
== SCSI_STATUS_CHECK_CONDITION
&& acb
->task
->datain
.size
>= 2) {
667 acb
->ioh
->driver_status
|= SG_ERR_DRIVER_SENSE
;
669 acb
->ioh
->sb_len_wr
= acb
->task
->datain
.size
- 2;
670 ss
= (acb
->ioh
->mx_sb_len
>= acb
->ioh
->sb_len_wr
) ?
671 acb
->ioh
->mx_sb_len
: acb
->ioh
->sb_len_wr
;
672 memcpy(acb
->ioh
->sbp
, &acb
->task
->datain
.data
[2], ss
);
675 iscsi_schedule_bh(acb
);
678 static BlockDriverAIOCB
*iscsi_aio_ioctl(BlockDriverState
*bs
,
679 unsigned long int req
, void *buf
,
680 BlockDriverCompletionFunc
*cb
, void *opaque
)
682 IscsiLun
*iscsilun
= bs
->opaque
;
683 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
684 struct iscsi_data data
;
687 assert(req
== SG_IO
);
689 acb
= qemu_aio_get(&iscsi_aiocb_info
, bs
, cb
, opaque
);
691 acb
->iscsilun
= iscsilun
;
694 acb
->status
= -EINPROGRESS
;
698 acb
->task
= malloc(sizeof(struct scsi_task
));
699 if (acb
->task
== NULL
) {
700 error_report("iSCSI: Failed to allocate task for scsi command. %s",
701 iscsi_get_error(iscsi
));
702 qemu_aio_release(acb
);
705 memset(acb
->task
, 0, sizeof(struct scsi_task
));
707 switch (acb
->ioh
->dxfer_direction
) {
708 case SG_DXFER_TO_DEV
:
709 acb
->task
->xfer_dir
= SCSI_XFER_WRITE
;
711 case SG_DXFER_FROM_DEV
:
712 acb
->task
->xfer_dir
= SCSI_XFER_READ
;
715 acb
->task
->xfer_dir
= SCSI_XFER_NONE
;
719 acb
->task
->cdb_size
= acb
->ioh
->cmd_len
;
720 memcpy(&acb
->task
->cdb
[0], acb
->ioh
->cmdp
, acb
->ioh
->cmd_len
);
721 acb
->task
->expxferlen
= acb
->ioh
->dxfer_len
;
724 if (acb
->task
->xfer_dir
== SCSI_XFER_WRITE
) {
725 if (acb
->ioh
->iovec_count
== 0) {
726 data
.data
= acb
->ioh
->dxferp
;
727 data
.size
= acb
->ioh
->dxfer_len
;
729 scsi_task_set_iov_out(acb
->task
,
730 (struct scsi_iovec
*) acb
->ioh
->dxferp
,
731 acb
->ioh
->iovec_count
);
735 if (iscsi_scsi_command_async(iscsi
, iscsilun
->lun
, acb
->task
,
737 (data
.size
> 0) ? &data
: NULL
,
739 scsi_free_scsi_task(acb
->task
);
740 qemu_aio_release(acb
);
744 /* tell libiscsi to read straight into the buffer we got from ioctl */
745 if (acb
->task
->xfer_dir
== SCSI_XFER_READ
) {
746 if (acb
->ioh
->iovec_count
== 0) {
747 scsi_task_add_data_in_buffer(acb
->task
,
751 scsi_task_set_iov_in(acb
->task
,
752 (struct scsi_iovec
*) acb
->ioh
->dxferp
,
753 acb
->ioh
->iovec_count
);
757 iscsi_set_events(iscsilun
);
762 static void ioctl_cb(void *opaque
, int status
)
764 int *p_status
= opaque
;
768 static int iscsi_ioctl(BlockDriverState
*bs
, unsigned long int req
, void *buf
)
770 IscsiLun
*iscsilun
= bs
->opaque
;
774 case SG_GET_VERSION_NUM
:
778 ((struct sg_scsi_id
*)buf
)->scsi_type
= iscsilun
->type
;
781 status
= -EINPROGRESS
;
782 iscsi_aio_ioctl(bs
, req
, buf
, ioctl_cb
, &status
);
784 while (status
== -EINPROGRESS
) {
785 aio_poll(iscsilun
->aio_context
, true);
797 iscsi_getlength(BlockDriverState
*bs
)
799 IscsiLun
*iscsilun
= bs
->opaque
;
802 len
= iscsilun
->num_blocks
;
803 len
*= iscsilun
->block_size
;
809 coroutine_fn
iscsi_co_discard(BlockDriverState
*bs
, int64_t sector_num
,
812 IscsiLun
*iscsilun
= bs
->opaque
;
813 struct IscsiTask iTask
;
814 struct unmap_list list
;
816 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
820 if (!iscsilun
->lbp
.lbpu
) {
821 /* UNMAP is not supported by the target */
825 list
.lba
= sector_qemu2lun(sector_num
, iscsilun
);
826 list
.num
= sector_qemu2lun(nb_sectors
, iscsilun
);
828 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
830 if (iscsi_unmap_task(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0, &list
, 1,
831 iscsi_co_generic_cb
, &iTask
) == NULL
) {
835 while (!iTask
.complete
) {
836 iscsi_set_events(iscsilun
);
837 qemu_coroutine_yield();
840 if (iTask
.task
!= NULL
) {
841 scsi_free_scsi_task(iTask
.task
);
845 if (iTask
.do_retry
) {
850 if (iTask
.status
== SCSI_STATUS_CHECK_CONDITION
) {
851 /* the target might fail with a check condition if it
852 is not happy with the alignment of the UNMAP request
853 we silently fail in this case */
857 if (iTask
.status
!= SCSI_STATUS_GOOD
) {
861 iscsi_allocationmap_clear(iscsilun
, sector_num
, nb_sectors
);
867 coroutine_fn
iscsi_co_write_zeroes(BlockDriverState
*bs
, int64_t sector_num
,
868 int nb_sectors
, BdrvRequestFlags flags
)
870 IscsiLun
*iscsilun
= bs
->opaque
;
871 struct IscsiTask iTask
;
874 bool use_16_for_ws
= iscsilun
->use_16_for_rw
;
876 if (!is_request_lun_aligned(sector_num
, nb_sectors
, iscsilun
)) {
880 if (flags
& BDRV_REQ_MAY_UNMAP
) {
881 if (!use_16_for_ws
&& !iscsilun
->lbp
.lbpws10
) {
882 /* WRITESAME10 with UNMAP is unsupported try WRITESAME16 */
883 use_16_for_ws
= true;
885 if (use_16_for_ws
&& !iscsilun
->lbp
.lbpws
) {
886 /* WRITESAME16 with UNMAP is not supported by the target,
887 * fall back and try WRITESAME10/16 without UNMAP */
888 flags
&= ~BDRV_REQ_MAY_UNMAP
;
889 use_16_for_ws
= iscsilun
->use_16_for_rw
;
893 if (!(flags
& BDRV_REQ_MAY_UNMAP
) && !iscsilun
->has_write_same
) {
894 /* WRITESAME without UNMAP is not supported by the target */
898 lba
= sector_qemu2lun(sector_num
, iscsilun
);
899 nb_blocks
= sector_qemu2lun(nb_sectors
, iscsilun
);
901 if (iscsilun
->zeroblock
== NULL
) {
902 iscsilun
->zeroblock
= g_malloc0(iscsilun
->block_size
);
905 iscsi_co_init_iscsitask(iscsilun
, &iTask
);
908 iTask
.task
= iscsi_writesame16_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
909 iscsilun
->zeroblock
, iscsilun
->block_size
,
910 nb_blocks
, 0, !!(flags
& BDRV_REQ_MAY_UNMAP
),
911 0, 0, iscsi_co_generic_cb
, &iTask
);
913 iTask
.task
= iscsi_writesame10_task(iscsilun
->iscsi
, iscsilun
->lun
, lba
,
914 iscsilun
->zeroblock
, iscsilun
->block_size
,
915 nb_blocks
, 0, !!(flags
& BDRV_REQ_MAY_UNMAP
),
916 0, 0, iscsi_co_generic_cb
, &iTask
);
918 if (iTask
.task
== 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 static void parse_chap(struct iscsi_context
*iscsi
, const char *target
,
965 const char *user
= NULL
;
966 const char *password
= NULL
;
968 list
= qemu_find_opts("iscsi");
973 opts
= qemu_opts_find(list
, target
);
975 opts
= QTAILQ_FIRST(&list
->head
);
981 user
= qemu_opt_get(opts
, "user");
986 password
= qemu_opt_get(opts
, "password");
988 error_setg(errp
, "CHAP username specified but no password was given");
992 if (iscsi_set_initiator_username_pwd(iscsi
, user
, password
)) {
993 error_setg(errp
, "Failed to set initiator username and password");
997 static void parse_header_digest(struct iscsi_context
*iscsi
, const char *target
,
1002 const char *digest
= NULL
;
1004 list
= qemu_find_opts("iscsi");
1009 opts
= qemu_opts_find(list
, target
);
1011 opts
= QTAILQ_FIRST(&list
->head
);
1017 digest
= qemu_opt_get(opts
, "header-digest");
1022 if (!strcmp(digest
, "CRC32C")) {
1023 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_CRC32C
);
1024 } else if (!strcmp(digest
, "NONE")) {
1025 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_NONE
);
1026 } else if (!strcmp(digest
, "CRC32C-NONE")) {
1027 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_CRC32C_NONE
);
1028 } else if (!strcmp(digest
, "NONE-CRC32C")) {
1029 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_NONE_CRC32C
);
1031 error_setg(errp
, "Invalid header-digest setting : %s", digest
);
1035 static char *parse_initiator_name(const char *target
)
1041 UuidInfo
*uuid_info
;
1043 list
= qemu_find_opts("iscsi");
1045 opts
= qemu_opts_find(list
, target
);
1047 opts
= QTAILQ_FIRST(&list
->head
);
1050 name
= qemu_opt_get(opts
, "initiator-name");
1052 return g_strdup(name
);
1057 uuid_info
= qmp_query_uuid(NULL
);
1058 if (strcmp(uuid_info
->UUID
, UUID_NONE
) == 0) {
1059 name
= qemu_get_vm_name();
1061 name
= uuid_info
->UUID
;
1063 iscsi_name
= g_strdup_printf("iqn.2008-11.org.linux-kvm%s%s",
1064 name
? ":" : "", name
? name
: "");
1065 qapi_free_UuidInfo(uuid_info
);
1069 static void iscsi_nop_timed_event(void *opaque
)
1071 IscsiLun
*iscsilun
= opaque
;
1073 if (iscsi_get_nops_in_flight(iscsilun
->iscsi
) > MAX_NOP_FAILURES
) {
1074 error_report("iSCSI: NOP timeout. Reconnecting...");
1075 iscsi_reconnect(iscsilun
->iscsi
);
1078 if (iscsi_nop_out_async(iscsilun
->iscsi
, NULL
, NULL
, 0, NULL
) != 0) {
1079 error_report("iSCSI: failed to sent NOP-Out. Disabling NOP messages.");
1083 timer_mod(iscsilun
->nop_timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + NOP_INTERVAL
);
1084 iscsi_set_events(iscsilun
);
1087 static void iscsi_readcapacity_sync(IscsiLun
*iscsilun
, Error
**errp
)
1089 struct scsi_task
*task
= NULL
;
1090 struct scsi_readcapacity10
*rc10
= NULL
;
1091 struct scsi_readcapacity16
*rc16
= NULL
;
1092 int retries
= ISCSI_CMD_RETRIES
;
1096 scsi_free_scsi_task(task
);
1100 switch (iscsilun
->type
) {
1102 task
= iscsi_readcapacity16_sync(iscsilun
->iscsi
, iscsilun
->lun
);
1103 if (task
!= NULL
&& task
->status
== SCSI_STATUS_GOOD
) {
1104 rc16
= scsi_datain_unmarshall(task
);
1106 error_setg(errp
, "iSCSI: Failed to unmarshall readcapacity16 data.");
1108 iscsilun
->block_size
= rc16
->block_length
;
1109 iscsilun
->num_blocks
= rc16
->returned_lba
+ 1;
1110 iscsilun
->lbpme
= rc16
->lbpme
;
1111 iscsilun
->lbprz
= rc16
->lbprz
;
1112 iscsilun
->use_16_for_rw
= (rc16
->returned_lba
> 0xffffffff);
1117 task
= iscsi_readcapacity10_sync(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0);
1118 if (task
!= NULL
&& task
->status
== SCSI_STATUS_GOOD
) {
1119 rc10
= scsi_datain_unmarshall(task
);
1121 error_setg(errp
, "iSCSI: Failed to unmarshall readcapacity10 data.");
1123 iscsilun
->block_size
= rc10
->block_size
;
1124 if (rc10
->lba
== 0) {
1125 /* blank disk loaded */
1126 iscsilun
->num_blocks
= 0;
1128 iscsilun
->num_blocks
= rc10
->lba
+ 1;
1136 } while (task
!= NULL
&& task
->status
== SCSI_STATUS_CHECK_CONDITION
1137 && task
->sense
.key
== SCSI_SENSE_UNIT_ATTENTION
1140 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1141 error_setg(errp
, "iSCSI: failed to send readcapacity10 command.");
1144 scsi_free_scsi_task(task
);
1148 /* TODO Convert to fine grained options */
1149 static QemuOptsList runtime_opts
= {
1151 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
1155 .type
= QEMU_OPT_STRING
,
1156 .help
= "URL to the iscsi image",
1158 { /* end of list */ }
1162 static struct scsi_task
*iscsi_do_inquiry(struct iscsi_context
*iscsi
, int lun
,
1163 int evpd
, int pc
, void **inq
, Error
**errp
)
1166 struct scsi_task
*task
= NULL
;
1167 task
= iscsi_inquiry_sync(iscsi
, lun
, evpd
, pc
, 64);
1168 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1171 full_size
= scsi_datain_getfullsize(task
);
1172 if (full_size
> task
->datain
.size
) {
1173 scsi_free_scsi_task(task
);
1175 /* we need more data for the full list */
1176 task
= iscsi_inquiry_sync(iscsi
, lun
, evpd
, pc
, full_size
);
1177 if (task
== NULL
|| task
->status
!= SCSI_STATUS_GOOD
) {
1182 *inq
= scsi_datain_unmarshall(task
);
1184 error_setg(errp
, "iSCSI: failed to unmarshall inquiry datain blob");
1191 error_setg(errp
, "iSCSI: Inquiry command failed : %s",
1192 iscsi_get_error(iscsi
));
1195 scsi_free_scsi_task(task
);
1200 static void iscsi_detach_aio_context(BlockDriverState
*bs
)
1202 IscsiLun
*iscsilun
= bs
->opaque
;
1204 aio_set_fd_handler(iscsilun
->aio_context
,
1205 iscsi_get_fd(iscsilun
->iscsi
),
1207 iscsilun
->events
= 0;
1209 if (iscsilun
->nop_timer
) {
1210 timer_del(iscsilun
->nop_timer
);
1211 timer_free(iscsilun
->nop_timer
);
1212 iscsilun
->nop_timer
= NULL
;
1216 static void iscsi_attach_aio_context(BlockDriverState
*bs
,
1217 AioContext
*new_context
)
1219 IscsiLun
*iscsilun
= bs
->opaque
;
1221 iscsilun
->aio_context
= new_context
;
1222 iscsi_set_events(iscsilun
);
1224 /* Set up a timer for sending out iSCSI NOPs */
1225 iscsilun
->nop_timer
= aio_timer_new(iscsilun
->aio_context
,
1226 QEMU_CLOCK_REALTIME
, SCALE_MS
,
1227 iscsi_nop_timed_event
, iscsilun
);
1228 timer_mod(iscsilun
->nop_timer
,
1229 qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + NOP_INTERVAL
);
1233 * We support iscsi url's on the form
1234 * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
1236 * Note: flags are currently not used by iscsi_open. If this function
1237 * is changed such that flags are used, please examine iscsi_reopen_prepare()
1238 * to see if needs to be changed as well.
1240 static int iscsi_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
1243 IscsiLun
*iscsilun
= bs
->opaque
;
1244 struct iscsi_context
*iscsi
= NULL
;
1245 struct iscsi_url
*iscsi_url
= NULL
;
1246 struct scsi_task
*task
= NULL
;
1247 struct scsi_inquiry_standard
*inq
= NULL
;
1248 struct scsi_inquiry_supported_pages
*inq_vpd
;
1249 char *initiator_name
= NULL
;
1251 Error
*local_err
= NULL
;
1252 const char *filename
;
1255 if ((BDRV_SECTOR_SIZE
% 512) != 0) {
1256 error_setg(errp
, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
1257 "BDRV_SECTOR_SIZE(%lld) is not a multiple "
1258 "of 512", BDRV_SECTOR_SIZE
);
1262 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
1263 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
1265 error_propagate(errp
, local_err
);
1270 filename
= qemu_opt_get(opts
, "filename");
1272 iscsi_url
= iscsi_parse_full_url(iscsi
, filename
);
1273 if (iscsi_url
== NULL
) {
1274 error_setg(errp
, "Failed to parse URL : %s", filename
);
1279 memset(iscsilun
, 0, sizeof(IscsiLun
));
1281 initiator_name
= parse_initiator_name(iscsi_url
->target
);
1283 iscsi
= iscsi_create_context(initiator_name
);
1284 if (iscsi
== NULL
) {
1285 error_setg(errp
, "iSCSI: Failed to create iSCSI context.");
1290 if (iscsi_set_targetname(iscsi
, iscsi_url
->target
)) {
1291 error_setg(errp
, "iSCSI: Failed to set target name.");
1296 if (iscsi_url
->user
!= NULL
) {
1297 ret
= iscsi_set_initiator_username_pwd(iscsi
, iscsi_url
->user
,
1300 error_setg(errp
, "Failed to set initiator username and password");
1306 /* check if we got CHAP username/password via the options */
1307 parse_chap(iscsi
, iscsi_url
->target
, &local_err
);
1308 if (local_err
!= NULL
) {
1309 error_propagate(errp
, local_err
);
1314 if (iscsi_set_session_type(iscsi
, ISCSI_SESSION_NORMAL
) != 0) {
1315 error_setg(errp
, "iSCSI: Failed to set session type to normal.");
1320 iscsi_set_header_digest(iscsi
, ISCSI_HEADER_DIGEST_NONE_CRC32C
);
1322 /* check if we got HEADER_DIGEST via the options */
1323 parse_header_digest(iscsi
, iscsi_url
->target
, &local_err
);
1324 if (local_err
!= NULL
) {
1325 error_propagate(errp
, local_err
);
1330 if (iscsi_full_connect_sync(iscsi
, iscsi_url
->portal
, iscsi_url
->lun
) != 0) {
1331 error_setg(errp
, "iSCSI: Failed to connect to LUN : %s",
1332 iscsi_get_error(iscsi
));
1337 iscsilun
->iscsi
= iscsi
;
1338 iscsilun
->aio_context
= bdrv_get_aio_context(bs
);
1339 iscsilun
->lun
= iscsi_url
->lun
;
1340 iscsilun
->has_write_same
= true;
1342 task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 0, 0,
1343 (void **) &inq
, errp
);
1348 iscsilun
->type
= inq
->periperal_device_type
;
1349 scsi_free_scsi_task(task
);
1352 iscsi_readcapacity_sync(iscsilun
, &local_err
);
1353 if (local_err
!= NULL
) {
1354 error_propagate(errp
, local_err
);
1358 bs
->total_sectors
= sector_lun2qemu(iscsilun
->num_blocks
, iscsilun
);
1359 bs
->request_alignment
= iscsilun
->block_size
;
1361 /* We don't have any emulation for devices other than disks and CD-ROMs, so
1362 * this must be sg ioctl compatible. We force it to be sg, otherwise qemu
1363 * will try to read from the device to guess the image format.
1365 if (iscsilun
->type
!= TYPE_DISK
&& iscsilun
->type
!= TYPE_ROM
) {
1369 task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 1,
1370 SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES
,
1371 (void **) &inq_vpd
, errp
);
1376 for (i
= 0; i
< inq_vpd
->num_pages
; i
++) {
1377 struct scsi_task
*inq_task
;
1378 struct scsi_inquiry_logical_block_provisioning
*inq_lbp
;
1379 struct scsi_inquiry_block_limits
*inq_bl
;
1380 switch (inq_vpd
->pages
[i
]) {
1381 case SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING
:
1382 inq_task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 1,
1383 SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING
,
1384 (void **) &inq_lbp
, errp
);
1385 if (inq_task
== NULL
) {
1389 memcpy(&iscsilun
->lbp
, inq_lbp
,
1390 sizeof(struct scsi_inquiry_logical_block_provisioning
));
1391 scsi_free_scsi_task(inq_task
);
1393 case SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS
:
1394 inq_task
= iscsi_do_inquiry(iscsilun
->iscsi
, iscsilun
->lun
, 1,
1395 SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS
,
1396 (void **) &inq_bl
, errp
);
1397 if (inq_task
== NULL
) {
1401 memcpy(&iscsilun
->bl
, inq_bl
,
1402 sizeof(struct scsi_inquiry_block_limits
));
1403 scsi_free_scsi_task(inq_task
);
1409 scsi_free_scsi_task(task
);
1412 iscsi_attach_aio_context(bs
, iscsilun
->aio_context
);
1414 /* Guess the internal cluster (page) size of the iscsi target by the means
1415 * of opt_unmap_gran. Transfer the unmap granularity only if it has a
1416 * reasonable size */
1417 if (iscsilun
->bl
.opt_unmap_gran
* iscsilun
->block_size
>= 4 * 1024 &&
1418 iscsilun
->bl
.opt_unmap_gran
* iscsilun
->block_size
<= 16 * 1024 * 1024) {
1419 iscsilun
->cluster_sectors
= (iscsilun
->bl
.opt_unmap_gran
*
1420 iscsilun
->block_size
) >> BDRV_SECTOR_BITS
;
1421 if (iscsilun
->lbprz
&& !(bs
->open_flags
& BDRV_O_NOCACHE
)) {
1422 iscsilun
->allocationmap
=
1423 bitmap_new(DIV_ROUND_UP(bs
->total_sectors
,
1424 iscsilun
->cluster_sectors
));
1429 qemu_opts_del(opts
);
1430 g_free(initiator_name
);
1431 if (iscsi_url
!= NULL
) {
1432 iscsi_destroy_url(iscsi_url
);
1435 scsi_free_scsi_task(task
);
1439 if (iscsi
!= NULL
) {
1440 iscsi_destroy_context(iscsi
);
1442 memset(iscsilun
, 0, sizeof(IscsiLun
));
1447 static void iscsi_close(BlockDriverState
*bs
)
1449 IscsiLun
*iscsilun
= bs
->opaque
;
1450 struct iscsi_context
*iscsi
= iscsilun
->iscsi
;
1452 iscsi_detach_aio_context(bs
);
1453 iscsi_destroy_context(iscsi
);
1454 g_free(iscsilun
->zeroblock
);
1455 g_free(iscsilun
->allocationmap
);
1456 memset(iscsilun
, 0, sizeof(IscsiLun
));
1459 static int iscsi_refresh_limits(BlockDriverState
*bs
)
1461 IscsiLun
*iscsilun
= bs
->opaque
;
1463 /* We don't actually refresh here, but just return data queried in
1464 * iscsi_open(): iscsi targets don't change their limits. */
1465 if (iscsilun
->lbp
.lbpu
) {
1466 if (iscsilun
->bl
.max_unmap
< 0xffffffff) {
1467 bs
->bl
.max_discard
= sector_lun2qemu(iscsilun
->bl
.max_unmap
,
1470 bs
->bl
.discard_alignment
= sector_lun2qemu(iscsilun
->bl
.opt_unmap_gran
,
1474 if (iscsilun
->bl
.max_ws_len
< 0xffffffff) {
1475 bs
->bl
.max_write_zeroes
= sector_lun2qemu(iscsilun
->bl
.max_ws_len
,
1478 if (iscsilun
->lbp
.lbpws
) {
1479 bs
->bl
.write_zeroes_alignment
= sector_lun2qemu(iscsilun
->bl
.opt_unmap_gran
,
1482 bs
->bl
.opt_transfer_length
= sector_lun2qemu(iscsilun
->bl
.opt_xfer_len
,
1487 /* Since iscsi_open() ignores bdrv_flags, there is nothing to do here in
1488 * prepare. Note that this will not re-establish a connection with an iSCSI
1489 * target - it is effectively a NOP. */
1490 static int iscsi_reopen_prepare(BDRVReopenState
*state
,
1491 BlockReopenQueue
*queue
, Error
**errp
)
1497 static int iscsi_truncate(BlockDriverState
*bs
, int64_t offset
)
1499 IscsiLun
*iscsilun
= bs
->opaque
;
1500 Error
*local_err
= NULL
;
1502 if (iscsilun
->type
!= TYPE_DISK
) {
1506 iscsi_readcapacity_sync(iscsilun
, &local_err
);
1507 if (local_err
!= NULL
) {
1508 error_free(local_err
);
1512 if (offset
> iscsi_getlength(bs
)) {
1516 if (iscsilun
->allocationmap
!= NULL
) {
1517 g_free(iscsilun
->allocationmap
);
1518 iscsilun
->allocationmap
=
1519 bitmap_new(DIV_ROUND_UP(bs
->total_sectors
,
1520 iscsilun
->cluster_sectors
));
1526 static int iscsi_create(const char *filename
, QemuOpts
*opts
, Error
**errp
)
1529 int64_t total_size
= 0;
1530 BlockDriverState
*bs
;
1531 IscsiLun
*iscsilun
= NULL
;
1534 bs
= bdrv_new("", &error_abort
);
1536 /* Read out options */
1538 qemu_opt_get_size_del(opts
, BLOCK_OPT_SIZE
, 0) / BDRV_SECTOR_SIZE
;
1539 bs
->opaque
= g_malloc0(sizeof(struct IscsiLun
));
1540 iscsilun
= bs
->opaque
;
1542 bs_options
= qdict_new();
1543 qdict_put(bs_options
, "filename", qstring_from_str(filename
));
1544 ret
= iscsi_open(bs
, bs_options
, 0, NULL
);
1545 QDECREF(bs_options
);
1550 iscsi_detach_aio_context(bs
);
1551 if (iscsilun
->type
!= TYPE_DISK
) {
1555 if (bs
->total_sectors
< total_size
) {
1562 if (iscsilun
->iscsi
!= NULL
) {
1563 iscsi_destroy_context(iscsilun
->iscsi
);
1571 static int iscsi_get_info(BlockDriverState
*bs
, BlockDriverInfo
*bdi
)
1573 IscsiLun
*iscsilun
= bs
->opaque
;
1574 bdi
->unallocated_blocks_are_zero
= !!iscsilun
->lbprz
;
1575 bdi
->can_write_zeroes_with_unmap
= iscsilun
->lbprz
&& iscsilun
->lbp
.lbpws
;
1576 bdi
->cluster_size
= iscsilun
->cluster_sectors
* BDRV_SECTOR_SIZE
;
1580 static QemuOptsList iscsi_create_opts
= {
1581 .name
= "iscsi-create-opts",
1582 .head
= QTAILQ_HEAD_INITIALIZER(iscsi_create_opts
.head
),
1585 .name
= BLOCK_OPT_SIZE
,
1586 .type
= QEMU_OPT_SIZE
,
1587 .help
= "Virtual disk size"
1589 { /* end of list */ }
1593 static BlockDriver bdrv_iscsi
= {
1594 .format_name
= "iscsi",
1595 .protocol_name
= "iscsi",
1597 .instance_size
= sizeof(IscsiLun
),
1598 .bdrv_needs_filename
= true,
1599 .bdrv_file_open
= iscsi_open
,
1600 .bdrv_close
= iscsi_close
,
1601 .bdrv_create
= iscsi_create
,
1602 .create_opts
= &iscsi_create_opts
,
1603 .bdrv_reopen_prepare
= iscsi_reopen_prepare
,
1605 .bdrv_getlength
= iscsi_getlength
,
1606 .bdrv_get_info
= iscsi_get_info
,
1607 .bdrv_truncate
= iscsi_truncate
,
1608 .bdrv_refresh_limits
= iscsi_refresh_limits
,
1610 .bdrv_co_get_block_status
= iscsi_co_get_block_status
,
1611 .bdrv_co_discard
= iscsi_co_discard
,
1612 .bdrv_co_write_zeroes
= iscsi_co_write_zeroes
,
1613 .bdrv_co_readv
= iscsi_co_readv
,
1614 .bdrv_co_writev
= iscsi_co_writev
,
1615 .bdrv_co_flush_to_disk
= iscsi_co_flush
,
1618 .bdrv_ioctl
= iscsi_ioctl
,
1619 .bdrv_aio_ioctl
= iscsi_aio_ioctl
,
1622 .bdrv_detach_aio_context
= iscsi_detach_aio_context
,
1623 .bdrv_attach_aio_context
= iscsi_attach_aio_context
,
1626 static QemuOptsList qemu_iscsi_opts
= {
1628 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
1632 .type
= QEMU_OPT_STRING
,
1633 .help
= "username for CHAP authentication to target",
1636 .type
= QEMU_OPT_STRING
,
1637 .help
= "password for CHAP authentication to target",
1639 .name
= "header-digest",
1640 .type
= QEMU_OPT_STRING
,
1641 .help
= "HeaderDigest setting. "
1642 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
1644 .name
= "initiator-name",
1645 .type
= QEMU_OPT_STRING
,
1646 .help
= "Initiator iqn name to use when connecting",
1648 { /* end of list */ }
1652 static void iscsi_block_init(void)
1654 bdrv_register(&bdrv_iscsi
);
1655 qemu_add_opts(&qemu_iscsi_opts
);
1658 block_init(iscsi_block_init
);