/*
- * $Id: db_param.c,v 1.3 2009-02-04 20:28:01 didg Exp $
+ * $Id: db_param.c,v 1.9 2009-11-23 19:04:14 franklahm Exp $
*
* Copyright (C) Joerg Lenneis 2003
+ * Copyright (c) Frank Lahm 2009
* All Rights Reserved. See COPYING.
*/
#include "config.h"
#endif /* HAVE_CONFIG_H */
-#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
+#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/param.h>
#include <sys/un.h>
-
-
+#include <sys/select.h>
#include <atalk/logger.h>
#include "db_param.h"
-
#define DB_PARAM_FN "db_param"
#define MAXKEYLEN 64
-#define DEFAULT_LOGFILE_AUTOREMOVE 0
-#define DEFAULT_CACHESIZE 1024 * 4
-#define DEFAULT_NOSYNC 0
-#define DEFAULT_FLUSH_FREQUENCY 100
-#define DEFAULT_FLUSH_INTERVAL 30
+#define DEFAULT_LOGFILE_AUTOREMOVE 1
+#define DEFAULT_CACHESIZE (8 * 1024) /* KB, so 8 MB */
+#define DEFAULT_MAXLOCKS 5000
+#define DEFAULT_MAXLOCKOBJS 5000
+#define DEFAULT_FLUSH_FREQUENCY 1000
+#define DEFAULT_FLUSH_INTERVAL 1800
#define DEFAULT_USOCK_FILE "usock"
-#define DEFAULT_FD_TABLE_SIZE 64
-#define DEFAULT_IDLE_TIMEOUT 600
-#define DEFAULT_CHECK 0
+#define DEFAULT_FD_TABLE_SIZE 512
+#define DEFAULT_IDLE_TIMEOUT (10 * 60)
static struct db_param params;
static int parse_err;
-static size_t usock_maxlen()
+static size_t usock_maxlen(void)
{
struct sockaddr_un addr;
-
return sizeof(addr.sun_path) - 1;
}
static void default_params(struct db_param *dbp, char *dir)
{
- dbp->check = DEFAULT_CHECK;
dbp->logfile_autoremove = DEFAULT_LOGFILE_AUTOREMOVE;
dbp->cachesize = DEFAULT_CACHESIZE;
- dbp->nosync = DEFAULT_NOSYNC;
+ dbp->maxlocks = DEFAULT_MAXLOCKS;
+ dbp->maxlockobjs = DEFAULT_MAXLOCKOBJS;
dbp->flush_frequency = DEFAULT_FLUSH_FREQUENCY;
dbp->flush_interval = DEFAULT_FLUSH_INTERVAL;
if (make_pathname(dbp->usock_file, dir, DEFAULT_USOCK_FILE, usock_maxlen()) < 0) {
dbp->usock_file[0] = '\0';
}
dbp->fd_table_size = DEFAULT_FD_TABLE_SIZE;
+ if ( dbp->fd_table_size > FD_SETSIZE -1)
+ dbp->fd_table_size = FD_SETSIZE -1;
dbp->idle_timeout = DEFAULT_IDLE_TIMEOUT;
+
return;
}
int items;
default_params(¶ms, dir);
+ params.dir = dir;
if (make_pathname(pfn, dir, DB_PARAM_FN, MAXPATHLEN) < 0) {
LOG(log_error, logtype_cnid, "Parameter filename too long");
parse_err++;
break;
}
-
- if (! strcmp(key, "logfile_autoremove"))
- params.logfile_autoremove = parse_int(val);
- else if (! strcmp(key, "cachesize"))
- params.cachesize = parse_int(val);
- else if (! strcmp(key, "nosync"))
- params.nosync = parse_int(val);
- else if (! strcmp(key, "check"))
- params.check = parse_int(val);
- else if (! strcmp(key, "flush_frequency"))
- params.flush_frequency = parse_int(val);
- else if (! strcmp(key, "flush_interval"))
- params.flush_interval = parse_int(val);
- else if (! strcmp(key, "usock_file")) {
+
+ /* Config for both cnid_meta and dbd */
+ if (! strcmp(key, "usock_file")) {
if (make_pathname(params.usock_file, dir, val, usock_maxlen()) < 0) {
LOG(log_error, logtype_cnid, "usock filename %s too long", val);
parse_err++;
- }
- } else if (! strcmp(key, "fd_table_size"))
+ } else
+ LOG(log_info, logtype_cnid, "db_param: setting UNIX domain socket filename to %s", params.usock_file);
+ }
+
+ if (! strcmp(key, "fd_table_size")) {
params.fd_table_size = parse_int(val);
- else if (! strcmp(key, "idle_timeout"))
+ LOG(log_info, logtype_cnid, "db_param: setting max number of concurrent afpd connections per volume (fd_table_size) to %d", params.fd_table_size);
+ } else if (! strcmp(key, "logfile_autoremove")) {
+ params.logfile_autoremove = parse_int(val);
+ LOG(log_info, logtype_cnid, "db_param: setting logfile_autoremove to %d", params.logfile_autoremove);
+ } else if (! strcmp(key, "cachesize")) {
+ params.cachesize = parse_int(val);
+ LOG(log_info, logtype_cnid, "db_param: setting cachesize to %d", params.cachesize);
+ } else if (! strcmp(key, "maxlocks")) {
+ params.maxlocks = parse_int(val);
+ LOG(log_info, logtype_cnid, "db_param: setting maxlocks to %d", params.maxlocks);
+ } else if (! strcmp(key, "maxlockobjs")) {
+ params.maxlockobjs = parse_int(val);
+ LOG(log_info, logtype_cnid, "db_param: setting maxlockobjs to %d", params.maxlockobjs);
+ } else if (! strcmp(key, "flush_frequency")) {
+ params.flush_frequency = parse_int(val);
+ LOG(log_info, logtype_cnid, "db_param: setting flush_frequency to %d", params.flush_frequency);
+ } else if (! strcmp(key, "flush_interval")) {
+ params.flush_interval = parse_int(val);
+ LOG(log_info, logtype_cnid, "db_param: setting flush_interval to %d", params.flush_interval);
+ } else if (! strcmp(key, "idle_timeout")) {
params.idle_timeout = parse_int(val);
- else {
- LOG(log_error, logtype_cnid, "error parsing %s -> %s in config file", key, val);
- parse_err++;
+ LOG(log_info, logtype_cnid, "db_param: setting idle timeout to %d", params.idle_timeout);
}
- if(parse_err)
+
+ if (parse_err)
break;
}
}
fclose(fp);
- if (! parse_err)
+ if (! parse_err) {
+ /* sanity checks */
+ if (params.flush_frequency <= 0)
+ params.flush_frequency = 86400;
+
+ if (params.flush_interval <= 0)
+ params.flush_interval = 1000000;
+
+ if (params.fd_table_size <= 2)
+ params.fd_table_size = 32;
+
+ if (params.idle_timeout <= 0)
+ params.idle_timeout = 86400;
+
return ¶ms;
+ }
else
return NULL;
}