From nobody Fri Apr 19 20:20:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1572866679; cv=none; d=zoho.com; s=zohoarc; b=X8bjkINTskThYUbi+szcXg0o2Gobg09DvJYfyXZjCCLBGBhLuWEt9trMk9Sokh/WQuEEKRIdD7uyicK5o8FDUZu3amKfM4iK7nkUEHH35vSegxNCRK3eID+ZHANSfC6K9E27iGfNMuIRu97YRwIXc8/edYji6q+oFjJ7JUZ+vcA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572866679; 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=bwiF3CFBStAkhoTJ+6GFTf/aLALn3/wAusMoksHUFks=; b=UKw0SquCVyUGaxXU3zGxapxLQPSKi7gqp/Igt3/1benJhsMiRtMtpinUeo5TdKu7udxwhswnAOwdEjzxPtjxnTSvexZD26d5JANm4z5MPGz4mjPLQvJNPflWqsPwHzyleUE91dOQwfPfGIb+FcZQlJ/JRi8TFm8r9naLrlAxaLs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1572866679887666.7832912688672; Mon, 4 Nov 2019 03:24:39 -0800 (PST) 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-242-mTB625uBMb-rfYkUg3phzw-1; Mon, 04 Nov 2019 06:24:36 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66121800A02; Mon, 4 Nov 2019 11:24:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 42DBA60863; Mon, 4 Nov 2019 11:24:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EF5E818034EB; Mon, 4 Nov 2019 11:24:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xA4BORnA005959 for ; Mon, 4 Nov 2019 06:24:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8F55960C88; Mon, 4 Nov 2019 11:24:27 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C145B60E1C; Mon, 4 Nov 2019 11:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572866678; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bwiF3CFBStAkhoTJ+6GFTf/aLALn3/wAusMoksHUFks=; b=JeDXZfn1dMM3FgKlkWVEPopJmxEqmLCrdpqMjXNjC8OTBkJIr+nodcSiPlXDIyHTCbyqKt 8y2/RmYhlYJVfxpJBEpAjci/IOK5QHL2ytiVsaGXnAYZ9+A+obW4NbkWJTucNXxqpRzk7i XkRFaWGHGSq0U8CQree+/l8GGq6kvTQ= From: Simon Kobyda To: libvir-list@redhat.com Date: Mon, 4 Nov 2019 12:24:08 +0100 Message-Id: <20191104112409.30613-2-skobyda@redhat.com> In-Reply-To: <20191104112409.30613-1-skobyda@redhat.com> References: <20191104112409.30613-1-skobyda@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Simon Kobyda Subject: [libvirt] [libvirt-dbus][PATCH v4 1/2] Introduce Domain Snapshot Interface X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: mTB625uBMb-rfYkUg3phzw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Simon Kobyda Reviewed-by: Pavel Hrdina --- data/meson.build | 1 + data/org.libvirt.DomainSnapshot.xml | 7 +++ src/connect.c | 6 +++ src/connect.h | 1 + src/domainsnapshot.c | 75 +++++++++++++++++++++++++++++ src/domainsnapshot.h | 9 ++++ src/meson.build | 1 + src/util.c | 53 ++++++++++++++++++++ src/util.h | 16 ++++++ 9 files changed, 169 insertions(+) create mode 100644 data/org.libvirt.DomainSnapshot.xml create mode 100644 src/domainsnapshot.c create mode 100644 src/domainsnapshot.h diff --git a/data/meson.build b/data/meson.build index 42a6799..0bd6338 100644 --- a/data/meson.build +++ b/data/meson.build @@ -1,6 +1,7 @@ install_data( 'org.libvirt.Connect.xml', 'org.libvirt.Domain.xml', + 'org.libvirt.DomainSnapshot.xml', 'org.libvirt.Interface.xml', 'org.libvirt.Network.xml', 'org.libvirt.NodeDevice.xml', diff --git a/data/org.libvirt.DomainSnapshot.xml b/data/org.libvirt.DomainS= napshot.xml new file mode 100644 index 0000000..8ba059f --- /dev/null +++ b/data/org.libvirt.DomainSnapshot.xml @@ -0,0 +1,7 @@ + + + + + + diff --git a/src/connect.c b/src/connect.c index f8f76a2..b40b0ba 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1,5 +1,6 @@ #include "connect.h" #include "domain.h" +#include "domainsnapshot.h" #include "events.h" #include "interface.h" #include "network.h" @@ -2002,6 +2003,7 @@ virtDBusConnectFree(virtDBusConnect *connect) virtDBusConnectClose(connect, TRUE); =20 g_free(connect->domainPath); + g_free(connect->domainSnapshotPath); g_free(connect->interfacePath); g_free(connect->networkPath); g_free(connect->nodeDevPath); @@ -2062,6 +2064,10 @@ virtDBusConnectNew(virtDBusConnect **connectp, if (error && *error) return; =20 + virtDBusDomainSnapshotRegister(connect, error); + if (error && *error) + return; + virtDBusInterfaceRegister(connect, error); if (error && *error) return; diff --git a/src/connect.h b/src/connect.h index 829bd57..74c89cf 100644 --- a/src/connect.h +++ b/src/connect.h @@ -13,6 +13,7 @@ struct virtDBusConnect { const gchar *uri; const gchar *connectPath; gchar *domainPath; + gchar *domainSnapshotPath; gchar *interfacePath; gchar *networkPath; gchar *nodeDevPath; diff --git a/src/domainsnapshot.c b/src/domainsnapshot.c new file mode 100644 index 0000000..c523c9e --- /dev/null +++ b/src/domainsnapshot.c @@ -0,0 +1,75 @@ +#include "domainsnapshot.h" +#include "util.h" + +#include + +static virtDBusGDBusPropertyTable virtDBusDomainSnapshotPropertyTable[] = =3D { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusDomainSnapshotMethodTable[] =3D { + { 0 } +}; + +static gchar ** +virtDBusDomainSnapshotEnumerate(gpointer userData) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virDomainPtr) domains =3D NULL; + gint numDoms =3D 0; + GPtrArray *list =3D NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + numDoms =3D virConnectListAllDomains(connect->connection, &domains, 0); + if (numDoms <=3D 0) + return NULL; + + list =3D g_ptr_array_new(); + + for (gint i =3D 0; i < numDoms; i++) { + g_autoptr(virDomainSnapshotPtr) domainSnapshots =3D NULL; + gint numSnaps; + + numSnaps =3D virDomainListAllSnapshots(domains[i], &domainSnapshot= s, 0); + if (numSnaps <=3D 0) + continue; + + for (gint j =3D 0; j < numSnaps; j++) { + gchar *snapPath =3D virtDBusUtilBusPathForVirDomainSnapshot(do= mains[i], + doma= inSnapshots[j], + conn= ect->domainSnapshotPath); + g_ptr_array_add(list, snapPath); + } + } + + if (list->len > 0) + g_ptr_array_add(list, NULL); + + return (gchar **)g_ptr_array_free(list, FALSE); +} + +static GDBusInterfaceInfo *interfaceInfo =3D NULL; + +void +virtDBusDomainSnapshotRegister(virtDBusConnect *connect, + GError **error) +{ + connect->domainSnapshotPath =3D g_strdup_printf("%s/domainsnapshot", c= onnect->connectPath); + + if (!interfaceInfo) { + interfaceInfo =3D virtDBusGDBusLoadIntrospectData(VIRT_DBUS_DOMAIN= _SNAPSHOT_INTERFACE, + error); + if (!interfaceInfo) + return; + } + + virtDBusGDBusRegisterSubtree(connect->bus, + connect->domainSnapshotPath, + interfaceInfo, + virtDBusDomainSnapshotEnumerate, + virtDBusDomainSnapshotMethodTable, + virtDBusDomainSnapshotPropertyTable, + connect); +} diff --git a/src/domainsnapshot.h b/src/domainsnapshot.h new file mode 100644 index 0000000..7d8a938 --- /dev/null +++ b/src/domainsnapshot.h @@ -0,0 +1,9 @@ +#pragma once + +#include "connect.h" + +#define VIRT_DBUS_DOMAIN_SNAPSHOT_INTERFACE "org.libvirt.DomainSnapshot" + +void +virtDBusDomainSnapshotRegister(virtDBusConnect *connect, + GError **error); diff --git a/src/meson.build b/src/meson.build index de96596..1839c79 100644 --- a/src/meson.build +++ b/src/meson.build @@ -16,6 +16,7 @@ exe_libvirt_dbus =3D executable( [ 'connect.c', 'domain.c', + 'domainsnapshot.c', 'events.c', 'gdbus.c', 'interface.c', diff --git a/src/util.c b/src/util.c index 103bb29..71ffba5 100644 --- a/src/util.c +++ b/src/util.c @@ -3,6 +3,9 @@ #include #include =20 +/* result of strlen("_00000000_1111_2222_3333_444444444444") */ +#define VIRT_DBUS_UUID_LEN 37 + static const GDBusErrorEntry virtDBusUtilErrorEntries[] =3D { { VIRT_DBUS_ERROR_LIBVIRT, "org.libvirt.Error" }, }; @@ -279,6 +282,56 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains) g_free(domains); } =20 +virDomainSnapshotPtr +virtDBusUtilVirDomainSnapshotFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *domainSnapshotPath) +{ + g_autofree gchar *uuidStr =3D NULL; + g_autofree gchar *snapshotName =3D NULL; + g_autoptr(virDomain) domain =3D NULL; + gsize prefixLen =3D strlen(domainSnapshotPath) + 1; + g_autofree gchar *tmp =3D g_strdup(path + prefixLen); + + tmp[VIRT_DBUS_UUID_LEN] =3D 0; + + uuidStr =3D virtDBusUtilDecodeUUID(tmp); + snapshotName =3D virtDBusUtilDecodeStr(tmp + VIRT_DBUS_UUID_LEN + 1); + + domain =3D virDomainLookupByUUIDString(connection, uuidStr); + + return virDomainSnapshotLookupByName(domain, snapshotName, 0); +} + +gchar * +virtDBusUtilBusPathForVirDomainSnapshot(virDomainPtr domain, + virDomainSnapshotPtr domainSnapsho= t, + const gchar *domainSnapshotPath) +{ + const gchar *snapshotName =3D NULL; + gchar uuidStr[VIR_UUID_STRING_BUFLEN] =3D ""; + g_autofree const gchar *encodedDomainNameStr =3D NULL; + g_autofree const gchar *encodedSnapshotNameStr =3D NULL; + + virDomainGetUUIDString(domain, uuidStr); + + snapshotName =3D virDomainSnapshotGetName(domainSnapshot); + encodedDomainNameStr =3D virtDBusUtilEncodeUUID(uuidStr); + encodedSnapshotNameStr =3D virtDBusUtilEncodeStr(snapshotName); + + return g_strdup_printf("%s/%s_%s", domainSnapshotPath, + encodedDomainNameStr, encodedSnapshotNameStr); +} + +void +virtDBusUtilVirDomainSnapshotListFree(virDomainSnapshotPtr* domainSnapshot= s) +{ + for (gint i =3D 0; domainSnapshots[i] !=3D NULL; i++) + virDomainSnapshotFree(domainSnapshots[i]); + + g_free(domainSnapshots); +} + virInterfacePtr virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection, const gchar *path, diff --git a/src/util.h b/src/util.h index b05c2fc..c0b314d 100644 --- a/src/util.h +++ b/src/util.h @@ -65,6 +65,22 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtil= VirDomainListFree); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecor= dListFree); =20 +virDomainSnapshotPtr +virtDBusUtilVirDomainSnapshotFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *domainSnapshotPath); + +gchar * +virtDBusUtilBusPathForVirDomainSnapshot(virDomainPtr domain, + virDomainSnapshotPtr domainSnapsho= t, + const gchar *domainSnapshotPath); + +void +virtDBusUtilVirDomainSnapshotListFree(virDomainSnapshotPtr* domainSnapshot= s); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSnapshot, virDomainSnapshotFree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainSnapshotPtr, virtDBusUtilVirDomainS= napshotListFree); + virInterfacePtr virtDBusUtilVirInterfaceFromBusPath(virConnectPtr connection, const gchar *path, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 20:20:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1572866680; cv=none; d=zoho.com; s=zohoarc; b=jPmLnc+SWMeObvhXu7b7RHNIMpLlRvs843CxcAo7AMU7wGgwLP6dvIq1mKj3bY1PKyzs+Ft2b9A6VrcIt2Rvdjt1ty8fg/b0XUubXB2G6RDwK4UIfu/BUFGh2S332t39psX38xqqIXyl7RK9PmYzSOECAGUIvAApcn2qSIoY52E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572866680; 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=6gM7xWSXBDh7vyohnxL352LUQrQH/6TeKrUWKntHPf0=; b=Hw6FkDPJFQQQXlnmrssCyHiOswOQGN4oiKvNQdj3ZnyWrKiYHnrm4O4h7wagf+d9tK/Ykinn0Hg1HN944ag6pP49rhD5ZgeWMeFOe2c2JmN4gZ/okNZnH9mroDoQl09AsfuWbMAsM1vvFojbxZDrIWcOKYrNVjCmWPW+9+bipBw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1572866680164310.9144340139677; Mon, 4 Nov 2019 03:24:40 -0800 (PST) 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-347-slnmWaoLNm67S9aaEHRISg-1; Mon, 04 Nov 2019 06:24:36 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 409AF800C73; Mon, 4 Nov 2019 11:24:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F7705D9CD; Mon, 4 Nov 2019 11:24:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BEF384BB65; Mon, 4 Nov 2019 11:24:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xA4BOSPL005968 for ; Mon, 4 Nov 2019 06:24:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id ABC7460C88; Mon, 4 Nov 2019 11:24:28 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCC7060E1C; Mon, 4 Nov 2019 11:24:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572866678; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6gM7xWSXBDh7vyohnxL352LUQrQH/6TeKrUWKntHPf0=; b=SKxqX46dXdb2JbuI+fssJ+Pue4jrnzbOSmRBe5ud8zliLW5XMADkJh7GCQ1l9dwWO90VLW r+d+r5Uclz72ok27T4WO8jCYurQCJr32cR1+SVzyg/wlqBwRnKOlGPikXvYVKp9grqzl9x xmkDJFHF65EbEj/TmcHNqWQTZKObdkM= From: Simon Kobyda To: libvir-list@redhat.com Date: Mon, 4 Nov 2019 12:24:09 +0100 Message-Id: <20191104112409.30613-3-skobyda@redhat.com> In-Reply-To: <20191104112409.30613-1-skobyda@redhat.com> References: <20191104112409.30613-1-skobyda@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Simon Kobyda Subject: [libvirt] [libvirt-dbus][PATCH v4 2/2] Implement snapshots APIs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: slnmWaoLNm67S9aaEHRISg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Simon Kobyda Reviewed-by: Pavel Hrdina --- data/org.libvirt.Domain.xml | 26 ++++ data/org.libvirt.DomainSnapshot.xml | 34 +++++ src/domain.c | 154 ++++++++++++++++++++ src/domainsnapshot.c | 216 ++++++++++++++++++++++++++++ tests/libvirttest.py | 12 ++ tests/meson.build | 1 + tests/test_domain.py | 8 ++ tests/test_snapshot.py | 45 ++++++ tests/xmldata.py | 6 + 9 files changed, 502 insertions(+) create mode 100755 tests/test_snapshot.py diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index b4ed495..3f108e7 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -350,6 +350,12 @@ + + + + + @@ -589,6 +595,26 @@ value=3D"See https://libvirt.org/html/libvirt-libvirt-domain.html#= virDomainShutdownFlags"/> + + + + + + + + + + + + + + + + + diff --git a/data/org.libvirt.DomainSnapshot.xml b/data/org.libvirt.DomainS= napshot.xml index 8ba059f..9e9daac 100644 --- a/data/org.libvirt.DomainSnapshot.xml +++ b/data/org.libvirt.DomainSnapshot.xml @@ -3,5 +3,39 @@ =20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/domain.c b/src/domain.c index 10fa8de..a656c6a 100644 --- a/src/domain.c +++ b/src/domain.c @@ -1857,6 +1857,49 @@ virtDBusDomainInjectNMI(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } =20 +static void +virtDBusDomainListDomainSnapshots(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virDomain) domain =3D NULL; + g_autoptr(virDomainSnapshotPtr) domainSnapshots =3D NULL; + guint flags; + GVariantBuilder builder; + GVariant *gdomainSnapshots; + + g_variant_get(inArgs, "(u)", &flags); + + domain =3D virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virDomainListAllSnapshots(domain, &domainSnapshots, flags) < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ao")); + + for (gint i =3D 0; domainSnapshots[i]; i++) { + g_autofree gchar *path =3D NULL; + path =3D virtDBusUtilBusPathForVirDomainSnapshot(domain, + domainSnapshots[i], + connect->domainSnap= shotPath); + + g_variant_builder_add(&builder, "o", path); + } + + gdomainSnapshots =3D g_variant_builder_end(&builder); + *outArgs =3D g_variant_new_tuple(&gdomainSnapshots, 1); +} + static void virtDBusDomainInterfaceAddresses(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -2966,6 +3009,113 @@ virtDBusDomainShutdown(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } =20 +static void +virtDBusDomainSnapshotCurrent(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autofree gchar *path =3D NULL; + g_autoptr(virDomain) domain =3D NULL; + g_autoptr(virDomainSnapshot) snapshot =3D NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + domain =3D virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + if (!virtDBusConnectOpen(connect, error)) + return; + + snapshot =3D virDomainSnapshotCurrent(domain, flags); + if (!snapshot) + return virtDBusUtilSetLastVirtError(error); + + path =3D virtDBusUtilBusPathForVirDomainSnapshot(domain, + snapshot, + connect->domainSnapshot= Path); + + *outArgs =3D g_variant_new("(o)", path); +} + +static void +virtDBusDomainSnapshotCreateXML(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autofree gchar *path =3D NULL; + g_autoptr(virDomain) domain =3D NULL; + g_autoptr(virDomainSnapshot) snapshot =3D NULL; + guint flags; + const gchar *xml; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + domain =3D virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + if (!virtDBusConnectOpen(connect, error)) + return; + + snapshot =3D virDomainSnapshotCreateXML(domain, xml, flags); + if (!snapshot) + return virtDBusUtilSetLastVirtError(error); + + path =3D virtDBusUtilBusPathForVirDomainSnapshot(domain, + snapshot, + connect->domainSnapshot= Path); + + *outArgs =3D g_variant_new("(o)", path); +} + +static void +virtDBusDomainSnapshotLookupByName(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autofree gchar *path =3D NULL; + g_autoptr(virDomain) domain =3D NULL; + g_autoptr(virDomainSnapshot) snapshot =3D NULL; + guint flags; + const gchar *name; + + g_variant_get(inArgs, "(&su)", &name, &flags); + + domain =3D virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + if (!virtDBusConnectOpen(connect, error)) + return; + + snapshot =3D virDomainSnapshotLookupByName(domain, name, flags); + if (!snapshot) + return virtDBusUtilSetLastVirtError(error); + + path =3D virtDBusUtilBusPathForVirDomainSnapshot(domain, + snapshot, + connect->domainSnapshot= Path); + + *outArgs =3D g_variant_new("(o)", path); +} + static void virtDBusDomainSuspend(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -3095,6 +3245,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodT= able[] =3D { { "HasManagedSaveImage", virtDBusDomainHasManagedSaveImage }, { "InjectNMI", virtDBusDomainInjectNMI }, { "InterfaceAddresses", virtDBusDomainInterfaceAddresses }, + { "ListDomainSnapshots", virtDBusDomainListDomainSnapshots }, { "ManagedSave", virtDBusDomainManagedSave }, { "ManagedSaveRemove", virtDBusDomainManagedSaveRemove }, { "MemoryPeek", virtDBusDomainMemoryPeek }, @@ -3132,6 +3283,9 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodT= able[] =3D { { "SetSchedulerParameters", virtDBusDomainSetSchedulerParameters }, { "SetTime", virtDBusDomainSetTime }, { "SetUserPassword", virtDBusDomainSetUserPassword }, + { "SnapshotCurrent", virtDBusDomainSnapshotCurrent }, + { "SnapshotCreateXML", virtDBusDomainSnapshotCreateXML }, + { "SnapshotLookupByName", virtDBusDomainSnapshotLookupByName }, { "Shutdown", virtDBusDomainShutdown }, { "Suspend", virtDBusDomainSuspend }, { "Undefine", virtDBusDomainUndefine }, diff --git a/src/domainsnapshot.c b/src/domainsnapshot.c index c523c9e..f3571a1 100644 --- a/src/domainsnapshot.c +++ b/src/domainsnapshot.c @@ -1,13 +1,229 @@ #include "domainsnapshot.h" +#include "domain.h" #include "util.h" =20 #include =20 +static virDomainSnapshotPtr +virtDBusDomainSnapshotGetVirDomainSnapshot(virtDBusConnect *connect, + const gchar *objectPath, + GError **error) +{ + virDomainSnapshotPtr domSnap; + + if (!virtDBusConnectOpen(connect, error)) + return NULL; + + domSnap =3D virtDBusUtilVirDomainSnapshotFromBusPath(connect->connecti= on, + objectPath, + connect->domainSnap= shotPath); + if (!domSnap) { + virtDBusUtilSetLastVirtError(error); + return NULL; + } + + return domSnap; +} + +static void +virtDBusDomainSnapshotDelete(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virDomainSnapshot) domainSnapshot =3D NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + domainSnapshot =3D virtDBusDomainSnapshotGetVirDomainSnapshot(connect, + objectPath, + error); + if (!domainSnapshot) + return; + + if (virDomainSnapshotDelete(domainSnapshot, flags) < 0) + return virtDBusUtilSetLastVirtError(error); +} + +static void +virtDBusDomainSnapshotGetParent(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virDomainSnapshot) domainSnapshot =3D NULL; + g_autoptr(virDomainSnapshot) parent =3D NULL; + guint flags; + g_autoptr(virDomain) domain =3D NULL; + g_autofree gchar *parentPath =3D NULL; + + g_variant_get(inArgs, "(u)", &flags); + + domainSnapshot =3D virtDBusDomainSnapshotGetVirDomainSnapshot(connect, + objectPath, + error); + if (!domainSnapshot) + return; + + parent =3D virDomainSnapshotGetParent(domainSnapshot, flags); + if (!parent) + return virtDBusUtilSetLastVirtError(error); + + domain =3D virDomainSnapshotGetDomain(domainSnapshot); + parentPath =3D virtDBusUtilBusPathForVirDomainSnapshot(domain, + parent, + connect->domainSn= apshotPath); + + *outArgs =3D g_variant_new("(o)", parentPath); +} + +static void +virtDBusDomainSnapshotGetXMLDesc(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virDomainSnapshot) domainSnapshot =3D NULL; + guint flags; + g_autofree gchar *xml =3D NULL; + + g_variant_get(inArgs, "(u)", &flags); + + domainSnapshot =3D virtDBusDomainSnapshotGetVirDomainSnapshot(connect, + objectPath, + error); + if (!domainSnapshot) + return; + + xml =3D virDomainSnapshotGetXMLDesc(domainSnapshot, flags); + if (!xml) + return virtDBusUtilSetLastVirtError(error); + + *outArgs =3D g_variant_new("(s)", xml); +} + +static void +virtDBusDomainSnapshotIsCurrent(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virDomainSnapshot) domainSnapshot =3D NULL; + guint flags; + gint isCurrent; + + g_variant_get(inArgs, "(u)", &flags); + + domainSnapshot =3D virtDBusDomainSnapshotGetVirDomainSnapshot(connect, + objectPath, + error); + if (!domainSnapshot) + return; + + isCurrent =3D virDomainSnapshotIsCurrent(domainSnapshot, flags); + if (isCurrent < 0) + return virtDBusUtilSetLastVirtError(error); + + *outArgs =3D g_variant_new("(b)", !!isCurrent); +} + +static void +virtDBusDomainSnapshotListAllChildren(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virDomainSnapshot) domainSnapshot =3D NULL; + g_autoptr(virDomainSnapshotPtr) snaps =3D NULL; + guint flags; + GVariantBuilder builder; + GVariant *gdomainSnapshots; + g_autoptr(virDomain) domain =3D NULL; + + g_variant_get(inArgs, "(u)", &flags); + + domainSnapshot =3D virtDBusDomainSnapshotGetVirDomainSnapshot(connect, + objectPath, + error); + if (!domainSnapshot) + return; + + if (virDomainSnapshotListAllChildren(domainSnapshot, &snaps, flags) < = 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ao")); + + domain =3D virDomainSnapshotGetDomain(domainSnapshot); + for (gint i =3D 0; snaps[i]; i++) { + g_autofree gchar *path =3D NULL; + path =3D virtDBusUtilBusPathForVirDomainSnapshot(domain, + snaps[i], + connect->domainSnap= shotPath); + + g_variant_builder_add(&builder, "o", path); + } + + gdomainSnapshots =3D g_variant_builder_end(&builder); + *outArgs =3D g_variant_new_tuple(&gdomainSnapshots, 1); +} + +static void +virtDBusDomainSnapshotRevert(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virDomainSnapshot) domainSnapshot =3D NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + domainSnapshot =3D virtDBusDomainSnapshotGetVirDomainSnapshot(connect, + objectPath, + error); + if (!domainSnapshot) + return; + + if (virDomainRevertToSnapshot(domainSnapshot, flags) < 0) + return virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusDomainSnapshotPropertyTable[] = =3D { { 0 } }; =20 static virtDBusGDBusMethodTable virtDBusDomainSnapshotMethodTable[] =3D { + { "Delete", virtDBusDomainSnapshotDelete }, + { "GetParent", virtDBusDomainSnapshotGetParent }, + { "GetXMLDesc", virtDBusDomainSnapshotGetXMLDesc }, + { "IsCurrent", virtDBusDomainSnapshotIsCurrent }, + { "ListChildren", virtDBusDomainSnapshotListAllChildren }, + { "Revert", virtDBusDomainSnapshotRevert }, { 0 } }; =20 diff --git a/tests/libvirttest.py b/tests/libvirttest.py index a442196..dd181c2 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -112,6 +112,18 @@ class BaseTestClass(): """ return self.node_device_create() =20 + @pytest.fixture + def snapshot_create(self): + """ Fixture to create simple domain snapshot on the test driver + + This fixture should be used in the setup of every test manipulating + with domain snaphots. + """ + _, test_domain =3D self.get_test_domain() + path =3D test_domain.SnapshotCreateXML(xmldata.minimal_snapshot_xm= l, 0) + obj =3D self.bus.get_object('org.libvirt', path) + return dbus.Interface(obj, 'org.libvirt.DomainSnapshot') + @pytest.fixture def storage_volume_create(self): """ Fixture to create dummy storage volume on the test driver diff --git a/tests/meson.build b/tests/meson.build index b6d4bd5..0ad5cdb 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -22,6 +22,7 @@ test('test_util', test_exec, suite: 'unit') python_tests =3D [ 'test_connect.py', 'test_domain.py', + 'test_snapshot.py', 'test_interface.py', 'test_network.py', 'test_nodedev.py', diff --git a/tests/test_domain.py b/tests/test_domain.py index b5879b4..624d25b 100755 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -2,6 +2,7 @@ =20 import dbus import libvirttest +import xmldata =20 DBUS_EXCEPTION_MISSING_FUNCTION =3D 'this function is not supported by the= connection driver' =20 @@ -160,6 +161,13 @@ class TestDomain(libvirttest.BaseTestClass): pinInfo =3D domain.GetVcpuPinInfo(0) assert pinInfo =3D=3D pinInfo_expected =20 + def test_snapshot(self): + obj, domain =3D self.get_test_domain() + domain.SnapshotCreateXML(xmldata.minimal_snapshot_xml, 0) + assert isinstance(domain.SnapshotCurrent(0), dbus.ObjectPath) + assert isinstance(domain.SnapshotLookupByName("my_snapshot", 0), d= bus.ObjectPath) + assert isinstance(domain.ListDomainSnapshots(0), dbus.Array) + =20 if __name__ =3D=3D '__main__': libvirttest.run() diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py new file mode 100755 index 0000000..566f4a6 --- /dev/null +++ b/tests/test_snapshot.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +import dbus +import libvirttest +import pytest + +EXCEPTION_NO_PARENT =3D 'does not have a parent' + + +@pytest.mark.usefixtures("snapshot_create") +class TestSnapshot(libvirttest.BaseTestClass): + """ Tests for methods and properties of the Snapshot snapshot + """ + + def test_snapshot_delete(self, snapshot_create): + snapshot_obj =3D snapshot_create + snapshot_obj.Delete(0) + + def test_snapshot_get_parent(self, snapshot_create): + snapshot_obj =3D snapshot_create + try: + snapshot_obj.GetParent(0) + except dbus.exceptions.DBusException as e: + if not any(EXCEPTION_NO_PARENT in arg for arg in e.args): + raise e + + def test_snapshot_get_xml(self, snapshot_create): + snapshot_obj =3D snapshot_create + assert isinstance(snapshot_obj.GetXMLDesc(0), dbus.String) + + def test_snapshot_get_is_current(self, snapshot_create): + snapshot_obj =3D snapshot_create + assert isinstance(snapshot_obj.IsCurrent(0), dbus.Boolean) + + def test_snapshot_list_children(self, snapshot_create): + snapshot_obj =3D snapshot_create + assert isinstance(snapshot_obj.ListChildren(0), dbus.Array) + + def test_snapshot_revert(self, snapshot_create): + snapshot_obj =3D snapshot_create + snapshot_obj.Revert(0) + + +if __name__ =3D=3D '__main__': + libvirttest.run() diff --git a/tests/xmldata.py b/tests/xmldata.py index 8075052..0146ccf 100644 --- a/tests/xmldata.py +++ b/tests/xmldata.py @@ -54,6 +54,12 @@ minimal_node_device_xml =3D ''' ''' =20 +minimal_snapshot_xml =3D ''' + + my_snapshot + +''' + minimal_storage_pool_xml =3D ''' foo --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list