summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c455
1 files changed, 278 insertions, 177 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index 187038fc029..7a86c2997b1 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -14,20 +14,20 @@
#include <sys/resource.h>
#include <libgen.h>
-#include "compat-uuid.h"
+#include <glusterfs/compat-uuid.h>
#include "glusterd.h"
#include "rpcsvc.h"
#include "fnmatch.h"
-#include "xlator.h"
-#include "call-stub.h"
-#include "defaults.h"
-#include "list.h"
-#include "dict.h"
-#include "options.h"
-#include "compat.h"
-#include "compat-errno.h"
-#include "syscall.h"
+#include <glusterfs/xlator.h>
+#include <glusterfs/call-stub.h>
+#include <glusterfs/defaults.h>
+#include <glusterfs/list.h>
+#include <glusterfs/dict.h>
+#include <glusterfs/options.h>
+#include <glusterfs/compat.h>
+#include <glusterfs/compat-errno.h>
+#include <glusterfs/syscall.h>
#include "glusterd-statedump.h"
#include "glusterd-sm.h"
#include "glusterd-op-sm.h"
@@ -37,19 +37,21 @@
#include "glusterd-locks.h"
#include "glusterd-svc-mgmt.h"
#include "glusterd-shd-svc.h"
+#ifdef BUILD_GNFS
#include "glusterd-nfs-svc.h"
+#endif
#include "glusterd-bitd-svc.h"
#include "glusterd-scrub-svc.h"
#include "glusterd-quotad-svc.h"
#include "glusterd-snapd-svc.h"
#include "glusterd-messages.h"
-#include "common-utils.h"
+#include <glusterfs/common-utils.h>
#include "glusterd-geo-rep.h"
-#include "run.h"
+#include <glusterfs/run.h>
#include "rpc-clnt-ping.h"
#include "rpc-common-xdr.h"
-#include "syncop.h"
+#include <glusterfs/syncop.h>
#include "glusterd-mountbroker.h"
@@ -65,7 +67,7 @@ extern struct rpcsvc_program gd_svc_cli_trusted_progs;
extern struct rpc_clnt_program gd_brick_prog;
extern struct rpcsvc_program glusterd_mgmt_hndsk_prog;
-extern char snap_mount_dir[PATH_MAX];
+extern char snap_mount_dir[VALID_GLUSTERD_PATHMAX];
rpcsvc_cbk_program_t glusterd_cbk_prog = {
.progname = "Gluster Callback",
@@ -200,8 +202,10 @@ glusterd_options_init(xlator_t *this)
priv = this->private;
priv->opts = dict_new();
- if (!priv->opts)
+ if (!priv->opts) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL);
goto out;
+ }
ret = glusterd_store_retrieve_options(this);
if (ret == 0) {
@@ -245,6 +249,7 @@ glusterd_client_statedump_submit_req(char *volname, char *target_ip, char *pid)
GF_ASSERT(conf);
if (target_ip == NULL || pid == NULL) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL);
ret = -1;
goto out;
}
@@ -445,14 +450,19 @@ glusterd_rpcsvc_options_build(dict_t *options)
{
int ret = 0;
uint32_t backlog = 0;
+ xlator_t *this = THIS;
+ GF_ASSERT(this);
ret = dict_get_uint32(options, "transport.listen-backlog", &backlog);
if (ret) {
backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG;
ret = dict_set_uint32(options, "transport.listen-backlog", backlog);
- if (ret)
+ if (ret) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED,
+ "Key=transport.listen-backlog", NULL);
goto out;
+ }
}
gf_msg_debug("glusterd", 0, "listen-backlog value: %d", backlog);
@@ -555,7 +565,9 @@ glusterd_crt_georep_folders(char *georepdir, glusterd_conf_t *conf)
char *greplg_s = NULL;
struct group *gr = NULL;
int ret = 0;
+ int gr_ret = 0;
int32_t len = 0;
+ char logdir[PATH_MAX] = {0};
GF_ASSERT(georepdir);
GF_ASSERT(conf);
@@ -570,87 +582,106 @@ glusterd_crt_georep_folders(char *georepdir, glusterd_conf_t *conf)
len = snprintf(georepdir, PATH_MAX, "%s/" GEOREP, conf->workdir);
if ((len < 0) || (len >= PATH_MAX)) {
+ gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_COPY_FAIL, NULL);
ret = -1;
goto out;
}
- ret = mkdir_p(georepdir, 0777, _gf_true);
+ ret = mkdir_p(georepdir, 0755, _gf_true);
if (-1 == ret) {
gf_msg("glusterd", GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create " GEOREP " directory %s", georepdir);
goto out;
}
- if (SLEN(DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP) >= PATH_MAX) {
+ ret = dict_get_str(THIS->options, GEOREP "-log-group", &greplg_s);
+ if (ret) {
+ gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DICT_GET_FAILED,
+ "Key=log-group", NULL);
+ ret = 0;
+ } else {
+ gr = getgrnam(greplg_s);
+ if (!gr) {
+ gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_LOGGROUP_INVALID,
+ "group " GEOREP "-log-group %s does not exist", greplg_s);
+ gr_ret = -1;
+ }
+ }
+ if ((strlen(conf->logdir) + 2 + SLEN(GEOREP)) >= PATH_MAX) {
ret = -1;
gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_DIRPATH_TOO_LONG,
- "directory path " DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP
- " is longer than PATH_MAX");
+ "directory path %s/" GEOREP " is longer than PATH_MAX",
+ conf->logdir);
goto out;
}
- ret = mkdir_p(DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP, 0777, _gf_true);
+ len = snprintf(logdir, PATH_MAX, "%s/" GEOREP, conf->logdir);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ ret = -1;
+ goto out;
+ }
+ ret = mkdir_p(logdir, 0755, _gf_true);
if (-1 == ret) {
gf_msg("glusterd", GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create " GEOREP " log directory");
goto out;
}
+ if (gr) {
+ gr_ret = group_write_allow(logdir, gr->gr_gid);
+ }
- /* Slave log file directory */
- if (SLEN(DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP "-slaves") >= PATH_MAX) {
+ if ((strlen(conf->logdir) + 2 + SLEN(GEOREP "-slaves")) >= PATH_MAX) {
ret = -1;
gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_DIRPATH_TOO_LONG,
- "directory path " DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP
+ "directory path %s/" GEOREP
"-slaves"
- " is longer than PATH_MAX");
+ " is longer than PATH_MAX",
+ conf->logdir);
+ goto out;
+ }
+ len = snprintf(logdir, PATH_MAX, "%s/" GEOREP "-slaves", conf->logdir);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_COPY_FAIL, NULL);
+ ret = -1;
goto out;
}
- ret = mkdir_p(DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP "-slaves", 0777,
- _gf_true);
+ ret = mkdir_p(logdir, 0755, _gf_true);
if (-1 == ret) {
gf_msg("glusterd", GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create " GEOREP " slave log directory");
goto out;
}
+ if (gr && !gr_ret) {
+ gr_ret = group_write_allow(logdir, gr->gr_gid);
+ }
/* MountBroker log file directory */
- if (SLEN(DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP "-slaves/mbr") >= PATH_MAX) {
+ if ((strlen(conf->logdir) + 2 + SLEN(GEOREP "-slaves/mbr")) >= PATH_MAX) {
ret = -1;
gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_DIRPATH_TOO_LONG,
- "directory path " DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP
+ "directory path %s/" GEOREP
"-slaves/mbr"
- " is longer than PATH_MAX");
+ " is longer than PATH_MAX",
+ conf->logdir);
+ goto out;
+ }
+
+ len = snprintf(logdir, PATH_MAX, "%s/" GEOREP "-slaves/mbr", conf->logdir);
+ if ((len < 0) || (len >= PATH_MAX)) {
+ gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_COPY_FAIL, NULL);
+ ret = -1;
goto out;
}
- ret = mkdir_p(DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP "-slaves/mbr", 0777,
- _gf_true);
+
+ ret = mkdir_p(logdir, 0755, _gf_true);
if (-1 == ret) {
gf_msg("glusterd", GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create " GEOREP " mountbroker slave log directory");
goto out;
}
-
- ret = dict_get_str(THIS->options, GEOREP "-log-group", &greplg_s);
- if (ret)
- ret = 0;
- else {
- gr = getgrnam(greplg_s);
- if (!gr) {
- gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_LOGGROUP_INVALID,
- "group " GEOREP "-log-group %s does not exist", greplg_s);
- ret = -1;
- goto out;
- }
-
- ret = group_write_allow(DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP,
- gr->gr_gid);
- if (ret == 0)
- ret = group_write_allow(
- DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP "-slaves", gr->gr_gid);
- if (ret == 0)
- ret = group_write_allow(DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP
- "-slaves/mbr",
- gr->gr_gid);
+ if (gr && !gr_ret) {
+ gr_ret = group_write_allow(logdir, gr->gr_gid);
}
-
+ if (gr_ret)
+ ret = gr_ret;
out:
gf_msg_debug("glusterd", 0, "Returning %d", ret);
return ret;
@@ -814,18 +845,19 @@ configure_syncdaemon(glusterd_conf_t *conf)
/* log-file */
runinit_gsyncd_setrx(&runner, conf);
- runner_add_args(&runner, "log-file",
- DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP
- "/${mastervol}/${eSlave}.log",
- ".", ".", NULL);
+ runner_add_arg(&runner, "log-file");
+ runner_argprintf(&runner, "%s/" GEOREP "/${mastervol}/${eSlave}.log",
+ conf->logdir);
+ runner_add_args(&runner, ".", ".", NULL);
RUN_GSYNCD_CMD;
/* gluster-log-file */
runinit_gsyncd_setrx(&runner, conf);
- runner_add_args(&runner, "gluster-log-file",
- DEFAULT_LOG_FILE_DIRECTORY
- "/" GEOREP "/${mastervol}/${eSlave}${local_id}.gluster.log",
- ".", ".", NULL);
+ runner_add_arg(&runner, "gluster-log-file");
+ runner_argprintf(
+ &runner, "%s/" GEOREP "/${mastervol}/${eSlave}${local_id}.gluster.log",
+ conf->logdir);
+ runner_add_args(&runner, ".", ".", NULL);
RUN_GSYNCD_CMD;
/* ignore-deletes */
@@ -867,33 +899,36 @@ configure_syncdaemon(glusterd_conf_t *conf)
/* log-file */
runinit_gsyncd_setrx(&runner, conf);
- runner_add_args(
- &runner, "log-file",
- DEFAULT_LOG_FILE_DIRECTORY
- "/" GEOREP
+ runner_add_arg(&runner, "log-file");
+ runner_argprintf(
+ &runner,
+ "%s/" GEOREP
"-slaves/${session_owner}:${local_node}${local_id}.${slavevol}.log",
- ".", NULL);
+ conf->logdir);
+ runner_add_args(&runner, ".", ".", NULL);
RUN_GSYNCD_CMD;
/* MountBroker log-file */
runinit_gsyncd_setrx(&runner, conf);
- runner_add_args(
- &runner, "log-file-mbr",
- DEFAULT_LOG_FILE_DIRECTORY
- "/" GEOREP
+ runner_add_arg(&runner, "log-file-mbr");
+ runner_argprintf(
+ &runner,
+ "%s/" GEOREP
"-slaves/mbr/${session_owner}:${local_node}${local_id}.${slavevol}.log",
- ".", NULL);
+ conf->logdir);
+ runner_add_args(&runner, ".", ".", NULL);
RUN_GSYNCD_CMD;
/* gluster-log-file */
runinit_gsyncd_setrx(&runner, conf);
- runner_add_args(
- &runner, "gluster-log-file",
- DEFAULT_LOG_FILE_DIRECTORY
- "/" GEOREP
+ runner_add_arg(&runner, "gluster-log-file");
+ runner_argprintf(
+ &runner,
+ "%s/" GEOREP
"-slaves/"
"${session_owner}:${local_node}${local_id}.${slavevol}.gluster.log",
- ".", NULL);
+ conf->logdir);
+ runner_add_args(&runner, ".", ".", NULL);
RUN_GSYNCD_CMD;
out:
@@ -1018,37 +1053,34 @@ _install_mount_spec(dict_t *opts, char *key, data_t *value, void *data)
glusterd_conf_t *priv = THIS->private;
char *label = NULL;
gf_boolean_t georep = _gf_false;
- gf_boolean_t ghadoop = _gf_false;
char *pdesc = value->data;
char *volname = NULL;
int rv = 0;
gf_mount_spec_t *mspec = NULL;
char *user = NULL;
- char *volfile_server = NULL;
+ xlator_t *this = THIS;
+ GF_ASSERT(this);
label = strtail(key, "mountbroker.");
- /* check for presence of geo-rep/hadoop label */
+ /* check for presence of geo-rep label */
if (!label) {
label = strtail(key, "mountbroker-" GEOREP ".");
if (label)
georep = _gf_true;
- else {
- label = strtail(key, "mountbroker-" GHADOOP ".");
- if (label)
- ghadoop = _gf_true;
- }
}
if (!label)
return 0;
mspec = GF_CALLOC(1, sizeof(*mspec), gf_gld_mt_mount_spec);
- if (!mspec)
+ if (!mspec) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_NO_MEMORY, NULL);
goto err;
+ }
mspec->label = label;
- if (georep || ghadoop) {
+ if (georep) {
volname = gf_strdup(pdesc);
if (!volname)
goto err;
@@ -1059,18 +1091,7 @@ _install_mount_spec(dict_t *opts, char *key, data_t *value, void *data)
} else
user = label;
- if (georep)
- rv = make_georep_mountspec(mspec, volname, user);
-
- if (ghadoop) {
- volfile_server = strchr(user, ':');
- if (volfile_server)
- *volfile_server++ = '\0';
- else
- volfile_server = "localhost";
-
- rv = make_ghadoop_mountspec(mspec, volname, user, volfile_server);
- }
+ rv = make_georep_mountspec(mspec, volname, user, priv->logdir);
GF_FREE(volname);
if (rv != 0)
@@ -1085,7 +1106,7 @@ err:
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_MOUNT_SPEC_INSTALL_FAIL,
"adding %smount spec failed: label: %s desc: %s",
- georep ? GEOREP " " : "", label, pdesc);
+ georep ? GEOREP " " : "", label, pdesc ? pdesc : "");
if (mspec) {
if (mspec->patterns) {
@@ -1106,25 +1127,22 @@ glusterd_init_uds_listener(xlator_t *this)
dict_t *options = NULL;
rpcsvc_t *rpc = NULL;
data_t *sock_data = NULL;
- char sockfile[UNIX_PATH_MAX + 1] = {
- 0,
- };
+ char sockfile[UNIX_PATH_MAX] = {0};
int i = 0;
GF_ASSERT(this);
- sock_data = dict_get(this->options, "glusterd-sockfile");
- if (!sock_data) {
- strncpy(sockfile, DEFAULT_GLUSTERD_SOCKFILE, UNIX_PATH_MAX);
- } else {
- strncpy(sockfile, sock_data->data, UNIX_PATH_MAX);
- }
-
options = dict_new();
- if (!options)
+ if (!options) {
+ gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL);
goto out;
+ }
+
+ sock_data = dict_get(this->options, "glusterd-sockfile");
+ (void)snprintf(sockfile, sizeof(sockfile), "%s",
+ sock_data ? sock_data->data : DEFAULT_GLUSTERD_SOCKFILE);
- ret = rpcsvc_transport_unix_options_build(&options, sockfile);
+ ret = rpcsvc_transport_unix_options_build(options, sockfile);
if (ret)
goto out;
@@ -1182,9 +1200,7 @@ glusterd_stop_uds_listener(xlator_t *this)
rpcsvc_listener_t *listener = NULL;
rpcsvc_listener_t *next = NULL;
data_t *sock_data = NULL;
- char sockfile[UNIX_PATH_MAX + 1] = {
- 0,
- };
+ char sockfile[UNIX_PATH_MAX] = {0};
GF_ASSERT(this);
conf = this->private;
@@ -1200,11 +1216,8 @@ glusterd_stop_uds_listener(xlator_t *this)
(void)rpcsvc_unregister_notify(conf->uds_rpc, glusterd_rpcsvc_notify, this);
sock_data = dict_get(this->options, "glusterd-sockfile");
- if (!sock_data) {
- strncpy(sockfile, DEFAULT_GLUSTERD_SOCKFILE, UNIX_PATH_MAX);
- } else {
- strncpy(sockfile, sock_data->data, UNIX_PATH_MAX);
- }
+ (void)snprintf(sockfile, sizeof(sockfile), "%s",
+ sock_data ? sock_data->data : DEFAULT_GLUSTERD_SOCKFILE);
sys_unlink(sockfile);
return;
@@ -1314,7 +1327,7 @@ glusterd_init_var_run_dirs(xlator_t *this, char *var_run_dir,
if ((-1 == ret) && (ENOENT == errno)) {
/* Create missing dirs */
- ret = mkdir_p(abs_path, 0777, _gf_true);
+ ret = mkdir_p(abs_path, 0755, _gf_true);
if (-1 == ret) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
@@ -1401,13 +1414,16 @@ init(xlator_t *this)
char rundir[PATH_MAX] = {
0,
};
+ char logdir[VALID_GLUSTERD_PATHMAX] = {
+ 0,
+ };
char cmd_log_filename[PATH_MAX] = {
0,
};
char *mountbroker_root = NULL;
int i = 0;
int total_transport = 0;
- gf_boolean_t valgrind = _gf_false;
+ gf_valgrind_tool vgtool;
char *valgrind_str = NULL;
char *transport_type = NULL;
char var_run_dir[PATH_MAX] = {
@@ -1418,6 +1434,15 @@ init(xlator_t *this)
gf_boolean_t downgrade = _gf_false;
char *localtime_logging = NULL;
int32_t len = 0;
+ int op_version = 0;
+
+#if defined(RUN_WITH_MEMCHECK)
+ vgtool = _gf_memcheck;
+#elif defined(RUN_WITH_DRD)
+ vgtool = _gf_drd;
+#else
+ vgtool = _gf_none;
+#endif
#ifndef GF_DARWIN_HOST_OS
{
@@ -1426,9 +1451,8 @@ init(xlator_t *this)
lim.rlim_max = 65536;
if (setrlimit(RLIMIT_NOFILE, &lim) == -1) {
- gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_SETXATTR_FAIL,
- "Failed to set 'ulimit -n "
- " 65536'");
+ gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_SET_XATTR_FAIL,
+ "Failed to set 'ulimit -n 65536'", NULL);
} else {
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_FILE_DESC_LIMIT_SET,
"Maximum allowed open file descriptors "
@@ -1448,6 +1472,26 @@ init(xlator_t *this)
if (len < 0 || len >= PATH_MAX)
exit(2);
+ dir_data = dict_get(this->options, "cluster-test-mode");
+ if (!dir_data) {
+ /* Use default working dir */
+ len = snprintf(logdir, VALID_GLUSTERD_PATHMAX, "%s",
+ DEFAULT_LOG_FILE_DIRECTORY);
+ } else {
+ len = snprintf(logdir, VALID_GLUSTERD_PATHMAX, "%s", dir_data->data);
+ gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_CLUSTER_RC_ENABLE,
+ "cluster-test-mode is enabled logdir is %s", dir_data->data);
+ }
+ if (len < 0 || len >= PATH_MAX)
+ exit(2);
+
+ ret = mkdir_p(logdir, 0777, _gf_true);
+ if ((ret == -1) && (EEXIST != errno)) {
+ gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED,
+ "Unable to create log dir %s", logdir);
+ exit(1);
+ }
+
dir_data = dict_get(this->options, "working-directory");
if (!dir_data) {
@@ -1475,7 +1519,7 @@ init(xlator_t *this)
}
if ((-1 == ret) && (ENOENT == errno)) {
- ret = mkdir_p(workdir, 0777, _gf_true);
+ ret = mkdir_p(workdir, 0755, _gf_true);
if (-1 == ret) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
@@ -1522,7 +1566,7 @@ init(xlator_t *this)
exit(1);
}
- ret = mkdir_p(GLUSTER_SHARED_STORAGE_BRICK_DIR, 0777, _gf_true);
+ ret = mkdir_p(GLUSTER_SHARED_STORAGE_BRICK_DIR, 0755, _gf_true);
if (ret) {
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_DIR_OP_FAILED,
"Unable to create "
@@ -1546,14 +1590,7 @@ init(xlator_t *this)
exit(1);
}
- ret = glusterd_init_var_run_dirs(this, rundir, GLUSTERD_GLUSTERSHD_RUN_DIR);
- if (ret) {
- gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_CREATE_DIR_FAILED,
- "Unable to create "
- "glustershd running directory");
- exit(1);
- }
-
+#ifdef BUILD_GNFS
ret = glusterd_init_var_run_dirs(this, rundir, GLUSTERD_NFS_RUN_DIR);
if (ret) {
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_CREATE_DIR_FAILED,
@@ -1561,6 +1598,7 @@ init(xlator_t *this)
"nfs running directory");
exit(1);
}
+#endif
ret = glusterd_init_var_run_dirs(this, rundir, GLUSTERD_QUOTAD_RUN_DIR);
if (ret) {
@@ -1570,8 +1608,7 @@ init(xlator_t *this)
exit(1);
}
- snprintf(cmd_log_filename, PATH_MAX, "%s/cmd_history.log",
- DEFAULT_LOG_FILE_DIRECTORY);
+ snprintf(cmd_log_filename, PATH_MAX, "%s/cmd_history.log", logdir);
ret = gf_cmd_log_init(cmd_log_filename);
if (ret == -1) {
@@ -1585,7 +1622,7 @@ init(xlator_t *this)
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
@@ -1601,7 +1638,7 @@ init(xlator_t *this)
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
@@ -1616,7 +1653,7 @@ init(xlator_t *this)
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
@@ -1631,7 +1668,7 @@ init(xlator_t *this)
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
@@ -1641,13 +1678,12 @@ init(xlator_t *this)
exit(1);
}
- len = snprintf(storedir, sizeof(storedir), "%s/bricks",
- DEFAULT_LOG_FILE_DIRECTORY);
+ len = snprintf(storedir, sizeof(storedir), "%s/bricks", logdir);
if ((len < 0) || (len >= sizeof(storedir))) {
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create logs directory %s"
@@ -1656,11 +1692,12 @@ init(xlator_t *this)
exit(1);
}
+#ifdef BUILD_GNFS
len = snprintf(storedir, sizeof(storedir), "%s/nfs", workdir);
if ((len < 0) || (len >= sizeof(storedir))) {
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create nfs directory %s"
@@ -1668,12 +1705,12 @@ init(xlator_t *this)
storedir, errno);
exit(1);
}
-
+#endif
len = snprintf(storedir, sizeof(storedir), "%s/bitd", workdir);
if ((len < 0) || (len >= sizeof(storedir))) {
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create bitrot directory %s", storedir);
@@ -1684,7 +1721,7 @@ init(xlator_t *this)
if ((len < 0) || (len >= sizeof(storedir))) {
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create scrub directory %s", storedir);
@@ -1695,7 +1732,7 @@ init(xlator_t *this)
if ((len < 0) || (len >= sizeof(storedir))) {
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create glustershd directory %s"
@@ -1708,7 +1745,7 @@ init(xlator_t *this)
if ((len < 0) || (len >= sizeof(storedir))) {
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create quotad directory %s"
@@ -1721,7 +1758,7 @@ init(xlator_t *this)
if ((len < 0) || (len >= sizeof(storedir))) {
exit(1);
}
- ret = sys_mkdir(storedir, 0777);
+ ret = sys_mkdir(storedir, 0755);
if ((-1 == ret) && (errno != EEXIST)) {
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
"Unable to create glustershd directory %s"
@@ -1828,15 +1865,42 @@ init(xlator_t *this)
CDS_INIT_LIST_HEAD(&conf->snapshots);
CDS_INIT_LIST_HEAD(&conf->missed_snaps_list);
CDS_INIT_LIST_HEAD(&conf->brick_procs);
+ CDS_INIT_LIST_HEAD(&conf->shd_procs);
+ pthread_mutex_init(&conf->attach_lock, NULL);
+ pthread_mutex_init(&conf->volume_lock, NULL);
pthread_mutex_init(&conf->mutex, NULL);
conf->rpc = rpc;
conf->uds_rpc = uds_rpc;
conf->gfs_mgmt = &gd_brick_prog;
- (void)strncpy(conf->workdir, workdir, strlen(workdir) + 1);
- (void)strncpy(conf->rundir, rundir, strlen(rundir) + 1);
+ conf->restart_shd = _gf_false;
+ this->private = conf;
+ /* conf->workdir and conf->rundir are smaller than PATH_MAX; gcc's
+ * snprintf checking will throw an error here if sprintf is used.
+ * Dueling gcc-8 and coverity, now coverity isn't smart enough to
+ * detect that these strncpy calls are safe. And for extra fun,
+ * the annotations don't do anything. */
+ if (strlen(workdir) >= sizeof(conf->workdir)) {
+ ret = -1;
+ goto out;
+ }
+ /* coverity[BUFFER_SIZE_WARNING] */
+ (void)strncpy(conf->workdir, workdir, sizeof(conf->workdir));
+ /* separate tests because combined tests confuses gcc */
+ if (strlen(rundir) >= sizeof(conf->rundir)) {
+ ret = -1;
+ goto out;
+ }
+ /* coverity[BUFFER_SIZE_WARNING] */
+ (void)strncpy(conf->rundir, rundir, sizeof(conf->rundir));
+
+ /* coverity[BUFFER_SIZE_WARNING] */
+ (void)strncpy(conf->logdir, logdir, sizeof(conf->logdir));
synclock_init(&conf->big_lock, SYNC_LOCK_RECURSIVE);
+ synccond_init(&conf->cond_restart_bricks);
+ synccond_init(&conf->cond_restart_shd);
+ synccond_init(&conf->cond_blockers);
pthread_mutex_init(&conf->xprt_lock, NULL);
INIT_LIST_HEAD(&conf->xprt_list);
pthread_mutex_init(&conf->import_volumes, NULL);
@@ -1869,31 +1933,37 @@ init(xlator_t *this)
}
/* Set option to run bricks on valgrind if enabled in glusterd.vol */
- this->ctx->cmd_args.valgrind = valgrind;
+ this->ctx->cmd_args.vgtool = vgtool;
ret = dict_get_str(this->options, "run-with-valgrind", &valgrind_str);
if (ret < 0) {
gf_msg_debug(this->name, 0, "cannot get run-with-valgrind value");
}
if (valgrind_str) {
- if (gf_string2boolean(valgrind_str, &valgrind)) {
+ gf_boolean_t vg = _gf_false;
+
+ if (!strcmp(valgrind_str, "memcheck"))
+ this->ctx->cmd_args.vgtool = _gf_memcheck;
+ else if (!strcmp(valgrind_str, "drd"))
+ this->ctx->cmd_args.vgtool = _gf_drd;
+ else if (!gf_string2boolean(valgrind_str, &vg))
+ this->ctx->cmd_args.vgtool = (vg ? _gf_memcheck : _gf_none);
+ else
gf_msg(this->name, GF_LOG_WARNING, EINVAL, GD_MSG_INVALID_ENTRY,
- "run-with-valgrind value not a boolean string");
- } else {
- this->ctx->cmd_args.valgrind = valgrind;
- }
+ "run-with-valgrind is neither boolean"
+ " nor one of 'memcheck' or 'drd'");
}
/* Store ping-timeout in conf */
ret = dict_get_int32(this->options, "ping-timeout", &conf->ping_timeout);
/* Not failing here since ping-timeout can be optional as well */
- this->private = conf;
glusterd_mgmt_v3_lock_init();
glusterd_mgmt_v3_lock_timer_init();
glusterd_txn_opinfo_dict_init();
- glusterd_shdsvc_build(&conf->shd_svc);
+#ifdef BUILD_GNFS
glusterd_nfssvc_build(&conf->nfs_svc);
+#endif
glusterd_quotadsvc_build(&conf->quotad_svc);
glusterd_bitdsvc_build(&conf->bitd_svc);
glusterd_scrubsvc_build(&conf->scrub_svc);
@@ -1976,18 +2046,36 @@ init(xlator_t *this)
}
}
- conf->blockers = 0;
+ GF_ATOMIC_INIT(conf->blockers, 0);
+ ret = glusterd_handle_upgrade_downgrade(this->options, conf, upgrade,
+ downgrade);
+ if (ret)
+ goto out;
+
+ ret = glusterd_retrieve_max_op_version(this, &op_version);
+ /* first condition indicates file isn't present which means this code
+ * change is hitting for the first time or someone has deleted it from the
+ * backend.second condition is when max op_version differs, in both cases
+ * volfiles should be regenerated
+ */
+ if (op_version == 0 || op_version != GD_OP_VERSION_MAX) {
+ gf_log(this->name, GF_LOG_INFO,
+ "Regenerating volfiles due to a max op-version mismatch or "
+ "glusterd.upgrade file not being present, op_version retrieved:"
+ "%d, max op_version: %d",
+ op_version, GD_OP_VERSION_MAX);
+ glusterd_recreate_volfiles(conf);
+ ret = glusterd_store_max_op_version(this);
+ if (ret)
+ gf_log(this->name, GF_LOG_ERROR, "Failed to store max op-version");
+ }
+
/* If the peer count is less than 2 then this would be the best time to
* spawn process/bricks that may need (re)starting since last time
* (this) glusterd was up. */
if (glusterd_get_peers_count() < 2)
glusterd_launch_synctask(glusterd_spawn_daemons, NULL);
- ret = glusterd_handle_upgrade_downgrade(this->options, conf, upgrade,
- downgrade);
- if (ret)
- goto out;
-
ret = glusterd_hooks_spawn_worker(this);
if (ret)
goto out;
@@ -1995,7 +2083,7 @@ init(xlator_t *this)
GF_OPTION_INIT("event-threads", workers, int32, out);
if (workers > 0 && workers != conf->workers) {
conf->workers = workers;
- ret = event_reconfigure_threads(this->ctx->event_pool, workers);
+ ret = gf_event_reconfigure_threads(this->ctx->event_pool, workers);
if (ret)
goto out;
}
@@ -2137,10 +2225,6 @@ struct volume_options options[] = {
.type = GF_OPTION_TYPE_ANY,
},
{
- .key = {"mountbroker-" GHADOOP ".*"},
- .type = GF_OPTION_TYPE_ANY,
- },
- {
.key = {GEOREP "-log-group"},
.type = GF_OPTION_TYPE_ANY,
},
@@ -2151,13 +2235,17 @@ struct volume_options options[] = {
{.key = {"server-quorum-type"},
.type = GF_OPTION_TYPE_STR,
.value = {"none", "server"},
- .description = "This feature is on the server-side i.e. in glusterd."
- " Whenever the glusterd on a machine observes that "
+ .default_value = "none",
+ .description = "It can be set to none or server. When set to server, "
+ "this option enables the specified volume to "
+ "participate in the server-side quorum. "
+ "This feature is on the server-side i.e. in glusterd. "
+ "Whenever the glusterd on a machine observes that "
"the quorum is not met, it brings down the bricks to "
"prevent data split-brains. When the network "
"connections are brought back up and the quorum is "
- "restored the bricks in the volume are brought back "
- "up."},
+ "restored the bricks in "
+ "the volume are brought back up."},
{.key = {"server-quorum-ratio"},
.type = GF_OPTION_TYPE_PERCENT,
.description = "Sets the quorum percentage for the trusted "
@@ -2202,3 +2290,16 @@ struct volume_options options[] = {
" power. Range 1-32 threads."},
{.key = {NULL}},
};
+
+xlator_api_t xlator_api = {
+ .init = init,
+ .fini = fini,
+ .mem_acct_init = mem_acct_init,
+ .op_version = {1}, /* Present from the initial version */
+ .dumpops = &dumpops,
+ .fops = &fops,
+ .cbks = &cbks,
+ .options = options,
+ .identifier = "glusterd",
+ .category = GF_MAINTAINED,
+};