struct scsi_get_lba_status *lbas = NULL;
struct scsi_lba_status_descriptor *lbasd = NULL;
struct IscsiTask iTask;
- uint64_t lba;
+ uint64_t lba, max_bytes;
int ret;
iscsi_co_init_iscsitask(iscsilun, &iTask);
}
lba = offset / iscsilun->block_size;
+ max_bytes = (iscsilun->num_blocks - lba) * iscsilun->block_size;
qemu_mutex_lock(&iscsilun->mutex);
retry:
}
lbas = scsi_datain_unmarshall(iTask.task);
- if (lbas == NULL) {
+ if (lbas == NULL || lbas->num_descriptors == 0) {
ret = -EIO;
goto out_unlock;
}
goto out_unlock;
}
- *pnum = (int64_t) lbasd->num_blocks * iscsilun->block_size;
+ *pnum = MIN((int64_t) lbasd->num_blocks * iscsilun->block_size, max_bytes);
if (lbasd->provisioning == SCSI_PROVISIONING_TYPE_DEALLOCATED ||
lbasd->provisioning == SCSI_PROVISIONING_TYPE_ANCHORED) {
acb->ioh->driver_status |= SG_ERR_DRIVER_SENSE;
acb->ioh->sb_len_wr = acb->task->datain.size - 2;
- ss = (acb->ioh->mx_sb_len >= acb->ioh->sb_len_wr) ?
- acb->ioh->mx_sb_len : acb->ioh->sb_len_wr;
+ ss = MIN(acb->ioh->mx_sb_len, acb->ioh->sb_len_wr);
memcpy(acb->ioh->sbp, &acb->task->datain.data[2], ss);
}
iscsilun->cluster_size = iscsilun->bl.opt_unmap_gran *
iscsilun->block_size;
if (iscsilun->lbprz) {
- ret = iscsi_allocmap_init(iscsilun, bs->open_flags);
+ ret = iscsi_allocmap_init(iscsilun, flags);
}
}
static int coroutine_fn iscsi_co_truncate(BlockDriverState *bs, int64_t offset,
bool exact, PreallocMode prealloc,
- Error **errp)
+ BdrvRequestFlags flags, Error **errp)
{
IscsiLun *iscsilun = bs->opaque;
int64_t cur_length;
return 0;
}
-static int coroutine_fn iscsi_co_create_opts(const char *filename, QemuOpts *opts,
- Error **errp)
-{
- int ret = 0;
- int64_t total_size = 0;
- BlockDriverState *bs;
- IscsiLun *iscsilun = NULL;
- QDict *bs_options;
- Error *local_err = NULL;
-
- bs = bdrv_new();
-
- /* Read out options */
- total_size = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
- BDRV_SECTOR_SIZE);
- bs->opaque = g_new0(struct IscsiLun, 1);
- iscsilun = bs->opaque;
-
- bs_options = qdict_new();
- iscsi_parse_filename(filename, bs_options, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- ret = -EINVAL;
- } else {
- ret = iscsi_open(bs, bs_options, 0, NULL);
- }
- qobject_unref(bs_options);
-
- if (ret != 0) {
- goto out;
- }
- iscsi_detach_aio_context(bs);
- if (iscsilun->type != TYPE_DISK) {
- ret = -ENODEV;
- goto out;
- }
- if (bs->total_sectors < total_size) {
- ret = -ENOSPC;
- goto out;
- }
-
- ret = 0;
-out:
- if (iscsilun->iscsi != NULL) {
- iscsi_destroy_context(iscsilun->iscsi);
- }
- g_free(bs->opaque);
- bs->opaque = NULL;
- bdrv_unref(bs);
- return ret;
-}
-
static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
{
IscsiLun *iscsilun = bs->opaque;
return r;
}
-static QemuOptsList iscsi_create_opts = {
- .name = "iscsi-create-opts",
- .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head),
- .desc = {
- {
- .name = BLOCK_OPT_SIZE,
- .type = QEMU_OPT_SIZE,
- .help = "Virtual disk size"
- },
- { /* end of list */ }
- }
-};
static const char *const iscsi_strong_runtime_opts[] = {
"transport",
.bdrv_parse_filename = iscsi_parse_filename,
.bdrv_file_open = iscsi_open,
.bdrv_close = iscsi_close,
- .bdrv_co_create_opts = iscsi_co_create_opts,
- .create_opts = &iscsi_create_opts,
+ .bdrv_co_create_opts = bdrv_co_create_opts_simple,
+ .create_opts = &bdrv_create_opts_simple,
.bdrv_reopen_prepare = iscsi_reopen_prepare,
.bdrv_reopen_commit = iscsi_reopen_commit,
.bdrv_co_invalidate_cache = iscsi_co_invalidate_cache,
.bdrv_parse_filename = iscsi_parse_filename,
.bdrv_file_open = iscsi_open,
.bdrv_close = iscsi_close,
- .bdrv_co_create_opts = iscsi_co_create_opts,
- .create_opts = &iscsi_create_opts,
+ .bdrv_co_create_opts = bdrv_co_create_opts_simple,
+ .create_opts = &bdrv_create_opts_simple,
.bdrv_reopen_prepare = iscsi_reopen_prepare,
.bdrv_reopen_commit = iscsi_reopen_commit,
.bdrv_co_invalidate_cache = iscsi_co_invalidate_cache,