From 15d9ee36c71bfe3499d7f3baf3a483199211261f Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Thu, 1 Jun 2017 15:08:44 +0530 Subject: daemon: make glfs lru cache capacity configurable $ gluster-blockd --help gluster-blockd (0.2) usage: gluster-blockd [--glfs-lru-count ] commands: --glfs-lru-count glfs objects cache capacity [max: 512] (default: 5) --help show this message and exit. --version show version info and exit. Change-Id: I00a9277690a1c5ace51e223e9e4ed9ce61ae2428 Signed-off-by: Prasanna Kumar Kalever --- utils/Makefile.am | 2 +- utils/lru.c | 5 ++--- utils/lru.h | 1 + utils/utils.c | 37 ++++++++++++++++++++++++++++++++++++- utils/utils.h | 30 ++++++++++++++++++++++++------ 5 files changed, 64 insertions(+), 11 deletions(-) (limited to 'utils') diff --git a/utils/Makefile.am b/utils/Makefile.am index 0da7857..bdebb52 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -5,7 +5,7 @@ libgb_la_SOURCES = common.c utils.c lru.c noinst_HEADERS = common.h utils.h lru.h list.h libgb_la_CFLAGS = $(GFAPI_CFLAGS) -DDATADIR=\"$(localstatedir)\" \ - -I$(top_builddir)/rpc/rpcl + -I$(top_builddir)/ -I$(top_builddir)/rpc/rpcl libgb_la_LIBADD = $(GFAPI_LIBS) diff --git a/utils/lru.c b/utils/lru.c index f1e884b..7fd036e 100644 --- a/utils/lru.c +++ b/utils/lru.c @@ -10,11 +10,10 @@ # include "lru.h" -# define LRU_CAPACITY 5 - static struct list_head Cache; static int lruCount; +size_t glfsLruCount = 5; /* default lru cache size */ typedef struct Entry { char volume[256]; @@ -50,7 +49,7 @@ appendNewEntry(const char *volname, glfs_t *fs) Entry *tmp; - if (lruCount == LRU_CAPACITY) { + if (lruCount == glfsLruCount) { releaseColdEntry(); } diff --git a/utils/lru.h b/utils/lru.h index e9af217..adb2834 100644 --- a/utils/lru.h +++ b/utils/lru.h @@ -17,6 +17,7 @@ # include "common.h" # include "list.h" +# define LRU_COUNT_MAX 512 void initCache(void); diff --git a/utils/utils.c b/utils/utils.c index 7f43bc4..49a5d3d 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -10,8 +10,19 @@ # include "utils.h" +# include "config.h" +const char *argp_program_version = "" \ + PACKAGE_NAME" ("PACKAGE_VERSION")" \ + "\nRepository rev: https://github.com/gluster/gluster-block.git\n" \ + "Copyright (c) 2016 Red Hat, Inc. \n" \ + "gluster-block comes with ABSOLUTELY NO WARRANTY.\n" \ + "It is licensed to you under your choice of the GNU Lesser\n" \ + "General Public License, version 3 or any later version (LGPLv3\n" \ + "or later), or the GNU General Public License, version 2 (GPLv2),\n"\ + "in all cases as published by the Free Software Foundation."; + int glusterBlockCLIOptEnumParse(const char *opt) @@ -24,7 +35,31 @@ glusterBlockCLIOptEnumParse(const char *opt) } for (i = 0; i < GB_CLI_OPT_MAX; i++) { - if (!strcmp(opt, gbCmdlineOptLookup[i])) { + if (!strcmp(opt, gbCliCmdlineOptLookup[i])) { + return i; + } + } + + return i; +} + + +int +glusterBlockDaemonOptEnumParse(const char *opt) +{ + int i; + + + if (!opt) { + return GB_DAEMON_OPT_MAX; + } + + for (i = 0; i < GB_DAEMON_OPT_MAX; i++) { + /* clip '--' from option */ + while (*opt == '-') { + opt++; + } + if (!strcmp(opt, gbDaemonCmdlineOptLookup[i])) { return i; } } diff --git a/utils/utils.h b/utils/utils.h index c9f0baf..db24833 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -213,9 +213,8 @@ gbFree(1 ? (void *) &(ptr) : (ptr)) -typedef enum gbCmdlineOption { +typedef enum gbCliCmdlineOption { GB_CLI_UNKNOWN = 0, - GB_CLI_CREATE = 1, GB_CLI_LIST = 2, GB_CLI_INFO = 3, @@ -229,12 +228,10 @@ typedef enum gbCmdlineOption { GB_CLI_HYPHEN_USAGE = 11, GB_CLI_OPT_MAX -} gbCmdlineOption; - +} gbCliCmdlineOption; -static const char *const gbCmdlineOptLookup[] = { +static const char *const gbCliCmdlineOptLookup[] = { [GB_CLI_UNKNOWN] = "NONE", - [GB_CLI_CREATE] = "create", [GB_CLI_LIST] = "list", [GB_CLI_INFO] = "info", @@ -250,6 +247,25 @@ static const char *const gbCmdlineOptLookup[] = { [GB_CLI_OPT_MAX] = NULL, }; +typedef enum gbDaemonCmdlineOption { + GB_DAEMON_UNKNOWN = 0, + GB_DAEMON_HELP = 1, + GB_DAEMON_VERSION = 2, + GB_DAEMON_USAGE = 3, + GB_DAEMON_GLFS_LRU_COUNT = 4, + + GB_DAEMON_OPT_MAX +} gbDaemonCmdlineOption; + +static const char *const gbDaemonCmdlineOptLookup[] = { + [GB_DAEMON_UNKNOWN] = "NONE", + [GB_DAEMON_HELP] = "help", + [GB_DAEMON_VERSION] = "version", + [GB_DAEMON_USAGE] = "usage", + [GB_DAEMON_GLFS_LRU_COUNT] = "glfs-lru-count", + + [GB_DAEMON_OPT_MAX] = NULL, +}; typedef enum LogLevel { GB_LOG_NONE = 0, @@ -368,6 +384,8 @@ static const char *const RemoteCreateRespLookup[] = { int glusterBlockCLIOptEnumParse(const char *opt); +int glusterBlockDaemonOptEnumParse(const char *opt); + int blockMetaKeyEnumParse(const char *opt); int blockMetaStatusEnumParse(const char *opt); -- cgit