Blame SOURCES/kvm-char-change-qemu_chr_fe_add_watch-to-return-unsigned.patch

619821
From 6106261b0f1501a3772f4f9b67ae329697c7b815 Mon Sep 17 00:00:00 2001
b28c64
From: Eduardo Habkost <ehabkost@redhat.com>
619821
Date: Tue, 23 May 2017 13:43:59 +0200
b28c64
Subject: [PATCH] char: change qemu_chr_fe_add_watch to return unsigned
b28c64
b28c64
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
619821
Message-id: <20170523134359.8747-1-ehabkost@redhat.com>
619821
Patchwork-id: 75396
619821
O-Subject: [RHEL-7.4 qemu-kvm PATCH] char: change qemu_chr_fe_add_watch to return unsigned
619821
Bugzilla: 1451470
b28c64
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
b28c64
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
b28c64
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
b28c64
b28c64
From: Paolo Bonzini <pbonzini@redhat.com>
b28c64
619821
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1451470#c32
619821
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=13257025
b28c64
b28c64
g_source_attach can return any value between 1 and UINT_MAX if you let
b28c64
QEMU run long enough.  However, qemu_chr_fe_add_watch can also return
b28c64
a negative errno value when the device is disconnected or does not
b28c64
support chr_add_watch.  Change it to return zero to avoid overloading
b28c64
these values.
b28c64
b28c64
Fix the cadence_uart which asserts in this case (easily obtained with
b28c64
"-serial pty").
b28c64
619821
Backport Conflicts:
b28c64
	hw/char/cadence_uart.c (no qemu_chr_fe_add_watch() call)
b28c64
	net/vhost-user.c (doesn't exit)
b28c64
	qemu-char.c (trivial conflict)
b28c64
b28c64
Tested-by: Bret Ketchum <bcketchum@gmail.com>
b28c64
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
b28c64
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
b28c64
(cherry picked from commit 6f1de6b70d857d5e316ae6fd908f52818b827b08)
b28c64
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
b28c64
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
b28c64
---
b28c64
 include/sysemu/char.h | 16 ++++++++++++++--
b28c64
 qemu-char.c           |  8 ++++----
b28c64
 2 files changed, 18 insertions(+), 6 deletions(-)
b28c64
b28c64
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
b28c64
index ad101d9..c0e5b25 100644
b28c64
--- a/include/sysemu/char.h
b28c64
+++ b/include/sysemu/char.h
b28c64
@@ -147,8 +147,20 @@ void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open);
b28c64
 void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
b28c64
     GCC_FMT_ATTR(2, 3);
b28c64
 
b28c64
-int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
b28c64
-                          GIOFunc func, void *user_data);
b28c64
+/**
b28c64
+ * @qemu_chr_fe_add_watch:
b28c64
+ *
b28c64
+ * If the backend is connected, create and add a #GSource that fires
b28c64
+ * when the given condition (typically G_IO_OUT|G_IO_HUP or G_IO_HUP)
b28c64
+ * is active; return the #GSource's tag.  If it is disconnected,
b28c64
+ * return 0.
b28c64
+ *
b28c64
+ * @cond the condition to poll for
b28c64
+ * @func the function to call when the condition happens
b28c64
+ * @user_data the opaque pointer to pass to @func
b28c64
+ */
b28c64
+guint qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
b28c64
+                            GIOFunc func, void *user_data);
b28c64
 
b28c64
 /**
b28c64
  * @qemu_chr_fe_write:
b28c64
diff --git a/qemu-char.c b/qemu-char.c
b28c64
index 08cb959..5edca0a 100644
b28c64
--- a/qemu-char.c
b28c64
+++ b/qemu-char.c
b28c64
@@ -3373,19 +3373,19 @@ void qemu_chr_fe_set_open(struct CharDriverState *chr, int fe_open)
b28c64
     }
b28c64
 }
b28c64
 
b28c64
-int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
b28c64
-                          GIOFunc func, void *user_data)
b28c64
+guint qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
b28c64
+                            GIOFunc func, void *user_data)
b28c64
 {
b28c64
     GSource *src;
b28c64
     guint tag;
b28c64
 
b28c64
     if (s->chr_add_watch == NULL) {
b28c64
-        return -ENOSYS;
b28c64
+        return 0;
b28c64
     }
b28c64
 
b28c64
     src = s->chr_add_watch(s, cond);
b28c64
     if (!src) {
b28c64
-        return -EINVAL;
b28c64
+        return 0;
b28c64
     }
b28c64
 
b28c64
     g_source_set_callback(src, (GSourceFunc)func, user_data, NULL);
b28c64
-- 
b28c64
1.8.3.1
b28c64