From patchwork Mon Jun 4 09:57:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 162764 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 D9FB8B7001 for ; Mon, 4 Jun 2012 21:46:38 +1000 (EST) Received: from localhost ([::1]:39236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbU4F-0001kT-UN for incoming@patchwork.ozlabs.org; Mon, 04 Jun 2012 05:59:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbU2v-0008Rl-Er for qemu-devel@nongnu.org; Mon, 04 Jun 2012 05:58:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbU2q-0004cF-Cj for qemu-devel@nongnu.org; Mon, 04 Jun 2012 05:57:57 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:46488) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbU2q-0004aQ-3S for qemu-devel@nongnu.org; Mon, 04 Jun 2012 05:57:52 -0400 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id C03834898A; Mon, 4 Jun 2012 18:57:45 +0900 (JST) Received: (nullmailer pid 5128 invoked by uid 1000); Mon, 04 Jun 2012 09:57:45 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org, kvm@vger.kernel.org Date: Mon, 4 Jun 2012 18:57:20 +0900 Message-Id: <1c1aca1d1b0f33a9609d43623dc1d37eae5c2440.1338802192.git.yamahata@valinux.co.jp> X-Mailer: git-send-email 1.7.1.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 210.128.90.3 Cc: benoit.hudzia@gmail.com, aarcange@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, t.hirofuchi@aist.go.jp, dlaor@redhat.com, satoshi.itoh@aist.go.jp, mdroth@linux.vnet.ibm.com, yoshikawa.takuya@oss.ntt.co.jp, owasserm@redhat.com, avi@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v2 18/41] QEMUFile: add qemu_file_fd() for later use 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: Isaku Yamahata --- qemu-file.h | 1 + savevm.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/qemu-file.h b/qemu-file.h index 331ac8b..98a8023 100644 --- a/qemu-file.h +++ b/qemu-file.h @@ -71,6 +71,7 @@ QEMUFile *qemu_fopen_socket(int fd); 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); +int qemu_file_fd(QEMUFile *f); void qemu_fflush(QEMUFile *f); void qemu_buffered_file_drain(QEMUFile *f); int qemu_fclose(QEMUFile *f); diff --git a/savevm.c b/savevm.c index fb47529..cba1a69 100644 --- a/savevm.c +++ b/savevm.c @@ -178,6 +178,7 @@ struct QEMUFile { uint8_t buf[IO_BUF_SIZE]; int last_error; + int fd; /* -1 means fd isn't associated */ }; typedef struct QEMUFileStdio @@ -276,6 +277,7 @@ QEMUFile *qemu_popen(FILE *stdio_file, const char *mode) s->file = qemu_fopen_ops(s, stdio_put_buffer, NULL, stdio_pclose, NULL, NULL, NULL); } + s->file->fd = fileno(stdio_file); return s->file; } @@ -291,6 +293,7 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode) return qemu_popen(popen_file, mode); } +/* TODO: replace this with qemu_file_fd() */ int qemu_stdio_fd(QEMUFile *f) { QEMUFileStdio *p; @@ -325,6 +328,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode) s->file = qemu_fopen_ops(s, stdio_put_buffer, NULL, stdio_fclose, NULL, NULL, NULL); } + s->file->fd = fd; return s->file; fail: @@ -339,6 +343,7 @@ QEMUFile *qemu_fopen_socket(int fd) s->fd = fd; s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL, NULL, NULL); + s->file->fd = fd; return s->file; } @@ -381,6 +386,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode) s->file = qemu_fopen_ops(s, NULL, file_get_buffer, stdio_fclose, NULL, NULL, NULL); } + s->file->fd = fileno(s->stdio_file); return s->file; fail: g_free(s); @@ -431,10 +437,16 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer, f->set_rate_limit = set_rate_limit; f->get_rate_limit = get_rate_limit; f->is_write = 0; + f->fd = -1; return f; } +int qemu_file_fd(QEMUFile *f) +{ + return f->fd; +} + int qemu_file_get_error(QEMUFile *f) { return f->last_error;