2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

841. [bug] When sdb modules were not declared threadsafe, their

create and destroy functions were not serialized.
This commit is contained in:
Brian Wellington
2001-05-29 18:34:24 +00:00
parent b96a1d9fa3
commit e2fd12f3a0
2 changed files with 31 additions and 22 deletions

View File

@@ -1,3 +1,6 @@
841. [bug] When sdb modules were not declared threadsafe, their
create and destroy functions were not serialized.
840. [bug] The config file parser could print the wrong file 840. [bug] The config file parser could print the wrong file
name if an error was detected after an included file name if an error was detected after an included file
was parsed. [RT #1353] was parsed. [RT #1353]

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: sdb.c,v 1.31 2001/05/02 19:25:19 bwelling Exp $ */ /* $Id: sdb.c,v 1.32 2001/05/29 18:34:24 bwelling Exp $ */
#include <config.h> #include <config.h>
@@ -52,6 +52,7 @@ struct dns_sdbimplementation {
void *driverdata; void *driverdata;
unsigned int flags; unsigned int flags;
isc_mem_t *mctx; isc_mem_t *mctx;
isc_mutex_t driverlock;
dns_dbimplementation_t *dbimp; dns_dbimplementation_t *dbimp;
}; };
@@ -62,7 +63,6 @@ struct dns_sdb {
dns_sdbimplementation_t *implementation; dns_sdbimplementation_t *implementation;
void *dbdata; void *dbdata;
isc_mutex_t lock; isc_mutex_t lock;
isc_mutex_t driverlock;
/* Locked */ /* Locked */
unsigned int references; unsigned int references;
@@ -119,14 +119,14 @@ typedef struct sdb_rdatasetiter {
do { \ do { \
unsigned int flags = sdb->implementation->flags; \ unsigned int flags = sdb->implementation->flags; \
if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \ if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
LOCK(&sdb->driverlock); \ LOCK(&sdb->implementation->driverlock); \
} while (0) } while (0)
#define MAYBE_UNLOCK(sdb) \ #define MAYBE_UNLOCK(sdb) \
do { \ do { \
unsigned int flags = sdb->implementation->flags; \ unsigned int flags = sdb->implementation->flags; \
if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \ if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \
UNLOCK(&sdb->driverlock); \ UNLOCK(&sdb->implementation->driverlock); \
} while (0) } while (0)
static int dummy; static int dummy;
@@ -220,16 +220,28 @@ dns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods,
imp->flags = flags; imp->flags = flags;
imp->mctx = NULL; imp->mctx = NULL;
isc_mem_attach(mctx, &imp->mctx); isc_mem_attach(mctx, &imp->mctx);
result = isc_mutex_init(&imp->driverlock);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_mutex_init() failed: %s",
isc_result_totext(result));
goto cleanup_mctx;
}
imp->dbimp = NULL; imp->dbimp = NULL;
result = dns_db_register(drivername, dns_sdb_create, imp, mctx, result = dns_db_register(drivername, dns_sdb_create, imp, mctx,
&imp->dbimp); &imp->dbimp);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS)
dns_sdb_unregister(&imp); goto cleanup_mutex;
return (result);
}
*sdbimp = imp; *sdbimp = imp;
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
cleanup_mutex:
DESTROYLOCK(&imp->driverlock);
cleanup_mctx:
isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
return (result);
} }
void void
@@ -241,6 +253,7 @@ dns_sdb_unregister(dns_sdbimplementation_t **sdbimp) {
imp = *sdbimp; imp = *sdbimp;
dns_db_unregister(&imp->dbimp); dns_db_unregister(&imp->dbimp);
DESTROYLOCK(&imp->driverlock);
mctx = imp->mctx; mctx = imp->mctx;
isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t)); isc_mem_put(mctx, imp, sizeof(dns_sdbimplementation_t));
@@ -476,13 +489,15 @@ destroy(dns_sdb_t *sdb) {
mctx = sdb->common.mctx; mctx = sdb->common.mctx;
if (imp->methods->destroy != NULL) if (imp->methods->destroy != NULL) {
MAYBE_LOCK(sdb);
imp->methods->destroy(sdb->zone, imp->driverdata, imp->methods->destroy(sdb->zone, imp->driverdata,
&sdb->dbdata); &sdb->dbdata);
MAYBE_UNLOCK(sdb);
}
isc_mem_free(mctx, sdb->zone); isc_mem_free(mctx, sdb->zone);
DESTROYLOCK(&sdb->lock); DESTROYLOCK(&sdb->lock);
DESTROYLOCK(&sdb->driverlock);
sdb->common.magic = 0; sdb->common.magic = 0;
sdb->common.impmagic = 0; sdb->common.impmagic = 0;
@@ -1195,18 +1210,9 @@ dns_sdb_create(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
goto cleanup_mctx; goto cleanup_mctx;
} }
result = isc_mutex_init(&sdb->driverlock);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_mutex_init() failed: %s",
isc_result_totext(result));
result = ISC_R_UNEXPECTED;
goto cleanup_lock;
}
result = dns_name_dupwithoffsets(origin, mctx, &sdb->common.origin); result = dns_name_dupwithoffsets(origin, mctx, &sdb->common.origin);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup_driverlock; goto cleanup_lock;
isc_buffer_init(&b, zonestr, sizeof(zonestr)); isc_buffer_init(&b, zonestr, sizeof(zonestr));
result = dns_name_totext(origin, ISC_TRUE, &b); result = dns_name_totext(origin, ISC_TRUE, &b);
@@ -1222,8 +1228,10 @@ dns_sdb_create(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
sdb->dbdata = NULL; sdb->dbdata = NULL;
if (imp->methods->create != NULL) { if (imp->methods->create != NULL) {
MAYBE_LOCK(sdb);
result = imp->methods->create(sdb->zone, argc, argv, result = imp->methods->create(sdb->zone, argc, argv,
imp->driverdata, &sdb->dbdata); imp->driverdata, &sdb->dbdata);
MAYBE_UNLOCK(sdb);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto cleanup_zonestr; goto cleanup_zonestr;
} }
@@ -1241,8 +1249,6 @@ dns_sdb_create(isc_mem_t *mctx, dns_name_t *origin, dns_dbtype_t type,
isc_mem_free(mctx, sdb->zone); isc_mem_free(mctx, sdb->zone);
cleanup_origin: cleanup_origin:
dns_name_free(&sdb->common.origin, mctx); dns_name_free(&sdb->common.origin, mctx);
cleanup_driverlock:
isc_mutex_destroy(&sdb->driverlock);
cleanup_lock: cleanup_lock:
isc_mutex_destroy(&sdb->lock); isc_mutex_destroy(&sdb->lock);
cleanup_mctx: cleanup_mctx: