Commit bef8ac5b authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Rewrite isc_refcount API to fetch_and_<op>, instead of former <op>_and_<fetch>

parent 7fbbf09d
......@@ -9143,7 +9143,6 @@ view_loaded(void *arg) {
ns_zoneload_t *zl = (ns_zoneload_t *) arg;
named_server_t *server = zl->server;
bool reconfig = zl->reconfig;
unsigned int refs;
/*
......@@ -9154,34 +9153,33 @@ view_loaded(void *arg) {
* We use the zoneload reference counter to let us
* know when all views are finished.
*/
isc_refcount_decrement(&zl->refs, &refs);
if (refs != 0)
return (ISC_R_SUCCESS);
if (isc_refcount_decrement(&zl->refs) == 1) {
isc_refcount_destroy(&zl->refs);
isc_mem_put(server->mctx, zl, sizeof (*zl));
isc_refcount_destroy(&zl->refs);
isc_mem_put(server->mctx, zl, sizeof (*zl));
/*
* To maintain compatibility with log parsing tools that might
* be looking for this string after "rndc reconfig", we keep it
* as it is
*/
if (reconfig) {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
"any newly configured zones are now loaded");
} else {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE,
"all zones loaded");
}
/*
* To maintain compatibility with log parsing tools that might
* be looking for this string after "rndc reconfig", we keep it
* as it is
*/
if (reconfig) {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
"any newly configured zones are now loaded");
} else {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE,
"all zones loaded");
}
CHECKFATAL(dns_zonemgr_forcemaint(server->zonemgr),
"forcing zone maintenance");
CHECKFATAL(dns_zonemgr_forcemaint(server->zonemgr),
"forcing zone maintenance");
named_os_started();
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE, "running");
named_os_started();
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE, "running");
}
return (ISC_R_SUCCESS);
}
......@@ -9191,7 +9189,6 @@ load_zones(named_server_t *server, bool init, bool reconfig) {
isc_result_t result;
dns_view_t *view;
ns_zoneload_t *zl;
unsigned int refs = 0;
zl = isc_mem_get(server->mctx, sizeof (*zl));
if (zl == NULL)
......@@ -9230,13 +9227,12 @@ load_zones(named_server_t *server, bool init, bool reconfig) {
* 'dns_view_asyncload' calls view_loaded if there are no
* zones.
*/
isc_refcount_increment(&zl->refs, NULL);
isc_refcount_increment(&zl->refs);
CHECK(dns_view_asyncload(view, view_loaded, zl));
}
cleanup:
isc_refcount_decrement(&zl->refs, &refs);
if (refs == 0) {
if (isc_refcount_decrement(&zl->refs) == 1) {
isc_refcount_destroy(&zl->refs);
isc_mem_put(server->mctx, zl, sizeof (*zl));
} else if (init) {
......
......@@ -72,7 +72,7 @@ attach(dns_db_t *source, dns_db_t **targetp) {
REQUIRE(VALID_SAMPLEDB(sampledb));
isc_refcount_increment(&sampledb->refs, NULL);
isc_refcount_increment(&sampledb->refs);
*targetp = source;
}
......@@ -88,13 +88,12 @@ free_sampledb(sampledb_t *sampledb) {
static void
detach(dns_db_t **dbp) {
sampledb_t *sampledb = (sampledb_t *)(*dbp);
unsigned int refs;
REQUIRE(VALID_SAMPLEDB(sampledb));
isc_refcount_decrement(&sampledb->refs, &refs);
if (refs == 0)
if (isc_refcount_decrement(&sampledb->refs) == 1) {
free_sampledb(sampledb);
}
*dbp = NULL;
}
......
......@@ -450,7 +450,7 @@ void
dns_acl_attach(dns_acl_t *source, dns_acl_t **target) {
REQUIRE(DNS_ACL_VALID(source));
isc_refcount_increment(&source->refcount, NULL);
isc_refcount_increment(&source->refcount);
*target = source;
}
......@@ -483,13 +483,13 @@ destroy(dns_acl_t *dacl) {
void
dns_acl_detach(dns_acl_t **aclp) {
dns_acl_t *acl = *aclp;
unsigned int refs;
REQUIRE(DNS_ACL_VALID(acl));
isc_refcount_decrement(&acl->refcount, &refs);
if (refs == 0)
if (isc_refcount_decrement(&acl->refcount) == 1) {
destroy(acl);
}
*aclp = NULL;
}
......
......@@ -233,7 +233,7 @@ dns_catz_entry_copy(dns_catz_zone_t *zone, const dns_catz_entry_t *entry,
void
dns_catz_entry_attach(dns_catz_entry_t *entry, dns_catz_entry_t **entryp) {
REQUIRE(entryp != NULL && *entryp == NULL);
isc_refcount_increment(&entry->refs, NULL);
isc_refcount_increment(&entry->refs);
*entryp = entry;
}
......@@ -241,23 +241,22 @@ void
dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) {
dns_catz_entry_t *entry;
isc_mem_t *mctx;
unsigned int refs;
REQUIRE(entryp != NULL && *entryp != NULL);
entry = *entryp;
*entryp = NULL;
mctx = zone->catzs->mctx;
isc_refcount_decrement(&entry->refs, &refs);
if (refs == 0) {
if (isc_refcount_decrement(&entry->refs) == 1) {
dns_catz_options_free(&entry->opts, mctx);
if (dns_name_dynamic(&entry->name))
dns_name_free(&entry->name, mctx);
isc_refcount_destroy(&entry->refs);
isc_mem_put(mctx, entry, sizeof(dns_catz_entry_t));
}
*entryp = NULL;
}
bool
......@@ -728,7 +727,7 @@ void
dns_catz_catzs_attach(dns_catz_zones_t *catzs, dns_catz_zones_t **catzsp) {
REQUIRE(catzsp != NULL && *catzsp == NULL);
isc_refcount_increment(&catzs->refs, NULL);
isc_refcount_increment(&catzs->refs);
*catzsp = catzs;
}
......@@ -736,7 +735,7 @@ void
dns_catz_zone_attach(dns_catz_zone_t *zone, dns_catz_zone_t **zonep) {
REQUIRE(zonep != NULL && *zonep == NULL);
isc_refcount_increment(&zone->refs, NULL);
isc_refcount_increment(&zone->refs);
*zonep = zone;
}
......@@ -746,14 +745,13 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
dns_catz_zone_t *zone;
isc_ht_iter_t *iter = NULL;
isc_mem_t *mctx;
unsigned int refs;
REQUIRE(zonep != NULL && *zonep != NULL);
zone = *zonep;
*zonep = NULL;
isc_refcount_decrement(&zone->refs, &refs);
if (refs == 0) {
if (isc_refcount_decrement(&zone->refs) == 1) {
isc_refcount_destroy(&zone->refs);
if (zone->entries != NULL) {
result = isc_ht_iter_create(zone->entries, &iter);
INSIST(result == ISC_R_SUCCESS);
......@@ -775,7 +773,6 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
}
mctx = zone->catzs->mctx;
isc_timer_detach(&zone->updatetimer);
isc_refcount_destroy(&zone->refs);
if (zone->db_registered == true) {
result = dns_db_updatenotify_unregister(zone->db,
dns_catz_dbupdate_callback,
......@@ -795,6 +792,8 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) {
zone->catzs = NULL;
isc_mem_put(mctx, zone, sizeof(dns_catz_zone_t));
}
*zonep = NULL;
}
void
......@@ -802,7 +801,6 @@ dns_catz_catzs_detach(dns_catz_zones_t ** catzsp) {
dns_catz_zones_t *catzs;
isc_ht_iter_t *iter = NULL;
isc_result_t result;
unsigned int refs;
dns_catz_zone_t *zone;
......@@ -811,9 +809,8 @@ dns_catz_catzs_detach(dns_catz_zones_t ** catzsp) {
REQUIRE(catzs != NULL);
*catzsp = NULL;
isc_refcount_decrement(&catzs->refs, &refs);
if (refs == 0) {
if (isc_refcount_decrement(&catzs->refs) == 1) {
isc_refcount_destroy(&catzs->refs);
DESTROYLOCK(&catzs->lock);
if (catzs->zones != NULL) {
result = isc_ht_iter_create(catzs->zones, &iter);
......@@ -830,7 +827,6 @@ dns_catz_catzs_detach(dns_catz_zones_t ** catzsp) {
INSIST(isc_ht_count(catzs->zones) == 0);
isc_ht_destroy(&catzs->zones);
}
isc_refcount_destroy(&catzs->refs);
isc_task_destroy(&catzs->updater);
isc_mem_putanddetach(&catzs->mctx, catzs, sizeof(*catzs));
}
......
......@@ -531,7 +531,7 @@ dns_dt_attach(dns_dtenv_t *source, dns_dtenv_t **destp) {
REQUIRE(VALID_DTENV(source));
REQUIRE(destp != NULL && *destp == NULL);
isc_refcount_increment(&source->refcount, NULL);
isc_refcount_increment(&source->refcount);
*destp = source;
}
......@@ -579,17 +579,17 @@ destroy(dns_dtenv_t *env) {
void
dns_dt_detach(dns_dtenv_t **envp) {
unsigned int refs;
dns_dtenv_t *env;
REQUIRE(envp != NULL && VALID_DTENV(*envp));
env = *envp;
*envp = NULL;
isc_refcount_decrement(&env->refcount, &refs);
if (refs == 0)
if (isc_refcount_decrement(&env->refcount) == 1) {
destroy(env);
}
*envp = NULL;
}
static isc_result_t
......
......@@ -1124,7 +1124,7 @@ dst_key_attach(dst_key_t *source, dst_key_t **target) {
REQUIRE(target != NULL && *target == NULL);
REQUIRE(VALID_KEY(source));
isc_refcount_increment(&source->refs, NULL);
isc_refcount_increment(&source->refs);
*target = source;
}
......@@ -1132,7 +1132,6 @@ void
dst_key_free(dst_key_t **keyp) {
isc_mem_t *mctx;
dst_key_t *key;
unsigned int refs;
REQUIRE(dst_initialized == true);
REQUIRE(keyp != NULL && VALID_KEY(*keyp));
......@@ -1140,26 +1139,24 @@ dst_key_free(dst_key_t **keyp) {
key = *keyp;
mctx = key->mctx;
isc_refcount_decrement(&key->refs, &refs);
if (refs != 0)
return;
isc_refcount_destroy(&key->refs);
if (key->keydata.generic != NULL) {
INSIST(key->func->destroy != NULL);
key->func->destroy(key);
}
if (key->engine != NULL)
isc_mem_free(mctx, key->engine);
if (key->label != NULL)
isc_mem_free(mctx, key->label);
dns_name_free(key->key_name, mctx);
isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
if (key->key_tkeytoken) {
isc_buffer_free(&key->key_tkeytoken);
if (isc_refcount_decrement(&key->refs) == 1) {
isc_refcount_destroy(&key->refs);
if (key->keydata.generic != NULL) {
INSIST(key->func->destroy != NULL);
key->func->destroy(key);
}
if (key->engine != NULL)
isc_mem_free(mctx, key->engine);
if (key->label != NULL)
isc_mem_free(mctx, key->label);
dns_name_free(key->key_name, mctx);
isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
if (key->key_tkeytoken) {
isc_buffer_free(&key->key_tkeytoken);
}
isc_safe_memwipe(key, sizeof(*key));
isc_mem_putanddetach(&mctx, key, sizeof(*key));
}
isc_safe_memwipe(key, sizeof(*key));
isc_mem_putanddetach(&mctx, key, sizeof(*key));
*keyp = NULL;
}
......
......@@ -1041,36 +1041,6 @@ dns_rbtnodechain_nextflat(dns_rbtnodechain_t *chain, dns_name_t *name);
* Find the next node at the current depth in DNSSEC order.
*/
/*
* Wrapper macros for manipulating the rbtnode reference counter:
* Since we selectively use isc_refcount_t for the reference counter of
* a rbtnode, operations on the counter depend on the actual type of it.
* The following macros provide a common interface to these operations,
* hiding the back-end. The usage is the same as that of isc_refcount_xxx().
*/
#define dns_rbtnode_refinit(node, n) \
do { \
isc_refcount_init(&(node)->references, (n)); \
} while (0)
#define dns_rbtnode_refdestroy(node) \
do { \
isc_refcount_destroy(&(node)->references); \
} while (0)
#define dns_rbtnode_refcurrent(node) \
isc_refcount_current(&(node)->references)
#define dns_rbtnode_refincrement0(node, refs) \
do { \
isc_refcount_increment0(&(node)->references, (refs)); \
} while (0)
#define dns_rbtnode_refincrement(node, refs) \
do { \
isc_refcount_increment(&(node)->references, (refs)); \
} while (0)
#define dns_rbtnode_refdecrement(node, refs) \
do { \
isc_refcount_decrement(&(node)->references, (refs)); \
} while (0)
void
dns_rbtnode_nodename(dns_rbtnode_t *node, dns_name_t *name);
......
......@@ -142,18 +142,19 @@ dns_iptable_merge(dns_iptable_t *tab, dns_iptable_t *source, bool pos)
void
dns_iptable_attach(dns_iptable_t *source, dns_iptable_t **target) {
REQUIRE(DNS_IPTABLE_VALID(source));
isc_refcount_increment(&source->refcount, NULL);
isc_refcount_increment(&source->refcount);
*target = source;
}
void
dns_iptable_detach(dns_iptable_t **tabp) {
dns_iptable_t *tab = *tabp;
unsigned int refs;
REQUIRE(DNS_IPTABLE_VALID(tab));
isc_refcount_decrement(&tab->refcount, &refs);
if (refs == 0)
if (isc_refcount_decrement(&tab->refcount) == 1) {
destroy_iptable(tab);
}
*tabp = NULL;
}
......
......@@ -118,7 +118,7 @@ dns_keytable_attach(dns_keytable_t *source, dns_keytable_t **targetp) {
REQUIRE(VALID_KEYTABLE(source));
REQUIRE(targetp != NULL && *targetp == NULL);
isc_refcount_increment(&source->references, NULL);
isc_refcount_increment(&source->references);
*targetp = source;
}
......@@ -126,7 +126,6 @@ dns_keytable_attach(dns_keytable_t *source, dns_keytable_t **targetp) {
void
dns_keytable_detach(dns_keytable_t **keytablep) {
dns_keytable_t *keytable;
unsigned int refs;
/*
* Detach *keytablep from its keytable.
......@@ -135,10 +134,8 @@ dns_keytable_detach(dns_keytable_t **keytablep) {
REQUIRE(keytablep != NULL && VALID_KEYTABLE(*keytablep));
keytable = *keytablep;
*keytablep = NULL;
isc_refcount_decrement(&keytable->references, &refs);
if (refs == 0) {
if (isc_refcount_decrement(&keytable->references) == 1) {
INSIST(isc_refcount_current(&keytable->active_nodes) == 0);
isc_refcount_destroy(&keytable->active_nodes);
isc_refcount_destroy(&keytable->references);
......@@ -148,6 +145,7 @@ dns_keytable_detach(dns_keytable_t **keytablep) {
isc_mem_putanddetach(&keytable->mctx,
keytable, sizeof(*keytable));
}
*keytablep = NULL;
}
/*%
......@@ -411,7 +409,7 @@ dns_keytable_find(dns_keytable_t *keytable, const dns_name_t *keyname,
DNS_RBTFIND_NOOPTIONS, NULL, NULL);
if (result == ISC_R_SUCCESS) {
if (node->data != NULL) {
isc_refcount_increment0(&keytable->active_nodes, NULL);
isc_refcount_increment0(&keytable->active_nodes);
dns_keynode_attach(node->data, keynodep);
} else
result = ISC_R_NOTFOUND;
......@@ -439,7 +437,7 @@ dns_keytable_nextkeynode(dns_keytable_t *keytable, dns_keynode_t *keynode,
return (ISC_R_NOTFOUND);
dns_keynode_attach(keynode->next, nextnodep);
isc_refcount_increment(&keytable->active_nodes, NULL);
isc_refcount_increment(&keytable->active_nodes);
return (ISC_R_SUCCESS);
}
......@@ -487,7 +485,7 @@ dns_keytable_findkeynode(dns_keytable_t *keytable, const dns_name_t *name,
break;
}
if (knode != NULL) {
isc_refcount_increment0(&keytable->active_nodes, NULL);
isc_refcount_increment0(&keytable->active_nodes);
dns_keynode_attach(knode, keynodep);
} else
result = DNS_R_PARTIALMATCH;
......@@ -525,7 +523,7 @@ dns_keytable_findnextkeynode(dns_keytable_t *keytable, dns_keynode_t *keynode,
break;
}
if (knode != NULL) {
isc_refcount_increment(&keytable->active_nodes, NULL);
isc_refcount_increment(&keytable->active_nodes);
result = ISC_R_SUCCESS;
dns_keynode_attach(knode, nextnodep);
} else
......@@ -574,7 +572,7 @@ dns_keytable_attachkeynode(dns_keytable_t *keytable, dns_keynode_t *source,
REQUIRE(VALID_KEYNODE(source));
REQUIRE(target != NULL && *target == NULL);
isc_refcount_increment(&keytable->active_nodes, NULL);
isc_refcount_increment(&keytable->active_nodes);
dns_keynode_attach(source, target);
}
......@@ -589,7 +587,7 @@ dns_keytable_detachkeynode(dns_keytable_t *keytable, dns_keynode_t **keynodep)
REQUIRE(VALID_KEYTABLE(keytable));
REQUIRE(keynodep != NULL && VALID_KEYNODE(*keynodep));
isc_refcount_decrement(&keytable->active_nodes, NULL);
(void)isc_refcount_decrement(&keytable->active_nodes);
dns_keynode_detach(keytable->mctx, keynodep);
}
......@@ -735,7 +733,7 @@ dns_keytable_forall(dns_keytable_t *keytable,
result = ISC_R_SUCCESS;
goto cleanup;
}
isc_refcount_increment0(&keytable->active_nodes, NULL);
isc_refcount_increment0(&keytable->active_nodes);
for (;;) {
dns_rbtnodechain_current(&chain, NULL, NULL, &node);
if (node->data != NULL)
......@@ -747,7 +745,7 @@ dns_keytable_forall(dns_keytable_t *keytable,
break;
}
}
isc_refcount_decrement(&keytable->active_nodes, NULL);
(void)isc_refcount_decrement(&keytable->active_nodes);
cleanup:
dns_rbtnodechain_invalidate(&chain);
......@@ -808,17 +806,15 @@ dns_keynode_create(isc_mem_t *mctx, dns_keynode_t **target) {
void
dns_keynode_attach(dns_keynode_t *source, dns_keynode_t **target) {
REQUIRE(VALID_KEYNODE(source));
isc_refcount_increment(&source->refcount, NULL);
isc_refcount_increment(&source->refcount);
*target = source;
}
void
dns_keynode_detach(isc_mem_t *mctx, dns_keynode_t **keynode) {
unsigned int refs;
dns_keynode_t *node = *keynode;
REQUIRE(VALID_KEYNODE(node));
isc_refcount_decrement(&node->refcount, &refs);
if (refs == 0) {
if (isc_refcount_decrement(&node->refcount) == 1) {
if (node->key != NULL)
dst_key_free(&node->key);
isc_refcount_destroy(&node->refcount);
......
......@@ -61,19 +61,16 @@ struct dns_nta {
*/
static void
nta_ref(dns_nta_t *nta) {
isc_refcount_increment(&nta->refcount, NULL);
isc_refcount_increment(&nta->refcount);
}
static void
nta_detach(isc_mem_t *mctx, dns_nta_t **ntap) {
unsigned int refs;
dns_nta_t *nta = *ntap;
REQUIRE(VALID_NTA(nta));
*ntap = NULL;
isc_refcount_decrement(&nta->refcount, &refs);
if (refs == 0) {
if (isc_refcount_decrement(&nta->refcount) == 1) {
nta->magic = 0;
if (nta->timer != NULL) {
(void) isc_timer_reset(nta->timer,
......@@ -92,6 +89,7 @@ nta_detach(isc_mem_t *mctx, dns_nta_t **ntap) {
}
isc_mem_put(mctx, nta, sizeof(dns_nta_t));
}
*ntap = NULL;
}
static void
......
......@@ -128,7 +128,7 @@ void
dns_order_attach(dns_order_t *source, dns_order_t **target) {
REQUIRE(DNS_ORDER_VALID(source));
REQUIRE(target != NULL && *target == NULL);
isc_refcount_increment(&source->references, NULL);
isc_refcount_increment(&source->references);
*target = source;
}
......@@ -136,21 +136,20 @@ void
dns_order_detach(dns_order_t **orderp) {
dns_order_t *order;
dns_order_ent_t *ent;
unsigned int references;
REQUIRE(orderp != NULL);
order = *orderp;
REQUIRE(DNS_ORDER_VALID(order));
isc_refcount_decrement(&order->references, &references);
*orderp = NULL;
if (references != 0)
return;
order->magic = 0;
while ((ent = ISC_LIST_HEAD(order->ents)) != NULL) {
ISC_LIST_UNLINK(order->ents, ent, link);
isc_mem_put(order->mctx, ent, sizeof(*ent));
if (isc_refcount_decrement(&order->references) == 1) {
order->magic = 0;
while ((ent = ISC_LIST_HEAD(order->ents)) != NULL) {
ISC_LIST_UNLINK(order->ents, ent, link);
isc_mem_put(order->mctx, ent, sizeof(*ent));
}
isc_refcount_destroy(&order->references);
isc_mem_putanddetach(&order->mctx, order, sizeof(*order));
}
isc_refcount_destroy(&order->references);
isc_mem_putanddetach(&order->mctx, order, sizeof(*order));
*orderp = NULL;
}
......@@ -228,21 +228,19 @@ dns_portlist_attach(dns_portlist_t *portlist, dns_portlist_t **portlistp) {
REQUIRE(DNS_VALID_PORTLIST(portlist));
REQUIRE(portlistp != NULL && *portlistp == NULL);
isc_refcount_increment(&portlist->refcount, NULL);
isc_refcount_increment(&portlist->refcount);
*portlistp = portlist;
}
void
dns_portlist_detach(dns_portlist_t **portlistp) {
dns_portlist_t *portlist;
unsigned int count;