qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 05/18] virtio: Return error from virtqueue_get_avail


From: Fam Zheng
Subject: [Qemu-devel] [PATCH 05/18] virtio: Return error from virtqueue_get_avail_bytes
Date: Fri, 17 Apr 2015 15:59:20 +0800

Add errp and pass in error_abort for now. Later, we can add error handling code
in callers.

Signed-off-by: Fam Zheng <address@hidden>
---
 hw/char/virtio-serial-bus.c |  2 +-
 hw/virtio/virtio-rng.c      |  2 +-
 hw/virtio/virtio.c          | 39 +++++++++++++++++++++++++++------------
 include/hw/virtio/virtio.h  |  3 ++-
 4 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 1e07858..a56dafc 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -272,7 +272,7 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port)
     if (use_multiport(port->vser) && !port->guest_connected) {
         return 0;
     }
-    virtqueue_get_avail_bytes(vq, &bytes, NULL, 4096, 0);
+    virtqueue_get_avail_bytes(vq, &bytes, NULL, 4096, 0, &error_abort);
     return bytes;
 }
 
diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 06e7178..9e1bd75 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -33,7 +33,7 @@ static size_t get_request_size(VirtQueue *vq, unsigned quota)
 {
     unsigned int in, out;
 
-    virtqueue_get_avail_bytes(vq, &in, &out, quota, 0);
+    virtqueue_get_avail_bytes(vq, &in, &out, quota, 0, &error_abort);
     return in;
 }
 
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 2a24829..1cd454b 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -355,7 +355,8 @@ static int virtqueue_next_desc(VirtIODevice *vdev, hwaddr 
desc_pa,
 
 void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
                                unsigned int *out_bytes,
-                               unsigned max_in_bytes, unsigned max_out_bytes)
+                               unsigned max_in_bytes, unsigned max_out_bytes,
+                               Error **errp)
 {
     unsigned int idx;
     unsigned int total_bufs, in_total, out_total;
@@ -363,27 +364,38 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned 
int *in_bytes,
     idx = vq->last_avail_idx;
 
     total_bufs = in_total = out_total = 0;
-    while (virtqueue_num_heads(vq, idx, &error_abort)) {
+    while (true) {
         VirtIODevice *vdev = vq->vdev;
         unsigned int max, num_bufs, indirect = 0;
         hwaddr desc_pa;
         int i;
 
+        i = virtqueue_num_heads(vq, idx, errp);
+        if (i < 0) {
+            return;
+        } else if (i == 0) {
+            break;
+        }
+
         max = vq->vring.num;
         num_bufs = total_bufs;
-        i = virtqueue_get_head(vq, idx++, &error_abort);
+        i = virtqueue_get_head(vq, idx++, errp);
+        if (i < 0) {
+            return;
+        }
+
         desc_pa = vq->vring.desc;
 
         if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) {
             if (vring_desc_len(vdev, desc_pa, i) % sizeof(VRingDesc)) {
-                error_report("Invalid size for indirect buffer table");
-                exit(1);
+                error_setg(errp, "Invalid size for indirect buffer table");
+                return;
             }
 
             /* If we've got too many, that implies a descriptor loop. */
             if (num_bufs >= max) {
-                error_report("Looped descriptor");
-                exit(1);
+                error_setg(errp, "Looped descriptor");
+                return;
             }
 
             /* loop over the indirect descriptor table */
@@ -396,8 +408,8 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int 
*in_bytes,
         while (true) {
             /* If we've got too many, that implies a descriptor loop. */
             if (++num_bufs > max) {
-                error_report("Looped descriptor");
-                exit(1);
+                error_setg(errp, "Looped descriptor");
+                return;
             }
 
             if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_WRITE) {
@@ -408,8 +420,10 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int 
*in_bytes,
             if (in_total >= max_in_bytes && out_total >= max_out_bytes) {
                 goto done;
             }
-            i = virtqueue_next_desc(vdev, desc_pa, i, max, &error_abort);
-            if (i == max) {
+            i = virtqueue_next_desc(vdev, desc_pa, i, max, errp);
+            if (i < 0) {
+                return;
+            } else if (i == max) {
                 break;
             }
         }
@@ -433,7 +447,8 @@ int virtqueue_avail_bytes(VirtQueue *vq, unsigned int 
in_bytes,
 {
     unsigned int in_total, out_total;
 
-    virtqueue_get_avail_bytes(vq, &in_total, &out_total, in_bytes, out_bytes);
+    virtqueue_get_avail_bytes(vq, &in_total, &out_total, in_bytes, out_bytes,
+                              &error_abort);
     return in_bytes <= in_total && out_bytes <= out_total;
 }
 
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 64c10cf..a37ee64 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -147,7 +147,8 @@ int virtqueue_avail_bytes(VirtQueue *vq, unsigned int 
in_bytes,
                           unsigned int out_bytes);
 void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
                                unsigned int *out_bytes,
-                               unsigned max_in_bytes, unsigned max_out_bytes);
+                               unsigned max_in_bytes, unsigned max_out_bytes,
+                               Error **errp);
 
 void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
 
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]