]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/dbif.c
Set cachesize for rebuild db
[netatalk.git] / etc / cnid_dbd / dbif.c
index b4e2b87fe0d9a78581202566fdc4fa9d1d8e9e3e..d7f19bd9a933f6512c2040d1cd55e84087f732e5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbif.c,v 1.14 2009-09-14 03:12:11 didg Exp $
+ * $Id: dbif.c,v 1.19 2009-12-21 06:41:09 franklahm Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * Copyright (C) Frank Lahm 2009
@@ -32,7 +32,7 @@
 static char *old_dbfiles[] = {"cnid.db", NULL};
 
 /* --------------- */
-static int upgrade_required()
+static int upgrade_required(void)
 {
     int i;
     int found = 0;
@@ -247,10 +247,29 @@ int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags)
             return -1;
         }
         if (logfiles != NULL) {
+            /* Remember cwd */
+            if ((cwd = open(".", O_RDONLY)) < 0) {
+                LOG(log_error, logtype_cnid, "error opening cwd: %s", strerror(errno));
+                goto logfiles_done;
+            }
+            /* chdir to db_envhome */
+            if ((chdir(dbd->db_envhome)) != 0) {
+                LOG(log_error, logtype_cnid, "error chdiring to db_env '%s': %s", dbd->db_envhome, strerror(errno));        
+                goto logfiles_done;
+            }
+
             for (file = logfiles; *file != NULL; file++) {
                 if (unlink(*file) < 0)
                     LOG(log_warning, logtype_cnid, "Error removing stale logfile %s: %s", *file, strerror(errno));
             }
+
+            /* chdir back */
+            if ((fchdir(cwd)) != 0) {
+                LOG(log_error, logtype_cnid, "error chdiring back: %s", strerror(errno));        
+                return -1;
+            }
+
+        logfiles_done:
             free(logfiles);
         }
 
@@ -277,7 +296,7 @@ int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags)
 }
 
 /* --------------- */
-int dbif_open(DBD *dbd, struct db_param *dbp _U_, int reindex)
+int dbif_open(DBD *dbd, struct db_param *dbp, int reindex)
 {
     int ret, i, cwd;
     u_int32_t count;
@@ -299,7 +318,7 @@ int dbif_open(DBD *dbd, struct db_param *dbp _U_, int reindex)
         }
         
         if ((stat(dbd->db_filename, &st)) == 0) {
-            LOG(log_debug, logtype_cnid, "See if we can upgrade the CNID database");
+            LOG(log_debug, logtype_cnid, "See if we can upgrade the CNID database...");
             if ((ret = db_create(&upgrade_db, dbd->db_env, 0))) {
                 LOG(log_error, logtype_cnid, "error creating handle for database: %s", db_strerror(ret));
                 return -1;
@@ -316,6 +335,7 @@ int dbif_open(DBD *dbd, struct db_param *dbp _U_, int reindex)
                 LOG(log_error, logtype_cnid, "error forcing checkpoint: %s", db_strerror(ret));
                 return -1;
             }
+            LOG(log_debug, logtype_cnid, "Finished CNID database upgrade check");
         }
         
         if ((fchdir(cwd)) != 0) {
@@ -341,6 +361,18 @@ int dbif_open(DBD *dbd, struct db_param *dbp _U_, int reindex)
             }
         }
 
+        if ( ! dbd->db_env) {   /* In memory db */
+            if ((ret = dbd->db_table[i].db->set_cachesize(dbd->db_table[i].db,
+                                                          0,
+                                                          dbp->cachesize,
+                                                          4)) /* split in 4 memory chunks */
+                < 0)  {
+                LOG(log_error, logtype_cnid, "error setting cachesize %u KB for database %s: %s",
+                    dbp->cachesize / 1024, dbd->db_table[i].name, db_strerror(ret));
+                return -1;
+            }
+        }
+
         if (dbd->db_table[i].db->open(dbd->db_table[i].db,
                                       dbd->db_txn,
                                       dbd->db_filename,
@@ -399,7 +431,7 @@ int dbif_open(DBD *dbd, struct db_param *dbp _U_, int reindex)
 }
 
 /* ------------------------ */
-int dbif_closedb(DBD *dbd)
+static int dbif_closedb(DBD *dbd)
 {
     int i;
     int ret;