From patchwork Tue Jun 24 17:43:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 363583 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E2B6614007C for ; Wed, 25 Jun 2014 03:45:06 +1000 (EST) Received: from localhost ([::1]:33150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzUmH-0004wS-6d for incoming@patchwork.ozlabs.org; Tue, 24 Jun 2014 13:45:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzUlD-0003Od-3J for qemu-devel@nongnu.org; Tue, 24 Jun 2014 13:44:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzUl5-00041V-8v for qemu-devel@nongnu.org; Tue, 24 Jun 2014 13:43:59 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:52061) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzUl4-000410-VQ for qemu-devel@nongnu.org; Tue, 24 Jun 2014 13:43:51 -0400 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 24 Jun 2014 18:43:49 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 24 Jun 2014 18:43:48 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7A9922190046 for ; Tue, 24 Jun 2014 18:43:35 +0100 (BST) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5OHhlrX31522938 for ; Tue, 24 Jun 2014 17:43:47 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5OHhkDK017093 for ; Tue, 24 Jun 2014 11:43:47 -0600 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s5OHhk5E017090; Tue, 24 Jun 2014 11:43:46 -0600 Received: from bahia.local (icon-9-164-148-109.megacenter.de.ibm.com [9.164.148.109]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 334B0210FF4; Tue, 24 Jun 2014 19:43:45 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Tue, 24 Jun 2014 19:43:44 +0200 Message-ID: <20140624174329.17522.9621.stgit@bahia.local> In-Reply-To: <20140624151955.17522.62537.stgit@bahia.local> References: <20140624151955.17522.62537.stgit@bahia.local> User-Agent: StGit/0.17-dirty MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14062417-0542-0000-0000-000009A55BED X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.113 Cc: Kevin Wolf , Peter Maydell , Stefan Hajnoczi , Juan Quintela , Rusty Russell , Alexander Graf , "Michael S. Tsirkin" , aneesh.kumar@linux.vnet.ibm.com, Anthony Liguori , Amit Shah , Paolo Bonzini , Andreas =?utf-8?q?F=C3=A4rber?= Subject: [Qemu-devel] [PATCH v9 17/22] virtio-blk: use virtio wrappers to access headers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 fd32a6a..6bdd29f 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -26,6 +26,7 @@ # include #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