From 749282d400213c7af7ae28c10e286960b9a5b9f3 Mon Sep 17 00:00:00 2001 From: Clementine Hayat Date: Tue, 17 Apr 2018 22:13:26 +0000 Subject: [PATCH] Add function that raises error if domain is not active MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a function named virDomainObjCheckIsActive in src/conf/domain_conf.c. It calls virDomainObjIsActive, raises error if necessary and returns. There is a lot of occurence of this pattern and it will save 3 lines on each call. Signed-off-by: Clementine Hayat Reviewed-by: Ján Tomko Signed-off-by: Ján Tomko --- src/conf/domain_conf.c | 11 +++++++++++ src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 14 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e2345bba17..ae2135263e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5997,6 +5997,17 @@ virDomainDefValidate(virDomainDefPtr def, return 0; } +int +virDomainObjCheckActive(virDomainObjPtr dom) +{ + if (!virDomainObjIsActive(dom)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + return -1; + } + return 0; +} + /** * virDomainDeviceLoadparmIsValid diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index bbaa24137d..122a051b2a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2722,6 +2722,8 @@ virDomainObjIsActive(virDomainObjPtr dom) return dom->def->id != -1; } +int virDomainObjCheckActive(virDomainObjPtr dom); + int virDomainDefSetVcpusMax(virDomainDefPtr def, unsigned int vcpus, virDomainXMLOptionPtr xmlopt); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0918e69525..b31f599bd2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -474,6 +474,7 @@ virDomainNostateReasonTypeFromString; virDomainNostateReasonTypeToString; virDomainObjAssignDef; virDomainObjBroadcast; +virDomainObjCheckActive; virDomainObjCopyPersistentDef; virDomainObjEndAPI; virDomainObjFormat;