[PATCH 01/11] xs: 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/xs_internal.c | 139 ++++++++++----------------------------------------
 1 file changed, 28 insertions(+), 111 deletions(-)

diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c
index 9308522..573c0c6 100644
--- a/src/xen/xs_internal.c
+++ b/src/xen/xs_internal.c
@@ -1,7 +1,7 @@
 /*
  * xs_internal.c: access to Xen Store
  *
- * Copyright (C) 2006, 2009-2012 Red Hat, Inc.
+ * Copyright (C) 2006, 2009-2013 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -86,12 +86,8 @@ static char **
 virConnectDoStoreList(virConnectPtr conn, const char *path,
                       unsigned int *nb)
 {
-    xenUnifiedPrivatePtr priv;
-
-    if (conn == NULL)
-        return NULL;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
     if (priv->xshandle == NULL || path == NULL || nb == NULL)
         return NULL;
 
@@ -113,12 +109,8 @@ virDomainDoStoreQuery(virConnectPtr conn, int domid, const char *path)
 {
     char s[256];
     unsigned int len = 0;
-    xenUnifiedPrivatePtr priv;
-
-    if (!conn)
-        return NULL;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
     if (priv->xshandle == NULL)
         return NULL;
 
@@ -143,16 +135,11 @@ virDomainDoStoreWrite(virDomainPtr domain, const char *path,
                       const char *value)
 {
     char s[256];
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv =
+        (xenUnifiedPrivatePtr) domain->conn->privateData;
     int ret = -1;
 
-    if (!VIR_IS_CONNECTED_DOMAIN(domain))
-        return -1;
-
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-    if (priv->xshandle == NULL)
-        return -1;
-    if (domain->conn->flags & VIR_CONNECT_RO)
+    if (priv->xshandle == NULL || domain->conn->flags & VIR_CONNECT_RO)
         return -1;
 
     snprintf(s, 255, "/local/domain/%d/%s", domain->id, path);
@@ -178,12 +165,9 @@ virDomainGetVM(virDomainPtr domain)
     char *vm;
     char query[200];
     unsigned int len;
-    xenUnifiedPrivatePtr priv;
-
-    if (!VIR_IS_CONNECTED_DOMAIN(domain))
-        return NULL;
+    xenUnifiedPrivatePtr priv =
+        (xenUnifiedPrivatePtr) domain->conn->privateData;
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     if (priv->xshandle == NULL)
         return NULL;
 
@@ -212,12 +196,8 @@ virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name)
     char s[256];
     char *ret = NULL;
     unsigned int len = 0;
-    xenUnifiedPrivatePtr priv;
-
-    if (!VIR_IS_CONNECTED_DOMAIN(domain))
-        return NULL;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr)domain->conn->privateData;
 
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
     if (priv->xshandle == NULL)
         return NULL;
 
@@ -326,14 +306,7 @@ xenStoreOpen(virConnectPtr conn,
 int
 xenStoreClose(virConnectPtr conn)
 {
-    xenUnifiedPrivatePtr priv;
-
-    if (conn == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
-
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
     if (xenStoreRemoveWatch(conn, "@introduceDomain", "introduceDomain") < 0) {
         VIR_DEBUG("Warning, could not remove @introduceDomain watch");
@@ -377,21 +350,9 @@ xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
     char *tmp, **tmp2;
     unsigned int nb_vcpus;
     char request[200];
-    xenUnifiedPrivatePtr priv;
-
-    if (!VIR_IS_CONNECTED_DOMAIN(domain))
-        return -1;
-
-    if ((domain == NULL) || (domain->conn == NULL) || (info == NULL)) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
-
-    priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-    if (priv->xshandle == NULL)
-        return -1;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr)domain->conn->privateData;
 
-    if (domain->id == -1)
+    if (priv->xshandle == NULL || domain->id == -1)
         return -1;
 
     tmp = virDomainDoStoreQuery(domain->conn, domain->id, "running");
@@ -482,8 +443,7 @@ xenStoreDomainSetMemory(virDomainPtr domain, unsigned long memory)
     int ret;
     char value[20];
 
-    if ((domain == NULL) || (domain->conn == NULL) ||
-        (memory < 1024 * MIN_XEN_GUEST_SIZE)) {
+    if (memory < 1024 * MIN_XEN_GUEST_SIZE) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
     }
@@ -512,14 +472,11 @@ xenStoreDomainGetMaxMemory(virDomainPtr domain)
 {
     char *tmp;
     unsigned long long ret = 0;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr)domain->conn->privateData;
 
-    if (!VIR_IS_CONNECTED_DOMAIN(domain))
-        return ret;
     if (domain->id == -1)
         return 0;
 
-    priv = domain->conn->privateData;
     xenUnifiedLock(priv);
     tmp = virDomainDoStoreQuery(domain->conn, domain->id, "memory/target");
     if (tmp != NULL) {
@@ -545,14 +502,8 @@ xenStoreNumOfDomains(virConnectPtr conn)
     char **idlist = NULL, *endptr;
     int i, ret = -1, realnum = 0;
     long id;
-    xenUnifiedPrivatePtr priv;
-
-    if (conn == NULL) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
     if (priv->xshandle == NULL) {
         virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         return -1;
@@ -632,16 +583,9 @@ out:
 int
 xenStoreListDomains(virConnectPtr conn, int *ids, int maxids)
 {
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
     int ret;
 
-    if ((conn == NULL) || (ids == NULL)) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
-
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
-
     xenUnifiedLock(priv);
     ret = xenStoreDoListDomains(conn, priv, ids, maxids);
     xenUnifiedUnlock(priv);
@@ -668,14 +612,8 @@ xenStoreLookupByName(virConnectPtr conn, const char *name)
     char prop[200], *tmp;
     int found = 0;
     struct xend_domain *xenddomain = NULL;
-    xenUnifiedPrivatePtr priv;
-
-    if ((conn == NULL) || (name == NULL)) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return NULL;
-    }
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
     if (priv->xshandle == NULL)
         return NULL;
 
@@ -732,19 +670,14 @@ int
 xenStoreDomainShutdown(virDomainPtr domain)
 {
     int ret;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr)domain->conn->privateData;
 
-    if ((domain == NULL) || (domain->conn == NULL)) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
     if (domain->id == -1 || domain->id == 0)
         return -1;
     /*
      * this is very hackish, the domU kernel probes for a special
      * node in the xenstore and launch the shutdown command if found.
      */
-    priv = domain->conn->privateData;
     xenUnifiedLock(priv);
     ret = virDomainDoStoreWrite(domain, "control/shutdown", "poweroff");
     xenUnifiedUnlock(priv);
@@ -766,21 +699,17 @@ int
 xenStoreDomainReboot(virDomainPtr domain, unsigned int flags)
 {
     int ret;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr)domain->conn->privateData;
 
     virCheckFlags(0, -1);
 
-    if ((domain == NULL) || (domain->conn == NULL)) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return -1;
-    }
     if (domain->id == -1 || domain->id == 0)
         return -1;
     /*
      * this is very hackish, the domU kernel probes for a special
      * node in the xenstore and launch the shutdown command if found.
      */
-    priv = domain->conn->privateData;
+
     xenUnifiedLock(priv);
     ret = virDomainDoStoreWrite(domain, "control/shutdown", "reboot");
     xenUnifiedUnlock(priv);
@@ -800,14 +729,10 @@ static char *
 xenStoreDomainGetOSType(virDomainPtr domain) {
     char *vm, *str = NULL;
 
-    if ((domain == NULL) || (domain->conn == NULL)) {
-        virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return NULL;
-    }
-
     vm = virDomainGetVM(domain);
     if (vm) {
-        xenUnifiedPrivatePtr priv = domain->conn->privateData;
+        xenUnifiedPrivatePtr priv =
+            (xenUnifiedPrivatePtr) domain->conn->privateData;
         xenUnifiedLock(priv);
         str = virDomainGetVMInfo(domain, vm, "image/ostype");
         xenUnifiedUnlock(priv);
@@ -904,12 +829,10 @@ xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac) {
     char dir[80], path[128], **list = NULL, *val = NULL;
     unsigned int len, i, num;
     char *ret = NULL;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
     if (id < 0)
         return NULL;
-
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
     if (priv->xshandle == NULL)
         return NULL;
     if (mac == NULL)
@@ -962,12 +885,10 @@ xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev) {
     char dir[80], path[128], **list = NULL, *val = NULL;
     unsigned int devlen, len, i, num;
     char *ret = NULL;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
     if (id < 0)
         return NULL;
-
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
     if (priv->xshandle == NULL)
         return NULL;
     if (dev == NULL)
@@ -1046,12 +967,10 @@ xenStoreDomainGetPCIID(virConnectPtr conn, int id, const char *bdf)
     char dir[80], path[128], **list = NULL, *val = NULL;
     unsigned int len, i, num;
     char *ret = NULL;
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
 
     if (id < 0)
         return NULL;
-
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
     if (priv->xshandle == NULL)
         return NULL;
     if (bdf == NULL)
@@ -1087,10 +1006,9 @@ xenStoreDomainGetPCIID(virConnectPtr conn, int id, const char *bdf)
 char *xenStoreDomainGetName(virConnectPtr conn,
                             int id) {
     char prop[200];
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
     unsigned int len;
 
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
     if (priv->xshandle == NULL)
         return NULL;
 
@@ -1107,12 +1025,11 @@ int xenStoreDomainGetUUID(virConnectPtr conn,
                           int id,
                           unsigned char *uuid) {
     char prop[200];
-    xenUnifiedPrivatePtr priv;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
     unsigned int len;
     char *uuidstr;
     int ret = 0;
 
-    priv = (xenUnifiedPrivatePtr) conn->privateData;
     if (priv->xshandle == NULL)
         return -1;
 
@@ -1335,7 +1252,7 @@ int xenStoreDomainIntroduced(virConnectPtr conn,
     int *new_domids;
     int nread;
 
-    xenUnifiedPrivatePtr priv = opaque;
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) opaque;
 
 retry:
     new_domain_cnt = xenStoreNumOfDomains(conn);
-- 
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]