From: "Denis V. Lunev" <den@openvz.org>
Cc: Michael Roth <mdroth@linux.vnet.ibm.com>,
Olga Krishtal <okrishtal@parallels.com>,
Stefan Weil <sw@weilnetz.de>,
qemu-devel@nongnu.org, "Denis V. Lunev" <den@openvz.org>
Subject: [Qemu-devel] [PATCH 3/3] qga: set file descriptor in qmp_guest_file_open non-blocking on Win32
Date: Wed, 28 Oct 2015 18:13:57 +0300 [thread overview]
Message-ID: <1446045237-19532-4-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1446045237-19532-1-git-send-email-den@openvz.org>
From: Olga Krishtal <okrishtal@parallels.com>
Set fd non-blocking to avoid common use cases (like reading from a
named pipe) from hanging the agent. This was missed in the original
code.
The patch introduces qemu_set_handle_nonoblocking, the local analog
of qemu_set_nonblock for HANDLES.
The usage of handles in qemu_set_non/block is impossible, because for
win32 there is a difference between file discriptors and file handles,
and all file ops are made via Win32 api.
Signed-off-by: Olga Krishtal <okrishtal@parallels.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Michael Roth <mdroth@linux.vnet.ibm.com>
CC: Stefan Weil <sw@weilnetz.de>
---
qga/commands-win32.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 97f19d5..a5306e7 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -128,6 +128,28 @@ static GuestFileHandle *guest_file_handle_find(int64_t id, Error **errp)
return NULL;
}
+static void handle_set_nonblocking(HANDLE fh)
+{
+ DWORD file_type, pipe_state;
+ file_type = GetFileType(fh);
+ if (file_type != FILE_TYPE_PIPE) {
+ return;
+ }
+ /* If file_type == FILE_TYPE_PIPE, according to MSDN
+ * the specified file is socket or named pipe */
+ if (!GetNamedPipeHandleState(fh, &pipe_state, NULL,
+ NULL, NULL, NULL, 0)) {
+ return;
+ }
+ /* The fd is named pipe fd */
+ if (pipe_state & PIPE_NOWAIT) {
+ return;
+ }
+
+ pipe_state |= PIPE_NOWAIT;
+ SetNamedPipeHandleState(fh, &pipe_state, NULL, NULL);
+}
+
int64_t qmp_guest_file_open(const char *path, bool has_mode,
const char *mode, Error **errp)
{
@@ -158,6 +180,11 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode,
return -1;
}
+ /* set fd non-blocking to avoid common use cases (like reading from a
+ * named pipe) from hanging the agent
+ */
+ handle_set_nonblocking(fh);
+
fd = guest_file_handle_add(fh, errp);
if (fd < 0) {
CloseHandle(fh);
--
2.1.4
next prev parent reply other threads:[~2015-10-28 15:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-28 15:13 [Qemu-devel] [PATCH v4 for 2.5 0/3] qga: non-blocking fd cleanups Denis V. Lunev
2015-10-28 15:13 ` [Qemu-devel] [PATCH 1/3] qga: drop hand-made guest_file_toggle_flags helper Denis V. Lunev
2015-10-28 15:13 ` [Qemu-devel] [PATCH 2/3] qga: fixed CloseHandle in qmp_guest_file_open Denis V. Lunev
2015-10-28 15:13 ` Denis V. Lunev [this message]
2015-10-29 20:09 ` [Qemu-devel] [PATCH v4 for 2.5 0/3] qga: non-blocking fd cleanups Michael Roth
-- strict thread matches above, loose matches on Subject: below --
2015-10-27 17:48 [Qemu-devel] [PATCH v3 " Denis V. Lunev
2015-10-27 17:48 ` [Qemu-devel] [PATCH 3/3] qga: set file descriptor in qmp_guest_file_open non-blocking on Win32 Denis V. Lunev
2015-10-27 19:11 ` Michael Roth
2015-10-27 19:13 ` Denis V. Lunev
2015-10-27 19:49 ` Michael Roth
2015-10-28 15:18 ` Denis V. Lunev
2015-10-27 19:14 ` Michael Roth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1446045237-19532-4-git-send-email-den@openvz.org \
--to=den@openvz.org \
--cc=mdroth@linux.vnet.ibm.com \
--cc=okrishtal@parallels.com \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).