[PATCH 04/11] xm: Remove redundant validity checks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Arguments for driver entry points are checked in libvirt.c, so no need to
check again.
---
 src/xen/xm_internal.c | 76 ++++++++++++---------------------------------------
 1 file changed, 17 insertions(+), 59 deletions(-)

diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 003e8f7..1c1db54 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -481,7 +481,8 @@ int xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) {
     xenUnifiedPrivatePtr priv;
     const char *filename;
     xenXMConfCachePtr entry;
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -527,7 +528,7 @@ char *xenXMDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
 
     /* Flags checked by virDomainDefFormat */
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return NULL;
     }
@@ -560,7 +561,7 @@ int xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory) {
     xenXMConfCachePtr entry;
     int ret = -1;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -605,7 +606,7 @@ int xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
     xenXMConfCachePtr entry;
     int ret = -1;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -648,7 +649,7 @@ unsigned long long xenXMDomainGetMaxMemory(virDomainPtr domain) {
     xenXMConfCachePtr entry;
     unsigned long long ret = 0;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return 0;
     }
@@ -696,7 +697,7 @@ xenXMDomainSetVcpusFlags(virDomainPtr domain, unsigned int vcpus,
                   VIR_DOMAIN_VCPU_CONFIG |
                   VIR_DOMAIN_VCPU_MAXIMUM, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -780,7 +781,7 @@ xenXMDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
                   VIR_DOMAIN_VCPU_CONFIG |
                   VIR_DOMAIN_VCPU_MAXIMUM, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -829,8 +830,7 @@ int xenXMDomainPinVcpu(virDomainPtr domain,
     xenXMConfCachePtr entry;
     int ret = -1;
 
-    if (domain == NULL || domain->conn == NULL || domain->name == NULL
-        || cpumap == NULL || maplen < 1 || maplen > (int)sizeof(cpumap_t)) {
+    if (domain->name == NULL || maplen > (int)sizeof(cpumap_t)) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -876,21 +876,11 @@ int xenXMDomainPinVcpu(virDomainPtr domain,
  * Find an inactive domain based on its name
  */
 virDomainPtr xenXMDomainLookupByName(virConnectPtr conn, const char *domname) {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = conn->privateData;
     const char *filename;
     xenXMConfCachePtr entry;
     virDomainPtr ret = NULL;
 
-    if (!VIR_IS_CONNECT(conn)) {
-        virReportError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        return NULL;
-    }
-    if (domname == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return NULL;
-    }
-
-    priv = conn->privateData;
     xenUnifiedLock(priv);
 
     if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh(conn) < 0)
@@ -933,20 +923,10 @@ static int xenXMDomainSearchForUUID(const void *payload, const void *name ATTRIB
  */
 virDomainPtr xenXMDomainLookupByUUID(virConnectPtr conn,
                                      const unsigned char *uuid) {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = conn->privateData;
     xenXMConfCachePtr entry;
     virDomainPtr ret = NULL;
 
-    if (!VIR_IS_CONNECT(conn)) {
-        virReportError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        return NULL;
-    }
-    if (uuid == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return NULL;
-    }
-
-    priv = conn->privateData;
     xenUnifiedLock(priv);
 
     if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh(conn) < 0)
@@ -974,12 +954,10 @@ cleanup:
 int xenXMDomainCreate(virDomainPtr domain) {
     char *sexpr;
     int ret = -1;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv= (xenUnifiedPrivatePtr) domain->conn->privateData;
     const char *filename;
     xenXMConfCachePtr entry;
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id != -1)
         return -1;
 
@@ -1036,14 +1014,6 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml)
     xenXMConfCachePtr entry = NULL;
     xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
-    if (!VIR_IS_CONNECT(conn)) {
-        virReportError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        return NULL;
-    }
-    if (xml == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return NULL;
-    }
     if (conn->flags & VIR_CONNECT_RO)
         return NULL;
 
@@ -1177,7 +1147,7 @@ int xenXMDomainUndefine(virDomainPtr domain) {
     xenXMConfCachePtr entry;
     int ret = -1;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -1249,16 +1219,10 @@ static void xenXMListIterator(void *payload ATTRIBUTE_UNUSED, const void *name,
  * are currently running
  */
 int xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = conn->privateData;
     struct xenXMListIteratorContext ctx;
     int i, ret = -1;
 
-    if (!VIR_IS_CONNECT(conn)) {
-        virReportError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        return -1;
-    }
-
-    priv = conn->privateData;
     xenUnifiedLock(priv);
 
     if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh(conn) < 0)
@@ -1295,15 +1259,9 @@ cleanup:
  * based on number running
  */
 int xenXMNumOfDefinedDomains(virConnectPtr conn) {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = conn->privateData;
     int ret = -1;
 
-    if (!VIR_IS_CONNECT(conn)) {
-        virReportError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        return -1;
-    }
-
-    priv = conn->privateData;
     xenUnifiedLock(priv);
 
     if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh(conn) < 0)
@@ -1343,7 +1301,7 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain, const char *xml,
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
 
-    if ((!domain) || (!domain->conn) || (!domain->name) || (!xml)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -1440,7 +1398,7 @@ xenXMDomainDetachDeviceFlags(virDomainPtr domain, const char *xml,
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
 
-    if ((!domain) || (!domain->conn) || (!domain->name) || (!xml)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
-- 
1.7.11.7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]