Commit e8637c90 authored by Jan Kiszka's avatar Jan Kiszka Committed by Aurelien Jarno
Browse files

scsi: Dequeue requests before invoking completion callback



The request completion callback of the LSI controller may start the next
request that can use the same tag as the completed one. As the latter is
still enqueued at that point, scsi_send_command will complain about the
tag reuse and cancel the completed request. That will cause a double
free later on when the completion path cleans up as well.

Fix this by dequeuing the request before invoking the callback.

Signed-off-by: default avatarJan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: default avatarAurelien Jarno <aurelien@aurel32.net>
parent 9651ac55
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t l
    req->tag = tag;
    req->lun = lun;
    req->status = -1;
    req->enqueued = true;
    QTAILQ_INSERT_TAIL(&d->requests, req, next);
    return req;
}
@@ -158,9 +159,17 @@ SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag)
    return NULL;
}

void scsi_req_free(SCSIRequest *req)
static void scsi_req_dequeue(SCSIRequest *req)
{
    if (req->enqueued) {
        QTAILQ_REMOVE(&req->dev->requests, req, next);
        req->enqueued = false;
    }
}

void scsi_req_free(SCSIRequest *req)
{
    scsi_req_dequeue(req);
    qemu_free(req);
}

@@ -512,6 +521,7 @@ void scsi_req_print(SCSIRequest *req)
void scsi_req_complete(SCSIRequest *req)
{
    assert(req->status != -1);
    scsi_req_dequeue(req);
    req->bus->complete(req->bus, SCSI_REASON_DONE,
                       req->tag,
                       req->status);
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ typedef struct SCSIRequest {
        enum SCSIXferMode mode;
    } cmd;
    BlockDriverAIOCB  *aiocb;
    bool enqueued;
    QTAILQ_ENTRY(SCSIRequest) next;
} SCSIRequest;