From patchwork Wed Apr 27 10:05:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 8954731 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 81F0F9F1D3 for ; Wed, 27 Apr 2016 10:28:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D109C2022A for ; Wed, 27 Apr 2016 10:28:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0930520142 for ; Wed, 27 Apr 2016 10:28:26 +0000 (UTC) Received: from localhost ([::1]:42432 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avMhl-0002xD-At for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Apr 2016 06:28:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48616) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avMM2-0005nl-3B for qemu-devel@nongnu.org; Wed, 27 Apr 2016 06:06:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avMLv-0004ZV-W4 for qemu-devel@nongnu.org; Wed, 27 Apr 2016 06:05:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40949) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avMLv-0004ZJ-Hc for qemu-devel@nongnu.org; Wed, 27 Apr 2016 06:05:51 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 423471A0EF9 for ; Wed, 27 Apr 2016 10:05:51 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-6-18.ams2.redhat.com [10.36.6.18]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3RA5MRR030816; Wed, 27 Apr 2016 06:05:50 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Wed, 27 Apr 2016 11:05:08 +0100 Message-Id: <1461751518-12128-19-git-send-email-berrange@redhat.com> In-Reply-To: <1461751518-12128-1-git-send-email-berrange@redhat.com> References: <1461751518-12128-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 for-2.7 18/28] migration: convert savevm to use QIOChannel for writing to files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amit Shah , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the exec savevm code to use QIOChannel and QEMUFileChannel, instead of the stdio APIs. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrange --- migration/savevm.c | 8 +++++--- tests/Makefile | 4 ++-- tests/test-vmstate.c | 11 ++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 06746d0..6fde687 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -51,6 +51,7 @@ #include "block/qapi.h" #include "qemu/cutils.h" #include "io/channel-buffer.h" +#include "io/channel-file.h" #ifndef ETH_P_RARP #define ETH_P_RARP 0x8035 @@ -2045,6 +2046,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) void qmp_xen_save_devices_state(const char *filename, Error **errp) { QEMUFile *f; + QIOChannelFile *ioc; int saved_vm_running; int ret; @@ -2052,11 +2054,11 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) vm_stop(RUN_STATE_SAVE_VM); global_state_store_running(); - f = qemu_fopen(filename, "wb"); - if (!f) { - error_setg_file_open(errp, errno, filename); + ioc = qio_channel_file_new_path(filename, O_WRONLY | O_CREAT, 0660, errp); + if (!ioc) { goto the_end; } + f = qemu_fopen_channel_output(QIO_CHANNEL(ioc)); ret = qemu_save_device_state(f); qemu_fclose(f); if (ret < 0) { diff --git a/tests/Makefile b/tests/Makefile index 797d59e..53b64b0 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -435,8 +435,8 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ $(test-qapi-obj-y) tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ migration/vmstate.o migration/qemu-file.o \ - migration/qemu-file-unix.o qjson.o \ - $(test-qom-obj-y) + migration/qemu-file-channel.o qjson.o \ + $(test-io-obj-y) tests/test-timed-average$(EXESUF): tests/test-timed-average.o qemu-timer.o \ $(test-util-obj-y) tests/test-base64$(EXESUF): tests/test-base64.o \ diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index f337cf6..d19b16a 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -29,6 +29,7 @@ #include "migration/migration.h" #include "migration/vmstate.h" #include "qemu/coroutine.h" +#include "io/channel-file.h" static char temp_file[] = "/tmp/vmst.test.XXXXXX"; static int temp_fd; @@ -49,11 +50,17 @@ void yield_until_fd_readable(int fd) static QEMUFile *open_test_file(bool write) { int fd = dup(temp_fd); + QIOChannel *ioc; lseek(fd, 0, SEEK_SET); if (write) { g_assert_cmpint(ftruncate(fd, 0), ==, 0); } - return qemu_fdopen(fd, write ? "wb" : "rb"); + ioc = QIO_CHANNEL(qio_channel_file_new_fd(fd)); + if (write) { + return qemu_fopen_channel_output(ioc); + } else { + return qemu_fopen_channel_input(ioc); + } } #define SUCCESS(val) \ @@ -469,6 +476,8 @@ int main(int argc, char **argv) { temp_fd = mkstemp(temp_file); + module_call_init(MODULE_INIT_QOM); + g_test_init(&argc, &argv, NULL); g_test_add_func("/vmstate/simple/primitive", test_simple_primitive); g_test_add_func("/vmstate/versioned/load/v1", test_load_v1);