From nobody Mon Feb 9 18:19:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1508152136045373.9904513939998; Mon, 16 Oct 2017 04:08:56 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 0696A3680B; Mon, 16 Oct 2017 11:08:55 +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 D769160618; Mon, 16 Oct 2017 11:08:54 +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 9A27018355DB; Mon, 16 Oct 2017 11:08:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9GB6eid008744 for ; Mon, 16 Oct 2017 07:06:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 200F95D964; Mon, 16 Oct 2017 11:06:40 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C5A85D961 for ; Mon, 16 Oct 2017 11:06:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0696A3680B Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Date: Mon, 16 Oct 2017 13:06:23 +0200 Message-Id: <7b9d0d4823d05967e5a876149861f11b0dd1ee87.1508151956.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/14] lib: introduce virDomainSetLifecycleAction() API 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 16 Oct 2017 11:08:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- docs/formatdomain.html.in | 6 +++++ include/libvirt/libvirt-domain.h | 28 ++++++++++++++++++++ src/conf/domain_conf.h | 19 -------------- src/driver-hypervisor.h | 7 +++++ src/libvirt-domain.c | 56 ++++++++++++++++++++++++++++++++++++= ++++ src/libvirt_public.syms | 5 ++++ src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 14 +++++++++- 8 files changed, 116 insertions(+), 20 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index b93ace7cba..cb19a547fe 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1623,6 +1623,12 @@ =20

+ The lifecycle events can be configured via + virDomainSetLifecycleAction() API + since 3.9.0 (QEMU only). +

+ +

The on_lockfailure element (since 1.0.0) may be used to configure what action should be taken when a lock manager loses resource locks. The following diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 9fb94a9837..4048acf38a 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -4728,4 +4728,32 @@ int virDomainSetBlockThreshold(virDomainPtr domain, unsigned long long threshold, unsigned int flags); =20 +typedef enum { + VIR_DOMAIN_LIFECYCLE_POWEROFF =3D 0, + VIR_DOMAIN_LIFECYCLE_REBOOT =3D 1, + VIR_DOMAIN_LIFECYCLE_CRASH =3D 2, + +# ifdef VIR_ENUM_SENTINELS + VIR_DOMAIN_LIFECYCLE_LAST +# endif +} virDomainLifecycle; + +typedef enum { + VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY =3D 0, + VIR_DOMAIN_LIFECYCLE_ACTION_RESTART =3D 1, + VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME =3D 2, + VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE =3D 3, + VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY =3D 4, + VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART =3D 5, + +# ifdef VIR_ENUM_SENTINELS + VIR_DOMAIN_LIFECYCLE_ACTION_LAST +# endif +} virDomainLifecycleAction; + +int virDomainSetLifecycleAction(virDomainPtr domain, + unsigned int type, + unsigned int action, + unsigned int flags); + #endif /* __VIR_LIBVIRT_DOMAIN_H__ */ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 38b966f6de..8240433611 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1792,25 +1792,6 @@ typedef enum { } virDomainCapsFeature; =20 typedef enum { - VIR_DOMAIN_LIFECYCLE_POWEROFF, - VIR_DOMAIN_LIFECYCLE_REBOOT, - VIR_DOMAIN_LIFECYCLE_CRASH, - - VIR_DOMAIN_LIFECYCLE_LAST -} virDomainLifecycle; - -typedef enum { - VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, - VIR_DOMAIN_LIFECYCLE_ACTION_RESTART, - VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME, - VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE, - VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY, - VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART, - - VIR_DOMAIN_LIFECYCLE_ACTION_LAST -} virDomainLifecycleAction; - -typedef enum { VIR_DOMAIN_LOCK_FAILURE_DEFAULT, VIR_DOMAIN_LOCK_FAILURE_POWEROFF, VIR_DOMAIN_LOCK_FAILURE_RESTART, diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 4de0581c3f..ce0e2b2525 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1277,6 +1277,12 @@ typedef int unsigned long long threshold, unsigned int flags); =20 +typedef int +(*virDrvDomainSetLifecycleAction)(virDomainPtr domain, + unsigned int type, + unsigned int action, + unsigned int flags); + =20 typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1521,6 +1527,7 @@ struct _virHypervisorDriver { virDrvDomainSetGuestVcpus domainSetGuestVcpus; virDrvDomainSetVcpu domainSetVcpu; virDrvDomainSetBlockThreshold domainSetBlockThreshold; + virDrvDomainSetLifecycleAction domainSetLifecycleAction; }; =20 =20 diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index fc2e4ce381..a51d8e3820 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12035,3 +12035,59 @@ virDomainSetBlockThreshold(virDomainPtr domain, virDispatchError(domain->conn); return -1; } + + +/** + * virDomainSetLifecycleAction: + * @domain: pointer to domain object + * @type: the lifecycle type from virDomainLifecycle + * @action: the action type from virDomainLifecycleAction + * @flags: bitwise-OR of virDomainModificationImpact + * + * Changes the actions of lifecycle events for domain represented as + * $action in the domain XML. + * + * Returns 0 on success, -1 on failure. + */ +int virDomainSetLifecycleAction(virDomainPtr domain, + unsigned int type, + unsigned int action, + unsigned int flags) +{ + VIR_DOMAIN_DEBUG(domain, "type=3D'%u' action=3D'%u' flags=3D'0x%x'", + type, action, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + virCheckReadOnlyGoto(domain->conn->flags, error); + + if (type >=3D VIR_DOMAIN_LIFECYCLE_LAST) { + virReportError(VIR_ERR_INVALID_ARG, + _("invalid lifecycle type '%u'"), type); + goto error; + } + + if (action >=3D VIR_DOMAIN_LIFECYCLE_ACTION_LAST) { + virReportError(VIR_ERR_INVALID_ARG, + _("invalid lifecycle action '%u'"), action); + goto error; + } + + if (domain->conn->driver->domainSetLifecycleAction) { + int ret; + ret =3D domain->conn->driver->domainSetLifecycleAction(domain, + type, + action, + flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(domain->conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 4986019431..0efde25a7f 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -774,4 +774,9 @@ LIBVIRT_3.7.0 { virDomainManagedSaveGetXMLDesc; virDomainManagedSaveDefineXML; } LIBVIRT_3.4.0; + +LIBVIRT_3.9.0 { + global: + virDomainSetLifecycleAction; +} LIBVIRT_3.7.0; # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 00e8086d51..06719bb825 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -8497,6 +8497,7 @@ static virHypervisorDriver hypervisor_driver =3D { .domainSetGuestVcpus =3D remoteDomainSetGuestVcpus, /* 2.0.0 */ .domainSetVcpu =3D remoteDomainSetVcpu, /* 3.1.0 */ .domainSetBlockThreshold =3D remoteDomainSetBlockThreshold, /* 3.2.0 */ + .domainSetLifecycleAction =3D remoteDomainSetLifecycleAction /* 3.9.0 = */ }; =20 static virNetworkDriver network_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index e3014f66bc..0aed25220d 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -3433,6 +3433,12 @@ struct remote_domain_set_block_threshold_args { unsigned int flags; }; =20 +struct remote_domain_set_lifecycle_action_args { + remote_nonnull_domain dom; + unsigned int type; + unsigned int action; + unsigned int flags; +}; =20 /*----- Protocol. -----*/ =20 @@ -6108,5 +6114,11 @@ enum remote_procedure { * @acl: domain:write * @acl: domain:hibernate */ - REMOTE_PROC_DOMAIN_MANAGED_SAVE_DEFINE_XML =3D 389 + REMOTE_PROC_DOMAIN_MANAGED_SAVE_DEFINE_XML =3D 389, + + /** + * @generate: both + * @acl: domain:write + */ + REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION =3D 390 }; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list