mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
leaseshelper: reduce indentation level in virLeaseReadCustomLeaseFile
Instead of nested ifs, jump out early. Mostly whitespace changes.
This commit is contained in:
parent
d7049a67b6
commit
ce9085eba1
@ -132,74 +132,78 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_array_new,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check for previous leases */
|
/* Check for previous leases */
|
||||||
if (custom_lease_file_len) {
|
if (custom_lease_file_len == 0) {
|
||||||
if (!(leases_array = virJSONValueFromString(lease_entries))) {
|
ret = 0;
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
goto cleanup;
|
||||||
_("invalid json in file: %s, rewriting it"),
|
}
|
||||||
custom_lease_file);
|
|
||||||
} else {
|
|
||||||
if (!virJSONValueIsArray(leases_array)) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("couldn't fetch array of leases"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
if (!(leases_array = virJSONValueFromString(lease_entries))) {
|
||||||
while (i < virJSONValueArraySize(leases_array)) {
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("invalid json in file: %s, rewriting it"),
|
||||||
|
custom_lease_file);
|
||||||
|
ret = 0;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(lease_tmp = virJSONValueArrayGet(leases_array, i))) {
|
if (!virJSONValueIsArray(leases_array)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("failed to parse json"));
|
_("couldn't fetch array of leases"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < virJSONValueArraySize(leases_array)) {
|
||||||
|
if (!(lease_tmp = virJSONValueArrayGet(leases_array, i))) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("failed to parse json"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address")) ||
|
||||||
|
(virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime) < 0)) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("failed to parse json"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
/* Check whether lease has expired or not */
|
||||||
|
if (expirytime < currtime) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check whether lease has to be included or not */
|
||||||
|
if (ip_to_delete && STREQ(ip_tmp, ip_to_delete)) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strchr(ip_tmp, ':')) {
|
||||||
|
/* This is an ipv6 lease */
|
||||||
|
if ((server_duid_tmp
|
||||||
|
= virJSONValueObjectGetString(lease_tmp, "server-duid"))) {
|
||||||
|
if (!*server_duid && VIR_STRDUP(*server_duid, server_duid_tmp) < 0) {
|
||||||
|
/* Control reaches here when the 'action' is not for an
|
||||||
|
* ipv6 lease or, for some weird reason the env var
|
||||||
|
* DNSMASQ_SERVER_DUID wasn't set*/
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (!(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address")) ||
|
/* Inject server-duid into those ipv6 leases which
|
||||||
(virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime) < 0)) {
|
* didn't have it previously, for example, those
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
* created by leaseshelper from libvirt 1.2.6 */
|
||||||
_("failed to parse json"));
|
if (virJSONValueObjectAppendString(lease_tmp, "server-duid", *server_duid) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
/* Check whether lease has expired or not */
|
|
||||||
if (expirytime < currtime) {
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check whether lease has to be included or not */
|
|
||||||
if (ip_to_delete && STREQ(ip_tmp, ip_to_delete)) {
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strchr(ip_tmp, ':')) {
|
|
||||||
/* This is an ipv6 lease */
|
|
||||||
if ((server_duid_tmp
|
|
||||||
= virJSONValueObjectGetString(lease_tmp, "server-duid"))) {
|
|
||||||
if (!*server_duid && VIR_STRDUP(*server_duid, server_duid_tmp) < 0) {
|
|
||||||
/* Control reaches here when the 'action' is not for an
|
|
||||||
* ipv6 lease or, for some weird reason the env var
|
|
||||||
* DNSMASQ_SERVER_DUID wasn't set*/
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Inject server-duid into those ipv6 leases which
|
|
||||||
* didn't have it previously, for example, those
|
|
||||||
* created by leaseshelper from libvirt 1.2.6 */
|
|
||||||
if (virJSONValueObjectAppendString(lease_tmp, "server-duid", *server_duid) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move old lease to new array */
|
|
||||||
if (virJSONValueArrayAppend(leases_array_new, lease_tmp) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("failed to create json"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ignore_value(virJSONValueArraySteal(leases_array, i));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Move old lease to new array */
|
||||||
|
if (virJSONValueArrayAppend(leases_array_new, lease_tmp) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("failed to create json"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ignore_value(virJSONValueArraySteal(leases_array, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user