diff mbox

[5/7] hw/block/virtio-blk: use virtio wrappers to access headers.

Message ID 1375938949-22622-6-git-send-email-rusty@rustcorp.com.au
State New
Headers show

Commit Message

Rusty Russell Aug. 8, 2013, 5:15 a.m. UTC
Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 hw/block/virtio-blk.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

Comments

Peter Maydell Aug. 8, 2013, 9:57 a.m. UTC | #1
On 8 August 2013 06:15, Rusty Russell <rusty@rustcorp.com.au> wrote:
> Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.

This is the right thing, incidentally. The _raw() functions are
supposed to take a guest physical address (as an integer), where
the _p() ones take a host void*. However the implementation means
you can get away with misusing the _raw() function where you meant
the _p() function provided your code is only built for system
emulation, because the macro's casts mean the compiler won't
call you it. (We should probably try to clean up some of the
misuses.)

-- PMM
Anthony Liguori Aug. 8, 2013, 1:32 p.m. UTC | #2
Rusty Russell <rusty@rustcorp.com.au> writes:

> Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.
>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>  hw/block/virtio-blk.c | 35 ++++++++++++++++++-----------------
>  1 file changed, 18 insertions(+), 17 deletions(-)
>
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index cf12469..9b897fa 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -25,6 +25,7 @@
>  # include <scsi/sg.h>
>  #endif
>  #include "hw/virtio/virtio-bus.h"
> +#include "hw/virtio/virtio-access.h"
>  
>  typedef struct VirtIOBlockReq
>  {
> @@ -76,7 +77,7 @@ 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);
> +        bool is_read = !(virtio_ldl_p(&req->out->type) & VIRTIO_BLK_T_OUT);
>          if (virtio_blk_handle_rw_error(req, -ret, is_read))
>              return;
>      }
> @@ -223,12 +224,12 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
>          hdr.status = CHECK_CONDITION;
>      }
>  
> -    stl_p(&req->scsi->errors,
> -          hdr.status | (hdr.msg_status << 8) |
> -          (hdr.host_status << 16) | (hdr.driver_status << 24));
> -    stl_p(&req->scsi->residual, hdr.resid);
> -    stl_p(&req->scsi->sense_len, hdr.sb_len_wr);
> -    stl_p(&req->scsi->data_len, hdr.dxfer_len);
> +    virtio_stl_p(&req->scsi->errors,
> +		 hdr.status | (hdr.msg_status << 8) |
> +		 (hdr.host_status << 16) | (hdr.driver_status << 24));
> +    virtio_stl_p(&req->scsi->residual, hdr.resid);
> +    virtio_stl_p(&req->scsi->sense_len, hdr.sb_len_wr);
> +    virtio_stl_p(&req->scsi->data_len, hdr.dxfer_len);
>  
>      virtio_blk_req_complete(req, status);
>      g_free(req);
> @@ -239,7 +240,7 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
>  
>  fail:
>      /* Just put anything nonzero so that the ioctl fails in the guest.  */
> -    stl_p(&req->scsi->errors, 255);
> +    virtio_stl_p(&req->scsi->errors, 255);
>      virtio_blk_req_complete(req, status);
>      g_free(req);
>  }
> @@ -285,7 +286,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(&req->out->sector);
>  
>      bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_WRITE);
>  
> @@ -319,7 +320,7 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
>  {
>      uint64_t sector;
>  
> -    sector = ldq_p(&req->out->sector);
> +    sector = virtio_ldq_p(&req->out->sector);
>  
>      bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_READ);
>  
> @@ -357,7 +358,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(&req->out->type);
>  
>      if (type & VIRTIO_BLK_T_FLUSH) {
>          virtio_blk_handle_flush(req, mrb);
> @@ -485,12 +486,12 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
>  
>      bdrv_get_geometry(s->bs, &capacity);
>      memset(&blkcfg, 0, sizeof(blkcfg));
> -    stq_raw(&blkcfg.capacity, capacity);
> -    stl_raw(&blkcfg.seg_max, 128 - 2);
> -    stw_raw(&blkcfg.cylinders, s->conf->cyls);
> -    stl_raw(&blkcfg.blk_size, blk_size);
> -    stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
> -    stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
> +    virtio_stq_p(&blkcfg.capacity, capacity);
> +    virtio_stl_p(&blkcfg.seg_max, 128 - 2);
> +    virtio_stw_p(&blkcfg.cylinders, s->conf->cyls);
> +    virtio_stl_p(&blkcfg.blk_size, blk_size);
> +    virtio_stw_p(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
> +    virtio_stw_p(&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
> -- 
> 1.8.1.2
diff mbox

Patch

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index cf12469..9b897fa 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -25,6 +25,7 @@ 
 # include <scsi/sg.h>
 #endif
 #include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-access.h"
 
 typedef struct VirtIOBlockReq
 {
@@ -76,7 +77,7 @@  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);
+        bool is_read = !(virtio_ldl_p(&req->out->type) & VIRTIO_BLK_T_OUT);
         if (virtio_blk_handle_rw_error(req, -ret, is_read))
             return;
     }
@@ -223,12 +224,12 @@  static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
         hdr.status = CHECK_CONDITION;
     }
 
-    stl_p(&req->scsi->errors,
-          hdr.status | (hdr.msg_status << 8) |
-          (hdr.host_status << 16) | (hdr.driver_status << 24));
-    stl_p(&req->scsi->residual, hdr.resid);
-    stl_p(&req->scsi->sense_len, hdr.sb_len_wr);
-    stl_p(&req->scsi->data_len, hdr.dxfer_len);
+    virtio_stl_p(&req->scsi->errors,
+		 hdr.status | (hdr.msg_status << 8) |
+		 (hdr.host_status << 16) | (hdr.driver_status << 24));
+    virtio_stl_p(&req->scsi->residual, hdr.resid);
+    virtio_stl_p(&req->scsi->sense_len, hdr.sb_len_wr);
+    virtio_stl_p(&req->scsi->data_len, hdr.dxfer_len);
 
     virtio_blk_req_complete(req, status);
     g_free(req);
@@ -239,7 +240,7 @@  static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
 
 fail:
     /* Just put anything nonzero so that the ioctl fails in the guest.  */
-    stl_p(&req->scsi->errors, 255);
+    virtio_stl_p(&req->scsi->errors, 255);
     virtio_blk_req_complete(req, status);
     g_free(req);
 }
@@ -285,7 +286,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(&req->out->sector);
 
     bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_WRITE);
 
@@ -319,7 +320,7 @@  static void virtio_blk_handle_read(VirtIOBlockReq *req)
 {
     uint64_t sector;
 
-    sector = ldq_p(&req->out->sector);
+    sector = virtio_ldq_p(&req->out->sector);
 
     bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_READ);
 
@@ -357,7 +358,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(&req->out->type);
 
     if (type & VIRTIO_BLK_T_FLUSH) {
         virtio_blk_handle_flush(req, mrb);
@@ -485,12 +486,12 @@  static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 
     bdrv_get_geometry(s->bs, &capacity);
     memset(&blkcfg, 0, sizeof(blkcfg));
-    stq_raw(&blkcfg.capacity, capacity);
-    stl_raw(&blkcfg.seg_max, 128 - 2);
-    stw_raw(&blkcfg.cylinders, s->conf->cyls);
-    stl_raw(&blkcfg.blk_size, blk_size);
-    stw_raw(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
-    stw_raw(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
+    virtio_stq_p(&blkcfg.capacity, capacity);
+    virtio_stl_p(&blkcfg.seg_max, 128 - 2);
+    virtio_stw_p(&blkcfg.cylinders, s->conf->cyls);
+    virtio_stl_p(&blkcfg.blk_size, blk_size);
+    virtio_stw_p(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
+    virtio_stw_p(&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