From 90ac132f1028af850b10a702c5ef38ddbc85a13a Mon Sep 17 00:00:00 2001 From: Bo Zhang Date: Tue, 10 Sep 2024 19:04:15 -0600 Subject: [PATCH] add swap config --- src/dspaces-conf.c | 62 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/dspaces-conf.c b/src/dspaces-conf.c index 0fc68ac5..7b5b86ca 100644 --- a/src/dspaces-conf.c +++ b/src/dspaces-conf.c @@ -313,10 +313,63 @@ static void parse_modules_table(toml_table_t *modules, struct ds_conf *conf) #endif } +static void parse_swap_table(toml_table_t *swap, struct ds_conf *conf) +{ + toml_datum_t dat; + + dat = toml_string_in(swap, "directory"); + if(dat.ok) { + conf->swap.file_dir = strdup(dat.u.s); + free(dat.u.s); + } else{ + conf->swap.file_dir = strdup("./swap/"); + } + + dat = toml_string_in(swap, "memory quota"); + if(dat.ok) { + memory_quota_parser(dat.u.s, &conf->swap); + free(dat.u.s); + } else{ + conf->swap.mem_quota_type = 1; + conf->swap.mem_quota.percent = 1.0; + } + + dat = toml_string_in(swap, "policy"); + if(dat.ok) { + if(policy_str_check(dat.u.s)) { + conf->swap.policy = strdup(dat.u.s); + } else { + conf->swap.policy = strdup("Default"); + fprintf(stderr, "WARNING: Swap Policy: %s is not supported. " + "Use FIFO policy as default.\n", dat.u.s); + } + free(dat.u.s); + } else { + conf->swap.policy = strdup("Default"); + } + + dat = toml_string_in(swap, "disk quota"); + if(dat.ok) { + disk_quota_parser(dat.u.s, &conf->swap); + free(dat.u.s); + } else { + conf->swap.disk_quota_MB = -1.0; + } +} + +static inline void set_default_swap(struct ds_conf *conf) +{ + conf->swap.file_dir = strdup("./swap/"); + conf->swap.mem_quota_type = 1; + conf->swap.mem_quota.percent = 1.0; + conf->swap.policy = strdup("Default"); + conf->swap.disk_quota_MB = -1.0; +} + int parse_conf_toml(const char *fname, struct ds_conf *conf) { FILE *fin; - toml_table_t *toml_conf, *server, *remotes, *storage, *modules; + toml_table_t *toml_conf, *server, *remotes, *storage, *modules, *swap; char errbuf[200]; char *ip; int port; @@ -366,6 +419,13 @@ int parse_conf_toml(const char *fname, struct ds_conf *conf) parse_modules_table(modules, conf); } + swap = toml_table_in(toml_conf, "swap space"); + if(swap) { + parse_swap_table(swap, conf); + } else { + set_default_swap(conf); + } + toml_free(toml_conf); return (0);