提交 162cbbd1 编写于 作者: A Anthony Liguori

Merge remote-tracking branch 'luiz/queue/qmp' into staging

# By Stefan Hajnoczi
# Via Luiz Capitulino
* luiz/queue/qmp:
  chardev: clear O_NONBLOCK on SCM_RIGHTS file descriptors
  qemu-socket: set passed fd non-blocking in socket_connect()
  net: ensure "socket" backend uses non-blocking fds
  oslib-posix: rename socket_set_nonblock() to qemu_set_nonblock()
...@@ -415,7 +415,7 @@ static int nbd_establish_connection(BlockDriverState *bs) ...@@ -415,7 +415,7 @@ static int nbd_establish_connection(BlockDriverState *bs)
/* Now that we're connected, set the socket to be non-blocking and /* Now that we're connected, set the socket to be non-blocking and
* kick the reply mechanism. */ * kick the reply mechanism. */
socket_set_nonblock(sock); qemu_set_nonblock(sock);
qemu_aio_set_fd_handler(sock, nbd_reply_ready, NULL, qemu_aio_set_fd_handler(sock, nbd_reply_ready, NULL,
nbd_have_request, s); nbd_have_request, s);
......
...@@ -471,7 +471,7 @@ static int connect_to_sdog(BDRVSheepdogState *s) ...@@ -471,7 +471,7 @@ static int connect_to_sdog(BDRVSheepdogState *s)
qerror_report_err(err); qerror_report_err(err);
error_free(err); error_free(err);
} else { } else {
socket_set_nonblock(fd); qemu_set_nonblock(fd);
} }
return fd; return fd;
......
...@@ -37,8 +37,8 @@ int qemu_socket(int domain, int type, int protocol); ...@@ -37,8 +37,8 @@ int qemu_socket(int domain, int type, int protocol);
int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int socket_set_cork(int fd, int v); int socket_set_cork(int fd, int v);
int socket_set_nodelay(int fd); int socket_set_nodelay(int fd);
void socket_set_block(int fd); void qemu_set_block(int fd);
void socket_set_nonblock(int fd); void qemu_set_nonblock(int fd);
int send_all(int fd, const void *buf, int len1); int send_all(int fd, const void *buf, int len1);
int recv_all(int fd, void *buf, int len1, bool single_read); int recv_all(int fd, void *buf, int len1, bool single_read);
......
...@@ -121,7 +121,7 @@ void process_incoming_migration(QEMUFile *f) ...@@ -121,7 +121,7 @@ void process_incoming_migration(QEMUFile *f)
int fd = qemu_get_fd(f); int fd = qemu_get_fd(f);
assert(fd != -1); assert(fd != -1);
socket_set_nonblock(fd); qemu_set_nonblock(fd);
qemu_coroutine_enter(co, f); qemu_coroutine_enter(co, f);
} }
......
...@@ -386,7 +386,7 @@ static int nbd_send_negotiate(NBDClient *client) ...@@ -386,7 +386,7 @@ static int nbd_send_negotiate(NBDClient *client)
[28 .. 151] reserved (0) [28 .. 151] reserved (0)
*/ */
socket_set_block(csock); qemu_set_block(csock);
rc = -EINVAL; rc = -EINVAL;
TRACE("Beginning negotiation."); TRACE("Beginning negotiation.");
...@@ -429,7 +429,7 @@ static int nbd_send_negotiate(NBDClient *client) ...@@ -429,7 +429,7 @@ static int nbd_send_negotiate(NBDClient *client)
TRACE("Negotiation succeeded."); TRACE("Negotiation succeeded.");
rc = 0; rc = 0;
fail: fail:
socket_set_nonblock(csock); qemu_set_nonblock(csock);
return rc; return rc;
} }
...@@ -443,7 +443,7 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags, ...@@ -443,7 +443,7 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
TRACE("Receiving negotiation."); TRACE("Receiving negotiation.");
socket_set_block(csock); qemu_set_block(csock);
rc = -EINVAL; rc = -EINVAL;
if (read_sync(csock, buf, 8) != 8) { if (read_sync(csock, buf, 8) != 8) {
...@@ -558,7 +558,7 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags, ...@@ -558,7 +558,7 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags,
rc = 0; rc = 0;
fail: fail:
socket_set_nonblock(csock); qemu_set_nonblock(csock);
return rc; return rc;
} }
......
...@@ -308,7 +308,7 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr ...@@ -308,7 +308,7 @@ static int net_socket_mcast_create(struct sockaddr_in *mcastaddr, struct in_addr
} }
} }
socket_set_nonblock(fd); qemu_set_nonblock(fd);
return fd; return fd;
fail: fail:
if (fd >= 0) if (fd >= 0)
...@@ -519,7 +519,7 @@ static int net_socket_listen_init(NetClientState *peer, ...@@ -519,7 +519,7 @@ static int net_socket_listen_init(NetClientState *peer,
perror("socket"); perror("socket");
return -1; return -1;
} }
socket_set_nonblock(fd); qemu_set_nonblock(fd);
/* allow fast reuse */ /* allow fast reuse */
val = 1; val = 1;
...@@ -565,7 +565,7 @@ static int net_socket_connect_init(NetClientState *peer, ...@@ -565,7 +565,7 @@ static int net_socket_connect_init(NetClientState *peer,
perror("socket"); perror("socket");
return -1; return -1;
} }
socket_set_nonblock(fd); qemu_set_nonblock(fd);
connected = 0; connected = 0;
for(;;) { for(;;) {
...@@ -674,6 +674,7 @@ static int net_socket_udp_init(NetClientState *peer, ...@@ -674,6 +674,7 @@ static int net_socket_udp_init(NetClientState *peer,
closesocket(fd); closesocket(fd);
return -1; return -1;
} }
qemu_set_nonblock(fd);
s = net_socket_fd_init(peer, model, name, fd, 0); s = net_socket_fd_init(peer, model, name, fd, 0);
if (!s) { if (!s) {
...@@ -712,7 +713,11 @@ int net_init_socket(const NetClientOptions *opts, const char *name, ...@@ -712,7 +713,11 @@ int net_init_socket(const NetClientOptions *opts, const char *name,
int fd; int fd;
fd = monitor_handle_fd_param(cur_mon, sock->fd); fd = monitor_handle_fd_param(cur_mon, sock->fd);
if (fd == -1 || !net_socket_fd_init(peer, "socket", name, fd, 1)) { if (fd == -1) {
return -1;
}
qemu_set_nonblock(fd);
if (!net_socket_fd_init(peer, "socket", name, fd, 1)) {
return -1; return -1;
} }
return 0; return 0;
......
...@@ -2444,6 +2444,9 @@ static void unix_process_msgfd(CharDriverState *chr, struct msghdr *msg) ...@@ -2444,6 +2444,9 @@ static void unix_process_msgfd(CharDriverState *chr, struct msghdr *msg)
if (fd < 0) if (fd < 0)
continue; continue;
/* O_NONBLOCK is preserved across SCM_RIGHTS so reset it */
qemu_set_block(fd);
#ifndef MSG_CMSG_CLOEXEC #ifndef MSG_CMSG_CLOEXEC
qemu_set_cloexec(fd); qemu_set_cloexec(fd);
#endif #endif
...@@ -2574,7 +2577,7 @@ static int tcp_chr_add_client(CharDriverState *chr, int fd) ...@@ -2574,7 +2577,7 @@ static int tcp_chr_add_client(CharDriverState *chr, int fd)
if (s->fd != -1) if (s->fd != -1)
return -1; return -1;
socket_set_nonblock(fd); qemu_set_nonblock(fd);
if (s->do_nodelay) if (s->do_nodelay)
socket_set_nodelay(fd); socket_set_nodelay(fd);
s->fd = fd; s->fd = fd;
...@@ -2726,7 +2729,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay, ...@@ -2726,7 +2729,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay,
printf("QEMU waiting for connection on: %s\n", printf("QEMU waiting for connection on: %s\n",
chr->filename); chr->filename);
tcp_chr_accept(s->listen_chan, G_IO_IN, chr); tcp_chr_accept(s->listen_chan, G_IO_IN, chr);
socket_set_nonblock(s->listen_fd); qemu_set_nonblock(s->listen_fd);
} }
return chr; return chr;
} }
...@@ -2768,7 +2771,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts) ...@@ -2768,7 +2771,7 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
} }
if (!is_waitconnect) if (!is_waitconnect)
socket_set_nonblock(fd); qemu_set_nonblock(fd);
chr = qemu_chr_open_socket_fd(fd, do_nodelay, is_listen, is_telnet, chr = qemu_chr_open_socket_fd(fd, do_nodelay, is_listen, is_telnet,
is_waitconnect, &local_err); is_waitconnect, &local_err);
...@@ -3657,7 +3660,7 @@ static CharDriverState *qmp_chardev_open_serial(ChardevHostdev *serial, ...@@ -3657,7 +3660,7 @@ static CharDriverState *qmp_chardev_open_serial(ChardevHostdev *serial,
if (error_is_set(errp)) { if (error_is_set(errp)) {
return NULL; return NULL;
} }
socket_set_nonblock(fd); qemu_set_nonblock(fd);
return qemu_chr_open_tty_fd(fd); return qemu_chr_open_tty_fd(fd);
#else #else
error_setg(errp, "character device backend type 'serial' not supported"); error_setg(errp, "character device backend type 'serial' not supported");
......
...@@ -422,7 +422,7 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode) ...@@ -422,7 +422,7 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode)
s->fd = fd; s->fd = fd;
if (mode[0] == 'w') { if (mode[0] == 'w') {
socket_set_block(s->fd); qemu_set_block(s->fd);
s->file = qemu_fopen_ops(s, &socket_write_ops); s->file = qemu_fopen_ops(s, &socket_write_ops);
} else { } else {
s->file = qemu_fopen_ops(s, &socket_read_ops); s->file = qemu_fopen_ops(s, &socket_read_ops);
......
...@@ -215,7 +215,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty) ...@@ -215,7 +215,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
qemu_setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)); qemu_setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int));
opt = 1; opt = 1;
qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); qemu_setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int));
socket_set_nonblock(so->s); qemu_set_nonblock(so->s);
/* Append the telnet options now */ /* Append the telnet options now */
if (so->so_m != NULL && do_pty == 1) { if (so->so_m != NULL && do_pty == 1) {
......
...@@ -336,7 +336,7 @@ int tcp_fconnect(struct socket *so) ...@@ -336,7 +336,7 @@ int tcp_fconnect(struct socket *so)
int opt, s=so->s; int opt, s=so->s;
struct sockaddr_in addr; struct sockaddr_in addr;
socket_set_nonblock(s); qemu_set_nonblock(s);
opt = 1; opt = 1;
qemu_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); qemu_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
opt = 1; opt = 1;
...@@ -425,7 +425,7 @@ void tcp_connect(struct socket *inso) ...@@ -425,7 +425,7 @@ void tcp_connect(struct socket *inso)
tcp_close(sototcpcb(so)); /* This will sofree() as well */ tcp_close(sototcpcb(so)); /* This will sofree() as well */
return; return;
} }
socket_set_nonblock(s); qemu_set_nonblock(s);
opt = 1; opt = 1;
qemu_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)); qemu_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int));
opt = 1; opt = 1;
......
...@@ -2732,7 +2732,7 @@ static void vnc_connect(VncDisplay *vd, int csock, int skipauth, bool websocket) ...@@ -2732,7 +2732,7 @@ static void vnc_connect(VncDisplay *vd, int csock, int skipauth, bool websocket)
VNC_DEBUG("New client on socket %d\n", csock); VNC_DEBUG("New client on socket %d\n", csock);
vd->dcl.idle = 0; vd->dcl.idle = 0;
socket_set_nonblock(vs->csock); qemu_set_nonblock(vs->csock);
#ifdef CONFIG_VNC_WS #ifdef CONFIG_VNC_WS
if (websocket) { if (websocket) {
vs->websocket = 1; vs->websocket = 1;
......
...@@ -134,14 +134,14 @@ void qemu_vfree(void *ptr) ...@@ -134,14 +134,14 @@ void qemu_vfree(void *ptr)
free(ptr); free(ptr);
} }
void socket_set_block(int fd) void qemu_set_block(int fd)
{ {
int f; int f;
f = fcntl(fd, F_GETFL); f = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, f & ~O_NONBLOCK); fcntl(fd, F_SETFL, f & ~O_NONBLOCK);
} }
void socket_set_nonblock(int fd) void qemu_set_nonblock(int fd)
{ {
int f; int f;
f = fcntl(fd, F_GETFL); f = fcntl(fd, F_GETFL);
......
...@@ -100,14 +100,14 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) ...@@ -100,14 +100,14 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
return p; return p;
} }
void socket_set_block(int fd) void qemu_set_block(int fd)
{ {
unsigned long opt = 0; unsigned long opt = 0;
WSAEventSelect(fd, NULL, 0); WSAEventSelect(fd, NULL, 0);
ioctlsocket(fd, FIONBIO, &opt); ioctlsocket(fd, FIONBIO, &opt);
} }
void socket_set_nonblock(int fd) void qemu_set_nonblock(int fd)
{ {
unsigned long opt = 1; unsigned long opt = 1;
ioctlsocket(fd, FIONBIO, &opt); ioctlsocket(fd, FIONBIO, &opt);
......
...@@ -277,7 +277,7 @@ static int inet_connect_addr(struct addrinfo *addr, bool *in_progress, ...@@ -277,7 +277,7 @@ static int inet_connect_addr(struct addrinfo *addr, bool *in_progress,
} }
qemu_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); qemu_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
if (connect_state != NULL) { if (connect_state != NULL) {
socket_set_nonblock(sock); qemu_set_nonblock(sock);
} }
/* connect to peer */ /* connect to peer */
do { do {
...@@ -737,7 +737,7 @@ int unix_connect_opts(QemuOpts *opts, Error **errp, ...@@ -737,7 +737,7 @@ int unix_connect_opts(QemuOpts *opts, Error **errp,
connect_state = g_malloc0(sizeof(*connect_state)); connect_state = g_malloc0(sizeof(*connect_state));
connect_state->callback = callback; connect_state->callback = callback;
connect_state->opaque = opaque; connect_state->opaque = opaque;
socket_set_nonblock(sock); qemu_set_nonblock(sock);
} }
memset(&un, 0, sizeof(un)); memset(&un, 0, sizeof(un));
...@@ -910,6 +910,7 @@ int socket_connect(SocketAddress *addr, Error **errp, ...@@ -910,6 +910,7 @@ int socket_connect(SocketAddress *addr, Error **errp,
case SOCKET_ADDRESS_KIND_FD: case SOCKET_ADDRESS_KIND_FD:
fd = monitor_get_fd(cur_mon, addr->fd->str, errp); fd = monitor_get_fd(cur_mon, addr->fd->str, errp);
if (callback) { if (callback) {
qemu_set_nonblock(fd);
callback(fd, opaque); callback(fd, opaque);
} }
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册