mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
src/xen: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
fb9bec1055
commit
ce17ddacca
@ -2879,13 +2879,9 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list,
|
||||
info->id = id;
|
||||
|
||||
/* Make space on list */
|
||||
n = list->count;
|
||||
if (VIR_REALLOC_N(list->doms, n + 1) < 0) {
|
||||
if (VIR_APPEND_ELEMENT(list->doms, list->count, info) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
list->doms[n] = info;
|
||||
list->count++;
|
||||
return 0;
|
||||
error:
|
||||
if (info)
|
||||
@ -2915,18 +2911,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;
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ typedef struct _xenUnifiedDomainInfo xenUnifiedDomainInfo;
|
||||
typedef xenUnifiedDomainInfo *xenUnifiedDomainInfoPtr;
|
||||
|
||||
struct _xenUnifiedDomainInfoList {
|
||||
unsigned int count;
|
||||
size_t count;
|
||||
xenUnifiedDomainInfoPtr *doms;
|
||||
};
|
||||
typedef struct _xenUnifiedDomainInfoList xenUnifiedDomainInfoList;
|
||||
|
@ -173,17 +173,8 @@ xenInotifyXendDomainsDirRemoveEntry(virConnectPtr conn, const char *fname)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1262,10 +1262,8 @@ xenXMDomainAttachDeviceFlags(virConnectPtr conn,
|
||||
|
||||
case VIR_DOMAIN_DEVICE_NET:
|
||||
{
|
||||
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0)
|
||||
if (VIR_APPEND_ELEMENT(def->nets, def->nnets, dev->data.net) < 0)
|
||||
goto cleanup;
|
||||
def->nets[def->nnets++] = dev->data.net;
|
||||
dev->data.net = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1348,12 +1346,7 @@ xenXMDomainDetachDeviceFlags(virConnectPtr conn,
|
||||
dev->data.disk->dst &&
|
||||
STREQ(def->disks[i]->dst, dev->data.disk->dst)) {
|
||||
virDomainDiskDefFree(def->disks[i]);
|
||||
if (i < (def->ndisks - 1))
|
||||
memmove(def->disks + i,
|
||||
def->disks + i + 1,
|
||||
sizeof(*def->disks) *
|
||||
(def->ndisks - (i + 1)));
|
||||
def->ndisks--;
|
||||
VIR_DELETE_ELEMENT(def->disks, i, def->ndisks);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1365,12 +1358,7 @@ xenXMDomainDetachDeviceFlags(virConnectPtr conn,
|
||||
for (i = 0; i < def->nnets; i++) {
|
||||
if (!virMacAddrCmp(&def->nets[i]->mac, &dev->data.net->mac)) {
|
||||
virDomainNetDefFree(def->nets[i]);
|
||||
if (i < (def->nnets - 1))
|
||||
memmove(def->nets + i,
|
||||
def->nets + i + 1,
|
||||
sizeof(*def->nets) *
|
||||
(def->nnets - (i + 1)));
|
||||
def->nnets--;
|
||||
VIR_DELETE_ELEMENT(def->nets, i, def->nnets);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -666,14 +666,9 @@ xenStoreAddWatch(virConnectPtr conn,
|
||||
VIR_STRDUP(watch->token, token) < 0)
|
||||
goto error;
|
||||
|
||||
/* Make space on list */
|
||||
n = list->count;
|
||||
if (VIR_REALLOC_N(list->watches, n + 1) < 0)
|
||||
if (VIR_APPEND_ELEMENT_COPY(list->watches, list->count, watch) < 0)
|
||||
goto error;
|
||||
|
||||
list->watches[n] = watch;
|
||||
list->count++;
|
||||
|
||||
return xs_watch(priv->xshandle, watch->path, watch->token);
|
||||
|
||||
error:
|
||||
@ -719,17 +714,7 @@ xenStoreRemoveWatch(virConnectPtr conn, const char *path, const char *token)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ typedef struct _xenStoreWatch xenStoreWatch;
|
||||
typedef xenStoreWatch *xenStoreWatchPtr;
|
||||
|
||||
struct _xenStoreWatchList {
|
||||
unsigned int count;
|
||||
size_t count;
|
||||
xenStoreWatchPtr *watches;
|
||||
};
|
||||
typedef struct _xenStoreWatchList xenStoreWatchList;
|
||||
|
Loading…
Reference in New Issue
Block a user