Skip to contentSkip to conversation

Block patches

GIT PULL Applied Stefan Hajnoczi 2 participants 7 messages Oct 3, 2017 – Oct 5, 2017

lore
Share & tools
lore
#0 lore raw

The following changes since commit d147f7e815f97cb477e223586bcb80c316ae10ea:

Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2017-10-03 16:27:24 +0100)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to f708a5e71cba0d784e307334c07ade5f56f827ab:

aio: fix assert when remove poll during destroy (2017-10-03 14:36:19 -0400)

----------------------------------------------------------------

----------------------------------------------------------------

Peter Xu (4):
qom: provide root container for internal objs
iothread: provide helpers for internal use
iothread: export iothread_stop()
iothread: delay the context release to finalize

Stefan Hajnoczi (1):
aio: fix assert when remove poll during destroy

 include/qom/object.h      | 11 +++++++++++
 include/sysemu/iothread.h |  9 +++++++++
 iothread.c                | 46 ++++++++++++++++++++++++++++++++++++----------
 qom/object.c              | 11 +++++++++++
 util/aio-posix.c          |  9 ++++++++-
 5 files changed, 75 insertions(+), 11 deletions(-)
Signature · 1 line
2.13.6
#1 lore raw

[Qemu-devel] [PULL 1/5] qom: provide root container for internal objs

From: Peter Xu <[email protected]>

We have object_get_objects_root() to keep user created objects, however no place for objects that will be used internally. Create such a container for internal objects.

CC Andreas Färber <[email protected]>
CC Markus Armbruster <[email protected]>
CC Paolo Bonzini <[email protected]>

Message-id: [email protected]

---
 include/qom/object.h | 11 +++++++++++
 qom/object.c         | 11 +++++++++++
 2 files changed, 22 insertions(+)
include/qom/object.h +11 -0
index f3e5cff37a..e0d9824415 100644
@@ -1214,6 +1214,17 @@ Object *object_get_root(void);
 Object *object_get_objects_root(void);
 
 /**
+ * object_get_internal_root:
+ *
+ * Get the container object that holds internally used object
+ * instances.  Any object which is put into this container must not be
+ * user visible, and it will not be exposed in the QOM tree.
+ *
+ * Returns: the internal object container
+ */
+Object *object_get_internal_root(void);
+
+/**
  * object_get_canonical_path_component:
  *
  * Returns: The final component in the object's canonical path.  The canonical
qom/object.c +11 -0
index 3e18537e9b..6a7bd9257b 100644
@@ -1370,6 +1370,17 @@ Object *object_get_objects_root(void)
     return container_get(object_get_root(), "/objects");
 }
 
+Object *object_get_internal_root(void)
+{
+    static Object *internal_root;
+
+    if (!internal_root) {
+        internal_root = object_new("container");
+    }
+
+    return internal_root;
+}
+
 static void object_get_child_property(Object *obj, Visitor *v,
                                       const char *name, void *opaque,
                                       Error **errp)
Signature · 1 line
2.13.6
#2 lore raw

[Qemu-devel] [PULL 2/5] iothread: provide helpers for internal use

In reply to Stefan Hajnoczi

From: Peter Xu <[email protected]>

IOThread is a general framework that contains IO loop environment and a real thread behind. It's also good to be used internally inside qemu. Provide some helpers for it to create iothreads to be used internally.

Put all the internal used iothreads into the internal object container.

Message-id: [email protected]

---
 include/sysemu/iothread.h |  8 ++++++++
 iothread.c                | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)
include/sysemu/iothread.h +8 -0
index d2985b30ba..b07663f0a1 100644
@@ -46,4 +46,12 @@ AioContext *iothread_get_aio_context(IOThread *iothread);
 void iothread_stop_all(void);
 GMainContext *iothread_get_g_main_context(IOThread *iothread);
 
+/*
+ * Helpers used to allocate iothreads for internal use.  These
+ * iothreads will not be seen by monitor clients when query using
+ * "query-iothreads".
+ */
+IOThread *iothread_create(const char *id, Error **errp);
+void iothread_destroy(IOThread *iothread);
+
 #endif /* IOTHREAD_H */
iothread.c +16 -0
index 59d0850988..0672a9196f 100644
@@ -354,3 +354,19 @@ GMainContext *iothread_get_g_main_context(IOThread *iothread)
 
     return iothread->worker_context;
 }
+
+IOThread *iothread_create(const char *id, Error **errp)
+{
+    Object *obj;
+
+    obj = object_new_with_props(TYPE_IOTHREAD,
+                                object_get_internal_root(),
+                                id, errp, NULL);
+
+    return IOTHREAD(obj);
+}
+
+void iothread_destroy(IOThread *iothread)
+{
+    object_unparent(OBJECT(iothread));
+}
Signature · 1 line
2.13.6
#3 lore raw

[Qemu-devel] [PULL 3/5] iothread: export iothread_stop()

In reply to Stefan Hajnoczi

From: Peter Xu <[email protected]>

So that internal iothread users can explicitly stop one iothread without destroying it.

Since at it, fix iothread_stop() to allow it to be called multiple times. Before this patch we may call iothread_stop() more than once on single iothread, while that may not be correct since qemu_thread_join() is not allowed to run twice. From manual of pthread_join():

Joining with a thread that has previously been joined results in undefined behavior.

Message-id: [email protected]

---
 include/sysemu/iothread.h |  1 +
 iothread.c                | 24 ++++++++++++++++--------
 2 files changed, 17 insertions(+), 8 deletions(-)
include/sysemu/iothread.h +1 -0
index b07663f0a1..110329b2b4 100644
@@ -52,6 +52,7 @@ GMainContext *iothread_get_g_main_context(IOThread *iothread);
  * "query-iothreads".
  */
 IOThread *iothread_create(const char *id, Error **errp);
+void iothread_stop(IOThread *iothread);
 void iothread_destroy(IOThread *iothread);
 
 #endif /* IOTHREAD_H */
iothread.c +16 -8
index 0672a9196f..b3c092b2d7 100644
@@ -80,13 +80,10 @@ static void *iothread_run(void *opaque)
     return NULL;
 }
 
-static int iothread_stop(Object *object, void *opaque)
+void iothread_stop(IOThread *iothread)
 {
-    IOThread *iothread;
-
-    iothread = (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD);
-    if (!iothread || !iothread->ctx || iothread->stopping) {
-        return 0;
+    if (!iothread->ctx || iothread->stopping) {
+        return;
     }
     iothread->stopping = true;
     aio_notify(iothread->ctx);
@@ -94,6 +91,17 @@ static int iothread_stop(Object *object, void *opaque)
         g_main_loop_quit(iothread->main_loop);
     }
     qemu_thread_join(&iothread->thread);
+}
+
+static int iothread_stop_iter(Object *object, void *opaque)
+{
+    IOThread *iothread;
+
+    iothread = (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD);
+    if (!iothread) {
+        return 0;
+    }
+    iothread_stop(iothread);
     return 0;
 }
 
@@ -108,7 +116,7 @@ static void iothread_instance_finalize(Object *obj)
 {
     IOThread *iothread = IOTHREAD(obj);
 
-    iothread_stop(obj, NULL);
+    iothread_stop(iothread);
     qemu_cond_destroy(&iothread->init_done_cond);
     qemu_mutex_destroy(&iothread->init_done_lock);
     if (!iothread->ctx) {
@@ -328,7 +336,7 @@ void iothread_stop_all(void)
         aio_context_release(ctx);
     }
 
-    object_child_foreach(container, iothread_stop, NULL);
+    object_child_foreach(container, iothread_stop_iter, NULL);
 }
 
 static gpointer iothread_g_main_context_init(gpointer opaque)
Signature · 1 line
2.13.6
#4 lore raw

[Qemu-devel] [PULL 4/5] iothread: delay the context release to finalize

In reply to Stefan Hajnoczi

From: Peter Xu <[email protected]>

When gcontext is used with iothread, the context will be destroyed during iothread_stop(). That's not good since sometimes we would like to keep the resources until iothread is destroyed, but we may want to stop the thread before that point.

Delay the destruction of gcontext to iothread finalize. Then we can do:

  iothread_stop(thread);
  some_cleanup_on_resources();
  iothread_destroy(thread);

We may need this patch if we want to run chardev IOs in iothreads and hopefully clean them up correctly. For more specific information, please see 2b316774f6 ("qemu-char: do not operate on sources from finalize callbacks").

Message-id: [email protected]

---
 iothread.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
iothread.c +4 -2
index b3c092b2d7..27a4288578 100644
@@ -71,8 +71,6 @@ static void *iothread_run(void *opaque)
             g_main_loop_unref(loop);
 
             g_main_context_pop_thread_default(iothread->worker_context);
-            g_main_context_unref(iothread->worker_context);
-            iothread->worker_context = NULL;
         }
     }
 
@@ -117,6 +115,10 @@ static void iothread_instance_finalize(Object *obj)
     IOThread *iothread = IOTHREAD(obj);
 
     iothread_stop(iothread);
+    if (iothread->worker_context) {
+        g_main_context_unref(iothread->worker_context);
+        iothread->worker_context = NULL;
+    }
     qemu_cond_destroy(&iothread->init_done_cond);
     qemu_mutex_destroy(&iothread->init_done_lock);
     if (!iothread->ctx) {
Signature · 1 line
2.13.6
#5 lore raw

[Qemu-devel] [PULL 5/5] aio: fix assert when remove poll during destroy

In reply to Stefan Hajnoczi

After iothread is enabled internally inside QEMU with GMainContext, we may encounter this warning when destroying the iothread:

(qemu-system-x86_64:19925): GLib-CRITICAL **: g_source_remove_poll:
assertion '!SOURCE_DESTROYED (source)' failed

The problem is that g_source_remove_poll() does not allow to remove one source from array if the source is detached from its owner context. (peterx: which IMHO does not make much sense)

Fix it on QEMU side by avoid calling g_source_remove_poll() if we know the object is during destruction, and we won't leak anything after all since the array will be gone soon cleanly even with that fd.

Message-id: [email protected]

[peterx: write the commit message]
---
 util/aio-posix.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
util/aio-posix.c +8 -1
index 2d51239ec6..5946ac09f0 100644
@@ -223,7 +223,14 @@ void aio_set_fd_handler(AioContext *ctx,
             return;
         }
 
-        g_source_remove_poll(&ctx->source, &node->pfd);
+        /* If the GSource is in the process of being destroyed then
+         * g_source_remove_poll() causes an assertion failure.  Skip
+         * removal in that case, because glib cleans up its state during
+         * destruction anyway.
+         */
+        if (!g_source_is_destroyed(&ctx->source)) {
+            g_source_remove_poll(&ctx->source, &node->pfd);
+        }
 
         /* If the lock is held, just mark the node as deleted */
         if (qemu_lockcnt_count(&ctx->list_lock)) {
Signature · 1 line
2.13.6
#6 lore raw
In reply to Stefan Hajnoczi
Quoted 6 lines · Stefan Hajnoczi

The following changes since commit d147f7e815f97cb477e223586bcb80c316ae10ea:

Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2017-10-03 16:27:24 +0100)

are available in the git repository at:

Quoted 8 lines

git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to f708a5e71cba0d784e307334c07ade5f56f827ab:

aio: fix assert when remove poll during destroy (2017-10-03 14:36:19 -0400)

----------------------------------------------------------------

Applied, thanks.

-- PMM