[libvirt] [PATCH v2 1/9] Add function that raises error if domain is not active

Clementine Hayat clem at lse.epita.fr
Tue Apr 17 22:13:26 UTC 2018


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 <clem at lse.epita.fr>
---
 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 d23182f18..dadb63360 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6003,6 +6003,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 bbaa24137..122a051b2 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 cab324c4d..99b5a0235 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -474,6 +474,7 @@ virDomainNostateReasonTypeFromString;
 virDomainNostateReasonTypeToString;
 virDomainObjAssignDef;
 virDomainObjBroadcast;
+virDomainObjCheckActive;
 virDomainObjCopyPersistentDef;
 virDomainObjEndAPI;
 virDomainObjFormat;
-- 
2.17.0




More information about the libvir-list mailing list