Received: from eggs.gnu.org ([2001:4830:134:3::10]:60384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1IS4-0000RI-18 for qemu-devel@nongnu.org; Sun, 29 Jun 2014 12:59:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1IRz-0003UA-CG for qemu-devel@nongnu.org; Sun, 29 Jun 2014 12:59:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1IRy-0003U0-Ti for qemu-devel@nongnu.org; Sun, 29 Jun 2014 12:59:35 -0400 Date: Sun, 29 Jun 2014 19:59:54 +0300 From: "Michael S. Tsirkin" Message-ID: <1404060115-27410-32-git-send-email-mst@redhat.com> References: <1404060115-27410-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1404060115-27410-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 31/37] virtio-blk: use virtio wrappers to access headers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Maydell , Anthony Liguori , Stefan Hajnoczi , Rusty Russell , Alexander Graf , Anthony Liguori , Greg Kurz From: Rusty Russell Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p. Signed-off-by: Rusty Russell Reviewed-by: Anthony Liguori [ pass VirtIODevice * to memory accessors, Greg Kurz ] Signed-off-by: Greg Kurz Reviewed-by: Alexander Graf Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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 b06af8c..e59ebc9 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -27,6 +27,7 @@ # include #endif #include "hw/virtio/virtio-bus.h" +#include "hw/virtio/virtio-access.h" static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s) { @@ -88,7 +89,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; } @@ -130,6 +132,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; @@ -224,12 +228,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 @@ -239,7 +243,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; } @@ -289,7 +293,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); @@ -323,7 +327,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); @@ -374,7 +378,7 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb) - sizeof(struct virtio_blk_inhdr); iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr)); - 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); @@ -504,12 +508,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 -- MST