[libvirt] [PATCHv4 08/17] xen: use VIR_DELETE_ELEMENT for xen domain and watch lists

Laine Stump laine at laine.org
Mon Dec 10 21:20:29 UTC 2012


Replaces memmove/VIR_REALLOC_N for xenUnifiedDomainList and
XenStoreWatchList.
---
 src/xen/xen_driver.c  | 14 +-------------
 src/xen/xen_driver.h  |  4 ++--
 src/xen/xen_inotify.c | 16 +++-------------
 src/xen/xs_internal.c | 13 +------------
 src/xen/xs_internal.h |  2 +-
 5 files changed, 8 insertions(+), 41 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index d2de141..b7159c6 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2495,19 +2495,7 @@ xenUnifiedRemoveDomainInfo(xenUnifiedDomainInfoListPtr list,
 
             VIR_FREE(list->doms[i]->name);
             VIR_FREE(list->doms[i]);
-
-            if (i < (list->count - 1))
-                memmove(list->doms + i,
-                        list->doms + i + 1,
-                        sizeof(*(list->doms)) *
-                                (list->count - (i + 1)));
-
-            if (VIR_REALLOC_N(list->doms,
-                              list->count - 1) < 0) {
-                ; /* Failure to reduce memory allocation isn't fatal */
-            }
-            list->count--;
-
+            VIR_DELETE_ELEMENT(list->doms, i, list->count);
             return 0;
         }
     }
diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h
index 078980e..b0aae9e 100644
--- a/src/xen/xen_driver.h
+++ b/src/xen/xen_driver.h
@@ -1,7 +1,7 @@
 /*
  * xen_unified.c: Unified Xen driver.
  *
- * Copyright (C) 2007, 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2007, 2010-2012 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
@@ -141,7 +141,7 @@ typedef struct _xenUnifiedDomainInfo xenUnifiedDomainInfo;
 typedef xenUnifiedDomainInfo *xenUnifiedDomainInfoPtr;
 
 struct _xenUnifiedDomainInfoList {
-    unsigned int count;
+    size_t count;
     xenUnifiedDomainInfoPtr *doms;
 };
 typedef struct _xenUnifiedDomainInfoList xenUnifiedDomainInfoList;
diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c
index 2e40015..fe9a813 100644
--- a/src/xen/xen_inotify.c
+++ b/src/xen/xen_inotify.c
@@ -4,7 +4,7 @@
  *                /etc/xen
  *                /var/lib/xend/domains
  *
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 Red Hat, Inc.
  * Copyright (C) 2008 VirtualIron
  *
  * This library is free software; you can redistribute it and/or
@@ -174,18 +174,8 @@ xenInotifyXendDomainsDirRemoveEntry(virConnectPtr conn,
         if (!memcmp(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) {
             VIR_FREE(priv->configInfoList->doms[i]->name);
             VIR_FREE(priv->configInfoList->doms[i]);
-
-            if (i < (priv->configInfoList->count - 1))
-                memmove(priv->configInfoList->doms + i,
-                        priv->configInfoList->doms + i + 1,
-                        sizeof(*(priv->configInfoList->doms)) *
-                                (priv->configInfoList->count - (i + 1)));
-
-            if (VIR_REALLOC_N(priv->configInfoList->doms,
-                              priv->configInfoList->count - 1) < 0) {
-                ; /* Failure to reduce memory allocation isn't fatal */
-            }
-            priv->configInfoList->count--;
+            VIR_DELETE_ELEMENT(priv->configInfoList->doms, i,
+                               priv->configInfoList->count);
             return 0;
         }
     }
diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c
index 8a0af62..1b8d3c7 100644
--- a/src/xen/xs_internal.c
+++ b/src/xen/xs_internal.c
@@ -1246,18 +1246,7 @@ int xenStoreRemoveWatch(virConnectPtr conn,
             VIR_FREE(list->watches[i]->path);
             VIR_FREE(list->watches[i]->token);
             VIR_FREE(list->watches[i]);
-
-            if (i < (list->count - 1))
-                memmove(list->watches + i,
-                        list->watches + i + 1,
-                        sizeof(*(list->watches)) *
-                                (list->count - (i + 1)));
-
-            if (VIR_REALLOC_N(list->watches,
-                              list->count - 1) < 0) {
-                ; /* Failure to reduce memory allocation isn't fatal */
-            }
-            list->count--;
+            VIR_DELETE_ELEMENT(list->watches, i, list->count);
             return 0;
         }
     }
diff --git a/src/xen/xs_internal.h b/src/xen/xs_internal.h
index 84d0d29..e3799b9 100644
--- a/src/xen/xs_internal.h
+++ b/src/xen/xs_internal.h
@@ -89,7 +89,7 @@ typedef struct _xenStoreWatch xenStoreWatch;
 typedef xenStoreWatch *xenStoreWatchPtr;
 
 struct _xenStoreWatchList {
-    unsigned int count;
+    size_t count;
     xenStoreWatchPtr *watches;
 };
 typedef struct _xenStoreWatchList xenStoreWatchList;
-- 
1.7.11.7




More information about the libvir-list mailing list