[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v8 16/20] virtio-blk: use virtio wrappers to access
From: |
Greg Kurz |
Subject: |
[Qemu-devel] [PATCH v8 16/20] virtio-blk: use virtio wrappers to access headers |
Date: |
Fri, 13 Jun 2014 13:24:46 +0200 |
User-agent: |
StGit/0.17-dirty |
From: Rusty Russell <address@hidden>
Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.
Signed-off-by: Rusty Russell <address@hidden>
Reviewed-by: Anthony Liguori <address@hidden>
[ pass VirtIODevice * to memory accessors,
Greg Kurz <address@hidden> ]
Signed-off-by: Greg Kurz <address@hidden>
---
hw/block/virtio-blk.c | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index e432bcd..dc7e811 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -26,6 +26,7 @@
# include <scsi/sg.h>
#endif
#include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-access.h"
typedef struct VirtIOBlockReq
{
@@ -76,7 +77,8 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
trace_virtio_blk_rw_complete(req, ret);
if (ret) {
- bool is_read = !(ldl_p(&req->out->type) & VIRTIO_BLK_T_OUT);
+ int p = virtio_ldl_p(VIRTIO_DEVICE(req->dev), &req->out->type);
+ bool is_read = !(p & VIRTIO_BLK_T_OUT);
if (virtio_blk_handle_rw_error(req, -ret, is_read))
return;
}
@@ -129,6 +131,8 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk,
{
int status = VIRTIO_BLK_S_OK;
struct virtio_scsi_inhdr *scsi = NULL;
+ VirtIODevice *vdev = VIRTIO_DEVICE(blk);
+
#ifdef __linux__
int i;
struct sg_io_hdr hdr;
@@ -223,12 +227,12 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk,
hdr.status = CHECK_CONDITION;
}
- stl_p(&scsi->errors,
- hdr.status | (hdr.msg_status << 8) |
- (hdr.host_status << 16) | (hdr.driver_status << 24));
- stl_p(&scsi->residual, hdr.resid);
- stl_p(&scsi->sense_len, hdr.sb_len_wr);
- stl_p(&scsi->data_len, hdr.dxfer_len);
+ virtio_stl_p(vdev, &scsi->errors,
+ hdr.status | (hdr.msg_status << 8) |
+ (hdr.host_status << 16) | (hdr.driver_status << 24));
+ virtio_stl_p(vdev, &scsi->residual, hdr.resid);
+ virtio_stl_p(vdev, &scsi->sense_len, hdr.sb_len_wr);
+ virtio_stl_p(vdev, &scsi->data_len, hdr.dxfer_len);
return status;
#else
@@ -238,7 +242,7 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk,
fail:
/* Just put anything nonzero so that the ioctl fails in the guest. */
if (scsi) {
- stl_p(&scsi->errors, 255);
+ virtio_stl_p(vdev, &scsi->errors, 255);
}
return status;
}
@@ -293,7 +297,7 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req,
MultiReqBuffer *mrb)
BlockRequest *blkreq;
uint64_t sector;
- sector = ldq_p(&req->out->sector);
+ sector = virtio_ldq_p(VIRTIO_DEVICE(req->dev), &req->out->sector);
bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_WRITE);
@@ -327,7 +331,7 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
{
uint64_t sector;
- sector = ldq_p(&req->out->sector);
+ sector = virtio_ldq_p(VIRTIO_DEVICE(req->dev), &req->out->sector);
bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_READ);
@@ -365,7 +369,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
req->out = (void *)req->elem.out_sg[0].iov_base;
req->in = (void *)req->elem.in_sg[req->elem.in_num - 1].iov_base;
- type = ldl_p(&req->out->type);
+ type = virtio_ldl_p(VIRTIO_DEVICE(req->dev), &req->out->type);
if (type & VIRTIO_BLK_T_FLUSH) {
virtio_blk_handle_flush(req, mrb);
@@ -494,12 +498,12 @@ static void virtio_blk_update_config(VirtIODevice *vdev,
uint8_t *config)
bdrv_get_geometry(s->bs, &capacity);
memset(&blkcfg, 0, sizeof(blkcfg));
- stq_p(&blkcfg.capacity, capacity);
- stl_p(&blkcfg.seg_max, 128 - 2);
- stw_p(&blkcfg.cylinders, s->conf->cyls);
- stl_p(&blkcfg.blk_size, blk_size);
- stw_p(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
- stw_p(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
+ virtio_stq_p(vdev, &blkcfg.capacity, capacity);
+ virtio_stl_p(vdev, &blkcfg.seg_max, 128 - 2);
+ virtio_stw_p(vdev, &blkcfg.cylinders, s->conf->cyls);
+ virtio_stl_p(vdev, &blkcfg.blk_size, blk_size);
+ virtio_stw_p(vdev, &blkcfg.min_io_size, s->conf->min_io_size / blk_size);
+ virtio_stw_p(vdev, &blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
blkcfg.heads = s->conf->heads;
/*
* We must ensure that the block device capacity is a multiple of
- Re: [Qemu-devel] [PATCH v8 11/20] virtio: add endian-ambivalent support to VirtIODevice, (continued)
[Qemu-devel] [PATCH v8 12/20] virtio: memory accessors for endian-ambivalent targets, Greg Kurz, 2014/06/13
[Qemu-devel] [PATCH v8 13/20] virtio: allow byte swapping for vring, Greg Kurz, 2014/06/13
[Qemu-devel] [PATCH v8 14/20] virtio-net: use virtio wrappers to access headers, Greg Kurz, 2014/06/13
[Qemu-devel] [PATCH v8 15/20] virtio-balloon: use virtio wrappers to access page frame numbers, Greg Kurz, 2014/06/13
[Qemu-devel] [PATCH v8 16/20] virtio-blk: use virtio wrappers to access headers,
Greg Kurz <=
[Qemu-devel] [PATCH v8 17/20] virtio-scsi: use virtio wrappers to access headers, Greg Kurz, 2014/06/13
[Qemu-devel] [PATCH v8 18/20] virtio-serial-bus: use virtio wrappers to access headers, Greg Kurz, 2014/06/13
[Qemu-devel] [PATCH v8 19/20] virtio-9p: use virtio wrappers to access headers, Greg Kurz, 2014/06/13
[Qemu-devel] [PATCH v8 20/20] target-ppc: enable virtio endian ambivalent support, Greg Kurz, 2014/06/13
Re: [Qemu-devel] [PATCH v8 00/20] virtio endian-ambivalent target, Alexander Graf, 2014/06/13