]> arthur.barton.de Git - netatalk.git/commitdiff
Fix some obvious problems in the new CNID code. However, things are still
authorjmarcus <jmarcus>
Mon, 21 Jan 2002 04:06:41 +0000 (04:06 +0000)
committerjmarcus <jmarcus>
Mon, 21 Jan 2002 04:06:41 +0000 (04:06 +0000)
broken, and need to be looked at.

libatalk/cnid/cnid_add.c
libatalk/cnid/cnid_update.c

index f0925dbc8ec9c1a1ac27841d84455148a4ac8f38..1b361afea56e5d9a3dbdf67585ea9422b2592ca5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_add.c,v 1.24 2002-01-18 04:51:27 jmarcus Exp $
+ * $Id: cnid_add.c,v 1.25 2002-01-21 04:06:41 jmarcus Exp $
  *
  * Copyright (c) 1999. Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT.
@@ -44,9 +44,6 @@
 static int add_cnid(CNID_private *db, DBT *key, DBT *data) {
     DBT altkey, altdata;
     DB_TXN *tid;
-    /* We create rc here because using errno is bad.  Why?  Well, if you
-     * use errno once, then call another function which resets it, you're
-     * screwed. */
     int rc, ret;
 
     memset(&altkey, 0, sizeof(altkey));
@@ -130,8 +127,7 @@ cnid_t cnid_add(void *CNID, const struct stat *st,
     /* ... Return id if it is valid, or if Rootinfo is read-only. */
     if (id || (db->flags & CNIDFLAG_DB_RO)) {
 #ifdef DEBUG
-        LOG(log_info, logtype_default, "cnid_add: Looked up did %u, name %s as %u",
-            ntohl(did), name, ntohl(id));
+        LOG(log_info, logtype_default, "cnid_add: Looked up did %u, name %s as %u", ntohl(did), name, ntohl(id));
 #endif
         return id;
     }
@@ -173,10 +169,6 @@ cnid_t cnid_add(void *CNID, const struct stat *st,
         }
     }
 
-    /* We need to create a random sleep interval to prevent deadlocks. */
-    /*(void)srand(getpid() ^ time(NULL));
-    t.tv_sec = 0;*/
-
     memset(&rootinfo_key, 0, sizeof(rootinfo_key));
     memset(&rootinfo_data, 0, sizeof(rootinfo_data));
     rootinfo_key.data = ROOTINFO_KEY;
@@ -199,6 +191,15 @@ retry:
         goto retry;
     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_MAX) {
+               txn_abort(tid);
+               LOG(log_error, logtype_default, "cnid_add: FATAL: Cannot add CNID for %s.  CNID database has reached its limit.", name);
+               return CNID_ERR_MAX;
+       }
+               hint = htonl(id);
 #ifdef DEBUG
         LOG(log_info, logtype_default, "cnid_add: Found rootinfo for did %u, name %s as %u", ntohl(did), name, ntohl(hint));
 #endif
@@ -206,8 +207,7 @@ retry:
     case DB_NOTFOUND:
         hint = htonl(CNID_START);
 #ifdef DEBUG
-        LOG(log_info, logtype_default, "cnid_add: Using CNID_START for did %u, name %s",
-            ntohl(did), name);
+        LOG(log_info, logtype_default, "cnid_add: Using CNID_START for did %u, name %s", ntohl(did), name);
 #endif
         break;
     default:
@@ -215,24 +215,6 @@ retry:
         goto cleanup_abort;
     }
 
-    id = ntohl(hint);
-    if (id <= CNID_START) {
-        id = CNID_START;
-    }
-    else {
-        id++;
-    }
-
-    /* If we've hit the MAX CNID allowed, we return a fatal error.  CNID needs
-     * to be recycled before proceding. */
-    if (id == CNID_MAX) {
-        txn_abort(tid);
-        LOG(log_error, logtype_default, "cnid_add: FATAL: Cannot add CNID for %s.  CNID database has reached its limit.", name);
-        return CNID_ERR_MAX;
-    }
-
-    hint = htonl(id);
-
     rootinfo_data.data = &hint;
     rootinfo_data.size = sizeof(hint);
 
@@ -244,18 +226,17 @@ retry:
         }
         goto retry;
     case 0:
-        break;
+       /* 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));
+               return CNID_ERR_DB;
+       }
+               break;
     default:
         LOG(log_error, logtype_default, "cnid_add: Unable to update rootinfo: %s", db_strerror(rc));
         goto cleanup_abort;
     }
 
-    /* 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));
-        return CNID_ERR_DB;
-    }
-
     /* Now we need to add the CNID data to the databases. */
     rc = add_cnid(db, &key, &data);
     if (rc) {
index 8a588fcd1866661a29c28c5604326402ed409904..a7a4cbca7559e1efd80d5e94e85a7424346844e5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_update.c,v 1.17 2002-01-19 21:42:08 jmarcus Exp $
+ * $Id: cnid_update.c,v 1.18 2002-01-21 04:06:41 jmarcus Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -42,8 +42,7 @@ int cnid_update(void *CNID, const cnid_t id, const struct stat *st,
 
 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));
+        LOG(log_error, logtype_default, "cnid_update: Failed to begin transaction: %s", db_strerror(rc));
         return rc;
     }