mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-19 09:53:01 +00:00
dm: virtio-block: clean up assert
This patch is to clean up assert from virtio-block Tracked-On: #3252 Signed-off-by: Conghui Chen <conghui.chen@intel.com> Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
This commit is contained in:
parent
3ef385d6c4
commit
d0e0871283
@ -31,7 +31,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <openssl/md5.h>
|
#include <openssl/md5.h>
|
||||||
|
|
||||||
@ -219,6 +218,15 @@ virtio_blk_done(struct blockif_req *br, int err)
|
|||||||
pthread_mutex_unlock(&blk->mtx);
|
pthread_mutex_unlock(&blk->mtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
virtio_blk_abort(struct virtio_vq_info *vq, uint16_t idx)
|
||||||
|
{
|
||||||
|
if (idx < vq->qsize) {
|
||||||
|
vq_relchain(vq, idx, 1);
|
||||||
|
vq_endchains(vq, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virtio_blk_proc(struct virtio_blk *blk, struct virtio_vq_info *vq)
|
virtio_blk_proc(struct virtio_blk *blk, struct virtio_vq_info *vq)
|
||||||
{
|
{
|
||||||
@ -231,6 +239,7 @@ virtio_blk_proc(struct virtio_blk *blk, struct virtio_vq_info *vq)
|
|||||||
struct iovec iov[BLOCKIF_IOV_MAX + 2];
|
struct iovec iov[BLOCKIF_IOV_MAX + 2];
|
||||||
uint16_t idx, flags[BLOCKIF_IOV_MAX + 2];
|
uint16_t idx, flags[BLOCKIF_IOV_MAX + 2];
|
||||||
|
|
||||||
|
idx = vq->qsize;
|
||||||
n = vq_getchain(vq, &idx, iov, BLOCKIF_IOV_MAX + 2, flags);
|
n = vq_getchain(vq, &idx, iov, BLOCKIF_IOV_MAX + 2, flags);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -241,18 +250,36 @@ virtio_blk_proc(struct virtio_blk *blk, struct virtio_vq_info *vq)
|
|||||||
* XXX - note - this fails on crash dump, which does a
|
* XXX - note - this fails on crash dump, which does a
|
||||||
* VIRTIO_BLK_T_FLUSH with a zero transfer length
|
* VIRTIO_BLK_T_FLUSH with a zero transfer length
|
||||||
*/
|
*/
|
||||||
assert(n >= 2 && n <= BLOCKIF_IOV_MAX + 2);
|
if (n < 2 || n > BLOCKIF_IOV_MAX + 2) {
|
||||||
|
WPRINTF(("%s: vq_getchain failed\n", __func__));
|
||||||
|
virtio_blk_abort(vq, idx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
io = &blk->ios[idx];
|
io = &blk->ios[idx];
|
||||||
assert((flags[0] & VRING_DESC_F_WRITE) == 0);
|
if ((flags[0] & VRING_DESC_F_WRITE) != 0) {
|
||||||
assert(iov[0].iov_len == sizeof(struct virtio_blk_hdr));
|
WPRINTF(("%s: the type for hdr should not be VRING_DESC_F_WRITE\n", __func__));
|
||||||
|
virtio_blk_abort(vq, idx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (iov[0].iov_len != sizeof(struct virtio_blk_hdr)) {
|
||||||
|
WPRINTF(("%s: the size for hdr %ld should be %ld \n",
|
||||||
|
__func__,
|
||||||
|
iov[0].iov_len,
|
||||||
|
sizeof(struct virtio_blk_hdr)));
|
||||||
|
virtio_blk_abort(vq, idx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
vbh = iov[0].iov_base;
|
vbh = iov[0].iov_base;
|
||||||
memcpy(&io->req.iov, &iov[1], sizeof(struct iovec) * (n - 2));
|
memcpy(&io->req.iov, &iov[1], sizeof(struct iovec) * (n - 2));
|
||||||
io->req.iovcnt = n - 2;
|
io->req.iovcnt = n - 2;
|
||||||
io->req.offset = vbh->sector * DEV_BSIZE;
|
io->req.offset = vbh->sector * DEV_BSIZE;
|
||||||
io->status = iov[--n].iov_base;
|
io->status = iov[--n].iov_base;
|
||||||
assert(iov[n].iov_len == 1);
|
if (iov[n].iov_len != 1 || ((flags[n] & VRING_DESC_F_WRITE) == 0)) {
|
||||||
assert(flags[n] & VRING_DESC_F_WRITE);
|
WPRINTF(("%s: status iov is invalid!\n", __func__));
|
||||||
|
virtio_blk_abort(vq, idx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX
|
* XXX
|
||||||
@ -283,7 +310,11 @@ virtio_blk_proc(struct virtio_blk *blk, struct virtio_vq_info *vq)
|
|||||||
* therefore test the inverse of the descriptor bit
|
* therefore test the inverse of the descriptor bit
|
||||||
* to the op.
|
* to the op.
|
||||||
*/
|
*/
|
||||||
assert(((flags[i] & VRING_DESC_F_WRITE) == 0) == writeop);
|
if (((flags[i] & VRING_DESC_F_WRITE) == 0) != writeop) {
|
||||||
|
WPRINTF(("%s: flag is confict with operation\n", __func__));
|
||||||
|
virtio_blk_done(&io->req, EINVAL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
iolen += iov[i].iov_len;
|
iolen += iov[i].iov_len;
|
||||||
}
|
}
|
||||||
io->req.resid = iolen;
|
io->req.resid = iolen;
|
||||||
@ -337,7 +368,8 @@ virtio_blk_proc(struct virtio_blk *blk, struct virtio_vq_info *vq)
|
|||||||
virtio_blk_done(&io->req, EOPNOTSUPP);
|
virtio_blk_done(&io->req, EOPNOTSUPP);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(err == 0);
|
if (err)
|
||||||
|
WPRINTF(("%s: request process failed\n", __func__));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user