From patchwork Fri Feb 15 17:47:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 220808 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5C4302C007C for ; Sat, 16 Feb 2013 05:53:32 +1100 (EST) Received: from localhost ([::1]:48143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6QPa-0003xB-L6 for incoming@patchwork.ozlabs.org; Fri, 15 Feb 2013 13:53:30 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6POn-00074y-VE for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U6POk-0004Sg-VP for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:37 -0500 Received: from mail-ve0-f182.google.com ([209.85.128.182]:47313) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6POk-0004SY-RY for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:34 -0500 Received: by mail-ve0-f182.google.com with SMTP id ox1so3305934veb.13 for ; Fri, 15 Feb 2013 09:48:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=jcXJp+c7YSIRSY5CZZ+28iCrGTRMqvhTxDYizQzh9mY=; b=W9z37gDGACmDE/nXvs50yv4m0oKMUnxjx4zha6OftXmETlactfFsJIhUuLvjRWWbz/ G2hTLjATSYMVuR+VT+IFh/C6/WtiW3eH8IaF+2p0lf0HdCVqa5deFvF8N2A53Dz3FZ8S Xx3Eiw2YoM3OloIOGyBMNvsm4JA/rzVQo1CPcKi5cGTs4NKAffDKyn3Cr0xDbGXfhEfp RwrqEqzClwScO53cBauohm7WMn8SFYavJ9vShdahOPbYnJbI/aEproO91sZk+XUOtfLh 3aZPQwcCfrS6dxlkr7tsDlM5aWGUmlDLCDYwmuDE4dkLsqLLU1MnJGOz8yzyN1TH75lC fvsg== X-Received: by 10.52.35.129 with SMTP id h1mr3792308vdj.74.1360950514451; Fri, 15 Feb 2013 09:48:34 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id yu12sm65402142vec.6.2013.02.15.09.48.32 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 15 Feb 2013 09:48:33 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 15 Feb 2013 18:47:04 +0100 Message-Id: <1360950433-17106-33-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360950433-17106-1-git-send-email-pbonzini@redhat.com> References: <1360950433-17106-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.128.182 Cc: owasserm@redhat.com, chegu_vinod@hp.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 32/41] qemu-file: add writable socket QEMUFile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Paolo Bonzini --- include/migration/qemu-file.h | 2 +- migration-tcp.c | 2 +- migration-unix.c | 2 +- savevm.c | 33 +++++++++++++++++++++++++++++++-- util/osdep.c | 6 +++++- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index 987e719..25e8461 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -76,7 +76,7 @@ typedef struct QEMUFileOps { QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops); QEMUFile *qemu_fopen(const char *filename, const char *mode); QEMUFile *qemu_fdopen(int fd, const char *mode); -QEMUFile *qemu_fopen_socket(int fd); +QEMUFile *qemu_fopen_socket(int fd, const char *mode); QEMUFile *qemu_popen_cmd(const char *command, const char *mode); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); diff --git a/migration-tcp.c b/migration-tcp.c index e78a296..7d975b5 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -95,7 +95,7 @@ static void tcp_accept_incoming_migration(void *opaque) goto out; } - f = qemu_fopen_socket(c); + f = qemu_fopen_socket(c, "rb"); if (f == NULL) { fprintf(stderr, "could not qemu_fopen socket\n"); goto out; diff --git a/migration-unix.c b/migration-unix.c index 218835a..4693b43 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -95,7 +95,7 @@ static void unix_accept_incoming_migration(void *opaque) goto out; } - f = qemu_fopen_socket(c); + f = qemu_fopen_socket(c, "rb"); if (f == NULL) { fprintf(stderr, "could not qemu_fopen socket\n"); goto out; diff --git a/savevm.c b/savevm.c index f593acd..b6cf415 100644 --- a/savevm.c +++ b/savevm.c @@ -198,6 +198,18 @@ static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) return len; } +static int socket_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) +{ + QEMUFileSocket *s = opaque; + ssize_t len; + + len = qemu_send_full(s->fd, buf, size, 0); + if (len == -1) { + len = -socket_error(); + } + return len; +} + static int socket_close(void *opaque) { QEMUFileSocket *s = opaque; @@ -369,12 +381,29 @@ static const QEMUFileOps socket_read_ops = { .close = socket_close }; -QEMUFile *qemu_fopen_socket(int fd) +static const QEMUFileOps socket_write_ops = { + .get_fd = socket_get_fd, + .put_buffer = socket_put_buffer, + .close = socket_close +}; + +QEMUFile *qemu_fopen_socket(int fd, const char *mode) { QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket)); + if (mode == NULL || + (mode[0] != 'r' && mode[0] != 'w') || + mode[1] != 'b' || mode[2] != 0) { + fprintf(stderr, "qemu_fopen: Argument validity check failed\n"); + return NULL; + } + s->fd = fd; - s->file = qemu_fopen_ops(s, &socket_read_ops); + if (mode[0] == 'w') { + s->file = qemu_fopen_ops(s, &socket_write_ops); + } else { + s->file = qemu_fopen_ops(s, &socket_read_ops); + } return s->file; } diff --git a/util/osdep.c b/util/osdep.c index 5b51a03..be168e5 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -243,8 +243,12 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count) while (count) { ret = write(fd, buf, count); if (ret < 0) { - if (errno == EINTR) + if (errno == EINTR) { continue; + } + if (total == 0) { + total = ret; + } break; }