2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 05:28:00 +00:00

more locking

This commit is contained in:
Mark Andrews 2000-12-11 19:21:15 +00:00
parent eb2d0f4d9d
commit fc03bf680e

View File

@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: zone.c,v 1.273 2000/12/08 19:34:06 marka Exp $ */ /* $Id: zone.c,v 1.274 2000/12/11 19:21:15 marka Exp $ */
#include <config.h> #include <config.h>
@ -106,7 +106,10 @@ typedef ISC_LIST(dns_io_t) dns_iolist_t;
#define DNS_ZONE_CHECKLOCK #define DNS_ZONE_CHECKLOCK
#ifdef DNS_ZONE_CHECKLOCK #ifdef DNS_ZONE_CHECKLOCK
#define LOCK_ZONE(z) \ #define LOCK_ZONE(z) \
do { LOCK(&(z)->lock); (z)->locked = ISC_TRUE; } while (0) do { LOCK(&(z)->lock); \
INSIST((z)->locked == ISC_FALSE); \
(z)->locked = ISC_TRUE; \
} while (0)
#define UNLOCK_ZONE(z) \ #define UNLOCK_ZONE(z) \
do { (z)->locked = ISC_FALSE; UNLOCK(&(z)->lock); } while (0) do { (z)->locked = ISC_FALSE; UNLOCK(&(z)->lock); } while (0)
#define LOCKED_ZONE(z) ((z)->locked) #define LOCKED_ZONE(z) ((z)->locked)
@ -2998,8 +3001,8 @@ stub_callback(isc_task_t *task, isc_event_t *event) {
dns_message_destroy(&msg); dns_message_destroy(&msg);
isc_event_free(&event); isc_event_free(&event);
dns_request_destroy(&zone->request);
LOCK_ZONE(zone); LOCK_ZONE(zone);
dns_request_destroy(&zone->request);
DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_REFRESH); DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_REFRESH);
zone->refreshtime = now + zone->refreshtime = now +
isc_random_jitter(zone->refresh, zone->refresh / 4); isc_random_jitter(zone->refresh, zone->refresh / 4);
@ -3018,8 +3021,8 @@ stub_callback(isc_task_t *task, isc_event_t *event) {
dns_db_detach(&stub->db); dns_db_detach(&stub->db);
if (msg != NULL) if (msg != NULL)
dns_message_destroy(&msg); dns_message_destroy(&msg);
LOCK_ZONE(zone);
isc_event_free(&event); isc_event_free(&event);
LOCK_ZONE(zone);
dns_request_destroy(&zone->request); dns_request_destroy(&zone->request);
zone->curmaster++; zone->curmaster++;
zone->refreshcnt = 0; zone->refreshcnt = 0;
@ -3042,7 +3045,7 @@ stub_callback(isc_task_t *task, isc_event_t *event) {
dns_request_destroy(&zone->request); dns_request_destroy(&zone->request);
UNLOCK_ZONE(zone); UNLOCK_ZONE(zone);
ns_query(zone, NULL, stub); ns_query(zone, NULL, stub);
goto detach; goto done;
free_stub: free_stub:
stub->magic = 0; stub->magic = 0;
@ -3051,7 +3054,7 @@ stub_callback(isc_task_t *task, isc_event_t *event) {
INSIST(stub->version == NULL); INSIST(stub->version == NULL);
isc_mem_put(stub->mctx, stub, sizeof(*stub)); isc_mem_put(stub->mctx, stub, sizeof(*stub));
detach: done:
INSIST(event == NULL); INSIST(event == NULL);
return; return;
} }
@ -3242,7 +3245,9 @@ refresh_callback(isc_task_t *task, isc_event_t *event) {
isc_serial_gt(serial, zone->serial)) { isc_serial_gt(serial, zone->serial)) {
tcp_transfer: tcp_transfer:
isc_event_free(&event); isc_event_free(&event);
LOCK_ZONE(zone);
dns_request_destroy(&zone->request); dns_request_destroy(&zone->request);
UNLOCK_ZONE(zone);
if (zone->type == dns_zone_slave) { if (zone->type == dns_zone_slave) {
queue_xfrin(zone); queue_xfrin(zone);
} else { } else {
@ -3276,13 +3281,13 @@ refresh_callback(isc_task_t *task, isc_event_t *event) {
} }
if (msg != NULL) if (msg != NULL)
dns_message_destroy(&msg); dns_message_destroy(&msg);
return; goto detach;
next_master: next_master:
if (msg != NULL) if (msg != NULL)
dns_message_destroy(&msg); dns_message_destroy(&msg);
LOCK_ZONE(zone);
isc_event_free(&event); isc_event_free(&event);
LOCK_ZONE(zone);
dns_request_destroy(&zone->request); dns_request_destroy(&zone->request);
zone->curmaster++; zone->curmaster++;
zone->refreshcnt = 0; zone->refreshcnt = 0;
@ -3294,21 +3299,23 @@ refresh_callback(isc_task_t *task, isc_event_t *event) {
} }
zone_settimer(zone, now); zone_settimer(zone, now);
UNLOCK_ZONE(zone); UNLOCK_ZONE(zone);
return; goto detach;
} }
UNLOCK_ZONE(zone); UNLOCK_ZONE(zone);
queue_soa_query(zone); queue_soa_query(zone);
return; goto detach;
same_master: same_master:
zone->refreshcnt++; zone->refreshcnt++;
if (msg != NULL) if (msg != NULL)
dns_message_destroy(&msg); dns_message_destroy(&msg);
LOCK_ZONE(zone);
isc_event_free(&event); isc_event_free(&event);
LOCK_ZONE(zone);
dns_request_destroy(&zone->request); dns_request_destroy(&zone->request);
UNLOCK_ZONE(zone); UNLOCK_ZONE(zone);
queue_soa_query(zone); queue_soa_query(zone);
detach:
dns_zone_idetach(&zone);
return; return;
} }
@ -3403,6 +3410,7 @@ soa_query(isc_task_t *task, isc_event_t *event) {
isc_result_t result; isc_result_t result;
dns_message_t *message = NULL; dns_message_t *message = NULL;
dns_zone_t *zone = event->ev_arg; dns_zone_t *zone = event->ev_arg;
dns_zone_t *dummy = NULL;
isc_netaddr_t masterip; isc_netaddr_t masterip;
dns_tsigkey_t *key = NULL; dns_tsigkey_t *key = NULL;
isc_uint32_t options; isc_uint32_t options;
@ -3453,11 +3461,15 @@ soa_query(isc_task_t *task, isc_event_t *event) {
result = ISC_R_NOTIMPLEMENTED; result = ISC_R_NOTIMPLEMENTED;
goto cleanup; goto cleanup;
} }
LOCK_ZONE(zone);
zone_iattach(zone, &dummy);
result = dns_request_createvia(zone->view->requestmgr, message, result = dns_request_createvia(zone->view->requestmgr, message,
&src, &zone->masteraddr, options, key, &src, &zone->masteraddr, options, key,
15 /* XXX */, zone->task, 15 /* XXX */, zone->task,
refresh_callback, zone, &zone->request); refresh_callback, zone, &zone->request);
UNLOCK_ZONE(zone);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
dns_zone_idetach(&dummy);
zone_log(zone, me, ISC_LOG_DEBUG(1), zone_log(zone, me, ISC_LOG_DEBUG(1),
"dns_request_createvia failed: %s", "dns_request_createvia failed: %s",
dns_result_totext(result)); dns_result_totext(result));
@ -3588,11 +3600,13 @@ ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset, dns_stub_t *stub) {
result = ISC_R_NOTIMPLEMENTED; result = ISC_R_NOTIMPLEMENTED;
goto cleanup; goto cleanup;
} }
LOCK_ZONE(zone);
result = dns_request_createvia(zone->view->requestmgr, message, result = dns_request_createvia(zone->view->requestmgr, message,
&src, &zone->masteraddr, &src, &zone->masteraddr,
DNS_REQUESTOPT_TCP, key, 15 /* XXX */, DNS_REQUESTOPT_TCP, key, 15 /* XXX */,
zone->task, stub_callback, stub, zone->task, stub_callback, stub,
&zone->request); &zone->request);
UNLOCK_ZONE(zone);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
zone_log(zone, me, ISC_LOG_DEBUG(1), zone_log(zone, me, ISC_LOG_DEBUG(1),
"dns_request_createvia failed: %s", "dns_request_createvia failed: %s",
@ -3603,6 +3617,7 @@ ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset, dns_stub_t *stub) {
return; return;
cleanup: cleanup:
cancel_refresh(zone);
if (stub != NULL) { if (stub != NULL) {
stub->magic = 0; stub->magic = 0;
if (stub->version != NULL) if (stub->version != NULL)
@ -3611,10 +3626,10 @@ ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset, dns_stub_t *stub) {
if (stub->db != NULL) if (stub->db != NULL)
dns_db_detach(&stub->db); dns_db_detach(&stub->db);
isc_mem_put(stub->mctx, stub, sizeof(*stub)); isc_mem_put(stub->mctx, stub, sizeof(*stub));
dns_zone_idetach(&zone);
} }
if (message != NULL) if (message != NULL)
dns_message_destroy(&message); dns_message_destroy(&message);
cancel_refresh(zone);
return; return;
} }
@ -3651,11 +3666,11 @@ zone_shutdown(isc_task_t *task, isc_event_t *event) {
if (zone->xfr != NULL) if (zone->xfr != NULL)
dns_xfrin_shutdown(zone->xfr); dns_xfrin_shutdown(zone->xfr);
LOCK_ZONE(zone);
if (zone->request != NULL) { if (zone->request != NULL) {
LOCK_ZONE(zone);
dns_request_cancel(zone->request); dns_request_cancel(zone->request);
UNLOCK_ZONE(zone);
} }
UNLOCK_ZONE(zone);
if (zone->readio != NULL) if (zone->readio != NULL)
zonemgr_cancelio(zone->readio); zonemgr_cancelio(zone->readio);