diff --git a/cli/gluster-block.c b/cli/gluster-block.c index 65cbeb6..0a5187f 100644 --- a/cli/gluster-block.c +++ b/cli/gluster-block.c @@ -42,6 +42,8 @@ extern const char *argp_program_version; +struct timeval TIMEOUT; /* cli process to daemon cli thread timeout */ + typedef enum clioperations { CREATE_CLI = 1, LIST_CLI = 2, @@ -54,6 +56,41 @@ typedef enum clioperations { } clioperations; +gbConfig * +glusterBlockCLILoadConfig(void) +{ + gbConfig *cfg = NULL; + int ret; + + if (GB_ALLOC(cfg) < 0) { + LOG("cli", GB_LOG_ERROR, + "Alloc GB config failed for configPath: %s!\n", GB_DEF_CONFIGPATH); + return NULL; + } + + if (GB_STRDUP(cfg->configPath, GB_DEF_CONFIGPATH) < 0) { + LOG("cli", GB_LOG_ERROR, + "failed to copy configPath: %s\n", GB_DEF_CONFIGPATH); + goto freeConfig; + } + + if (glusterBlockLoadConfig(cfg, false)) { + LOG("cli", GB_LOG_ERROR, + "Loading GB config failed for configPath: %s!\n", GB_DEF_CONFIGPATH); + goto freeConfigPath; + } + + return cfg; + + freeConfigPath: + GB_FREE(cfg->configPath); + freeConfig: + GB_FREE(cfg); + + return NULL; +} + + static int glusterBlockCliRPC_1(void *cobj, clioperations opt) { @@ -71,6 +108,7 @@ glusterBlockCliRPC_1(void *cobj, clioperations opt) blockGenConfigCli *genconfig_obj; blockResponse reply = {0,}; char errMsg[2048] = {0}; + gbConfig *conf = NULL; if (strlen(GB_UNIX_ADDRESS) > SUN_PATH_MAX) { @@ -110,6 +148,20 @@ glusterBlockCliRPC_1(void *cobj, clioperations opt) goto out; } + conf = glusterBlockCLILoadConfig(); + if (!conf) { + LOG("cli", GB_LOG_ERROR, + "glusterBlockCLILoadConfig() failed, for block %s create on volume %s" + " with hosts %s\n", create_obj->block_name, create_obj->volume, + create_obj->block_hosts); + goto out; + } + + TIMEOUT.tv_sec = conf->GB_CLI_TIMEOUT; + if (!TIMEOUT.tv_sec) { + TIMEOUT.tv_sec = CLI_TIMEOUT_DEF; + } + switch(opt) { case CREATE_CLI: create_obj = cobj; @@ -212,6 +264,11 @@ glusterBlockCliRPC_1(void *cobj, clioperations opt) close (sockfd); } + if (conf) { + GB_FREE(conf->configPath); + GB_FREE(conf); + } + return ret; } diff --git a/daemon/gluster-blockd.c b/daemon/gluster-blockd.c index 384905d..5eac136 100644 --- a/daemon/gluster-blockd.c +++ b/daemon/gluster-blockd.c @@ -37,6 +37,8 @@ extern const char *argp_program_version; static gbConfig *gbCfg; +struct timeval TIMEOUT = {CLI_TIMEOUT_DEF, 0}; /* remote rpc call timeout, 5 mins */ + static void glusterBlockDHelp(void) { diff --git a/rpc/rpcl/Makefile.am b/rpc/rpcl/Makefile.am index 08a40ea..20c8112 100644 --- a/rpc/rpcl/Makefile.am +++ b/rpc/rpcl/Makefile.am @@ -11,13 +11,15 @@ CLEANFILES = *~ $(BUILT_SOURCES) block.h: block.x rpcgen -hM -o $(top_builddir)/rpc/rpcl/$@ $^ + $(SED) -i '0,/#endif/s//#endif\nextern struct timeval TIMEOUT;/' \ + $(top_builddir)/rpc/rpcl/$@ block_xdr.c: block.x rpcgen -cM -o $(top_builddir)/rpc/rpcl/$@ $^ block_clnt.c: block.x rpcgen -lM -o $(top_builddir)/rpc/rpcl/$@ $^ - $(SED) -i 's|TIMEOUT = { 25, 0 }|TIMEOUT = { 300, 0 }|' $(top_builddir)/rpc/rpcl/$@ + $(SED) -i '/TIMEOUT = { 25, 0 }/d' $(top_builddir)/rpc/rpcl/$@ block_svc.c: block.x rpcgen -mM -o $(top_builddir)/rpc/rpcl/$@ $^ diff --git a/systemd/gluster-blockd.sysconfig b/systemd/gluster-blockd.sysconfig index 4914c81..461d2bb 100644 --- a/systemd/gluster-blockd.sysconfig +++ b/systemd/gluster-blockd.sysconfig @@ -19,5 +19,9 @@ # default volfile server is set to localhost #GB_BHV_VOLSERVER="localhost" +# CLI rpc timeout, +# it is the time in seconds that cli has to wait for daemon to respond +#GB_CLI_TIMEOUT=300 + # Expert use only, just incase if we have any extra args to pass for daemon #GB_EXTRA_ARGS="" diff --git a/utils/Makefile.am b/utils/Makefile.am index c997e01..a11321b 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -10,6 +10,8 @@ libgb_la_CFLAGS = $(GFAPI_CFLAGS) -DDATADIR=\"$(localstatedir)\" \ libgb_la_LIBADD = $(GFAPI_LIBS) +libgb_la_LDFLAGS = -lpthread + libgb_ladir = $(includedir)/gluster-block/utils EXTRA_DIST = gluster-block-caps.info diff --git a/utils/common.h b/utils/common.h index 945378b..296210f 100644 --- a/utils/common.h +++ b/utils/common.h @@ -16,6 +16,7 @@ # include "block.h" # define GB_VOLS_DELIMITER ',' +# define CLI_TIMEOUT_DEF 300 typedef struct blockServerDef { @@ -108,4 +109,6 @@ void blockServerDefFree(blockServerDefPtr blkServers); bool blockhostIsValid(char *status); +int glusterBlockLoadConfig(gbConfig *cfg, bool reloading); + # endif /* _COMMON_H */ diff --git a/utils/dyn-config.c b/utils/dyn-config.c index 7c10090..6fd5e8a 100644 --- a/utils/dyn-config.c +++ b/utils/dyn-config.c @@ -184,6 +184,16 @@ glusterBlockConfSetOptions(gbConfig *cfg, bool reloading) if (cfg->GB_GLFS_LRU_COUNT) { glusterBlockSetLruCount(cfg->GB_GLFS_LRU_COUNT); } + + GB_PARSE_CFG_INT(cfg, GB_CLI_TIMEOUT, CLI_TIMEOUT_DEF); + /* NOTE: we don't use CLI_TIMEOUT in daemon at the moment + * TODO: use gbConf in cli too, for logLevel/LogDir and other future options + * + * if (cfg->GB_CLI_TIMEOUT) { + * glusterBlockSetCliTimeout(cfg->GB_CLI_TIMEOUT); + * } + */ + /* add your new config options */ } @@ -438,7 +448,7 @@ glusterBlockParseOptions(gbConfig *cfg, char *buf, int len, bool reloading) glusterBlockConfSetOptions(cfg, reloading); } -static int +int glusterBlockLoadConfig(gbConfig *cfg, bool reloading) { ssize_t len = 0; diff --git a/utils/utils.c b/utils/utils.c index 89362c7..fc5074f 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -19,7 +19,8 @@ struct gbConf gbConf = { .glfsLruCount = LRU_COUNT_DEF, .logLevel = GB_LOG_INFO, - .logDir = GB_LOGDIR + .logDir = GB_LOGDIR, + .cliTimeout = CLI_TIMEOUT_DEF }; const char *argp_program_version = "" \ @@ -49,6 +50,24 @@ glusterBlockSetLogLevel(unsigned int logLevel) return 0; } + +/* TODO: use gbConf in cli too, for logLevel/LogDir and other future options +int +glusterBlockSetCliTimeout(size_t timeout) +{ + if (timeout < 0) { + MSG(stderr, "unknown GB_CLI_TIMEOUT: '%zu'\n", timeout); + return -1; + } + LOCK(gbConf.lock); + gbConf.cliTimeout = timeout; + UNLOCK(gbConf.lock); + + return 0; +} +*/ + + int glusterBlockCLIOptEnumParse(const char *opt) { diff --git a/utils/utils.h b/utils/utils.h index e45e77b..e35a1ad 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -57,7 +57,7 @@ # define GB_METASTORE_RESERVE 10485760 /* 10 MiB reserve for block-meta */ -# define GB_DEF_CONFIGPATH "/etc/sysconfig/gluster-blockd"; /* the default config file */ +# define GB_DEF_CONFIGPATH "/etc/sysconfig/gluster-blockd" /* the default config file */ # define GB_TIME_STRING_BUFLEN \ (4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 6 + 1 + 5) @@ -132,6 +132,7 @@ struct gbConf { size_t glfsLruCount; unsigned int logLevel; + size_t cliTimeout; char logDir[PATH_MAX]; char daemonLogFile[PATH_MAX]; char cliLogFile[PATH_MAX]; @@ -574,10 +575,13 @@ typedef struct gbConfig { bool isDynamic; char *GB_LOG_LEVEL; ssize_t GB_GLFS_LRU_COUNT; + ssize_t GB_CLI_TIMEOUT; /* seconds */ } gbConfig; int glusterBlockSetLogLevel(unsigned int logLevel); +//int glusterBlockSetCliTimeout(size_t timeout); + int glusterBlockCLIOptEnumParse(const char *opt); int glusterBlockCLICreateOptEnumParse(const char *opt);