From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeJQj-0003JO-W4 for qemu-devel@nongnu.org; Wed, 15 Oct 2014 03:55:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeJQd-0006ze-R0 for qemu-devel@nongnu.org; Wed, 15 Oct 2014 03:55:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeJQd-0006zW-Gs for qemu-devel@nongnu.org; Wed, 15 Oct 2014 03:55:27 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9F7tQEx032410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 15 Oct 2014 03:55:27 -0400 From: Juan Quintela Date: Wed, 15 Oct 2014 09:55:10 +0200 Message-Id: <1413359710-2799-8-git-send-email-quintela@redhat.com> In-Reply-To: <1413359710-2799-1-git-send-email-quintela@redhat.com> References: <1413359710-2799-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 7/7] vmstate: Create optional sections List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, laine@redhat.com, lcapitulino@redhat.com To make sections optional, we need to do it at the beggining of the code. Signed-off-by: Juan Quintela --- include/migration/vmstate.h | 2 ++ savevm.c | 4 ++++ vmstate.c | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 3556924..a5155be 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -766,6 +766,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque); +bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); + int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, void *base, int alias_id, diff --git a/savevm.c b/savevm.c index eed43e6..3884e0b 100644 --- a/savevm.c +++ b/savevm.c @@ -727,6 +727,10 @@ void qemu_savevm_state_complete(QEMUFile *f) if ((!se->ops || !se->ops->save_state) && !se->vmsd) { continue; } + if (se->vmsd && !vmstate_save_needed(se->vmsd, se->opaque)) { + continue; + } + trace_savevm_section_start(se->idstr, se->section_id); /* Section type */ qemu_put_byte(f, QEMU_VM_SECTION_FULL); diff --git a/vmstate.c b/vmstate.c index bb02b7d..b8914ac 100644 --- a/vmstate.c +++ b/vmstate.c @@ -131,6 +131,17 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, return 0; } + +bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque) +{ + if (vmsd->needed && !vmsd->needed(opaque)) { + /* optional section not needed */ + return false; + } + return true; +} + + void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque) { -- 2.1.0