[SLOF] [PATCH v1 03/27] virtio-blk: add helpers for filling descriptors
Nikunj A Dadhania
nikunj at linux.vnet.ibm.com
Wed Jan 13 22:16:50 AEDT 2016
Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
---
lib/libvirtio/virtio-blk.c | 29 ++++++++++++++---------------
lib/libvirtio/virtio.c | 10 ++++++++++
lib/libvirtio/virtio.h | 3 +++
3 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/lib/libvirtio/virtio-blk.c b/lib/libvirtio/virtio-blk.c
index 826f2ea..b8c4da2 100644
--- a/lib/libvirtio/virtio-blk.c
+++ b/lib/libvirtio/virtio-blk.c
@@ -77,6 +77,13 @@ virtioblk_shutdown(struct virtio_device *dev)
virtio_reset_device(dev);
}
+static void fill_blk_hdr(struct virtio_blk_req *blkhdr,
+ uint32_t type, uint32_t ioprio, uint32_t sector)
+{
+ blkhdr->type = type;
+ blkhdr->ioprio = ioprio;
+ blkhdr->sector = sector;
+}
/**
* Read blocks
@@ -132,33 +139,25 @@ virtioblk_read(struct virtio_device *dev, char *buf, long 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, 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, (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, (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, (uint64_t)&status, 1, VRING_DESC_F_WRITE, 0);
vq_avail->ring[vq_avail->idx % vq_size] = id;
mb();
diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c
index f9c00a6..8094e3a 100644
--- a/lib/libvirtio/virtio.c
+++ b/lib/libvirtio/virtio.c
@@ -109,6 +109,16 @@ struct vring_used *virtio_get_vring_used(struct virtio_device *dev, int queue)
}
+void virtio_fill_desc(struct vring_desc *desc,
+ uint64_t addr, uint32_t len,
+ uint16_t flags, uint16_t next)
+{
+ desc->addr = addr;
+ desc->len = len;
+ desc->flags = flags;
+ desc->next = next;
+}
+
/**
* Reset virtio device
*/
diff --git a/lib/libvirtio/virtio.h b/lib/libvirtio/virtio.h
index d5759b4..9293d19 100644
--- a/lib/libvirtio/virtio.h
+++ b/lib/libvirtio/virtio.h
@@ -75,6 +75,9 @@ extern int virtio_get_qsize(struct virtio_device *dev, int queue);
extern struct vring_desc *virtio_get_vring_desc(struct virtio_device *dev, int queue);
extern struct vring_avail *virtio_get_vring_avail(struct virtio_device *dev, int queue);
extern struct vring_used *virtio_get_vring_used(struct virtio_device *dev, int queue);
+extern void virtio_fill_desc(struct vring_desc *desc,
+ uint64_t addr, uint32_t len,
+ uint16_t flags, uint16_t next);
extern void virtio_reset_device(struct virtio_device *dev);
extern void virtio_queue_notify(struct virtio_device *dev, int queue);
--
2.5.0
More information about the SLOF
mailing list