summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/gluster-block.c31
-rw-r--r--daemon/Makefile.am6
-rw-r--r--daemon/gluster-blockd.c65
-rw-r--r--utils/Makefile.am2
-rw-r--r--utils/lru.c5
-rw-r--r--utils/lru.h1
-rw-r--r--utils/utils.c37
-rw-r--r--utils/utils.h30
8 files changed, 143 insertions, 34 deletions
diff --git a/cli/gluster-block.c b/cli/gluster-block.c
index 228eb24..f2334e6 100644
--- a/cli/gluster-block.c
+++ b/cli/gluster-block.c
@@ -15,26 +15,6 @@
# include <ctype.h>
-
-typedef enum clioperations {
- CREATE_CLI = 1,
- LIST_CLI = 2,
- INFO_CLI = 3,
- DELETE_CLI = 4,
- MODIFY_CLI = 5
-} clioperations;
-
-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. <https://redhat.com/>\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.";
-
-
# define GB_CREATE_HELP_STR "gluster-block create <volname/blockname> "\
"[ha <count>] [auth enable|disable] "\
"<HOST1[,HOST2,...]> <size> [--json*]"
@@ -55,6 +35,17 @@ const char *argp_program_version = "" \
} while(0)
+extern const char *argp_program_version;
+
+typedef enum clioperations {
+ CREATE_CLI = 1,
+ LIST_CLI = 2,
+ INFO_CLI = 3,
+ DELETE_CLI = 4,
+ MODIFY_CLI = 5
+} clioperations;
+
+
static int
glusterBlockCliRPC_1(void *cobj, clioperations opt)
{
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index a44158a..de5367c 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -3,10 +3,10 @@ sbin_PROGRAMS = gluster-blockd
gluster_blockd_SOURCES = gluster-blockd.c
gluster_blockd_CFLAGS = $(GFAPI_CFLAGS) -DDATADIR=\"$(localstatedir)\" \
- -I$(top_srcdir)/utils/ -I$(top_srcdir)/rpc \
- -I$(top_builddir)/rpc/rpcl
+ -I$(top_builddir)/ -I$(top_srcdir)/utils/ \
+ -I$(top_srcdir)/rpc -I$(top_builddir)/rpc/rpcl
-gluster_blockd_LDADD = $(PTHREAD) $(top_builddir)/rpc/libgbrpc.la \
+gluster_blockd_LDADD = $(PTHREAD) $(top_builddir)/rpc/libgbrpc.la \
$(top_builddir)/utils/libgb.la
DISTCLEANFILES = Makefile.in
diff --git a/daemon/gluster-blockd.c b/daemon/gluster-blockd.c
index 0f06a70..5d546bd 100644
--- a/daemon/gluster-blockd.c
+++ b/daemon/gluster-blockd.c
@@ -15,6 +15,7 @@
# include <pthread.h>
# include <rpc/pmap_clnt.h>
+# include "config.h"
# include "common.h"
# include "lru.h"
# include "block.h"
@@ -22,6 +23,30 @@
+extern size_t glfsLruCount;
+extern const char *argp_program_version;
+
+
+static void
+glusterBlockDHelp(void)
+{
+ MSG("%s",
+ "gluster-blockd ("PACKAGE_VERSION")\n"
+ "usage:\n"
+ " gluster-blockd [--glfs-lru-count <count>]\n"
+ "\n"
+ "commands:\n"
+ " --glfs-lru-count <count>\n"
+ " glfs objects cache capacity [max: 512] (default: 5)\n"
+ " --help\n"
+ " show this message and exit.\n"
+ " --version\n"
+ " show version info and exit.\n"
+ "\n"
+ );
+}
+
+
static bool
glusterBlockLogdirCreate(void)
{
@@ -184,8 +209,48 @@ main (int argc, char **argv)
pthread_t server_thread;
struct flock lock = {0, };
int errnosv = 0;
+ size_t opt = 0;
+ if (argc > 1) {
+ opt = glusterBlockDaemonOptEnumParse(argv[1]);
+ if (!opt || opt >= GB_DAEMON_OPT_MAX) {
+ MSG("unknown option: %s\n", argv[1]);
+ return -1;
+ }
+
+ switch (opt) {
+ case GB_DAEMON_HELP:
+ case GB_DAEMON_USAGE:
+ if (argc != 2) {
+ MSG("undesired options for: %s\n", argv[1]);
+ }
+ glusterBlockDHelp();
+ return 0;
+
+ case GB_DAEMON_VERSION:
+ MSG("%s\n", argp_program_version);
+ return 0;
+
+ case GB_DAEMON_GLFS_LRU_COUNT:
+ if (argc != 3) {
+ MSG("undesired options for: %s\n", argv[1]);
+ return -1;
+ }
+ if (sscanf(argv[2], "%zu", &glfsLruCount) != 1) {
+ MSG("option '%s' expect argument type integer <count>\n", argv[1]);
+ return -1;
+ }
+ if (!glfsLruCount || (glfsLruCount > LRU_COUNT_MAX)) {
+ MSG("glfs-lru-count argument should be [0 < count < %d]\n", LRU_COUNT_MAX);
+ LOG("mgmt", GB_LOG_ERROR,
+ "glfs-lru-count argument should be [0 < count < %d]\n", LRU_COUNT_MAX);
+ return -1;
+ }
+ break;
+ }
+ }
+
if (!glusterBlockLogdirCreate()) {
return -1;
}
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. <https://redhat.com/>\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);