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