mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 17:23:56 -06:00
block/nvme: Replace qemu_try_blockalign0 by qemu_try_blockalign/memset
In the next commit we'll get rid of qemu_try_blockalign(). To ease review, first replace qemu_try_blockalign0() by explicit calls to qemu_try_blockalign() and memset(). Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200821195359.1285345-10-philmd@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
7d3b214ae4
commit
2ed846930d
1 changed files with 9 additions and 7 deletions
16
block/nvme.c
16
block/nvme.c
|
@ -174,12 +174,12 @@ static void nvme_init_queue(BlockDriverState *bs, NVMeQueue *q,
|
||||||
|
|
||||||
bytes = ROUND_UP(nentries * entry_bytes, s->page_size);
|
bytes = ROUND_UP(nentries * entry_bytes, s->page_size);
|
||||||
q->head = q->tail = 0;
|
q->head = q->tail = 0;
|
||||||
q->queue = qemu_try_blockalign0(bs, bytes);
|
q->queue = qemu_try_blockalign(bs, bytes);
|
||||||
|
|
||||||
if (!q->queue) {
|
if (!q->queue) {
|
||||||
error_setg(errp, "Cannot allocate queue");
|
error_setg(errp, "Cannot allocate queue");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
memset(q->queue, 0, bytes);
|
||||||
r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova);
|
r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova);
|
||||||
if (r) {
|
if (r) {
|
||||||
error_setg(errp, "Cannot map queue");
|
error_setg(errp, "Cannot map queue");
|
||||||
|
@ -223,11 +223,12 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs,
|
||||||
if (!q) {
|
if (!q) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
q->prp_list_pages = qemu_try_blockalign0(bs,
|
q->prp_list_pages = qemu_try_blockalign(bs,
|
||||||
s->page_size * NVME_NUM_REQS);
|
s->page_size * NVME_NUM_REQS);
|
||||||
if (!q->prp_list_pages) {
|
if (!q->prp_list_pages) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
memset(q->prp_list_pages, 0, s->page_size * NVME_NUM_REQS);
|
||||||
qemu_mutex_init(&q->lock);
|
qemu_mutex_init(&q->lock);
|
||||||
q->s = s;
|
q->s = s;
|
||||||
q->index = idx;
|
q->index = idx;
|
||||||
|
@ -521,7 +522,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
|
||||||
.cdw10 = cpu_to_le32(0x1),
|
.cdw10 = cpu_to_le32(0x1),
|
||||||
};
|
};
|
||||||
|
|
||||||
id = qemu_try_blockalign0(bs, sizeof(*id));
|
id = qemu_try_blockalign(bs, sizeof(*id));
|
||||||
if (!id) {
|
if (!id) {
|
||||||
error_setg(errp, "Cannot allocate buffer for identify response");
|
error_setg(errp, "Cannot allocate buffer for identify response");
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -531,8 +532,9 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
|
||||||
error_setg(errp, "Cannot map buffer for DMA");
|
error_setg(errp, "Cannot map buffer for DMA");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
cmd.dptr.prp1 = cpu_to_le64(iova);
|
|
||||||
|
|
||||||
|
memset(id, 0, sizeof(*id));
|
||||||
|
cmd.dptr.prp1 = cpu_to_le64(iova);
|
||||||
if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) {
|
if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) {
|
||||||
error_setg(errp, "Failed to identify controller");
|
error_setg(errp, "Failed to identify controller");
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -1283,11 +1285,11 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs,
|
||||||
|
|
||||||
assert(s->nr_queues > 1);
|
assert(s->nr_queues > 1);
|
||||||
|
|
||||||
buf = qemu_try_blockalign0(bs, s->page_size);
|
buf = qemu_try_blockalign(bs, s->page_size);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
memset(buf, 0, s->page_size);
|
||||||
buf->nlb = cpu_to_le32(bytes >> s->blkshift);
|
buf->nlb = cpu_to_le32(bytes >> s->blkshift);
|
||||||
buf->slba = cpu_to_le64(offset >> s->blkshift);
|
buf->slba = cpu_to_le64(offset >> s->blkshift);
|
||||||
buf->cattr = 0;
|
buf->cattr = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue