From patchwork Mon Mar 12 13:11:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 146101 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 E7D81B6FA8 for ; Tue, 13 Mar 2012 00:45:09 +1100 (EST) Received: from localhost ([::1]:48759 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S752y-0002IU-4i for incoming@patchwork.ozlabs.org; Mon, 12 Mar 2012 09:12:20 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S752l-0002Hw-TC for qemu-devel@nongnu.org; Mon, 12 Mar 2012 09:12:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S752c-0002UH-Kn for qemu-devel@nongnu.org; Mon, 12 Mar 2012 09:12:06 -0400 Received: from mail-ee0-f45.google.com ([74.125.83.45]:46114) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S752c-0002SZ-Bz for qemu-devel@nongnu.org; Mon, 12 Mar 2012 09:11:58 -0400 Received: by eeit10 with SMTP id t10so1280919eei.4 for ; Mon, 12 Mar 2012 06:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=BedZ1PFYMMNV2Iret07qb4Z5mnE5KX0RKPNHKERfEGk=; b=cOlzd1R8QjYJ4ZgS97Yxx4IiS2w8bt5oGNQpng+G1OIQvXxj+GuyKmCs6OILKYhEYy uVb3xs8WsM/FJW4+LDi+wCYHZRK/gNHmjJrHLo3nhJXkxKcWU5KGBYoNrxgzUdWVfbBk p7CkQPMjVa4nM96R46t1PnJ9CLSQlc060D+kBkOcc7JApAswrUTEi5+DQUtelxn6pWR9 Mvx8AMnV9SlTRK8qhAzHG249/U2Z1PKo9FhMn8gaO1neY999iQApkUiQzjis4ekps8HR RZ3fkZqobhd69d8dhGueKzLzTp4rrVD0EIPm13SWgHM+YxA+hODj/H3kwrQPBKEVYOt1 Pvuw== Received: by 10.213.108.77 with SMTP id e13mr985547ebp.11.1331557909863; Mon, 12 Mar 2012 06:11:49 -0700 (PDT) Received: from localhost (133.pool85-58-35.dynamic.orange.es. [85.58.35.133]) by mx.google.com with ESMTPS id r44sm12392965eef.2.2012.03.12.06.11.48 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 12 Mar 2012 06:11:49 -0700 (PDT) From: "=?UTF-8?q?Marc-Andr=C3=A9=20Lureau?=" To: qemu-devel@nongnu.org Date: Mon, 12 Mar 2012 14:11:28 +0100 Message-Id: <1331557893-30806-3-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1331557893-30806-1-git-send-email-marcandre.lureau@redhat.com> References: <1331557893-30806-1-git-send-email-marcandre.lureau@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.83.45 Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [Qemu-devel] [PATCH/RFC 2/7] Allow a qemu_fopen_socket() to be opened for writing 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 --- migration-tcp.c | 2 +- migration-unix.c | 2 +- qemu-file.h | 2 +- savevm.c | 36 ++++++++++++++++++++++++++++++++---- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/migration-tcp.c b/migration-tcp.c index 35a5781..f567898 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -140,7 +140,7 @@ static void tcp_accept_incoming_migration(void *opaque) goto out2; } - f = qemu_fopen_socket(c); + f = qemu_fopen_socket(c, "r"); if (f == NULL) { fprintf(stderr, "could not qemu_fopen socket\n"); goto out; diff --git a/migration-unix.c b/migration-unix.c index 169de88..3928f4c 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -137,7 +137,7 @@ static void unix_accept_incoming_migration(void *opaque) goto out2; } - f = qemu_fopen_socket(c); + f = qemu_fopen_socket(c, "r"); if (f == NULL) { fprintf(stderr, "could not qemu_fopen socket\n"); goto out; diff --git a/qemu-file.h b/qemu-file.h index 31b83f6..efd6b1c 100644 --- a/qemu-file.h +++ b/qemu-file.h @@ -67,7 +67,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, QEMUFileGetRateLimit *get_rate_limit); 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(FILE *popen_file, const char *mode); QEMUFile *qemu_popen_cmd(const char *command, const char *mode); int qemu_stdio_fd(QEMUFile *f); diff --git a/savevm.c b/savevm.c index 80be1ff..4171ebf 100644 --- a/savevm.c +++ b/savevm.c @@ -205,6 +205,21 @@ 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; + + do { + len = write(s->fd, buf, size); + } while (len == -1 && socket_error() == EINTR); + + if (len == -1) + len = -socket_error(); + + return len; +} + static int socket_close(void *opaque) { QEMUFileSocket *s = opaque; @@ -316,7 +331,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode) if (!s->stdio_file) goto fail; - if(mode[0] == 'r') { + if (mode[0] == 'r') { s->file = qemu_fopen_ops(s, NULL, stdio_get_buffer, stdio_fclose, NULL, NULL, NULL); } else { @@ -330,13 +345,26 @@ fail: return NULL; } -QEMUFile *qemu_fopen_socket(int fd) +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_socket: Argument validity check failed\n"); + return NULL; + } + s->fd = fd; - s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, - NULL, NULL, NULL); + if (mode[0] == 'r') { + s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, + NULL, NULL, NULL); + } else { + s->file = qemu_fopen_ops(s, socket_put_buffer, NULL, socket_close, + NULL, NULL, NULL); + } + return s->file; }