Skip to content

Commit 469513b

Browse files
Fam Zhengmdroth
authored andcommitted
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 <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit cd723b8) Signed-off-by: Michael Roth <[email protected]>
1 parent 12664c5 commit 469513b

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

hw/scsi/scsi-disk.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static void scsi_read_data(SCSIRequest *req)
392392
return;
393393
}
394394

395-
if (s->tray_open) {
395+
if (!blk_is_available(req->dev->conf.blk)) {
396396
scsi_read_complete(r, -ENOMEDIUM);
397397
return;
398398
}
@@ -523,7 +523,7 @@ static void scsi_write_data(SCSIRequest *req)
523523
scsi_write_complete_noio(r, 0);
524524
return;
525525
}
526-
if (s->tray_open) {
526+
if (!blk_is_available(req->dev->conf.blk)) {
527527
scsi_write_complete_noio(r, -ENOMEDIUM);
528528
return;
529529
}
@@ -795,10 +795,7 @@ static inline bool media_is_dvd(SCSIDiskState *s)
795795
if (s->qdev.type != TYPE_ROM) {
796796
return false;
797797
}
798-
if (!blk_is_inserted(s->qdev.conf.blk)) {
799-
return false;
800-
}
801-
if (s->tray_open) {
798+
if (!blk_is_available(s->qdev.conf.blk)) {
802799
return false;
803800
}
804801
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
@@ -811,10 +808,7 @@ static inline bool media_is_cd(SCSIDiskState *s)
811808
if (s->qdev.type != TYPE_ROM) {
812809
return false;
813810
}
814-
if (!blk_is_inserted(s->qdev.conf.blk)) {
815-
return false;
816-
}
817-
if (s->tray_open) {
811+
if (!blk_is_available(s->qdev.conf.blk)) {
818812
return false;
819813
}
820814
blk_get_geometry(s->qdev.conf.blk, &nb_sectors);
@@ -878,7 +872,7 @@ static int scsi_read_dvd_structure(SCSIDiskState *s, SCSIDiskReq *r,
878872
}
879873

880874
if (format != 0xff) {
881-
if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
875+
if (!blk_is_available(s->qdev.conf.blk)) {
882876
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
883877
return -1;
884878
}
@@ -1874,7 +1868,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
18741868
break;
18751869

18761870
default:
1877-
if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
1871+
if (!blk_is_available(s->qdev.conf.blk)) {
18781872
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
18791873
return 0;
18801874
}
@@ -1903,7 +1897,7 @@ static int32_t scsi_disk_emulate_command(SCSIRequest *req, uint8_t *buf)
19031897
memset(outbuf, 0, r->buflen);
19041898
switch (req->cmd.buf[0]) {
19051899
case TEST_UNIT_READY:
1906-
assert(!s->tray_open && blk_is_inserted(s->qdev.conf.blk));
1900+
assert(blk_is_available(s->qdev.conf.blk));
19071901
break;
19081902
case INQUIRY:
19091903
buflen = scsi_disk_emulate_inquiry(req, outbuf);
@@ -2142,7 +2136,7 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
21422136

21432137
command = buf[0];
21442138

2145-
if (s->tray_open || !blk_is_inserted(s->qdev.conf.blk)) {
2139+
if (!blk_is_available(s->qdev.conf.blk)) {
21462140
scsi_check_condition(r, SENSE_CODE(NO_MEDIUM));
21472141
return 0;
21482142
}

0 commit comments

Comments
 (0)