scsi-disk: Cleaning up around tray open state
Even if tray is not open, it can be empty (blk_is_inserted() == false).
Handle both cases correctly by replacing the s->tray_open checks with
blk_is_available(), which is an AND of the two.
Also simplify successive checks of them into blk_is_available(), in a
couple cases.
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-Id: <1473848224-24809-2-git-send-email-famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit cd723b8560)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
12664c5a1c
commit
469513b38a
|
|
@ -392,7 +392,7 @@ static void scsi_read_data(SCSIRequest *req)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->tray_open) {
|
if (!blk_is_available(req->dev->conf.blk)) {
|
||||||
scsi_read_complete(r, -ENOMEDIUM);
|
scsi_read_complete(r, -ENOMEDIUM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -523,7 +523,7 @@ static void scsi_write_data(SCSIRequest *req)
|
||||||
scsi_write_complete_noio(r, 0);
|
scsi_write_complete_noio(r, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (s->tray_open) {
|
if (!blk_is_available(req->dev->conf.blk)) {
|
||||||
scsi_write_complete_noio(r, -ENOMEDIUM);
|
scsi_write_complete_noio(r, -ENOMEDIUM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -795,10 +795,7 @@ static inline bool media_is_dvd(SCSIDiskState *s)
|
||||||
if (s->qdev.type != TYPE_ROM) {
|
if (s->qdev.type != TYPE_ROM) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!blk_is_inserted(s->qdev.conf.blk)) {
|
if (!blk_is_available(s->qdev.conf.blk)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (s->tray_open) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
|
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
|
||||||
|
|
@ -811,10 +808,7 @@ static inline bool media_is_cd(SCSIDiskState *s)
|
||||||
if (s->qdev.type != TYPE_ROM) {
|
if (s->qdev.type != TYPE_ROM) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!blk_is_inserted(s->qdev.conf.blk)) {
|
if (!blk_is_available(s->qdev.conf.blk)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (s->tray_open) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
|
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
|
||||||
|
|
@ -878,7 +872,7 @@ static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format != 0xff) {
|
if (format != 0xff) {
|
||||||
if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
|
if (!blk_is_available(s->qdev.conf.blk)) {
|
||||||
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
|
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -1874,7 +1868,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
|
if (!blk_is_available(s->qdev.conf.blk)) {
|
||||||
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
|
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1903,7 +1897,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
|
||||||
memset(outbuf, 0, r->buflen);
|
memset(outbuf, 0, r->buflen);
|
||||||
switch (req->cmd.buf[0]) {
|
switch (req->cmd.buf[0]) {
|
||||||
case TEST_UNIT_READY:
|
case TEST_UNIT_READY:
|
||||||
assert(!s->tray_open && blk_is_inserted(s->qdev.conf.blk));
|
assert(blk_is_available(s->qdev.conf.blk));
|
||||||
break;
|
break;
|
||||||
case INQUIRY:
|
case INQUIRY:
|
||||||
buflen = scsi_disk_emulate_inquiry(req, outbuf);
|
buflen = scsi_disk_emulate_inquiry(req, outbuf);
|
||||||
|
|
@ -2142,7 +2136,7 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
|
||||||
|
|
||||||
command = buf[0];
|
command = buf[0];
|
||||||
|
|
||||||
if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
|
if (!blk_is_available(s->qdev.conf.blk)) {
|
||||||
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
|
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue