qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PULL 03/18] vring: factor common code for error exits
Date: Fri, 20 Dec 2013 16:46:41 +0100	[thread overview]
Message-ID: <1387554416-5837-4-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1387554416-5837-1-git-send-email-stefanha@redhat.com>

From: Paolo Bonzini <pbonzini@redhat.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 hw/block/dataplane/virtio-blk.c |  1 +
 hw/virtio/dataplane/vring.c     | 34 +++++++++++++++++++++-------------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 1e57f3a..2b4a773 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -308,6 +308,7 @@ static void handle_notify(EventNotifier *e)
 
             if (process_request(&s->ioqueue, iov, out_num, in_num, head) < 0) {
                 vring_set_broken(&s->vring);
+                ret = -EFAULT;
                 break;
             }
             iov += out_num + in_num;
diff --git a/hw/virtio/dataplane/vring.c b/hw/virtio/dataplane/vring.c
index 8294f36..d81b653 100644
--- a/hw/virtio/dataplane/vring.c
+++ b/hw/virtio/dataplane/vring.c
@@ -244,7 +244,8 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
 
     /* If there was a fatal error then refuse operation */
     if (vring->broken) {
-        return -EFAULT;
+        ret = -EFAULT;
+        goto out;
     }
 
     /* Check it isn't doing very strange things with descriptor numbers. */
@@ -255,13 +256,14 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
     if (unlikely((uint16_t)(avail_idx - last_avail_idx) > num)) {
         error_report("Guest moved used index from %u to %u",
                      last_avail_idx, avail_idx);
-        vring->broken = true;
-        return -EFAULT;
+        ret = -EFAULT;
+        goto out;
     }
 
     /* If there's nothing new since last we looked. */
     if (avail_idx == last_avail_idx) {
-        return -EAGAIN;
+        ret = -EAGAIN;
+        goto out;
     }
 
     /* Only get avail ring entries after they have been exposed by guest. */
@@ -274,8 +276,8 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
     /* If their number is silly, that's an error. */
     if (unlikely(head >= num)) {
         error_report("Guest says index %u > %u is available", head, num);
-        vring->broken = true;
-        return -EFAULT;
+        ret = -EFAULT;
+        goto out;
     }
 
     if (vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
@@ -289,14 +291,14 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
     do {
         if (unlikely(i >= num)) {
             error_report("Desc index is %u > %u, head = %u", i, num, head);
-            vring->broken = true;
-            return -EFAULT;
+            ret = -EFAULT;
+            goto out;
         }
         if (unlikely(++found > num)) {
             error_report("Loop detected: last one at %u vq size %u head %u",
                          i, num, head);
-            vring->broken = true;
-            return -EFAULT;
+            ret = -EFAULT;
+            goto out;
         }
         desc = vring->vr.desc[i];
 
@@ -306,15 +308,14 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
         if (desc.flags & VRING_DESC_F_INDIRECT) {
             int ret = get_indirect(vring, iov, iov_end, out_num, in_num, &desc);
             if (ret < 0) {
-                return ret;
+                goto out;
             }
             continue;
         }
 
         ret = get_desc(vring, iov, iov_end, out_num, in_num, &desc);
         if (ret < 0) {
-            vring->broken |= (ret == -EFAULT);
-            return ret;
+            goto out;
         }
 
         i = desc.next;
@@ -323,6 +324,13 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
     /* On success, increment avail index. */
     vring->last_avail_idx++;
     return head;
+
+out:
+    assert(ret < 0);
+    if (ret == -EFAULT) {
+        vring->broken = true;
+    }
+    return ret;
 }
 
 /* After we've used one of their buffers, we tell them about it.
-- 
1.8.4.2

  parent reply	other threads:[~2013-12-20 15:47 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-20 15:46 [Qemu-devel] [PULL 00/18] Block patches Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 01/18] sheepdog: fix dynamic grow for running qcow2 format Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 02/18] vring: create a common function to parse descriptors Stefan Hajnoczi
2013-12-20 15:46 ` Stefan Hajnoczi [this message]
2014-01-13 10:18   ` [Qemu-devel] [PULL 03/18] vring: factor common code for error exits Peter Maydell
2013-12-20 15:46 ` [Qemu-devel] [PULL 04/18] dataplane: change vring API to use VirtQueueElement Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 05/18] dataplane: replace hostmem with memory_region_find Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 06/18] qapi-schema: fix QEMU 1.8 references Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 07/18] block/iscsi: Fix compilation for libiscsi 1.4.0 (API change) Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 08/18] block: vhdx - improve error message, and .bdrv_check implementation Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 09/18] docs: updated qemu-img man page and qemu-doc to reflect VHDX support Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 10/18] vmdk: Check VMFS extent line field number Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 11/18] vmdk: Allow vmdk_create to work with protocol Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 12/18] qemu-iotests: drop duplicate virtio-blk initialization failure Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 13/18] mirror: Don't close target Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 14/18] mirror: Move base to MirrorBlockJob Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 15/18] block: Add commit_active_start() Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 16/18] commit: Support commit active layer Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 17/18] qemu-iotests: Update test cases for commit active Stefan Hajnoczi
2013-12-20 15:46 ` [Qemu-devel] [PULL 18/18] commit: Remove unused check Stefan Hajnoczi
2014-01-10 17:29 ` [Qemu-devel] [PULL 00/18] Block patches Stefan Weil
2014-01-10 18:06   ` Paolo Bonzini
2014-01-10 18:37     ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1387554416-5837-4-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).