simplify dns_dumpctx API

the functions dns_dumpctx_db() and dns_dumpctx_version() are used in
only one place, to get the serial number of the version being dumped.
it's simpler to expose the serial number through its own call,
dns_dumpctx_serial(), and remove the others.
This commit is contained in:
Evan Hunt 2025-09-02 23:59:35 -07:00
parent 2ffb16c436
commit 34314915e2
3 changed files with 22 additions and 44 deletions

View file

@ -224,22 +224,13 @@ dns_dumpctx_cancel(dns_dumpctx_t *dctx);
*\li 'dctx' to be valid.
*/
dns_dbversion_t *
dns_dumpctx_version(dns_dumpctx_t *dctx);
/*%<
* Return the version handle (if any) of the database being dumped.
isc_result_t
dns_dumpctx_serial(dns_dumpctx_t *dctx, uint32_t *serial);
/*
* Return the serial number of the database being dumped.
*
* Require:
*\li 'dctx' to be valid.
*/
dns_db_t *
dns_dumpctx_db(dns_dumpctx_t *dctx);
/*%<
* Return the database being dumped.
*
* Require:
*\li 'dctx' to be valid.
*\li The database being dumped is a zone, not a cache.
*/
/*@{*/

View file

@ -250,7 +250,6 @@ struct dns_dumpctx {
isc_mutex_t lock;
isc_refcount_t references;
atomic_bool canceled;
bool do_date;
isc_stdtime_t now;
FILE *f;
dns_db_t *db;
@ -1397,16 +1396,12 @@ dns_dumpctx_detach(dns_dumpctx_t **dctxp) {
}
}
dns_dbversion_t *
dns_dumpctx_version(dns_dumpctx_t *dctx) {
isc_result_t
dns_dumpctx_serial(dns_dumpctx_t *dctx, uint32_t *serial) {
REQUIRE(DNS_DCTX_VALID(dctx));
return dctx->version;
}
REQUIRE(!dns_db_iscache(dctx->db));
dns_db_t *
dns_dumpctx_db(dns_dumpctx_t *dctx) {
REQUIRE(DNS_DCTX_VALID(dctx));
return dctx->db;
return dns_db_getsoaserial(dctx->db, dctx->version, serial);
}
void
@ -1573,10 +1568,13 @@ dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
dctx->now = isc_stdtime_now();
dns_db_attach(db, &dctx->db);
dctx->do_date = dns_db_iscache(dctx->db);
if (dctx->do_date) {
if (dns_db_iscache(dctx->db)) {
(void)dns_db_getservestalettl(dctx->db,
&dctx->tctx.serve_stale_ttl);
} else if (version != NULL) {
dns_db_attachversion(dctx->db, version, &dctx->version);
} else {
dns_db_currentversion(dctx->db, &dctx->version);
}
if (dctx->format == dns_masterformat_text &&
@ -1592,12 +1590,6 @@ dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version,
}
isc_mutex_init(&dctx->lock);
if (version != NULL) {
dns_db_attachversion(dctx->db, version, &dctx->version);
} else if (!dns_db_iscache(db)) {
dns_db_currentversion(dctx->db, &dctx->version);
}
isc_mem_attach(mctx, &dctx->mctx);
isc_refcount_init(&dctx->references, 1);
@ -1639,7 +1631,7 @@ writeheader(dns_dumpctx_t *dctx) {
* incompatible with pre-RFC2540 software, so we omit
* it in the zone case.
*/
if (dctx->do_date) {
if (dns_db_iscache(dctx->db)) {
fprintf(dctx->f, "; using a %u second stale ttl\n",
dctx->tctx.serve_stale_ttl);
result = dns_time32_totext(dctx->now, &buffer);

View file

@ -12208,12 +12208,10 @@ static void
dump_done(void *arg, isc_result_t result) {
dns_zone_t *zone = arg;
dns_zone_t *secure = NULL;
dns_db_t *db;
dns_dbversion_t *version;
bool again = false;
bool compact = false;
uint32_t serial;
isc_result_t tresult;
isc_result_t tresult = ISC_R_UNSET;
REQUIRE(DNS_ZONE_VALID(zone));
@ -12241,13 +12239,10 @@ dump_done(void *arg, isc_result_t result) {
}
if (result == ISC_R_SUCCESS && zone->journal != NULL) {
/*
* We don't own these, zone->dctx must stay valid.
*/
db = dns_dumpctx_db(zone->dumpctx);
version = dns_dumpctx_version(zone->dumpctx);
tresult = dns_db_getsoaserial(db, version, &serial);
tresult = dns_dumpctx_serial(zone->dumpctx, &serial);
}
if (tresult == ISC_R_SUCCESS) {
/*
* Handle lock order inversion.
*/
@ -12269,7 +12264,7 @@ dump_done(void *arg, isc_result_t result) {
* If there is a secure version of this zone
* use its serial if it is less than ours.
*/
if (tresult == ISC_R_SUCCESS && secure != NULL) {
if (secure != NULL) {
uint32_t sserial;
isc_result_t mresult;
@ -12285,13 +12280,13 @@ dump_done(void *arg, isc_result_t result) {
}
ZONEDB_UNLOCK(&secure->dblock, isc_rwlocktype_read);
}
if (tresult == ISC_R_SUCCESS && zone->xfr == NULL) {
if (zone->xfr == NULL) {
dns_db_t *zdb = NULL;
if (dns_zone_getdb(zone, &zdb) == ISC_R_SUCCESS) {
zone_journal_compact(zone, zdb, serial);
dns_db_detach(&zdb);
}
} else if (tresult == ISC_R_SUCCESS) {
} else {
compact = true;
zone->compact_serial = serial;
}