提交 0fe4aa14 编写于 作者: M Michal Privoznik

fdstream: Report error from the I/O thread

Problem with our error reporting is that the error object is a
thread local variable. That means if there's an error reported
within the I/O thread it gets logged and everything, but later
when the event loop aborts the stream it doesn't see the original
error. So we are left with some generic error. We can do better
if we copy the error message between the threads.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 3a2ca2fb
...@@ -231,17 +231,23 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque) ...@@ -231,17 +231,23 @@ daemonStreamEvent(virStreamPtr st, int events, void *opaque)
int ret; int ret;
virNetMessagePtr msg; virNetMessagePtr msg;
virNetMessageError rerr; virNetMessageError rerr;
virErrorPtr origErr = virSaveLastError();
memset(&rerr, 0, sizeof(rerr)); memset(&rerr, 0, sizeof(rerr));
stream->closed = true; stream->closed = true;
virStreamEventRemoveCallback(stream->st); virStreamEventRemoveCallback(stream->st);
virStreamAbort(stream->st); virStreamAbort(stream->st);
if (events & VIR_STREAM_EVENT_HANGUP) if (origErr && origErr->code != VIR_ERR_OK) {
virReportError(VIR_ERR_RPC, virSetError(origErr);
"%s", _("stream had unexpected termination")); virFreeError(origErr);
else } else {
virReportError(VIR_ERR_RPC, if (events & VIR_STREAM_EVENT_HANGUP)
"%s", _("stream had I/O failure")); virReportError(VIR_ERR_RPC,
"%s", _("stream had unexpected termination"));
else
virReportError(VIR_ERR_RPC,
"%s", _("stream had I/O failure"));
}
msg = virNetMessageNew(false); msg = virNetMessageNew(false);
if (!msg) { if (!msg) {
......
...@@ -106,7 +106,7 @@ struct virFDStreamData { ...@@ -106,7 +106,7 @@ struct virFDStreamData {
/* Thread data */ /* Thread data */
virThreadPtr thread; virThreadPtr thread;
virCond threadCond; virCond threadCond;
int threadErr; virErrorPtr threadErr;
bool threadQuit; bool threadQuit;
bool threadAbort; bool threadAbort;
bool threadDoRead; bool threadDoRead;
...@@ -123,6 +123,7 @@ virFDStreamDataDispose(void *obj) ...@@ -123,6 +123,7 @@ virFDStreamDataDispose(void *obj)
virFDStreamDataPtr fdst = obj; virFDStreamDataPtr fdst = obj;
VIR_DEBUG("obj=%p", fdst); VIR_DEBUG("obj=%p", fdst);
virFreeError(fdst->threadErr);
virFDStreamMsgQueueFree(&fdst->msg); virFDStreamMsgQueueFree(&fdst->msg);
} }
...@@ -312,8 +313,10 @@ static void virFDStreamEvent(int watch ATTRIBUTE_UNUSED, ...@@ -312,8 +313,10 @@ static void virFDStreamEvent(int watch ATTRIBUTE_UNUSED,
return; return;
} }
if (fdst->threadErr) if (fdst->threadErr) {
events |= VIR_STREAM_EVENT_ERROR; events |= VIR_STREAM_EVENT_ERROR;
virSetError(fdst->threadErr);
}
cb = fdst->cb; cb = fdst->cb;
cbopaque = fdst->opaque; cbopaque = fdst->opaque;
...@@ -641,7 +644,7 @@ virFDStreamThread(void *opaque) ...@@ -641,7 +644,7 @@ virFDStreamThread(void *opaque)
return; return;
error: error:
fdst->threadErr = errno; fdst->threadErr = virSaveLastError();
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册