提交 1288844e 编写于 作者: P Paolo Bonzini

iscsi: reorganize iscsi_readcapacity_sync

Avoid the goto, and use the same retry logic for the 10- and 16-
byte versions.

Cc: qemu-stable@nongnu.org
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 f0d2a4d4
...@@ -931,60 +931,58 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun) ...@@ -931,60 +931,58 @@ static int iscsi_readcapacity_sync(IscsiLun *iscsilun)
int ret = 0; int ret = 0;
int retries = ISCSI_CMD_RETRIES; int retries = ISCSI_CMD_RETRIES;
try_again: do {
switch (iscsilun->type) { if (task != NULL) {
case TYPE_DISK: scsi_free_scsi_task(task);
task = iscsi_readcapacity16_sync(iscsilun->iscsi, iscsilun->lun); task = NULL;
if (task == NULL || task->status != SCSI_STATUS_GOOD) {
if (task != NULL && task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_UNIT_ATTENTION
&& retries-- > 0) {
scsi_free_scsi_task(task);
goto try_again;
}
error_report("iSCSI: failed to send readcapacity16 command.");
ret = -EINVAL;
goto out;
}
rc16 = scsi_datain_unmarshall(task);
if (rc16 == NULL) {
error_report("iSCSI: Failed to unmarshall readcapacity16 data.");
ret = -EINVAL;
goto out;
}
iscsilun->block_size = rc16->block_length;
iscsilun->num_blocks = rc16->returned_lba + 1;
break;
case TYPE_ROM:
task = iscsi_readcapacity10_sync(iscsilun->iscsi, iscsilun->lun, 0, 0);
if (task == NULL || task->status != SCSI_STATUS_GOOD) {
error_report("iSCSI: failed to send readcapacity10 command.");
ret = -EINVAL;
goto out;
}
rc10 = scsi_datain_unmarshall(task);
if (rc10 == NULL) {
error_report("iSCSI: Failed to unmarshall readcapacity10 data.");
ret = -EINVAL;
goto out;
} }
iscsilun->block_size = rc10->block_size;
if (rc10->lba == 0) { switch (iscsilun->type) {
/* blank disk loaded */ case TYPE_DISK:
iscsilun->num_blocks = 0; task = iscsi_readcapacity16_sync(iscsilun->iscsi, iscsilun->lun);
} else { if (task != NULL && task->status == SCSI_STATUS_GOOD) {
iscsilun->num_blocks = rc10->lba + 1; rc16 = scsi_datain_unmarshall(task);
if (rc16 == NULL) {
error_report("iSCSI: Failed to unmarshall readcapacity16 data.");
ret = -EINVAL;
} else {
iscsilun->block_size = rc16->block_length;
iscsilun->num_blocks = rc16->returned_lba + 1;
}
}
break;
case TYPE_ROM:
task = iscsi_readcapacity10_sync(iscsilun->iscsi, iscsilun->lun, 0, 0);
if (task != NULL && task->status == SCSI_STATUS_GOOD) {
rc10 = scsi_datain_unmarshall(task);
if (rc10 == NULL) {
error_report("iSCSI: Failed to unmarshall readcapacity10 data.");
ret = -EINVAL;
} else {
iscsilun->block_size = rc10->block_size;
if (rc10->lba == 0) {
/* blank disk loaded */
iscsilun->num_blocks = 0;
} else {
iscsilun->num_blocks = rc10->lba + 1;
}
}
}
break;
default:
return 0;
} }
break; } while (task != NULL && task->status == SCSI_STATUS_CHECK_CONDITION
default: && task->sense.key == SCSI_SENSE_UNIT_ATTENTION
break; && retries-- > 0);
}
out: if (task == NULL || task->status != SCSI_STATUS_GOOD) {
error_report("iSCSI: failed to send readcapacity10 command.");
ret = -EINVAL;
}
if (task) { if (task) {
scsi_free_scsi_task(task); scsi_free_scsi_task(task);
} }
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册