]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virfdstream: Check for thread error more frequently
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 29 May 2017 14:29:11 +0000 (16:29 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 11 Jul 2017 06:40:13 +0000 (08:40 +0200)
When the I/O thread quits (e.g. due to an I/O error, lseek()
error, whatever), any subsequent virFDStream API should return
error too. Moreover, when invoking stream event callback, we must
set the VIR_STREAM_EVENT_ERROR flag so that the callback knows
something bad happened.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/util/virfdstream.c

index ae6f78e01217912a2ce595407d9842f6d73de300..bd2355d17f1122d52d9f39a3148eb5e41b9bb04f 100644 (file)
@@ -312,6 +312,9 @@ static void virFDStreamEvent(int watch ATTRIBUTE_UNUSED,
         return;
     }
 
+    if (fdst->threadErr)
+        events |= VIR_STREAM_EVENT_ERROR;
+
     cb = fdst->cb;
     cbopaque = fdst->opaque;
     ff = fdst->ff;
@@ -791,10 +794,10 @@ static int virFDStreamWrite(virStreamPtr st, const char *bytes, size_t nbytes)
     if (fdst->thread) {
         char *buf;
 
-        if (fdst->threadQuit) {
+        if (fdst->threadQuit || fdst->threadErr) {
             virReportSystemError(EBADF, "%s",
                                  _("cannot write to stream"));
-            return -1;
+            goto cleanup;
         }
 
         if (VIR_ALLOC(msg) < 0 ||
@@ -870,7 +873,7 @@ static int virFDStreamRead(virStreamPtr st, char *bytes, size_t nbytes)
         virFDStreamMsgPtr msg = NULL;
 
         while (!(msg = fdst->msg)) {
-            if (fdst->threadQuit) {
+            if (fdst->threadQuit || fdst->threadErr) {
                 if (nbytes) {
                     virReportSystemError(EBADF, "%s",
                                          _("stream is not open"));
@@ -971,6 +974,13 @@ virFDStreamSendHole(virStreamPtr st,
          * the thread to do the lseek() for us. Under no
          * circumstances we can do the lseek() ourselves here. We
          * might mess up file position for the thread. */
+
+        if (fdst->threadQuit || fdst->threadErr) {
+            virReportSystemError(EBADF, "%s",
+                                 _("stream is not open"));
+            goto cleanup;
+        }
+
         if (fdst->threadDoRead) {
             msg = fdst->msg;
             if (msg->type != VIR_FDSTREAM_MSG_TYPE_HOLE) {
@@ -1025,6 +1035,9 @@ virFDStreamInData(virStreamPtr st,
     if (fdst->thread) {
         virFDStreamMsgPtr msg;
 
+        if (fdst->threadErr)
+            goto cleanup;
+
         while (!(msg = fdst->msg)) {
             if (fdst->threadQuit) {
                 *inData = *length = 0;