summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorNiels de Vos <ndevos@redhat.com>2015-05-18 16:26:02 +0200
committerPranith Kumar Karampuri <pkarampu@redhat.com>2015-05-29 05:43:17 -0700
commit8a9328e37b8c63d60583184dc8dab12f85810682 (patch)
tree0fa017379bf5e9dfaa2e6d8132c73cc1090a3d52 /libglusterfs/src
parent5d912230a7d4f9979c10ff15da724624bd8e069d (diff)
build: do not #include "config.h" in each file
Instead of including config.h in each file, and have the additional config.h included from the compiler commandline (-include option). When a .c file tests for a certain #define, and config.h was not included, incorrect assumtions were made. With this change, it can not happen again. BUG: 1222319 Change-Id: I4f9097b8740b81ecfe8b218d52ca50361f74cb64 Signed-off-by: Niels de Vos <ndevos@redhat.com> Reviewed-on: http://review.gluster.org/10808 Tested-by: Gluster Build System <jenkins@build.gluster.com> Tested-by: NetBSD Build System Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com> Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/call-stub.c5
-rw-r--r--libglusterfs/src/call-stub.h5
-rw-r--r--libglusterfs/src/client_t.c5
-rw-r--r--libglusterfs/src/client_t.h5
-rw-r--r--libglusterfs/src/cluster-syncop.h5
-rw-r--r--libglusterfs/src/common-utils.c5
-rw-r--r--libglusterfs/src/common-utils.h5
-rw-r--r--libglusterfs/src/compat-errno.c5
-rw-r--r--libglusterfs/src/compat-errno.h5
-rw-r--r--libglusterfs/src/compat.c5
-rw-r--r--libglusterfs/src/compat.h5
-rw-r--r--libglusterfs/src/ctx.c5
-rw-r--r--libglusterfs/src/daemon.h5
-rw-r--r--libglusterfs/src/defaults.c5
-rw-r--r--libglusterfs/src/defaults.h5
-rw-r--r--libglusterfs/src/dict.c5
-rw-r--r--libglusterfs/src/dict.h5
-rw-r--r--libglusterfs/src/event-epoll.c5
-rw-r--r--libglusterfs/src/event-history.h5
-rw-r--r--libglusterfs/src/event-poll.c5
-rw-r--r--libglusterfs/src/event.c5
-rw-r--r--libglusterfs/src/event.h5
-rw-r--r--libglusterfs/src/fd.c5
-rw-r--r--libglusterfs/src/fd.h5
-rw-r--r--libglusterfs/src/gf-dirent.c5
-rw-r--r--libglusterfs/src/gf-dirent.h5
-rw-r--r--libglusterfs/src/gfdb/gfdb_data_store.h5
-rw-r--r--libglusterfs/src/gfdb/gfdb_data_store_types.h5
-rw-r--r--libglusterfs/src/gfdb/gfdb_sqlite3.h5
-rw-r--r--libglusterfs/src/gfdb/gfdb_sqlite3_helper.h5
-rw-r--r--libglusterfs/src/glfs-message-id.h5
-rw-r--r--libglusterfs/src/globals.c5
-rw-r--r--libglusterfs/src/glusterfs.h5
-rw-r--r--libglusterfs/src/graph-print.c5
-rw-r--r--libglusterfs/src/graph.c5
-rw-r--r--libglusterfs/src/hashfn.c5
-rw-r--r--libglusterfs/src/hashfn.h5
-rw-r--r--libglusterfs/src/iatt.h5
-rw-r--r--libglusterfs/src/inode.c5
-rw-r--r--libglusterfs/src/inode.h5
-rw-r--r--libglusterfs/src/lkowner.h5
-rw-r--r--libglusterfs/src/locking.h5
-rw-r--r--libglusterfs/src/logging.c5
-rw-r--r--libglusterfs/src/logging.h5
-rw-r--r--libglusterfs/src/lvm-defaults.h5
-rw-r--r--libglusterfs/src/options.c5
-rw-r--r--libglusterfs/src/options.h5
-rw-r--r--libglusterfs/src/stack.h5
-rw-r--r--libglusterfs/src/store.c5
-rw-r--r--libglusterfs/src/store.h5
-rw-r--r--libglusterfs/src/strfd.c5
-rw-r--r--libglusterfs/src/syncop-utils.c5
-rw-r--r--libglusterfs/src/syncop.c5
-rw-r--r--libglusterfs/src/syncop.h5
-rw-r--r--libglusterfs/src/syscall.c5
-rw-r--r--libglusterfs/src/template-component-messages.h5
-rw-r--r--libglusterfs/src/timer.c5
-rw-r--r--libglusterfs/src/timer.h5
-rw-r--r--libglusterfs/src/trie.h5
-rw-r--r--libglusterfs/src/xlator.c5
-rw-r--r--libglusterfs/src/xlator.h5
61 files changed, 0 insertions, 305 deletions
diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c
index 128dcf9e15f..911ea334909 100644
--- a/libglusterfs/src/call-stub.c
+++ b/libglusterfs/src/call-stub.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <openssl/md5.h>
#include <inttypes.h>
diff --git a/libglusterfs/src/call-stub.h b/libglusterfs/src/call-stub.h
index 954338be915..af4a2f55aff 100644
--- a/libglusterfs/src/call-stub.h
+++ b/libglusterfs/src/call-stub.h
@@ -11,11 +11,6 @@
#ifndef _CALL_STUB_H_
#define _CALL_STUB_H_
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "xlator.h"
#include "defaults.h"
#include "stack.h"
diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c
index 84257e66b09..9e6c90eba41 100644
--- a/libglusterfs/src/client_t.c
+++ b/libglusterfs/src/client_t.c
@@ -16,11 +16,6 @@
#include "rpcsvc.h"
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
static int
gf_client_chain_client_entries (cliententry_t *entries, uint32_t startidx,
uint32_t endcount)
diff --git a/libglusterfs/src/client_t.h b/libglusterfs/src/client_t.h
index 64c0514c8ac..bfea62061bd 100644
--- a/libglusterfs/src/client_t.h
+++ b/libglusterfs/src/client_t.h
@@ -11,11 +11,6 @@
#ifndef _CLIENT_T_H
#define _CLIENT_T_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "glusterfs.h"
#include "locking.h" /* for gf_lock_t, not included by glusterfs.h */
diff --git a/libglusterfs/src/cluster-syncop.h b/libglusterfs/src/cluster-syncop.h
index a681951c27d..3712259c65b 100644
--- a/libglusterfs/src/cluster-syncop.h
+++ b/libglusterfs/src/cluster-syncop.h
@@ -12,11 +12,6 @@
#ifndef _CLUSTER_SYNCOP_H
#define _CLUSTER_SYNCOP_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "xlator.h"
#include <sys/time.h>
#include <pthread.h>
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 4bcef6ae33f..bda336e348a 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#else
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index c361405d5eb..6691259f518 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -11,11 +11,6 @@
#ifndef _COMMON_UTILS_H
#define _COMMON_UTILS_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <stdint.h>
#include <sys/uio.h>
#include <netdb.h>
diff --git a/libglusterfs/src/compat-errno.c b/libglusterfs/src/compat-errno.c
index d8ab82a5d20..3674596ad71 100644
--- a/libglusterfs/src/compat-errno.c
+++ b/libglusterfs/src/compat-errno.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <stdint.h>
#include "compat-errno.h"
diff --git a/libglusterfs/src/compat-errno.h b/libglusterfs/src/compat-errno.h
index 65e52081dd3..6f46157e697 100644
--- a/libglusterfs/src/compat-errno.h
+++ b/libglusterfs/src/compat-errno.h
@@ -11,11 +11,6 @@
#ifndef __COMPAT_ERRNO_H__
#define __COMPAT_ERRNO_H__
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <errno.h>
#define GF_ERROR_CODE_SUCCESS 0
diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c
index 93e7b45a69e..0538a3298cb 100644
--- a/libglusterfs/src/compat.c
+++ b/libglusterfs/src/compat.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h
index 1522257dffe..458a751c2f4 100644
--- a/libglusterfs/src/compat.h
+++ b/libglusterfs/src/compat.h
@@ -11,11 +11,6 @@
#ifndef __COMPAT_H__
#define __COMPAT_H__
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <stdint.h>
#include "dict.h"
diff --git a/libglusterfs/src/ctx.c b/libglusterfs/src/ctx.c
index aa9d4216fd3..c70d97bc5d4 100644
--- a/libglusterfs/src/ctx.c
+++ b/libglusterfs/src/ctx.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif /* !_CONFIG_H */
-
#include <pthread.h>
#include "globals.h"
diff --git a/libglusterfs/src/daemon.h b/libglusterfs/src/daemon.h
index 80836a326d5..95e134b78b0 100644
--- a/libglusterfs/src/daemon.h
+++ b/libglusterfs/src/daemon.h
@@ -11,11 +11,6 @@
#ifndef _DAEMON_H
#define _DAEMON_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#define DEVNULLPATH "/dev/null"
int os_daemon_return(int nochdir, int noclose);
diff --git a/libglusterfs/src/defaults.c b/libglusterfs/src/defaults.c
index 1414da90731..b7174c8a939 100644
--- a/libglusterfs/src/defaults.c
+++ b/libglusterfs/src/defaults.c
@@ -20,11 +20,6 @@
All the functions are plain enough to understand.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "xlator.h"
#include "defaults.h"
diff --git a/libglusterfs/src/defaults.h b/libglusterfs/src/defaults.h
index a4ec7625409..68d23974b35 100644
--- a/libglusterfs/src/defaults.h
+++ b/libglusterfs/src/defaults.h
@@ -15,11 +15,6 @@
#ifndef _DEFAULTS_H
#define _DEFAULTS_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "xlator.h"
typedef struct {
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index ffc92e72724..23e25b16edc 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -16,11 +16,6 @@
#include <limits.h>
#include <fnmatch.h>
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "glusterfs.h"
#include "common-utils.h"
#include "dict.h"
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h
index a9004e96a50..46cb2a3ca55 100644
--- a/libglusterfs/src/dict.h
+++ b/libglusterfs/src/dict.h
@@ -11,11 +11,6 @@
#ifndef _DICT_H
#define _DICT_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <inttypes.h>
#include <sys/uio.h>
#include <pthread.h>
diff --git a/libglusterfs/src/event-epoll.c b/libglusterfs/src/event-epoll.c
index 92420f3734e..9703fdc0f3d 100644
--- a/libglusterfs/src/event-epoll.c
+++ b/libglusterfs/src/event-epoll.c
@@ -21,11 +21,6 @@
#include "mem-pool.h"
#include "common-utils.h"
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#ifdef HAVE_SYS_EPOLL_H
#include <sys/epoll.h>
diff --git a/libglusterfs/src/event-history.h b/libglusterfs/src/event-history.h
index b64f63b5eb4..de5d47cdfee 100644
--- a/libglusterfs/src/event-history.h
+++ b/libglusterfs/src/event-history.h
@@ -11,11 +11,6 @@
#ifndef _EH_H
#define _EH_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "mem-types.h"
#include "circ-buff.h"
diff --git a/libglusterfs/src/event-poll.c b/libglusterfs/src/event-poll.c
index 0daceb0d5a6..b32d38f6aa6 100644
--- a/libglusterfs/src/event-poll.c
+++ b/libglusterfs/src/event-poll.c
@@ -21,11 +21,6 @@
#include "mem-pool.h"
#include "common-utils.h"
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
struct event_slot_poll {
diff --git a/libglusterfs/src/event.c b/libglusterfs/src/event.c
index 35564e46ea8..ab93f6c1f12 100644
--- a/libglusterfs/src/event.c
+++ b/libglusterfs/src/event.c
@@ -21,11 +21,6 @@
#include "mem-pool.h"
#include "common-utils.h"
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
struct event_pool *
diff --git a/libglusterfs/src/event.h b/libglusterfs/src/event.h
index eac57bc01ad..b01ef24bb8e 100644
--- a/libglusterfs/src/event.h
+++ b/libglusterfs/src/event.h
@@ -11,11 +11,6 @@
#ifndef _EVENT_H_
#define _EVENT_H_
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <pthread.h>
struct event_pool;
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c
index 613f9017b0d..1a191f340eb 100644
--- a/libglusterfs/src/fd.c
+++ b/libglusterfs/src/fd.c
@@ -15,11 +15,6 @@
#include "statedump.h"
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
static int
gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr);
diff --git a/libglusterfs/src/fd.h b/libglusterfs/src/fd.h
index c1b9157d882..5a98ec38ca7 100644
--- a/libglusterfs/src/fd.h
+++ b/libglusterfs/src/fd.h
@@ -11,11 +11,6 @@
#ifndef _FD_H
#define _FD_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "list.h"
#include <sys/types.h>
#include <unistd.h>
diff --git a/libglusterfs/src/gf-dirent.c b/libglusterfs/src/gf-dirent.c
index 99c0eb6441d..c602d08b278 100644
--- a/libglusterfs/src/gf-dirent.c
+++ b/libglusterfs/src/gf-dirent.c
@@ -9,11 +9,6 @@
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <stdio.h>
#include <string.h>
diff --git a/libglusterfs/src/gf-dirent.h b/libglusterfs/src/gf-dirent.h
index faeaf411941..098a66ace15 100644
--- a/libglusterfs/src/gf-dirent.h
+++ b/libglusterfs/src/gf-dirent.h
@@ -12,11 +12,6 @@
#ifndef _GF_DIRENT_H
#define _GF_DIRENT_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "iatt.h"
#include "inode.h"
diff --git a/libglusterfs/src/gfdb/gfdb_data_store.h b/libglusterfs/src/gfdb/gfdb_data_store.h
index 977794df5cb..57f3de18f1c 100644
--- a/libglusterfs/src/gfdb/gfdb_data_store.h
+++ b/libglusterfs/src/gfdb/gfdb_data_store.h
@@ -11,11 +11,6 @@
#define __GFDB_DATA_STORE_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "glusterfs.h"
#include "xlator.h"
#include "logging.h"
diff --git a/libglusterfs/src/gfdb/gfdb_data_store_types.h b/libglusterfs/src/gfdb/gfdb_data_store_types.h
index 72a1c89a741..5f6650dd910 100644
--- a/libglusterfs/src/gfdb/gfdb_data_store_types.h
+++ b/libglusterfs/src/gfdb/gfdb_data_store_types.h
@@ -11,11 +11,6 @@
#define __GFDB_DATA_STORE_TYPE_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <time.h>
#include <sys/time.h>
#include <string.h>
diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3.h b/libglusterfs/src/gfdb/gfdb_sqlite3.h
index 04bfde7fa38..5b6921eafe2 100644
--- a/libglusterfs/src/gfdb/gfdb_sqlite3.h
+++ b/libglusterfs/src/gfdb/gfdb_sqlite3.h
@@ -11,11 +11,6 @@
#define __GFDB_SQLITE3_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
/*Sqlite3 header file*/
#include <sqlite3.h>
diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3_helper.h b/libglusterfs/src/gfdb/gfdb_sqlite3_helper.h
index 8b62be1d4d0..0d222305d01 100644
--- a/libglusterfs/src/gfdb/gfdb_sqlite3_helper.h
+++ b/libglusterfs/src/gfdb/gfdb_sqlite3_helper.h
@@ -11,11 +11,6 @@
#define __GFDB_SQLITE3_HELPER_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "gfdb_sqlite3.h"
/******************************************************************************
diff --git a/libglusterfs/src/glfs-message-id.h b/libglusterfs/src/glfs-message-id.h
index 0cd035f875f..f6ee181768c 100644
--- a/libglusterfs/src/glfs-message-id.h
+++ b/libglusterfs/src/glfs-message-id.h
@@ -11,11 +11,6 @@
#ifndef _GLFS_MESSAGE_ID_H_
#define _GLFS_MESSAGE_ID_H_
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
/* Base of all message IDs, all message IDs would be
* greater than this */
#define GLFS_MSGID_BASE 100000
diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c
index bd1165ec50c..a875049dfec 100644
--- a/libglusterfs/src/globals.c
+++ b/libglusterfs/src/globals.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif /* !_CONFIG_H */
-
#include <pthread.h>
#include "glusterfs.h"
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index 6f20185f80b..10e22af004e 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -11,11 +11,6 @@
#ifndef _GLUSTERFS_H
#define _GLUSTERFS_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
diff --git a/libglusterfs/src/graph-print.c b/libglusterfs/src/graph-print.c
index d860d63b308..d352cc798b8 100644
--- a/libglusterfs/src/graph-print.c
+++ b/libglusterfs/src/graph-print.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <sys/uio.h>
#include "common-utils.h"
diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c
index 709ec3b3ce3..e3a864bf111 100644
--- a/libglusterfs/src/graph.c
+++ b/libglusterfs/src/graph.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "xlator.h"
#include <dlfcn.h>
#include <netdb.h>
diff --git a/libglusterfs/src/hashfn.c b/libglusterfs/src/hashfn.c
index f79165b221e..62f7ab87800 100644
--- a/libglusterfs/src/hashfn.c
+++ b/libglusterfs/src/hashfn.c
@@ -11,11 +11,6 @@
#include <stdint.h>
#include <stdlib.h>
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "hashfn.h"
#define get16bits(d) (*((const uint16_t *) (d)))
diff --git a/libglusterfs/src/hashfn.h b/libglusterfs/src/hashfn.h
index 06ae37e796b..fed464e11cd 100644
--- a/libglusterfs/src/hashfn.h
+++ b/libglusterfs/src/hashfn.h
@@ -11,11 +11,6 @@
#ifndef __HASHFN_H__
#define __HASHFN_H__
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <sys/types.h>
#include <stdint.h>
diff --git a/libglusterfs/src/iatt.h b/libglusterfs/src/iatt.h
index a404d9c8cd0..e89f94662aa 100644
--- a/libglusterfs/src/iatt.h
+++ b/libglusterfs/src/iatt.h
@@ -12,11 +12,6 @@
#ifndef _IATT_H
#define _IATT_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <sys/types.h>
#include <sys/stat.h> /* for iatt <--> stat conversions */
#include <unistd.h>
diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c
index c010db2a682..47096de5410 100644
--- a/libglusterfs/src/inode.c
+++ b/libglusterfs/src/inode.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "inode.h"
#include "fd.h"
#include "common-utils.h"
diff --git a/libglusterfs/src/inode.h b/libglusterfs/src/inode.h
index 50815599347..83646ebda5a 100644
--- a/libglusterfs/src/inode.h
+++ b/libglusterfs/src/inode.h
@@ -11,11 +11,6 @@
#ifndef _INODE_H
#define _INODE_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <stdint.h>
#include <sys/types.h>
diff --git a/libglusterfs/src/lkowner.h b/libglusterfs/src/lkowner.h
index 969d13e5044..78f54a628d1 100644
--- a/libglusterfs/src/lkowner.h
+++ b/libglusterfs/src/lkowner.h
@@ -11,11 +11,6 @@
#ifndef _LK_OWNER_H
#define _LK_OWNER_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#define GF_MAX_LOCK_OWNER_LEN 1024 /* 1kB as per NLM */
/* 16strings-16strings-... */
diff --git a/libglusterfs/src/locking.h b/libglusterfs/src/locking.h
index 79c6992af0b..a66cdc188db 100644
--- a/libglusterfs/src/locking.h
+++ b/libglusterfs/src/locking.h
@@ -11,11 +11,6 @@
#ifndef _LOCKING_H
#define _LOCKING_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <pthread.h>
#if HAVE_SPINLOCK
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index e8fca2db916..90eebee2ab5 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h
index f19fe9e1002..515b4372e8a 100644
--- a/libglusterfs/src/logging.h
+++ b/libglusterfs/src/logging.h
@@ -11,11 +11,6 @@
#ifndef __LOGGING_H__
#define __LOGGING_H__
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <sys/time.h>
#include <stdint.h>
#include <stdio.h>
diff --git a/libglusterfs/src/lvm-defaults.h b/libglusterfs/src/lvm-defaults.h
index 4d3b010b200..32feebf3f6e 100644
--- a/libglusterfs/src/lvm-defaults.h
+++ b/libglusterfs/src/lvm-defaults.h
@@ -11,11 +11,6 @@
#ifndef _LVM_DEFAULTS_H
#define _LVM_DEFAULTS_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#define LVM_RESIZE "/sbin/lvresize"
#define LVM_CREATE "/sbin/lvcreate"
#define LVM_CONVERT "/sbin/lvconvert"
diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c
index 75dce0ea3b6..33d81879917 100644
--- a/libglusterfs/src/options.c
+++ b/libglusterfs/src/options.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <fnmatch.h>
#include "xlator.h"
diff --git a/libglusterfs/src/options.h b/libglusterfs/src/options.h
index 05a3d4332cf..83b545850c8 100644
--- a/libglusterfs/src/options.h
+++ b/libglusterfs/src/options.h
@@ -11,11 +11,6 @@
#ifndef _OPTIONS_H
#define _OPTIONS_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h
index f2d2ef95032..e0cc45eeb60 100644
--- a/libglusterfs/src/stack.h
+++ b/libglusterfs/src/stack.h
@@ -16,11 +16,6 @@
#ifndef _STACK_H
#define _STACK_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
struct _call_stack_t;
typedef struct _call_stack_t call_stack_t;
struct _call_frame_t;
diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c
index 351741f4297..42d2d75d8aa 100644
--- a/libglusterfs/src/store.c
+++ b/libglusterfs/src/store.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <inttypes.h>
#include <libgen.h>
diff --git a/libglusterfs/src/store.h b/libglusterfs/src/store.h
index 6b7c98a3547..4a726c6f00b 100644
--- a/libglusterfs/src/store.h
+++ b/libglusterfs/src/store.h
@@ -10,11 +10,6 @@
#ifndef _GLUSTERD_STORE_H_
#define _GLUSTERD_STORE_H_
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "compat.h"
#include "glusterfs.h"
diff --git a/libglusterfs/src/strfd.c b/libglusterfs/src/strfd.c
index 3eda05c2dbc..002d48629bc 100644
--- a/libglusterfs/src/strfd.c
+++ b/libglusterfs/src/strfd.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <stdarg.h>
#include "mem-types.h"
diff --git a/libglusterfs/src/syncop-utils.c b/libglusterfs/src/syncop-utils.c
index 349fa92d64f..81393136abb 100644
--- a/libglusterfs/src/syncop-utils.c
+++ b/libglusterfs/src/syncop-utils.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "syncop.h"
#include "common-utils.h"
diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c
index 81eae5a9105..a4e39702b70 100644
--- a/libglusterfs/src/syncop.c
+++ b/libglusterfs/src/syncop.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "syncop.h"
int
diff --git a/libglusterfs/src/syncop.h b/libglusterfs/src/syncop.h
index f41706a9d37..7779fada109 100644
--- a/libglusterfs/src/syncop.h
+++ b/libglusterfs/src/syncop.h
@@ -11,11 +11,6 @@
#ifndef _SYNCOP_H
#define _SYNCOP_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "xlator.h"
#include <sys/time.h>
#include <pthread.h>
diff --git a/libglusterfs/src/syscall.c b/libglusterfs/src/syscall.c
index 0828b8a64fa..dc257f6cfcc 100644
--- a/libglusterfs/src/syscall.c
+++ b/libglusterfs/src/syscall.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "compat.h"
#include "syscall.h"
diff --git a/libglusterfs/src/template-component-messages.h b/libglusterfs/src/template-component-messages.h
index c1ea38cf770..7a6d0d14e17 100644
--- a/libglusterfs/src/template-component-messages.h
+++ b/libglusterfs/src/template-component-messages.h
@@ -11,11 +11,6 @@
#ifndef _component_MESSAGES_H_
#define _component_MESSAGES_H_
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "glfs-message-id.h"
/* NOTE: Rules for message additions
diff --git a/libglusterfs/src/timer.c b/libglusterfs/src/timer.c
index 0d845cdeb38..1aa2079f097 100644
--- a/libglusterfs/src/timer.c
+++ b/libglusterfs/src/timer.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "timer.h"
#include "logging.h"
#include "common-utils.h"
diff --git a/libglusterfs/src/timer.h b/libglusterfs/src/timer.h
index e64b350ec58..220a280c705 100644
--- a/libglusterfs/src/timer.h
+++ b/libglusterfs/src/timer.h
@@ -11,11 +11,6 @@
#ifndef _TIMER_H
#define _TIMER_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "glusterfs.h"
#include "xlator.h"
#include <sys/time.h>
diff --git a/libglusterfs/src/trie.h b/libglusterfs/src/trie.h
index 0356e66210e..f7a4deee02f 100644
--- a/libglusterfs/src/trie.h
+++ b/libglusterfs/src/trie.h
@@ -11,11 +11,6 @@
#ifndef _TRIE_H_
#define _TRIE_H_
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
struct trienode;
typedef struct trienode trienode_t;
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 628f3499956..117454092cb 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -8,11 +8,6 @@
cases as published by the Free Software Foundation.
*/
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include "xlator.h"
#include <dlfcn.h>
#include <netdb.h>
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index ca30f99650e..d7dbfb413be 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -11,11 +11,6 @@
#ifndef _XLATOR_H
#define _XLATOR_H
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
f='#n2479'>2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705
/*
   Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com>
   This file is part of GlusterFS.

   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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>

#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#include "cli.h"
#include "cli-cmd.h"
#include "cli-mem-types.h"
#include "dict.h"

#include "protocol-common.h"
#include "cli1-xdr.h"

#define MAX_SNAP_DESCRIPTION_LEN 1024

struct snap_config_opt_vals_ snap_confopt_vals[] = {
        {.op_name        = "snap-max-hard-limit",
         .question       = "Changing snapshot-max-hard-limit "
                           "will lead to deletion of snapshots "
                           "if they exceed the new limit.\n"
                           "Do you want to continue?"
        },
        {.op_name        = "snap-max-soft-limit",
         .question       = "Changing snapshot-max-soft-limit "
                           "will lead to deletion of snapshots "
                           "if they exceed the new limit.\n"
                           "Do you want to continue?"
        },
        {.op_name        = "both",
        .question        = "Changing snapshot-max-hard-limit & "
                           "snapshot-max-soft-limit will lead to "
                           "deletion of snapshots if they exceed "
                           "the new limit.\nDo you want to continue?"
        },
        {.op_name        = NULL,
        }
};

enum cli_snap_config_set_types {
        GF_SNAP_CONFIG_SET_HARD = 0,
        GF_SNAP_CONFIG_SET_SOFT = 1,
        GF_SNAP_CONFIG_SET_BOTH = 2,
};
typedef enum cli_snap_config_set_types cli_snap_config_set_types;

static const char *
id_sel (void *wcon)
{
        return (const char *)wcon;
}

static char *
str_getunamb (const char *tok, char **opwords)
{
        return (char *)cli_getunamb (tok, (void **)opwords, id_sel);
}

int32_t
cli_cmd_bricks_parse (const char **words, int wordcount, int brick_index,
                      char **bricks, int *brick_count)
{
        int                    ret = 0;
        char             *tmp_list = NULL;
        char    brick_list[120000] = {0,};
        char                *space = " ";
        char            *delimiter = NULL;
        char            *host_name = NULL;
        char        *free_list_ptr = NULL;
        char               *tmpptr = NULL;
        int                      j = 0;
        int         brick_list_len = 0;
        char             *tmp_host = NULL;

        GF_ASSERT (words);
        GF_ASSERT (wordcount);
        GF_ASSERT (bricks);
        GF_ASSERT (brick_index > 0);
        GF_ASSERT (brick_index < wordcount);

        strncpy (brick_list, space, strlen (space));
        brick_list_len++;
        while (brick_index < wordcount) {
                if (validate_brick_name ((char *)words[brick_index])) {
                        cli_err ("Wrong brick type: %s, use <HOSTNAME>:"
                                 "<export-dir-abs-path>", words[brick_index]);
                        ret = -1;
                        goto out;
                } else {
                        delimiter = strrchr (words[brick_index], ':');
                        ret = gf_canonicalize_path (delimiter + 1);
                        if (ret)
                                goto out;
                }

                if ((brick_list_len + strlen (words[brick_index]) + 1) > sizeof (brick_list)) {
                        cli_err ("Total brick list is larger than a request. "
                                 "Can take (brick_count %d)", *brick_count);
                        ret = -1;
                        goto out;
                }

                tmp_host = gf_strdup ((char *)words[brick_index]);
                if (!tmp_host) {
                        gf_log ("cli", GF_LOG_ERROR, "Out of memory");
                        ret = -1;
                        goto out;
                }
                get_host_name (tmp_host, &host_name);
                if (!host_name) {
                        ret = -1;
                        gf_log("cli",GF_LOG_ERROR, "Unable to allocate "
                               "memory");
                        goto out;
                }

                if (!(strcmp (host_name, "localhost") &&
                      strcmp (host_name, "127.0.0.1") &&
                      strncmp (host_name, "0.", 2))) {
                        cli_err ("Please provide a valid hostname/ip other "
                                 "than localhost, 127.0.0.1 or loopback "
                                 "address (0.0.0.0 to 0.255.255.255).");
                        ret = -1;
                        GF_FREE (tmp_host);
                        goto out;
                }
                if (!valid_internet_address (host_name, _gf_false)) {
                        cli_err ("internet address '%s' does not conform to "
                                 "standards", host_name);
                }
                GF_FREE (tmp_host);
                tmp_list = gf_strdup (brick_list + 1);
                if (free_list_ptr) {
                        GF_FREE (free_list_ptr);
                        free_list_ptr = NULL;
                }
                free_list_ptr = tmp_list;
                j = 0;
                while(j < *brick_count) {
                        strtok_r (tmp_list, " ", &tmpptr);
                        if (!(strcmp (tmp_list, words[brick_index]))) {
                                ret = -1;
                                cli_err ("Found duplicate"
                                         " exports %s",words[brick_index]);
                                goto out;
                       }
                       tmp_list = tmpptr;
                       j++;
                }
                strcat (brick_list, words[brick_index]);
                strcat (brick_list, " ");
                brick_list_len += (strlen (words[brick_index]) + 1);
                ++(*brick_count);
                ++brick_index;
        }

        *bricks = gf_strdup (brick_list);
        if (!*bricks)
                ret = -1;
out:
        GF_FREE (free_list_ptr);
        return ret;
}

int32_t
cli_cmd_create_disperse_check (struct cli_state *state, int *disperse,
                               int *redundancy, int *data, int count)
{
        int i = 0;
        int tmp = 0;
        gf_answer_t answer = GF_ANSWER_NO;
        char question[128];

        const char *question1 = "There isn't an optimal redundancy value "
                                "for this configuration. Do you want to "
                                "create the volume with redundancy 1 ?";

        const char *question2 = "The optimal redundancy for this "
                                "configuration is %d. Do you want to create "
                                "the volume with this value ?";

        const char *question3 = "This configuration is not optimal on most "
                                "workloads. Do you want to use it ?";

        const char *question4 = "Redundancy for this configuration is %d. "
                                "Do you want to create "
                                "the volume with this value ?";

        if (*data > 0) {
                if (*disperse > 0 && *redundancy > 0) {
                        if (*disperse != (*data + *redundancy)) {
                                cli_err ("Disperse count(%d) should be equal "
                                         "to sum of disperse-data count(%d) and "
                                         "redundancy count(%d)", *disperse,
                                         *data, *redundancy);
                                return -1;
                        }
                } else if (*redundancy > 0) {
                        *disperse = *data + *redundancy;
                } else if (*disperse > 0) {
                        *redundancy = *disperse - *data;
                } else {
                        if ((count - *data) >= *data) {
                                cli_err ("Please provide redundancy count "
                                         "along with disperse-data count");
                                return -1;
                        } else {
                                sprintf (question, question4, count - *data);
                                answer = cli_cmd_get_confirmation (state,
                                                                   question);
                                if (answer == GF_ANSWER_NO)
                                        return -1;
                                *redundancy = count - *data;
                                *disperse = count;
                        }
                }
        }

        if (*disperse <= 0) {
                if (count < 3) {
                        cli_err ("number of bricks must be greater "
                                 "than 2");

                        return -1;
                }
                *disperse = count;
        }

        if (*redundancy == -1) {
                tmp = *disperse - 1;
                for (i = tmp / 2;
                     (i > 0) && ((tmp & -tmp) != tmp);
                     i--, tmp--);

                if (i == 0) {
                        answer = cli_cmd_get_confirmation(state, question1);
                        if (answer == GF_ANSWER_NO)
                                return -1;

                        *redundancy = 1;
                }
                else
                {
                        *redundancy = *disperse - tmp;
                        if (*redundancy > 1) {
                                sprintf(question, question2, *redundancy);
                                answer = cli_cmd_get_confirmation(state,
                                                                  question);
                                if (answer == GF_ANSWER_NO)
                                        return -1;
                        }
                }

                tmp = 0;
        } else {
                tmp = *disperse - *redundancy;
        }

        if (*redundancy > (*disperse - 1) / 2) {
                cli_err ("redundancy must be less than %d for a "
                         "disperse %d volume",
                         (*disperse + 1) / 2, *disperse);

                return -1;
        }

        if ((tmp & -tmp) != tmp) {
                answer = cli_cmd_get_confirmation(state, question3);
                if (answer == GF_ANSWER_NO)
                        return -1;
        }

        return 0;
}

static int32_t
cli_validate_disperse_volume (char *word, gf1_cluster_type type,
                              const char **words, int32_t wordcount,
                              int32_t index, int32_t *disperse_count,
                              int32_t *redundancy_count,
                              int32_t *data_count)
{
        int     ret = -1;

        switch (type) {
        case GF_CLUSTER_TYPE_NONE:
        case GF_CLUSTER_TYPE_DISPERSE:
                if (strcmp (word, "disperse") == 0) {
                        if (*disperse_count >= 0) {
                                cli_err ("disperse option given twice");
                                goto out;
                        }
                        if (wordcount < (index+2)) {
                                goto out;
                        }
                        ret = gf_string2int (words[index + 1], disperse_count);
                        if (ret == -1 && errno == EINVAL) {
                                *disperse_count = 0;
                                ret = 1;
                        } else if (ret == -1) {
                                goto out;
                        } else {
                                if (*disperse_count < 3) {
                                        cli_err ("disperse count must "
                                                 "be greater than 2");
                                        goto out;
                                }
                                ret = 2;
                        }
                } else if (strcmp (word, "disperse-data") == 0) {
                        if (*data_count >= 0) {
                                cli_err ("disperse-data option given twice");
                                goto out;
                        }
                        if (wordcount < (index+2)) {
                                goto out;
                        }
                        ret = gf_string2int (words[index+1], data_count);
                        if (ret == -1 || *data_count < 2) {
                                cli_err ("disperse-data must be greater than 1");
                                goto out;
                        }
                        ret = 2;
                } else if (strcmp (word, "redundancy") == 0) {
                        if (*redundancy_count >= 0) {
                                cli_err ("redundancy option given twice");
                                goto out;
                        }
                        if (wordcount < (index+2)) {
                                goto out;
                        }
                        ret = gf_string2int (words[index+1], redundancy_count);
                        if (ret == -1 || *redundancy_count < 1) {
                                cli_err ("redundancy must be greater than 0");
                                goto out;
                        }
                        ret = 2;
                }
                break;
        case GF_CLUSTER_TYPE_STRIPE_REPLICATE:
                cli_err ("striped-replicated-dispersed volume "
                         "is not supported");
                goto out;
        case GF_CLUSTER_TYPE_STRIPE:
                cli_err ("striped-dispersed volume is not "
                         "supported");
                goto out;
        case GF_CLUSTER_TYPE_REPLICATE:
                cli_err ("replicated-dispersed volume is not "
                         "supported");
                goto out;
        }
out:
        return ret;
}

int32_t
cli_cmd_volume_create_parse (struct cli_state *state, const char **words,
                             int wordcount, dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        int     ret = -1;
        gf1_cluster_type type = GF_CLUSTER_TYPE_NONE;
        int     count = 1;
        int     sub_count = 1;
        int     brick_index = 0;
        int     i = 0;
        char    *trans_type = NULL;
        int32_t index = 0;
        char    *bricks = NULL;
        int32_t brick_count = 0;
        char    *opwords[] = { "replica", "stripe", "transport", "disperse",
                               "redundancy", "disperse-data", NULL };

        char    *invalid_volnames[] = {"volume", "type", "subvolumes", "option",
                                       "end-volume", "all", "volume_not_in_ring",
                                       "description", "force",
                                       "snap-max-hard-limit",
                                       "snap-max-soft-limit", "auto-delete",
                                       "activate-on-create", NULL};
        char    *w = NULL;
        char    *ptr = NULL;
        int      op_count = 0;
        int32_t  replica_count = 1;
        int32_t  stripe_count = 1;
        int32_t  disperse_count = -1;
        int32_t  redundancy_count = -1;
        int32_t  disperse_data_count = -1;
        gf_boolean_t is_force = _gf_false;
        int wc = wordcount;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 3)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        /* Validate the volume name here itself */
        {
                if (volname[0] == '-')
                        goto out;

                for (i = 0; invalid_volnames[i]; i++) {
                        if (!strcmp (volname, invalid_volnames[i])) {
                                cli_err ("\"%s\" cannot be the name of a volume.",
                                         volname);
                                goto out;
                        }
                }

                if (strchr (volname, '/'))
                        goto out;

                if (strlen (volname) > GD_VOLUME_NAME_MAX) {
                        cli_err("Volume name exceeds %d characters.",
                                GD_VOLUME_NAME_MAX);
                        goto out;
                }

                for (i = 0; i < strlen (volname); i++)
                        if (!isalnum (volname[i]) && (volname[i] != '_') &&
                           (volname[i] != '-')) {
                                cli_err ("Volume name should not contain \"%c\""
                                         " character.\nVolume names can only"
                                         "contain alphanumeric, '-' and '_' "
                                         "characters.",volname[i]);
                                goto out;
                        }
        }

        if (wordcount < 4) {
                ret = -1;
                goto out;
        }

        type = GF_CLUSTER_TYPE_NONE;
        index = 3;

        while (op_count < 3) {
                ret = -1;
                w = str_getunamb (words[index], opwords);
                if (!w) {
                        break;
                } else if ((strcmp (w, "replica")) == 0) {
                        switch (type) {
                        case GF_CLUSTER_TYPE_STRIPE_REPLICATE:
                        case GF_CLUSTER_TYPE_REPLICATE:
                                cli_err ("replica option given twice");
                                goto out;
                        case GF_CLUSTER_TYPE_NONE:
                                type = GF_CLUSTER_TYPE_REPLICATE;
                                break;
                        case GF_CLUSTER_TYPE_STRIPE:
                                type = GF_CLUSTER_TYPE_STRIPE_REPLICATE;
                                break;
                        case GF_CLUSTER_TYPE_DISPERSE:
                                cli_err ("replicated-dispersed volume is not "
                                         "supported");
                                goto out;
                        }

                        if (wordcount < (index+2)) {
                                ret = -1;
                                goto out;
                        }
                        replica_count = strtol (words[index+1], NULL, 0);
                        if (replica_count < 2) {
                                cli_err ("replica count should be greater"
                                         " than 1");
                                ret = -1;
                                goto out;
                        }
                        ret = dict_set_int32 (dict, "replica-count", replica_count);
                        if (ret)
                                goto out;

                        index += 2;

                } else if ((strcmp (w, "stripe")) == 0) {
                        switch (type) {
                        case GF_CLUSTER_TYPE_STRIPE_REPLICATE:
                        case GF_CLUSTER_TYPE_STRIPE:
                                cli_err ("stripe option given twice");
                                goto out;
                        case GF_CLUSTER_TYPE_NONE:
                                type = GF_CLUSTER_TYPE_STRIPE;
                                break;
                        case GF_CLUSTER_TYPE_REPLICATE:
                                type = GF_CLUSTER_TYPE_STRIPE_REPLICATE;
                                break;
                        case GF_CLUSTER_TYPE_DISPERSE:
                                cli_err ("striped-dispersed volume is not "
                                         "supported");
                                goto out;
                        }
                        if (wordcount < (index + 2)) {
                                ret = -1;
                                goto out;
                        }
                        stripe_count = strtol (words[index+1], NULL, 0);
                        if (stripe_count < 2) {
                                cli_err ("stripe count should be greater"
                                         " than 1");
                                ret = -1;
                                goto out;
                        }
                        ret = dict_set_int32 (dict, "stripe-count", stripe_count);
                        if (ret)
                                goto out;

                        index += 2;

                } else if ((strcmp (w, "transport")) == 0) {
                        if (trans_type) {
                                cli_err ("'transport' option given more"
                                         " than one time");
                                goto out;
                        }
                        if ((strcasecmp (words[index+1], "tcp") == 0)) {
                                trans_type = gf_strdup ("tcp");
                        } else if ((strcasecmp (words[index+1], "rdma") == 0)) {
                                trans_type = gf_strdup ("rdma");
                        } else if ((strcasecmp (words[index+1], "tcp,rdma") == 0) ||
                                   (strcasecmp (words[index+1], "rdma,tcp") == 0)) {
                                trans_type = gf_strdup ("tcp,rdma");
                        } else {
                                gf_log ("", GF_LOG_ERROR, "incorrect transport"
                                        " protocol specified");
                                ret = -1;
                                goto out;
                        }
                        index += 2;

                } else if ((strcmp (w, "disperse") == 0) ||
                           (strcmp (w, "redundancy") == 0) ||
                           (strcmp (w, "disperse-data") == 0)) {
                        ret = cli_validate_disperse_volume (w, type, words,
                                      wordcount, index, &disperse_count,
                                      &redundancy_count, &disperse_data_count);
                        if (ret < 0)
                                goto out;
                        index += ret;
                        type = GF_CLUSTER_TYPE_DISPERSE;
                } else {
                        GF_ASSERT (!"opword mismatch");
                        ret = -1;
                        goto out;
                }
                op_count++;
        }

        if (!trans_type)
                trans_type = gf_strdup ("tcp");

        /* reset the count value now */
        count = 1;

        if (index >= wordcount) {
                ret = -1;
                goto out;
        }

        brick_index = index;

        if (strcmp (words[wordcount - 1], "force") == 0) {
                is_force = _gf_true;
                wc = wordcount - 1;
        }

        ret = cli_cmd_bricks_parse (words, wc, brick_index, &bricks,
                                    &brick_count);
        if (ret)
                goto out;

        /* If brick-count is not valid when replica or stripe is
           given, exit here */
        if (!brick_count) {
                cli_err ("No bricks specified");
                ret = -1;
                goto out;
        }

        if (type == GF_CLUSTER_TYPE_DISPERSE) {
                ret = cli_cmd_create_disperse_check (state, &disperse_count,
                                                     &redundancy_count,
                                                     &disperse_data_count,
                                                     brick_count);
                if (!ret)
                        ret = dict_set_int32 (dict, "disperse-count",
                                              disperse_count);
                if (!ret)
                        ret = dict_set_int32 (dict, "redundancy-count",
                                              redundancy_count);
                if (ret)
                        goto out;

                sub_count = disperse_count;
        } else
                sub_count = stripe_count * replica_count;

        if (brick_count % sub_count) {
                if (type == GF_CLUSTER_TYPE_STRIPE)
                        cli_err ("number of bricks is not a multiple of "
                                 "stripe count");
                else if (type == GF_CLUSTER_TYPE_REPLICATE)
                        cli_err ("number of bricks is not a multiple of "
                                 "replica count");
                else if (type == GF_CLUSTER_TYPE_DISPERSE)
                        cli_err ("number of bricks is not a multiple of "
                                 "disperse count");
                else
                        cli_err ("number of bricks given doesn't match "
                                 "required count");

                ret = -1;
                goto out;
        }

        /* Everything is parsed fine. start setting info in dict */
        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "type", type);
        if (ret)
                goto out;

        ret = dict_set_dynstr (dict, "transport", trans_type);
        if (ret)
                goto out;
        trans_type = NULL;

        ret = dict_set_dynstr (dict, "bricks", bricks);
        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "count", brick_count);
        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "force", is_force);
        if (ret)
                goto out;

        *options = dict;

out:
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to parse create volume CLI");
                if (dict)
                        dict_destroy (dict);
        }

        GF_FREE (trans_type);

        return ret;
}

int32_t
cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        int     ret = -1;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 3)
                goto out;

        if (wordcount > 5)
                goto out;

        volname = (char *)words[2];

        if (!volname) {
                ret = -1;
                goto out;
        }

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        if (wordcount == 3) {
                ret = dict_set_str (dict, "key", "all");
                if (ret)
                        goto out;
        }

        if (wordcount >= 4) {
                if (!strcmp ("force", (char*)words[3])) {
                        ret = dict_set_int32 (dict, "force", 1);
                        if (ret)
                                goto out;
                        ret = dict_set_str (dict, "key", "all");
                        if (ret)
                                goto out;
                } else {
                        ret = dict_set_str (dict, "key", (char *)words[3]);
                        if (ret)
                                goto out;
                }
        }

        if (wordcount == 5) {
                if (strcmp ("force", (char*)words[4])) {
                        ret = -1;
                        goto out;
                } else {
                        ret = dict_set_int32 (dict, "force", 1);
                        if (ret)
                                goto out;
                }
        }

        *options = dict;

out:
        if (ret && dict) {
                dict_destroy (dict);
        }

                return ret;
}

/* Parsing global option for NFS-Ganesha config
 *  gluster features.ganesha enable/disable */

int32_t
cli_cmd_ganesha_parse (struct cli_state *state,
                       const char **words, int wordcount,
                       dict_t **options, char **op_errstr)
{
        dict_t  *dict     =       NULL;
        int     ret       =       -1;
        int     flags     =       0;
        char    *key      =       NULL;
        char    *value    =       NULL;
        int     i         =       0;
        char    *w        =       NULL;
        char   *opwords[] =      { "enable", "disable" };
        const char      *question       =       NULL;
        gf_answer_t     answer          =       GF_ANSWER_NO;


        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount != 2)
                goto out;

        key   = (char *) words[0];
        value = (char *) words[1];

        if (!key || !value) {
                cli_out ("Usage : features.ganesha <enable/disable>");
                ret = -1;
                goto out;
        }

        ret = gf_strip_whitespace (value, strlen (value));
        if (ret == -1)
                goto out;

        if (strcmp (key, "features.ganesha")) {
                gf_asprintf (op_errstr, "Global option: error: ' %s '"
                          "is not a valid global option.", key);
                ret = -1;
                goto out;
        }

        w = str_getunamb (value, opwords);
        if (!w) {
                cli_out ("Invalid global option \n"
                         "Usage : features.ganesha <enable/disable>");
                ret = -1;
                goto out;
        }

        question = "Enabling NFS-Ganesha requires Gluster-NFS to be"
                   "disabled across the trusted pool. Do you "
                   "still want to continue?";

        if (strcmp (value, "enable") == 0) {
                answer = cli_cmd_get_confirmation (state, question);
                if (GF_ANSWER_NO == answer) {
                        gf_log ("cli", GF_LOG_ERROR, "Global operation "
                                "cancelled, exiting");
                        ret = -1;
                        goto out;
                }
        }

        ret = dict_set_str (dict, "key", key);
        if (ret) {
               gf_log (THIS->name, GF_LOG_ERROR, "dict set on key failed");
                goto out;
        }

        ret = dict_set_str (dict, "value", value);
        if (ret) {
               gf_log (THIS->name, GF_LOG_ERROR, "dict set on value failed");
                goto out;
        }

        *options = dict;
out:
        if (ret)
                dict_unref (dict);

        return ret;
}

int32_t
cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options)
{
        dict_t          *dict    = NULL;
        char            *volname = NULL;
        int              ret     = -1;
        int              i       = 0;
        char             key[20] = {0, };
        uint64_t         value   = 0;
        gf_quota_type    type    = GF_QUOTA_OPTION_TYPE_NONE;
        char           *opwords[] = { "enable", "disable", "limit-usage",
                                      "remove", "list", "alert-time",
                                      "soft-timeout", "hard-timeout",
                                      "default-soft-limit", NULL};
        char            *w       = NULL;
        uint32_t         time    = 0;
        double           percent = 0;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();
        if (!dict)
                goto out;

        if (wordcount < 4)
                goto out;

        volname = (char *)words[2];
        if (!volname) {
                ret = -1;
                goto out;
        }

        /* Validate the volume name here itself */
        {
                if (volname[0] == '-')
                        goto out;

                if (!strcmp (volname, "all")) {
                        cli_err ("\"all\" cannot be the name of a volume.");
                        goto out;
                }

                if (strchr (volname, '/'))
                        goto out;

                if (strlen (volname) > GD_VOLUME_NAME_MAX) {
                        cli_err("Volname can not exceed %d characters.",
                                GD_VOLUME_NAME_MAX);
                        goto out;
                }

                for (i = 0; i < strlen (volname); i++)
                       if (!isalnum (volname[i]) && (volname[i] != '_') &&
                          (volname[i] != '-')) {
                                cli_err ("Volume name should not contain \"%c\""
                                         " character.\nVolume names can only"
                                         "contain alphanumeric, '-' and '_' "
                                         "characters.",volname[i]);
                                goto out;
                       }
        }

        ret = dict_set_str (dict, "volname", volname);
        if (ret < 0)
                goto out;

        w = str_getunamb (words[3], opwords);
        if (!w) {
                cli_out ("Invalid quota option : %s", words[3]);
                ret = - 1;
                goto out;
        }

        if (strcmp (w, "enable") == 0) {
                if (wordcount == 4) {
                        type = GF_QUOTA_OPTION_TYPE_ENABLE;
                        ret = 0;
                        goto set_type;
                } else {
                        ret = -1;
                        goto out;
                }
        }

        if (strcmp (w, "disable") == 0) {
                if (wordcount == 4) {
                        type = GF_QUOTA_OPTION_TYPE_DISABLE;
                        ret = 0;
                        goto set_type;
                } else {
                        ret = -1;
                        goto out;
                }
        }

        if (strcmp (w, "limit-usage") == 0) {

                if (wordcount < 6 || wordcount > 7) {
                        ret = -1;
                        goto out;
                }

                type = GF_QUOTA_OPTION_TYPE_LIMIT_USAGE;

                if (words[4][0] != '/') {
                        cli_err ("Please enter absolute path");
                        ret = -1;
                        goto out;
                }
                ret = dict_set_str (dict, "path", (char *) words[4]);
                if (ret)
                        goto out;

                if (!words[5]) {
                        cli_err ("Please enter the limit value to be set");
                        ret = -1;
                        goto out;
                }

                ret = gf_string2bytesize_uint64 (words[5], &value);
                if (ret != 0) {
                        if (errno == ERANGE)
                                cli_err ("Value too large: %s", words[5]);
                        else
                                cli_err ("Please enter a correct value");
                        goto out;
                }

                ret  = dict_set_str (dict, "hard-limit", (char *) words[5]);
                if (ret < 0)
                        goto out;

                if (wordcount == 7) {

                        ret = gf_string2percent (words[6], &percent);
                        if (ret != 0) {
                                cli_err ("Please enter a correct value");
                                goto out;
                        }

                        ret = dict_set_str (dict, "soft-limit",
                                            (char *) words[6]);
                        if (ret < 0)
                                goto out;
                }

                goto set_type;
        }
        if (strcmp (w, "remove") == 0) {
                if (wordcount != 5) {
                        ret = -1;
                        goto out;
                }

                type = GF_QUOTA_OPTION_TYPE_REMOVE;

                if (words[4][0] != '/') {
                        cli_err ("Please enter absolute path");
                        ret = -1;
                        goto out;
                }

                ret = dict_set_str (dict, "path", (char *) words[4]);
                if (ret < 0)
                        goto out;
                goto set_type;
        }

        if (strcmp (w, "list") == 0) {
                if (wordcount < 4) {
                        ret = -1;
                        goto out;
                }

                type = GF_QUOTA_OPTION_TYPE_LIST;

                i = 4;
                while (i < wordcount) {
                        snprintf (key, 20, "path%d", i-4);

                        ret = dict_set_str (dict, key, (char *) words [i++]);
                        if (ret < 0)
                                goto out;
                }

                ret = dict_set_int32 (dict, "count", i - 4);
                if (ret < 0)
                        goto out;

                goto set_type;
        }


        if (strcmp (w, "alert-time") == 0) {
                if (wordcount != 5) {
                        ret = -1;
                        goto out;
                }
                type = GF_QUOTA_OPTION_TYPE_ALERT_TIME;

                ret = gf_string2time (words[4], &time);
                if (ret) {
                        cli_err ("Invalid argument %s. Please enter a valid "
                                 "string", words[4]);
                        goto out;
                }

                ret = dict_set_str (dict, "value", (char *)words[4]);
                if (ret < 0)
                        goto out;
                goto set_type;
        }
        if (strcmp (w, "soft-timeout") == 0) {
                if (wordcount != 5) {
                        ret = -1;
                        goto out;
                }
                type = GF_QUOTA_OPTION_TYPE_SOFT_TIMEOUT;

                ret = gf_string2time (words[4], &time);
                if (ret) {
                        cli_err ("Invalid argument %s. Please enter a valid "
                                 "string", words[4]);
                        goto out;
                }

                ret = dict_set_str (dict, "value", (char *)words[4]);
                if (ret < 0)
                        goto out;
                goto set_type;
        }
        if (strcmp (w, "hard-timeout") == 0) {
                if(wordcount != 5) {
                        ret = -1;
                        goto out;
                }
                type = GF_QUOTA_OPTION_TYPE_HARD_TIMEOUT;

                ret = gf_string2time (words[4], &time);
                if (ret) {
                        cli_err ("Invalid argument %s. Please enter a valid "
                                 "string", words[4]);
                        goto out;
                }

                ret = dict_set_str (dict, "value", (char *)words[4]);
                if (ret < 0)
                        goto out;
                goto set_type;
        }
        if (strcmp (w, "default-soft-limit") == 0) {
                if(wordcount != 5) {
                        ret = -1;
                        goto out;
                }
                type = GF_QUOTA_OPTION_TYPE_DEFAULT_SOFT_LIMIT;

                ret = dict_set_str (dict, "value", (char *)words[4]);
                if (ret < 0)
                        goto out;
                goto set_type;
        } else {
                GF_ASSERT (!"opword mismatch");
        }

set_type:
        ret = dict_set_int32 (dict, "type", type);
        if (ret < 0)
                goto out;

        *options = dict;
out:
        if (ret < 0) {
                if (dict)
                        dict_destroy (dict);
        }

        return ret;
}

static inline gf_boolean_t
cli_is_key_spl (char *key)
{
        return (strcmp (key, "group") == 0);
}

static int
cli_add_key_group (dict_t *dict, char *key, char *value, char **op_errstr)
{
        int             ret = -1;
        int             opt_count = 0;
        char            iter_key[1024] = {0,};
        char            iter_val[1024] = {0,};
        char            *saveptr = NULL;
        char            *tok_key = NULL;
        char            *tok_val = NULL;
        char            *dkey = NULL;
        char            *dval = NULL;
        char            *tagpath = NULL;
        char            *buf = NULL;
        char            line[PATH_MAX + 256] = {0,};
        char            errstr[2048] = "";
        FILE            *fp = NULL;

        ret = gf_asprintf (&tagpath, "%s/groups/%s",
                           GLUSTERD_DEFAULT_WORKDIR, value);
        if (ret == -1) {
                tagpath = NULL;
                goto out;
        }

        fp = fopen (tagpath, "r");
        if (!fp) {
                ret = -1;
                snprintf(errstr, sizeof(errstr), "Unable to open file '%s'."
                         " Error: %s", tagpath, strerror (errno));
                if (op_errstr)
                        *op_errstr = gf_strdup(errstr);
                goto out;
        }

        opt_count = 0;
        buf = line;
        while (fscanf (fp, "%s", buf) != EOF) {

                opt_count++;
                tok_key = strtok_r (line, "=", &saveptr);
                tok_val = strtok_r (NULL, "=", &saveptr);
                if (!tok_key || !tok_val) {
                        ret = -1;
                        snprintf(errstr, sizeof(errstr), "'%s' file format "
                                 "not valid.", tagpath);
                        if (op_errstr)
                                *op_errstr = gf_strdup(errstr);
                        goto out;
                }

                snprintf (iter_key, sizeof (iter_key), "key%d", opt_count);
                dkey = gf_strdup (tok_key);
                ret = dict_set_dynstr (dict, iter_key, dkey);
                if (ret)
                        goto out;
                dkey = NULL;

                snprintf (iter_val, sizeof (iter_val), "value%d", opt_count);
                dval = gf_strdup (tok_val);
                ret = dict_set_dynstr (dict, iter_val, dval);
                if (ret)
                        goto out;
                dval = NULL;

        }

        if (!opt_count) {
                ret = -1;
                snprintf(errstr, sizeof(errstr), "'%s' file format "
                         "not valid.", tagpath);
                if (op_errstr)
                        *op_errstr = gf_strdup(errstr);
                goto out;
        }
        ret = dict_set_int32 (dict, "count", opt_count);
out:

        GF_FREE (tagpath);

        if (ret) {
                GF_FREE (dkey);
                GF_FREE (dval);
        }

        if (fp)
                fclose (fp);

        return ret;
}

int32_t
cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options,
                          char **op_errstr)
{
        dict_t                  *dict = NULL;
        char                    *volname = NULL;
        int                     ret = -1;
        int                     count = 0;
        char                    *key = NULL;
        char                    *value = NULL;
        int                     i = 0;
        char                    str[50] = {0,};

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 3)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);

        if (ret)
                goto out;

        if ((!strcmp (volname, "help") || !strcmp (volname, "help-xml"))
            && wordcount == 3 ) {
                ret = dict_set_str (dict, volname, volname);
                if (ret)
                        goto out;

        } else if (wordcount < 5) {
                ret = -1;
                goto out;

        } else if (wordcount == 5  && cli_is_key_spl ((char *)words[3])) {
                key = (char *) words[3];
                value = (char *) words[4];
                if ( !key || !value) {
                        ret = -1;
                        goto out;
                }

                ret = gf_strip_whitespace (value, strlen (value));
                if (ret == -1)
                        goto out;

                if (strlen (value) == 0) {
                        ret = -1;
                        goto out;
                }

                ret = cli_add_key_group (dict, key, value, op_errstr);
                if (ret == 0)
                        *options = dict;
                goto out;
        }

        for (i = 3; i < wordcount; i+=2) {

                key = (char *) words[i];
                value = (char *) words[i+1];

                if ( !key || !value) {
                        ret = -1;
                        goto out;
                }

                count++;

                ret = gf_strip_whitespace (value, strlen (value));
                if (ret == -1)
                        goto out;

                if (strlen (value) == 0) {
                        ret = -1;
                        goto out;
                }

                if (cli_is_key_spl (key)) {
                        ret = -1;
                        goto out;
                }

                sprintf (str, "key%d", count);
                ret = dict_set_str (dict, str, key);
                if (ret)
                        goto out;

                sprintf (str, "value%d", count);
                ret = dict_set_str (dict, str, value);

                if (ret)
                        goto out;
        }

        ret = dict_set_int32 (dict, "count", wordcount-3);

        if (ret)
                goto out;

        *options = dict;

out:
        if (ret)
                dict_destroy (dict);

        return ret;
}

int32_t
cli_cmd_volume_add_brick_parse (const char **words, int wordcount,
                                dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        int     ret = -1;
        int     brick_count = 0, brick_index = 0;
        char    *bricks = NULL;
        char    *opwords_cl[] = { "replica", "stripe", NULL };
        gf1_cluster_type type = GF_CLUSTER_TYPE_NONE;
        int     count = 1;
        char    *w = NULL;
        int     index;
        gf_boolean_t is_force = _gf_false;
        int wc = wordcount;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 3)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);

        if (ret)
                goto out;

        if (wordcount < 4) {
                ret = -1;
                goto out;
        }
        if (wordcount < 6) {
                /* seems no options are given, go directly to the parse_brick */
                brick_index = 3;
                type = GF_CLUSTER_TYPE_NONE;
                goto parse_bricks;
        }

        w = str_getunamb (words[3], opwords_cl);
        if (!w) {
                type = GF_CLUSTER_TYPE_NONE;
                index = 3;
        } else if ((strcmp (w, "replica")) == 0) {
                type = GF_CLUSTER_TYPE_REPLICATE;
                if (wordcount < 5) {
                        ret = -1;
                        goto out;
                }
                count = strtol (words[4], NULL, 0);
                if (!count || (count < 2)) {
                        cli_err ("replica count should be greater than 1");
                        ret = -1;
                        goto out;
                }
                ret = dict_set_int32 (dict, "replica-count", count);
                if (ret)
                        goto out;
                index = 5;
        } else if ((strcmp (w, "stripe")) == 0) {
                type = GF_CLUSTER_TYPE_STRIPE;
                if (wordcount < 5) {
                        ret = -1;
                        goto out;
                }
                count = strtol (words[4], NULL, 0);
                if (!count || (count < 2)) {
                        cli_err ("stripe count should be greater than 1");
                        ret = -1;
                        goto out;
                }
                ret = dict_set_int32 (dict, "stripe-count", count);
                if (ret)
                        goto out;
                index = 5;
        } else {
                GF_ASSERT (!"opword mismatch");
                ret = -1;
                goto out;
        }

        brick_index = index;

parse_bricks:

        if (strcmp (words[wordcount - 1], "force") == 0) {
                is_force = _gf_true;
                wc = wordcount - 1;
        }

        ret = cli_cmd_bricks_parse (words, wc, brick_index, &bricks,
                                    &brick_count);
        if (ret)
                goto out;

        ret = dict_set_dynstr (dict, "bricks", bricks);
        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "count", brick_count);

        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "force", is_force);
        if (ret)
                goto out;

        *options = dict;

out:
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to parse add-brick CLI");
                if (dict)
                        dict_destroy (dict);
        }

        return ret;
}


int32_t
cli_cmd_volume_remove_brick_parse (const char **words, int wordcount,
                                   dict_t **options, int *question)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        char    *delimiter = NULL;
        int     ret = -1;
        char    key[50];
        int     brick_count = 0, brick_index = 0;
        int32_t tmp_index = 0;
        int32_t j = 0;
        char    *tmp_brick = NULL;
        char    *tmp_brick1 = NULL;
        char    *type_opword[] = { "replica", NULL };
        char    *opwords[] = { "start", "commit", "stop", "status",
                               "force", NULL };
        char    *w = NULL;
        int32_t  command = GF_OP_CMD_NONE;
        long     count = 0;

        GF_ASSERT (words);
        GF_ASSERT (options);

        if (wordcount < 5)
                goto out;

        dict = dict_new ();
        if (!dict)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        brick_index = 3;
        w = str_getunamb (words[3], type_opword);
        if (w && !strcmp ("replica", w)) {
                if (wordcount < 6) {
                        ret = -1;
                        goto out;
                }
                count = strtol (words[4], NULL, 0);
                if (count < 1) {
                        cli_err ("replica count should be greater than 0 in "
                                 "case of remove-brick");
                        ret = -1;
                        goto out;
                }

                ret = dict_set_int32 (dict, "replica-count", count);
                if (ret)
                        goto out;
                brick_index = 5;
        } else if (w) {
                GF_ASSERT (!"opword mismatch");
        }

        w = str_getunamb (words[wordcount - 1], opwords);
        if (!w) {
                ret = -1;
                goto out;
        } else {
                /* handled this option */
                wordcount--;
                if (!strcmp ("start", w)) {
                        command = GF_OP_CMD_START;
                } else if (!strcmp ("commit", w)) {
                        command = GF_OP_CMD_COMMIT;
                        if (question)
                                *question = 1;
                } else if (!strcmp ("stop", w)) {
                        command = GF_OP_CMD_STOP;
                } else if (!strcmp ("status", w)) {
                        command = GF_OP_CMD_STATUS;
                } else if (!strcmp ("force", w)) {
                        command = GF_OP_CMD_COMMIT_FORCE;
                        if (question)
                                *question = 1;
                } else {
                        GF_ASSERT (!"opword mismatch");
                        ret = -1;
                        goto out;
                }
        }

        ret = dict_set_int32 (dict, "command", command);
        if (ret)
                gf_log ("cli", GF_LOG_INFO, "failed to set 'command' %d",
                        command);


        tmp_index = brick_index;
        tmp_brick = GF_MALLOC(2048 * sizeof(*tmp_brick), gf_common_mt_char);

        if (!tmp_brick) {
                gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: "
                        "Unable to get memory");
                ret = -1;
                goto out;
        }

        tmp_brick1 = GF_MALLOC(2048 * sizeof(*tmp_brick1), gf_common_mt_char);

        if (!tmp_brick1) {
                gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: "
                        "Unable to get memory");
                ret = -1;
                goto out;
        }

        while (brick_index < wordcount) {
                if (validate_brick_name ((char *)words[brick_index])) {
                        cli_err ("wrong brick type: %s, use <HOSTNAME>:"
                                 "<export-dir-abs-path>", words[brick_index]);
                        ret = -1;
                        goto out;
                } else {
                        delimiter = strrchr(words[brick_index], ':');
                        ret = gf_canonicalize_path (delimiter + 1);
                        if (ret)
                                goto out;
                }

                j = tmp_index;
                strcpy(tmp_brick, words[brick_index]);
                while ( j < brick_index) {
                        strcpy(tmp_brick1, words[j]);
                        if (!(strcmp (tmp_brick, tmp_brick1))) {
                                gf_log("",GF_LOG_ERROR, "Duplicate bricks"
                                       " found %s", words[brick_index]);
                                cli_err("Duplicate bricks found %s",
                                        words[brick_index]);
                                ret = -1;
                                goto out;
                        }
                        j++;
                }
                snprintf (key, 50, "brick%d", ++brick_count);
                ret = dict_set_str (dict, key, (char *)words[brick_index++]);

                if (ret)
                        goto out;
        }

        ret = dict_set_int32 (dict, "count", brick_count);
        if (ret)
                goto out;

        *options = dict;

out:
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI");
                if (dict)
                        dict_destroy (dict);
        }

        GF_FREE (tmp_brick);
        GF_FREE (tmp_brick1);

        return ret;
}


int32_t
cli_cmd_volume_replace_brick_parse (const char **words, int wordcount,
                                   dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        int     ret = -1;
        int     op_index = 0;
        char    *delimiter = NULL;
        gf1_cli_replace_op replace_op = GF_REPLACE_OP_NONE;
        char    *opwords[] = { "start", "commit", "pause", "abort", "status",
                                NULL };
        char    *w = NULL;
        gf_boolean_t is_force = _gf_false;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 3)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);

        if (ret)
                goto out;

        if (wordcount < 4) {
                ret = -1;
                goto out;
        }

        if (validate_brick_name ((char *)words[3])) {
                cli_err ("wrong brick type: %s, use "
                         "<HOSTNAME>:<export-dir-abs-path>", words[3]);
                ret = -1;
                goto out;
        } else {
                delimiter = strrchr ((char *)words[3], ':');
                ret = gf_canonicalize_path (delimiter + 1);
                if (ret)
                        goto out;
        }
        ret = dict_set_str (dict, "src-brick", (char *)words[3]);

        if (ret)
                goto out;

        if (wordcount < 5) {
                ret = -1;
                goto out;
        }

        if (validate_brick_name ((char *)words[4])) {
                cli_err ("wrong brick type: %s, use "
                         "<HOSTNAME>:<export-dir-abs-path>", words[4]);
                ret = -1;
                goto out;
        } else {
                delimiter = strrchr ((char *)words[4], ':');
                ret = gf_canonicalize_path (delimiter + 1);
                if (ret)
                        goto out;
        }


        ret = dict_set_str (dict, "dst-brick", (char *)words[4]);

        if (ret)
                goto out;

        op_index = 5;
        if ((wordcount < (op_index + 1))) {
                ret = -1;
                goto out;
        }

        w = str_getunamb (words[op_index], opwords);

        if (!w) {
        } else if (!strcmp ("start", w)) {
                replace_op = GF_REPLACE_OP_START;
        } else if (!strcmp ("commit", w)) {
                replace_op = GF_REPLACE_OP_COMMIT;
        } else if (!strcmp ("pause", w)) {
                replace_op = GF_REPLACE_OP_PAUSE;
        } else if (!strcmp ("abort", w)) {
                replace_op = GF_REPLACE_OP_ABORT;
        } else if (!strcmp ("status", w)) {
                replace_op = GF_REPLACE_OP_STATUS;
        } else
                GF_ASSERT (!"opword mismatch");

        /* commit force option */

        op_index = 6;

        if (wordcount > (op_index + 1)) {
                ret = -1;
                goto out;
        }

        if (wordcount == (op_index + 1)) {
                if ((replace_op != GF_REPLACE_OP_COMMIT) &&
                    (replace_op != GF_REPLACE_OP_START)) {
                        ret = -1;
                        goto out;
                }
                if (!strcmp ("force", words[op_index])) {
                        if (replace_op == GF_REPLACE_OP_COMMIT)
                                replace_op = GF_REPLACE_OP_COMMIT_FORCE;

                        else if (replace_op == GF_REPLACE_OP_START)
                                is_force = _gf_true;
                }
        }

        if (replace_op == GF_REPLACE_OP_NONE) {
                ret = -1;
                goto out;
        }

        ret = dict_set_int32 (dict, "operation", (int32_t) replace_op);

        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "force", is_force);
        if (ret)
                goto out;

        *options = dict;

out:
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to parse replace-brick CLI");
                if (dict)
                        dict_destroy (dict);
        }

        return ret;
}

int32_t
cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        char    *str = NULL;
        int     ret = -1;
        char    *delimiter = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();
        if (!dict)
                goto out;

        volname = (char *)words[3];
        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        str = (char *)words[4];
        if (strchr (str, ':')) {
                delimiter = strchr (words[4], ':');
                if (!delimiter || delimiter == words[4]
                    || *(delimiter+1) != '/') {
                        cli_err ("wrong brick type: %s, use <HOSTNAME>:"
                                 "<export-dir-abs-path>", words[4]);
                        ret = -1;
                        goto out;
                } else {
                        ret = gf_canonicalize_path (delimiter + 1);
                        if (ret)
                                goto out;
                }
                ret = dict_set_str (dict, "brick", str);
                if (ret)
                        goto out;
                /* Path */
                str = (char *)words[5];
                ret = dict_set_str (dict, "path", str);
                if (ret)
                        goto out;
        } else {
                ret = dict_set_str (dict, "path", str);
                if (ret)
                        goto out;
        }

        *options = dict;

out:
        if (ret && dict)
                dict_destroy (dict);

        return ret;
}

int32_t
cli_cmd_log_level_parse (const char **words, int worcount, dict_t **options)
{
        dict_t *dict            = NULL;
        int     ret             = -1;

        GF_ASSERT (words);
        GF_ASSERT (options);

        /*
         * loglevel command format:
         *  > volume log level <VOL> <XLATOR[*]> <LOGLEVEL>
         *  > volume log level colon-o posix WARNING
         *  > volume log level colon-o replicate* DEBUG
         *  > volume log level coon-o * TRACE
         */

        GF_ASSERT ((strncmp(words[0], "volume", 6) == 0));
        GF_ASSERT ((strncmp(words[1], "log", 3) == 0));
        GF_ASSERT ((strncmp(words[2], "level", 5) == 0));

        ret = glusterd_check_log_level(words[5]);
        if (ret == -1) {
                cli_err("Invalid log level [%s] specified", words[5]);
                cli_err("Valid values for loglevel: (DEBUG|WARNING|ERROR"
                        "|CRITICAL|NONE|TRACE)");
                goto out;
        }

        dict = dict_new ();
        if (!dict)
                goto out;

        GF_ASSERT(words[3]);
        GF_ASSERT(words[4]);

        ret = dict_set_str (dict, "volname", (char *)words[3]);
        if (ret)
                goto out;

        ret = dict_set_str (dict, "xlator", (char *)words[4]);
        if (ret)
                goto out;

        ret = dict_set_str (dict, "loglevel", (char *)words[5]);
        if (ret)
                goto out;

        *options = dict;

 out:
        if (ret && dict)
                dict_destroy (dict);

        return ret;
}

int32_t
cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        char    *str = NULL;
        int     ret = -1;
        char    *delimiter = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();
        if (!dict)
                goto out;

        volname = (char *)words[3];
        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        if (words[4]) {
                delimiter = strchr (words[4], ':');
                if (!delimiter || delimiter == words[4]
                    || *(delimiter+1) != '/') {
                        cli_err ("wrong brick type: %s, use <HOSTNAME>:"
                                 "<export-dir-abs-path>", words[4]);
                        ret = -1;
                        goto out;
                } else {
                        ret = gf_canonicalize_path (delimiter + 1);
                        if (ret)
                                goto out;
                }
                str = (char *)words[4];
                ret = dict_set_str (dict, "brick", str);
                if (ret)
                        goto out;
        }

        *options = dict;

out:
        if (ret && dict)
                dict_destroy (dict);

        return ret;
}

int32_t
cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        char    *str = NULL;
        int     ret = -1;
        char    *delimiter = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();
        if (!dict)
                goto out;

        if (strcmp ("rotate", words[3]) == 0)
                volname = (char *)words[2];
        else if (strcmp ("rotate", words[2]) == 0)
                volname = (char *)words[3];
        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        if (words[4]) {
                delimiter = strchr (words[4], ':');
                if (!delimiter || delimiter == words[4]
                    || *(delimiter+1) != '/') {
                        cli_err ("wrong brick type: %s, use <HOSTNAME>:"
                                 "<export-dir-abs-path>", words[4]);
                        ret = -1;
                        goto out;
                } else {
                        ret = gf_canonicalize_path (delimiter + 1);
                        if (ret)
                                goto out;
                }
                str = (char *)words[4];
                ret = dict_set_str (dict, "brick", str);
                if (ret)
                        goto out;
        }

        *options = dict;

out:
        if (ret && dict)
                dict_destroy (dict);

        return ret;
}

static gf_boolean_t
gsyncd_url_check (const char *w)
{
        return !!strpbrk (w, ":/");
}

static gf_boolean_t
gsyncd_glob_check (const char *w)
{
        return !!strpbrk (w, "*?[");
}

static int
config_parse (const char **words, int wordcount, dict_t *dict,
              unsigned cmdi, unsigned glob)
{
        int32_t            ret     = -1;
        int32_t            i       = -1;
        char               *append_str = NULL;
        size_t             append_len = 0;
        char               *subop = NULL;

        switch ((wordcount - 1) - cmdi) {
        case 0:
                subop = gf_strdup ("get-all");
                break;
        case 1:
                if (words[cmdi + 1][0] == '!') {
                        (words[cmdi + 1])++;
                        if (gf_asprintf (&subop, "del%s",
                                         glob ? "-glob" : "") == -1)
                                subop = NULL;
                } else
                        subop = gf_strdup ("get");

                ret = dict_set_str (dict, "op_name", ((char *)words[cmdi + 1]));
                if (ret < 0)
                        goto out;
                break;
        default:
                if (gf_asprintf (&subop, "set%s", glob ? "-glob" : "") == -1)
                        subop = NULL;

                ret = dict_set_str (dict, "op_name", ((char *)words[cmdi + 1]));
                if (ret < 0)
                        goto out;

                /* join the varargs by spaces to get the op_value */

                for (i = cmdi + 2; i < wordcount; i++)
                        append_len += (strlen (words[i]) + 1);
                /* trailing strcat will add two bytes, make space for that */
                append_len++;

                append_str = GF_CALLOC (1, append_len, cli_mt_append_str);
                if (!append_str) {
                        ret = -1;
                        goto out;
                }

                for (i = cmdi + 2; i < wordcount; i++) {
                        strcat (append_str, words[i]);
                        strcat (append_str, " ");
                }
                append_str[append_len - 2] = '\0';
                /* "checkpoint now" is special: we resolve that "now" */
                if ((strcmp (words[cmdi + 1], "checkpoint") == 0) &&
                    (strcmp (append_str, "now") == 0)) {
                        struct timeval tv = {0,};

                        ret = gettimeofday (&tv, NULL);
                        if (ret == -1)
                                goto out;

                        GF_FREE (append_str);
                        append_str = GF_CALLOC (1, 300, cli_mt_append_str);
                        if (!append_str) {
                                ret = -1;
                                goto out;
                        }
                        snprintf (append_str, 300, "now:%" GF_PRI_SECOND ".%06"GF_PRI_SUSECONDS,
                                  tv.tv_sec, tv.tv_usec);
                }

                ret = dict_set_dynstr (dict, "op_value", append_str);
        }

        ret = -1;
        if (subop) {
                ret = dict_set_dynstr (dict, "subop", subop);
                if (!ret)
                      subop = NULL;
        }

out:
        if (ret && append_str)
                GF_FREE (append_str);

        GF_FREE (subop);

        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}

static int32_t
force_push_pem_no_verify_parse (const char **words, int wordcount,
                      dict_t *dict, unsigned *cmdi)
{
        int32_t            ret     = 0;

        if (!strcmp ((char *)words[wordcount-1], "force")) {
                if ((strcmp ((char *)words[wordcount-2], "start")) &&
                    (strcmp ((char *)words[wordcount-2], "stop")) &&
                    (strcmp ((char *)words[wordcount-2], "create")) &&
                    (strcmp ((char *)words[wordcount-2], "no-verify")) &&
                    (strcmp ((char *)words[wordcount-2], "push-pem")) &&
                    (strcmp ((char *)words[wordcount-2], "pause")) &&
                    (strcmp ((char *)words[wordcount-2], "resume"))) {
                        ret = -1;
                        goto out;
                }
                ret = dict_set_uint32 (dict, "force",
                                       _gf_true);
                if (ret)
                        goto out;
                (*cmdi)++;

                if (!strcmp ((char *)words[wordcount-2], "push-pem")) {
                        if (strcmp ((char *)words[wordcount-3], "create")) {
                                ret = -1;
                                goto out;
                        }
                        ret = dict_set_int32 (dict, "push_pem", 1);
                        if (ret)
                                goto out;
                        (*cmdi)++;
                } else if (!strcmp ((char *)words[wordcount-2], "no-verify")) {
                        if (strcmp ((char *)words[wordcount-3], "create")) {
                                ret = -1;
                                goto out;
                        }
                        ret = dict_set_uint32 (dict, "no_verify",
                                               _gf_true);
                        if (ret)
                                goto out;
                        (*cmdi)++;
                }
        } else if (!strcmp ((char *)words[wordcount-1], "push-pem")) {
                if (strcmp ((char *)words[wordcount-2], "create")) {
                        ret = -1;
                        goto out;
                }
                ret = dict_set_int32 (dict, "push_pem", 1);
                if (ret)
                        goto out;
                (*cmdi)++;
        } else if (!strcmp ((char *)words[wordcount-1], "no-verify")) {
                if ((strcmp ((char *)words[wordcount-2], "create"))) {
                        ret = -1;
                        goto out;
                }
                ret = dict_set_uint32 (dict, "no_verify",
                                       _gf_true);
                if (ret)
                        goto out;
                (*cmdi)++;
        }

out:
        gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
        return ret;
}


int32_t
cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options)
{
        int32_t            ret     = -1;
        dict_t             *dict   = NULL;
        gf1_cli_gsync_set  type    = GF_GSYNC_OPTION_TYPE_NONE;
        int                i       = 0;
        unsigned           masteri = 0;
        unsigned           slavei  = 0;
        unsigned           glob    = 0;
        unsigned           cmdi    = 0;
        char               *opwords[] = { "create", "status", "start", "stop",
                                          "config", "force", "delete", "no-verify"
                                          "push-pem", "detail", "pause",
                                          "resume", NULL };
        char               *w = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();
        if (!dict)
                goto out;

        /* new syntax:
         *
         * volume geo-replication $m $s create [[no-verify] | [push-pem]] [force]
         * volume geo-replication [$m [$s]] status [detail]
         * volume geo-replication [$m] $s config [[!]$opt [$val]]
         * volume geo-replication $m $s start|stop [force]
         * volume geo-replication $m $s delete
         * volume geo-replication $m $s pause [force]
         * volume geo-replication $m $s resume [force]
         */

        if (wordcount < 3)
                goto out;

        for (i = 2; i <= 3 && i < wordcount - 1; i++) {
                if (gsyncd_glob_check (words[i]))
                        glob = i;
                if (gsyncd_url_check (words[i])) {
                        slavei = i;
                        break;
                }
        }

        if (glob && !slavei)
                /* glob is allowed only for config, thus it implies there is a
                 * slave argument; but that might have not been recognized on
                 * the first scan as it's url characteristics has been covered
                 * by the glob syntax.
                 *
                 * In this case, the slave is perforce the last glob-word -- the
                 * upcoming one is neither glob, nor url, so it's definitely not
                 * the slave.
                 */
                slavei = glob;
        if (slavei) {
                cmdi = slavei + 1;
                if (slavei == 3)
                        masteri = 2;
        } else if (i <= 3) {
                if (!strcmp ((char *)words[wordcount-1], "detail")) {
                        /* For status detail it is mandatory to provide
                         * both master and slave */
                        ret = -1;
                        goto out;
                }

                /* no $s, can only be status cmd
                 * (with either a single $m before it or nothing)
                 * -- these conditions imply that i <= 3 after
                 * the iteration and that i is the successor of
                 * the (0 or 1 length) sequence of $m-s.
                 */
                cmdi = i;
                if (i == 3)
                        masteri = 2;
        } else
                goto out;

        /* now check if input really complies syntax
         * (in a somewhat redundant way, in favor
         * transparent soundness)
         */

        if (masteri && gsyncd_url_check (words[masteri]))
                goto out;
        if (slavei && !glob && !gsyncd_url_check (words[slavei]))
                goto out;

        w = str_getunamb (words[cmdi], opwords);
        if (!w)
                goto out;

        if (strcmp (w, "create") == 0) {
                type = GF_GSYNC_OPTION_TYPE_CREATE;

                if (!masteri || !slavei)
                        goto out;
        } else if (strcmp (w, "status") == 0) {
                type = GF_GSYNC_OPTION_TYPE_STATUS;

                if (slavei && !masteri)
                        goto out;
        } else if (strcmp (w, "config") == 0) {
                type = GF_GSYNC_OPTION_TYPE_CONFIG;

                if (!slavei)
                        goto out;
        } else if (strcmp (w, "start") == 0) {
                type = GF_GSYNC_OPTION_TYPE_START;

                if (!masteri || !slavei)
                        goto out;
        } else if (strcmp (w, "stop") == 0) {
                type = GF_GSYNC_OPTION_TYPE_STOP;

                if (!masteri || !slavei)
                        goto out;
        } else if (strcmp (w, "delete") == 0) {
                type = GF_GSYNC_OPTION_TYPE_DELETE;

                if (!masteri || !slavei)
                        goto out;
        } else if (strcmp (w, "pause") == 0) {
                type = GF_GSYNC_OPTION_TYPE_PAUSE;

                if (!masteri || !slavei)
                        goto out;
        } else if (strcmp (w, "resume") == 0) {
                type = GF_GSYNC_OPTION_TYPE_RESUME;

                if (!masteri || !slavei)
                        goto out;
        } else
                GF_ASSERT (!"opword mismatch");

        ret = force_push_pem_no_verify_parse (words, wordcount, dict, &cmdi);
        if (ret)
                goto out;

        if (!strcmp ((char *)words[wordcount-1], "detail")) {
                if (strcmp ((char *)words[wordcount-2], "status")) {
                        ret = -1;
                        goto out;
                }
                if (!slavei || !masteri) {
                        ret = -1;
                        goto out;
                }
                ret = dict_set_uint32 (dict, "status-detail", _gf_true);
                if (ret)
                        goto out;
                cmdi++;
        }

        if (type != GF_GSYNC_OPTION_TYPE_CONFIG &&
            (cmdi < wordcount - 1 || glob))
                goto out;

        /* If got so far, input is valid, assemble the message */

        ret = 0;

        if (masteri) {
                ret = dict_set_str (dict, "master", (char *)words[masteri]);
                if (!ret)
                        ret = dict_set_str (dict, "volname",
                                            (char *)words[masteri]);
        }
        if (!ret && slavei)
                ret = dict_set_str (dict, "slave", (char *)words[slavei]);
        if (!ret)
                ret = dict_set_int32 (dict, "type", type);
        if (!ret && type == GF_GSYNC_OPTION_TYPE_CONFIG)
                ret = config_parse (words, wordcount, dict, cmdi, glob);

out:
        if (ret) {
                if (dict)
                        dict_destroy (dict);
        } else
                *options = dict;


        return ret;
}

int32_t
cli_cmd_volume_profile_parse (const char **words, int wordcount,
                              dict_t **options)
{
        dict_t              *dict       = NULL;
        char                *volname    = NULL;
        int                 ret         = -1;
        gf1_cli_stats_op    op          = GF_CLI_STATS_NONE;
        gf1_cli_info_op     info_op     = GF_CLI_INFO_NONE;
        gf_boolean_t        is_peek     = _gf_false;

        char      *opwords[] = { "start", "stop", "info", NULL };
        char      *w = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();
        if (!dict)
                goto out;

        if (wordcount < 4)
                goto out;

        volname = (char *)words[2];

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        w = str_getunamb (words[3], opwords);
        if (!w) {
                ret = -1;
                goto out;
        }

        if ((strcmp (w, "start") == 0 || strcmp (w, "stop") == 0) &&
            wordcount > 5)
                goto out;

        if (strcmp (w, "info") == 0 && wordcount > 7)
                goto out;

        if (strcmp (w, "start") == 0) {
                op = GF_CLI_STATS_START;
        } else if (strcmp (w, "stop") == 0) {
                op = GF_CLI_STATS_STOP;
        } else if (strcmp (w, "info") == 0) {
                op = GF_CLI_STATS_INFO;
                info_op = GF_CLI_INFO_ALL;
                if (wordcount > 4) {
                        if (strcmp (words[4], "incremental") == 0) {
                                info_op = GF_CLI_INFO_INCREMENTAL;
                                if (wordcount > 5 &&
                                    strcmp (words[5], "peek") == 0) {
                                        is_peek = _gf_true;
                                }
                        } else if (strcmp (words[4], "cumulative") == 0) {
                                info_op = GF_CLI_INFO_CUMULATIVE;
                        } else if (strcmp (words[4], "clear") == 0) {
                                info_op = GF_CLI_INFO_CLEAR;
                        } else if (strcmp (words[4], "peek") == 0) {
                                is_peek = _gf_true;
                        }
                }
        } else
                GF_ASSERT (!"opword mismatch");

        ret = dict_set_int32 (dict, "op", (int32_t)op);
        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "info-op", (int32_t)info_op);
        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "peek", is_peek);
        if (ret)
                goto out;

        if (!strcmp (words[wordcount - 1], "nfs")) {
                ret = dict_set_int32 (dict, "nfs", _gf_true);
                if (ret)
                        goto out;
        }

        *options = dict;
out:
        if (ret && dict)
                dict_destroy (dict);
        return ret;
}

int32_t
cli_cmd_volume_top_parse (const char **words, int wordcount,
                              dict_t **options)
{
        dict_t  *dict           = NULL;
        char    *volname        = NULL;
        char    *value          = NULL;
        char    *key            = NULL;
        int      ret            = -1;
        gf1_cli_stats_op op = GF_CLI_STATS_NONE;
        gf1_cli_top_op    top_op = GF_CLI_TOP_NONE;
        int32_t  list_cnt       = -1;
        int      index          = 0;
        int      perf           = 0;
        uint32_t  blk_size      = 0;
        uint32_t  count         = 0;
        gf_boolean_t nfs        = _gf_false;
        char    *delimiter      = NULL;
        char    *opwords[]      = { "open", "read", "write", "opendir",
                                    "readdir", "read-perf", "write-perf",
                                    "clear", NULL };
        char    *w = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();
        if (!dict)
                goto out;

        if (wordcount < 4)
                goto out;

        volname = (char *)words[2];

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        op = GF_CLI_STATS_TOP;
        ret = dict_set_int32 (dict, "op", (int32_t)op);
        if (ret)
                goto out;

        w = str_getunamb (words[3], opwords);
        if (!w) {
                ret = -1;
                goto out;
        }
        if (strcmp (w, "open") == 0) {
                top_op = GF_CLI_TOP_OPEN;
        } else if (strcmp (w, "read") == 0) {
                top_op = GF_CLI_TOP_READ;
        } else if (strcmp (w, "write") == 0) {
                top_op = GF_CLI_TOP_WRITE;
        } else if (strcmp (w, "opendir") == 0) {
                top_op = GF_CLI_TOP_OPENDIR;
        } else if (strcmp (w, "readdir") == 0) {
                top_op = GF_CLI_TOP_READDIR;
        } else if (strcmp (w, "read-perf") == 0) {
                top_op = GF_CLI_TOP_READ_PERF;
                perf = 1;
        } else if (strcmp (w, "write-perf") == 0) {
                top_op = GF_CLI_TOP_WRITE_PERF;
                perf = 1;
        } else if (strcmp (w, "clear") == 0) {
                ret = dict_set_int32 (dict, "clear-stats", 1);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR,
                                "Could not set clear-stats in dict");
                        goto out;
                }
        } else
                GF_ASSERT (!"opword mismatch");
        ret = dict_set_int32 (dict, "top-op", (int32_t)top_op);
        if (ret)
                goto out;

        if ((wordcount > 4) && !strcmp (words[4], "nfs")) {
                nfs = _gf_true;
                ret = dict_set_int32 (dict, "nfs", nfs);
                if (ret)
                        goto out;
                index = 5;
        } else {
                index = 4;
        }

        for (; index < wordcount; index+=2) {

                key = (char *) words[index];
                value = (char *) words[index+1];

                if ( key && !value ) {
                        ret = -1;
                        goto out;
                }
                if (!strcmp (key, "brick")) {
                        delimiter = strchr (value, ':');
                        if (!delimiter || delimiter == value
                            || *(delimiter+1) != '/') {
                                cli_err ("wrong brick type: %s, use <HOSTNAME>:"
                                         "<export-dir-abs-path>", value);
                                ret = -1;
                                goto out;
                        } else {
                                ret = gf_canonicalize_path (delimiter + 1);
                                if (ret)
                                        goto out;
                        }
                        ret = dict_set_str (dict, "brick", value);

                } else if (!strcmp (key, "list-cnt")) {
                        ret = gf_is_str_int (value);
                        if (!ret)
                                list_cnt = atoi (value);
                        if (ret || (list_cnt < 0) || (list_cnt > 100)) {
                                cli_err ("list-cnt should be between 0 to 100");
                                ret = -1;
                                goto out;
                        }
                } else if (perf && !nfs && !strcmp (key, "bs")) {
                        ret = gf_is_str_int (value);
                        if (!ret)
                                blk_size = atoi (value);
                        if (ret || (blk_size <= 0)) {
                                if (blk_size < 0)
                                        cli_err ("block size is an invalid"
                                                 " number");
                                else
                                        cli_err ("block size should be an "
                                                 "integer greater than zero");
                                ret = -1;
                                goto out;
                        }
                        ret = dict_set_uint32 (dict, "blk-size", blk_size);
                } else if (perf && !nfs && !strcmp (key, "count")) {
                        ret = gf_is_str_int (value);
                        if (!ret)
                                count = atoi(value);
                        if (ret || (count <= 0)) {
                                if (count < 0)
                                        cli_err ("count is an invalid number");
                                else
                                        cli_err ("count should be an integer "
                                                 "greater than zero");

                                ret = -1;
                                goto out;
                        }
                        ret = dict_set_uint32 (dict, "blk-cnt", count);
                } else {
                        ret = -1;
                        goto out;
                }
                if (ret) {
                        gf_log ("", GF_LOG_WARNING, "Dict set failed for "
                                "key %s", key);
                        goto out;
                }
        }
        if (list_cnt == -1)
                list_cnt = 100;
        ret = dict_set_int32 (dict, "list-cnt", list_cnt);
        if (ret) {
                gf_log ("", GF_LOG_WARNING, "Dict set failed for list_cnt");
                goto out;
        }

        if ((blk_size > 0) ^ (count > 0)) {
                cli_err ("Need to give both 'bs' and 'count'");
                ret = -1;
                goto out;
        } else if (((uint64_t)blk_size * count) > (10 * GF_UNIT_GB)) {
                cli_err ("'bs * count' value %"PRIu64" is greater than "
                         "maximum allowed value of 10GB",
                         ((uint64_t)blk_size * count));
                ret = -1;
                goto out;
        }

        *options = dict;
out:
        if (ret && dict)
                dict_destroy (dict);
        return ret;
}

uint32_t
cli_cmd_get_statusop (const char *arg)
{
        int        i         = 0;
        uint32_t   ret       = GF_CLI_STATUS_NONE;
        char      *w         = NULL;
        char      *opwords[] = {"detail", "mem", "clients", "fd",
                                "inode", "callpool", "tasks", NULL};
        struct {
                char      *opname;
                uint32_t   opcode;
        } optable[] = {
                { "detail",   GF_CLI_STATUS_DETAIL   },
                { "mem",      GF_CLI_STATUS_MEM      },
                { "clients",  GF_CLI_STATUS_CLIENTS  },
                { "fd",       GF_CLI_STATUS_FD       },
                { "inode",    GF_CLI_STATUS_INODE    },
                { "callpool", GF_CLI_STATUS_CALLPOOL },
                { "tasks",    GF_CLI_STATUS_TASKS    },
                { NULL }
        };

        w = str_getunamb (arg, opwords);
        if (!w) {
                gf_log ("cli", GF_LOG_DEBUG,
                        "Not a status op  %s", arg);
                goto out;
        }

        for (i = 0; optable[i].opname; i++) {
                if (!strcmp (w, optable[i].opname)) {
                        ret = optable[i].opcode;
                        break;
                }
        }

 out:
        return ret;
}

int
cli_cmd_volume_status_parse (const char **words, int wordcount,
                             dict_t **options)
{
        dict_t    *dict            = NULL;
        int        ret             = -1;
        uint32_t   cmd             = 0;

        GF_ASSERT (options);

        dict = dict_new ();
        if (!dict)
                goto out;

        switch (wordcount) {

        case 2:
                cmd = GF_CLI_STATUS_ALL;
                ret = 0;
                break;

        case 3:
                if (!strcmp (words[2], "all")) {
                        cmd = GF_CLI_STATUS_ALL;
                        ret = 0;

                } else {
                        cmd = GF_CLI_STATUS_VOL;
                        ret = dict_set_str (dict, "volname", (char *)words[2]);
                }

                break;

        case 4:
                cmd = cli_cmd_get_statusop (words[3]);

                if (!strcmp (words[2], "all")) {
                        if (cmd == GF_CLI_STATUS_NONE) {
                                cli_err ("%s is not a valid status option",
                                         words[3]);
                                ret = -1;
                                goto out;
                        }
                        cmd |= GF_CLI_STATUS_ALL;
                        ret  = 0;

                } else {
                        ret = dict_set_str (dict, "volname",
                                            (char *)words[2]);
                        if (ret)
                                goto out;

                        if (cmd == GF_CLI_STATUS_NONE) {
                                if (!strcmp (words[3], "nfs")) {
                                        cmd |= GF_CLI_STATUS_NFS;
                                } else if (!strcmp (words[3], "shd")) {
                                        cmd |= GF_CLI_STATUS_SHD;
                                } else if (!strcmp (words[3], "quotad")) {
                                        cmd |= GF_CLI_STATUS_QUOTAD;
                                } else if (!strcmp (words[3], "snapd")) {
                                        cmd |= GF_CLI_STATUS_SNAPD;
                                } else {
                                        cmd = GF_CLI_STATUS_BRICK;
                                        ret = dict_set_str (dict, "brick",
                                                            (char *)words[3]);
                                }

                        } else {
                                cmd |= GF_CLI_STATUS_VOL;
                                ret  = 0;
                        }
                }

                break;

        case 5:
                if (!strcmp (words[2], "all")) {
                        cli_err ("Cannot specify brick/nfs for \"all\"");
                        ret = -1;
                        goto out;
                }

                cmd = cli_cmd_get_statusop (words[4]);
                if (cmd == GF_CLI_STATUS_NONE) {
                        cli_err ("%s is not a valid status option",
                                 words[4]);
                        ret = -1;
                        goto out;
                }


                ret = dict_set_str (dict, "volname", (char *)words[2]);
                if (ret)
                        goto out;

                if (!strcmp (words[3], "nfs")) {
                        if (cmd == GF_CLI_STATUS_FD ||
                            cmd == GF_CLI_STATUS_DETAIL ||
                            cmd == GF_CLI_STATUS_TASKS) {
                                cli_err ("Detail/FD/Tasks status not available"
                                         " for NFS Servers");
                                ret = -1;
                                goto out;
                        }
                        cmd |= GF_CLI_STATUS_NFS;
                } else if (!strcmp (words[3], "shd")){
                        if (cmd == GF_CLI_STATUS_FD ||
                            cmd == GF_CLI_STATUS_CLIENTS ||
                            cmd == GF_CLI_STATUS_DETAIL ||
                            cmd == GF_CLI_STATUS_TASKS) {
                                cli_err ("Detail/FD/Clients/Tasks status not "
                                         "available for Self-heal Daemons");
                                ret = -1;
                                goto out;
                        }
                        cmd |= GF_CLI_STATUS_SHD;
                } else if (!strcmp (words[3], "quotad")) {
                        if (cmd == GF_CLI_STATUS_FD ||
                            cmd == GF_CLI_STATUS_CLIENTS ||
                            cmd == GF_CLI_STATUS_DETAIL ||
                            cmd == GF_CLI_STATUS_INODE) {
                                cli_err ("Detail/FD/Clients/Inode status not "
                                         "available for Quota Daemon");
                                ret = -1;
                                goto out;
                        }
                        cmd |= GF_CLI_STATUS_QUOTAD;
                } else if  (!strcmp (words[3], "snapd")) {
                        if (cmd == GF_CLI_STATUS_FD ||
                            cmd == GF_CLI_STATUS_CLIENTS ||
                            cmd == GF_CLI_STATUS_DETAIL ||
                            cmd == GF_CLI_STATUS_INODE) {
                                cli_err ("Detail/FD/Clients/Inode status not "
                                         "available for snap daemon");
                                ret = -1;
                                goto out;
                        }
                        cmd |= GF_CLI_STATUS_SNAPD;
                } else {
                        if (cmd == GF_CLI_STATUS_TASKS) {
                                cli_err ("Tasks status not available for "
                                         "bricks");
                                ret = -1;
                                goto out;
                        }
                        cmd |= GF_CLI_STATUS_BRICK;
                        ret = dict_set_str (dict, "brick", (char *)words[3]);
                }
                break;

        default:
                goto out;
        }

        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "cmd", cmd);
        if (ret)
                goto out;

        *options = dict;

 out:
        if (ret && dict)
                dict_destroy (dict);

        return ret;
}

gf_boolean_t
cli_cmd_validate_dumpoption (const char *arg, char **option)
{
        char    *opwords[] = {"all", "nfs", "mem", "iobuf", "callpool", "priv",
                              "fd", "inode", "history", "inodectx", "fdctx",
                              "quotad", NULL};
        char    *w = NULL;

        w = str_getunamb (arg, opwords);
        if (!w) {
                gf_log ("cli", GF_LOG_DEBUG, "Unknown statedump option  %s",
                        arg);
                return _gf_false;
        }
        *option = w;
        return _gf_true;
}

int
cli_cmd_volume_statedump_options_parse (const char **words, int wordcount,
                                        dict_t **options)
{
        int     ret = 0;
        int     i = 0;
        dict_t  *dict = NULL;
        int     option_cnt = 0;
        char    *option = NULL;
        char    option_str[100] = {0,};

        for (i = 3; i < wordcount; i++, option_cnt++) {
                if (!cli_cmd_validate_dumpoption (words[i], &option)) {
                        ret = -1;
                        goto out;
                }
                strncat (option_str, option, strlen (option));
                strncat (option_str, " ", 1);
        }
        if((strstr (option_str, "nfs")) && strstr (option_str, "quotad")) {
                ret = -1;
                goto out;
        }

        dict = dict_new ();
        if (!dict)
                goto out;

        ret = dict_set_dynstr (dict, "options", gf_strdup (option_str));
        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "option_cnt", option_cnt);
        if (ret)
                goto out;

        *options = dict;
out:
        if (ret && dict)
                dict_destroy (dict);
        if (ret)
                gf_log ("cli", GF_LOG_ERROR, "Error parsing dumpoptions");
        return ret;
}

int
cli_cmd_volume_clrlks_opts_parse (const char **words, int wordcount,
                                  dict_t **options)
{
        int     ret = -1;
        int     i = 0;
        dict_t  *dict = NULL;
        char    *kind_opts[4] = {"blocked", "granted", "all", NULL};
        char    *types[4] = {"inode", "entry", "posix", NULL};
        char    *free_ptr = NULL;

        dict = dict_new ();
        if (!dict)
                goto out;

        if (strcmp (words[4], "kind"))
                goto out;

        for (i = 0; kind_opts[i]; i++) {
               if (!strcmp (words[5], kind_opts[i])) {
                       free_ptr = gf_strdup (words[5]);
                       ret = dict_set_dynstr (dict, "kind", free_ptr);
                       if (ret)
                               goto out;
                       free_ptr = NULL;
                       break;
               }
        }
        if (i == 3)
                goto out;

        ret = -1;
        for (i = 0; types[i]; i++) {
               if (!strcmp (words[6], types[i])) {
                       free_ptr = gf_strdup (words[6]);
                       ret = dict_set_dynstr (dict, "type", free_ptr);
                       if (ret)
                               goto out;
                       free_ptr = NULL;
                       break;
               }
        }
        if (i == 3)
                goto out;

        if (wordcount == 8) {
                free_ptr = gf_strdup (words[7]);
                ret = dict_set_dynstr (dict, "opts", free_ptr);
                if (ret)
                        goto out;
                free_ptr = NULL;
        }

        ret = 0;
        *options = dict;
out:
       if (ret) {
               GF_FREE (free_ptr);
               dict_unref (dict);
       }

       return ret;
}

static int
extract_hostname_path_from_token (const char *tmp_words, char **hostname,
                                  char **path)
{
        int ret = 0;
        char *delimiter = NULL;
        char *tmp_host = NULL;
        char *host_name = NULL;
        char *words = NULL;

        *hostname = NULL;
        *path = NULL;

        words = GF_CALLOC (1, strlen (tmp_words) + 1, gf_common_mt_char);
        if (!words){
                ret = -1;
                goto out;
        }

        strncpy (words, tmp_words, strlen (tmp_words) + 1);

        if (validate_brick_name (words)) {
                cli_err ("Wrong brick type: %s, use <HOSTNAME>:"
                        "<export-dir-abs-path>", words);
                ret = -1;
                goto out;
        } else {
                delimiter = strrchr (words, ':');
                ret = gf_canonicalize_path (delimiter + 1);
                if (ret) {
                        goto out;
                } else {
                        *path = GF_CALLOC (1, strlen (delimiter+1) +1,
                                           gf_common_mt_char);
                        if (!*path) {
                           ret = -1;
                                goto out;

                        }
                        strncpy (*path, delimiter +1,
                                 strlen(delimiter + 1) + 1);
                }
        }

        tmp_host = gf_strdup (words);
        if (!tmp_host) {
                gf_log ("cli", GF_LOG_ERROR, "Out of memory");
                ret = -1;
                goto out;
        }
        get_host_name (tmp_host, &host_name);
        if (!host_name) {
                ret = -1;
                gf_log("cli",GF_LOG_ERROR, "Unable to allocate "
                        "memory");
                goto out;
        }
        if (!(strcmp (host_name, "localhost") &&
            strcmp (host_name, "127.0.0.1") &&
            strncmp (host_name, "0.", 2))) {
                cli_err ("Please provide a valid hostname/ip other "
                         "than localhost, 127.0.0.1 or loopback "
                         "address (0.0.0.0 to 0.255.255.255).");
                ret = -1;
                goto out;
        }
        if (!valid_internet_address (host_name, _gf_false)) {
                cli_err ("internet address '%s' does not conform to "
                          "standards", host_name);
                ret = -1;
                goto out;
        }

        *hostname = GF_CALLOC (1, strlen (host_name) + 1,
                                       gf_common_mt_char);
        if (!*hostname) {
                ret = -1;
                goto out;
        }
        strncpy (*hostname, host_name, strlen (host_name) + 1);
        ret = 0;

out:
        GF_FREE (words);
        GF_FREE (tmp_host);
        return ret;
}

static int
set_hostname_path_in_dict (const char *token, dict_t *dict, int heal_op)
{
        char *hostname = NULL;
        char *path     = NULL;
        int   ret      = 0;

        ret = extract_hostname_path_from_token (token, &hostname, &path);
        if (ret)
                goto out;

        switch (heal_op) {
        case GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK:
                ret = dict_set_dynstr (dict, "heal-source-hostname",
                                       hostname);
                if (ret)
                        goto out;
                ret = dict_set_dynstr (dict, "heal-source-brickpath",
                                       path);
                break;
        case GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA:
                ret = dict_set_dynstr (dict, "per-replica-cmd-hostname",
                                       hostname);
                if (ret)
                        goto out;
                ret = dict_set_dynstr (dict, "per-replica-cmd-path",
                                       path);
                break;
        default:
                ret = -1;
                break;
        }

out:
        return ret;
}

static int
heal_command_type_get (const char *command)
{
        int     i = 0;
        /* subcommands are set as NULL */
        char    *heal_cmds[GF_SHD_OP_HEAL_DISABLE + 1] = {
                [GF_SHD_OP_INVALID]                            = NULL,
                [GF_SHD_OP_HEAL_INDEX]                         = NULL,
                [GF_SHD_OP_HEAL_FULL]                          = "full",
                [GF_SHD_OP_INDEX_SUMMARY]                      = "info",
                [GF_SHD_OP_HEALED_FILES]                       = NULL,
                [GF_SHD_OP_HEAL_FAILED_FILES]                  = NULL,
                [GF_SHD_OP_SPLIT_BRAIN_FILES]                  = NULL,
                [GF_SHD_OP_STATISTICS]                         = "statistics",
                [GF_SHD_OP_STATISTICS_HEAL_COUNT]              = NULL,
                [GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA]  = NULL,
                [GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE]       = "split-brain",
                [GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK]             = "split-brain",
                [GF_SHD_OP_HEAL_ENABLE]                        = "enable",
                [GF_SHD_OP_HEAL_DISABLE]                       = "disable",
        };

        for (i = 0; i <= GF_SHD_OP_HEAL_DISABLE; i++) {
                if (heal_cmds[i] && (strcmp (heal_cmds[i], command) == 0))
                        return i;
        }

        return GF_SHD_OP_INVALID;
}

int
cli_cmd_volume_heal_options_parse (const char **words, int wordcount,
                                   dict_t **options)
{
        int     ret = 0;
        dict_t  *dict = NULL;
        char    *hostname = NULL;
        char    *path = NULL;
        gf_xl_afr_op_t op = GF_SHD_OP_INVALID;

        dict = dict_new ();
        if (!dict)
                goto out;

        ret = dict_set_str (dict, "volname", (char *) words[2]);
        if (ret) {
                gf_log (THIS->name, GF_LOG_ERROR, "failed to set volname");
                goto out;
        }

        if (wordcount == 3) {
                ret = dict_set_int32 (dict, "heal-op", GF_SHD_OP_HEAL_INDEX);
                goto done;
        }

        if (wordcount == 4) {
                op = heal_command_type_get (words[3]);
                if (op == GF_SHD_OP_INVALID) {
                        ret = -1;
                        goto out;
                }

                ret = dict_set_int32 (dict, "heal-op", op);
                goto done;
        }

        if (wordcount == 5) {
                if (strcmp (words[3], "info") &&
                    strcmp (words[3], "statistics")) {
                        ret = -1;
                        goto out;
                }

                if (!strcmp (words[3], "info")) {
                        if (!strcmp (words[4], "healed")) {
                                ret = dict_set_int32 (dict, "heal-op",
                                                      GF_SHD_OP_HEALED_FILES);
                                goto done;
                        }
                        if (!strcmp (words[4], "heal-failed")) {
                                ret = dict_set_int32 (dict, "heal-op",
                                                   GF_SHD_OP_HEAL_FAILED_FILES);
                                goto done;
                        }
                        if (!strcmp (words[4], "split-brain")) {
                                ret = dict_set_int32 (dict, "heal-op",
                                                   GF_SHD_OP_SPLIT_BRAIN_FILES);
                                goto done;
                        }
                }

                if (!strcmp (words[3], "statistics")) {
                        if (!strcmp (words[4], "heal-count")) {
                                ret = dict_set_int32 (dict, "heal-op",
                                               GF_SHD_OP_STATISTICS_HEAL_COUNT);
                                goto done;
                        }
                }
                ret = -1;
                goto out;
        }
        if (wordcount == 6) {
                if (strcmp (words[3], "split-brain")) {
                        ret = -1;
                        goto out;
                }
                if (!strcmp (words[4], "bigger-file")) {
                        ret = dict_set_int32 (dict, "heal-op",
                                        GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE);
                        if (ret)
                                goto out;
                        ret = dict_set_str (dict, "file", (char *)words[5]);
                        if (ret)
                                goto out;
                        goto done;
                }
                if (!strcmp (words[4], "source-brick")) {
                        ret = dict_set_int32 (dict, "heal-op",
                                              GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK);
                        if (ret)
                                goto out;
                        ret = set_hostname_path_in_dict (words[5], dict,
                                              GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK);
                        if (ret)
                                goto out;
                        goto done;
                }
                ret = -1;
                goto out;
        }
        if (wordcount == 7) {
                if (!strcmp (words[3], "statistics")
                    && !strcmp (words[4], "heal-count")
                    && !strcmp (words[5], "replica")) {

                        ret = dict_set_int32 (dict, "heal-op",
                                   GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA);
                        if (ret)
                                goto out;
                        ret = set_hostname_path_in_dict (words[6], dict,
                                   GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA);
                        if (ret)
                                goto out;
                        goto done;

                }
                if (!strcmp (words[3], "split-brain") &&
                    !strcmp (words[4], "source-brick")) {
                        ret = dict_set_int32 (dict, "heal-op",
                                              GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK);
                        ret = set_hostname_path_in_dict (words[5], dict,
                                              GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK);
                        if (ret)
                                goto out;
                        ret = dict_set_str (dict, "file",
                                            (char *) words[6]);
                        if (ret)
                                goto out;
                        goto done;
                }
        }
        ret = -1;
        goto out;
done:
        *options = dict;
out:
        if (ret && dict) {
                dict_unref (dict);
                *options = NULL;
        }

        return ret;
}

int
cli_cmd_volume_defrag_parse (const char **words, int wordcount,
                             dict_t **options)
{
        dict_t                 *dict = NULL;
        int                      ret = -1;
        char                *option  = NULL;
        char                *volname = NULL;
        char                *command = NULL;
        gf_cli_defrag_type       cmd = 0;

        GF_ASSERT (words);
        GF_ASSERT (options);

        dict = dict_new ();
        if (!dict)
                goto out;

        if (!((wordcount == 4) || (wordcount == 5)))
                goto out;

        if (wordcount == 4) {
                if (strcmp (words[3], "start") && strcmp (words[3], "stop") &&
                    strcmp (words[3], "status"))
                            goto out;
        } else {
                if (strcmp (words[3], "fix-layout") &&
                    strcmp (words[3], "start"))
                        goto out;
        }

        volname = (char *) words[2];

        if (wordcount == 4) {
                command = (char *) words[3];
        }
        if (wordcount == 5) {
               if ((strcmp (words[3], "fix-layout") ||
                    strcmp (words[4], "start")) &&
                    (strcmp (words[3], "start") ||
                    strcmp (words[4], "force"))) {
                        ret = -1;
                        goto out;
                }
                command = (char *) words[3];
                option = (char *) words[4];
        }

        if (strcmp (command, "start") == 0) {
                cmd = GF_DEFRAG_CMD_START;
                if (option && strcmp (option, "force") == 0) {
                                cmd = GF_DEFRAG_CMD_START_FORCE;
                        }
                goto done;
        }

        if (strcmp (command, "fix-layout") == 0) {
                cmd = GF_DEFRAG_CMD_START_LAYOUT_FIX;
                goto done;
        }
        if (strcmp (command, "stop") == 0) {
                cmd = GF_DEFRAG_CMD_STOP;
                goto done;
        }
        if (strcmp (command, "status") == 0) {
                cmd = GF_DEFRAG_CMD_STATUS;
        }

done:
        ret = dict_set_str (dict, "volname", volname);

        if (ret) {
                gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict");
                goto out;
        }

        ret = dict_set_int32 (dict, "rebalance-command", (int32_t) cmd);

        if (ret) {
                gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict");
                goto out;
        }

        *options = dict;

out:
        if (ret && dict)
                dict_destroy (dict);

        return ret;
}

int32_t
cli_snap_create_desc_parse (dict_t *dict, const char **words,
                            size_t wordcount, int32_t desc_opt_loc)
{
        int32_t        ret      = -1;
        char          *desc     = NULL;
        int32_t        desc_len = 0;

        desc = GF_CALLOC (MAX_SNAP_DESCRIPTION_LEN + 1, sizeof(char),
                          gf_common_mt_char);
        if (!desc) {
                ret = -1;
                goto out;
        }


        if (strlen (words[desc_opt_loc]) >= MAX_SNAP_DESCRIPTION_LEN) {
                cli_out ("snapshot create: description truncated: "
                         "Description provided is longer than 1024 characters");
                desc_len = MAX_SNAP_DESCRIPTION_LEN;
        } else {
                desc_len = strlen (words[desc_opt_loc]);
        }

        strncpy (desc, words[desc_opt_loc], desc_len);
        desc[desc_len] = '\0';
        /* Calculating the size of the description as given by the user */

        ret = dict_set_dynstr (dict, "description", desc);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to save snap "
                        "description");
                goto out;
        }

        ret = 0;
out:
        if (ret && desc)
                GF_FREE (desc);

        return ret;
}

/* Function to check whether the Volume name is repeated */
int
cli_check_if_volname_repeated (const char **words, unsigned int start_index,
                           uint64_t cur_index) {
        uint64_t        i       =       -1;
        int             ret     =        0;

        GF_ASSERT (words);

        for (i = start_index ; i < cur_index ; i++) {
                if (strcmp (words[i], words[cur_index]) == 0) {
                        ret = -1;
                        goto out;
                }
        }
out:
        return ret;
}

/* snapshot clone <clonename> <snapname>
 * @arg-0, dict     : Request Dictionary to be sent to server side.
 * @arg-1, words    : Contains individual words of CLI command.
 * @arg-2, wordcount: Contains number of words present in the CLI command.
 *
 * return value : -1 on failure
 *                 0 on success
 */
int
cli_snap_clone_parse (dict_t *dict, const char **words, int wordcount) {
        uint64_t        i               =       0;
        int             ret             =       -1;
        char            key[PATH_MAX]   =       "";
        char            *clonename      =       NULL;
        unsigned int    cmdi            =       2;
        int             flags           =       0;
        /* cmdi is command index, here cmdi is "2" (gluster snapshot clone)*/

        GF_ASSERT (words);
        GF_ASSERT (dict);

        if (wordcount == cmdi + 1) {
                cli_err ("Invalid Syntax.");
                gf_log ("cli", GF_LOG_ERROR,
                        "Invalid number of  words for snap clone command");
                goto out;
        }

        if (strlen(words[cmdi]) >= GLUSTERD_MAX_SNAP_NAME) {
                cli_err ("snapshot clone: failed: clonename cannot exceed "
                         "255 characters.");
                gf_log ("cli", GF_LOG_ERROR, "Clone name too long");

                goto out;
        }

        clonename = (char *) words[cmdi];
        for (i = 0 ; i < strlen (clonename); i++) {
                /* Following volume name convention */
                if (!isalnum (clonename[i]) && (clonename[i] != '_'
                                           && (clonename[i] != '-'))) {
                        /* TODO : Is this message enough?? */
                        cli_err ("Clonename can contain only alphanumeric, "
                                 "\"-\" and \"_\" characters");
                        goto out;
                }
        }

        ret = dict_set_int32 (dict, "volcount", 1);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Could not save volcount");
                goto out;
        }

        ret = dict_set_str (dict, "clonename", (char *)words[cmdi]);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Could not save clone "
                        "name(%s)", (char *)words[cmdi]);
                goto out;
        }

        /* Filling snap name in the dictionary */
        ret = dict_set_str (dict, "snapname", (char *)words[cmdi+1]);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Could not "
                        "save snap name(%s)", (char *)words[cmdi+1]);
                goto out;
        }


        ret = 0;

out:
        return ret;
}


/* snapshot create <snapname> <vol-name(s)> [description <description>]
 *                                           [force]
 * @arg-0, dict     : Request Dictionary to be sent to server side.
 * @arg-1, words    : Contains individual words of CLI command.
 * @arg-2, wordcount: Contains number of words present in the CLI command.
 *
 * return value : -1 on failure
 *                 0 on success
 */
int
cli_snap_create_parse (dict_t *dict, const char **words, int wordcount) {
        uint64_t        i               =       0;
        int             ret             =       -1;
        uint64_t        volcount        =       0;
        char            key[PATH_MAX]   =       "";
        char            *snapname       =       NULL;
        unsigned int    cmdi            =       2;
        int             flags           =       0;
        /* cmdi is command index, here cmdi is "2" (gluster snapshot create)*/

        GF_ASSERT (words);
        GF_ASSERT (dict);

        if (wordcount <= cmdi + 1) {
                cli_err ("Invalid Syntax.");
                gf_log ("cli", GF_LOG_ERROR,
                        "Too less words for snap create command");
                goto out;
        }

        if (strlen(words[cmdi]) >= GLUSTERD_MAX_SNAP_NAME) {
                cli_err ("snapshot create: failed: snapname cannot exceed "
                         "255 characters.");
                gf_log ("cli", GF_LOG_ERROR, "Snapname too long");

                goto out;
        }

        snapname = (char *) words[cmdi];
        for (i = 0 ; i < strlen (snapname); i++) {
                /* Following volume name convention */
                if (!isalnum (snapname[i]) && (snapname[i] != '_'
                                           && (snapname[i] != '-'))) {
                        /* TODO : Is this message enough?? */
                        cli_err ("Snapname can contain only alphanumeric, "
                                 "\"-\" and \"_\" characters");
                        goto out;
                }
        }

        ret = dict_set_str (dict, "snapname", (char *)words[cmdi]);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Could not save snap "
                        "name(%s)", (char *)words[cmdi]);
                goto out;
        }

        /* Filling volume name in the dictionary */
        for (i = cmdi + 1 ; i < wordcount
                            && (strcmp (words[i], "description")) != 0
                            && (strcmp (words[i], "force") != 0)
                            && (strcmp (words[i], "no-timestamp") != 0);
                            i++) {
                volcount++;
                /* volume index starts from 1 */
                ret = snprintf (key, sizeof (key), "volname%"PRIu64, volcount);
                if (ret < 0) {
                        goto out;
                }

                ret = dict_set_str (dict, key, (char *)words[i]);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Could not "
                                "save volume name(%s)", (char *)words[i]);
                        goto out;
                }

                if (i >= cmdi + 2) {
                        ret = -1;
                        cli_err("Creating multiple volume snapshot is not "
                                "supported as of now");
                        goto out;
                }
                /* TODO : remove this above condition check once
                 * multiple volume snapshot is supported */
        }

        if (volcount == 0) {
                ret = -1;
                cli_err ("Please provide the volume name");
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        ret = dict_set_int32 (dict, "volcount", volcount);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Could not save volcount");
                goto out;
        }

        /* Verify how we got out of "for" loop,
         * if it is by reaching wordcount limit then goto "out",
         * because we need not parse for "description","force" and
         * "no-timestamp" after this.
         */
        if (i == wordcount) {
                goto out;
        }

        if (strcmp (words[i], "no-timestamp") == 0) {
                ret = dict_set_str (dict, "no-timestamp", "true");
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Could not save "
                                "time-stamp option");
                }
                if (i == (wordcount-1))
                        goto out;
                i++;
        }

        if ((strcmp (words[i], "description")) == 0) {
                ++i;
                if (i > (wordcount - 1)) {
                        ret = -1;
                        cli_err ("Please provide a description");
                        gf_log ("cli", GF_LOG_ERROR,
                                "Description not provided");
                        goto out;
                }

                ret = cli_snap_create_desc_parse(dict, words, wordcount, i);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Could not save snap "
                                "description");
                        goto out;
                }

                if (i == (wordcount - 1))
                        goto out;
                i++;
                /* point the index to next word.
                 * As description might be follwed by force option.
                 * Before that, check if wordcount limit is reached
                 */
        }

        if (strcmp (words[i], "force") == 0) {
                flags = GF_CLI_FLAG_OP_FORCE;

        } else {
                ret = -1;
                cli_err ("Invalid Syntax.");
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        /* Check if the command has anything after "force" keyword */
        if (++i < wordcount) {
                ret = -1;
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        ret = 0;

out:
        if(ret == 0) {
                /*Adding force flag in either of the case i.e force set
                 * or unset*/
                ret = dict_set_int32 (dict, "flags", flags);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Could not save "
                                "snap force option");
                }
        }
        return ret;
}

/* snapshot list [volname]
 * @arg-0, dict     : Request Dictionary to be sent to server side.
 * @arg-1, words    : Contains individual words of CLI command.
 * @arg-2, wordcount: Contains number of words present in the CLI command.
 *
 * return value : -1 on failure
 *                 0 on success
 */
int
cli_snap_list_parse (dict_t *dict, const char **words, int wordcount) {
        int             ret     =       -1;

        GF_ASSERT (words);
        GF_ASSERT (dict);

        if (wordcount < 2 || wordcount > 3) {
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        if (wordcount == 2) {
                ret = 0;
                goto out;
        }

        ret = dict_set_str (dict, "volname", (char *)words[2]);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR,
                        "Failed to save volname in dictionary");
                goto out;
        }
out:
        return ret;
}

/* snapshot info [(snapname |  volume <volname>)]
 * @arg-0, dict     : Request Dictionary to be sent to server side.
 * @arg-1, words    : Contains individual words of CLI command.
 * @arg-2, wordcount: Contains number of words present in the CLI command.
 *
 * return value : -1 on failure
 *                 0 on success
 */
int
cli_snap_info_parse (dict_t *dict, const char **words, int wordcount)
{

        int             ret             =       -1;
        int32_t         cmd             =       GF_SNAP_INFO_TYPE_ALL;
        unsigned int    cmdi            =        2;
        /* cmdi is command index, here cmdi is "2" (gluster snapshot info)*/

        GF_ASSERT (words);
        GF_ASSERT (dict);

        if (wordcount > 4 || wordcount < cmdi) {
                gf_log ("cli", GF_LOG_ERROR, "Invalid syntax");
                goto out;
        }

        if (wordcount == cmdi) {
                ret = 0;
                goto out;
        }

        /* If 3rd word is not "volume", then it must
         * be snapname.
         */
        if (strcmp (words[cmdi], "volume") != 0) {
                ret = dict_set_str (dict, "snapname",
                                   (char *)words[cmdi]);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Unable to save "
                                "snapname %s", words[cmdi]);
                        goto out;
                }

                /* Once snap name is parsed, if we encounter any other
                 * word then fail it. Invalid Syntax.
                 * example : snapshot info <snapname> word
                 */
                if ((cmdi + 1) != wordcount) {
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }

                cmd = GF_SNAP_INFO_TYPE_SNAP;
                ret = 0;
                goto out;
                /* No need to continue the parsing once we
                 * get the snapname
                 */
        }

        /* If 3rd word is "volume", then check if next word
         * is present. As, "snapshot info volume" is an
         * invalid command.
         */
        if ((cmdi + 1) == wordcount) {
                ret = -1;
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        ret = dict_set_str (dict, "volname", (char *)words[wordcount - 1]);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Could not save "
                        "volume name %s", words[wordcount - 1]);
                goto out;
        }
        cmd = GF_SNAP_INFO_TYPE_VOL;
out:
        if (ret == 0) {
                ret = dict_set_int32 (dict, "cmd", cmd);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Could not save "
                                "type of snapshot info");
                }
        }
        return ret;
}



/* snapshot restore <snapname>
 * @arg-0, dict     : Request Dictionary to be sent to server side.
 * @arg-1, words    : Contains individual words of CLI command.
 * @arg-2, wordcount: Contains number of words present in the CLI command.
 *
 * return value : -1 on failure
 *                 0 on success
 */
int
cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount,
                        struct cli_state *state)
{

        int             ret             =       -1;
        const char      *question       =       NULL;
        gf_answer_t     answer          =       GF_ANSWER_NO;

        GF_ASSERT (words);
        GF_ASSERT (dict);

        if (wordcount != 3) {
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        ret = dict_set_str (dict, "snapname", (char *)words[2]);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s",
                        words[2]);
                goto out;
        }

        question = "Restore operation will replace the "
                   "original volume with the snapshotted volume. "
                   "Do you still want to continue?";

        answer = cli_cmd_get_confirmation (state, question);
        if (GF_ANSWER_NO == answer) {
                ret = 1;
                gf_log ("cli", GF_LOG_ERROR, "User cancelled a snapshot "
                        "restore operation for snap %s", (char *)words[2]);
                goto out;
        }
out:
        return ret;
}

/* snapshot activate <snapname> [force]
 * @arg-0, dict     : Request Dictionary to be sent to server side.
 * @arg-1, words    : Contains individual words of CLI command.
 * @arg-2, wordcount: Contains number of words present in the CLI command.
 *
 * return value : -1 on failure
 *                 0 on success
 */
int
cli_snap_activate_parse (dict_t *dict, const char **words, int wordcount)
{

        int ret = -1;
        int flags = 0;

        GF_ASSERT (words);
        GF_ASSERT (dict);

        if ((wordcount < 3) || (wordcount > 4)) {
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        ret = dict_set_str (dict, "snapname", (char *)words[2]);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s",
                        words[2]);
                goto out;
        }

        if (wordcount == 4) {
                if (!strcmp("force", (char *)words[3])) {
                        flags = GF_CLI_FLAG_OP_FORCE;
                } else {
                        gf_log ("cli", GF_LOG_ERROR, "Invalid option");
                        ret = -1;
                        goto out;
                }
        }
        ret = dict_set_int32 (dict, "flags", flags);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to save force option");
                goto out;
        }
out:
        return ret;
}

/* snapshot deactivate <snapname>
 * @arg-0, dict     : Request Dictionary to be sent to server side.
 * @arg-1, words    : Contains individual words of CLI command.
 * @arg-2, wordcount: Contains number of words present in the CLI command.
 *
 * return value : -1 on failure
 *                 0 on success
 *                 1 if user cancelled the request
 */
int
cli_snap_deactivate_parse (dict_t *dict, const char **words, int wordcount,
                        struct cli_state *state)
{

        int             ret             = -1;
        gf_answer_t     answer          = GF_ANSWER_NO;
        const char     *question        = "Deactivating snap will make its "
                                          "data inaccessible. Do you want to "
                                          "continue?";


        GF_ASSERT (words);
        GF_ASSERT (dict);

        if ((wordcount != 3)) {
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        ret = dict_set_str (dict, "snapname", (char *)words[2]);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s",
                        words[2]);
                goto out;
        }

        answer = cli_cmd_get_confirmation (state, question);
        if (GF_ANSWER_NO == answer) {
                ret = 1;
                gf_log ("cli", GF_LOG_DEBUG, "User cancelled "
                        "snapshot deactivate operation");
                goto out;
        }

out:
        return ret;
}

/* snapshot delete (all | snapname | volume <volname>)
 * @arg-0, dict     : Request Dictionary to be sent to server side.
 * @arg-1, words    : Contains individual words of CLI command.
 * @arg-2, wordcount: Contains number of words present in the CLI command.
 *
 * return value : -1 on failure
 *                 0 on success
 *                 1 if user cancel the operation
 */
int
cli_snap_delete_parse (dict_t *dict, const char **words, int wordcount,
                       struct cli_state *state) {

        int             ret             =       -1;
        const char      *question       =       NULL;
        int32_t         cmd             =       -1;
        unsigned int    cmdi            =       2;
        gf_answer_t     answer          =       GF_ANSWER_NO;

        GF_ASSERT (words);
        GF_ASSERT (dict);

        if (wordcount > 4 || wordcount <= cmdi) {
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        question = "Deleting snap will erase all the information about "
                   "the snap. Do you still want to continue?";

        if (strcmp (words [cmdi], "all") == 0) {
                ret = 0;
                cmd = GF_SNAP_DELETE_TYPE_ALL;
        } else if (strcmp (words [cmdi], "volume") == 0) {
                if (++cmdi == wordcount) {
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }

                ret = dict_set_str (dict, "volname",
                                    (char *)words[cmdi]);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Could not save "
                                "volume name %s", words[wordcount - 1]);
                        goto out;
                }
                cmd = GF_SNAP_DELETE_TYPE_VOL;
        } else {
                ret = dict_set_str (dict, "snapname", (char *)words[cmdi]);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Unable to save "
                                "snapname %s", words[2]);
                        goto out;
                }
                cmd = GF_SNAP_DELETE_TYPE_SNAP;
        }

        if ((cmdi + 1) != wordcount) {
                ret = -1;
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        if (cmd == GF_SNAP_DELETE_TYPE_SNAP) {
                answer = cli_cmd_get_confirmation (state, question);
                if (GF_ANSWER_NO == answer) {
                        ret = 1;
                        gf_log ("cli", GF_LOG_DEBUG, "User cancelled "
                                "snapshot delete operation for snap %s",
                                (char *)words[2]);
                        goto out;
                }
        }

        ret = dict_set_int32 (dict, "delete-cmd", cmd);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Could not save "
                        "type of snapshot delete");
        }
out:
        return ret;
}

/* snapshot status [(snapname | volume <volname>)]
 * @arg-0, dict     : Request Dictionary to be sent to server side.
 * @arg-1, words    : Contains individual words of CLI command.
 * @arg-2, wordcount: Contains number of words present in the CLI command.
 *
 * return value : -1 on failure
 *                 0 on success
 */
int
cli_snap_status_parse (dict_t *dict, const char **words, int wordcount)
{

        int             ret  =        -1;
        int32_t         cmd  =       GF_SNAP_STATUS_TYPE_ALL;
        unsigned int    cmdi =        2;
        /* cmdi is command index, here cmdi is "2" (gluster snapshot status)*/

        GF_ASSERT (words);
        GF_ASSERT (dict);

        if (wordcount > 4 || wordcount < cmdi) {
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        if (wordcount == cmdi) {
                ret = 0;
                goto out;
        }

        /* if 3rd word is not "volume", then it must be "snapname"
        */
        if (strcmp (words[cmdi], "volume") != 0) {
                ret = dict_set_str (dict, "snapname",
                                   (char *)words[cmdi]);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Count not save "
                                "snap name %s", words[cmdi]);
                        goto out;
                }

                if ((cmdi + 1) != wordcount) {
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }

                ret = 0;
                cmd = GF_SNAP_STATUS_TYPE_SNAP;
                goto out;
        }

        /* If 3rd word is "volume", then check if next word is present.
         * As, "snapshot info volume" is an invalid command
         */
        if ((cmdi + 1) == wordcount) {
                ret = -1;
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        ret = dict_set_str (dict, "volname", (char *)words [wordcount - 1]);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Count not save "
                        "volume name %s", words[wordcount - 1]);
                goto out;
        }
        cmd = GF_SNAP_STATUS_TYPE_VOL;

out:
        if (ret == 0) {
                ret = dict_set_int32 (dict, "status-cmd", cmd);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Could not save cmd "
                                "of snapshot status");
                }
        }

        return ret;
}


/* return value:
 *      -1  in case of failure.
 *       0  in case of success.
 */
int32_t
cli_snap_config_limit_parse (const char **words, dict_t *dict,
                             unsigned int wordcount, unsigned int index,
                             char *key)
{
        int             ret             = -1;
        int             limit           = 0;
        char            *end_ptr        = NULL;

        GF_ASSERT (words);
        GF_ASSERT (dict);
        GF_ASSERT (key);

        if (index >= wordcount) {
                ret = -1;
                cli_err ("Please provide a value for %s.", key);
                gf_log ("cli", GF_LOG_ERROR, "Value not provided for %s", key);
                goto out;
        }

        limit = strtol (words[index], &end_ptr, 10);

        if (limit <= 0 || strcmp (end_ptr, "") != 0) {
                ret = -1;
                cli_err("Please enter an integer value "
                        "greater than zero for %s", key);
                goto out;
        }

        ret = dict_set_int32 (dict, key, limit);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Could not set "
                        "%s in dictionary", key);
                goto out;
        }

out:
        return ret;
}

/* function cli_snap_config_parse
 * Config Syntax : gluster snapshot config [volname]
 *                                         [snap-max-hard-limit <count>]
 *                                         [snap-max-soft-limit <count>]
 *
   return value: <0  on failure
                  1  if user cancels the operation, or limit value is out of
                                                                      range
                  0  on success

  NOTE : snap-max-soft-limit can only be set for system.
*/
int32_t
cli_snap_config_parse (const char **words, int wordcount, dict_t *dict,
                       struct cli_state *state)
{
        int                            ret                 = -1;
        gf_answer_t                    answer              = GF_ANSWER_NO;
        gf_boolean_t                   vol_presence        = _gf_false;
        struct snap_config_opt_vals_  *conf_vals           = NULL;
        int8_t                         hard_limit          = 0;
        int8_t                         soft_limit          = 0;
        int8_t                         config_type         = -1;
        const char                    *question            = NULL;
        unsigned int                   cmdi                = 2;
        /* cmdi is command index, here cmdi is "2" (gluster snapshot config)*/

        GF_ASSERT (words);
        GF_ASSERT (dict);
        GF_ASSERT (state);

        if ((wordcount < 2) || (wordcount > 7)) {
                gf_log ("cli", GF_LOG_ERROR,
                        "Invalid wordcount(%d)", wordcount);
                goto out;
        }

        if (wordcount == 2) {
                config_type = GF_SNAP_CONFIG_DISPLAY;
                ret = 0;
                goto set;
        }

        /* auto-delete cannot be a volume name */
        /* Check whether the 3rd word is volname */
        if (strcmp (words[cmdi], "snap-max-hard-limit") != 0
             && strcmp (words[cmdi], "snap-max-soft-limit") != 0
             && strcmp (words[cmdi], "auto-delete") != 0
             && strcmp (words[cmdi], "activate-on-create") != 0) {
                ret = dict_set_str (dict, "volname", (char *)words[cmdi]);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Failed to set volname");
                        goto out;
                }
                cmdi++;
                vol_presence = _gf_true;

                if (cmdi == wordcount) {
                        config_type = GF_SNAP_CONFIG_DISPLAY;
                        ret = 0;
                        goto set;
                }
        }

        config_type = GF_SNAP_CONFIG_TYPE_SET;

        if (strcmp (words[cmdi], "snap-max-hard-limit") == 0) {
                ret = cli_snap_config_limit_parse (words, dict, wordcount,
                                                ++cmdi, "snap-max-hard-limit");
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Failed to parse snap "
                                "config hard limit");
                        goto out;
                }
                hard_limit = 1;

                if (++cmdi == wordcount) {
                        ret = 0;
                        goto set;
                }
        }

        if (strcmp (words[cmdi], "snap-max-soft-limit") == 0) {
                if (vol_presence == 1) {
                        ret = -1;
                        cli_err ("Soft limit cannot be set to individual "
                                  "volumes.");
                        gf_log ("cli", GF_LOG_ERROR, "Soft limit cannot be "
                                "set to volumes");
                        goto out;
                }

                ret = cli_snap_config_limit_parse (words, dict, wordcount,
                                                ++cmdi, "snap-max-soft-limit");
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Failed to parse snap "
                                "config soft limit");
                        goto out;
                }

                if (++cmdi != wordcount) {
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }
                soft_limit = 1;
        }

        if (hard_limit || soft_limit)
                goto set;

        if (strcmp(words[cmdi], "auto-delete") == 0) {
                if (vol_presence == 1) {
                        ret = -1;
                        cli_err ("As of now, auto-delete option cannot be set "
                                "to volumes");
                        gf_log ("cli", GF_LOG_ERROR, "auto-delete option "
                                "cannot be set to volumes");
                        goto out;
                }

                if (++cmdi >= wordcount) {
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }

                ret = dict_set_str (dict, "auto-delete", (char *)words[cmdi]);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Failed to set "
                                "value of auto-delete in request "
                                "dictionary");
                        goto out;
                }

                if (++cmdi != wordcount) {
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }
        } else if (strcmp(words[cmdi], "activate-on-create") == 0) {
                if (vol_presence == 1) {
                        ret = -1;
                        cli_err ("As of now, activate-on-create option "
                                 "cannot be set to volumes");
                        gf_log ("cli", GF_LOG_ERROR, "activate-on-create "
                                "option cannot be set to volumes");
                        goto out;
                }

                if (++cmdi >= wordcount) {
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }

                ret = dict_set_str (dict, "snap-activate-on-create",
                                    (char *)words[cmdi]);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Failed to set value "
                                "of activate-on-create in request dictionary");
                        goto out;
                }

                if (++cmdi != wordcount) {
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }
        } else {
                ret = -1;
                gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                goto out;
        }

        ret = 0; /* Success */

set:
        ret = dict_set_int32 (dict, "config-command", config_type);
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to set "
                        "config-command");
                goto out;
        }

        if (config_type == GF_SNAP_CONFIG_TYPE_SET &&
           (hard_limit || soft_limit)) {
                conf_vals = snap_confopt_vals;
                if (hard_limit && soft_limit) {
                        question = conf_vals[GF_SNAP_CONFIG_SET_BOTH].question;
                } else if (soft_limit) {
                        question = conf_vals[GF_SNAP_CONFIG_SET_SOFT].question;
                } else if (hard_limit) {
                        question = conf_vals[GF_SNAP_CONFIG_SET_HARD].question;
                }

                answer = cli_cmd_get_confirmation (state, question);
                if (GF_ANSWER_NO == answer) {
                        ret = 1;
                        gf_log ("cli", GF_LOG_DEBUG, "User cancelled "
                        "snapshot config operation");
                }
        }

out:
        return ret;
}

int
validate_op_name (const char *op, const char *opname, char **opwords) {
        int     ret     =       -1;
        int     i       =       0;

        GF_ASSERT (opname);
        GF_ASSERT (opwords);

        for (i = 0 ; opwords[i] != NULL; i++) {
                if (strcmp (opwords[i], opname) == 0) {
                        cli_out ("\"%s\" cannot be a %s", opname, op);
                        goto out;
                }
        }
        ret = 0;
out:
        return ret;
}

int32_t
cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
                        struct cli_state *state)
{
        int32_t            ret        = -1;
        dict_t             *dict      = NULL;
        gf1_cli_snapshot   type       = GF_SNAP_OPTION_TYPE_NONE;
        char               *w         = NULL;
        char               *opwords[] = {"create", "delete", "restore",
                                        "activate", "deactivate", "list",
                                        "status", "config", "info", "clone",
                                        NULL};
        char               *invalid_snapnames[] = {"description", "force",
                                                  "volume", "all", NULL};
        char               *invalid_volnames[]  = {"volume", "type",
                                                   "subvolumes", "option",
                                                   "end-volume", "all",
                                                   "volume_not_in_ring",
                                                   "description", "force",
                                                   "snap-max-hard-limit",
                                                   "snap-max-soft-limit",
                                                   "auto-delete",
                                                   "activate-on-create", NULL};

        GF_ASSERT (words);
        GF_ASSERT (options);
        GF_ASSERT (state);

        dict = dict_new ();
        if (!dict)
                goto out;

        /* Lowest wordcount possible */
        if (wordcount < 2) {
                gf_log ("", GF_LOG_ERROR,
                        "Invalid command: Not enough arguments");
                goto out;
        }

        w = str_getunamb (words[1], opwords);
        if (!w) {
                /* Checks if the operation is a valid operation */
                gf_log ("", GF_LOG_ERROR, "Opword Mismatch");
                goto out;
        }

        if (!strcmp (w, "create")) {
                type = GF_SNAP_OPTION_TYPE_CREATE;
        } else if (!strcmp (w, "list")) {
                type = GF_SNAP_OPTION_TYPE_LIST;
        } else if (!strcmp (w, "info")) {
                type = GF_SNAP_OPTION_TYPE_INFO;
        } else if (!strcmp (w, "delete")) {
                type = GF_SNAP_OPTION_TYPE_DELETE;
        } else if (!strcmp (w, "config")) {
                type = GF_SNAP_OPTION_TYPE_CONFIG;
        } else if (!strcmp (w, "restore")) {
                type = GF_SNAP_OPTION_TYPE_RESTORE;
        } else if (!strcmp (w, "status")) {
                type = GF_SNAP_OPTION_TYPE_STATUS;
        } else if (!strcmp (w, "activate")) {
                type = GF_SNAP_OPTION_TYPE_ACTIVATE;
        } else if (!strcmp (w, "deactivate")) {
                type = GF_SNAP_OPTION_TYPE_DEACTIVATE;
        } else if (!strcmp(w, "clone")) {
                type = GF_SNAP_OPTION_TYPE_CLONE;
        }

        if (type != GF_SNAP_OPTION_TYPE_CONFIG &&
            type != GF_SNAP_OPTION_TYPE_STATUS) {
                ret = dict_set_int32 (dict, "hold_snap_locks", _gf_true);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR,
                                "Unable to set hold-snap-locks value "
                                "as _gf_true");
                        goto out;
                }
        }

        /* Following commands does not require volume locks  */
        if (type == GF_SNAP_OPTION_TYPE_STATUS ||
            type == GF_SNAP_OPTION_TYPE_ACTIVATE ||
            type == GF_SNAP_OPTION_TYPE_DEACTIVATE) {
                ret = dict_set_int32 (dict, "hold_vol_locks", _gf_false);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Setting volume lock "
                                "flag failed");
                        goto out;
                }
        }

        /* Check which op is intended */
        switch (type) {
        case GF_SNAP_OPTION_TYPE_CREATE:
                /* Syntax :
                 * gluster snapshot create <snapname> <vol-name(s)>
                 *                         [no-timestamp]
                 *                         [description <description>]
                 *                         [force]
                 */
                /* In cases where the snapname is not given then
                 * parsing fails & snapname cannot be "description",
                 * "force" and "volume", that check is made here
                 */
                if (wordcount == 2){
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }

                ret = validate_op_name ("snapname", words[2],
                                        invalid_snapnames);
                if (ret) {
                        goto out;
                }

                ret = cli_snap_create_parse (dict, words, wordcount);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR,
                                "create command parsing failed.");
                        goto out;
                }
                break;

        case GF_SNAP_OPTION_TYPE_CLONE:
                /* Syntax :
                 * gluster snapshot clone <clonename> <snapname>
                 */
                /* In cases where the clonename is not given then
                 * parsing fails & snapname cannot be "description",
                 * "force" and "volume", that check is made here
                 */
                if (wordcount == 2) {
                        ret = -1;
                        gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
                        goto out;
                }

                ret = validate_op_name ("clonename", words[2],
                                        invalid_volnames);
                if (ret) {
                        goto out;
                }

                ret = cli_snap_clone_parse (dict, words, wordcount);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR,
                                "clone command parsing failed.");
                        goto out;
                }
                break;


        case GF_SNAP_OPTION_TYPE_INFO:
                /* Syntax :
                 * gluster snapshot info [(snapname] | [vol <volname>)]
                 */
                ret = cli_snap_info_parse (dict, words, wordcount);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Failed to parse "
                                "snapshot info command");
                        goto out;
                }
                break;

        case GF_SNAP_OPTION_TYPE_LIST:
                /* Syntax :
                 * gluster snaphsot list [volname]
                 */

                ret = cli_snap_list_parse (dict, words, wordcount);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Failed to parse "
                                "snapshot list command");
                        goto out;
                }
                break;

        case GF_SNAP_OPTION_TYPE_DELETE:
                /* Syntax :
                 * snapshot delete (all | snapname | volume <volname>)
                 */
                ret = cli_snap_delete_parse (dict, words, wordcount, state);
                if (ret) {
                        /* A positive ret value means user cancelled
                        * the command */
                        if (ret < 0) {
                                gf_log ("cli", GF_LOG_ERROR, "Failed to parse "
                                        "snapshot delete command");
                        }
                        goto out;
                }
                break;

        case GF_SNAP_OPTION_TYPE_CONFIG:
                /* snapshot config [volname]  [snap-max-hard-limit <count>]
                 *                            [snap-max-soft-limit <percent>] */
                ret = cli_snap_config_parse (words, wordcount, dict, state);
                if (ret) {
                        if (ret < 0)
                                gf_log ("cli", GF_LOG_ERROR,
                                        "config command parsing failed.");
                        goto out;
                }

                ret = dict_set_int32 (dict, "type", GF_SNAP_OPTION_TYPE_CONFIG);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Unable to set "
                                "config type");
                        ret = -1;
                        goto out;
                }
                break;

        case GF_SNAP_OPTION_TYPE_STATUS:
                {
                        /* Syntax :
                         * gluster snapshot status [(snapname |
                         *                         volume <volname>)]
                         */
                        ret = cli_snap_status_parse (dict, words, wordcount);
                        if (ret) {
                                gf_log ("cli", GF_LOG_ERROR, "Failed to parse "
                                        "snapshot status command");
                                goto out;
                        }
                        break;
                }

        case GF_SNAP_OPTION_TYPE_RESTORE:
                /* Syntax:
                 * snapshot restore <snapname>
                 */
                ret = cli_snap_restore_parse (dict, words, wordcount, state);
                if (ret) {
                        gf_log ("cli", GF_LOG_ERROR, "Failed to parse "
                                "restore command");
                        goto out;
                }
                break;

                case GF_SNAP_OPTION_TYPE_ACTIVATE:
                        /* Syntax:
                        * snapshot activate <snapname> [force]
                        */
                        ret = cli_snap_activate_parse (dict, words, wordcount);
                        if (ret) {
                                gf_log ("cli", GF_LOG_ERROR, "Failed to parse "
                                        "start command");
                                goto out;
                        }
                        break;
                case GF_SNAP_OPTION_TYPE_DEACTIVATE:
                        /* Syntax:
                        * snapshot deactivate <snapname>
                        */
                        ret = cli_snap_deactivate_parse (dict, words, wordcount,
                                state);
                        if (ret) {
                                /* A positive ret value means user cancelled
                                 * the command */
                                if (ret < 0) {
                                        gf_log ("cli", GF_LOG_ERROR,
                                                "Failed to parse deactivate "
                                                "command");
                                }
                                goto out;
                        }
                        break;

        default:
                gf_log ("", GF_LOG_ERROR, "Opword Mismatch");
                goto out;
        }

        ret = dict_set_int32 (dict, "type", type);
        if (ret) {
                gf_log ("", GF_LOG_ERROR,
                        "Failed to set type.");
                goto out;
        }
        /* If you got so far, input is valid */
        ret = 0;
out:
        if (ret) {
                if (dict)
                        dict_destroy (dict);
        } else
                *options = dict;

        return ret;
}