diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2012-10-24 09:39:49 -0500 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-10-24 09:39:49 -0500 |
commit | c6b8141b84e1b80eff1f04e2a5feb38decae65d8 (patch) | |
tree | 0be44fcd574751487e2e4bb932897881a2ee0966 /migration-unix.c | |
parent | a8170e5e97ad17ca169c64ba87ae2f53850dab4c (diff) | |
parent | 6dd844db4a49a367cc15cd0e8bfb72cfc6652766 (diff) | |
download | qemu-c6b8141b84e1b80eff1f04e2a5feb38decae65d8.zip qemu-c6b8141b84e1b80eff1f04e2a5feb38decae65d8.tar.gz qemu-c6b8141b84e1b80eff1f04e2a5feb38decae65d8.tar.bz2 |
Merge remote-tracking branch 'bonzini/nbd-next' into staging
* bonzini/nbd-next: (30 commits)
qmp: add NBD server commands
block: add close notifiers
block: prepare code for adding block notifiers
qemu-sockets: add socket_listen, socket_connect, socket_parse
tests: do not include tools-obj-y Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-sockets: return InetSocketAddress from inet_parse
qapi: add socket address types
build: add QAPI files to the tools
vnc: drop QERR_VNC_SERVER_FAILED
qemu-sockets: add error propagation to Unix socket functions
qemu-sockets: add error propagation to inet_parse
qemu-sockets: add error propagation to inet_dgram_opts
qemu-sockets: add error propagation to inet_connect_addr
qemu-sockets: include strerror or gai_strerror output in error messages
vnc: add error propagation to vnc_display_open
vnc: reorganize code for reverse mode
vnc: introduce a single label for error returns
vnc: avoid Yoda conditionals
qemu-ga: ask and print error information from qemu-sockets
nbd: ask and print error information from qemu-sockets
...
Diffstat (limited to 'migration-unix.c')
-rw-r--r-- | migration-unix.c | 95 |
1 files changed, 13 insertions, 82 deletions
diff --git a/migration-unix.c b/migration-unix.c index 169de88..ed3db3a 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -53,69 +53,28 @@ static int unix_close(MigrationState *s) return r; } -static void unix_wait_for_connect(void *opaque) +static void unix_wait_for_connect(int fd, void *opaque) { MigrationState *s = opaque; - int val, ret; - socklen_t valsize = sizeof(val); - DPRINTF("connect completed\n"); - do { - ret = getsockopt(s->fd, SOL_SOCKET, SO_ERROR, (void *) &val, &valsize); - } while (ret == -1 && errno == EINTR); - - if (ret < 0) { + if (fd < 0) { + DPRINTF("migrate connect error\n"); + s->fd = -1; migrate_fd_error(s); - return; - } - - qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); - - if (val == 0) + } else { + DPRINTF("migrate connect success\n"); + s->fd = fd; migrate_fd_connect(s); - else { - DPRINTF("error connecting %d\n", val); - migrate_fd_error(s); } } -int unix_start_outgoing_migration(MigrationState *s, const char *path) +void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp) { - struct sockaddr_un addr; - int ret; - - addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); s->get_error = unix_errno; s->write = unix_write; s->close = unix_close; - s->fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0); - if (s->fd == -1) { - DPRINTF("Unable to open socket"); - return -errno; - } - - socket_set_nonblock(s->fd); - - do { - ret = connect(s->fd, (struct sockaddr *)&addr, sizeof(addr)); - if (ret == -1) { - ret = -errno; - } - if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) { - qemu_set_fd_handler2(s->fd, NULL, NULL, unix_wait_for_connect, s); - return 0; - } - } while (ret == -EINTR); - - if (ret < 0) { - DPRINTF("connect failed\n"); - migrate_fd_error(s); - return ret; - } - migrate_fd_connect(s); - return 0; + s->fd = unix_nonblocking_connect(path, unix_wait_for_connect, s, errp); } static void unix_accept_incoming_migration(void *opaque) @@ -152,43 +111,15 @@ out2: close(s); } -int unix_start_incoming_migration(const char *path) +void unix_start_incoming_migration(const char *path, Error **errp) { - struct sockaddr_un addr; int s; - int ret; - - DPRINTF("Attempting to start an incoming migration\n"); - - s = qemu_socket(PF_UNIX, SOCK_STREAM, 0); - if (s == -1) { - fprintf(stderr, "Could not open unix socket: %s\n", strerror(errno)); - return -errno; - } - - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); - unlink(addr.sun_path); - if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) { - ret = -errno; - fprintf(stderr, "bind(unix:%s): %s\n", addr.sun_path, strerror(errno)); - goto err; - } - if (listen(s, 1) == -1) { - fprintf(stderr, "listen(unix:%s): %s\n", addr.sun_path, - strerror(errno)); - ret = -errno; - goto err; + s = unix_listen(path, NULL, 0, errp); + if (s < 0) { + return; } qemu_set_fd_handler2(s, NULL, unix_accept_incoming_migration, NULL, (void *)(intptr_t)s); - - return 0; - -err: - close(s); - return ret; } |