From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ysw0E-0004ti-I4 for qemu-devel@nongnu.org; Thu, 14 May 2015 12:28:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ysw0D-0006cP-LA for qemu-devel@nongnu.org; Thu, 14 May 2015 12:28:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46962) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ysw0D-0006bz-DU for qemu-devel@nongnu.org; Thu, 14 May 2015 12:28:53 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4EGSqIP026343 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 14 May 2015 12:28:52 -0400 From: Juan Quintela Date: Thu, 14 May 2015 18:28:39 +0200 Message-Id: <1431620920-19710-9-git-send-email-quintela@redhat.com> In-Reply-To: <1431620920-19710-1-git-send-email-quintela@redhat.com> References: <1431620920-19710-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 8/9] vmstate: Create optional sections List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 ++ migration/vmstate.c | 11 +++++++++++ savevm.c | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index fc5e643..a8b59eb 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -813,6 +813,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, QJSON *vmdesc); +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/migration/vmstate.c b/migration/vmstate.c index 108995e..36dab84 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -276,6 +276,17 @@ static void vmsd_desc_field_end(const VMStateDescription *vmsd, QJSON *vmdesc, json_end_object(vmdesc); } + +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, QJSON *vmdesc) { diff --git a/savevm.c b/savevm.c index 01770cd..2b4e554 100644 --- a/savevm.c +++ b/savevm.c @@ -763,6 +763,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); json_start_object(vmdesc, NULL); -- 2.4.0