From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQu7R-0003C4-MX for qemu-devel@nongnu.org; Wed, 03 Feb 2016 04:53:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aQu7O-0005gq-D9 for qemu-devel@nongnu.org; Wed, 03 Feb 2016 04:53:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39412) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aQu7O-0005gi-5m for qemu-devel@nongnu.org; Wed, 03 Feb 2016 04:52:58 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id BFB0380505 for ; Wed, 3 Feb 2016 09:52:57 +0000 (UTC) Date: Wed, 3 Feb 2016 09:52:54 +0000 From: "Dr. David Alan Gilbert" Message-ID: <20160203095253.GA2376@work-vm> References: <1452599056-27357-1-git-send-email-berrange@redhat.com> <1452599056-27357-15-git-send-email-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1452599056-27357-15-git-send-email-berrange@redhat.com> Subject: Re: [Qemu-devel] [PATCH v1 14/22] migration: convert savevm to use QIOChannel for writing to files List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: Amit Shah , qemu-devel@nongnu.org, Juan Quintela * Daniel P. Berrange (berrange@redhat.com) wrote: > Convert the exec savevm code to use QIOChannel and QEMUFileChannel, > instead of the stdio APIs. > > Signed-off-by: Daniel P. Berrange Reviewed-by: Dr. David Alan Gilbert > --- > 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 f2e1880..e57d7ce 100644 > --- a/migration/savevm.c > +++ b/migration/savevm.c > @@ -51,6 +51,7 @@ > #include "block/snapshot.h" > #include "block/qapi.h" > #include "io/channel-buffer.h" > +#include "io/channel-file.h" > > > #ifndef ETH_P_RARP > @@ -1990,6 +1991,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; > > @@ -1997,11 +1999,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 5a1b25f..e8f759a 100644 > --- a/tests/Makefile > +++ b/tests/Makefile > @@ -423,8 +423,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 0f943d5..6bbda8a 100644 > --- a/tests/test-vmstate.c > +++ b/tests/test-vmstate.c > @@ -28,6 +28,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; > @@ -48,11 +49,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) \ > @@ -468,6 +475,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); > -- > 2.5.0 > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK