[PATCHv2 06/11] xen: use VIR_DELETE_ELEMENTS_N for xen domain and watch lists

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

 



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 | 14 ++------------
 src/xen/xs_internal.h |  2 +-
 5 files changed, 9 insertions(+), 41 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 6f08aad..969a3e1 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2383,19 +2383,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--;
-
+            ignore_value(VIR_DELETE_ELEMENTS_N(list->doms, i, list->count, 1));
             return 0;
         }
     }
diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h
index b3fbcff..e6ba867 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 10b7834..eee22b4 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--;
+            ignore_value(VIR_DELETE_ELEMENTS_N(priv->configInfoList->doms, i,
+                                               priv->configInfoList->count, 1));
             return 0;
         }
     }
diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c
index a91d409..c18051e 100644
--- a/src/xen/xs_internal.c
+++ b/src/xen/xs_internal.c
@@ -1246,18 +1246,8 @@ 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--;
+            ignore_value(VIR_DELETE_ELEMENTS_N(list->watches, i,
+                                               list->count, 1));
             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

--
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]