* 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.
#undef BSD4_4
#undef CNID_DB
#undef FILE_MANGLING
+#undef CNID_DB_CDB
#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)
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])
fi
+ , AC_MSG_RESULT([no])
)
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.
#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;
+#ifndef CNID_DB_CDB
DB_TXN *tid;
+#endif /* CNID_DB_CDB */
int rc, ret;
memset(&altkey, 0, sizeof(altkey));
memset(&altdata, 0, sizeof(altdata));
+#ifndef CNID_DB_CDB
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))) {
+#ifndef CNID_DB_CDB
if (rc == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
return ret;
}
goto retry;
}
+#endif /* CNID_DB_CDB */
goto abort;
}
altdata.data = key->data;
altdata.size = key->size;
if ((rc = db->db_devino->put(db->db_devino, tid, &altkey, &altdata, 0))) {
+#ifndef CNID_DB_CDB
if (rc == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
return ret;
}
goto retry;
}
+#endif /* CNID_DB_CDB */
goto abort;
}
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))) {
+#ifndef CNID_DB_CDB
if (rc == DB_LOCK_DEADLOCK) {
if ((ret = txn_abort(tid)) != 0) {
return ret;
}
goto retry;
}
+#endif /* CNID_DB_CDB */
goto abort;
}
+#ifndef 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;
}
+#endif /* CNID_DB_CDB */
return 0;
{
CNID_private *db;
DBT key, data, rootinfo_key, rootinfo_data;
+#ifndef CNID_DB_CDB
DB_TXN *tid;
+#endif /* CNID_DB_CDB */
struct timeval t;
cnid_t id, save;
int rc;
rootinfo_key.data = ROOTINFO_KEY;
rootinfo_key.size = ROOTINFO_KEYLEN;
+#ifndef CNID_DB_CDB
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 */
/* Get the key. */
+#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:
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) {
+#ifndef CNID_DB_CDB
txn_abort(tid);
+#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;
rootinfo_data.size = sizeof(hint);
switch (rc = db->db_didname->put(db->db_didname, tid, &rootinfo_key, &rootinfo_data, 0)) {
+#ifndef CNID_DB_CDB
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;
+#endif /* CNID_DB_CDB */
case 0:
+#ifndef 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;
}
+#endif /* CNID_DB_CDB */
break;
default:
LOG(log_error, logtype_default, "cnid_add: Unable to update rootinfo: %s", db_strerror(rc));
return hint;
cleanup_abort:
+#ifndef CNID_DB_CDB
txn_abort(tid);
+#endif /* CNID_DB_CDB */
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 $
*/
#ifdef HAVE_CONFIG_H
return;
}
+#ifndef CNID_DB_CDB
/* 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);
}
+#endif /* CNID_DB_CDB */
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);
+#ifndef CNID_DB_CDB
if (db->lockfd > -1) {
close(db->lockfd); /* This will also release any locks we have. */
}
+#endif /* CNID_DB_CDB */
free(db);
}
/*
- * $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.
#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;
+#ifndef CNID_DB_CDB
DB_TXN *tid;
+#endif /* CNID_DB_CDB */
int rc, found = 0;
if (!(db = CNID) || !id || (db->flags & CNIDFLAG_DB_RO)) {
case 0:
found = 1;
break;
+#ifndef CNID_DB_CDB
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",
}
}
+#ifndef CNID_DB_CDB
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))) {
+#ifndef CNID_DB_CDB
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:
+#endif /* CNID_DB_CDB */
goto abort_err;
+#ifndef CNID_DB_CDB
}
+#endif /* CNID_DB_CDB */
}
/* 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) {
+#ifndef CNID_DB_CDB
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
return rc;
}
goto retry;
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
/* Quietly fall through if the entry isn't found. */
break;
default:
+#ifndef CNID_DB_CDB
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 */
goto abort_err;
}
}
key.size = data.size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->del(db->db_didname, tid, &key, 0))) {
switch (rc) {
+#ifndef CNID_DB_CDB
case DB_LOCK_DEADLOCK:
if ((rc = txn_abort(tid)) != 0) {
LOG(log_error, logtype_default, "cnid_delete: txn_abort: %s",
return rc;
}
goto retry;
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
break;
default:
+#ifndef CNID_DB_CDB
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 */
goto abort_err;
}
}
#ifdef DEBUG
LOG(log_info, logtype_default, "cnid_delete: Deleting CNID %u", ntohl(id));
#endif
+#ifndef CNID_DB_CDB
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 */
return 0;
abort_err:
/*
- * $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 $
*/
#ifdef HAVE_CONFIG_H
key.size = CNID_DID_LEN + len + 1;
while ((rc = db->db_didname->get(db->db_didname, NULL, &key, &data, 0))) {
+#ifndef CNID_DB_CDB
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",
/*
- * $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 $
*/
#ifdef HAVE_CONFIG_H
return 0;
}
+#ifndef CNID_DB_CDB
/* 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. */
return 0;
}
}
+#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");
key.data = buf;
key.size = CNID_DEVINO_LEN;
while ((rc = db->db_devino->get(db->db_devino, NULL, &key, &devdata, 0))) {
+#ifndef CNID_DB_CDB
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
+#endif /* CNID_DB_CDB */
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))) {
+#ifndef CNID_DB_CDB
if (rc == DB_LOCK_DEADLOCK) {
continue;
}
+#endif /* CNID_DB_CDB */
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 $
*/
#ifdef HAVE_CONFIG_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;
+#ifndef CNID_DB_CDB
DB_TXN *tid;
+#endif /* CNID_DB_CDB */
cnid_t id;
int rc, ret;
data.data = filename;
data.size = strlen(filename) + 1;
+#ifndef CNID_DB_CDB
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 ((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;
+ }
}
+#ifndef CNID_DB_CDB
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 */
return 0;
}
/*
- * $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 $
*/
#ifdef HAVE_CONFIG_H
{
CNID_private *db;
DBT key, data;
- DB_TXN *tid;
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.
* 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 */
#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)
#define DBOPTIONS (DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | \
DB_INIT_LOG | DB_INIT_TXN)
#endif /* DB_VERSION_MINOR */
+#endif /* CNID_DB_CDB */
+#ifndef 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
#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. */
void *cnid_open(const char *dir) {
struct stat st, rsb, lsb, csb;
+#ifndef CNID_DB_CDB
struct flock lock;
+#endif /* CNID_DB_CDB */
char path[MAXPATHLEN + 1];
CNID_private *db;
DBT key, data;
len++;
}
- 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;
}
+#ifndef CNID_DB_CDB
+ lock.l_type = F_WRLCK;
+ lock.l_whence = SEEK_SET;
/* 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);
}
+#endif /* CNID_DB_CDB */
path[len + DBHOMELEN] = '\0';
open_flag = DB_CREATE;
goto fail_lock;
}
+#ifndef CNID_DB_CDB
/* 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 */
+#ifndef 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. */
}
#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) {
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",
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
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);
goto fail_appinit;
}
db->dbenv->close(db->dbenv, 0);
fail_lock:
+#ifndef CNID_DB_CDB
if (db->lockfd > -1) {
close(db->lockfd);
(void)remove(db->lock_file);
}
+#endif /* CNID_DB_CDB */
fail_adouble:
/*
- * $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 $
*/
#ifdef HAVE_CONFIG_H
key.data = id;
key.size = sizeof(cnid_t);
while ((rc = db->db_cnid->get(db->db_cnid, NULL, &key, &data, 0))) {
+#ifndef CNID_DB_CDB
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",
/*
- * $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 $
*/
#ifdef HAVE_CONFIG_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_private *db;
DBT key, data, altdata;
+#ifndef CNID_DB_CDB
DB_TXN *tid;
+#endif /* CNID_DB_CDB */
int rc;
if (!(db = CNID) || !id || !st || !name || (db->flags & CNIDFLAG_DB_RO)) {
memset(&key, 0, sizeof(key));
memset(&altdata, 0, sizeof(altdata));
+#ifndef CNID_DB_CDB
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));
+#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);
+#endif /* CNID_DB_CDB */
switch (rc) {
+#ifndef CNID_DB_CDB
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
key.size = CNID_DEVINO_LEN;
if ((rc = db->db_devino->del(db->db_devino, tid, &key, 0))) {
switch (rc) {
+#ifndef CNID_DB_CDB
case DB_LOCK_DEADLOCK:
txn_abort(tid);
goto retry;
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
break;
default:
+#ifndef CNID_DB_CDB
txn_abort(tid);
+#endif /* CNID_DB_CDB */
goto update_err;
}
}
key.size = data.size - CNID_DEVINO_LEN;
if ((rc = db->db_didname->del(db->db_didname, tid, &key, 0))) {
switch (rc) {
+#ifndef CNID_DB_CDB
case DB_LOCK_DEADLOCK:
txn_abort(tid);
goto retry;
+#endif /* CNID_DB_CDB */
case DB_NOTFOUND:
break;
default:
+#ifndef CNID_DB_CDB
txn_abort(tid);
+#endif /* CNID_DB_CDB */
goto update_err;
}
}
key.data = (cnid_t *) &id;
key.size = sizeof(id);
if ((rc = db->db_cnid->put(db->db_cnid, tid, &key, &data, 0))) {
+#ifndef CNID_DB_CDB
txn_abort(tid);
+#endif /* CNID_DB_CDB */
switch (rc) {
+#ifndef CNID_DB_CDB
case DB_LOCK_DEADLOCK:
goto retry;
+#endif /* CNID_DB_CDB */
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))) {
+#ifndef CNID_DB_CDB
txn_abort(tid);
+#endif /* CNID_DB_CDB */
switch (rc) {
+#ifndef CNID_DB_CDB
case DB_LOCK_DEADLOCK:
goto retry;
+#endif /* CNID_DB_CDB */
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))) {
+#ifndef CNID_DB_CDB
txn_abort(tid);
+#endif /* CNID_DB_CDB */
switch (rc) {
+#ifndef CNID_DB_CDB
case DB_LOCK_DEADLOCK:
goto retry;
+#endif /* CNID_DB_CDB */
default:
goto update_err;
}
}
+#ifdef CNID_DB_CDB
+ return 0;
+#else /* CNID_DB_CDB */
return txn_commit(tid, 0);
+#endif /* CNID_DB_CDB */
update_err:
LOG(log_error, logtype_default, "cnid_update: Unable to update CNID %u: %s",