diff options
author | Prasanna Kumar Kalever <prasanna.kalever@redhat.com> | 2018-01-10 23:48:38 +0530 |
---|---|---|
committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2018-01-18 10:11:39 +0000 |
commit | 46f460fa669ce9f7b9f2de9e54cefc3726dcd029 (patch) | |
tree | 54a22636bc90649186e4b3001d13f861df75c61f /utils | |
parent | 5d98272c53816813872aaa807e4ccc1ee2ad1bfc (diff) |
versioning: add capabilities support
Change-Id: Ic63f7c9fa169ee37b796093554c59016fbbfaa46
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/Makefile.am | 17 | ||||
-rw-r--r-- | utils/capabilities.c | 109 | ||||
-rw-r--r-- | utils/capabilities.h | 65 | ||||
-rw-r--r-- | utils/gluster-block-caps.info | 98 | ||||
-rw-r--r-- | utils/utils.h | 8 |
5 files changed, 294 insertions, 3 deletions
diff --git a/utils/Makefile.am b/utils/Makefile.am index bdebb52..6eadf79 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -1,16 +1,27 @@ noinst_LTLIBRARIES = libgb.la -libgb_la_SOURCES = common.c utils.c lru.c +libgb_la_SOURCES = common.c utils.c lru.c capabilities.c -noinst_HEADERS = common.h utils.h lru.h list.h +noinst_HEADERS = common.h utils.h lru.h list.h capabilities.h -libgb_la_CFLAGS = $(GFAPI_CFLAGS) -DDATADIR=\"$(localstatedir)\" \ +libgb_la_CFLAGS = $(GFAPI_CFLAGS) \ + -DDATADIR=\"$(localstatedir)\" -DCONFDIR=\"$(sysconfigdir)\" \ -I$(top_builddir)/ -I$(top_builddir)/rpc/rpcl libgb_la_LIBADD = $(GFAPI_LIBS) libgb_ladir = $(includedir)/gluster-block/utils +EXTRA_DIST = gluster-block-caps.info + DISTCLEANFILES = Makefile.in CLEANFILES = *~ + +install-data-local: + $(MKDIR_P) $(DESTDIR)${sysconfigdir}; \ + $(INSTALL_DATA) gluster-block-caps.info \ + $(DESTDIR)${sysconfigdir}/gluster-block-caps.info; + +uninstall-local: + rm -f $(DESTDIR)${sysconfigdir}/gluster-block-caps.info diff --git a/utils/capabilities.c b/utils/capabilities.c new file mode 100644 index 0000000..d44dc8f --- /dev/null +++ b/utils/capabilities.c @@ -0,0 +1,109 @@ +/* + Copyright (c) 2018 Red Hat, Inc. <http://www.redhat.com> + This file is part of gluster-block. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + + +# include "capabilities.h" + + +int +gbCapabilitiesEnumParse(const char *cap) +{ + int i; + + + if (!cap) { + return GB_CAP_MAX; + } + + for (i = 0; i < GB_CAP_MAX; i++) { + if (!strcmp(cap, gbCapabilitiesLookup[i])) { + return i; + } + } + + return i; +} + + +int +gbSetCapabilties(blockResponse **c) +{ + FILE * fp; + char *line = NULL; + size_t len = 0; + int count = 0; + int ret = 0; + blockResponse *reply = *c; + gbCapObj *caps = NULL; + char *p, *sep; + + + fp = fopen(GB_CAPS_FILE, "r"); + if (fp == NULL) { + return -1; + } + + if (GB_ALLOC_N(caps, GB_CAP_MAX) < 0) { + fclose(fp); + return -1; + } + + while ((getline(&line, &len, fp)) != -1) { + if (!line) { + continue; + } + if ((line[0] == '\n') || (line[0] == '#')) { + GB_FREE(line); + continue; + } + + /* Part before ':' */ + p = line; + sep = strchr(p, ':'); + *sep = '\0'; + + ret = gbCapabilitiesEnumParse(p); + if (ret != GB_CAP_MAX) { + strncpy(caps[count].cap, gbCapabilitiesLookup[ret], 256); + + /* Part after ':' and before '\n' */ + p = sep + 1; + sep = strchr(p, '\n'); + *sep = '\0'; + + while(isspace((unsigned char)*p)) p++; + ret = convertStringToTrillianParse(p); + if (ret >= 0) { + caps[count].status = ret; + } else { + ret = -1; + goto out; + } + count++; + } + + GB_FREE(line); + } + + if (GB_CAP_MAX != count) { + ret = -1; + goto out; + } + + reply->xdata.xdata_len = GB_CAP_MAX * sizeof(gbCapObj); + reply->xdata.xdata_val = (char *) caps; + + ret = 0; + out: + GB_FREE(line); + fclose(fp); + + return ret; +} diff --git a/utils/capabilities.h b/utils/capabilities.h new file mode 100644 index 0000000..b157d80 --- /dev/null +++ b/utils/capabilities.h @@ -0,0 +1,65 @@ +/* + Copyright (c) 2018 Red Hat, Inc. <http://www.redhat.com> + This file is part of gluster-block. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + + +# include "block.h" +# include "common.h" + + +typedef struct gbCapObj { + char cap[256]; + bool status; +} gbCapObj; + + +typedef struct gbCapResp { + int capMax; + gbCapObj *response; +} gbCapResp; + + +enum gbCapabilities { + GB_CREATE_CAP, + GB_CREATE_HA_CAP, + GB_CREATE_PREALLOC_CAP, + GB_CREATE_AUTH_CAP, + + GB_DELETE_CAP, + GB_DELETE_FORCE_CAP, + + GB_MODIFY_CAP, + GB_MODIFY_AUTH_CAP, + + GB_JSON_CAP, + + GB_CAP_MAX +}; + + +static const char *const gbCapabilitiesLookup[] = { + [GB_CREATE_CAP] = "create", + [GB_CREATE_HA_CAP] = "create_ha", + [GB_CREATE_PREALLOC_CAP] = "create_prealloc", + [GB_CREATE_AUTH_CAP] = "create_auth", + + [GB_DELETE_CAP] = "delete", + [GB_DELETE_FORCE_CAP] = "delete_force", + + [GB_MODIFY_CAP] = "modify", + [GB_MODIFY_AUTH_CAP] = "modify_auth", + + [GB_JSON_CAP] = "json", + + [GB_CAP_MAX] = NULL +}; + + +int gbCapabilitiesEnumParse(const char *cap); +int gbSetCapabilties (blockResponse **c); diff --git a/utils/gluster-block-caps.info b/utils/gluster-block-caps.info new file mode 100644 index 0000000..2dcdbd4 --- /dev/null +++ b/utils/gluster-block-caps.info @@ -0,0 +1,98 @@ +## +# Nature: cli command +# +# Label: 'create' +# +# Description: capability to create block storage in local node +# +# Since: 0.1 +## +create: true + +## +# Nature: cli sub-command +# +# Label: 'ha' +# +# Description: capability to replicate configuration of block for high availability +# +# Since: 0.1 +## +create_ha: true + +## +# Nature: cli sub-command +# +# Label: 'prealloc' +# +# Description: capability to preallocate underline storage +# +# Since: 0.3 +## +create_prealloc: true + +## +# Nature: cli sub-command +# +# Label: 'auth' +# +# Description: capability to set CHAP authentication for block +# +# Since: 0.2 +## +create_auth: true + +## +# Nature: cli command +# +# Label: 'delete' +# +# Description: capability to delete a block storage +# +# Since: 0.1 +## +delete: true + +## +# Nature: cli command +# +# Label: 'force' +# +# Description: capability to delete a block storage forcefully +# +# Since: 0.1 +## +delete_force: true + +## +# Nature: cli command +# +# Label: 'modify' +# +# Description: capability to modify already existing block +# +# Since: 0.2 +## +modify: true + +## +# Nature: cli sub-command +# +# Label: 'auth' +# +# Description: capability to modify CHAP authentication caps for existing block +# +# Since: 0.2 +## +modify_auth: true + +## +# Nature: cli sub-command +# +# Label: '--json' +# +# Description: capability to furnish results of any command in json formated way +# +# Since: 0.2 +## +json: true diff --git a/utils/utils.h b/utils/utils.h index 8a30d25..7141a3f 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -31,6 +31,9 @@ # define GB_LOCK_FILE GB_INFODIR "/gluster-blockd.lock" # define GB_UNIX_ADDRESS GB_INFODIR "/gluster-blockd.socket" + +# define GB_CAPS_FILE CONFDIR "/gluster-block-caps.info" + # define GB_TCP_PORT 24010 # define GB_TCP_PORT_STR "24010" @@ -59,6 +62,11 @@ # define FAILED_CREATING_FILE "failed while creating block file in gluster volume" # define FAILED_CREATING_META "failed while creating block meta file from volume" +/* Target Capabilities */ +# define FAILED_CAPS "failed in capabilities check" +# define FAILED_REMOTE_CAPS "failed in remote capabilities check" +# define FAILED_REMOTE_AYNC_CAPS "failed in remote async capabilities check" + /* Target List */ # define FAILED_LIST "failed in list" |