From nobody Sun Apr 28 13:22:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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=1571829135; cv=none; d=zoho.com; s=zohoarc; b=mipbvJWqV4mpCk0c6Eb7thDnAgtVOd0+xKc07qUIG0NLDgiIXQEVBC+pJsTyTt4iKeSM/zLivvQcAPe5t5DuNwderiSwFfeXOls2msj76PO1Kq4mJpBDiaV00dNX8bDdb8QtfpQ1lwN3AHLG6fChItoJGhOalxFihXL2NIoDwGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571829135; 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=XZIjN4ivtWNb/0UTum2qn6nSSGip8Eilov6hTvAC1n4=; b=Nhw7J0ih5zcLl6HYf87R88gT2ndWIH2nfikkDQZDLWk9ohDnSHouli9Pwa3NEbuuY+YGhaJISmF0XB853e4ZyTKqNiSVaPKSwOgBp77ctf06DIh7npUbIBdvhbdS4POhqpo1+V4s70PVCaS7lY9K6JsUGIKQ1H3FWGnmyqwzsdE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1571829135934984.1217937760521; Wed, 23 Oct 2019 04:12:15 -0700 (PDT) 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-283-LfMyFtuzNIq87VcrqsOx9g-1; Wed, 23 Oct 2019 07:12:12 -0400 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 F10A0476; Wed, 23 Oct 2019 11:12:07 +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 5BDA55C1D4; Wed, 23 Oct 2019 11:12:06 +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 895141800535; Wed, 23 Oct 2019 11:12:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9NBBrO1021833 for ; Wed, 23 Oct 2019 07:11:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id C0DE660628; Wed, 23 Oct 2019 11:11:53 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F15D46061E; Wed, 23 Oct 2019 11:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571829134; 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=XZIjN4ivtWNb/0UTum2qn6nSSGip8Eilov6hTvAC1n4=; b=BjjJbENauFW62vlN+ceLmG3ur1WAGpM8YLzsfQBM4grCQrTMxrNd/C/aMNu+HHFd1MNom+ zsSqxie0W7pwS8m8sCrZjyeBdz28uxYjY0ZnfzorDwiHHUKbSgSRVPE1Vg+PRfkViKU+b/ jdK1u3Ld1N8nx0ByCffRhWPczyIqh8M= From: Simon Kobyda To: libvir-list@redhat.com Date: Wed, 23 Oct 2019 13:11:45 +0200 Message-Id: <20191023111146.23628-2-skobyda@redhat.com> In-Reply-To: <20191023111146.23628-1-skobyda@redhat.com> References: <20191023111146.23628-1-skobyda@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Simon Kobyda Subject: [libvirt] [libvirt-dbus][PATCH v3 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.16 X-MC-Unique: LfMyFtuzNIq87VcrqsOx9g-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 --- 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 ++++++ 8 files changed, 168 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/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 Sun Apr 28 13:22:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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=1571829145; cv=none; d=zoho.com; s=zohoarc; b=hmhPgtruphcjL5N0WwIlT/m2szKn+b7PMA+p0fY6kSXZsF1Fk/EuouuuXMXeobkXF+2uuroppIlKeMjjUKoxNBrkxkrf6GyO8IYcZ9T6Gttu3fLJsAJWXkeFcxp6TkRqZZO4NjMtNOBK/df78SWy71pR1Oh/ySlbHoecYjDMFJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571829145; 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=PdZIinWjdwn5t8PQVQjr32TdP2ynFjTprMGvg/ukTDw=; b=fOIXSIuV8pIE+yD5Vb+Z9TvHTe6uiyHp9sOV2/YxMMaVtgBa5pLBCm6N1rl5HPCgxp8YVld8wvmUAGvMoM0lVg1hXG8bYX36VfUjmImxz11Kenx6calWkW3/Mo/U6zXTDPRCPiUFZOXd7d124NlsqWihvWTwv0R8BJd1BLHa6xc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1571829145111533.1167715290433; Wed, 23 Oct 2019 04:12:25 -0700 (PDT) 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-263-iN_g27WOOgiYTIchTI_Glg-1; Wed, 23 Oct 2019 07:12:21 -0400 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 0BC59476; Wed, 23 Oct 2019 11:12:17 +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 D02896061E; Wed, 23 Oct 2019 11:12:16 +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 626894E9F5; Wed, 23 Oct 2019 11:12:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9NBBsFI021841 for ; Wed, 23 Oct 2019 07:11:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id E0017608C0; Wed, 23 Oct 2019 11:11:54 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C1C56061E; Wed, 23 Oct 2019 11:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571829143; 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=PdZIinWjdwn5t8PQVQjr32TdP2ynFjTprMGvg/ukTDw=; b=XeByKFzkOfxr0w8hbR21CHFdnOnONaGHIaE2uqkClF1Cg+mRiM/h2GnngqPOhUoV1r/hn3 m49TJHAeDs4OhrUMADel61edVz7GJKz5wyIMBwOW9o1+ffkQZgSmb5wyW+PPqvn0UWmEkT jrgGwW8pxSTqnTL9Kj89azpyZcU/VU4= From: Simon Kobyda To: libvir-list@redhat.com Date: Wed, 23 Oct 2019 13:11:46 +0200 Message-Id: <20191023111146.23628-3-skobyda@redhat.com> In-Reply-To: <20191023111146.23628-1-skobyda@redhat.com> References: <20191023111146.23628-1-skobyda@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Simon Kobyda Subject: [libvirt] [libvirt-dbus][PATCH v3 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.13 X-MC-Unique: iN_g27WOOgiYTIchTI_Glg-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 --- data/org.libvirt.Domain.xml | 26 ++++ data/org.libvirt.DomainSnapshot.xml | 34 +++++ src/domain.c | 154 ++++++++++++++++++++++ src/domainsnapshot.c | 196 +++++++++++++++++++++++++++- tests/libvirttest.py | 12 ++ tests/meson.build | 1 + tests/test_domain.py | 8 ++ tests/test_snapshot.py | 43 ++++++ tests/xmldata.py | 6 + 9 files changed, 479 insertions(+), 1 deletion(-) 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..8e2cce0 100644 --- a/src/domainsnapshot.c +++ b/src/domainsnapshot.c @@ -1,14 +1,208 @@ #include "domainsnapshot.h" +#include "domain.h" #include "util.h" =20 #include =20 +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 virtDBusUtilVirDomainSnapshotFromBusPath(connect->c= onnection, + objectPath, + connect->dom= ainSnapshotPath); + 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 virtDBusUtilVirDomainSnapshotFromBusPath(connect->c= onnection, + objectPath, + connect->dom= ainSnapshotPath); + 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 virtDBusUtilVirDomainSnapshotFromBusPath(connect->c= onnection, + objectPath, + connect->dom= ainSnapshotPath); + 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 virtDBusUtilVirDomainSnapshotFromBusPath(connect->c= onnection, + objectPath, + connect->dom= ainSnapshotPath); + 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 virtDBusUtilVirDomainSnapshotFromBusPath(connect->c= onnection, + objectPath, + connect->dom= ainSnapshotPath); + 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 virtDBusUtilVirDomainSnapshotFromBusPath(connect->c= onnection, + objectPath, + connect->dom= ainSnapshotPath); + if (!domainSnapshot) + return; + + if (virDomainRevertToSnapshot(domainSnapshot, flags) < 0) + return virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusDomainSnapshotPropertyTable[] = =3D { { 0 } }; =20 static virtDBusGDBusMethodTable virtDBusDomainSnapshotMethodTable[] =3D { - { 0 } + { "Delete", virtDBusDomainSnapshotDelete }, + { "GetParent", virtDBusDomainSnapshotGetParent }, + { "GetXMLDesc", virtDBusDomainSnapshotGetXMLDesc }, + { "IsCurrent", virtDBusDomainSnapshotIsCurrent }, + { "ListChildren", virtDBusDomainSnapshotListAllChildren }, + { "Revert", virtDBusDomainSnapshotRevert }, }; =20 static gchar ** 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..fdb5aa4 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..e9cc5b9 --- /dev/null +++ b/tests/test_snapshot.py @@ -0,0 +1,43 @@ +#!/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