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;
|
info->id = id;
|
||||||
|
|
||||||
/* Make space on list */
|
/* Make space on list */
|
||||||
n = list->count;
|
if (VIR_APPEND_ELEMENT(list->doms, list->count, info) < 0)
|
||||||
if (VIR_REALLOC_N(list->doms, n + 1) < 0) {
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
list->doms[n] = info;
|
|
||||||
list->count++;
|
|
||||||
return 0;
|
return 0;
|
||||||
error:
|
error:
|
||||||
if (info)
|
if (info)
|
||||||
@ -2915,18 +2911,7 @@ xenUnifiedRemoveDomainInfo(xenUnifiedDomainInfoListPtr list,
|
|||||||
VIR_FREE(list->doms[i]->name);
|
VIR_FREE(list->doms[i]->name);
|
||||||
VIR_FREE(list->doms[i]);
|
VIR_FREE(list->doms[i]);
|
||||||
|
|
||||||
if (i < (list->count - 1))
|
VIR_DELETE_ELEMENT(list->doms, i, list->count);
|
||||||
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--;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ typedef struct _xenUnifiedDomainInfo xenUnifiedDomainInfo;
|
|||||||
typedef xenUnifiedDomainInfo *xenUnifiedDomainInfoPtr;
|
typedef xenUnifiedDomainInfo *xenUnifiedDomainInfoPtr;
|
||||||
|
|
||||||
struct _xenUnifiedDomainInfoList {
|
struct _xenUnifiedDomainInfoList {
|
||||||
unsigned int count;
|
size_t count;
|
||||||
xenUnifiedDomainInfoPtr *doms;
|
xenUnifiedDomainInfoPtr *doms;
|
||||||
};
|
};
|
||||||
typedef struct _xenUnifiedDomainInfoList xenUnifiedDomainInfoList;
|
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]->name);
|
||||||
VIR_FREE(priv->configInfoList->doms[i]);
|
VIR_FREE(priv->configInfoList->doms[i]);
|
||||||
|
|
||||||
if (i < (priv->configInfoList->count - 1))
|
VIR_DELETE_ELEMENT(priv->configInfoList->doms, i,
|
||||||
memmove(priv->configInfoList->doms + i,
|
priv->configInfoList->count);
|
||||||
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--;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1262,10 +1262,8 @@ xenXMDomainAttachDeviceFlags(virConnectPtr conn,
|
|||||||
|
|
||||||
case VIR_DOMAIN_DEVICE_NET:
|
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;
|
goto cleanup;
|
||||||
def->nets[def->nnets++] = dev->data.net;
|
|
||||||
dev->data.net = NULL;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1348,12 +1346,7 @@ xenXMDomainDetachDeviceFlags(virConnectPtr conn,
|
|||||||
dev->data.disk->dst &&
|
dev->data.disk->dst &&
|
||||||
STREQ(def->disks[i]->dst, dev->data.disk->dst)) {
|
STREQ(def->disks[i]->dst, dev->data.disk->dst)) {
|
||||||
virDomainDiskDefFree(def->disks[i]);
|
virDomainDiskDefFree(def->disks[i]);
|
||||||
if (i < (def->ndisks - 1))
|
VIR_DELETE_ELEMENT(def->disks, i, def->ndisks);
|
||||||
memmove(def->disks + i,
|
|
||||||
def->disks + i + 1,
|
|
||||||
sizeof(*def->disks) *
|
|
||||||
(def->ndisks - (i + 1)));
|
|
||||||
def->ndisks--;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1365,12 +1358,7 @@ xenXMDomainDetachDeviceFlags(virConnectPtr conn,
|
|||||||
for (i = 0; i < def->nnets; i++) {
|
for (i = 0; i < def->nnets; i++) {
|
||||||
if (!virMacAddrCmp(&def->nets[i]->mac, &dev->data.net->mac)) {
|
if (!virMacAddrCmp(&def->nets[i]->mac, &dev->data.net->mac)) {
|
||||||
virDomainNetDefFree(def->nets[i]);
|
virDomainNetDefFree(def->nets[i]);
|
||||||
if (i < (def->nnets - 1))
|
VIR_DELETE_ELEMENT(def->nets, i, def->nnets);
|
||||||
memmove(def->nets + i,
|
|
||||||
def->nets + i + 1,
|
|
||||||
sizeof(*def->nets) *
|
|
||||||
(def->nnets - (i + 1)));
|
|
||||||
def->nnets--;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -666,14 +666,9 @@ xenStoreAddWatch(virConnectPtr conn,
|
|||||||
VIR_STRDUP(watch->token, token) < 0)
|
VIR_STRDUP(watch->token, token) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* Make space on list */
|
if (VIR_APPEND_ELEMENT_COPY(list->watches, list->count, watch) < 0)
|
||||||
n = list->count;
|
|
||||||
if (VIR_REALLOC_N(list->watches, n + 1) < 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
list->watches[n] = watch;
|
|
||||||
list->count++;
|
|
||||||
|
|
||||||
return xs_watch(priv->xshandle, watch->path, watch->token);
|
return xs_watch(priv->xshandle, watch->path, watch->token);
|
||||||
|
|
||||||
error:
|
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]->token);
|
||||||
VIR_FREE(list->watches[i]);
|
VIR_FREE(list->watches[i]);
|
||||||
|
|
||||||
if (i < (list->count - 1))
|
VIR_DELETE_ELEMENT(list->watches, i, list->count);
|
||||||
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--;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ typedef struct _xenStoreWatch xenStoreWatch;
|
|||||||
typedef xenStoreWatch *xenStoreWatchPtr;
|
typedef xenStoreWatch *xenStoreWatchPtr;
|
||||||
|
|
||||||
struct _xenStoreWatchList {
|
struct _xenStoreWatchList {
|
||||||
unsigned int count;
|
size_t count;
|
||||||
xenStoreWatchPtr *watches;
|
xenStoreWatchPtr *watches;
|
||||||
};
|
};
|
||||||
typedef struct _xenStoreWatchList xenStoreWatchList;
|
typedef struct _xenStoreWatchList xenStoreWatchList;
|
||||||
|
Loading…
Reference in New Issue
Block a user