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