1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

network: Use @nnames instead of @got

To make it clearer, let's use @nnames instead of @got for counting the
names in the @names array.  Keeps things consistent and clear.
This commit is contained in:
John Ferlan 2017-08-15 16:48:37 -04:00
parent 21de51c3e2
commit 6862ad3cd7

View File

@ -1444,9 +1444,9 @@ struct virNetworkObjListGetHelperData {
virConnectPtr conn; virConnectPtr conn;
virNetworkObjListFilter filter; virNetworkObjListFilter filter;
char **names; char **names;
int nnames;
int maxnames; int maxnames;
bool active; bool active;
int got;
bool error; bool error;
}; };
@ -1462,7 +1462,7 @@ virNetworkObjListGetHelper(void *payload,
return 0; return 0;
if (data->maxnames >= 0 && if (data->maxnames >= 0 &&
data->got == data->maxnames) data->nnames == data->maxnames)
return 0; return 0;
virObjectLock(obj); virObjectLock(obj);
@ -1474,11 +1474,11 @@ virNetworkObjListGetHelper(void *payload,
if ((data->active && virNetworkObjIsActive(obj)) || if ((data->active && virNetworkObjIsActive(obj)) ||
(!data->active && !virNetworkObjIsActive(obj))) { (!data->active && !virNetworkObjIsActive(obj))) {
if (data->names && if (data->names &&
VIR_STRDUP(data->names[data->got], obj->def->name) < 0) { VIR_STRDUP(data->names[data->nnames], obj->def->name) < 0) {
data->error = true; data->error = true;
goto cleanup; goto cleanup;
} }
data->got++; data->nnames++;
} }
cleanup: cleanup:
@ -1498,8 +1498,8 @@ virNetworkObjListGetNames(virNetworkObjListPtr nets,
int ret = -1; int ret = -1;
struct virNetworkObjListGetHelperData data = { struct virNetworkObjListGetHelperData data = {
.conn = conn, .filter = filter, .names = names, .conn = conn, .filter = filter, .names = names, .nnames = 0,
.maxnames = maxnames, .active = active, .got = 0, .error = false}; .maxnames = maxnames, .active = active, .error = false};
virObjectLock(nets); virObjectLock(nets);
virHashForEach(nets->objs, virNetworkObjListGetHelper, &data); virHashForEach(nets->objs, virNetworkObjListGetHelper, &data);
@ -1508,11 +1508,11 @@ virNetworkObjListGetNames(virNetworkObjListPtr nets,
if (data.error) if (data.error)
goto cleanup; goto cleanup;
ret = data.got; ret = data.nnames;
cleanup: cleanup:
if (ret < 0) { if (ret < 0) {
while (data.got) while (data.nnames)
VIR_FREE(data.names[--data.got]); VIR_FREE(data.names[--data.nnames]);
} }
return ret; return ret;
} }
@ -1525,14 +1525,14 @@ virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets,
virConnectPtr conn) virConnectPtr conn)
{ {
struct virNetworkObjListGetHelperData data = { struct virNetworkObjListGetHelperData data = {
.conn = conn, .filter = filter, .names = NULL, .conn = conn, .filter = filter, .names = NULL, .nnames = 0,
.maxnames = -1, .active = active, .got = 0, .error = false}; .maxnames = -1, .active = active, .error = false};
virObjectLock(nets); virObjectLock(nets);
virHashForEach(nets->objs, virNetworkObjListGetHelper, &data); virHashForEach(nets->objs, virNetworkObjListGetHelper, &data);
virObjectUnlock(nets); virObjectUnlock(nets);
return data.got; return data.nnames;
} }