[PATCH 06/11] xend: 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/xend_internal.c | 227 ++++++++++++------------------------------------
 1 file changed, 56 insertions(+), 171 deletions(-)

diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index b03b7bc..a8e276d 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -613,9 +613,6 @@ xenDaemonOpen_unix(virConnectPtr conn, const char *path)
     struct sockaddr_un *addr;
     xenUnifiedPrivatePtr priv;
 
-    if ((conn == NULL) || (path == NULL))
-        return -1;
-
     priv = (xenUnifiedPrivatePtr) conn->privateData;
     memset(&priv->addr, 0, sizeof(priv->addr));
     priv->addrfamily = AF_UNIX;
@@ -650,17 +647,12 @@ xenDaemonOpen_unix(virConnectPtr conn, const char *path)
 static int
 xenDaemonOpen_tcp(virConnectPtr conn, const char *host, const char *port)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
     struct addrinfo *res, *r;
     struct addrinfo hints;
     int saved_errno = EINVAL;
     int ret;
 
-    if ((conn == NULL) || (host == NULL) || (port == NULL))
-        return -1;
-
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
-
     priv->addrlen = 0;
     memset(&priv->addr, 0, sizeof(priv->addr));
 
@@ -928,14 +920,7 @@ static int
 xend_detect_config_version(virConnectPtr conn) {
     struct sexpr *root;
     const char *value;
-    xenUnifiedPrivatePtr priv;
-
-    if (!VIR_IS_CONNECT(conn)) {
-        virReportError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        return -1;
-    }
-
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
     root = sexpr_get(conn, "/xend/node/");
     if (root == NULL)
@@ -1013,9 +998,6 @@ sexpr_to_xend_domain_info(virDomainPtr domain, const struct sexpr *root,
 {
     int vcpus;
 
-    if ((root == NULL) || (info == NULL))
-        return -1;
-
     info->state = sexpr_to_xend_domain_state(domain, root);
     info->memory = sexpr_u64(root, "domain/memory") << 10;
     info->maxMem = sexpr_u64(root, "domain/maxmem") << 10;
@@ -1044,10 +1026,6 @@ sexpr_to_xend_node_info(const struct sexpr *root, virNodeInfoPtr info)
 {
     const char *machine;
 
-
-    if ((root == NULL) || (info == NULL))
-        return -1;
-
     machine = sexpr_node(root, "node/machine");
     if (machine == NULL) {
         info->model[0] = 0;
@@ -1200,12 +1178,7 @@ sexpr_to_domain(virConnectPtr conn, const struct sexpr *root)
     unsigned char uuid[VIR_UUID_BUFLEN];
     const char *name;
     const char *tmp;
-    xenUnifiedPrivatePtr priv;
-
-    if ((conn == NULL) || (root == NULL))
-        return NULL;
-
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
     if (sexpr_uuid(uuid, root, "domain/uuid") < 0)
         goto error;
@@ -1350,7 +1323,7 @@ xenDaemonClose(virConnectPtr conn ATTRIBUTE_UNUSED)
 int
 xenDaemonDomainSuspend(virDomainPtr domain)
 {
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -1376,7 +1349,7 @@ xenDaemonDomainSuspend(virDomainPtr domain)
 int
 xenDaemonDomainResume(virDomainPtr domain)
 {
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -1403,7 +1376,7 @@ xenDaemonDomainResume(virDomainPtr domain)
 int
 xenDaemonDomainShutdown(virDomainPtr domain)
 {
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -1433,7 +1406,7 @@ xenDaemonDomainReboot(virDomainPtr domain, unsigned int flags)
 {
     virCheckFlags(0, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -1470,7 +1443,7 @@ xenDaemonDomainDestroyFlags(virDomainPtr domain,
 {
     virCheckFlags(0, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -1498,15 +1471,13 @@ xenDaemonDomainGetOSType(virDomainPtr domain)
 {
     char *type;
     struct sexpr *root;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return NULL;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return NULL;
 
@@ -1545,8 +1516,7 @@ xenDaemonDomainGetOSType(virDomainPtr domain)
 int
 xenDaemonDomainSave(virDomainPtr domain, const char *filename)
 {
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
-        (filename == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -1583,8 +1553,7 @@ xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename,
 {
     virCheckFlags(VIR_DUMP_LIVE | VIR_DUMP_CRASH, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
-        (filename == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -1616,11 +1585,6 @@ xenDaemonDomainCoreDump(virDomainPtr domain, const char *filename,
 int
 xenDaemonDomainRestore(virConnectPtr conn, const char *filename)
 {
-    if ((conn == NULL) || (filename == NULL)) {
-        /* this should be caught at the interface but ... */
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
     return xend_op(conn, "", "op", "restore", "file", filename, NULL);
 }
 
@@ -1638,15 +1602,13 @@ xenDaemonDomainGetMaxMemory(virDomainPtr domain)
 {
     unsigned long long ret = 0;
     struct sexpr *root;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return 0;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return 0;
 
@@ -1677,15 +1639,13 @@ int
 xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
 {
     char buf[1024];
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return -1;
 
@@ -1714,15 +1674,13 @@ int
 xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory)
 {
     char buf[1024];
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return -1;
 
@@ -1739,7 +1697,7 @@ xenDaemonDomainFetch(virConnectPtr conn,
                      const char *cpus)
 {
     struct sexpr *root;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
     virDomainDefPtr def;
     int id;
     char * tty;
@@ -1752,8 +1710,6 @@ xenDaemonDomainFetch(virConnectPtr conn,
     if (root == NULL)
         return NULL;
 
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
-
     id = xenGetDomIdFromSxpr(root, priv->xendConfigVersion);
     xenUnifiedLock(priv);
     if (sexpr_lookup(root, "domain/image/hvm"))
@@ -1791,17 +1747,16 @@ char *
 xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags,
                           const char *cpus)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     virDomainDefPtr def;
     char *xml;
 
     /* 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;
     }
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
     if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
         /* fall-through to the next driver to handle */
@@ -1837,16 +1792,13 @@ xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
 {
     struct sexpr *root;
     int ret;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL) ||
-        (info == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return -1;
 
@@ -1915,11 +1867,6 @@ xenDaemonLookupByName(virConnectPtr conn, const char *domname)
     struct sexpr *root;
     virDomainPtr ret = NULL;
 
-    if ((conn == NULL) || (domname == NULL)) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return NULL;
-    }
-
     root = sexpr_get(conn, "/xend/domain/%s?detail=1", domname);
     if (root == NULL)
         goto error;
@@ -1946,15 +1893,6 @@ xenDaemonNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) {
     int ret = -1;
     struct sexpr *root;
 
-    if (!VIR_IS_CONNECT(conn)) {
-        virReportError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        return -1;
-    }
-    if (info == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
-
     root = sexpr_get(conn, "/xend/node/");
     if (root == NULL)
         return -1;
@@ -1979,16 +1917,6 @@ xenDaemonNodeGetTopology(virConnectPtr conn,
     int ret = -1;
     struct sexpr *root;
 
-    if (!VIR_IS_CONNECT(conn)) {
-        virReportError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        return -1;
-    }
-
-    if (caps == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
-
     root = sexpr_get(conn, "/xend/node/");
     if (root == NULL) {
         return -1;
@@ -2017,14 +1945,6 @@ xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer)
     int major, minor;
     unsigned long version;
 
-    if (!VIR_IS_CONNECT(conn)) {
-        virReportError(VIR_ERR_INVALID_CONN, __FUNCTION__);
-        return -1;
-    }
-    if (hvVer == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
     root = sexpr_get(conn, "/xend/node/");
     if (root == NULL)
         return -1;
@@ -2061,8 +1981,6 @@ xenDaemonListDomains(virConnectPtr conn, int *ids, int maxids)
     if (maxids == 0)
         return 0;
 
-    if ((ids == NULL) || (maxids < 0))
-        goto error;
     root = sexpr_get(conn, "/xend/domain");
     if (root == NULL)
         goto error;
@@ -2168,21 +2086,18 @@ xenDaemonDomainSetVcpusFlags(virDomainPtr domain, unsigned int vcpus,
                              unsigned int flags)
 {
     char buf[VIR_UUID_BUFLEN];
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     int max;
 
     virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
                   VIR_DOMAIN_VCPU_CONFIG |
                   VIR_DOMAIN_VCPU_MAXIMUM, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
-        || (vcpus < 1)) {
+    if (vcpus < 1) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if ((domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) ||
         (flags & VIR_DOMAIN_VCPU_MAXIMUM))
         return -2;
@@ -2254,16 +2169,14 @@ xenDaemonDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
 {
     char buf[VIR_UUID_BUFLEN], mapstr[sizeof(cpumap_t) * 64];
     int i, j, ret;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     virDomainDefPtr def = NULL;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
-     || (cpumap == NULL) || (maplen < 1) || (maplen > (int)sizeof(cpumap_t))) {
+    if (maplen > (int)sizeof(cpumap_t)) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
         mapstr[0] = '[';
         mapstr[1] = 0;
@@ -2335,19 +2248,17 @@ xenDaemonDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
 {
     struct sexpr *root;
     int ret;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
     virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
                   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;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     /* If xendConfigVersion is 2, then we can only report _LIVE (and
      * xm_internal reports _CONFIG).  If it is 3, then _LIVE and
      * _CONFIG are always in sync for a running system.  */
@@ -2404,12 +2315,7 @@ xenDaemonDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
     unsigned char *cpumap;
     int vcpu, cpu;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)
-        || (info == NULL) || (maxinfo < 1)) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
-    if (cpumaps != NULL && maplen < 1) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -2568,13 +2474,11 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc,
     int ret;
     char *sexpr;
     virDomainPtr dom = NULL;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;;
     virDomainDefPtr def;
 
     virCheckFlags(0, NULL);
 
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
-
     if (!(def = virDomainDefParseString(priv->caps, xmlDesc,
                                         1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
@@ -2630,7 +2534,7 @@ static int
 xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
                            unsigned int flags)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     char *sexpr = NULL;
     int ret = -1;
     virDomainDeviceDefPtr dev = NULL;
@@ -2641,13 +2545,11 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id < 0) {
         /* Cannot modify live config if domain is inactive */
         if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
@@ -2798,7 +2700,7 @@ int
 xenDaemonUpdateDeviceFlags(virDomainPtr domain, const char *xml,
                            unsigned int flags)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     char *sexpr = NULL;
     int ret = -1;
     virDomainDeviceDefPtr dev = NULL;
@@ -2809,13 +2711,11 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain, const char *xml,
     virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
                   VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id < 0) {
         /* Cannot modify live config if domain is inactive */
         if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
@@ -2912,7 +2812,7 @@ static int
 xenDaemonDetachDeviceFlags(virDomainPtr domain, const char *xml,
                            unsigned int flags)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     char class[8], ref[80];
     virDomainDeviceDefPtr dev = NULL;
     virDomainDefPtr def = NULL;
@@ -2922,13 +2822,11 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain, const char *xml,
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id < 0) {
         /* Cannot modify live config if domain is inactive */
         if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
@@ -3013,9 +2911,9 @@ xenDaemonDomainGetAutostart(virDomainPtr domain,
 {
     struct sexpr *root;
     const char *tmp;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -3023,7 +2921,6 @@ xenDaemonDomainGetAutostart(virDomainPtr domain,
     /* xm_internal.c (the support for defined domains from /etc/xen
      * config files used by old Xen) will handle this.
      */
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return -1;
 
@@ -3053,9 +2950,9 @@ xenDaemonDomainSetAutostart(virDomainPtr domain,
     virBuffer buffer = VIR_BUFFER_INITIALIZER;
     char *content = NULL;
     int ret = -1;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, __FUNCTION__);
         return -1;
     }
@@ -3063,7 +2960,6 @@ xenDaemonDomainSetAutostart(virDomainPtr domain,
     /* xm_internal.c (the support for defined domains from /etc/xen
      * config files used by old Xen) will handle this.
      */
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return -1;
 
@@ -3315,15 +3211,15 @@ xenDaemonDomainMigratePerform(virDomainPtr domain,
     return ret;
 }
 
-virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
+virDomainPtr
+xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc)
+{
     int ret;
     char *sexpr;
     virDomainPtr dom;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
     virDomainDefPtr def;
 
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
-
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return NULL;
 
@@ -3362,17 +3258,15 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
 }
 int xenDaemonDomainCreate(virDomainPtr domain)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     int ret;
     virDomainPtr tmp;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return -1;
 
@@ -3391,15 +3285,13 @@ int xenDaemonDomainCreate(virDomainPtr domain)
 
 int xenDaemonDomainUndefine(virDomainPtr domain)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return -1;
 
@@ -3457,8 +3349,6 @@ xenDaemonListDefinedDomains(virConnectPtr conn, char **const names, int maxnames
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return -1;
 
-    if ((names == NULL) || (maxnames < 0))
-        goto error;
     if (maxnames == 0)
         return 0;
 
@@ -3509,18 +3399,17 @@ error:
 static char *
 xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     struct sexpr *root;
     const char *ret = NULL;
     char *schedulertype = NULL;
 
-    if (domain->conn == NULL || domain->name == NULL) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return NULL;
     }
 
     /* Support only xendConfigVersion >=4 */
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("unsupported in xendConfigVersion < 4"));
@@ -3581,19 +3470,18 @@ static int
 xenDaemonGetSchedulerParameters(virDomainPtr domain,
                                 virTypedParameterPtr params, int *nparams)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     struct sexpr *root;
     char *sched_type = NULL;
     int sched_nparam = 0;
     int ret = -1;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
     /* Support only xendConfigVersion >=4 */
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("unsupported in xendConfigVersion < 4"));
@@ -3688,20 +3576,19 @@ static int
 xenDaemonSetSchedulerParameters(virDomainPtr domain,
                                 virTypedParameterPtr params, int nparams)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     struct sexpr *root;
     char *sched_type = NULL;
     int i;
     int sched_nparam = 0;
     int ret = -1;
 
-    if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
+    if (domain->name == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
 
     /* Support only xendConfigVersion >=4 and active domains */
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("unsupported in xendConfigVersion < 4"));
@@ -3799,7 +3686,7 @@ xenDaemonDomainBlockPeek(virDomainPtr domain, const char *path,
                          unsigned long long offset, size_t size,
                          void *buffer)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     struct sexpr *root = NULL;
     int fd = -1, ret = -1;
     virDomainDefPtr def;
@@ -3808,8 +3695,6 @@ xenDaemonDomainBlockPeek(virDomainPtr domain, const char *path,
     int vncport;
     const char *actual;
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
     if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
         return -2;              /* Decline, allow XM to handle it. */
 
-- 
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]