Skip to content

Commit 6e18475

Browse files
Fam Zhengmdroth
authored andcommitted
virtio-scsi: Don't abort when media is ejected
With an ejected block backend, blk_get_aio_context() would return qemu_aio_context. In this case don't assert. Signed-off-by: Fam Zheng <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit 2a2d69f) Signed-off-by: Michael Roth <[email protected]>
1 parent 469513b commit 6e18475

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

hw/scsi/virtio-scsi.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ static void virtio_scsi_cancel_notify(Notifier *notifier, void *data)
236236
g_free(n);
237237
}
238238

239+
static inline void virtio_scsi_ctx_check(VirtIOSCSI *s, SCSIDevice *d)
240+
{
241+
if (s->dataplane_started && d && blk_is_available(d->conf.blk)) {
242+
assert(blk_get_aio_context(d->conf.blk) == s->ctx);
243+
}
244+
}
245+
239246
/* Return 0 if the request is ready to be completed and return to guest;
240247
* -EINPROGRESS if the request is submitted and will be completed later, in the
241248
* case of async cancellation. */
@@ -247,9 +254,7 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
247254
int target;
248255
int ret = 0;
249256

250-
if (s->dataplane_started && d) {
251-
assert(blk_get_aio_context(d->conf.blk) == s->ctx);
252-
}
257+
virtio_scsi_ctx_check(s, d);
253258
/* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */
254259
req->resp.tmf.response = VIRTIO_SCSI_S_OK;
255260

@@ -539,9 +544,7 @@ static bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req
539544
virtio_scsi_complete_cmd_req(req);
540545
return false;
541546
}
542-
if (s->dataplane_started) {
543-
assert(blk_get_aio_context(d->conf.blk) == s->ctx);
544-
}
547+
virtio_scsi_ctx_check(s, d);
545548
req->sreq = scsi_req_new(d, req->req.cmd.tag,
546549
virtio_scsi_get_lun(req->req.cmd.lun),
547550
req->req.cmd.cdb, req);

0 commit comments

Comments
 (0)