[PATCH v3 7/7] hw/scsi/spapr_vscsi: do not crash QEMU on migration errors

Laurent Vivier <[email protected]>
Newsgroups gmane.comp.emulators.qemu,gmane.comp.emulators.qemu.block
Message-ID <[email protected]>
Currently vscsi asserts on invalid SCSI requests.

Fail migration gracefully instead.

Signed-off-by: Laurent Vivier <[email protected]>
---

Notes:
    v2: New patch to manage vscsi

 hw/scsi/spapr_vscsi.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/hw/scsi/spapr_vscsi.c b/hw/scsi/spapr_vscsi.c
index 7768ec0bdd49..b6a0411e9c44 100644
--- a/hw/scsi/spapr_vscsi.c
+++ b/hw/scsi/spapr_vscsi.c
@@ -650,9 +650,17 @@ static void *vscsi_load_request(QEMUFile *f, SCSIRequest *sreq, Error **errp)
     int rc;
     Error *local_err = NULL;
 
-    assert(sreq->tag < VSCSI_REQ_LIMIT);
+    if (sreq->tag >= VSCSI_REQ_LIMIT) {
+        error_setg(errp, "VSCSI: request tag#%u out of range (max %d)",
+                   sreq->tag, VSCSI_REQ_LIMIT);
+        return NULL;
+    }
+
     req = &s->reqs[sreq->tag];
-    assert(!req->active);
+    if (req->active) {
+        error_setg(errp, "VSCSI: request tag#%u already active", sreq->tag);
+        return NULL;
+    }
 
     memset(req, 0, sizeof(*req));
     rc = vmstate_load_state(f, &vmstate_spapr_vscsi_req, req, 1, &local_err);
@@ -662,7 +670,11 @@ static void *vscsi_load_request(QEMUFile *f, SCSIRequest *sreq, Error **errp)
                                 sreq->tag);
         return NULL;
     }
-    assert(req->active);
+    if (!req->active) {
+        error_setg(errp, "VSCSI: request tag#%u not active after load",
+                   sreq->tag);
+        return NULL;
+    }
 
     req->sreq = scsi_req_ref(sreq);
 
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.