diff --git a/client/src/client.c b/client/src/client.c index e674ad565..855a51ad6 100644 --- a/client/src/client.c +++ b/client/src/client.c @@ -15,9 +15,6 @@ static struct setting setting = { SETTING(OPTION_INIT) }; -#define PRINT_DEFAULT(_name, _type, _default, _description) \ - log_stdout(" %-31s ( default: %s )", #_name, _default); - static const unsigned int nopt = OPTION_CARDINALITY(struct setting); static void @@ -41,7 +38,7 @@ show_usage(void) "./pelikan_client ../template/client.conf" CRLF ); log_stdout("Setting & Default Values:"); - SETTING(PRINT_DEFAULT) + option_printall_default((struct option *)&setting, nopt); } static rstatus_t @@ -138,10 +135,10 @@ main(int argc, char *argv[]) exit(EX_DATAERR); } - option_printall((struct option *)&setting, nopt); - setup(); + option_printall((struct option *)&setting, nopt); + client_core_run(); return 0; diff --git a/deps/ccommon/include/buffer/cc_buf.h b/deps/ccommon/include/buffer/cc_buf.h index c18f4ff84..4e3bca9f4 100644 --- a/deps/ccommon/include/buffer/cc_buf.h +++ b/deps/ccommon/include/buffer/cc_buf.h @@ -35,9 +35,10 @@ extern "C" { #include #include -#define BUF_OPTION(ACTION) \ - ACTION( buf_init_size, OPTION_TYPE_UINT, str(BUF_DEFAULT_SIZE), "default size when buf is created" )\ - ACTION( buf_poolsize, OPTION_TYPE_UINT, str(BUF_POOLSIZE), "buf pool size" ) +/* name type default description */ +#define BUF_OPTION(ACTION) \ + ACTION( buf_init_size, OPTION_TYPE_UINT, BUF_DEFAULT_SIZE, "default size when buf is created" )\ + ACTION( buf_poolsize, OPTION_TYPE_UINT, BUF_POOLSIZE, "buf pool size" ) /* name type description */ #define BUF_METRIC(ACTION) \ diff --git a/deps/ccommon/include/buffer/cc_dbuf.h b/deps/ccommon/include/buffer/cc_dbuf.h index 526f51851..8db97d24f 100644 --- a/deps/ccommon/include/buffer/cc_dbuf.h +++ b/deps/ccommon/include/buffer/cc_dbuf.h @@ -27,8 +27,9 @@ extern "C" { #include +/* name type default description */ #define DBUF_OPTION(ACTION) \ - ACTION( dbuf_max_power, OPTION_TYPE_UINT, str(DBUF_DEFAULT_MAX), "max number of doubling" ) + ACTION( dbuf_max_power, OPTION_TYPE_UINT, DBUF_DEFAULT_MAX, "max number of doubling" ) #define DBUF_DEFAULT_MAX 6 /* with 16KiB default size, this gives us 1 MiB max */ diff --git a/deps/ccommon/include/cc_array.h b/deps/ccommon/include/cc_array.h index bab9546d3..2259d08ea 100644 --- a/deps/ccommon/include/cc_array.h +++ b/deps/ccommon/include/cc_array.h @@ -30,9 +30,9 @@ extern "C" { #define NELEM_DELTA 16 -/* name type default description */ -#define ARRAY_OPTION(ACTION) \ - ACTION( array_nelem_delta, OPTION_TYPE_UINT, str(NELEM_DELTA), "max nelem delta during expansion" ) +/* name type default description */ +#define ARRAY_OPTION(ACTION) \ + ACTION( array_nelem_delta, OPTION_TYPE_UINT, NELEM_DELTA, "max nelem delta during expansion" ) typedef int (*array_compare_t)(const void *, const void *); diff --git a/deps/ccommon/include/cc_debug.h b/deps/ccommon/include/cc_debug.h index 3fcd361cc..9c875f0be 100644 --- a/deps/ccommon/include/cc_debug.h +++ b/deps/ccommon/include/cc_debug.h @@ -31,12 +31,12 @@ extern "C" { #define DEBUG_LOG_NBUF 4 * MiB /* default log buf size */ #define DEBUG_LOG_INTVL 100000 /* flush every 100 milliseconds */ -/* name type default description */ -#define DEBUG_OPTION(ACTION) \ - ACTION( debug_log_level, OPTION_TYPE_UINT, str(DEBUG_LOG_LEVEL), "debug log level" )\ - ACTION( debug_log_file, OPTION_TYPE_STR, NULL, "debug log file" )\ - ACTION( debug_log_nbuf, OPTION_TYPE_UINT, str(DEBUG_LOG_NBUF), "debug log buf size" )\ - ACTION( debug_log_intvl, OPTION_TYPE_UINT, str(DEBUG_LOG_INTVL), "debug log flush interval") +/* name type default description */ +#define DEBUG_OPTION(ACTION) \ + ACTION( debug_log_level, OPTION_TYPE_UINT, DEBUG_LOG_LEVEL, "debug log level" )\ + ACTION( debug_log_file, OPTION_TYPE_STR, NULL, "debug log file" )\ + ACTION( debug_log_nbuf, OPTION_TYPE_UINT, DEBUG_LOG_NBUF, "debug log buf size" )\ + ACTION( debug_log_intvl, OPTION_TYPE_UINT, DEBUG_LOG_INTVL, "debug log flush interval") /** * the debug module override the following signal handlers: diff --git a/deps/ccommon/include/cc_option.h b/deps/ccommon/include/cc_option.h index 22de94974..45f8f1637 100644 --- a/deps/ccommon/include/cc_option.h +++ b/deps/ccommon/include/cc_option.h @@ -44,6 +44,9 @@ extern "C" { /* TODO(yao): add an (optional) callback that can sanity-check input values */ +#define OPTION_TYPE_BOOL_VAR vbool +#define OPTION_TYPE_UINT_VAR vuint +#define OPTION_TYPE_STR_VAR vstr #define OPTION_DECLARE(_name, _type, _default, _description) \ struct option _name; @@ -51,7 +54,7 @@ extern "C" { /* Initialize option */ #define OPTION_INIT(_name, _type, _default, _description) \ ._name = {.name = #_name, .set = false, .type = _type, \ - .default_val_str = _default, .description = _description}, + .default_val._type ## _VAR = _default, .description = _description}, #define OPTION_CARDINALITY(_o) sizeof(_o)/sizeof(struct option) @@ -76,7 +79,7 @@ struct option { char *name; bool set; option_type_t type; - char *default_val_str; + option_val_u default_val; option_val_u val; char *description; }; @@ -85,6 +88,7 @@ rstatus_t option_set(struct option *opt, char *val_str); rstatus_t option_parse(char *line, char *name, char *val); void option_print(struct option *opt); void option_printall(struct option options[], unsigned int nopt); +void option_printall_default(struct option options[], unsigned int nopt); rstatus_t option_load_default(struct option options[], unsigned int nopt); rstatus_t option_load_file(FILE *fp, struct option options[], unsigned int nopt); void option_free(struct option options[], unsigned int nopt); diff --git a/deps/ccommon/include/cc_ring_array.h b/deps/ccommon/include/cc_ring_array.h index 6d7c4c7b2..dfb7a653e 100644 --- a/deps/ccommon/include/cc_ring_array.h +++ b/deps/ccommon/include/cc_ring_array.h @@ -33,9 +33,9 @@ #define RING_ARRAY_DEFAULT_CAP 1024 -/* name type default description */ -#define RING_ARRAY_OPTION(ACTION) \ - ACTION( ring_array_cap, OPTION_TYPE_UINT, str(RING_ARRAY_DEFAULT_CAP), "default ring array capacity" ) +/* name type default description */ +#define RING_ARRAY_OPTION(ACTION) \ + ACTION( ring_array_cap, OPTION_TYPE_UINT, RING_ARRAY_DEFAULT_CAP, "default ring array capacity" ) struct ring_array { size_t elem_size; /* element size */ diff --git a/deps/ccommon/include/channel/cc_pipe.h b/deps/ccommon/include/channel/cc_pipe.h index 4ffd802ae..0c2bd3444 100644 --- a/deps/ccommon/include/channel/cc_pipe.h +++ b/deps/ccommon/include/channel/cc_pipe.h @@ -63,8 +63,9 @@ typedef struct { *(_metrics) = (pipe_metrics_st) { PIPE_METRIC(METRIC_INIT) }; \ } while (0) +/* name type default description */ #define PIPE_OPTION(ACTION) \ - ACTION( pipe_poolsize, OPTION_TYPE_UINT, str(PIPE_POOLSIZE), "pipe conn pool size" ) + ACTION( pipe_poolsize, OPTION_TYPE_UINT, PIPE_POOLSIZE, "pipe conn pool size" ) struct pipe_conn { STAILQ_ENTRY(pipe_conn) next; /* for pool */ diff --git a/deps/ccommon/include/channel/cc_tcp.h b/deps/ccommon/include/channel/cc_tcp.h index 15f6f9deb..401ca2c45 100644 --- a/deps/ccommon/include/channel/cc_tcp.h +++ b/deps/ccommon/include/channel/cc_tcp.h @@ -74,10 +74,10 @@ typedef struct { *(_metrics) = (tcp_metrics_st) { TCP_METRIC(METRIC_INIT) }; \ } while(0) -/* name type default description */ -#define TCP_OPTION(ACTION) \ - ACTION( tcp_backlog, OPTION_TYPE_UINT, str(TCP_BACKLOG), "tcp conn backlog limit" )\ - ACTION( tcp_poolsize, OPTION_TYPE_UINT, str(TCP_POOLSIZE), "tcp conn pool size" ) +/* name type default description */ +#define TCP_OPTION(ACTION) \ + ACTION( tcp_backlog, OPTION_TYPE_UINT, TCP_BACKLOG, "tcp conn backlog limit" )\ + ACTION( tcp_poolsize, OPTION_TYPE_UINT, TCP_POOLSIZE, "tcp conn pool size" ) struct tcp_conn { STAILQ_ENTRY(tcp_conn) next; /* for conn pool */ diff --git a/deps/ccommon/include/stream/cc_sockio.h b/deps/ccommon/include/stream/cc_sockio.h index e87e4d8d2..1186f3a75 100644 --- a/deps/ccommon/include/stream/cc_sockio.h +++ b/deps/ccommon/include/stream/cc_sockio.h @@ -54,9 +54,9 @@ extern "C" { #define BUFSOCK_POOLSIZE 0 /* unlimited */ -/* name type default description */ -#define SOCKIO_OPTION(ACTION) \ - ACTION( buf_sock_poolsize, OPTION_TYPE_UINT, str(BUFSOCK_POOLSIZE), "buf_sock limit" ) +/* name type default description */ +#define SOCKIO_OPTION(ACTION) \ + ACTION( buf_sock_poolsize, OPTION_TYPE_UINT, BUFSOCK_POOLSIZE, "buf_sock limit" ) struct buf_sock { /* these fields are useful for resource managmenet */ diff --git a/deps/ccommon/src/cc_option.c b/deps/ccommon/src/cc_option.c index cf8f35d9b..95283a744 100644 --- a/deps/ccommon/src/cc_option.c +++ b/deps/ccommon/src/cc_option.c @@ -446,25 +446,22 @@ option_parse(char *line, char name[OPTNAME_MAXLEN+1], char val[OPTVAL_MAXLEN+1]) return CC_OK; } -void option_print(struct option *opt) +static void +option_print_val(char *s, size_t len, option_type_t type, option_val_u val) { - loga("name: %s, type: %s, set? %s, default: %s, description: %s", - opt->name, option_type_str[opt->type], opt->set ? "yes" : "no", - opt->default_val_str, opt->description); - - switch (opt->type) { + switch (type) { case OPTION_TYPE_BOOL: - loga("current value: %d", opt->val.vbool); + snprintf(s, len, "%s", val.vbool ? "yes" : "no"); break; case OPTION_TYPE_UINT: - loga("current value: %ju", opt->val.vuint); + snprintf(s, len, "%ju", val.vuint); break; case OPTION_TYPE_STR: - loga("current value: %s", opt->val.vstr == NULL ? "NULL" : opt->val.vstr); + snprintf(s, len, "%s", val.vstr == NULL ? "NULL" : val.vstr); break; @@ -473,7 +470,22 @@ void option_print(struct option *opt) } } -void option_printall(struct option options[], unsigned int nopt) +void +option_print(struct option *opt) +{ +#define MAX_LEN 40 + char default_s[MAX_LEN]; + char current_s[MAX_LEN]; + option_print_val(default_s, MAX_LEN, opt->type, opt->default_val); + option_print_val(current_s, MAX_LEN, opt->type, opt->val); + loga("name: %s, type: %s, set? %s, default: %s, description: %s, current: %s", + opt->name, option_type_str[opt->type], opt->set ? "yes" : "no", + default_s, opt->description, current_s); +#undef MAX_LEN +} + +void +option_printall(struct option options[], unsigned int nopt) { unsigned int i; struct option *opt = options; @@ -484,21 +496,35 @@ void option_printall(struct option options[], unsigned int nopt) } +static void +_option_print_default(struct option *opt) +{ +#define MAX_LEN (10 + PATH_MAX) + char default_s[MAX_LEN]; + option_print_val(default_s, MAX_LEN, opt->type, opt->default_val); + log_stdout(" %-31s ( default: %s )", opt->name, default_s); +#undef MAX_LEN +} + +void +option_printall_default(struct option options[], unsigned int nopt) +{ + unsigned int i; + struct option *opt = options; + + for (i = 0; i < nopt; i++, opt++) { + _option_print_default(opt); + } +} + rstatus_t option_load_default(struct option options[], unsigned int nopt) { unsigned int i; - rstatus_t status; struct option *opt = options; for (i = 0; i < nopt; i++, opt++) { - status = option_set(opt, opt->default_val_str); - if (status != CC_OK) { - loga("error loading default value %s into option type %d", - opt->default_val_str, opt->type); - - return CC_ERROR; - } + opt->val = opt->default_val; } return CC_OK; diff --git a/src/pingserver/main.c b/src/pingserver/main.c index 22151abbe..2e7c3cd4e 100644 --- a/src/pingserver/main.c +++ b/src/pingserver/main.c @@ -16,9 +16,6 @@ static struct setting setting = { SETTING(OPTION_INIT) }; -#define PRINT_DEFAULT(_name, _type, _default, _description) \ - log_stdout(" %-31s ( default: %s )", #_name, _default); - static const unsigned int nopt = OPTION_CARDINALITY(struct setting); static void @@ -42,7 +39,7 @@ show_usage(void) " ./pelikan_pingserver" CRLF ); log_stdout("Setting & Default Values:"); - SETTING(PRINT_DEFAULT) + option_printall_default((struct option *)&setting, nopt); } static void @@ -164,9 +161,9 @@ main(int argc, char **argv) exit(EX_DATAERR); } - option_printall((struct option *)&setting, nopt); - setup(); + option_printall((struct option *)&setting, nopt); + exit(EX_OK); } diff --git a/src/pingserver/setting.h b/src/pingserver/setting.h index 990b19e59..aa33124aa 100644 --- a/src/pingserver/setting.h +++ b/src/pingserver/setting.h @@ -6,7 +6,7 @@ /* option related */ /* name type default description */ #define SERVER_OPTION(ACTION) \ - ACTION( daemonize, OPTION_TYPE_BOOL, "no", "daemonize the process" )\ + ACTION( daemonize, OPTION_TYPE_BOOL, false, "daemonize the process" )\ ACTION( pid_filename, OPTION_TYPE_STR, NULL, "file storing the pid" )\ ACTION( server_host, OPTION_TYPE_STR, NULL, "interfaces listening on" )\ ACTION( server_port, OPTION_TYPE_STR, "54321", "port listening on" ) diff --git a/src/protocol/memcache/klog.h b/src/protocol/memcache/klog.h index 7899331b7..01e3d64dd 100644 --- a/src/protocol/memcache/klog.h +++ b/src/protocol/memcache/klog.h @@ -9,12 +9,12 @@ #define KLOG_INTVL 100000 /* flush every 100 milliseconds */ #define KLOG_SAMPLE 100 /* log one in every 100 commands */ -/* name type default description */ -#define KLOG_OPTION(ACTION) \ - ACTION( klog_file, OPTION_TYPE_STR, NULL, "command log file" )\ - ACTION( klog_nbuf, OPTION_TYPE_UINT, str(KLOG_NBUF), "command log buf size" )\ - ACTION( klog_intvl, OPTION_TYPE_UINT, str(KLOG_INTVL), "command log flush interval" )\ - ACTION( klog_sample, OPTION_TYPE_UINT, str(KLOG_SAMPLE), "command log sample ratio" ) +/* name type default description */ +#define KLOG_OPTION(ACTION) \ + ACTION( klog_file, OPTION_TYPE_STR, NULL, "command log file" )\ + ACTION( klog_nbuf, OPTION_TYPE_UINT, KLOG_NBUF, "command log buf size" )\ + ACTION( klog_intvl, OPTION_TYPE_UINT, KLOG_INTVL, "command log flush interval" )\ + ACTION( klog_sample, OPTION_TYPE_UINT, KLOG_SAMPLE, "command log sample ratio" ) /* name type description */ #define KLOG_METRIC(ACTION) \ diff --git a/src/protocol/memcache/request.h b/src/protocol/memcache/request.h index 9486c74db..3486e5a63 100644 --- a/src/protocol/memcache/request.h +++ b/src/protocol/memcache/request.h @@ -14,8 +14,8 @@ #define REQ_POOLSIZE 0 /* name type default description */ -#define REQUEST_OPTION(ACTION) \ - ACTION( request_poolsize, OPTION_TYPE_UINT, str(REQ_POOLSIZE), "request pool size") +#define REQUEST_OPTION(ACTION) \ + ACTION( request_poolsize, OPTION_TYPE_UINT, REQ_POOLSIZE, "request pool size") /* name type description */ #define REQUEST_METRIC(ACTION) \ diff --git a/src/protocol/memcache/response.h b/src/protocol/memcache/response.h index 851dbb624..b4eeede85 100644 --- a/src/protocol/memcache/response.h +++ b/src/protocol/memcache/response.h @@ -8,9 +8,9 @@ #define RSP_POOLSIZE 0 -/* name type default description */ -#define RESPONSE_OPTION(ACTION) \ - ACTION( response_poolsize, OPTION_TYPE_UINT, str(RSP_POOLSIZE), "response pool size" ) +/* name type default description */ +#define RESPONSE_OPTION(ACTION) \ + ACTION( response_poolsize, OPTION_TYPE_UINT, RSP_POOLSIZE, "response pool size" ) /* name type description */ #define RESPONSE_METRIC(ACTION) \ diff --git a/src/protocol/ping/request.h b/src/protocol/ping/request.h index 209b3593a..53c02f8f4 100644 --- a/src/protocol/ping/request.h +++ b/src/protocol/ping/request.h @@ -3,9 +3,9 @@ #include #include -/* name type default description */ -#define REQUEST_OPTION(ACTION) \ - ACTION( request_poolsize, OPTION_TYPE_UINT, str(REQ_POOLSIZE), "request pool size") +/* name type default description */ +#define REQUEST_OPTION(ACTION) \ + ACTION( request_poolsize, OPTION_TYPE_UINT, REQ_POOLSIZE, "request pool size") /* name type description */ #define REQUEST_METRIC(ACTION) \ diff --git a/src/protocol/ping/response.h b/src/protocol/ping/response.h index 7bfda392b..2a4ab7450 100644 --- a/src/protocol/ping/response.h +++ b/src/protocol/ping/response.h @@ -3,9 +3,9 @@ #include #include -/* name type default description */ -#define RESPONSE_OPTION(ACTION) \ - ACTION( response_poolsize, OPTION_TYPE_UINT, str(RSP_POOLSIZE), "response pool size" ) +/* name type default description */ +#define RESPONSE_OPTION(ACTION) \ + ACTION( response_poolsize, OPTION_TYPE_UINT, RSP_POOLSIZE, "response pool size" ) /* name type description */ #define RESPONSE_METRIC(ACTION) \ diff --git a/src/redis/main.c b/src/redis/main.c index 9fd71f6ee..65b88bd9e 100644 --- a/src/redis/main.c +++ b/src/redis/main.c @@ -16,9 +16,6 @@ static struct setting setting = { SETTING(OPTION_INIT) }; -#define PRINT_DEFAULT(_name, _type, _default, _description) \ - log_stdout(" %-31s ( default: %s )", #_name, _default); - static const unsigned int nopt = OPTION_CARDINALITY(struct setting); static void @@ -44,7 +41,7 @@ show_usage(void) " ./pelikan_redis" CRLF ); log_stdout("Setting & Default Values:"); - SETTING(PRINT_DEFAULT) + option_printall_default((struct option *)&setting, nopt); } static void @@ -152,9 +149,9 @@ main(int argc, char **argv) exit(EX_DATAERR); } - option_printall((struct option *)&setting, nopt); - setup(); + option_printall((struct option *)&setting, nopt); + exit(EX_OK); } diff --git a/src/redis/setting.h b/src/redis/setting.h index 31a149a5d..b83820186 100644 --- a/src/redis/setting.h +++ b/src/redis/setting.h @@ -6,7 +6,7 @@ /* option related */ /* name type default description */ #define SERVER_OPTION(ACTION) \ - ACTION( daemonize, OPTION_TYPE_BOOL, "no", "daemonize the process" )\ + ACTION( daemonize, OPTION_TYPE_BOOL, false, "daemonize the process" )\ ACTION( pid_filename, OPTION_TYPE_STR, NULL, "file storing the pid" )\ ACTION( server_host, OPTION_TYPE_STR, NULL, "interfaces listening on" )\ ACTION( server_port, OPTION_TYPE_STR, "63790", "port listening on" ) diff --git a/src/slimcache/main.c b/src/slimcache/main.c index 1b0b038d5..63b304888 100644 --- a/src/slimcache/main.c +++ b/src/slimcache/main.c @@ -21,9 +21,6 @@ static struct setting setting = { SETTING(OPTION_INIT) }; -#define PRINT_DEFAULT(_name, _type, _default, _description) \ - log_stdout(" %-31s ( default: %s )", #_name, _default); - static const unsigned int nopt = OPTION_CARDINALITY(struct setting); static void @@ -53,8 +50,7 @@ show_usage(void) "Example:" CRLF " ./pelikan_slimcache ../template/slimcache.config" CRLF ); - log_stdout("Setting & Default Values:"); - SETTING(PRINT_DEFAULT) + option_printall_default((struct option *)&setting, nopt); } static void @@ -243,10 +239,10 @@ main(int argc, char **argv) exit(EX_DATAERR); } - option_printall((struct option *)&setting, nopt); - setup(); + option_printall((struct option *)&setting, nopt); + core_run(); exit(EX_OK); diff --git a/src/slimcache/setting.h b/src/slimcache/setting.h index b4ec44651..01a10531b 100644 --- a/src/slimcache/setting.h +++ b/src/slimcache/setting.h @@ -18,7 +18,7 @@ /* option related */ /* name type default description */ #define SERVER_OPTION(ACTION) \ - ACTION( daemonize, OPTION_TYPE_BOOL, "no", "daemonize the process" )\ + ACTION( daemonize, OPTION_TYPE_BOOL, false, "daemonize the process" )\ ACTION( pid_filename, OPTION_TYPE_STR, NULL, "file storing the pid" )\ ACTION( server_host, OPTION_TYPE_STR, NULL, "interfaces listening on" )\ ACTION( server_port, OPTION_TYPE_STR, "22222", "port listening on" ) diff --git a/src/storage/cuckoo/cuckoo.h b/src/storage/cuckoo/cuckoo.h index 93b4a8ba5..0c1d3e859 100644 --- a/src/storage/cuckoo/cuckoo.h +++ b/src/storage/cuckoo/cuckoo.h @@ -16,13 +16,13 @@ #define CUCKOO_NITEM 1024 #define CUCKOO_POLICY CUCKOO_POLICY_RANDOM -/* name type default description */ -#define CUCKOO_OPTION(ACTION) \ - ACTION( cuckoo_displace, OPTION_TYPE_UINT, str(CUCKOO_DISPLACE), "# displaces allowed" )\ - ACTION( cuckoo_item_cas, OPTION_TYPE_BOOL, "yes", "support cas in items" )\ - ACTION( cuckoo_item_size, OPTION_TYPE_UINT, str(CUCKOO_ITEM_SIZE), "item size (inclusive)" )\ - ACTION( cuckoo_nitem, OPTION_TYPE_UINT, str(CUCKOO_NITEM), "# items allocated" )\ - ACTION( cuckoo_policy, OPTION_TYPE_UINT, str(CUCKOO_POLICY), "evict policy" ) +/* name type default description */ +#define CUCKOO_OPTION(ACTION) \ + ACTION( cuckoo_displace, OPTION_TYPE_UINT, CUCKOO_DISPLACE, "# displaces allowed" )\ + ACTION( cuckoo_item_cas, OPTION_TYPE_BOOL, true, "support cas in items" )\ + ACTION( cuckoo_item_size, OPTION_TYPE_UINT, CUCKOO_ITEM_SIZE, "item size (inclusive)" )\ + ACTION( cuckoo_nitem, OPTION_TYPE_UINT, CUCKOO_NITEM, "# items allocated" )\ + ACTION( cuckoo_policy, OPTION_TYPE_UINT, CUCKOO_POLICY, "evict policy" ) /* name type description */ #define ITEM_METRIC(ACTION) \ diff --git a/src/storage/slab/item.h b/src/storage/slab/item.h index 55bb00ae7..2913a6772 100644 --- a/src/storage/slab/item.h +++ b/src/storage/slab/item.h @@ -12,10 +12,10 @@ #include #include -/* name type default description */ -#define ITEM_OPTION(ACTION) \ - ACTION( item_use_cas, OPTION_TYPE_BOOL, "yes", "CAS enabled for slabbed mm" )\ - ACTION( item_hash_power, OPTION_TYPE_UINT, str(HASH_POWER), "Hash power for item table" ) +/* name type default description */ +#define ITEM_OPTION(ACTION) \ + ACTION( item_use_cas, OPTION_TYPE_BOOL, true, "CAS enabled for slabbed mm" )\ + ACTION( item_hash_power, OPTION_TYPE_UINT, HASH_POWER, "Hash power for item table" ) /* name type description */ #define ITEM_METRIC(ACTION) \ diff --git a/src/storage/slab/slab.h b/src/storage/slab/slab.h index ed7ab130f..2dc8d86ab 100644 --- a/src/storage/slab/slab.h +++ b/src/storage/slab/slab.h @@ -31,17 +31,17 @@ /* The defaults here are placeholder values for now */ /* name type default description */ #define SLAB_OPTION(ACTION) \ - ACTION( slab_prealloc, OPTION_TYPE_BOOL, "yes", "Allocate slabs ahead of time" )\ - ACTION( slab_evict_opt, OPTION_TYPE_UINT, str(EVICT_NONE), "Eviction strategy" )\ - ACTION( slab_use_freeq, OPTION_TYPE_BOOL, "yes", "Use items in free queue?" )\ - ACTION( slab_size, OPTION_TYPE_UINT, str(MiB), "Slab size" )\ - ACTION( slab_min_chunk_size, OPTION_TYPE_UINT, str(SLAB_MIN_CHUNK), "Minimum chunk size" )\ - ACTION( slab_max_chunk_size, OPTION_TYPE_UINT, str(SLAB_MAX_CHUNK), "Maximum chunk size" )\ - ACTION( slab_maxbytes, OPTION_TYPE_UINT, str(GiB), "Maximum bytes allocated" )\ + ACTION( slab_prealloc, OPTION_TYPE_BOOL, true, "Allocate slabs ahead of time" )\ + ACTION( slab_evict_opt, OPTION_TYPE_UINT, EVICT_NONE, "Eviction strategy" )\ + ACTION( slab_use_freeq, OPTION_TYPE_BOOL, true, "Use items in free queue?" )\ + ACTION( slab_size, OPTION_TYPE_UINT, MiB, "Slab size" )\ + ACTION( slab_min_chunk_size, OPTION_TYPE_UINT, SLAB_MIN_CHUNK, "Minimum chunk size" )\ + ACTION( slab_max_chunk_size, OPTION_TYPE_UINT, SLAB_MAX_CHUNK, "Maximum chunk size" )\ + ACTION( slab_maxbytes, OPTION_TYPE_UINT, GiB, "Maximum bytes allocated" )\ ACTION( slab_profile, OPTION_TYPE_STR, NULL, "Slab profile" )\ ACTION( slab_profile_factor, OPTION_TYPE_STR, str(SLAB_FACTOR), "Slab class growth factor" )\ - ACTION( slab_use_cas, OPTION_TYPE_BOOL, "yes", "CAS enabled for slabbed mm" )\ - ACTION( slab_hash_power, OPTION_TYPE_UINT, str(SLAB_HASH), "Hash power for item table" ) + ACTION( slab_use_cas, OPTION_TYPE_BOOL, true, "CAS enabled for slabbed mm" )\ + ACTION( slab_hash_power, OPTION_TYPE_UINT, SLAB_HASH, "Hash power for item table" ) /* name type description */ #define SLAB_METRIC(ACTION) \ diff --git a/src/twemcache/main.c b/src/twemcache/main.c index d7a1c0223..21879bbbe 100644 --- a/src/twemcache/main.c +++ b/src/twemcache/main.c @@ -24,9 +24,6 @@ static struct setting setting = { SETTING(OPTION_INIT) }; -#define PRINT_DEFAULT(_name, _type, _default, _description) \ - log_stdout(" %-31s ( default: %s )", #_name, _default); - static const unsigned int nopt = OPTION_CARDINALITY(struct setting); static void @@ -53,7 +50,12 @@ show_usage(void) " ./pelikan_twemcache ../template/twemcache.conf" CRLF ); log_stdout("Setting & Default Values:"); - SETTING(PRINT_DEFAULT) + + if (option_load_default((struct option *)&setting, nopt) != CC_OK) { + log_stderr("failed to load default option values"); + exit(EX_CONFIG); + } + option_printall_default((struct option *)&setting, nopt); } static void @@ -244,10 +246,10 @@ main(int argc, char **argv) exit(EX_DATAERR); } - option_printall((struct option *)&setting, nopt); - setup(); + option_printall((struct option *)&setting, nopt); + core_run(); exit(EX_OK); diff --git a/src/twemcache/setting.h b/src/twemcache/setting.h index f6760a5c2..2158ba22a 100644 --- a/src/twemcache/setting.h +++ b/src/twemcache/setting.h @@ -15,7 +15,7 @@ /* option related */ /* name type default description */ #define SERVER_OPTION(ACTION) \ - ACTION( daemonize, OPTION_TYPE_BOOL, "no", "daemonize the process" )\ + ACTION( daemonize, OPTION_TYPE_BOOL, false, "daemonize the process" )\ ACTION( pid_filename, OPTION_TYPE_STR, NULL, "file storing the pid" )\ ACTION( server_host, OPTION_TYPE_STR, NULL, "interfaces listening on" )\ ACTION( server_port, OPTION_TYPE_STR, "12321", "port listening on" )