[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 3/3] virStream: Remove callbacks on Abort/Finish



Users need to remove their callbacks before calling virStreamAbort()
or virStreamFinish() even though that's not documented anywhere.
Since it makes no sense to keep those callbacks, we can remove them
when the stream is being aborted or finished.  That way it is also
more intuitive for developers as that removes some confusing errors
being reported.

Signed-off-by: Martin Kletzander <mkletzan redhat com>
---
 src/remote/remote_driver.c |  1 +
 src/util/virfdstream.c     | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 49909bf69747..0ab70a8761b5 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -5870,6 +5870,7 @@ remoteStreamCloseInt(virStreamPtr st, bool streamAbort)
     priv->localUses--;

  cleanup:
+    virNetClientStreamEventRemoveCallback(privst, true);
     virNetClientRemoveStream(priv->client, privst);
     virObjectUnref(privst);
     st->privateData = NULL;
diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c
index 7ee58be136d1..ac1f4a24d60e 100644
--- a/src/util/virfdstream.c
+++ b/src/util/virfdstream.c
@@ -721,6 +721,15 @@ virFDStreamCloseInt(virStreamPtr st, bool streamAbort)

     st->privateData = NULL;

+    if (fdst->watch)
+        virEventRemoveHandle(fdst->watch);
+
+    fdst->watch = 0;
+    fdst->ff = NULL;
+    fdst->cb = NULL;
+    fdst->events = 0;
+    fdst->opaque = NULL;
+
     /* call the internal stream closing callback */
     if (fdst->icbCb) {
         /* the mutex is not accessible anymore, as private data is null */
@@ -731,8 +740,11 @@ virFDStreamCloseInt(virStreamPtr st, bool streamAbort)

     if (fdst->dispatching) {
         fdst->closed = true;
+        fdst->cbRemoved = true;
         virObjectUnlock(fdst);
     } else {
+        if (fdst->ff)
+            (fdst->ff)(fdst->opaque);
         virObjectUnlock(fdst);
         virObjectUnref(fdst);
     }
-- 
2.13.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]