diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-geo-rep.c')
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 305 |
1 files changed, 195 insertions, 110 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index c8a4be2cdea..bf062c87060 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -7,7 +7,7 @@ later), or the GNU General Public License, version 2 (GPLv2), in all cases as published by the Free Software Foundation. */ -#include "common-utils.h" +#include <glusterfs/common-utils.h> #include "cli1-xdr.h" #include "xdr-generic.h" #include "glusterd.h" @@ -17,8 +17,8 @@ #include "glusterd-utils.h" #include "glusterd-volgen.h" #include "glusterd-svc-helper.h" -#include "run.h" -#include "syscall.h" +#include <glusterfs/run.h> +#include <glusterfs/syscall.h> #include "glusterd-messages.h" #include <signal.h> @@ -76,6 +76,19 @@ static char *gsync_reserved_opts[] = {"gluster-command", static char *gsync_no_restart_opts[] = {"checkpoint", "log_rsync_performance", "log-rsync-performance", NULL}; +void +set_gsyncd_inet6_arg(runner_t *runner) +{ + xlator_t *this = NULL; + char *af; + int ret; + + this = THIS; + ret = dict_get_str(this->options, "transport.address-family", &af); + if (ret == 0) + runner_argprintf(runner, "--%s", af); +} + int __glusterd_handle_sys_exec(rpcsvc_request_t *req) { @@ -102,13 +115,18 @@ __glusterd_handle_sys_exec(rpcsvc_request_t *req) ret = xdr_to_generic(req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { req->rpc_err = GARBAGE_ARGS; + snprintf(err_str, sizeof(err_str), "Garbage args received"); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_GARBAGE_ARGS, NULL); goto out; } if (cli_req.dict.dict_len) { dict = dict_new(); - if (!dict) + if (!dict) { + gf_smsg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, + NULL); goto out; + } ret = dict_unserialize(cli_req.dict.dict_val, cli_req.dict.dict_len, &dict); @@ -129,13 +147,18 @@ __glusterd_handle_sys_exec(rpcsvc_request_t *req) snprintf(err_str, sizeof(err_str), "Failed to get " "the uuid of local glusterd"); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_UUID_GET_FAIL, + NULL); ret = -1; goto out; } ret = dict_set_dynstr(dict, "host-uuid", host_uuid); - if (ret) + if (ret) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_SET_FAILED, + "Key=host-uuid", NULL); goto out; + } } ret = glusterd_op_begin_synctask(req, cli_op, dict); @@ -175,13 +198,18 @@ __glusterd_handle_copy_file(rpcsvc_request_t *req) ret = xdr_to_generic(req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { req->rpc_err = GARBAGE_ARGS; + snprintf(err_str, sizeof(err_str), "Garbage args received"); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_GARBAGE_ARGS, NULL); goto out; } if (cli_req.dict.dict_len) { dict = dict_new(); - if (!dict) + if (!dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, + NULL); goto out; + } ret = dict_unserialize(cli_req.dict.dict_val, cli_req.dict.dict_len, &dict); @@ -202,6 +230,8 @@ __glusterd_handle_copy_file(rpcsvc_request_t *req) snprintf(err_str, sizeof(err_str), "Failed to get " "the uuid of local glusterd"); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_UUID_GET_FAIL, + NULL); ret = -1; goto out; } @@ -254,13 +284,18 @@ __glusterd_handle_gsync_set(rpcsvc_request_t *req) ret = xdr_to_generic(req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { req->rpc_err = GARBAGE_ARGS; + snprintf(err_str, sizeof(err_str), "Garbage args received"); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_GARBAGE_ARGS, NULL); goto out; } if (cli_req.dict.dict_len) { dict = dict_new(); - if (!dict) + if (!dict) { + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, + NULL); goto out; + } ret = dict_unserialize(cli_req.dict.dict_val, cli_req.dict.dict_len, &dict); @@ -281,6 +316,8 @@ __glusterd_handle_gsync_set(rpcsvc_request_t *req) snprintf(err_str, sizeof(err_str), "Failed to get " "the uuid of local glusterd"); + gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_UUID_GET_FAIL, + NULL); ret = -1; goto out; } @@ -384,6 +421,7 @@ glusterd_urltransform_init(runner_t *runner, const char *transname) { runinit(runner); runner_add_arg(runner, GSYNCD_PREFIX "/gsyncd"); + set_gsyncd_inet6_arg(runner); runner_argprintf(runner, "--%s-url", transname); } @@ -588,7 +626,7 @@ struct slave_vol_config { char old_slvhost[_POSIX_HOST_NAME_MAX + 1]; char old_slvuser[LOGIN_NAME_MAX]; unsigned old_slvidx; - char slave_voluuid[GF_UUID_BUF_SIZE]; + char slave_voluuid[UUID_CANONICAL_FORM_LEN + 1]; }; static int @@ -725,6 +763,7 @@ glusterd_get_slave_voluuid(char *slave_host, char *slave_vol, char *vol_uuid) runinit(&runner); runner_add_arg(&runner, GSYNCD_PREFIX "/gsyncd"); + set_gsyncd_inet6_arg(&runner); runner_add_arg(&runner, "--slavevoluuid-get"); runner_argprintf(&runner, "%s::%s", slave_host, slave_vol); @@ -788,6 +827,7 @@ glusterd_gsync_get_config(char *master, char *slave, char *conf_path, runinit(&runner); runner_add_args(&runner, GSYNCD_PREFIX "/gsyncd", "-c", NULL); runner_argprintf(&runner, "%s", conf_path); + set_gsyncd_inet6_arg(&runner); runner_argprintf(&runner, "--iprefix=%s", DATADIR); runner_argprintf(&runner, ":%s", master); runner_add_args(&runner, slave, "--config-get-all", NULL); @@ -803,6 +843,7 @@ _fcbk_statustostruct(char *resbuf, size_t blen, FILE *fp, void *data) char *v = NULL; char *k = NULL; gf_gsync_status_t *sts_val = NULL; + size_t len = 0; sts_val = (gf_gsync_status_t *)data; @@ -836,47 +877,63 @@ _fcbk_statustostruct(char *resbuf, size_t blen, FILE *fp, void *data) } if (strcmp(k, "worker_status") == 0) { - memcpy(sts_val->worker_status, v, strlen(v)); - sts_val->worker_status[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->worker_status) - 1)); + memcpy(sts_val->worker_status, v, len); + sts_val->worker_status[len] = '\0'; } else if (strcmp(k, "slave_node") == 0) { - memcpy(sts_val->slave_node, v, strlen(v)); - sts_val->slave_node[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->slave_node) - 1)); + memcpy(sts_val->slave_node, v, len); + sts_val->slave_node[len] = '\0'; } else if (strcmp(k, "crawl_status") == 0) { - memcpy(sts_val->crawl_status, v, strlen(v)); - sts_val->crawl_status[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->crawl_status) - 1)); + memcpy(sts_val->crawl_status, v, len); + sts_val->crawl_status[len] = '\0'; } else if (strcmp(k, "last_synced") == 0) { - memcpy(sts_val->last_synced, v, strlen(v)); - sts_val->last_synced[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->last_synced) - 1)); + memcpy(sts_val->last_synced, v, len); + sts_val->last_synced[len] = '\0'; } else if (strcmp(k, "last_synced_utc") == 0) { - memcpy(sts_val->last_synced_utc, v, strlen(v)); - sts_val->last_synced_utc[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->last_synced_utc) - 1)); + memcpy(sts_val->last_synced_utc, v, len); + sts_val->last_synced_utc[len] = '\0'; } else if (strcmp(k, "entry") == 0) { - memcpy(sts_val->entry, v, strlen(v)); - sts_val->entry[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->entry) - 1)); + memcpy(sts_val->entry, v, len); + sts_val->entry[len] = '\0'; } else if (strcmp(k, "data") == 0) { - memcpy(sts_val->data, v, strlen(v)); - sts_val->data[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->data) - 1)); + memcpy(sts_val->data, v, len); + sts_val->data[len] = '\0'; } else if (strcmp(k, "meta") == 0) { - memcpy(sts_val->meta, v, strlen(v)); - sts_val->meta[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->meta) - 1)); + memcpy(sts_val->meta, v, len); + sts_val->meta[len] = '\0'; } else if (strcmp(k, "failures") == 0) { - memcpy(sts_val->failures, v, strlen(v)); - sts_val->failures[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->failures) - 1)); + memcpy(sts_val->failures, v, len); + sts_val->failures[len] = '\0'; } else if (strcmp(k, "checkpoint_time") == 0) { - memcpy(sts_val->checkpoint_time, v, strlen(v)); - sts_val->checkpoint_time[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->checkpoint_time) - 1)); + memcpy(sts_val->checkpoint_time, v, len); + sts_val->checkpoint_time[len] = '\0'; } else if (strcmp(k, "checkpoint_time_utc") == 0) { - memcpy(sts_val->checkpoint_time_utc, v, strlen(v)); - sts_val->checkpoint_time_utc[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->checkpoint_time_utc) - 1)); + memcpy(sts_val->checkpoint_time_utc, v, len); + sts_val->checkpoint_time_utc[len] = '\0'; } else if (strcmp(k, "checkpoint_completed") == 0) { - memcpy(sts_val->checkpoint_completed, v, strlen(v)); - sts_val->checkpoint_completed[strlen(v)] = '\0'; + len = min(strlen(v), (sizeof(sts_val->checkpoint_completed) - 1)); + memcpy(sts_val->checkpoint_completed, v, len); + sts_val->checkpoint_completed[len] = '\0'; } else if (strcmp(k, "checkpoint_completion_time") == 0) { - memcpy(sts_val->checkpoint_completion_time, v, strlen(v)); - sts_val->checkpoint_completion_time[strlen(v)] = '\0'; + len = min(strlen(v), + (sizeof(sts_val->checkpoint_completion_time) - 1)); + memcpy(sts_val->checkpoint_completion_time, v, len); + sts_val->checkpoint_completion_time[len] = '\0'; } else if (strcmp(k, "checkpoint_completion_time_utc") == 0) { - memcpy(sts_val->checkpoint_completion_time_utc, v, strlen(v)); - sts_val->checkpoint_completion_time_utc[strlen(v)] = '\0'; + len = min(strlen(v), + (sizeof(sts_val->checkpoint_completion_time_utc) - 1)); + memcpy(sts_val->checkpoint_completion_time_utc, v, len); + sts_val->checkpoint_completion_time_utc[len] = '\0'; } GF_FREE(v); GF_FREE(k); @@ -900,6 +957,7 @@ glusterd_gsync_get_status(char *master, char *slave, char *conf_path, runinit(&runner); runner_add_args(&runner, GSYNCD_PREFIX "/gsyncd", "-c", NULL); runner_argprintf(&runner, "%s", conf_path); + set_gsyncd_inet6_arg(&runner); runner_argprintf(&runner, "--iprefix=%s", DATADIR); runner_argprintf(&runner, ":%s", master); runner_add_args(&runner, slave, "--status-get", NULL); @@ -920,6 +978,7 @@ glusterd_gsync_get_param_file(char *prmfile, const char *param, char *master, runinit(&runner); runner_add_args(&runner, GSYNCD_PREFIX "/gsyncd", "-c", NULL); runner_argprintf(&runner, "%s", conf_path); + set_gsyncd_inet6_arg(&runner); runner_argprintf(&runner, "--iprefix=%s", DATADIR); runner_argprintf(&runner, ":%s", master); runner_add_args(&runner, slave, "--config-get", NULL); @@ -1695,9 +1754,10 @@ glusterd_store_slave_in_info(glusterd_volinfo_t *volinfo, char *slave, char *value = NULL; char *slavekey = NULL; char *slaveentry = NULL; - char key[512] = { + char key[32] = { 0, }; + int keylen; char *t = NULL; xlator_t *this = NULL; struct slave_vol_config slave1 = { @@ -1769,21 +1829,21 @@ glusterd_store_slave_in_info(glusterd_volinfo_t *volinfo, char *slave, goto out; /* Given the slave volume uuid, check and get any existing slave */ - memcpy(slave1.slave_voluuid, slave_voluuid, GF_UUID_BUF_SIZE); + memcpy(slave1.slave_voluuid, slave_voluuid, UUID_CANONICAL_FORM_LEN); ret = dict_foreach(volinfo->gsync_slaves, _get_slave_idx_slave_voluuid, &slave1); if (ret == 0) { /* New slave */ dict_foreach(volinfo->gsync_slaves, _get_max_gsync_slave_num, &maxslv); - snprintf(key, sizeof(key), "slave%d", maxslv + 1); + keylen = snprintf(key, sizeof(key), "slave%d", maxslv + 1); - ret = dict_set_dynstr(volinfo->gsync_slaves, key, value); + ret = dict_set_dynstrn(volinfo->gsync_slaves, key, keylen, value); if (ret) { GF_FREE(value); goto out; } } else if (ret == -1) { /* Existing slave */ - snprintf(key, sizeof(key), "slave%d", slave1.old_slvidx); + keylen = snprintf(key, sizeof(key), "slave%d", slave1.old_slvidx); gf_msg_debug(this->name, 0, "Replacing key:%s with new value" @@ -1791,7 +1851,7 @@ glusterd_store_slave_in_info(glusterd_volinfo_t *volinfo, char *slave, key, value); /* Add new slave's value, with the same slave index */ - ret = dict_set_dynstr(volinfo->gsync_slaves, key, value); + ret = dict_set_dynstrn(volinfo->gsync_slaves, key, keylen, value); if (ret) { GF_FREE(value); goto out; @@ -2215,6 +2275,9 @@ glusterd_op_verify_gsync_running(glusterd_volinfo_t *volinfo, char *slave, "Volume %s needs to be started " "before " GEOREP " start", volinfo->volname); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_GEO_REP_START_FAILED, + "Volume is not in a started state, Volname=%s", + volinfo->volname, NULL); goto out; } @@ -2271,7 +2334,6 @@ glusterd_verify_gsync_status_opts(dict_t *dict, char **op_errstr) char errmsg[PATH_MAX] = { 0, }; - gf_boolean_t exists = _gf_false; glusterd_volinfo_t *volinfo = NULL; int ret = 0; char *conf_path = NULL; @@ -2299,9 +2361,8 @@ glusterd_verify_gsync_status_opts(dict_t *dict, char **op_errstr) goto out; } - exists = glusterd_check_volume_exists(volname); ret = glusterd_volinfo_find(volname, &volinfo); - if ((ret) || (!exists)) { + if (ret) { gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_VOL_NOT_FOUND, "volume name does not exist"); snprintf(errmsg, sizeof(errmsg), @@ -2309,7 +2370,6 @@ glusterd_verify_gsync_status_opts(dict_t *dict, char **op_errstr) " exist", volname); *op_errstr = gf_strdup(errmsg); - ret = -1; goto out; } @@ -2522,6 +2582,7 @@ glusterd_op_stage_copy_file(dict_t *dict, char **op_errstr) len = snprintf(abs_filename, sizeof(abs_filename), "%s/%s", priv->workdir, filename); if ((len < 0) || (len >= sizeof(abs_filename))) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_COPY_FAIL, NULL); ret = -1; goto out; } @@ -2534,6 +2595,9 @@ glusterd_op_stage_copy_file(dict_t *dict, char **op_errstr) if (len < 0) { strcpy(errmsg, "<error>"); } + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_REALPATH_GET_FAIL, + "Realpath=%s, Reason=%s", priv->workdir, strerror(errno), + NULL); *op_errstr = gf_strdup(errmsg); ret = -1; goto out; @@ -2544,6 +2608,8 @@ glusterd_op_stage_copy_file(dict_t *dict, char **op_errstr) "Failed to get " "realpath of %s: %s", filename, strerror(errno)); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_REALPATH_GET_FAIL, + "Filename=%s, Reason=%s", filename, strerror(errno), NULL); *op_errstr = gf_strdup(errmsg); ret = -1; goto out; @@ -2553,6 +2619,7 @@ glusterd_op_stage_copy_file(dict_t *dict, char **op_errstr) will succeed for /var/lib/glusterd_bad */ len = snprintf(workdir, sizeof(workdir), "%s/", realpath_workdir); if ((len < 0) || (len >= sizeof(workdir))) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_COPY_FAIL, NULL); ret = -1; goto out; } @@ -2566,6 +2633,8 @@ glusterd_op_stage_copy_file(dict_t *dict, char **op_errstr) if (len < 0) { strcpy(errmsg, "<error>"); } + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_SRC_FILE_ERROR, errmsg, + NULL); *op_errstr = gf_strdup(errmsg); ret = -1; goto out; @@ -2580,6 +2649,8 @@ glusterd_op_stage_copy_file(dict_t *dict, char **op_errstr) if (len < 0) { strcpy(errmsg, "<error>"); } + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_SRC_FILE_ERROR, errmsg, + NULL); *op_errstr = gf_strdup(errmsg); goto out; } @@ -2588,9 +2659,9 @@ glusterd_op_stage_copy_file(dict_t *dict, char **op_errstr) snprintf(errmsg, sizeof(errmsg), "Source file" " is not a regular file."); + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_SRC_FILE_ERROR, errmsg, + NULL); *op_errstr = gf_strdup(errmsg); - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SRC_FILE_ERROR, "%s", - errmsg); ret = -1; goto out; } @@ -2794,6 +2865,7 @@ glusterd_verify_slave(char *volname, char *slave_url, char *slave_vol, char *slave_ip = NULL; glusterd_conf_t *priv = NULL; xlator_t *this = NULL; + char *af = NULL; this = THIS; GF_ASSERT(this); @@ -2808,8 +2880,11 @@ glusterd_verify_slave(char *volname, char *slave_url, char *slave_vol, */ if (strstr(slave_url, "@")) { slave_url_buf = gf_strdup(slave_url); - if (!slave_url_buf) + if (!slave_url_buf) { + gf_smsg(this->name, GF_LOG_ERROR, 0, GD_MSG_STRDUP_FAILED, + "Slave_url=%s", slave_url, NULL); goto out; + } slave_user = strtok_r(slave_url_buf, "@", &save_ptr); slave_ip = strtok_r(NULL, "@", &save_ptr); @@ -2824,8 +2899,8 @@ glusterd_verify_slave(char *volname, char *slave_url, char *slave_vol, goto out; } - snprintf(log_file_path, sizeof(log_file_path), - DEFAULT_LOG_FILE_DIRECTORY "/create_verify_log"); + snprintf(log_file_path, sizeof(log_file_path), "%s/create_verify_log", + priv->logdir); runinit(&runner); runner_add_args(&runner, GSYNCD_PREFIX "/gverify.sh", NULL); @@ -2835,9 +2910,16 @@ glusterd_verify_slave(char *volname, char *slave_url, char *slave_vol, runner_argprintf(&runner, "%s", slave_vol); runner_argprintf(&runner, "%d", ssh_port); runner_argprintf(&runner, "%s", log_file_path); - gf_msg_debug(this->name, 0, "gverify Args = %s %s %s %s %s %s %s", + ret = dict_get_str(this->options, "transport.address-family", &af); + if (ret) + af = "-"; + + runner_argprintf(&runner, "%s", af); + + gf_msg_debug(this->name, 0, "gverify Args = %s %s %s %s %s %s %s %s", runner.argv[0], runner.argv[1], runner.argv[2], runner.argv[3], - runner.argv[4], runner.argv[5], runner.argv[6]); + runner.argv[4], runner.argv[5], runner.argv[6], + runner.argv[7]); runner_redir(&runner, STDOUT_FILENO, RUN_PIPE); synclock_unlock(&priv->big_lock); ret = runner_run(&runner); @@ -3097,7 +3179,6 @@ glusterd_op_stage_gsync_create(dict_t *dict, char **op_errstr) gf_boolean_t is_force = -1; gf_boolean_t is_no_verify = -1; gf_boolean_t is_force_blocker = -1; - gf_boolean_t exists = _gf_false; gf_boolean_t is_template_in_use = _gf_false; glusterd_conf_t *conf = NULL; glusterd_volinfo_t *volinfo = NULL; @@ -3147,18 +3228,15 @@ glusterd_op_stage_gsync_create(dict_t *dict, char **op_errstr) goto out; } - exists = glusterd_check_volume_exists(volname); ret = glusterd_volinfo_find(volname, &volinfo); - if ((ret) || (!exists)) { + if (ret) { gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_VOL_NOT_FOUND, "volume name does not exist"); snprintf(errmsg, sizeof(errmsg), "Volume name %s does not" " exist", volname); - *op_errstr = gf_strdup(errmsg); - gf_msg_debug(this->name, 0, "Returning %d", ret); - return -1; + goto out; } ret = glusterd_get_slave_details_confpath(volinfo, dict, &slave_url, @@ -3399,6 +3477,12 @@ glusterd_op_stage_gsync_create(dict_t *dict, char **op_errstr) goto out; } + /* There is a remote possibility that slave_host can be NULL when + control reaches here. Add a check so we wouldn't crash in next + line */ + if (!slave_host) + goto out; + /* Now, check whether session is already started.If so, warn!*/ is_different_slavehost = (strcmp(slave_host, slave1.old_slvhost) != 0) ? _gf_true @@ -3493,7 +3577,6 @@ out: if (slave_url_buf) GF_FREE(slave_url_buf); - gf_msg_debug(this->name, 0, "Returning %d", ret); return ret; } @@ -3572,7 +3655,6 @@ glusterd_op_stage_gsync_set(dict_t *dict, char **op_errstr) char *statedir = NULL; char *path_list = NULL; char *conf_path = NULL; - gf_boolean_t exists = _gf_false; glusterd_volinfo_t *volinfo = NULL; char errmsg[PATH_MAX] = { 0, @@ -3623,14 +3705,12 @@ glusterd_op_stage_gsync_set(dict_t *dict, char **op_errstr) goto out; } - exists = glusterd_check_volume_exists(volname); ret = glusterd_volinfo_find(volname, &volinfo); - if ((ret) || (!exists)) { + if (ret) { snprintf(errmsg, sizeof(errmsg), "Volume name %s does not" " exist", volname); - ret = -1; goto out; } @@ -4064,6 +4144,7 @@ gd_pause_or_resume_gsync(dict_t *dict, char *master, char *slave, out: sys_close(pfd); + /* coverity[INTEGER_OVERFLOW] */ return ret; } @@ -4128,10 +4209,10 @@ stop_gsync(char *master, char *slave, char **msg, char *conf_path, * still be alive, give some more time * before SIGKILL (hack) */ - usleep(50000); + gf_nanosleep(50000 * GF_US_IN_NS); break; } - usleep(50000); + gf_nanosleep(50000 * GF_US_IN_NS); } kill(-pid, SIGKILL); sys_unlink(pidfile); @@ -4140,7 +4221,7 @@ stop_gsync(char *master, char *slave, char **msg, char *conf_path, out: sys_close(pfd); - + /* coverity[INTEGER_OVERFLOW] */ return ret; } @@ -4211,8 +4292,8 @@ glusterd_gsync_op_already_set(char *master, char *slave, char *conf_path, } if (is_bool) { - if (!strcmp(op_value, "true") || !strcmp(op_value, "1") || - !strcmp(op_value, "yes")) { + if (op_value && (!strcmp(op_value, "true") || !strcmp(op_value, "1") || + !strcmp(op_value, "yes"))) { op_val_cli = 1; } else { op_val_cli = 0; @@ -4223,7 +4304,7 @@ glusterd_gsync_op_already_set(char *master, char *slave, char *conf_path, goto out; } } else { - if (!strcmp(op_val_buf, op_value)) { + if (op_value && !strcmp(op_val_buf, op_value)) { ret = 0; goto out; } @@ -5075,7 +5156,6 @@ glusterd_get_gsync_status(dict_t *dict, char **op_errstr, dict_t *rsp_dict) char errmsg[PATH_MAX] = { 0, }; - gf_boolean_t exists = _gf_false; glusterd_volinfo_t *volinfo = NULL; int ret = 0; char my_hostname[256] = { @@ -5098,9 +5178,8 @@ glusterd_get_gsync_status(dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } - exists = glusterd_check_volume_exists(volname); ret = glusterd_volinfo_find(volname, &volinfo); - if ((ret) || (!exists)) { + if (ret) { gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_VOL_NOT_FOUND, "volume name does not exist"); snprintf(errmsg, sizeof(errmsg), @@ -5108,7 +5187,6 @@ glusterd_get_gsync_status(dict_t *dict, char **op_errstr, dict_t *rsp_dict) " exist", volname); *op_errstr = gf_strdup(errmsg); - ret = -1; goto out; } @@ -5938,7 +6016,7 @@ glusterd_get_slave_info(char *slave, char **slave_url, char **hostname, GF_ASSERT(this); ret = glusterd_urltransform_single(slave, "normalize", &linearr); - if (ret == -1) { + if ((ret == -1) || (linearr[0] == NULL)) { ret = snprintf(errmsg, sizeof(errmsg) - 1, "Invalid Url: %s", slave); errmsg[ret] = '\0'; *op_errstr = gf_strdup(errmsg); @@ -5949,7 +6027,10 @@ glusterd_get_slave_info(char *slave, char **slave_url, char **hostname, tmp = strtok_r(linearr[0], "/", &save_ptr); tmp = strtok_r(NULL, "/", &save_ptr); - slave = strtok_r(tmp, ":", &save_ptr); + slave = NULL; + if (tmp != NULL) { + slave = strtok_r(tmp, ":", &save_ptr); + } if (slave) { ret = glusterd_geo_rep_parse_slave(slave, hostname, op_errstr); if (ret) { @@ -6203,26 +6284,28 @@ create_conf_file(glusterd_conf_t *conf, char *conf_path) /* log-file */ runinit_gsyncd_setrx(&runner, conf_path); - 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/%s/${mastervol}/${eSlave}.log", conf->logdir, + GEOREP); + runner_add_args(&runner, ".", ".", NULL); RUN_GSYNCD_CMD; /* changelog-log-file */ runinit_gsyncd_setrx(&runner, conf_path); - runner_add_args(&runner, "changelog-log-file", - DEFAULT_LOG_FILE_DIRECTORY - "/" GEOREP "/${mastervol}/${eSlave}${local_id}-changes.log", - ".", ".", NULL); + runner_add_arg(&runner, "changelog-log-file"); + runner_argprintf(&runner, + "%s/%s/${mastervol}/${eSlave}${local_id}-changes.log", + conf->logdir, GEOREP); + runner_add_args(&runner, ".", ".", NULL); RUN_GSYNCD_CMD; /* gluster-log-file */ runinit_gsyncd_setrx(&runner, conf_path); - 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/%s/${mastervol}/${eSlave}${local_id}.gluster.log", + conf->logdir, GEOREP); + runner_add_args(&runner, ".", ".", NULL); RUN_GSYNCD_CMD; /* ignore-deletes */ @@ -6264,33 +6347,35 @@ create_conf_file(glusterd_conf_t *conf, char *conf_path) /* log-file */ runinit_gsyncd_setrx(&runner, conf_path); - runner_add_args( - &runner, "log-file", - DEFAULT_LOG_FILE_DIRECTORY - "/" GEOREP - "-slaves/${session_owner}:${local_node}${local_id}.${slavevol}.log", - ".", NULL); + runner_add_arg(&runner, "log-file"); + runner_argprintf(&runner, + "%s/%s-slaves/" + "${session_owner}:${local_node}${local_id}.${slavevol}." + "log", + conf->logdir, GEOREP); + runner_add_args(&runner, ".", ".", NULL); RUN_GSYNCD_CMD; /* MountBroker log-file */ runinit_gsyncd_setrx(&runner, conf_path); - runner_add_args( - &runner, "log-file-mbr", - DEFAULT_LOG_FILE_DIRECTORY - "/" GEOREP - "-slaves/mbr/${session_owner}:${local_node}${local_id}.${slavevol}.log", - ".", NULL); + runner_add_arg(&runner, "log-file-mbr"); + runner_argprintf(&runner, + "%s/%s-slaves/mbr/" + "${session_owner}:${local_node}${local_id}.${slavevol}." + "log", + conf->logdir, GEOREP); + runner_add_args(&runner, ".", ".", NULL); RUN_GSYNCD_CMD; /* gluster-log-file */ runinit_gsyncd_setrx(&runner, conf_path); - runner_add_args( - &runner, "gluster-log-file", - DEFAULT_LOG_FILE_DIRECTORY - "/" GEOREP - "-slaves/" - "${session_owner}:${local_node}${local_id}.${slavevol}.gluster.log", - ".", NULL); + runner_add_arg(&runner, "gluster-log-file"); + runner_argprintf(&runner, + "%s/%s-slaves/" + "${session_owner}:${local_node}${local_id}.${slavevol}." + "gluster.log", + conf->logdir, GEOREP); + runner_add_args(&runner, ".", ".", NULL); RUN_GSYNCD_CMD; out: @@ -6341,7 +6426,7 @@ glusterd_create_essential_dir_files(glusterd_volinfo_t *volinfo, dict_t *dict, ret = -1; goto out; } - ret = mkdir_p(buf, 0777, _gf_true); + ret = mkdir_p(buf, 0755, _gf_true); if (ret) { len = snprintf(errmsg, sizeof(errmsg), "Unable to create %s" @@ -6356,13 +6441,13 @@ glusterd_create_essential_dir_files(glusterd_volinfo_t *volinfo, dict_t *dict, goto out; } - ret = snprintf(buf, PATH_MAX, DEFAULT_LOG_FILE_DIRECTORY "/" GEOREP "/%s", + ret = snprintf(buf, PATH_MAX, "%s/" GEOREP "/%s", conf->logdir, volinfo->volname); if ((ret < 0) || (ret >= PATH_MAX)) { ret = -1; goto out; } - ret = mkdir_p(buf, 0777, _gf_true); + ret = mkdir_p(buf, 0755, _gf_true); if (ret) { len = snprintf(errmsg, sizeof(errmsg), "Unable to create %s" |
