[Spice-commits] 3 commits - server/char_device.c

Hans de Goede jwrdegoede at kemper.freedesktop.org
Mon Apr 1 10:56:22 PDT 2013


 server/char_device.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

New commits:
commit baa7cab700155201abde86e31018e1a8f28dc330
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Fri Mar 29 10:07:26 2013 +0100

    char_device: Don't set active when stopped and don't access dev after unref
    
    2 closely related changes in one:
    1) When leaving the read or write loop because the chardev has been stopped
    active should not be updated. It has been set to FALSE by
    spice_char_device_stop and should stay FALSE
    2) The updating of dev->active should be done *before* unref-ing dev
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/server/char_device.c b/server/char_device.c
index 63afee1..f500f04 100644
--- a/server/char_device.c
+++ b/server/char_device.c
@@ -320,8 +320,10 @@ static int spice_char_device_read_from_device(SpiceCharDeviceState *dev)
         max_send_tokens--;
     }
     dev->during_read_from_device = 0;
+    if (dev->running) {
+        dev->active = dev->active || did_read;
+    }
     spice_char_device_state_unref(dev);
-    dev->active = dev->active || did_read;
     return did_read;
 }
 
@@ -475,9 +477,9 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev)
         } else {
             spice_assert(ring_is_empty(&dev->write_queue));
         }
+        dev->active = dev->active || total;
     }
     spice_char_device_state_unref(dev);
-    dev->active = dev->active || total;
     return total;
 }
 
commit 3d775594b506e4199e850b51af8de762902b849a
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Fri Mar 29 10:05:24 2013 +0100

    char_device: Don't set the write-retry timer when not running
    
    The write-retry timer should not be set when we're leaving
    spice_char_device_write_to_device because the char-dev has been stopped.
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/server/char_device.c b/server/char_device.c
index 368c9bc..63afee1 100644
--- a/server/char_device.c
+++ b/server/char_device.c
@@ -468,10 +468,13 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev)
         dev->cur_write_buf_pos += n;
     }
     /* retry writing as long as the write queue is not empty */
-    if (dev->cur_write_buf) {
-        core->timer_start(dev->write_to_dev_timer, CHAR_DEVICE_WRITE_TO_TIMEOUT);
-    } else {
-        spice_assert(ring_is_empty(&dev->write_queue));
+    if (dev->running) {
+        if (dev->cur_write_buf) {
+            core->timer_start(dev->write_to_dev_timer,
+                              CHAR_DEVICE_WRITE_TO_TIMEOUT);
+        } else {
+            spice_assert(ring_is_empty(&dev->write_queue));
+        }
     }
     spice_char_device_state_unref(dev);
     dev->active = dev->active || total;
commit e3c6f793f7592bce4778986b2e28f9e7f2c56589
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Fri Mar 29 10:02:35 2013 +0100

    char_device: Properly update buffer status when leaving the write loop on stop
    
    Before this patch the write-loop in spice_char_device_write_to_device would
    break on running becoming 0, after having written some data, without updating
    the buffer status, causing the same data to be written *again* when started.
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/server/char_device.c b/server/char_device.c
index e07eda1..368c9bc 100644
--- a/server/char_device.c
+++ b/server/char_device.c
@@ -438,7 +438,7 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev)
     core->timer_cancel(dev->write_to_dev_timer);
 
     sif = SPICE_CONTAINEROF(dev->sin->base.sif, SpiceCharDeviceInterface, base);
-    while (1) {
+    while (dev->running) {
         uint32_t write_len;
 
         if (!dev->cur_write_buf) {
@@ -454,9 +454,6 @@ static int spice_char_device_write_to_device(SpiceCharDeviceState *dev)
         write_len = dev->cur_write_buf->buf + dev->cur_write_buf->buf_used -
                     dev->cur_write_buf_pos;
         n = sif->write(dev->sin, dev->cur_write_buf_pos, write_len);
-        if (!dev->running) {
-            break;
-        }
         if (n <= 0) {
             break;
         }


More information about the Spice-commits mailing list