From nobody Sun Apr 28 10:49:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576759765; cv=none; d=zohomail.com; s=zohoarc; b=hVJQFia3vh1V6NeTgZhqpq47q8EKCof5TD+5g+eBgcxVsucKAyJD0XHl2ksgYPZifiKr9uPxvnGUl1cc/hgg7iBS/SHbklV3O/Lv4hrcJ9sBVleoeJDafYnqgEgbmK04sHV9MsBajHNAzc53gSw5hfDOTRussAawjRuS3mx7zx4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576759765; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vCHO9ERRT5i+5ymbnbgqq02uxG5UeMhV/3W94nXH/tI=; b=LmI19FX5NfIUJIYd4o4ql0xD+b7eiCJaD/VcCwkQpoeurrJTJhlqYI76iwcDfgcQDmAnUYAKosNRDR1O3k6VXAtnMhLSiSGiYk7lIFflaaOo0AUwWZPQoMvZ3I6qUCduu0IUFW4c90JwlPyaCyf2wpjpSOK/Fl+1n1DZ+PhUeWQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576759765172106.52012236016958; Thu, 19 Dec 2019 04:49:25 -0800 (PST) Received: from localhost ([::1]:40394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihvF4-0006PD-PH for importer@patchew.org; Thu, 19 Dec 2019 07:49:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40371) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihuxS-000897-Uv for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihuxR-0000Am-Bj for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:10 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:45637 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihuxR-00006X-5H for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:09 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-332-5-A2r3TON5qRRAEoeuz4PQ-1; Thu, 19 Dec 2019 07:31:04 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E479D800D41 for ; Thu, 19 Dec 2019 12:31:03 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id E449D5C1B0; Thu, 19 Dec 2019 12:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576758668; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vCHO9ERRT5i+5ymbnbgqq02uxG5UeMhV/3W94nXH/tI=; b=RJncbNz/VF5Q5xJNEUhg5b4QXJZQSSXgDlfWEx6HIzBKYJPcqobdvlA2EwFGKCV4Z6u6m/ Hqth++dT/1DFp4GvOHDIegjFB3j6onUHhkCfaEVtme/QtlwFlOJZQjsYkK1crThgpiryEu Nw64K6HYLkfq+L1a8R9FTMHeCe1Psao= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v7 1/9] vmstate: add qom interface to get id Date: Thu, 19 Dec 2019 16:30:21 +0400 Message-Id: <20191219123029.200788-2-marcandre.lureau@redhat.com> In-Reply-To: <20191219123029.200788-1-marcandre.lureau@redhat.com> References: <20191219123029.200788-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 5-A2r3TON5qRRAEoeuz4PQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add an interface to get the instance id, instead of depending on Device and qdev_get_dev_path(). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Acked-by: Dr. David Alan Gilbert --- MAINTAINERS | 2 ++ hw/core/Makefile.objs | 1 + hw/core/qdev.c | 14 +++++++++++++ hw/core/vmstate-if.c | 23 +++++++++++++++++++++ include/hw/vmstate-if.h | 40 ++++++++++++++++++++++++++++++++++++ include/migration/register.h | 2 ++ include/migration/vmstate.h | 2 ++ tests/Makefile.include | 1 + 8 files changed, 85 insertions(+) create mode 100644 hw/core/vmstate-if.c create mode 100644 include/hw/vmstate-if.h diff --git a/MAINTAINERS b/MAINTAINERS index 740401bcbb..7a0ea36717 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2194,6 +2194,8 @@ Migration M: Juan Quintela M: Dr. David Alan Gilbert S: Maintained +F: hw/core/vmstate-if.c +F: include/hw/vmstate-if.h F: include/migration/ F: migration/ F: scripts/vmstate-static-checker.py diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index fd0550d1d9..0edd9e635d 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -9,6 +9,7 @@ common-obj-y +=3D hotplug.o common-obj-$(CONFIG_SOFTMMU) +=3D nmi.o common-obj-$(CONFIG_SOFTMMU) +=3D vm-change-state-handler.o common-obj-y +=3D cpu.o +common-obj-y +=3D vmstate-if.o =20 common-obj-$(CONFIG_EMPTY_SLOT) +=3D empty_slot.o common-obj-$(CONFIG_XILINX_AXI) +=3D stream.o diff --git a/hw/core/qdev.c b/hw/core/qdev.c index cf1ba28fe3..add43d460e 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -1089,9 +1089,18 @@ static void device_unparent(Object *obj) } } =20 +static char * +device_vmstate_if_get_id(VMStateIf *obj) +{ + DeviceState *dev =3D DEVICE(obj); + + return qdev_get_dev_path(dev); +} + static void device_class_init(ObjectClass *class, void *data) { DeviceClass *dc =3D DEVICE_CLASS(class); + VMStateIfClass *vc =3D VMSTATE_IF_CLASS(class); =20 class->unparent =3D device_unparent; =20 @@ -1103,6 +1112,7 @@ static void device_class_init(ObjectClass *class, voi= d *data) */ dc->hotpluggable =3D true; dc->user_creatable =3D true; + vc->get_id =3D device_vmstate_if_get_id; } =20 void device_class_set_parent_reset(DeviceClass *dc, @@ -1160,6 +1170,10 @@ static const TypeInfo device_type_info =3D { .class_init =3D device_class_init, .abstract =3D true, .class_size =3D sizeof(DeviceClass), + .interfaces =3D (InterfaceInfo[]) { + { TYPE_VMSTATE_IF }, + { } + } }; =20 static void qdev_register_types(void) diff --git a/hw/core/vmstate-if.c b/hw/core/vmstate-if.c new file mode 100644 index 0000000000..bf453620fe --- /dev/null +++ b/hw/core/vmstate-if.c @@ -0,0 +1,23 @@ +/* + * VMState interface + * + * Copyright (c) 2009-2019 Red Hat Inc + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/vmstate-if.h" + +static const TypeInfo vmstate_if_info =3D { + .name =3D TYPE_VMSTATE_IF, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(VMStateIfClass), +}; + +static void vmstate_register_types(void) +{ + type_register_static(&vmstate_if_info); +} + +type_init(vmstate_register_types); diff --git a/include/hw/vmstate-if.h b/include/hw/vmstate-if.h new file mode 100644 index 0000000000..8ff7f0f292 --- /dev/null +++ b/include/hw/vmstate-if.h @@ -0,0 +1,40 @@ +/* + * VMState interface + * + * Copyright (c) 2009-2019 Red Hat Inc + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef VMSTATE_IF_H +#define VMSTATE_IF_H + +#include "qom/object.h" + +#define TYPE_VMSTATE_IF "vmstate-if" + +#define VMSTATE_IF_CLASS(klass) \ + OBJECT_CLASS_CHECK(VMStateIfClass, (klass), TYPE_VMSTATE_IF) +#define VMSTATE_IF_GET_CLASS(obj) \ + OBJECT_GET_CLASS(VMStateIfClass, (obj), TYPE_VMSTATE_IF) +#define VMSTATE_IF(obj) \ + INTERFACE_CHECK(VMStateIf, (obj), TYPE_VMSTATE_IF) + +typedef struct VMStateIf VMStateIf; + +typedef struct VMStateIfClass { + InterfaceClass parent_class; + + char * (*get_id)(VMStateIf *obj); +} VMStateIfClass; + +static inline char *vmstate_if_get_id(VMStateIf *vmif) +{ + if (!vmif) { + return NULL; + } + + return VMSTATE_IF_GET_CLASS(vmif)->get_id(vmif); +} + +#endif /* VMSTATE_IF_H */ diff --git a/include/migration/register.h b/include/migration/register.h index a13359a08d..73149c9a01 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -14,6 +14,8 @@ #ifndef MIGRATION_REGISTER_H #define MIGRATION_REGISTER_H =20 +#include "hw/vmstate-if.h" + typedef struct SaveVMHandlers { /* This runs inside the iothread lock. */ SaveStateHandler *save_state; diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index ac4f46a67d..f546f61c5e 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -27,6 +27,8 @@ #ifndef QEMU_VMSTATE_H #define QEMU_VMSTATE_H =20 +#include "hw/vmstate-if.h" + typedef struct VMStateInfo VMStateInfo; typedef struct VMStateField VMStateField; =20 diff --git a/tests/Makefile.include b/tests/Makefile.include index b381387048..fa4140cbde 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -579,6 +579,7 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-= global-props.o \ hw/core/irq.o \ hw/core/fw-path-provider.o \ hw/core/reset.o \ + hw/core/vmstate-if.o \ $(test-qapi-obj-y) tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ migration/vmstate.o migration/vmstate-types.o migration/qemu-file.o \ --=20 2.24.0.308.g228f53135a From nobody Sun Apr 28 10:49:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576760916; cv=none; d=zohomail.com; s=zohoarc; b=BHFa2cMYKa5E3rMJl9QQQDWewAyS91L5FW1mD7mbEvmPxD0wkkLoemaX8SkecLpA/SRYhRutqIAR+irWokAo7eJuqx30ze7QWZt6OnCJATNTY74uBGcbmCOV3wlUNLFHk1c+t/78OHJHiI10DB8hY2vxGoguueHWtvxoTg2HAUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576760916; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YovsefqkDCb88PowQRGU4k8V5ag/mFw+4KdGkVx8ejg=; b=h0DDrlor9l7U31FoFIkpRpdJXi1joyfuITnsAYwqPC6fqO2ZxZxC9LbAutH/6/8RyevWOe58KLCE3lqCPmOmY3mTZwqgpOGu1o05t55reG9NTQObJpvwLLkadDInIq1DKalq36hWV95nKp566Y6Kfjlw8p+iQDqmUxke9JOXe/o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576760916730632.4054029503426; Thu, 19 Dec 2019 05:08:36 -0800 (PST) Received: from localhost ([::1]:40740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihvXf-0007wq-GJ for importer@patchew.org; Thu, 19 Dec 2019 08:08:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42028) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihuxn-0008Sp-7H for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihuxk-0001M4-Oa for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:31 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:28530 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihuxk-0001Jl-FS for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:28 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-130-xwMBMz7BMCy2PWeApPauKA-1; Thu, 19 Dec 2019 07:31:21 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 68C06184BEC0 for ; Thu, 19 Dec 2019 12:31:20 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51DFF1001281; Thu, 19 Dec 2019 12:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576758686; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YovsefqkDCb88PowQRGU4k8V5ag/mFw+4KdGkVx8ejg=; b=g/N1v3XKOKm/fcz2LIKSWoNHnNNmCxkxajUCsEbfOqB7/hnBSIt6gAbFw9eGxG/vS9+BBq QQvb68hzpS70UZrqwzGhvcYNrQlBxzivN3J94hxMaWJ19CC0Y8JiiVR4GsgSMSlNcc5u/L 0rAlQj6C+lLsb24KWm7+Q7kV/XDXzh8= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v7 2/9] vmstate: replace DeviceState with VMStateIf Date: Thu, 19 Dec 2019 16:30:22 +0400 Message-Id: <20191219123029.200788-3-marcandre.lureau@redhat.com> In-Reply-To: <20191219123029.200788-1-marcandre.lureau@redhat.com> References: <20191219123029.200788-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: xwMBMz7BMCy2PWeApPauKA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Replace DeviceState dependency with VMStateIf on vmstate API. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Acked-by: Halil Pasic --- hw/block/onenand.c | 2 +- hw/core/qdev.c | 7 ++++--- hw/ide/cmd646.c | 2 +- hw/ide/isa.c | 2 +- hw/ide/piix.c | 2 +- hw/ide/via.c | 2 +- hw/misc/max111x.c | 2 +- hw/net/eepro100.c | 4 ++-- hw/net/virtio-net.c | 3 ++- hw/nvram/eeprom93xx.c | 4 ++-- hw/ppc/spapr_drc.c | 9 +++++---- hw/ppc/spapr_iommu.c | 4 ++-- hw/s390x/s390-skeys.c | 2 +- include/migration/register.h | 2 +- include/migration/vmstate.h | 8 ++++---- migration/savevm.c | 20 ++++++++++---------- stubs/vmstate.c | 4 ++-- 17 files changed, 41 insertions(+), 38 deletions(-) diff --git a/hw/block/onenand.c b/hw/block/onenand.c index fcc5a69b90..9c233c12e4 100644 --- a/hw/block/onenand.c +++ b/hw/block/onenand.c @@ -822,7 +822,7 @@ static void onenand_realize(DeviceState *dev, Error **e= rrp) onenand_mem_setup(s); sysbus_init_irq(sbd, &s->intr); sysbus_init_mmio(sbd, &s->container); - vmstate_register(dev, + vmstate_register(VMSTATE_IF(dev), ((s->shift & 0x7f) << 24) | ((s->id.man & 0xff) << 16) | ((s->id.dev & 0xff) << 8) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index add43d460e..fadc01f622 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -890,7 +890,8 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) dev->canonical_path =3D object_get_canonical_path(OBJECT(dev)); =20 if (qdev_get_vmsd(dev)) { - if (vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev)= , dev, + if (vmstate_register_with_alias_id(VMSTATE_IF(dev), + -1, qdev_get_vmsd(dev), dev, dev->instance_id_alias, dev->alias_required_for_ver= sion, &local_err) < 0) { @@ -925,7 +926,7 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) local_errp); } if (qdev_get_vmsd(dev)) { - vmstate_unregister(dev, qdev_get_vmsd(dev), dev); + vmstate_unregister(VMSTATE_IF(dev), qdev_get_vmsd(dev), dev); } if (dc->unrealize) { local_errp =3D local_err ? NULL : &local_err; @@ -949,7 +950,7 @@ child_realize_fail: } =20 if (qdev_get_vmsd(dev)) { - vmstate_unregister(dev, qdev_get_vmsd(dev), dev); + vmstate_unregister(VMSTATE_IF(dev), qdev_get_vmsd(dev), dev); } =20 post_realize_fail: diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c index 19984d2af9..3f9be968d1 100644 --- a/hw/ide/cmd646.c +++ b/hw/ide/cmd646.c @@ -302,7 +302,7 @@ static void pci_cmd646_ide_realize(PCIDevice *dev, Erro= r **errp) } g_free(irq); =20 - vmstate_register(DEVICE(dev), 0, &vmstate_ide_pci, d); + vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d); qemu_register_reset(cmd646_reset, d); } =20 diff --git a/hw/ide/isa.c b/hw/ide/isa.c index 7b6e283679..9c7f88b2d5 100644 --- a/hw/ide/isa.c +++ b/hw/ide/isa.c @@ -75,7 +75,7 @@ static void isa_ide_realizefn(DeviceState *dev, Error **e= rrp) ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2); isa_init_irq(isadev, &s->irq, s->isairq); ide_init2(&s->bus, s->irq); - vmstate_register(dev, 0, &vmstate_ide_isa, s); + vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_isa, s); ide_register_restart_cb(&s->bus); } =20 diff --git a/hw/ide/piix.c b/hw/ide/piix.c index db313dd3b1..bc575b4d70 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -156,7 +156,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error = **errp) bmdma_setup_bar(d); pci_register_bar(dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &d->bmdma_bar); =20 - vmstate_register(DEVICE(dev), 0, &vmstate_ide_pci, d); + vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d); =20 pci_piix_init_ports(d); } diff --git a/hw/ide/via.c b/hw/ide/via.c index 053622bd82..096de8dba0 100644 --- a/hw/ide/via.c +++ b/hw/ide/via.c @@ -190,7 +190,7 @@ static void via_ide_realize(PCIDevice *dev, Error **err= p) bmdma_setup_bar(d); pci_register_bar(dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &d->bmdma_bar); =20 - vmstate_register(DEVICE(dev), 0, &vmstate_ide_pci, d); + vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d); =20 for (i =3D 0; i < 2; i++) { ide_bus_new(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2); diff --git a/hw/misc/max111x.c b/hw/misc/max111x.c index a713149f16..211008ce02 100644 --- a/hw/misc/max111x.c +++ b/hw/misc/max111x.c @@ -146,7 +146,7 @@ static int max111x_init(SSISlave *d, int inputs) s->input[7] =3D 0x80; s->com =3D 0; =20 - vmstate_register(dev, -1, &vmstate_max111x, s); + vmstate_register(VMSTATE_IF(dev), -1, &vmstate_max111x, s); return 0; } =20 diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index cc2dd8b1c9..cc71a7a036 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -1815,7 +1815,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev) { EEPRO100State *s =3D DO_UPCAST(EEPRO100State, dev, pci_dev); =20 - vmstate_unregister(&pci_dev->qdev, s->vmstate, s); + vmstate_unregister(VMSTATE_IF(&pci_dev->qdev), s->vmstate, s); g_free(s->vmstate); eeprom93xx_free(&pci_dev->qdev, s->eeprom); qemu_del_nic(s->nic); @@ -1874,7 +1874,7 @@ static void e100_nic_realize(PCIDevice *pci_dev, Erro= r **errp) =20 s->vmstate =3D g_memdup(&vmstate_eepro100, sizeof(vmstate_eepro100)); s->vmstate->name =3D qemu_get_queue(s->nic)->model; - vmstate_register(&pci_dev->qdev, -1, s->vmstate, s); + vmstate_register(VMSTATE_IF(&pci_dev->qdev), -1, s->vmstate, s); } =20 static void eepro100_instance_init(Object *obj) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index db3d7c38e6..777d62d3c8 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2853,7 +2853,8 @@ static void virtio_net_handle_migration_primary(VirtI= ONet *n, =20 if (migration_in_setup(s) && !should_be_hidden) { if (failover_unplug_primary(n)) { - vmstate_unregister(n->primary_dev, qdev_get_vmsd(n->primary_de= v), + vmstate_unregister(VMSTATE_IF(n->primary_dev), + qdev_get_vmsd(n->primary_dev), n->primary_dev); qapi_event_send_unplug_primary(n->primary_device_id); atomic_set(&n->primary_should_be_hidden, true); diff --git a/hw/nvram/eeprom93xx.c b/hw/nvram/eeprom93xx.c index 5b01b9b03f..07f09549ed 100644 --- a/hw/nvram/eeprom93xx.c +++ b/hw/nvram/eeprom93xx.c @@ -321,7 +321,7 @@ eeprom_t *eeprom93xx_new(DeviceState *dev, uint16_t nwo= rds) /* Output DO is tristate, read results in 1. */ eeprom->eedo =3D 1; logout("eeprom =3D 0x%p, nwords =3D %u\n", eeprom, nwords); - vmstate_register(dev, 0, &vmstate_eeprom, eeprom); + vmstate_register(VMSTATE_IF(dev), 0, &vmstate_eeprom, eeprom); return eeprom; } =20 @@ -329,7 +329,7 @@ void eeprom93xx_free(DeviceState *dev, eeprom_t *eeprom) { /* Destroy EEPROM. */ logout("eeprom =3D 0x%p\n", eeprom); - vmstate_unregister(dev, &vmstate_eeprom, eeprom); + vmstate_unregister(VMSTATE_IF(dev), &vmstate_eeprom, eeprom); g_free(eeprom); } =20 diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 62f1a42592..17aeac3801 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -511,7 +511,7 @@ static void realize(DeviceState *d, Error **errp) error_propagate(errp, err); return; } - vmstate_register(DEVICE(drc), spapr_drc_index(drc), &vmstate_spapr_drc, + vmstate_register(VMSTATE_IF(drc), spapr_drc_index(drc), &vmstate_spapr= _drc, drc); trace_spapr_drc_realize_complete(spapr_drc_index(drc)); } @@ -523,7 +523,7 @@ static void unrealize(DeviceState *d, Error **errp) gchar *name; =20 trace_spapr_drc_unrealize(spapr_drc_index(drc)); - vmstate_unregister(DEVICE(drc), &vmstate_spapr_drc, drc); + vmstate_unregister(VMSTATE_IF(drc), &vmstate_spapr_drc, drc); root_container =3D container_get(object_get_root(), DRC_CONTAINER_PATH= ); name =3D g_strdup_printf("%x", spapr_drc_index(drc)); object_property_del(root_container, name, errp); @@ -619,7 +619,8 @@ static void realize_physical(DeviceState *d, Error **er= rp) return; } =20 - vmstate_register(DEVICE(drcp), spapr_drc_index(SPAPR_DR_CONNECTOR(drcp= )), + vmstate_register(VMSTATE_IF(drcp), + spapr_drc_index(SPAPR_DR_CONNECTOR(drcp)), &vmstate_spapr_drc_physical, drcp); qemu_register_reset(drc_physical_reset, drcp); } @@ -635,7 +636,7 @@ static void unrealize_physical(DeviceState *d, Error **= errp) return; } =20 - vmstate_unregister(DEVICE(drcp), &vmstate_spapr_drc_physical, drcp); + vmstate_unregister(VMSTATE_IF(drcp), &vmstate_spapr_drc_physical, drcp= ); qemu_unregister_reset(drc_physical_reset, drcp); } =20 diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index 3d3bcc8649..5704fe6051 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -317,7 +317,7 @@ static void spapr_tce_table_realize(DeviceState *dev, E= rror **errp) =20 QLIST_INSERT_HEAD(&spapr_tce_tables, tcet, list); =20 - vmstate_register(DEVICE(tcet), tcet->liobn, &vmstate_spapr_tce_table, + vmstate_register(VMSTATE_IF(tcet), tcet->liobn, &vmstate_spapr_tce_tab= le, tcet); } =20 @@ -420,7 +420,7 @@ static void spapr_tce_table_unrealize(DeviceState *dev,= Error **errp) { SpaprTceTable *tcet =3D SPAPR_TCE_TABLE(dev); =20 - vmstate_unregister(DEVICE(tcet), &vmstate_spapr_tce_table, tcet); + vmstate_unregister(VMSTATE_IF(tcet), &vmstate_spapr_tce_table, tcet); =20 QLIST_REMOVE(tcet, list); =20 diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index bd37f39120..5da6e5292f 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -392,7 +392,7 @@ static inline void s390_skeys_set_migration_enabled(Obj= ect *obj, bool value, register_savevm_live(TYPE_S390_SKEYS, 0, 1, &savevm_s390_storage_keys, ss); } else { - unregister_savevm(DEVICE(ss), TYPE_S390_SKEYS, ss); + unregister_savevm(VMSTATE_IF(ss), TYPE_S390_SKEYS, ss); } } =20 diff --git a/include/migration/register.h b/include/migration/register.h index 73149c9a01..00c38ebe9f 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -76,6 +76,6 @@ int register_savevm_live(const char *idstr, const SaveVMHandlers *ops, void *opaque); =20 -void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque); +void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque); =20 #endif diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index f546f61c5e..4aef72c426 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -1158,22 +1158,22 @@ int vmstate_save_state_v(QEMUFile *f, const VMState= Description *vmsd, bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque); =20 /* Returns: 0 on success, -1 on failure */ -int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, +int vmstate_register_with_alias_id(VMStateIf *obj, int instance_id, const VMStateDescription *vmsd, void *base, int alias_id, int required_for_version, Error **errp); =20 /* Returns: 0 on success, -1 on failure */ -static inline int vmstate_register(DeviceState *dev, int instance_id, +static inline int vmstate_register(VMStateIf *obj, int instance_id, const VMStateDescription *vmsd, void *opaque) { - return vmstate_register_with_alias_id(dev, instance_id, vmsd, + return vmstate_register_with_alias_id(obj, instance_id, vmsd, opaque, -1, 0, NULL); } =20 -void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, +void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, void *opaque); =20 struct MemoryRegion; diff --git a/migration/savevm.c b/migration/savevm.c index a71b930b91..59efc1981d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -760,17 +760,17 @@ int register_savevm_live(const char *idstr, return 0; } =20 -void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) +void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque) { SaveStateEntry *se, *new_se; char id[256] =3D ""; =20 - if (dev) { - char *path =3D qdev_get_dev_path(dev); - if (path) { - pstrcpy(id, sizeof(id), path); + if (obj) { + char *oid =3D vmstate_if_get_id(obj); + if (oid) { + pstrcpy(id, sizeof(id), oid); pstrcat(id, sizeof(id), "/"); - g_free(path); + g_free(oid); } } pstrcat(id, sizeof(id), idstr); @@ -784,7 +784,7 @@ void unregister_savevm(DeviceState *dev, const char *id= str, void *opaque) } } =20 -int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, +int vmstate_register_with_alias_id(VMStateIf *obj, int instance_id, const VMStateDescription *vmsd, void *opaque, int alias_id, int required_for_version, @@ -802,8 +802,8 @@ int vmstate_register_with_alias_id(DeviceState *dev, in= t instance_id, se->vmsd =3D vmsd; se->alias_id =3D alias_id; =20 - if (dev) { - char *id =3D qdev_get_dev_path(dev); + if (obj) { + char *id =3D vmstate_if_get_id(obj); if (id) { if (snprintf(se->idstr, sizeof(se->idstr), "%s/", id) >=3D sizeof(se->idstr)) { @@ -834,7 +834,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, in= t instance_id, return 0; } =20 -void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, +void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, void *opaque) { SaveStateEntry *se, *new_se; diff --git a/stubs/vmstate.c b/stubs/vmstate.c index e1e89b87f0..6951d9fdc5 100644 --- a/stubs/vmstate.c +++ b/stubs/vmstate.c @@ -3,7 +3,7 @@ =20 const VMStateDescription vmstate_dummy =3D {}; =20 -int vmstate_register_with_alias_id(DeviceState *dev, +int vmstate_register_with_alias_id(VMStateIf *obj, int instance_id, const VMStateDescription *vmsd, void *base, int alias_id, @@ -13,7 +13,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, return 0; } =20 -void vmstate_unregister(DeviceState *dev, +void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, void *opaque) { --=20 2.24.0.308.g228f53135a From nobody Sun Apr 28 10:49:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576761002; cv=none; d=zohomail.com; s=zohoarc; b=CgjLHguD29NpxafAgoHcW+z0cU18k2R55VVgGu9QMJYYRp46KYZqYe4BDBmlZT/FgURFa3/kpspc1dGiRwBeVBUWdb3Zow2+GToYNhHHo+wSXXrDxafZQR/Nlg0QTtNCvfLgdxSLC1lQowudLTU4zo7QEsnyhyeDCT+Jqd1F0mo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576761002; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Y++G7l9YxmyK7LTiAQUSGkOErlXqcbNeqr+OEtZGre8=; b=GloKXSiAMzcrXnoFsZ10nbsJ6GzOt7kGU9CsMTBanpMdcjO246rxIfC2WIV7iGy/v6CiE7EqhmXMSMk9Y1ooR/RN7biJdzg+ZrzL2dFmcfgLVVm8qhVUDffRTBFiMHW3HOgdXmrMUYcnv5ljzf4neFV0tGDsgm6r0stdYm4sF9c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576761002109484.84761010549414; Thu, 19 Dec 2019 05:10:02 -0800 (PST) Received: from localhost ([::1]:40754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihvZ1-0001KA-Oh for importer@patchew.org; Thu, 19 Dec 2019 08:10:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42973) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihuxw-0000Cy-9q for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihuxu-00027W-Gn for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:40 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:44847 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihuxu-00023f-9c for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-75-2SFsEnBKNOW64kPv6U0j7Q-1; Thu, 19 Dec 2019 07:31:32 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE617184BEC0 for ; Thu, 19 Dec 2019 12:31:31 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D56060BC7; Thu, 19 Dec 2019 12:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576758697; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y++G7l9YxmyK7LTiAQUSGkOErlXqcbNeqr+OEtZGre8=; b=DZ1TN/NapZwDLFPAFn446vfJFTHjRXctBHy70JdVKDtg8RGs2UJzLeGM0WKSkLBTP7gOhC 9xOnt8c83nr8f3EXeTo5VmAPYrbz3EZLU6YeE0zXP/3sas/sBljGHcxG3pzbxnqeZJOLSN SfMCaSIQqpMdJFAiiN7z3SFydBmz6Dc= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v7 3/9] docs: start a document to describe D-Bus usage Date: Thu, 19 Dec 2019 16:30:23 +0400 Message-Id: <20191219123029.200788-4-marcandre.lureau@redhat.com> In-Reply-To: <20191219123029.200788-1-marcandre.lureau@redhat.com> References: <20191219123029.200788-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 2SFsEnBKNOW64kPv6U0j7Q-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- MAINTAINERS | 5 ++ docs/interop/dbus.rst | 105 +++++++++++++++++++++++++++++++++++++++++ docs/interop/index.rst | 1 + 3 files changed, 111 insertions(+) create mode 100644 docs/interop/dbus.rst diff --git a/MAINTAINERS b/MAINTAINERS index 7a0ea36717..c0faf5377d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2204,6 +2204,11 @@ F: tests/migration-test.c F: docs/devel/migration.rst F: qapi/migration.json =20 +D-Bus +M: Marc-Andr=C3=A9 Lureau +S: Maintained +F: docs/interop/dbus.rst + Seccomp M: Eduardo Otubo S: Supported diff --git a/docs/interop/dbus.rst b/docs/interop/dbus.rst new file mode 100644 index 0000000000..ef80d4204d --- /dev/null +++ b/docs/interop/dbus.rst @@ -0,0 +1,105 @@ +=3D=3D=3D=3D=3D +D-Bus +=3D=3D=3D=3D=3D + +Introduction +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +QEMU may be running with various helper processes involved: + - vhost-user* processes (gpu, virtfs, input, etc...) + - TPM emulation (or other devices) + - user networking (slirp) + - network services (DHCP/DNS, samba/ftp etc) + - background tasks (compression, streaming etc) + - client UI + - admin & cli + +Having several processes allows stricter security rules, as well as +greater modularity. + +While QEMU itself uses QMP as primary IPC (and Spice/VNC for remote +display), D-Bus is the de facto IPC of choice on Unix systems. The +wire format is machine friendly, good bindings exist for various +languages, and there are various tools available. + +Using a bus, helper processes can discover and communicate with each +other easily, without going through QEMU. The bus topology is also +easier to apprehend and debug than a mesh. However, it is wise to +consider the security aspects of it. + +Security +=3D=3D=3D=3D=3D=3D=3D=3D + +A QEMU D-Bus bus should be private to a single VM. Thus, only +cooperative tasks are running on the same bus to serve the VM. + +D-Bus, the protocol and standard, doesn't have mechanisms to enforce +security between peers once the connection is established. Peers may +have additional mechanisms to enforce security rules, based for +example on UNIX credentials. + +The daemon can control which peers can send/recv messages using +various metadata attributes, however, this is alone is not generally +sufficient to make the deployment secure. The semantics of the actual +methods implemented using D-Bus are just as critical. Peers need to +carefully validate any information they received from a peer with a +different trust level. + +dbus-daemon policy +------------------ + +dbus-daemon can enforce various policies based on the UID/GID of the +processes that are connected to it. It is thus a good idea to run +helpers as different UID from QEMU and set appropriate policies. + +Depending on the use case, you may choose different scenarios: + + - Everything the same UID + + - Convenient for developers + - Improved reliability - crash of one part doens't take + out entire VM + - No security benefit over traditional QEMU, unless additional + unless additional controls such as SELinux or AppArmor are + applied + + - Two UIDs, one for QEMU, one for dbus & helpers + + - Moderately improved user based security isolation + + - Many UIDs, one for QEMU one for dbus and one for each helpers + + - Best user based security isolation + - Complex to manager distinct UIDs needed for each VM + +For example, to allow only ``qemu`` user to talk to ``qemu-helper`` +``org.qemu.Helper1`` service, a dbus-daemon policy may contain: + +.. code:: xml + + + + + + + + + + + +dbus-daemon can also perfom SELinux checks based on the security +context of the source and the target. For example, ``virtiofs_t`` +could be allowed to send a message to ``svirt_t``, but ``virtiofs_t`` +wouldn't be allowed to send a message to ``virtiofs_t``. + +See dbus-daemon man page for details. + +Guidelines +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +When implementing new D-Bus interfaces, it is recommended to follow +the "D-Bus API Design Guidelines": +https://dbus.freedesktop.org/doc/dbus-api-design.html + +The "org.qemu.*" prefix is reserved for services implemented & +distributed by the QEMU project. diff --git a/docs/interop/index.rst b/docs/interop/index.rst index 3e33fb5933..ded134ea75 100644 --- a/docs/interop/index.rst +++ b/docs/interop/index.rst @@ -13,6 +13,7 @@ Contents: :maxdepth: 2 =20 bitmaps + dbus live-block-operations pr-helper qemu-ga --=20 2.24.0.308.g228f53135a From nobody Sun Apr 28 10:49:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576761125; cv=none; d=zohomail.com; s=zohoarc; b=MtvzxdLieamBR9nBskEkjaU/T3jc6rIVjBz0NaQB9zMIIM3xCGdPyPkdle1zhXynBEFUX/szWPYCCScgPHZui1I45+gJUUmWxxa1Io5jRRmnu9afERHzKTVk/jcTM91pmh9BejRFSv54Ua+r68iApipJmrh5XDmBlsPxcvAE004= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576761125; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d1NwnKNFRuuxevU3nGqbAtAHtU1cIvtea8ojJXVOLbw=; b=lpujIhStAa3KP8m2jquc2vq1V5bG5n4cTDpNq1N7MLeygmqu8TmQ6r3JT6BuBsFIh2vJFohaLvu0rI6BFy6TbvBYJyavbBeW4HkRhVRxBo72jKibnN4kvb4hCBqFturZ6kfeyG2b4xpLtED5pMU6zPn77U2wP+9SqhS0a2wanX0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576761125921156.26155576259555; Thu, 19 Dec 2019 05:12:05 -0800 (PST) Received: from localhost ([::1]:40876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihvaz-0004BS-Vc for importer@patchew.org; Thu, 19 Dec 2019 08:12:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43874) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihuy3-0000PT-QA for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihuy2-0002re-GN for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:47 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20075 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihuy2-0002oP-AK for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:31:46 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-115-AsHM7xG4NVuFyG0icI_ngw-1; Thu, 19 Dec 2019 07:31:42 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2B3A184BEC5 for ; Thu, 19 Dec 2019 12:31:41 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 203B463B8E; Thu, 19 Dec 2019 12:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576758705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d1NwnKNFRuuxevU3nGqbAtAHtU1cIvtea8ojJXVOLbw=; b=HGnAqT1EbN56wvfmQtL+9P7kJZ0Kv6jRLiiC//O8Yjia+/TZCOxpRD0eG2qyKnbtte5Tck eGBOZPTFhv9pSGrAjRkbiCEnjPzg1CCb+hvIC96YRiIJC8nZ4Ek71SSiEDRiqvLM+pWZTn z7O7DyzWWJr5GAbsAoL7zaRAciEDeZY= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v7 4/9] util: add dbus helper unit Date: Thu, 19 Dec 2019 16:30:24 +0400 Message-Id: <20191219123029.200788-5-marcandre.lureau@redhat.com> In-Reply-To: <20191219123029.200788-1-marcandre.lureau@redhat.com> References: <20191219123029.200788-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: AsHM7xG4NVuFyG0icI_ngw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- MAINTAINERS | 2 ++ include/qemu/dbus.h | 19 +++++++++++++++ util/Makefile.objs | 3 +++ util/dbus.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 include/qemu/dbus.h create mode 100644 util/dbus.c diff --git a/MAINTAINERS b/MAINTAINERS index c0faf5377d..9c03214693 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2207,6 +2207,8 @@ F: qapi/migration.json D-Bus M: Marc-Andr=C3=A9 Lureau S: Maintained +F: util/dbus.c +F: include/qemu/dbus.h F: docs/interop/dbus.rst =20 Seccomp diff --git a/include/qemu/dbus.h b/include/qemu/dbus.h new file mode 100644 index 0000000000..9d591f9ee4 --- /dev/null +++ b/include/qemu/dbus.h @@ -0,0 +1,19 @@ +/* + * Helpers for using D-Bus + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#ifndef DBUS_H +#define DBUS_H + +#include + +GStrv qemu_dbus_get_queued_owners(GDBusConnection *connection, + const char *name, + Error **errp); + +#endif /* DBUS_H */ diff --git a/util/Makefile.objs b/util/Makefile.objs index df124af1c5..80b76352cd 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -55,5 +55,8 @@ util-obj-$(CONFIG_INOTIFY1) +=3D filemonitor-inotify.o util-obj-$(CONFIG_LINUX) +=3D vfio-helpers.o util-obj-$(CONFIG_POSIX) +=3D drm.o util-obj-y +=3D guest-random.o +util-obj-$(CONFIG_GIO) +=3D dbus.o +dbus.o-cflags =3D $(GIO_CFLAGS) +dbus.o-libs =3D $(GIO_LIBS) =20 stub-obj-y +=3D filemonitor-stub.o diff --git a/util/dbus.c b/util/dbus.c new file mode 100644 index 0000000000..9099dc5b4b --- /dev/null +++ b/util/dbus.c @@ -0,0 +1,57 @@ +/* + * Helpers for using D-Bus + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/dbus.h" +#include "qemu/error-report.h" +#include "qapi/error.h" + +/* + * qemu_dbus_get_queued_owners() - return the list of queued unique names + * @connection: A GDBusConnection + * @name: a service name + * + * Return: a GStrv of unique names, or NULL on failure. + */ +GStrv +qemu_dbus_get_queued_owners(GDBusConnection *connection, const char *name, + Error **errp) +{ + g_autoptr(GDBusProxy) proxy =3D NULL; + g_autoptr(GVariant) result =3D NULL; + g_autoptr(GVariant) child =3D NULL; + g_autoptr(GError) err =3D NULL; + + proxy =3D g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_NONE, N= ULL, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + NULL, &err); + if (!proxy) { + error_setg(errp, "Failed to create DBus proxy: %s", err->message); + return NULL; + } + + result =3D g_dbus_proxy_call_sync(proxy, "ListQueuedOwners", + g_variant_new("(s)", name), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, NULL, &err); + if (!result) { + if (g_error_matches(err, + G_DBUS_ERROR, + G_DBUS_ERROR_NAME_HAS_NO_OWNER)) { + return g_new0(char *, 1); + } + error_setg(errp, "Failed to call ListQueuedOwners: %s", err->messa= ge); + return NULL; + } + + child =3D g_variant_get_child_value(result, 0); + return g_variant_dup_strv(child, NULL); +} --=20 2.24.0.308.g228f53135a From nobody Sun Apr 28 10:49:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576759933; cv=none; d=zohomail.com; s=zohoarc; b=LIEGxNJZXoy5XLESPDKoyk4WCWb8XhMSkaF+pbcfeEzsmyf0qek9xPyp2WAhb7MJHBBtMVd08mPVBbaNB4JegbNmfNTdEa8Yi1eBAXV7DL9+omp+jlpwutma3vmDpkM6ePAIgS8k9YCjtnQZsWCJQM3EHSpfZwyVU0suOOu8+P4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576759933; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1kYJuAHvuzuGup/JDLB0/wjdvJVNJRc7+t+EVc3tm1g=; b=fu5WY72Akha/EvvYbxe5KdTL6dUSGHOAP3reM53PhVmliO3i4l3kquvjPB70zIhWwCOKCT1KjvH74/LqJ/P/EkPkMHaVynHIOCO8teAffpkra3pMcRNBLhrT1dzLhxTq1TudX9OJxBQNMxsO+pHfb09BvoBrUPXqBGRwc/pslEo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576759933570498.29042462260645; Thu, 19 Dec 2019 04:52:13 -0800 (PST) Received: from localhost ([::1]:40430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihvHn-0002GT-S1 for importer@patchew.org; Thu, 19 Dec 2019 07:52:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46204) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihuyZ-0000vf-RR for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihuyX-0004md-11 for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:19 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:37429 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihuyV-0004jz-1m for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-yOo6JezjMiWv_6XnE_dv-w-1; Thu, 19 Dec 2019 07:32:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 850AB1005510 for ; Thu, 19 Dec 2019 12:32:08 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id D82BF60C18; Thu, 19 Dec 2019 12:31:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576758734; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1kYJuAHvuzuGup/JDLB0/wjdvJVNJRc7+t+EVc3tm1g=; b=IrRydnQtZu5MOQ/mxxs1VzV1BeGxDd9UPwyM/yLbveXMYlJlU6d75fZKjdfQlIbtFwstxT bZZfPVkRTi2mL9SpWj75ziS0ZEcVXeor0C+O7fLnpn2wFYEIYKDKKOHGOiJIixFmS4xYH8 7UWrl086xPLhaPDZbKs4VW6swbvzxqI= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v7 5/9] Add dbus-vmstate object Date: Thu, 19 Dec 2019 16:30:25 +0400 Message-Id: <20191219123029.200788-6-marcandre.lureau@redhat.com> In-Reply-To: <20191219123029.200788-1-marcandre.lureau@redhat.com> References: <20191219123029.200788-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: yOo6JezjMiWv_6XnE_dv-w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When instantiated, this object will connect to the given D-Bus bus "addr". During migration, it will take/restore the data from org.qemu.VMState1 instances. See documentation for details. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- MAINTAINERS | 2 + Makefile.objs | 1 + backends/Makefile.objs | 4 + backends/dbus-vmstate.c | 510 ++++++++++++++++++++++++++++++++++ backends/trace-events | 7 + docs/interop/dbus-vmstate.rst | 74 +++++ docs/interop/dbus.rst | 5 + docs/interop/index.rst | 1 + 8 files changed, 604 insertions(+) create mode 100644 backends/dbus-vmstate.c create mode 100644 backends/trace-events create mode 100644 docs/interop/dbus-vmstate.rst diff --git a/MAINTAINERS b/MAINTAINERS index 9c03214693..353d7a0cf5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2207,9 +2207,11 @@ F: qapi/migration.json D-Bus M: Marc-Andr=C3=A9 Lureau S: Maintained +F: backends/dbus-vmstate.c F: util/dbus.c F: include/qemu/dbus.h F: docs/interop/dbus.rst +F: docs/interop/dbus-vmstate.rst =20 Seccomp M: Eduardo Otubo diff --git a/Makefile.objs b/Makefile.objs index 4e4d6ddbb3..a529935c76 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -128,6 +128,7 @@ vhost-user-gpu-obj-y =3D contrib/vhost-user-gpu/ trace-events-subdirs =3D trace-events-subdirs +=3D accel/kvm trace-events-subdirs +=3D accel/tcg +trace-events-subdirs +=3D backends trace-events-subdirs +=3D crypto trace-events-subdirs +=3D monitor ifeq ($(CONFIG_USER_ONLY),y) diff --git a/backends/Makefile.objs b/backends/Makefile.objs index f0691116e8..28a847cd57 100644 --- a/backends/Makefile.objs +++ b/backends/Makefile.objs @@ -17,3 +17,7 @@ endif common-obj-$(call land,$(CONFIG_VHOST_USER),$(CONFIG_VIRTIO)) +=3D vhost-u= ser.o =20 common-obj-$(CONFIG_LINUX) +=3D hostmem-memfd.o + +common-obj-$(CONFIG_GIO) +=3D dbus-vmstate.o +dbus-vmstate.o-cflags =3D $(GIO_CFLAGS) +dbus-vmstate.o-libs =3D $(GIO_LIBS) diff --git a/backends/dbus-vmstate.c b/backends/dbus-vmstate.c new file mode 100644 index 0000000000..8116181fc0 --- /dev/null +++ b/backends/dbus-vmstate.c @@ -0,0 +1,510 @@ +/* + * QEMU dbus-vmstate + * + * Copyright (C) 2019 Red Hat Inc + * + * Authors: + * Marc-Andr=C3=A9 Lureau + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu/dbus.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "qom/object_interfaces.h" +#include "qapi/qmp/qerror.h" +#include "migration/vmstate.h" +#include "trace.h" + +typedef struct DBusVMState DBusVMState; +typedef struct DBusVMStateClass DBusVMStateClass; + +#define TYPE_DBUS_VMSTATE "dbus-vmstate" +#define DBUS_VMSTATE(obj) \ + OBJECT_CHECK(DBusVMState, (obj), TYPE_DBUS_VMSTATE) +#define DBUS_VMSTATE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(DBusVMStateClass, (obj), TYPE_DBUS_VMSTATE) +#define DBUS_VMSTATE_CLASS(klass) \ + OBJECT_CLASS_CHECK(DBusVMStateClass, (klass), TYPE_DBUS_VMSTATE) + +struct DBusVMStateClass { + ObjectClass parent_class; +}; + +struct DBusVMState { + Object parent; + + GDBusConnection *bus; + char *dbus_addr; + char *id_list; + + uint32_t data_size; + uint8_t *data; +}; + +static const GDBusPropertyInfo vmstate_property_info[] =3D { + { -1, (char *) "Id", (char *) "s", + G_DBUS_PROPERTY_INFO_FLAGS_READABLE, NULL }, +}; + +static const GDBusPropertyInfo * const vmstate_property_info_pointers[] = =3D { + &vmstate_property_info[0], + NULL +}; + +static const GDBusInterfaceInfo vmstate1_interface_info =3D { + -1, + (char *) "org.qemu.VMState1", + (GDBusMethodInfo **) NULL, + (GDBusSignalInfo **) NULL, + (GDBusPropertyInfo **) &vmstate_property_info_pointers, + NULL, +}; + +#define DBUS_VMSTATE_SIZE_LIMIT (1 * MiB) + +static GHashTable * +get_id_list_set(DBusVMState *self) +{ + g_auto(GStrv) ids =3D NULL; + g_autoptr(GHashTable) set =3D NULL; + int i; + + if (!self->id_list) { + return NULL; + } + + ids =3D g_strsplit(self->id_list, ",", -1); + set =3D g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + for (i =3D 0; ids[i]; i++) { + g_hash_table_add(set, ids[i]); + ids[i] =3D NULL; + } + + return g_steal_pointer(&set); +} + +static GHashTable * +dbus_get_proxies(DBusVMState *self, GError **err) +{ + g_autoptr(GHashTable) proxies =3D NULL; + g_autoptr(GHashTable) ids =3D NULL; + g_auto(GStrv) names =3D NULL; + Error *error =3D NULL; + size_t i; + + ids =3D get_id_list_set(self); + proxies =3D g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, g_object_unref); + + names =3D qemu_dbus_get_queued_owners(self->bus, "org.qemu.VMState1", = &error); + if (!names) { + g_set_error(err, G_IO_ERROR, G_IO_ERROR_FAILED, "%s", + error_get_pretty(error)); + error_free(error); + return NULL; + } + + for (i =3D 0; names[i]; i++) { + g_autoptr(GDBusProxy) proxy =3D NULL; + g_autoptr(GVariant) result =3D NULL; + g_autofree char *id =3D NULL; + size_t size; + + proxy =3D g_dbus_proxy_new_sync(self->bus, G_DBUS_PROXY_FLAGS_NONE, + (GDBusInterfaceInfo *) &vmstate1_interface_info, + names[i], + "/org/qemu/VMState1", + "org.qemu.VMState1", + NULL, err); + if (!proxy) { + return NULL; + } + + result =3D g_dbus_proxy_get_cached_property(proxy, "Id"); + if (!result) { + g_set_error_literal(err, G_IO_ERROR, G_IO_ERROR_FAILED, + "VMState Id property is missing."); + return NULL; + } + + id =3D g_variant_dup_string(result, &size); + if (ids && !g_hash_table_remove(ids, id)) { + g_clear_pointer(&id, g_free); + g_clear_object(&proxy); + continue; + } + if (size =3D=3D 0 || size >=3D 256) { + g_set_error(err, G_IO_ERROR, G_IO_ERROR_FAILED, + "VMState Id '%s' is invalid.", id); + return NULL; + } + + if (!g_hash_table_insert(proxies, id, proxy)) { + g_set_error(err, G_IO_ERROR, G_IO_ERROR_FAILED, + "Duplicated VMState Id '%s'", id); + return NULL; + } + id =3D NULL; + proxy =3D NULL; + + g_clear_pointer(&result, g_variant_unref); + } + + if (ids) { + g_autofree char **left =3D NULL; + + left =3D (char **)g_hash_table_get_keys_as_array(ids, NULL); + if (*left) { + g_autofree char *leftids =3D g_strjoinv(",", left); + g_set_error(err, G_IO_ERROR, G_IO_ERROR_FAILED, + "Required VMState Id are missing: %s", leftids); + return NULL; + } + } + + return g_steal_pointer(&proxies); +} + +static int +dbus_load_state_proxy(GDBusProxy *proxy, const uint8_t *data, size_t size) +{ + g_autoptr(GError) err =3D NULL; + g_autoptr(GVariant) result =3D NULL; + g_autoptr(GVariant) value =3D NULL; + + value =3D g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, + data, size, sizeof(char)); + result =3D g_dbus_proxy_call_sync(proxy, "Load", + g_variant_new("(@ay)", + g_steal_pointer(&value)), + G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, NULL, &err); + if (!result) { + error_report("%s: Failed to Load: %s", __func__, err->message); + return -1; + } + + return 0; +} + +static int dbus_vmstate_post_load(void *opaque, int version_id) +{ + DBusVMState *self =3D DBUS_VMSTATE(opaque); + g_autoptr(GInputStream) m =3D NULL; + g_autoptr(GDataInputStream) s =3D NULL; + g_autoptr(GError) err =3D NULL; + g_autoptr(GHashTable) proxies =3D NULL; + uint32_t nelem; + + trace_dbus_vmstate_post_load(version_id); + + proxies =3D dbus_get_proxies(self, &err); + if (!proxies) { + error_report("%s: Failed to get proxies: %s", __func__, err->messa= ge); + return -1; + } + + m =3D g_memory_input_stream_new_from_data(self->data, self->data_size,= NULL); + s =3D g_data_input_stream_new(m); + g_data_input_stream_set_byte_order(s, G_DATA_STREAM_BYTE_ORDER_BIG_END= IAN); + + nelem =3D g_data_input_stream_read_uint32(s, NULL, &err); + if (err) { + goto error; + } + + while (nelem > 0) { + GDBusProxy *proxy =3D NULL; + uint32_t len; + gsize bytes_read, avail; + char id[256]; + + len =3D g_data_input_stream_read_uint32(s, NULL, &err); + if (err) { + goto error; + } + if (len >=3D 256) { + error_report("%s: Invalid DBus vmstate proxy name %u", + __func__, len); + return -1; + } + if (!g_input_stream_read_all(G_INPUT_STREAM(s), id, len, + &bytes_read, NULL, &err)) { + goto error; + } + g_return_val_if_fail(bytes_read =3D=3D len, -1); + id[len] =3D 0; + + trace_dbus_vmstate_loading(id); + + proxy =3D g_hash_table_lookup(proxies, id); + if (!proxy) { + error_report("%s: Failed to find proxy Id '%s'", __func__, id); + return -1; + } + + len =3D g_data_input_stream_read_uint32(s, NULL, &err); + avail =3D g_buffered_input_stream_get_available( + G_BUFFERED_INPUT_STREAM(s)); + + if (len > DBUS_VMSTATE_SIZE_LIMIT || len > avail) { + error_report("%s: Invalid vmstate size: %u", __func__, len); + return -1; + } + + if (dbus_load_state_proxy(proxy, + g_buffered_input_stream_peek_buffer(G_BUFFERED_INPUT_STREA= M(s), + NULL), + len) < 0) { + error_report("%s: Failed to restore Id '%s'", __func__, id); + return -1; + } + + if (!g_seekable_seek(G_SEEKABLE(s), len, G_SEEK_CUR, NULL, &err)) { + goto error; + } + + nelem -=3D 1; + } + + return 0; + +error: + error_report("%s: Failed to read from stream: %s", __func__, err->mess= age); + return -1; +} + +static void +dbus_save_state_proxy(gpointer key, + gpointer value, + gpointer user_data) +{ + GDataOutputStream *s =3D user_data; + const char *id =3D key; + GDBusProxy *proxy =3D value; + g_autoptr(GVariant) result =3D NULL; + g_autoptr(GVariant) child =3D NULL; + g_autoptr(GError) err =3D NULL; + const uint8_t *data; + gsize size; + + trace_dbus_vmstate_saving(id); + + result =3D g_dbus_proxy_call_sync(proxy, "Save", + NULL, G_DBUS_CALL_FLAGS_NO_AUTO_START, + -1, NULL, &err); + if (!result) { + error_report("%s: Failed to Save: %s", __func__, err->message); + return; + } + + child =3D g_variant_get_child_value(result, 0); + data =3D g_variant_get_fixed_array(child, &size, sizeof(char)); + if (!data) { + error_report("%s: Failed to Save: not a byte array", __func__); + return; + } + if (size > DBUS_VMSTATE_SIZE_LIMIT) { + error_report("%s: Too large vmstate data to save: %" G_GSIZE_FORMA= T, + __func__, size); + return; + } + + if (!g_data_output_stream_put_uint32(s, strlen(id), NULL, &err) || + !g_data_output_stream_put_string(s, id, NULL, &err) || + !g_data_output_stream_put_uint32(s, size, NULL, &err) || + !g_output_stream_write_all(G_OUTPUT_STREAM(s), + data, size, NULL, NULL, &err)) { + error_report("%s: Failed to write to stream: %s", + __func__, err->message); + } +} + +static int dbus_vmstate_pre_save(void *opaque) +{ + DBusVMState *self =3D DBUS_VMSTATE(opaque); + g_autoptr(GOutputStream) m =3D NULL; + g_autoptr(GDataOutputStream) s =3D NULL; + g_autoptr(GHashTable) proxies =3D NULL; + g_autoptr(GError) err =3D NULL; + + trace_dbus_vmstate_pre_save(); + + proxies =3D dbus_get_proxies(self, &err); + if (!proxies) { + error_report("%s: Failed to get proxies: %s", __func__, err->messa= ge); + return -1; + } + + m =3D g_memory_output_stream_new_resizable(); + s =3D g_data_output_stream_new(m); + g_data_output_stream_set_byte_order(s, G_DATA_STREAM_BYTE_ORDER_BIG_EN= DIAN); + + if (!g_data_output_stream_put_uint32(s, g_hash_table_size(proxies), + NULL, &err)) { + error_report("%s: Failed to write to stream: %s", + __func__, err->message); + return -1; + } + + g_hash_table_foreach(proxies, dbus_save_state_proxy, s); + + if (g_memory_output_stream_get_size(G_MEMORY_OUTPUT_STREAM(m)) + > UINT32_MAX) { + error_report("%s: DBus vmstate buffer is too large", __func__); + return -1; + } + + if (!g_output_stream_close(G_OUTPUT_STREAM(m), NULL, &err)) { + error_report("%s: Failed to close stream: %s", __func__, err->mess= age); + return -1; + } + + g_free(self->data); + self->data_size =3D + g_memory_output_stream_get_size(G_MEMORY_OUTPUT_STREAM(m)); + self->data =3D + g_memory_output_stream_steal_data(G_MEMORY_OUTPUT_STREAM(m)); + + return 0; +} + +static const VMStateDescription dbus_vmstate =3D { + .name =3D TYPE_DBUS_VMSTATE, + .version_id =3D 0, + .pre_save =3D dbus_vmstate_pre_save, + .post_load =3D dbus_vmstate_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(data_size, DBusVMState), + VMSTATE_VBUFFER_ALLOC_UINT32(data, DBusVMState, 0, 0, data_size), + VMSTATE_END_OF_LIST() + } +}; + +static void +dbus_vmstate_complete(UserCreatable *uc, Error **errp) +{ + DBusVMState *self =3D DBUS_VMSTATE(uc); + g_autoptr(GError) err =3D NULL; + + if (!object_resolve_path_type("", TYPE_DBUS_VMSTATE, NULL)) { + error_setg(errp, "There is already an instance of %s", + TYPE_DBUS_VMSTATE); + return; + } + + if (!self->dbus_addr) { + error_setg(errp, QERR_MISSING_PARAMETER, "addr"); + return; + } + + self->bus =3D g_dbus_connection_new_for_address_sync(self->dbus_addr, + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | + G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION, + NULL, NULL, &err); + if (err) { + error_setg(errp, "failed to connect to DBus: '%s'", err->message); + return; + } + + if (vmstate_register(VMSTATE_IF(self), -1, &dbus_vmstate, self) < 0) { + error_setg(errp, "Failed to register vmstate"); + } +} + +static void +dbus_vmstate_finalize(Object *o) +{ + DBusVMState *self =3D DBUS_VMSTATE(o); + + vmstate_unregister(VMSTATE_IF(self), &dbus_vmstate, self); + + g_clear_object(&self->bus); + g_free(self->dbus_addr); + g_free(self->id_list); + g_free(self->data); +} + +static char * +get_dbus_addr(Object *o, Error **errp) +{ + DBusVMState *self =3D DBUS_VMSTATE(o); + + return g_strdup(self->dbus_addr); +} + +static void +set_dbus_addr(Object *o, const char *str, Error **errp) +{ + DBusVMState *self =3D DBUS_VMSTATE(o); + + g_free(self->dbus_addr); + self->dbus_addr =3D g_strdup(str); +} + +static char * +get_id_list(Object *o, Error **errp) +{ + DBusVMState *self =3D DBUS_VMSTATE(o); + + return g_strdup(self->id_list); +} + +static void +set_id_list(Object *o, const char *str, Error **errp) +{ + DBusVMState *self =3D DBUS_VMSTATE(o); + + g_free(self->id_list); + self->id_list =3D g_strdup(str); +} + +static char * +dbus_vmstate_get_id(VMStateIf *vmif) +{ + return g_strdup(TYPE_DBUS_VMSTATE); +} + +static void +dbus_vmstate_class_init(ObjectClass *oc, void *data) +{ + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); + VMStateIfClass *vc =3D VMSTATE_IF_CLASS(oc); + + ucc->complete =3D dbus_vmstate_complete; + vc->get_id =3D dbus_vmstate_get_id; + + object_class_property_add_str(oc, "addr", + get_dbus_addr, set_dbus_addr, + &error_abort); + object_class_property_add_str(oc, "id-list", + get_id_list, set_id_list, + &error_abort); +} + +static const TypeInfo dbus_vmstate_info =3D { + .name =3D TYPE_DBUS_VMSTATE, + .parent =3D TYPE_OBJECT, + .instance_size =3D sizeof(DBusVMState), + .instance_finalize =3D dbus_vmstate_finalize, + .class_size =3D sizeof(DBusVMStateClass), + .class_init =3D dbus_vmstate_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { TYPE_VMSTATE_IF }, + { } + } +}; + +static void +register_types(void) +{ + type_register_static(&dbus_vmstate_info); +} + +type_init(register_types); diff --git a/backends/trace-events b/backends/trace-events new file mode 100644 index 0000000000..59058f7630 --- /dev/null +++ b/backends/trace-events @@ -0,0 +1,7 @@ +# See docs/devel/tracing.txt for syntax documentation. + +# dbus-vmstate.c +dbus_vmstate_pre_save(void) +dbus_vmstate_post_load(int version_id) "version_id: %d" +dbus_vmstate_loading(const char *id) "id: %s" +dbus_vmstate_saving(const char *id) "id: %s" diff --git a/docs/interop/dbus-vmstate.rst b/docs/interop/dbus-vmstate.rst new file mode 100644 index 0000000000..1d719c1c60 --- /dev/null +++ b/docs/interop/dbus-vmstate.rst @@ -0,0 +1,74 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +D-Bus VMState +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Introduction +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The QEMU dbus-vmstate object's aim is to migrate helpers' data running +on a QEMU D-Bus bus. (refer to the :doc:`dbus` document for +some recommendations on D-Bus usage) + +Upon migration, QEMU will go through the queue of +``org.qemu.VMState1`` D-Bus name owners and query their ``Id``. It +must be unique among the helpers. + +It will then save arbitrary data of each Id to be transferred in the +migration stream and restored/loaded at the corresponding destination +helper. + +For now, the data amount to be transferred is arbitrarily limited to +1Mb. The state must be saved quickly (a fraction of a second). (D-Bus +imposes a time limit on reply anyway, and migration would fail if data +isn't given quickly enough.) + +dbus-vmstate object can be configured with the expected list of +helpers by setting its ``id-list`` property, with a comma-separated +``Id`` list. + +Interface +=3D=3D=3D=3D=3D=3D=3D=3D=3D + +On object path ``/org/qemu/VMState1``, the following +``org.qemu.VMState1`` interface should be implemented: + +.. code:: xml + + + + + + + + + + + +"Id" property +------------- + +A string that identifies the helper uniquely. (maximum 256 bytes +including terminating NUL byte) + +.. note:: + + The helper ID namespace is a separate namespace. In particular, it is n= ot + related to QEMU "id" used in -object/-device objects. + +Load(in u8[] bytes) method +-------------------------- + +The method called on destination with the state to restore. + +The helper may be initially started in a waiting state (with +an --incoming argument for example), and it may resume on success. + +An error may be returned to the caller. + +Save(out u8[] bytes) method +--------------------------- + +The method called on the source to get the current state to be +migrated. The helper should continue to run normally. + +An error may be returned to the caller. diff --git a/docs/interop/dbus.rst b/docs/interop/dbus.rst index ef80d4204d..76a5bde625 100644 --- a/docs/interop/dbus.rst +++ b/docs/interop/dbus.rst @@ -103,3 +103,8 @@ https://dbus.freedesktop.org/doc/dbus-api-design.html =20 The "org.qemu.*" prefix is reserved for services implemented & distributed by the QEMU project. + +QEMU Interfaces +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +:doc:`dbus-vmstate` diff --git a/docs/interop/index.rst b/docs/interop/index.rst index ded134ea75..049387ac6d 100644 --- a/docs/interop/index.rst +++ b/docs/interop/index.rst @@ -14,6 +14,7 @@ Contents: =20 bitmaps dbus + dbus-vmstate live-block-operations pr-helper qemu-ga --=20 2.24.0.308.g228f53135a From nobody Sun Apr 28 10:49:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576760025; cv=none; d=zohomail.com; s=zohoarc; b=lHHKlHW3Si2jcwPj9uaXe0TywBhVSuoRwcUo7+dpxI4e913Jy/u6+QiPLNFkgBKE9UIDW/whakoim2gDpShTFK/37R9QVFmgl5bLAX2ptIHyFGDuoUVAdye1Encc2lRNkteiMdJdv23xG+/5s+ZeaNzajmJ93lcdnrYiZvazECg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576760025; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YOh9YHEZJBhPYlgnaaZFcBlij8k8I6gf+3KGiXuLZWQ=; b=kp0SOxA/R2GQ0ZP8UPE4wFnKMtzSPf/DtJZmH5MXnrUePlz7jUB8iyNpPCexXZuYO1Ho+EyzGafzG991tJCmSR/2C8wLelN0AXY0BPDaCc0htXGgbVLYx9ZZWDKwo7KmnJVfkKec1sSwxdN36BJxB/rppNd3V25s+cepkAOdt/w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576760025979454.1190072394528; Thu, 19 Dec 2019 04:53:45 -0800 (PST) Received: from localhost ([::1]:40454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihvJI-0004Xp-Ij for importer@patchew.org; Thu, 19 Dec 2019 07:53:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47418) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihuyi-00017G-N5 for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihuyh-0005cD-Fv for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:28 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:40893 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihuyh-0005Xa-62 for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:27 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-6AbODKUFMn66N9pmkgT2Zg-1; Thu, 19 Dec 2019 07:32:23 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 798EC1005513 for ; Thu, 19 Dec 2019 12:32:22 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7084620DB; Thu, 19 Dec 2019 12:32:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576758746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YOh9YHEZJBhPYlgnaaZFcBlij8k8I6gf+3KGiXuLZWQ=; b=KpvlYOtgYG9HKuFGlQi0pD9K/vO7WH+ms9/p16fOX/DJYUcY4A7EB05PYVvX4Iidm0W9QG FPsW0Oe+YxiO+5yUcDUdXWQJwdKEyQ0+Wi+x4zyNI7DhtHUgDTQlGEx9+upuPkvqNHMHzs ngFpAcQ9+Jy6DNjkruBWIS2a7XVo4sg= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v7 6/9] configure: add GDBUS_CODEGEN Date: Thu, 19 Dec 2019 16:30:26 +0400 Message-Id: <20191219123029.200788-7-marcandre.lureau@redhat.com> In-Reply-To: <20191219123029.200788-1-marcandre.lureau@redhat.com> References: <20191219123029.200788-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 6AbODKUFMn66N9pmkgT2Zg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" gdbus-codegen generated code requires gio-unix on Unix, so add it to GIO libs/cflags. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- configure | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure b/configure index 84b413dbfc..5610d9187f 100755 --- a/configure +++ b/configure @@ -3694,10 +3694,16 @@ if $pkg_config --atleast-version=3D$glib_req_ver gi= o-2.0; then gio=3Dyes gio_cflags=3D$($pkg_config --cflags gio-2.0) gio_libs=3D$($pkg_config --libs gio-2.0) + gdbus_codegen=3D$($pkg_config --variable=3Dgdbus_codegen gio-2.0) else gio=3Dno fi =20 +if $pkg_config --atleast-version=3D$glib_req_ver gio-unix-2.0; then + gio_cflags=3D"$gio_cflags $($pkg_config --cflags gio-unix-2.0)" + gio_libs=3D"$gio_libs $($pkg_config --libs gio-unix-2.0)" +fi + # Sanity check that the current size_t matches the # size that glib thinks it should be. This catches # problems on multi-arch where people try to build @@ -6902,6 +6908,7 @@ if test "$gio" =3D "yes" ; then echo "CONFIG_GIO=3Dy" >> $config_host_mak echo "GIO_CFLAGS=3D$gio_cflags" >> $config_host_mak echo "GIO_LIBS=3D$gio_libs" >> $config_host_mak + echo "GDBUS_CODEGEN=3D$gdbus_codegen" >> $config_host_mak fi echo "CONFIG_TLS_PRIORITY=3D\"$tls_priority\"" >> $config_host_mak if test "$gnutls" =3D "yes" ; then --=20 2.24.0.308.g228f53135a From nobody Sun Apr 28 10:49:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576760983; cv=none; d=zohomail.com; s=zohoarc; b=OUgEG0q42FUuiiyjEixOiVPFcu/5WfMHlSm6OX/Ela25bB7bHGH9V6+xileHzEZMo+kIMd/PaqvwJ5/rACw5Ng8aDt1ObrXT7cy3sJDg+lZZWVgjsSC83tgjCiEWlXMFHhgVOgdjDV04Flgv5+L8yUPrLdkkKPrgP8fO/lCTpu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576760983; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BuyE/qTzYXt1c1/LGWpcX7MbcN7ayH6LYIr9Eyrm/Cw=; b=OhcvktjuWc5TM+x9lZBXGwBT5Md0eXRWmJmrnWxkfKIYk7dA+Vw20leV1Yvh94PvJXu259/hgvhB5mke0nm8CxQzpXgUlVT7pnmFHk9dEpR0lr4vNkpQSVQkjxkR5VwnJ8Y3rUHepfTBmNPlUl1SM7ToQ8WTkGXqWeK6jjFRKe0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157676098317112.404325823899853; Thu, 19 Dec 2019 05:09:43 -0800 (PST) Received: from localhost ([::1]:40752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihvYj-00012N-Su for importer@patchew.org; Thu, 19 Dec 2019 08:09:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48043) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihuyn-0001EC-Vo for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihuym-00065C-Li for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:33 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:48987 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihuym-00062s-Cj for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:32 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-145-td0z7RckPEGu2tHdflxYuw-1; Thu, 19 Dec 2019 07:32:31 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1EE36800D41 for ; Thu, 19 Dec 2019 12:32:30 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5F6060BC7; Thu, 19 Dec 2019 12:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576758752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BuyE/qTzYXt1c1/LGWpcX7MbcN7ayH6LYIr9Eyrm/Cw=; b=BH97PbI3nIcwphZ3vQesrr+S1m8C+er+05fvDUaqnTneXO2FRaY5n4XZfVaTuQmvJa4hPx r6MCJxHY8Fz9o0HFVxwGWVoQIqd5bclVtRAR8P5kr7SbSYD3+5deDeDvj2LLGdOnKCjZ9O XNattln1wqjQERMaWqyXkVYBgJoqSDU= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v7 7/9] dockerfiles: add dbus-daemon to some of latest distributions Date: Thu, 19 Dec 2019 16:30:27 +0400 Message-Id: <20191219123029.200788-8-marcandre.lureau@redhat.com> In-Reply-To: <20191219123029.200788-1-marcandre.lureau@redhat.com> References: <20191219123029.200788-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: td0z7RckPEGu2tHdflxYuw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" To get dbus-vmstate test covered. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- tests/docker/dockerfiles/centos7.docker | 1 + tests/docker/dockerfiles/debian10.docker | 1 + tests/docker/dockerfiles/fedora.docker | 1 + tests/docker/dockerfiles/ubuntu.docker | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/docker/dockerfiles/centos7.docker b/tests/docker/dockerf= iles/centos7.docker index 953637065c..562d65be9e 100644 --- a/tests/docker/dockerfiles/centos7.docker +++ b/tests/docker/dockerfiles/centos7.docker @@ -8,6 +8,7 @@ ENV PACKAGES \ bzip2-devel \ ccache \ csnappy-devel \ + dbus-daemon \ flex \ gcc-c++ \ gcc \ diff --git a/tests/docker/dockerfiles/debian10.docker b/tests/docker/docker= files/debian10.docker index dad498b52e..5de79ae552 100644 --- a/tests/docker/dockerfiles/debian10.docker +++ b/tests/docker/dockerfiles/debian10.docker @@ -21,6 +21,7 @@ RUN apt update && \ build-essential \ ca-certificates \ clang \ + dbus \ flex \ gettext \ git \ diff --git a/tests/docker/dockerfiles/fedora.docker b/tests/docker/dockerfi= les/fedora.docker index 51d475e6be..987a3c170a 100644 --- a/tests/docker/dockerfiles/fedora.docker +++ b/tests/docker/dockerfiles/fedora.docker @@ -8,6 +8,7 @@ ENV PACKAGES \ ccache \ clang \ cyrus-sasl-devel \ + dbus-daemon \ device-mapper-multipath-devel \ findutils \ flex \ diff --git a/tests/docker/dockerfiles/ubuntu.docker b/tests/docker/dockerfi= les/ubuntu.docker index 18f1100409..4177f33691 100644 --- a/tests/docker/dockerfiles/ubuntu.docker +++ b/tests/docker/dockerfiles/ubuntu.docker @@ -13,6 +13,7 @@ FROM ubuntu:19.04 ENV PACKAGES flex bison \ ccache \ clang \ + dbus \ gcc \ gettext \ git \ --=20 2.24.0.308.g228f53135a From nobody Sun Apr 28 10:49:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576760091; cv=none; d=zohomail.com; s=zohoarc; b=gdGgC7dypPn2NVIo4l5Ucy2pFOA7paKNmBTSpiM/PSiqkbmGvUTP9njIlJ7JT/bG/TX/gZdFUzflkOMeDdHaGWFjQu+bBX1xm8/8ZSXzv4W5QHYb+GIHhIPT+ZmKyqc3ad5wRFvG/WxKL1qnJxkG6YWrn/5VCxNHt/Hhw7prkvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576760091; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0Ma/H5NbB9BGAt4xU8QspKxhJxth7q7yxK/1QFdxJ84=; b=i74Qp/48QK5neoKfodg1cxg14Z+5vdfcGHKK92I36Pwks6NGNXYi+Wy+BLmne4XrFOk9/mktcxVoZeOqDNszXMhgu5O2/R8qW+PN91kjcBf5eLroEW13yNBnaHP2wyB9PZ/6H1XoSNa3mfjRBbavrywrFhzb+jw1sk6ckfAKclo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576760091337344.14461616596964; Thu, 19 Dec 2019 04:54:51 -0800 (PST) Received: from localhost ([::1]:40456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihvKL-0006LY-If for importer@patchew.org; Thu, 19 Dec 2019 07:54:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50060) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihuz4-0001em-H1 for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihuz1-0007Pt-TH for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:50 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:32929 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihuz1-0007N6-KT for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:32:47 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-SernIptJN8KwJN9Lw5MCzg-1; Thu, 19 Dec 2019 07:32:45 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8084184BEC0 for ; Thu, 19 Dec 2019 12:32:44 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27E875C1B0; Thu, 19 Dec 2019 12:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576758767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0Ma/H5NbB9BGAt4xU8QspKxhJxth7q7yxK/1QFdxJ84=; b=ESCinfAV7i320DJDwgnXlaaEmDa80hp8RO8vSfp6D/Fl+nfg8JUq1xWu4Ng4pVg5kHAfth HnkpT1YZ6fR9T6qKRJR7kN5V+5QbgHPBaVG3UhDivBZVW1br5g1VnZyY6bgJJVc0nKvcYt YYru2yZmkerz1zuyvdJgfuInqgZvkkQ= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v7 8/9] tests: add migration-helpers unit Date: Thu, 19 Dec 2019 16:30:28 +0400 Message-Id: <20191219123029.200788-9-marcandre.lureau@redhat.com> In-Reply-To: <20191219123029.200788-1-marcandre.lureau@redhat.com> References: <20191219123029.200788-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: SernIptJN8KwJN9Lw5MCzg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Move a few helper functions from migration-test.c to migration-helpers.c Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- tests/Makefile.include | 2 +- tests/migration-helpers.c | 167 ++++++++++++++++++++++++++++++++++++ tests/migration-helpers.h | 37 ++++++++ tests/migration-test.c | 176 +++----------------------------------- 4 files changed, 216 insertions(+), 166 deletions(-) create mode 100644 tests/migration-helpers.c create mode 100644 tests/migration-helpers.h diff --git a/tests/Makefile.include b/tests/Makefile.include index fa4140cbde..af88e8d6e1 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -827,7 +827,7 @@ tests/usb-hcd-uhci-test$(EXESUF): tests/usb-hcd-uhci-te= st.o $(libqos-usb-obj-y) tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-test.o $(libqos-usb-o= bj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-o= bj-y) tests/cpu-plug-test$(EXESUF): tests/cpu-plug-test.o -tests/migration-test$(EXESUF): tests/migration-test.o +tests/migration-test$(EXESUF): tests/migration-test.o tests/migration-help= ers.o tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_s= cm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) tests/test-keyval$(EXESUF): tests/test-keyval.o $(test-util-obj-y) $(test-= qapi-obj-y) diff --git a/tests/migration-helpers.c b/tests/migration-helpers.c new file mode 100644 index 0000000000..516093b39a --- /dev/null +++ b/tests/migration-helpers.c @@ -0,0 +1,167 @@ +/* + * QTest migration helpers + * + * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates + * based on the vhost-user-test.c that is: + * Copyright (c) 2014 Virtual Open Systems Sarl. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi/qmp/qjson.h" + +#include "migration-helpers.h" + +bool got_stop; + +static void stop_cb(void *opaque, const char *name, QDict *data) +{ + if (!strcmp(name, "STOP")) { + got_stop =3D true; + } +} + +/* + * Events can get in the way of responses we are actually waiting for. + */ +QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...) +{ + va_list ap; + + va_start(ap, command); + qtest_qmp_vsend_fds(who, &fd, 1, command, ap); + va_end(ap); + + return qtest_qmp_receive_success(who, stop_cb, NULL); +} + +/* + * Events can get in the way of responses we are actually waiting for. + */ +QDict *wait_command(QTestState *who, const char *command, ...) +{ + va_list ap; + + va_start(ap, command); + qtest_qmp_vsend(who, command, ap); + va_end(ap); + + return qtest_qmp_receive_success(who, stop_cb, NULL); +} + +/* + * Send QMP command "migrate". + * Arguments are built from @fmt... (formatted like + * qobject_from_jsonf_nofail()) with "uri": @uri spliced in. + */ +void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...) +{ + va_list ap; + QDict *args, *rsp; + + va_start(ap, fmt); + args =3D qdict_from_vjsonf_nofail(fmt, ap); + va_end(ap); + + g_assert(!qdict_haskey(args, "uri")); + qdict_put_str(args, "uri", uri); + + rsp =3D qtest_qmp(who, "{ 'execute': 'migrate', 'arguments': %p}", arg= s); + + g_assert(qdict_haskey(rsp, "return")); + qobject_unref(rsp); +} + +/* + * Note: caller is responsible to free the returned object via + * qobject_unref() after use + */ +QDict *migrate_query(QTestState *who) +{ + return wait_command(who, "{ 'execute': 'query-migrate' }"); +} + +/* + * Note: caller is responsible to free the returned object via + * g_free() after use + */ +static gchar *migrate_query_status(QTestState *who) +{ + QDict *rsp_return =3D migrate_query(who); + gchar *status =3D g_strdup(qdict_get_str(rsp_return, "status")); + + g_assert(status); + qobject_unref(rsp_return); + + return status; +} + +static bool check_migration_status(QTestState *who, const char *goal, + const char **ungoals) +{ + bool ready; + char *current_status; + const char **ungoal; + + current_status =3D migrate_query_status(who); + ready =3D strcmp(current_status, goal) =3D=3D 0; + if (!ungoals) { + g_assert_cmpstr(current_status, !=3D, "failed"); + /* + * If looking for a state other than completed, + * completion of migration would cause the test to + * hang. + */ + if (strcmp(goal, "completed") !=3D 0) { + g_assert_cmpstr(current_status, !=3D, "completed"); + } + } else { + for (ungoal =3D ungoals; *ungoal; ungoal++) { + g_assert_cmpstr(current_status, !=3D, *ungoal); + } + } + g_free(current_status); + return ready; +} + +void wait_for_migration_status(QTestState *who, + const char *goal, const char **ungoals) +{ + while (!check_migration_status(who, goal, ungoals)) { + usleep(1000); + } +} + +void wait_for_migration_complete(QTestState *who) +{ + wait_for_migration_status(who, "completed", NULL); +} + +void wait_for_migration_fail(QTestState *from, bool allow_active) +{ + QDict *rsp_return; + char *status; + bool failed; + + do { + status =3D migrate_query_status(from); + bool result =3D !strcmp(status, "setup") || !strcmp(status, "faile= d") || + (allow_active && !strcmp(status, "active")); + if (!result) { + fprintf(stderr, "%s: unexpected status status=3D%s allow_activ= e=3D%d\n", + __func__, status, allow_active); + } + g_assert(result); + failed =3D !strcmp(status, "failed"); + g_free(status); + } while (!failed); + + /* Is the machine currently running? */ + rsp_return =3D wait_command(from, "{ 'execute': 'query-status' }"); + g_assert(qdict_haskey(rsp_return, "running")); + g_assert(qdict_get_bool(rsp_return, "running")); + qobject_unref(rsp_return); +} diff --git a/tests/migration-helpers.h b/tests/migration-helpers.h new file mode 100644 index 0000000000..a11808b3b7 --- /dev/null +++ b/tests/migration-helpers.h @@ -0,0 +1,37 @@ +/* + * QTest migration helpers + * + * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates + * based on the vhost-user-test.c that is: + * Copyright (c) 2014 Virtual Open Systems Sarl. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ +#ifndef MIGRATION_HELPERS_H_ +#define MIGRATION_HELPERS_H_ + +#include "libqtest.h" + +extern bool got_stop; + +GCC_FMT_ATTR(3, 4) +QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...); + +GCC_FMT_ATTR(2, 3) +QDict *wait_command(QTestState *who, const char *command, ...); + +GCC_FMT_ATTR(3, 4) +void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...); + +QDict *migrate_query(QTestState *who); + +void wait_for_migration_status(QTestState *who, + const char *goal, const char **ungoals); + +void wait_for_migration_complete(QTestState *who); + +void wait_for_migration_fail(QTestState *from, bool allow_active); + +#endif /* MIGRATION_HELPERS_H_ */ diff --git a/tests/migration-test.c b/tests/migration-test.c index a5343fdc66..03fb1f1328 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -14,7 +14,6 @@ =20 #include "libqtest.h" #include "qapi/qmp/qdict.h" -#include "qapi/qmp/qjson.h" #include "qemu/module.h" #include "qemu/option.h" #include "qemu/range.h" @@ -24,6 +23,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" =20 +#include "migration-helpers.h" #include "migration/migration-test.h" =20 /* TODO actually test the results and get rid of this */ @@ -31,7 +31,6 @@ =20 unsigned start_address; unsigned end_address; -bool got_stop; static bool uffd_feature_thread_id; =20 #if defined(__linux__) @@ -157,67 +156,6 @@ static void wait_for_serial(const char *side) } while (true); } =20 -static void stop_cb(void *opaque, const char *name, QDict *data) -{ - if (!strcmp(name, "STOP")) { - got_stop =3D true; - } -} - -/* - * Events can get in the way of responses we are actually waiting for. - */ -GCC_FMT_ATTR(3, 4) -static QDict *wait_command_fd(QTestState *who, int fd, const char *command= , ...) -{ - va_list ap; - - va_start(ap, command); - qtest_qmp_vsend_fds(who, &fd, 1, command, ap); - va_end(ap); - - return qtest_qmp_receive_success(who, stop_cb, NULL); -} - -/* - * Events can get in the way of responses we are actually waiting for. - */ -GCC_FMT_ATTR(2, 3) -static QDict *wait_command(QTestState *who, const char *command, ...) -{ - va_list ap; - - va_start(ap, command); - qtest_qmp_vsend(who, command, ap); - va_end(ap); - - return qtest_qmp_receive_success(who, stop_cb, NULL); -} - -/* - * Note: caller is responsible to free the returned object via - * qobject_unref() after use - */ -static QDict *migrate_query(QTestState *who) -{ - return wait_command(who, "{ 'execute': 'query-migrate' }"); -} - -/* - * Note: caller is responsible to free the returned object via - * g_free() after use - */ -static gchar *migrate_query_status(QTestState *who) -{ - QDict *rsp_return =3D migrate_query(who); - gchar *status =3D g_strdup(qdict_get_str(rsp_return, "status")); - - g_assert(status); - qobject_unref(rsp_return); - - return status; -} - /* * It's tricky to use qemu's migration event capability with qtest, * events suddenly appearing confuse the qmp()/hmp() responses. @@ -265,48 +203,6 @@ static void read_blocktime(QTestState *who) qobject_unref(rsp_return); } =20 -static bool check_migration_status(QTestState *who, const char *goal, - const char **ungoals) -{ - bool ready; - char *current_status; - const char **ungoal; - - current_status =3D migrate_query_status(who); - ready =3D strcmp(current_status, goal) =3D=3D 0; - if (!ungoals) { - g_assert_cmpstr(current_status, !=3D, "failed"); - /* - * If looking for a state other than completed, - * completion of migration would cause the test to - * hang. - */ - if (strcmp(goal, "completed") !=3D 0) { - g_assert_cmpstr(current_status, !=3D, "completed"); - } - } else { - for (ungoal =3D ungoals; *ungoal; ungoal++) { - g_assert_cmpstr(current_status, !=3D, *ungoal); - } - } - g_free(current_status); - return ready; -} - -static void wait_for_migration_status(QTestState *who, - const char *goal, - const char **ungoals) -{ - while (!check_migration_status(who, goal, ungoals)) { - usleep(1000); - } -} - -static void wait_for_migration_complete(QTestState *who) -{ - wait_for_migration_status(who, "completed", NULL); -} - static void wait_for_migration_pass(QTestState *who) { uint64_t initial_pass =3D get_migration_pass(who); @@ -513,30 +409,6 @@ static void migrate_set_capability(QTestState *who, co= nst char *capability, qobject_unref(rsp); } =20 -/* - * Send QMP command "migrate". - * Arguments are built from @fmt... (formatted like - * qobject_from_jsonf_nofail()) with "uri": @uri spliced in. - */ -GCC_FMT_ATTR(3, 4) -static void migrate(QTestState *who, const char *uri, const char *fmt, ...) -{ - va_list ap; - QDict *args, *rsp; - - va_start(ap, fmt); - args =3D qdict_from_vjsonf_nofail(fmt, ap); - va_end(ap); - - g_assert(!qdict_haskey(args, "uri")); - qdict_put_str(args, "uri", uri); - - rsp =3D qtest_qmp(who, "{ 'execute': 'migrate', 'arguments': %p}", arg= s); - - g_assert(qdict_haskey(rsp, "return")); - qobject_unref(rsp); -} - static void migrate_postcopy_start(QTestState *from, QTestState *to) { QDict *rsp; @@ -795,7 +667,7 @@ static int migrate_postcopy_prepare(QTestState **from_p= tr, /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); =20 - migrate(from, uri, "{}"); + migrate_qmp(from, uri, "{}"); g_free(uri); =20 wait_for_migration_pass(from); @@ -882,7 +754,7 @@ static void test_postcopy_recovery(void) wait_for_migration_status(from, "postcopy-paused", (const char * []) { "failed", "active", "completed", NULL }); - migrate(from, uri, "{'resume': true}"); + migrate_qmp(from, uri, "{'resume': true}"); g_free(uri); =20 /* Restore the postcopy bandwidth to unlimited */ @@ -891,32 +763,6 @@ static void test_postcopy_recovery(void) migrate_postcopy_complete(from, to); } =20 -static void wait_for_migration_fail(QTestState *from, bool allow_active) -{ - QDict *rsp_return; - char *status; - bool failed; - - do { - status =3D migrate_query_status(from); - bool result =3D !strcmp(status, "setup") || !strcmp(status, "faile= d") || - (allow_active && !strcmp(status, "active")); - if (!result) { - fprintf(stderr, "%s: unexpected status status=3D%s allow_activ= e=3D%d\n", - __func__, status, allow_active); - } - g_assert(result); - failed =3D !strcmp(status, "failed"); - g_free(status); - } while (!failed); - - /* Is the machine currently running? */ - rsp_return =3D wait_command(from, "{ 'execute': 'query-status' }"); - g_assert(qdict_haskey(rsp_return, "running")); - g_assert(qdict_get_bool(rsp_return, "running")); - qobject_unref(rsp_return); -} - static void test_baddest(void) { QTestState *from, *to; @@ -924,7 +770,7 @@ static void test_baddest(void) if (test_migrate_start(&from, &to, "tcp:0:0", true, false, NULL, NULL)= ) { return; } - migrate(from, "tcp:0:0", "{}"); + migrate_qmp(from, "tcp:0:0", "{}"); wait_for_migration_fail(from, false); test_migrate_end(from, to, false); } @@ -950,7 +796,7 @@ static void test_precopy_unix(void) /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); =20 - migrate(from, uri, "{}"); + migrate_qmp(from, uri, "{}"); =20 wait_for_migration_pass(from); =20 @@ -987,7 +833,7 @@ static void test_ignore_shared(void) /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); =20 - migrate(from, uri, "{}"); + migrate_qmp(from, uri, "{}"); =20 wait_for_migration_pass(from); =20 @@ -1033,7 +879,7 @@ static void test_xbzrle(const char *uri) /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); =20 - migrate(from, uri, "{}"); + migrate_qmp(from, uri, "{}"); =20 wait_for_migration_pass(from); =20 @@ -1084,7 +930,7 @@ static void test_precopy_tcp(void) =20 uri =3D migrate_get_socket_address(to, "socket-address"); =20 - migrate(from, uri, "{}"); + migrate_qmp(from, uri, "{}"); =20 wait_for_migration_pass(from); =20 @@ -1152,7 +998,7 @@ static void test_migrate_fd_proto(void) close(pair[1]); =20 /* Start migration to the 2nd socket*/ - migrate(from, "fd:fd-mig", "{}"); + migrate_qmp(from, "fd:fd-mig", "{}"); =20 wait_for_migration_pass(from); =20 @@ -1210,7 +1056,7 @@ static void do_test_validate_uuid(const char *uuid_ar= g_src, /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); =20 - migrate(from, uri, "{}"); + migrate_qmp(from, uri, "{}"); =20 if (should_fail) { qtest_set_expected_status(to, 1); @@ -1292,7 +1138,7 @@ static void test_migrate_auto_converge(void) /* Wait for the first serial output from the source */ wait_for_serial("src_serial"); =20 - migrate(from, uri, "{}"); + migrate_qmp(from, uri, "{}"); =20 /* Wait for throttling begins */ percentage =3D 0; --=20 2.24.0.308.g228f53135a From nobody Sun Apr 28 10:49:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576760243; cv=none; d=zohomail.com; s=zohoarc; b=FXTeyBWVHBqv64hZPkuzlyvbG94lHDupAX47hovEASPhz6D74UfyliN73zWU4czJQMHpuP5tVal7hXPlApikCzmTjdv/6Rk+0uqkedMEo4jrS+OLkzIJmIfSpzbKJo0IxsMKX0m1LiSABcFS+c9YrALTujjEJS6eyC0oRQKVwek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576760243; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=otxw7Ql9ynNW3nQiJPhZL+rwYGFk3n6ZOxeSzEcsN8M=; b=mxh4rYHEplzkm/+KyYncDf01jHYhUi5BLNpVesD+axsZb3sHF49GOcEr1CMPVw+6Bdy9qEkoyLEg8yPMNJ0AagqkDPWmd7ynzCpxuUcTsYEfwdXPPZ/ZofzOLY3u7IHUzksMhox552awKOMCby1uAzkaynu+2e5OrmQUluqKuDE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576760243980940.5233455880036; Thu, 19 Dec 2019 04:57:23 -0800 (PST) Received: from localhost ([::1]:40498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihvMo-000209-7r for importer@patchew.org; Thu, 19 Dec 2019 07:57:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51651) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihuzH-00020P-6e for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:33:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihuzE-0008SL-7g for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:33:03 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24552 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihuzD-0008OB-VT for qemu-devel@nongnu.org; Thu, 19 Dec 2019 07:33:00 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-420-2HXA_4eLMN28-JuFZ02ydA-1; Thu, 19 Dec 2019 07:32:57 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F5B3800D41 for ; Thu, 19 Dec 2019 12:32:57 +0000 (UTC) Received: from localhost (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 544F263B8E; Thu, 19 Dec 2019 12:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576758779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=otxw7Ql9ynNW3nQiJPhZL+rwYGFk3n6ZOxeSzEcsN8M=; b=eLIaNX4DCeW6KS+fIkiwzVYxiBzBxo6VDLGpw55utbFCnHXNF3lvL3RH2nou/gVNBZhpp9 IXBocemNZnL2cmhMDVdD26TrLNBcIP+Hn19bAPBU36Vb0qOsToYR+BxzHi5Os2vTVo7AdB GvJg2sz0lQh8koHTZ29Oomoygz/TGeA= From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Subject: [PATCH v7 9/9] tests: add dbus-vmstate-test Date: Thu, 19 Dec 2019 16:30:29 +0400 Message-Id: <20191219123029.200788-10-marcandre.lureau@redhat.com> In-Reply-To: <20191219123029.200788-1-marcandre.lureau@redhat.com> References: <20191219123029.200788-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-MC-Unique: 2HXA_4eLMN28-JuFZ02ydA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: berrange@redhat.com, quintela@redhat.com, mprivozn@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- MAINTAINERS | 1 + roms/SLOF | 2 +- tests/Makefile.include | 22 +- tests/dbus-vmstate-daemon.sh | 95 +++++++++ tests/dbus-vmstate-test.c | 382 +++++++++++++++++++++++++++++++++++ tests/dbus-vmstate1.xml | 12 ++ 6 files changed, 512 insertions(+), 2 deletions(-) create mode 100755 tests/dbus-vmstate-daemon.sh create mode 100644 tests/dbus-vmstate-test.c create mode 100644 tests/dbus-vmstate1.xml diff --git a/MAINTAINERS b/MAINTAINERS index 353d7a0cf5..77bdf8333f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2208,6 +2208,7 @@ D-Bus M: Marc-Andr=C3=A9 Lureau S: Maintained F: backends/dbus-vmstate.c +F: tests/dbus-vmstate* F: util/dbus.c F: include/qemu/dbus.h F: docs/interop/dbus.rst diff --git a/roms/SLOF b/roms/SLOF index 9546892a80..8ebf2f55e1 160000 --- a/roms/SLOF +++ b/roms/SLOF @@ -1 +1 @@ -Subproject commit 9546892a80d5a4c73deea6719de46372f007f4a6 +Subproject commit 8ebf2f55e1ba1492b942ba4b682160e644fc0f98 diff --git a/tests/Makefile.include b/tests/Makefile.include index af88e8d6e1..b088b8d743 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -158,12 +158,17 @@ check-qtest-generic-$(CONFIG_MODULES) +=3D tests/modu= les-test$(EXESUF) =20 check-qtest-generic-y +=3D tests/device-introspect-test$(EXESUF) check-qtest-generic-y +=3D tests/cdrom-test$(EXESUF) +DBUS_DAEMON :=3D $(shell which dbus-daemon 2>/dev/null) +ifneq ($(GDBUS_CODEGEN),) +ifneq ($(DBUS_DAEMON),) +check-qtest-pci-$(CONFIG_GIO) +=3D tests/dbus-vmstate-test$(EXESUF) +endif +endif =20 check-qtest-pci-$(CONFIG_RTL8139_PCI) +=3D tests/rtl8139-test$(EXESUF) check-qtest-pci-$(CONFIG_VGA) +=3D tests/display-vga-test$(EXESUF) check-qtest-pci-$(CONFIG_HDA) +=3D tests/intel-hda-test$(EXESUF) check-qtest-pci-$(CONFIG_IVSHMEM_DEVICE) +=3D tests/ivshmem-test$(EXESUF) - check-qtest-i386-$(CONFIG_ISA_TESTDEV) =3D tests/endianness-test$(EXESUF) check-qtest-i386-y +=3D tests/fdc-test$(EXESUF) check-qtest-i386-y +=3D tests/ide-test$(EXESUF) @@ -634,6 +639,19 @@ tests/qapi-schema/doc-good.test.texi: $(SRC_PATH)/test= s/qapi-schema/doc-good.jso @mv tests/qapi-schema/doc-good-qapi-doc.texi $@ @rm -f tests/qapi-schema/doc-good-qapi-*.[ch] tests/qapi-schema/doc-good-= qmp-*.[ch] =20 +tests/dbus-vmstate1.h tests/dbus-vmstate1.c: tests/dbus-vmstate1-gen-times= tamp ; +tests/dbus-vmstate1-gen-timestamp: $(SRC_PATH)/tests/dbus-vmstate1.xml + $(call quiet-command,$(GDBUS_CODEGEN) $< \ + --interface-prefix org.qemu --generate-c-code tests/dbus-vmstate1, \ + "GEN","$(@:%-timestamp=3D%)") + @>$@ + +tests/dbus-vmstate-test.o-cflags :=3D -DSRCDIR=3D"$(SRC_PATH)" +tests/dbus-vmstate1.o-cflags :=3D $(GIO_CFLAGS) +tests/dbus-vmstate1.o-libs :=3D $(GIO_LIBS) + +tests/dbus-vmstate-test.o: tests/dbus-vmstate1.h + tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visito= r.o $(test-qapi-obj-y) tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.= o $(test-qapi-obj-y) tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) t= ests/test-qapi-events.o @@ -837,6 +855,7 @@ tests/test-filter-mirror$(EXESUF): tests/test-filter-mi= rror.o $(qtest-obj-y) tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qt= est-obj-y) tests/test-x86-cpuid-compat$(EXESUF): tests/test-x86-cpuid-compat.o $(qtes= t-obj-y) tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/i= vshmem-server.o $(libqos-pc-obj-y) $(libqos-spapr-obj-y) +tests/dbus-vmstate-test$(EXESUF): tests/dbus-vmstate-test.o tests/migratio= n-helpers.o tests/dbus-vmstate1.o $(libqos-pc-obj-y) $(libqos-spapr-obj-y) tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o $(test-util-ob= j-y) libvhost-user.a tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) tests/test-arm-mptimer$(EXESUF): tests/test-arm-mptimer.o @@ -1198,6 +1217,7 @@ check-clean: rm -rf $(check-unit-y) tests/*.o $(QEMU_IOTESTS_HELPERS-y) rm -rf $(sort $(foreach target,$(SYSEMU_TARGET_LIST), $(check-qtest-$(tar= get)-y)) $(check-qtest-generic-y)) rm -f tests/test-qapi-gen-timestamp + rm -f tests/dbus-vmstate1-gen-timestamp rm -rf $(TESTS_VENV_DIR) $(TESTS_RESULTS_DIR) =20 clean: check-clean diff --git a/tests/dbus-vmstate-daemon.sh b/tests/dbus-vmstate-daemon.sh new file mode 100755 index 0000000000..474e250154 --- /dev/null +++ b/tests/dbus-vmstate-daemon.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +# dbus-daemon wrapper script for dbus-vmstate testing +# +# This script allows to tweak the dbus-daemon policy during the test +# to test different configurations. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# Copyright (C) 2019 Red Hat, Inc. + +write_config() +{ + CONF=3D"$1" + cat > "$CONF" < + session + unix:tmpdir=3D$DBUS_VMSTATE_TEST_TMPDIR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + contexts/dbus_contexts + + +EOF +} + +ARGS=3D +for arg in "$@" +do + case $arg in + --config-file=3D*) + CONF=3D"${arg#*=3D}" + write_config "$CONF" + ARGS=3D"$ARGS $1" + shift + ;; + *) + ARGS=3D"$ARGS $1" + shift + ;; + esac +done + +exec dbus-daemon $ARGS diff --git a/tests/dbus-vmstate-test.c b/tests/dbus-vmstate-test.c new file mode 100644 index 0000000000..2e5e47dec2 --- /dev/null +++ b/tests/dbus-vmstate-test.c @@ -0,0 +1,382 @@ +#include "qemu/osdep.h" +#include +#include +#include "libqtest.h" +#include "qemu-common.h" +#include "dbus-vmstate1.h" +#include "migration-helpers.h" + +static char *workdir; + +typedef struct TestServerId { + const char *name; + const char *data; + size_t size; +} TestServerId; + +static const TestServerId idA =3D { + "idA", "I'am\0idA!", sizeof("I'am\0idA!") +}; + +static const TestServerId idB =3D { + "idB", "I'am\0idB!", sizeof("I'am\0idB!") +}; + +typedef struct TestServer { + const TestServerId *id; + bool save_called; + bool load_called; +} TestServer; + +typedef struct Test { + const char *id_list; + bool migrate_fail; + bool without_dst_b; + TestServer srcA; + TestServer dstA; + TestServer srcB; + TestServer dstB; + GMainLoop *loop; + QTestState *src_qemu; +} Test; + +static gboolean +vmstate_load(VMState1 *object, GDBusMethodInvocation *invocation, + const gchar *arg_data, gpointer user_data) +{ + TestServer *h =3D user_data; + g_autoptr(GVariant) var =3D NULL; + GVariant *args; + const uint8_t *data; + size_t size; + + args =3D g_dbus_method_invocation_get_parameters(invocation); + var =3D g_variant_get_child_value(args, 0); + data =3D g_variant_get_fixed_array(var, &size, sizeof(char)); + g_assert_cmpuint(size, =3D=3D, h->id->size); + g_assert(!memcmp(data, h->id->data, h->id->size)); + h->load_called =3D true; + + g_dbus_method_invocation_return_value(invocation, g_variant_new("()")); + return TRUE; +} + +static gboolean +vmstate_save(VMState1 *object, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + TestServer *h =3D user_data; + GVariant *var; + + var =3D g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, + h->id->data, h->id->size, sizeof(char)= ); + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(@ay)", var)); + h->save_called =3D true; + + return TRUE; +} + +typedef struct WaitNamed { + GMainLoop *loop; + bool named; +} WaitNamed; + +static void +named_cb(GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + WaitNamed *t =3D user_data; + + t->named =3D true; + g_main_loop_quit(t->loop); +} + +static GDBusConnection * +get_connection(Test *test, guint *ownid) +{ + g_autofree gchar *addr =3D NULL; + WaitNamed *wait; + GError *err =3D NULL; + GDBusConnection *c; + + wait =3D g_new0(WaitNamed, 1); + wait->loop =3D test->loop; + addr =3D g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SESSION, NULL, &er= r); + g_assert_no_error(err); + + c =3D g_dbus_connection_new_for_address_sync( + addr, + G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION | + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, + NULL, NULL, &err); + g_assert_no_error(err); + *ownid =3D g_bus_own_name_on_connection(c, "org.qemu.VMState1", + G_BUS_NAME_OWNER_FLAGS_NONE, + named_cb, named_cb, wait, g_free= ); + if (!wait->named) { + g_main_loop_run(wait->loop); + } + + return c; +} + +static GDBusObjectManagerServer * +get_server(GDBusConnection *conn, TestServer *s, const TestServerId *id) +{ + g_autoptr(GDBusObjectSkeleton) sk =3D NULL; + g_autoptr(VMState1Skeleton) v =3D NULL; + GDBusObjectManagerServer *os; + + s->id =3D id; + os =3D g_dbus_object_manager_server_new("/org/qemu"); + sk =3D g_dbus_object_skeleton_new("/org/qemu/VMState1"); + + v =3D VMSTATE1_SKELETON(vmstate1_skeleton_new()); + g_object_set(v, "id", id->name, NULL); + + g_signal_connect(v, "handle-load", G_CALLBACK(vmstate_load), s); + g_signal_connect(v, "handle-save", G_CALLBACK(vmstate_save), s); + + g_dbus_object_skeleton_add_interface(sk, G_DBUS_INTERFACE_SKELETON(v)); + g_dbus_object_manager_server_export(os, sk); + g_dbus_object_manager_server_set_connection(os, conn); + + return os; +} + +static void +set_id_list(Test *test, QTestState *s) +{ + if (!test->id_list) { + return; + } + + g_assert(!qmp_rsp_is_err(qtest_qmp(s, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': '/objects/dv', 'property': 'id-list', 'value': %s } }", + test->id_list))); +} + +static gpointer +dbus_vmstate_thread(gpointer data) +{ + GMainLoop *loop =3D data; + + g_main_loop_run(loop); + + return NULL; +} + +static void +test_dbus_vmstate(Test *test) +{ + g_autofree char *src_qemu_args =3D NULL; + g_autofree char *dst_qemu_args =3D NULL; + g_autoptr(GTestDBus) srcbus =3D NULL; + g_autoptr(GTestDBus) dstbus =3D NULL; + g_autoptr(GDBusConnection) srcconnA =3D NULL; + g_autoptr(GDBusConnection) srcconnB =3D NULL; + g_autoptr(GDBusConnection) dstconnA =3D NULL; + g_autoptr(GDBusConnection) dstconnB =3D NULL; + g_autoptr(GDBusObjectManagerServer) srcserverA =3D NULL; + g_autoptr(GDBusObjectManagerServer) srcserverB =3D NULL; + g_autoptr(GDBusObjectManagerServer) dstserverA =3D NULL; + g_autoptr(GDBusObjectManagerServer) dstserverB =3D NULL; + g_auto(GStrv) srcaddr =3D NULL; + g_auto(GStrv) dstaddr =3D NULL; + g_autoptr(GThread) thread =3D NULL; + g_autoptr(GMainLoop) loop =3D NULL; + g_autofree char *uri =3D NULL; + QTestState *src_qemu =3D NULL, *dst_qemu =3D NULL; + guint ownsrcA, ownsrcB, owndstA, owndstB; + + uri =3D g_strdup_printf("unix:%s/migsocket", workdir); + + loop =3D g_main_loop_new(NULL, FALSE); + test->loop =3D loop; + + srcbus =3D g_test_dbus_new(G_TEST_DBUS_NONE); + g_test_dbus_up(srcbus); + srcconnA =3D get_connection(test, &ownsrcA); + srcserverA =3D get_server(srcconnA, &test->srcA, &idA); + srcconnB =3D get_connection(test, &ownsrcB); + srcserverB =3D get_server(srcconnB, &test->srcB, &idB); + + /* remove ,guid=3Dfoo part */ + srcaddr =3D g_strsplit(g_test_dbus_get_bus_address(srcbus), ",", 2); + src_qemu_args =3D + g_strdup_printf("-object dbus-vmstate,id=3Ddv,addr=3D%s", srcaddr[= 0]); + + dstbus =3D g_test_dbus_new(G_TEST_DBUS_NONE); + g_test_dbus_up(dstbus); + dstconnA =3D get_connection(test, &owndstA); + dstserverA =3D get_server(dstconnA, &test->dstA, &idA); + if (!test->without_dst_b) { + dstconnB =3D get_connection(test, &owndstB); + dstserverB =3D get_server(dstconnB, &test->dstB, &idB); + } + + dstaddr =3D g_strsplit(g_test_dbus_get_bus_address(dstbus), ",", 2); + dst_qemu_args =3D + g_strdup_printf("-object dbus-vmstate,id=3Ddv,addr=3D%s -incoming = %s", + dstaddr[0], uri); + + src_qemu =3D qtest_init(src_qemu_args); + dst_qemu =3D qtest_init(dst_qemu_args); + set_id_list(test, src_qemu); + set_id_list(test, dst_qemu); + + thread =3D g_thread_new("dbus-vmstate-thread", dbus_vmstate_thread, lo= op); + + migrate_qmp(src_qemu, uri, "{}"); + test->src_qemu =3D src_qemu; + if (test->migrate_fail) { + wait_for_migration_fail(src_qemu, true); + qtest_set_expected_status(dst_qemu, 1); + } else { + wait_for_migration_complete(src_qemu); + } + + qtest_quit(dst_qemu); + qtest_quit(src_qemu); + g_bus_unown_name(ownsrcA); + g_bus_unown_name(ownsrcB); + g_bus_unown_name(owndstA); + if (!test->without_dst_b) { + g_bus_unown_name(owndstB); + } + + g_main_loop_quit(test->loop); +} + +static void +check_not_migrated(TestServer *s, TestServer *d) +{ + assert(!s->save_called); + assert(!s->load_called); + assert(!d->save_called); + assert(!d->load_called); +} + +static void +check_migrated(TestServer *s, TestServer *d) +{ + assert(s->save_called); + assert(!s->load_called); + assert(!d->save_called); + assert(d->load_called); +} + +static void +test_dbus_vmstate_without_list(void) +{ + Test test =3D { 0, }; + + test_dbus_vmstate(&test); + + check_migrated(&test.srcA, &test.dstA); + check_migrated(&test.srcB, &test.dstB); +} + +static void +test_dbus_vmstate_with_list(void) +{ + Test test =3D { .id_list =3D "idA,idB" }; + + test_dbus_vmstate(&test); + + check_migrated(&test.srcA, &test.dstA); + check_migrated(&test.srcB, &test.dstB); +} + +static void +test_dbus_vmstate_only_a(void) +{ + Test test =3D { .id_list =3D "idA" }; + + test_dbus_vmstate(&test); + + check_migrated(&test.srcA, &test.dstA); + check_not_migrated(&test.srcB, &test.dstB); +} + +static void +test_dbus_vmstate_missing_src(void) +{ + Test test =3D { .id_list =3D "idA,idC", .migrate_fail =3D true }; + + /* run in subprocess to silence QEMU error reporting */ + if (g_test_subprocess()) { + test_dbus_vmstate(&test); + check_not_migrated(&test.srcA, &test.dstA); + check_not_migrated(&test.srcB, &test.dstB); + return; + } + + g_test_trap_subprocess(NULL, 0, 0); + g_test_trap_assert_passed(); +} + +static void +test_dbus_vmstate_missing_dst(void) +{ + Test test =3D { .id_list =3D "idA,idB", + .without_dst_b =3D true, + .migrate_fail =3D true }; + + /* run in subprocess to silence QEMU error reporting */ + if (g_test_subprocess()) { + test_dbus_vmstate(&test); + assert(test.srcA.save_called); + assert(test.srcB.save_called); + assert(!test.dstB.save_called); + return; + } + + g_test_trap_subprocess(NULL, 0, 0); + g_test_trap_assert_passed(); +} + +int +main(int argc, char **argv) +{ + GError *err =3D NULL; + g_autofree char *dbus_daemon =3D NULL; + int ret; + + dbus_daemon =3D g_build_filename(G_STRINGIFY(SRCDIR), + "tests", + "dbus-vmstate-daemon.sh", + NULL); + g_setenv("G_TEST_DBUS_DAEMON", dbus_daemon, true); + + g_test_init(&argc, &argv, NULL); + + workdir =3D g_dir_make_tmp("dbus-vmstate-test-XXXXXX", &err); + if (!workdir) { + g_error("Unable to create temporary dir: %s\n", err->message); + exit(1); + } + + g_setenv("DBUS_VMSTATE_TEST_TMPDIR", workdir, true); + + qtest_add_func("/dbus-vmstate/without-list", + test_dbus_vmstate_without_list); + qtest_add_func("/dbus-vmstate/with-list", + test_dbus_vmstate_with_list); + qtest_add_func("/dbus-vmstate/only-a", + test_dbus_vmstate_only_a); + qtest_add_func("/dbus-vmstate/missing-src", + test_dbus_vmstate_missing_src); + qtest_add_func("/dbus-vmstate/missing-dst", + test_dbus_vmstate_missing_dst); + + ret =3D g_test_run(); + + rmdir(workdir); + g_free(workdir); + + return ret; +} diff --git a/tests/dbus-vmstate1.xml b/tests/dbus-vmstate1.xml new file mode 100644 index 0000000000..cc8563be4c --- /dev/null +++ b/tests/dbus-vmstate1.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + --=20 2.24.0.308.g228f53135a