]> arthur.barton.de Git - netatalk.git/commitdiff
Fix a bunch of problems with database contention and corruption. Note:
authorjmarcus <jmarcus>
Fri, 21 Sep 2001 15:08:32 +0000 (15:08 +0000)
committerjmarcus <jmarcus>
Fri, 21 Sep 2001 15:08:32 +0000 (15:08 +0000)
the database no longer starts with the DB_RECOVER flag.  This caused
problems with multiple afpd processes accessing the same database.

libatalk/cnid/cnid_add.c
libatalk/cnid/cnid_get.c
libatalk/cnid/cnid_lookup.c
libatalk/cnid/cnid_open.c
libatalk/cnid/cnid_update.c

index 47534d5da6bcbf84bb945a385199c12e41985b35..b1a9bdaca10092ba71595f6a90019d3614f9a4c2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_add.c,v 1.9 2001-09-19 17:44:39 jmarcus Exp $
+ * $Id: cnid_add.c,v 1.10 2001-09-21 15:08:32 jmarcus Exp $
  *
  * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT.
@@ -160,7 +160,7 @@ cnid_t cnid_add(void *CNID, const struct stat *st,
   /* Abort and retry the modification. */
   if (0) {
 retry:    if ((rc = txn_abort(tid)) != 0)
-              syslog(LOG_ERR, "cnid_add: txn_begin failed (%d)", rc);
+              syslog(LOG_ERR, "cnid_add: txn_abort failed (%d)", rc);
           /* FALLTHROUGH */
   }
 
index e5f7e6e51a696ef48eb62b2148bf32e7b6ea662a..b81e32b76b28c74ae50f8922323327e93404515c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_get.c,v 1.4 2001-08-31 14:58:48 rufustfirefly Exp $
+ * $Id: cnid_get.c,v 1.5 2001-09-21 15:08:37 jmarcus Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -44,13 +44,13 @@ cnid_t cnid_get(void *CNID, const cnid_t did, const char *name,
   key.data = start;
   key.size = CNID_DID_LEN + len + 1;
 
-  while ((errno = db->db_didname->get(db->db_didname, NULL,
+  while ((rc = db->db_didname->get(db->db_didname, NULL,
                                      &key, &data, 0))) {
-    if (errno == EAGAIN) 
+    if (rc == EAGAIN) 
       continue;
 
-    if (errno != DB_NOTFOUND)
-      syslog(LOG_ERR, "cnid_get: can't get CNID(%u:%s)", did, name);
+    if (rc != DB_NOTFOUND)
+      syslog(LOG_ERR, "cnid_get: can't get CNID(%u:%s) (%d)", did, name, rc);
 
     return 0;
   }
index 61afe246f37c2edad61528d0f205cb10c0065ba1..707a0acbbf62453c6f42b597c148e1b390bce0f5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_lookup.c,v 1.6 2001-08-31 14:58:48 rufustfirefly Exp $
+ * $Id: cnid_lookup.c,v 1.7 2001-09-21 15:08:37 jmarcus Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -35,6 +35,7 @@ cnid_t cnid_lookup(void *CNID,
   DBT key, devdata, diddata;
   int devino = 1, didname = 1;
   cnid_t id = 0;
+  int rc = 0;
 
   int debug = 0;
 
@@ -45,9 +46,13 @@ cnid_t cnid_lookup(void *CNID,
    * cnid_lookup gets called when we do directory lookups. only do
    * this if we're using a read-write database. */
   if ((db->flags & CNIDFLAG_DB_RO) == 0) {
-    errno = txn_checkpoint(db->dbenv, LOGFILEMAX, CHECKTIMEMAX, 0);
-    while (errno == DB_INCOMPLETE)
-      errno = txn_checkpoint(db->dbenv, 0, 0, 0);
+    rc = txn_checkpoint(db->dbenv, LOGFILEMAX, CHECKTIMEMAX, 0);
+    while (rc == DB_INCOMPLETE)
+      rc = txn_checkpoint(db->dbenv, 0, 0, 0);
+       if (rc) {
+         syslog(LOG_ERR, "cnid_lookup: txn_checkpoint failed with: %d", rc);
+         return 0;
+       }
   }
 
  if ((buf = make_cnid_data(st, did, name, len)) == NULL) {
@@ -62,18 +67,18 @@ cnid_t cnid_lookup(void *CNID,
      only get a match on one of them, that means a file has moved. */
   key.data = buf; /* dev/ino is the first part of the buffer */
   key.size = CNID_DEVINO_LEN;
-  while ((errno = db->db_devino->get(db->db_devino, NULL,
+  while ((rc = db->db_devino->get(db->db_devino, NULL,
                                    &key, &devdata, 0))) {
-    if (errno == DB_LOCK_DEADLOCK)
+    if (rc == DB_LOCK_DEADLOCK)
       continue;
 
-    if (errno == DB_NOTFOUND) {
+    if (rc == DB_NOTFOUND) {
       devino = 0;
       break;
     }
 
-    syslog(LOG_ERR, "cnid_lookup: can't get CNID(%u/%u)",
-          st->st_dev, st->st_ino);
+    syslog(LOG_ERR, "cnid_lookup: can't get CNID(%u/%u) (%d)",
+          st->st_dev, st->st_ino, rc);
     return 0;
   }
 
@@ -81,18 +86,18 @@ cnid_t cnid_lookup(void *CNID,
   key.data = buf + CNID_DEVINO_LEN;
   key.size = CNID_DID_LEN + len + 1;
   memset(&diddata, 0, sizeof(diddata));
-  while ((errno = db->db_didname->get(db->db_didname, NULL,
+  while ((rc = db->db_didname->get(db->db_didname, NULL,
                                       &key, &diddata, 0))) {
-    if (errno == DB_LOCK_DEADLOCK)
+    if (rc == DB_LOCK_DEADLOCK)
       continue;
 
-    if (errno == DB_NOTFOUND) {
+    if (rc == DB_NOTFOUND) {
       didname = 0;
       break;
     }
 
-    syslog(LOG_ERR, "cnid_lookup: can't get CNID(%u:%s)",
-          did, name);
+    syslog(LOG_ERR, "cnid_lookup: can't get CNID(%u:%s) (%d)",
+          did, name, rc);
     return 0;
   }
 
index fa8ed2a8e6311f727cf7e99dc79790d8af35614e..adcee666f34491bf7248165b29ce67af7831eb53 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_open.c,v 1.9 2001-09-18 22:21:47 jmarcus Exp $
+ * $Id: cnid_open.c,v 1.10 2001-09-21 15:08:37 jmarcus Exp $
  *
  * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT.
 
 #if DB_VERSION_MINOR > 1
 #define DBOPTIONS    (DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | \
-DB_INIT_LOG | DB_INIT_TXN | DB_RECOVER)
+DB_INIT_LOG | DB_INIT_TXN)
 #else
 #define DBOPTIONS    (DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | \
-DB_INIT_LOG | DB_INIT_TXN | DB_TXN_NOSYNC | DB_RECOVER)
+DB_INIT_LOG | DB_INIT_TXN | DB_TXN_NOSYNC)
 #endif
 
 #define MAXITER     0xFFFF /* maximum number of simultaneously open CNID
@@ -236,10 +236,12 @@ mkdir_appledb:
     goto fail_lock;
   }
 
-  /* Check to see if a DBENV already exists.  If it does, join it. */
 #if DB_VERSION_MINOR > 1
-  if (db->dbenv->open(db->dbenv, path, DB_JOINENV, 0666)) {
+  db->dbenv->set_flags(db->dbenv, DB_TXN_NOSYNC, 1);
 #endif
+
+  /* Check to see if a DBENV already exists.  If it does, join it. */
+/*  if (db->dbenv->open(db->dbenv, path, DB_JOINENV, 0666)) {*/
   if (db->dbenv->open(db->dbenv, path, DBOPTIONS, 0666)) {
 
     /* try with a shared memory pool */
@@ -255,13 +257,8 @@ mkdir_appledb:
     open_flag = DB_RDONLY;
     syslog(LOG_INFO, "cnid_open: read-only CNID database");
   }
-#if DB_VERSION_MINOR > 1
-  }
-#endif
+  /*}*/
 
-#if DB_VERSION_MINOR > 1
-  db->dbenv->set_flags(db->dbenv, DB_TXN_NOSYNC, 1);
-#endif
 
   /* did/name reverse mapping. we use a btree for this one. */
   if (db_create(&db->db_didname, db->dbenv, 0))
index e7c320852bfa29717c787678446f5647220909d6..1c8c9a13de1c5f174e302b163ecc80e494474aae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_update.c,v 1.7 2001-09-20 06:07:12 jmarcus Exp $
+ * $Id: cnid_update.c,v 1.8 2001-09-21 15:08:37 jmarcus Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -44,6 +44,7 @@ int cnid_update(void *CNID, const cnid_t id, const struct stat *st,
   /* begin a transaction */
 retry:
   if ((rc = txn_begin(db->dbenv, NULL, &tid, 0))) {
+       syslog(LOG_ERR, "cnid_update: txn_begin failed with: %d", rc);
     return rc;
   }