virlease: Allow infinite lease expiry time

When adding a new lease by our leaseshelper then virLeaseNew() is
called. Here, we check for DNSMASQ_LEASE_EXPIRES environment
variable which is the expiration time for the lease. For infinite
lease time the value is zero. However, our code is not prepared
for that and adds "expiry-time" into the JSON file only if lease
expiry time is non-zero. This breaks the assumption that the
"expiry-time" attribute is always present (as can be seen in
virLeaseReadCustomLeaseFile() and virLeasePrintLeases()).

Store "expiry-time" always.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Michal Privoznik 2020-12-18 16:09:11 +01:00
parent 003fff38e7
commit 6f1ae57129

View File

@ -227,14 +227,13 @@ virLeaseNew(virJSONValuePtr *lease_ret,
/* Removed extraneous trailing space in DNSMASQ_LEASE_EXPIRES
* (dnsmasq < 2.52) */
virTrimSpaces(exptime, NULL);
}
if (!exptime ||
virStrToLong_ll(exptime, NULL, 10, &expirytime) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to convert lease expiry time to long long: %s"),
NULLSTR(exptime));
return -1;
if (virStrToLong_ll(exptime, NULL, 10, &expirytime) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to convert lease expiry time to long long: %s"),
NULLSTR(exptime));
return -1;
}
}
/* Create new lease */
@ -252,7 +251,7 @@ virLeaseNew(virJSONValuePtr *lease_ret,
return -1;
if (server_duid && virJSONValueObjectAppendString(lease_new, "server-duid", server_duid) < 0)
return -1;
if (expirytime && virJSONValueObjectAppendNumberLong(lease_new, "expiry-time", expirytime) < 0)
if (virJSONValueObjectAppendNumberLong(lease_new, "expiry-time", expirytime) < 0)
return -1;
*lease_ret = lease_new;