In this phase, CDB is a configure option, and is either enabled or disabled
for all volumes at compile time. By default, CDB is disabled in favor of
transactional data store.
CDB has some advantages. It doesn't use transactions or logging, thus it's
less likely to be corrupted if the server dies prematurely. It also
doesn't eat up disk space with transaction logs. The disadvantage is that
it's designed for environments with many readers and one writer. This means
that many afpd clients could block while waiting for a write lock on
the database. That's why testing is in order.
In phase 2, CDB is be configurable on a per-volume basis.
Phase 3 (if testing of phase 1 and 2 is good) will be to enable CDB as the
default CNID data store scheme.
To enable CDB, simply specify the configure argument --with-cdb when
configuring with CNID DID support.
Submitted by: Dan Wilga <dwilga@mtholyoke.edu>
13 files changed:
* NEW: Add a -noslp option to disable SLP per afpd instance.
* NEW: Added -d option for pap to enable debugging at runtime rather than
compile time.
* NEW: Add a -noslp option to disable SLP per afpd instance.
* NEW: Added -d option for pap to enable debugging at runtime rather than
compile time.
+* NEW: Add the ability to use Concurrent Data Store instead of full
+ transactional data store with the CNID DID calculation scheme.
* FIX: Cleaned up pap man page, eliminating duplicate pap man page (8).
* FIX: Print out pap status in postscript (%%[..]%%) format for LPRng
compatibility.
* FIX: Cleaned up pap man page, eliminating duplicate pap man page (8).
* FIX: Print out pap status in postscript (%%[..]%%) format for LPRng
compatibility.
#undef BSD4_4
#undef CNID_DB
#undef FILE_MANGLING
#undef BSD4_4
#undef CNID_DB
#undef FILE_MANGLING
#undef DISABLE_LOGGER
#undef LOGFILEPATH
#undef DEBUG
#undef DISABLE_LOGGER
#undef LOGFILEPATH
#undef DEBUG
-dnl $Id: configure.in,v 1.161 2002-08-25 13:26:19 rlewczuk Exp $
+dnl $Id: configure.in,v 1.162 2002-08-30 03:12:45 jmarcus Exp $
dnl configure.in for netatalk
AC_INIT(bin/adv1tov2/adv1tov2.c)
dnl configure.in for netatalk
AC_INIT(bin/adv1tov2/adv1tov2.c)
AC_DEFINE(FILE_MANGLING, 1)
AC_MSG_RESULT([yes])
fi
AC_DEFINE(FILE_MANGLING, 1)
AC_MSG_RESULT([yes])
fi
+ else
+ AC_MSG_RESULT([no])
+ fi
+ , AC_MSG_RESULT([no])
+)
+
+dnl Determine whether or not to use CDB or transactional DB store
+AC_MSG_CHECKING([whether or not to use CNID with Concurrent Data Store])
+AC_ARG_WITH(cdb,
+ [ --with-cdb enable CNID with Concurrent Data Store],
+ if test "$withval" = "yes"; then
+ if test "x$did_scheme" != "xcnid"; then
+ AC_MSG_ERROR([DID scheme must be CNID to use CDB])
+ else
+ AC_DEFINE(CNID_DB_CDB, 1)
+ AC_MSG_RESULT([yes])
+ fi
+ else
+ AC_MSG_RESULT([no])
)
dnl Check for Berkeley DB3 library
)
dnl Check for Berkeley DB3 library
- * $Id: cnid_add.c,v 1.29 2002-02-02 19:11:37 jmarcus Exp $
+ * $Id: cnid_add.c,v 1.30 2002-08-30 03:12:52 jmarcus Exp $
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
#include "cnid_private.h"
#include "cnid_private.h"
+#ifdef CNID_DB_CDB
+ #define tid NULL
+#endif /* CNID_DB_CDB */
+
/* add an entry to the CNID databases. we do this as a transaction
* to prevent messiness. */
static int add_cnid(CNID_private *db, DBT *key, DBT *data) {
DBT altkey, altdata;
/* add an entry to the CNID databases. we do this as a transaction
* to prevent messiness. */
static int add_cnid(CNID_private *db, DBT *key, DBT *data) {
DBT altkey, altdata;
+#endif /* CNID_DB_CDB */
int rc, ret;
memset(&altkey, 0, sizeof(altkey));
memset(&altdata, 0, sizeof(altdata));
int rc, ret;
memset(&altkey, 0, sizeof(altkey));
memset(&altdata, 0, sizeof(altdata));
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
return rc;
}
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
return rc;
}
+#endif /* CNID_DB_CDB */
/* main database */
if ((rc = db->db_cnid->put(db->db_cnid, tid, key, data, DB_NOOVERWRITE))) {
/* main database */
if ((rc = db->db_cnid->put(db->db_cnid, tid, key, data, DB_NOOVERWRITE))) {
if (rc == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
return ret;
}
goto retry;
}
if (rc == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
return ret;
}
goto retry;
}
+#endif /* CNID_DB_CDB */
altdata.data = key->data;
altdata.size = key->size;
if ((rc = db->db_devino->put(db->db_devino, tid, &altkey, &altdata, 0))) {
altdata.data = key->data;
altdata.size = key->size;
if ((rc = db->db_devino->put(db->db_devino, tid, &altkey, &altdata, 0))) {
if (rc == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
return ret;
}
goto retry;
}
if (rc == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
return ret;
}
goto retry;
}
+#endif /* CNID_DB_CDB */
altkey.data = (char *) data->data + CNID_DEVINO_LEN;
altkey.size = data->size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->put(db->db_didname, tid, &altkey, &altdata, 0))) {
altkey.data = (char *) data->data + CNID_DEVINO_LEN;
altkey.size = data->size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->put(db->db_didname, tid, &altkey, &altdata, 0))) {
if (rc == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
return ret;
}
goto retry;
}
if (rc == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
return ret;
}
goto retry;
}
+#endif /* CNID_DB_CDB */
if ((rc = txn_commit(tid, 0)) != 0) {
LOG(log_error, logtype_default, "add_cnid: Failed to commit transaction: %s", db_strerror(rc));
return rc;
}
if ((rc = txn_commit(tid, 0)) != 0) {
LOG(log_error, logtype_default, "add_cnid: Failed to commit transaction: %s", db_strerror(rc));
return rc;
}
+#endif /* CNID_DB_CDB */
{
CNID_private *db;
DBT key, data, rootinfo_key, rootinfo_data;
{
CNID_private *db;
DBT key, data, rootinfo_key, rootinfo_data;
+#endif /* CNID_DB_CDB */
struct timeval t;
cnid_t id, save;
int rc;
struct timeval t;
cnid_t id, save;
int rc;
rootinfo_key.data = ROOTINFO_KEY;
rootinfo_key.size = ROOTINFO_KEYLEN;
rootinfo_key.data = ROOTINFO_KEY;
rootinfo_key.size = ROOTINFO_KEYLEN;
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_add: Failed to begin transaction: %s", db_strerror(rc));
errno = CNID_ERR_DB;
return CNID_INVALID;
}
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_add: Failed to begin transaction: %s", db_strerror(rc));
errno = CNID_ERR_DB;
return CNID_INVALID;
}
+#endif /* CNID_DB_CDB */
+#ifdef CNID_DB_CDB
+ switch (rc = db->db_didname->get(db->db_didname, NULL, &rootinfo_key,
+ &rootinfo_data, 0)) {
+#else /* CNID_DB_CDB */
switch (rc = db->db_didname->get(db->db_didname, tid, &rootinfo_key,
&rootinfo_data, DB_RMW)) {
case DB_LOCK_DEADLOCK:
switch (rc = db->db_didname->get(db->db_didname, tid, &rootinfo_key,
&rootinfo_data, DB_RMW)) {
case DB_LOCK_DEADLOCK:
return CNID_INVALID;
}
goto retry;
return CNID_INVALID;
}
goto retry;
+#endif /* CNID_DB_CDB */
case 0:
memcpy(&hint, rootinfo_data.data, sizeof(hint));
id = ntohl(hint);
/* If we've hit the max CNID allowed, we return a fatal error. CNID
* needs to be recycled before proceding. */
if (++id == CNID_INVALID) {
case 0:
memcpy(&hint, rootinfo_data.data, sizeof(hint));
id = ntohl(hint);
/* If we've hit the max CNID allowed, we return a fatal error. CNID
* needs to be recycled before proceding. */
if (++id == CNID_INVALID) {
+#endif /* CNID_DB_CDB */
LOG(log_error, logtype_default, "cnid_add: FATAL: Cannot add CNID for %s. CNID database has reached its limit.", name);
errno = CNID_ERR_MAX;
return CNID_INVALID;
LOG(log_error, logtype_default, "cnid_add: FATAL: Cannot add CNID for %s. CNID database has reached its limit.", name);
errno = CNID_ERR_MAX;
return CNID_INVALID;
rootinfo_data.size = sizeof(hint);
switch (rc = db->db_didname->put(db->db_didname, tid, &rootinfo_key, &rootinfo_data, 0)) {
rootinfo_data.size = sizeof(hint);
switch (rc = db->db_didname->put(db->db_didname, tid, &rootinfo_key, &rootinfo_data, 0)) {
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_add: txn_abort: %s", db_strerror(rc));
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_add: txn_abort: %s", db_strerror(rc));
return CNID_INVALID;
}
goto retry;
return CNID_INVALID;
}
goto retry;
+#endif /* CNID_DB_CDB */
/* The transaction finished, commit it. */
if ((rc = txn_commit(tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_add: Unable to commit transaction: %s", db_strerror(rc));
errno = CNID_ERR_DB;
return CNID_INVALID;
}
/* The transaction finished, commit it. */
if ((rc = txn_commit(tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_add: Unable to commit transaction: %s", db_strerror(rc));
errno = CNID_ERR_DB;
return CNID_INVALID;
}
+#endif /* CNID_DB_CDB */
break;
default:
LOG(log_error, logtype_default, "cnid_add: Unable to update rootinfo: %s", db_strerror(rc));
break;
default:
LOG(log_error, logtype_default, "cnid_add: Unable to update rootinfo: %s", db_strerror(rc));
return hint;
cleanup_abort:
return hint;
cleanup_abort:
+#endif /* CNID_DB_CDB */
errno = CNID_ERR_DB;
return CNID_INVALID;
errno = CNID_ERR_DB;
return CNID_INVALID;
- * $Id: cnid_close.c,v 1.24 2002-06-03 22:58:10 jmarcus Exp $
+ * $Id: cnid_close.c,v 1.25 2002-08-30 03:12:52 jmarcus Exp $
/* Flush the transaction log and delete the log file if we can. */
if ((db->lockfd > -1) && ((db->flags & CNIDFLAG_DB_RO) == 0)) {
struct flock lock;
/* Flush the transaction log and delete the log file if we can. */
if ((db->lockfd > -1) && ((db->flags & CNIDFLAG_DB_RO) == 0)) {
struct flock lock;
}
(void)remove(db->lock_file);
}
}
(void)remove(db->lock_file);
}
+#endif /* CNID_DB_CDB */
db->db_didname->close(db->db_didname, 0);
db->db_devino->close(db->db_devino, 0);
db->db_didname->close(db->db_didname, 0);
db->db_devino->close(db->db_devino, 0);
#endif /* FILE_MANGLING */
db->dbenv->close(db->dbenv, 0);
#endif /* FILE_MANGLING */
db->dbenv->close(db->dbenv, 0);
if (db->lockfd > -1) {
close(db->lockfd); /* This will also release any locks we have. */
}
if (db->lockfd > -1) {
close(db->lockfd); /* This will also release any locks we have. */
}
+#endif /* CNID_DB_CDB */
- * $Id: cnid_delete.c,v 1.13 2002-01-19 21:42:08 jmarcus Exp $
+ * $Id: cnid_delete.c,v 1.14 2002-08-30 03:12:52 jmarcus Exp $
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
#include "cnid_private.h"
#include "cnid_private.h"
+#ifdef CNID_DB_CDB
+ #define tid NULL
+#endif /* CNID_DB_CDB */
+
int cnid_delete(void *CNID, const cnid_t id) {
CNID_private *db;
DBT key, data;
int cnid_delete(void *CNID, const cnid_t id) {
CNID_private *db;
DBT key, data;
+#endif /* CNID_DB_CDB */
int rc, found = 0;
if (!(db = CNID) || !id || (db->flags & CNIDFLAG_DB_RO)) {
int rc, found = 0;
if (!(db = CNID) || !id || (db->flags & CNIDFLAG_DB_RO)) {
case 0:
found = 1;
break;
case 0:
found = 1;
break;
case DB_LOCK_DEADLOCK:
break;
case DB_LOCK_DEADLOCK:
break;
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
#ifdef DEBUG
LOG(log_info, logtype_default, "cnid_delete: CNID %u not in database",
case DB_NOTFOUND:
#ifdef DEBUG
LOG(log_info, logtype_default, "cnid_delete: CNID %u not in database",
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: Failed to begin transaction: %s",
db_strerror(rc));
return rc;
}
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: Failed to begin transaction: %s",
db_strerror(rc));
return rc;
}
+#endif /* CNID_DB_CDB */
/* Now delete from the main CNID database. */
key.data = (cnid_t *)&id;
key.size = sizeof(id);
if ((rc = db->db_cnid->del(db->db_cnid, tid, &key, 0))) {
/* Now delete from the main CNID database. */
key.data = (cnid_t *)&id;
key.size = sizeof(id);
if ((rc = db->db_cnid->del(db->db_cnid, tid, &key, 0))) {
int ret;
if ((ret = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s", db_strerror(ret));
int ret;
if ((ret = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s", db_strerror(ret));
case DB_LOCK_DEADLOCK:
goto retry;
default:
case DB_LOCK_DEADLOCK:
goto retry;
default:
+#endif /* CNID_DB_CDB */
+#endif /* CNID_DB_CDB */
}
/* Now delete from dev/ino database. */
}
/* Now delete from dev/ino database. */
key.size = CNID_DEVINO_LEN;
if ((rc = db->db_devino->del(db->db_devino, tid, &key, 0))) {
switch (rc) {
key.size = CNID_DEVINO_LEN;
if ((rc = db->db_devino->del(db->db_devino, tid, &key, 0))) {
switch (rc) {
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
/* Quietly fall through if the entry isn't found. */
break;
default:
case DB_NOTFOUND:
/* Quietly fall through if the entry isn't found. */
break;
default:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
db_strerror(rc));
return rc;
}
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
db_strerror(rc));
return rc;
}
+#endif /* CNID_DB_CDB */
key.size = data.size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->del(db->db_didname, tid, &key, 0))) {
switch (rc) {
key.size = data.size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->del(db->db_didname, tid, &key, 0))) {
switch (rc) {
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
break;
default:
case DB_NOTFOUND:
break;
default:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
db_strerror(rc));
return rc;
}
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
db_strerror(rc));
return rc;
}
+#endif /* CNID_DB_CDB */
#ifdef DEBUG
LOG(log_info, logtype_default, "cnid_delete: Deleting CNID %u", ntohl(id));
#endif
#ifdef DEBUG
LOG(log_info, logtype_default, "cnid_delete: Deleting CNID %u", ntohl(id));
#endif
if ((rc = txn_commit(tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: Failed to commit transaction: %s",
db_strerror(rc));
return rc;
}
if ((rc = txn_commit(tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: Failed to commit transaction: %s",
db_strerror(rc));
return rc;
}
+#endif /* CNID_DB_CDB */
- * $Id: cnid_get.c,v 1.12 2002-01-19 21:42:08 jmarcus Exp $
+ * $Id: cnid_get.c,v 1.13 2002-08-30 03:12:52 jmarcus Exp $
key.size = CNID_DID_LEN + len + 1;
while ((rc = db->db_didname->get(db->db_didname, NULL, &key, &data, 0))) {
key.size = CNID_DID_LEN + len + 1;
while ((rc = db->db_didname->get(db->db_didname, NULL, &key, &data, 0))) {
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
+#endif /* CNID_DB_CDB */
if (rc != DB_NOTFOUND) {
LOG(log_error, logtype_default, "cnid_get: Unable to get CNID %u, name %s: %s",
if (rc != DB_NOTFOUND) {
LOG(log_error, logtype_default, "cnid_get: Unable to get CNID %u, name %s: %s",
- * $Id: cnid_lookup.c,v 1.13 2002-06-03 22:58:10 jmarcus Exp $
+ * $Id: cnid_lookup.c,v 1.14 2002-08-30 03:12:52 jmarcus Exp $
/* Do a little checkpointing if necessary. I stuck it here as cnid_lookup
* gets called when we do directory lookups. Only do this if we're using
* a read-write database. */
/* Do a little checkpointing if necessary. I stuck it here as cnid_lookup
* gets called when we do directory lookups. Only do this if we're using
* a read-write database. */
+#endif /* CNID_DB_CDB */
if ((buf = make_cnid_data(st, did, name, len)) == NULL) {
LOG(log_error, logtype_default, "cnid_lookup: Pathname is too long");
if ((buf = make_cnid_data(st, did, name, len)) == NULL) {
LOG(log_error, logtype_default, "cnid_lookup: Pathname is too long");
key.data = buf;
key.size = CNID_DEVINO_LEN;
while ((rc = db->db_devino->get(db->db_devino, NULL, &key, &devdata, 0))) {
key.data = buf;
key.size = CNID_DEVINO_LEN;
while ((rc = db->db_devino->get(db->db_devino, NULL, &key, &devdata, 0))) {
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
+#endif /* CNID_DB_CDB */
if (rc == DB_NOTFOUND) {
devino = 0;
if (rc == DB_NOTFOUND) {
devino = 0;
key.data = buf + CNID_DEVINO_LEN;
key.size = CNID_DID_LEN + len + 1;
while ((rc = db->db_didname->get(db->db_didname, NULL, &key, &diddata, 0))) {
key.data = buf + CNID_DEVINO_LEN;
key.size = CNID_DID_LEN + len + 1;
while ((rc = db->db_didname->get(db->db_didname, NULL, &key, &diddata, 0))) {
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
+#endif /* CNID_DB_CDB */
if (rc == DB_NOTFOUND) {
didname = 0;
if (rc == DB_NOTFOUND) {
didname = 0;
- * $Id: cnid_mangle_add.c,v 1.3 2002-06-03 22:55:31 jmarcus Exp $
+ * $Id: cnid_mangle_add.c,v 1.4 2002-08-30 03:12:52 jmarcus Exp $
#include "cnid_private.h"
#include "cnid_private.h"
+#ifdef CNID_DB_CDB
+ #define tid NULL
+#endif /* CNID_DB_CDB */
+
/* Add a mangled filename. */
int
cnid_mangle_add(void *CNID, char *mfilename, char *filename)
{
CNID_private *db;
DBT key, data;
/* Add a mangled filename. */
int
cnid_mangle_add(void *CNID, char *mfilename, char *filename)
{
CNID_private *db;
DBT key, data;
+#endif /* CNID_DB_CDB */
data.data = filename;
data.size = strlen(filename) + 1;
data.data = filename;
data.size = strlen(filename) + 1;
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
- LOG(log_error, logtype_default, "cnid_mangle_add: Failed to begin transaction: %s", db_strerror(rc));
- return -1;
+ LOG(log_error, logtype_default, "cnid_mangle_add: Failed to begin transaction: %s", db_strerror(rc));
+ return -1;
+#endif /* CNID_DB_CDB */
if ((rc = db->db_mangle->put(db->db_mangle, tid, &key, &data, 0))) {
if ((rc = db->db_mangle->put(db->db_mangle, tid, &key, &data, 0))) {
- if ((ret = txn_abort(tid)) != 0) {
- LOG(log_error, logtype_default, "cnid_mangle_add: txn_abort: %s", db_strerror(ret));
- return -1;
- }
- switch (rc) {
- case DB_LOCK_DEADLOCK:
- goto retry;
- default:
- LOG(log_error, logtype_default, "cnid_mangle_add: Failed to add mangled filename to the database: %s", db_strerror(rc));
- return -1;
- }
+#ifndef CNID_DB_CDB
+ if ((ret = txn_abort(tid)) != 0) {
+ LOG(log_error, logtype_default, "cnid_mangle_add: txn_abort: %s", db_strerror(ret));
+ return -1;
+ }
+#endif /* CNID_DB_CDB */
+ switch (rc) {
+#ifndef CNID_DB_CDB
+ case DB_LOCK_DEADLOCK:
+ goto retry;
+#endif /* CNID_DB_CDB */
+ default:
+ LOG(log_error, logtype_default, "cnid_mangle_add: Failed to add mangled filename to the database: %s", db_strerror(rc));
+ return -1;
+ }
if ((rc = txn_commit(tid, 0)) != 0) {
if ((rc = txn_commit(tid, 0)) != 0) {
- LOG(log_error, logtype_default, "cnid_mangle_add: Unable to commit transaction: %s", db_strerror(rc));
- return -1;
+ LOG(log_error, logtype_default, "cnid_mangle_add: Unable to commit transaction: %s", db_strerror(rc));
+ return -1;
+#endif /* CNID_DB_CDB */
- * $Id: cnid_mangle_get.c,v 1.5 2002-06-09 07:15:58 jmarcus Exp $
+ * $Id: cnid_mangle_get.c,v 1.6 2002-08-30 03:12:52 jmarcus Exp $
{
CNID_private *db;
DBT key, data;
{
CNID_private *db;
DBT key, data;
cnid_t id;
struct stat st;
char *filename;
cnid_t id;
struct stat st;
char *filename;
- * $Id: cnid_open.c,v 1.41 2002-06-03 22:58:10 jmarcus Exp $
+ * $Id: cnid_open.c,v 1.42 2002-08-30 03:12:52 jmarcus Exp $
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
*
* Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT.
* CNIDs 4-16 are reserved according to page 31 of the AFP 3.0 spec so,
* CNID_START begins at 17.
*/
* CNIDs 4-16 are reserved according to page 31 of the AFP 3.0 spec so,
* CNID_START begins at 17.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#define DBVERSION1 0x00000001U
#define DBVERSION DBVERSION1
#define DBVERSION1 0x00000001U
#define DBVERSION DBVERSION1
+#ifdef CNID_DB_CDB
+#define DBOPTIONS (DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL)
+#else /* !CNID_DB_CDB */
#if DB_VERSION_MAJOR >= 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR > 1)
#define DBOPTIONS (DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | \
DB_INIT_LOG | DB_INIT_TXN)
#if DB_VERSION_MAJOR >= 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR > 1)
#define DBOPTIONS (DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | \
DB_INIT_LOG | DB_INIT_TXN)
#define DBOPTIONS (DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | \
DB_INIT_LOG | DB_INIT_TXN)
#endif /* DB_VERSION_MINOR */
#define DBOPTIONS (DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | \
DB_INIT_LOG | DB_INIT_TXN)
#endif /* DB_VERSION_MINOR */
+#endif /* CNID_DB_CDB */
/* Let's try and use the youngest lock detector if present.
* If we can't do that, then let DB3 use its default deadlock detector. */
#if defined DB_LOCK_YOUNGEST
/* Let's try and use the youngest lock detector if present.
* If we can't do that, then let DB3 use its default deadlock detector. */
#if defined DB_LOCK_YOUNGEST
#else /* DB_LOCK_YOUNGEST */
#define DEAD_LOCK_DETECT DB_LOCK_DEFAULT
#endif /* DB_LOCK_YOUNGEST */
#else /* DB_LOCK_YOUNGEST */
#define DEAD_LOCK_DETECT DB_LOCK_DEFAULT
#endif /* DB_LOCK_YOUNGEST */
+#endif /* CNID_DB_CDB */
#define MAXITER 0xFFFF /* maximum number of simultaneously open CNID
* databases. */
#define MAXITER 0xFFFF /* maximum number of simultaneously open CNID
* databases. */
void *cnid_open(const char *dir) {
struct stat st, rsb, lsb, csb;
void *cnid_open(const char *dir) {
struct stat st, rsb, lsb, csb;
+#endif /* CNID_DB_CDB */
char path[MAXPATHLEN + 1];
CNID_private *db;
DBT key, data;
char path[MAXPATHLEN + 1];
CNID_private *db;
DBT key, data;
- lock.l_type = F_WRLCK;
- lock.l_whence = SEEK_SET;
-
strcpy(path + len, DBHOME);
if ((stat(path, &st) < 0) && (ad_mkdir(path, 0777) < 0)) {
LOG(log_error, logtype_default, "cnid_open: DBHOME mkdir failed for %s", path);
goto fail_adouble;
}
strcpy(path + len, DBHOME);
if ((stat(path, &st) < 0) && (ad_mkdir(path, 0777) < 0)) {
LOG(log_error, logtype_default, "cnid_open: DBHOME mkdir failed for %s", path);
goto fail_adouble;
}
+#ifndef CNID_DB_CDB
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
/* Make sure cnid.lock goes in .AppleDB. */
strcat(path, "/");
len++;
/* Make sure cnid.lock goes in .AppleDB. */
strcat(path, "/");
len++;
else {
LOG(log_error, logtype_default, "cnid_open: Cannot establish logfile cleanup lock for database environment %s (open() failed)", path);
}
else {
LOG(log_error, logtype_default, "cnid_open: Cannot establish logfile cleanup lock for database environment %s (open() failed)", path);
}
+#endif /* CNID_DB_CDB */
path[len + DBHOMELEN] = '\0';
open_flag = DB_CREATE;
path[len + DBHOMELEN] = '\0';
open_flag = DB_CREATE;
/* Setup internal deadlock detection. */
if ((rc = db->dbenv->set_lk_detect(db->dbenv, DEAD_LOCK_DETECT)) != 0) {
LOG(log_error, logtype_default, "cnid_open: set_lk_detect: %s", db_strerror(rc));
goto fail_lock;
}
/* Setup internal deadlock detection. */
if ((rc = db->dbenv->set_lk_detect(db->dbenv, DEAD_LOCK_DETECT)) != 0) {
LOG(log_error, logtype_default, "cnid_open: set_lk_detect: %s", db_strerror(rc));
goto fail_lock;
}
+#endif /* CNID_DB_CDB */
#if DB_VERSION_MAJOR >= 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR > 1)
#if 0
/* Take care of setting the DB_TXN_NOSYNC flag in db3 > 3.1.x. */
#if DB_VERSION_MAJOR >= 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR > 1)
#if 0
/* Take care of setting the DB_TXN_NOSYNC flag in db3 > 3.1.x. */
}
#endif
#endif /* DB_VERSION_MINOR > 1 */
}
#endif
#endif /* DB_VERSION_MINOR > 1 */
+#endif /* CNID_DB_CDB */
/* Open the database environment. */
if ((rc = db->dbenv->open(db->dbenv, path, DBOPTIONS, 0666)) != 0) {
/* Open the database environment. */
if ((rc = db->dbenv->open(db->dbenv, path, DBOPTIONS, 0666)) != 0) {
key.data = DBVERSION_KEY;
key.size = DBVERSION_KEYLEN;
key.data = DBVERSION_KEY;
key.size = DBVERSION_KEYLEN;
+#ifdef CNID_DB_CDB
+ if ((rc = db->db_didname->get(db->db_didname, NULL, &key, &data, 0)) != 0) {
+ int ret;
+ {
+ u_int32_t version = htonl(DBVERSION);
+
+ data.data = &version;
+ data.size = sizeof(version);
+ }
+ if ((ret = db->db_didname->put(db->db_didname, NULL, &key, &data,
+ DB_NOOVERWRITE))) {
+ LOG(log_error, logtype_default, "cnid_open: Error putting new version: %s",
+ db_strerror(ret));
+ db->db_didname->close(db->db_didname, 0);
+ goto fail_appinit;
+ }
+ }
+#else /* CNID_DB_CDB */
dbversion_retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: txn_begin: failed to check db version: %s",
dbversion_retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0)) != 0) {
LOG(log_error, logtype_default, "cnid_open: txn_begin: failed to check db version: %s",
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
db->db_didname->close(db->db_didname, 0);
goto fail_appinit;
}
+#endif /* CNID_DB_CDB */
/* TODO In the future we might check for version number here. */
#if 0
/* TODO In the future we might check for version number here. */
#if 0
db->db_shortname->close(db->db_shortname, 0);
db->db_longname->close(db->db_longname, 0);
#endif /* EXTENDED_DB */
db->db_shortname->close(db->db_shortname, 0);
db->db_longname->close(db->db_longname, 0);
#endif /* EXTENDED_DB */
- db->db_devino->close(db->db_devino, 0);
+ db->db_devino->close(db->db_devino, 0);
db->dbenv->close(db->dbenv, 0);
fail_lock:
db->dbenv->close(db->dbenv, 0);
fail_lock:
if (db->lockfd > -1) {
close(db->lockfd);
(void)remove(db->lock_file);
}
if (db->lockfd > -1) {
close(db->lockfd);
(void)remove(db->lock_file);
}
+#endif /* CNID_DB_CDB */
- * $Id: cnid_resolve.c,v 1.12 2002-03-24 17:43:42 jmarcus Exp $
+ * $Id: cnid_resolve.c,v 1.13 2002-08-30 03:12:52 jmarcus Exp $
key.data = id;
key.size = sizeof(cnid_t);
while ((rc = db->db_cnid->get(db->db_cnid, NULL, &key, &data, 0))) {
key.data = id;
key.size = sizeof(cnid_t);
while ((rc = db->db_cnid->get(db->db_cnid, NULL, &key, &data, 0))) {
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
+#endif /* CNID_DB_CDB */
if (rc != DB_NOTFOUND) {
LOG(log_error, logtype_default, "cnid_resolve: Unable to get did/name: %s",
if (rc != DB_NOTFOUND) {
LOG(log_error, logtype_default, "cnid_resolve: Unable to get did/name: %s",
- * $Id: cnid_update.c,v 1.19 2002-01-24 16:46:53 jmarcus Exp $
+ * $Id: cnid_update.c,v 1.20 2002-08-30 03:12:52 jmarcus Exp $
#include "cnid_private.h"
#include "cnid_private.h"
+#ifdef CNID_DB_CDB
+ #define tid NULL
+#endif /* CNID_DB_CDB */
+
/* cnid_update: takes the given cnid and updates the metadata. To
* handle the did/name data, there are a bunch of functions to get
* and set the various fields. */
/* cnid_update: takes the given cnid and updates the metadata. To
* handle the did/name data, there are a bunch of functions to get
* and set the various fields. */
{
CNID_private *db;
DBT key, data, altdata;
{
CNID_private *db;
DBT key, data, altdata;
+#endif /* CNID_DB_CDB */
int rc;
if (!(db = CNID) || !id || !st || !name || (db->flags & CNIDFLAG_DB_RO)) {
int rc;
if (!(db = CNID) || !id || !st || !name || (db->flags & CNIDFLAG_DB_RO)) {
memset(&key, 0, sizeof(key));
memset(&altdata, 0, sizeof(altdata));
memset(&key, 0, sizeof(key));
memset(&altdata, 0, sizeof(altdata));
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0))) {
LOG(log_error, logtype_default, "cnid_update: Failed to begin transaction: %s", db_strerror(rc));
return rc;
}
retry:
if ((rc = txn_begin(db->dbenv, NULL, &tid, 0))) {
LOG(log_error, logtype_default, "cnid_update: Failed to begin transaction: %s", db_strerror(rc));
return rc;
}
+#endif /* CNID_DB_CDB */
/* Get the old info. */
key.data = (cnid_t *)&id;
key.size = sizeof(id);
memset(&data, 0, sizeof(data));
/* Get the old info. */
key.data = (cnid_t *)&id;
key.size = sizeof(id);
memset(&data, 0, sizeof(data));
+#ifdef CNID_DB_CDB
+ if ((rc = db->db_cnid->get(db->db_cnid, NULL, &key, &data, 0))) {
+#else /* CNID_DB_CDB */
if ((rc = db->db_cnid->get(db->db_cnid, tid, &key, &data, DB_RMW))) {
txn_abort(tid);
if ((rc = db->db_cnid->get(db->db_cnid, tid, &key, &data, DB_RMW))) {
txn_abort(tid);
+#endif /* CNID_DB_CDB */
case DB_LOCK_DEADLOCK:
goto retry;
case DB_LOCK_DEADLOCK:
goto retry;
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
/* Silently fail here. We're allowed to do this since this CNID
* might have been deleted out from under us, or someone has
case DB_NOTFOUND:
/* Silently fail here. We're allowed to do this since this CNID
* might have been deleted out from under us, or someone has
key.size = CNID_DEVINO_LEN;
if ((rc = db->db_devino->del(db->db_devino, tid, &key, 0))) {
switch (rc) {
key.size = CNID_DEVINO_LEN;
if ((rc = db->db_devino->del(db->db_devino, tid, &key, 0))) {
switch (rc) {
case DB_LOCK_DEADLOCK:
txn_abort(tid);
goto retry;
case DB_LOCK_DEADLOCK:
txn_abort(tid);
goto retry;
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
break;
default:
case DB_NOTFOUND:
break;
default:
+#endif /* CNID_DB_CDB */
key.size = data.size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->del(db->db_didname, tid, &key, 0))) {
switch (rc) {
key.size = data.size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->del(db->db_didname, tid, &key, 0))) {
switch (rc) {
case DB_LOCK_DEADLOCK:
txn_abort(tid);
goto retry;
case DB_LOCK_DEADLOCK:
txn_abort(tid);
goto retry;
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
break;
default:
case DB_NOTFOUND:
break;
default:
+#endif /* CNID_DB_CDB */
key.data = (cnid_t *) &id;
key.size = sizeof(id);
if ((rc = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
key.data = (cnid_t *) &id;
key.size = sizeof(id);
if ((rc = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
+#endif /* CNID_DB_CDB */
case DB_LOCK_DEADLOCK:
goto retry;
case DB_LOCK_DEADLOCK:
goto retry;
+#endif /* CNID_DB_CDB */
default:
goto update_err;
}
default:
goto update_err;
}
altdata.data = (cnid_t *) &id;
altdata.size = sizeof(id);
if ((rc = db->db_devino->put(db->db_devino, tid, &key, &altdata, 0))) {
altdata.data = (cnid_t *) &id;
altdata.size = sizeof(id);
if ((rc = db->db_devino->put(db->db_devino, tid, &key, &altdata, 0))) {
+#endif /* CNID_DB_CDB */
case DB_LOCK_DEADLOCK:
goto retry;
case DB_LOCK_DEADLOCK:
goto retry;
+#endif /* CNID_DB_CDB */
default:
goto update_err;
}
default:
goto update_err;
}
key.data = (char *) data.data + CNID_DEVINO_LEN;
key.size = data.size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->put(db->db_didname, tid, &key, &altdata, 0))) {
key.data = (char *) data.data + CNID_DEVINO_LEN;
key.size = data.size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->put(db->db_didname, tid, &key, &altdata, 0))) {
+#endif /* CNID_DB_CDB */
case DB_LOCK_DEADLOCK:
goto retry;
case DB_LOCK_DEADLOCK:
goto retry;
+#endif /* CNID_DB_CDB */
default:
goto update_err;
}
}
default:
goto update_err;
}
}
+#ifdef CNID_DB_CDB
+ return 0;
+#else /* CNID_DB_CDB */
return txn_commit(tid, 0);
return txn_commit(tid, 0);
+#endif /* CNID_DB_CDB */
update_err:
LOG(log_error, logtype_default, "cnid_update: Unable to update CNID %u: %s",
update_err:
LOG(log_error, logtype_default, "cnid_update: Unable to update CNID %u: %s",