aboutsummaryrefslogtreecommitdiff
path: root/lib/libvirtio/virtio-blk.c
diff options
context:
space:
mode:
authorNikunj A Dadhania <nikunj@linux.vnet.ibm.com>2016-02-01 11:17:58 +0530
committerAlexey Kardashevskiy <aik@ozlabs.ru>2016-02-08 16:40:38 +1100
commitfdb62149dc88c8003f1c2273f6becca08629910a (patch)
tree6c1ae5e12ac0d35dd13ac2b532512707b59ed36c /lib/libvirtio/virtio-blk.c
parentb5a692d3f7c2cf3ca2eea5e9f8f99f0972cf56d1 (diff)
downloadSLOF-fdb62149dc88c8003f1c2273f6becca08629910a.zip
SLOF-fdb62149dc88c8003f1c2273f6becca08629910a.tar.gz
SLOF-fdb62149dc88c8003f1c2273f6becca08629910a.tar.bz2
virtio-blk: add helpers for filling descriptors
Enable virtio_fill_desc/fill_blk_hdr with legacy and modern mode for further use Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib/libvirtio/virtio-blk.c')
-rw-r--r--lib/libvirtio/virtio-blk.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/libvirtio/virtio-blk.c b/lib/libvirtio/virtio-blk.c
index 1a8ee1b..d7a3039 100644
--- a/lib/libvirtio/virtio-blk.c
+++ b/lib/libvirtio/virtio-blk.c
@@ -13,6 +13,7 @@
#include <stdio.h>
#include <cpu.h>
#include <helpers.h>
+#include <byteorder.h>
#include "virtio.h"
#include "virtio-blk.h"
@@ -82,6 +83,19 @@ virtioblk_shutdown(struct virtio_device *dev)
virtio_reset_device(dev);
}
+static void fill_blk_hdr(struct virtio_blk_req *blkhdr, bool is_modern,
+ uint32_t type, uint32_t ioprio, uint32_t sector)
+{
+ if (is_modern) {
+ blkhdr->type = cpu_to_le32(type);
+ blkhdr->ioprio = cpu_to_le32(ioprio);
+ blkhdr->sector = cpu_to_le64(sector);
+ } else {
+ blkhdr->type = type;
+ blkhdr->ioprio = ioprio;
+ blkhdr->sector = sector;
+ }
+}
/**
* Read blocks
@@ -137,33 +151,25 @@ virtioblk_read(struct virtio_device *dev, char *buf, uint64_t blocknum, long cnt
current_used_idx = &vq_used->idx;
/* Set up header */
- blkhdr.type = VIRTIO_BLK_T_IN | VIRTIO_BLK_T_BARRIER;
- blkhdr.ioprio = 1;
- blkhdr.sector = blocknum * blk_size / DEFAULT_SECTOR_SIZE;
+ fill_blk_hdr(&blkhdr, false, VIRTIO_BLK_T_IN | VIRTIO_BLK_T_BARRIER,
+ 1, blocknum * blk_size / DEFAULT_SECTOR_SIZE);
/* Determine descriptor index */
id = (vq_avail->idx * 3) % vq_size;
/* Set up virtqueue descriptor for header */
desc = &vq_desc[id];
- desc->addr = (uint64_t)&blkhdr;
- desc->len = sizeof(struct virtio_blk_req);
- desc->flags = VRING_DESC_F_NEXT;
- desc->next = (id + 1) % vq_size;
+ virtio_fill_desc(desc, false, (uint64_t)&blkhdr, sizeof(struct virtio_blk_req),
+ VRING_DESC_F_NEXT, (id + 1) % vq_size);
/* Set up virtqueue descriptor for data */
desc = &vq_desc[(id + 1) % vq_size];
- desc->addr = (uint64_t)buf;
- desc->len = cnt * blk_size;
- desc->flags = VRING_DESC_F_NEXT | VRING_DESC_F_WRITE;
- desc->next = (id + 2) % vq_size;
+ virtio_fill_desc(desc, false, (uint64_t)buf, cnt * blk_size,
+ VRING_DESC_F_NEXT | VRING_DESC_F_WRITE, (id + 2) % vq_size);
/* Set up virtqueue descriptor for status */
desc = &vq_desc[(id + 2) % vq_size];
- desc->addr = (uint64_t)&status;
- desc->len = 1;
- desc->flags = VRING_DESC_F_WRITE;
- desc->next = 0;
+ virtio_fill_desc(desc, false, (uint64_t)&status, 1, VRING_DESC_F_WRITE, 0);
vq_avail->ring[vq_avail->idx % vq_size] = id;
mb();