summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c412
1 files changed, 4 insertions, 408 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
index d3ad906705c..aa9010f20b2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
@@ -26,6 +26,9 @@
#include "glusterd-utils.h"
#include "glusterd-store.h"
#include "glusterd-volgen.h"
+#include "glusterd-snapd-svc.h"
+#include "glusterd-svc-helper.h"
+#include "glusterd-snapd-svc-helper.h"
#include "glusterd-snapshot-utils.h"
/*
@@ -1721,12 +1724,6 @@ out:
return ret;
}
-struct rpc_clnt*
-glusterd_snapd_get_rpc (glusterd_volinfo_t *volinfo)
-{
- return volinfo->snapd.rpc;
-}
-
int32_t
glusterd_add_snapd_to_dict (glusterd_volinfo_t *volinfo,
dict_t *dict, int32_t count)
@@ -1767,7 +1764,7 @@ glusterd_add_snapd_to_dict (glusterd_volinfo_t *volinfo,
if (ret)
goto out;
- glusterd_get_snapd_pidfile (volinfo, pidfile, sizeof (pidfile));
+ glusterd_svc_build_snapd_pidfile (volinfo, pidfile, sizeof (pidfile));
brick_online = gf_is_service_running (pidfile, &pid);
@@ -3231,407 +3228,6 @@ glusterd_is_snapd_enabled (glusterd_volinfo_t *volinfo)
return ret;
}
-void
-glusterd_get_snapd_rundir (glusterd_volinfo_t *volinfo,
- char *path, int path_len)
-{
- char workdir[PATH_MAX] = {0,};
- glusterd_conf_t *priv = THIS->private;
-
- GLUSTERD_GET_VOLUME_DIR (workdir, volinfo, priv);
-
- snprintf (path, path_len, "%s/run", workdir);
-}
-
-void
-glusterd_get_snapd_volfile (glusterd_volinfo_t *volinfo,
- char *path, int path_len)
-{
- char workdir[PATH_MAX] = {0,};
- glusterd_conf_t *priv = THIS->private;
-
- GLUSTERD_GET_VOLUME_DIR (workdir, volinfo, priv);
-
- snprintf (path, path_len, "%s/%s-snapd.vol", workdir,
- volinfo->volname);
-}
-
-void
-glusterd_get_snapd_pidfile (glusterd_volinfo_t *volinfo,
- char *path, int path_len)
-{
- char rundir[PATH_MAX] = {0,};
-
- glusterd_get_snapd_rundir (volinfo, rundir, sizeof (rundir));
-
- snprintf (path, path_len, "%s/%s-snapd.pid", rundir, volinfo->volname);
-}
-
-void
-glusterd_set_snapd_socket_filepath (glusterd_volinfo_t *volinfo,
- char *path, int path_len)
-{
- char sockfilepath[PATH_MAX] = {0,};
- char rundir[PATH_MAX] = {0,};
-
- glusterd_get_snapd_rundir (volinfo, rundir, sizeof (rundir));
- snprintf (sockfilepath, sizeof (sockfilepath), "%s/run-%s",
- rundir, uuid_utoa (MY_UUID));
-
- glusterd_set_socket_filepath (sockfilepath, path, path_len);
-}
-
-gf_boolean_t
-glusterd_is_snapd_running (glusterd_volinfo_t *volinfo)
-{
- char pidfile[PATH_MAX] = {0,};
- int pid = -1;
- glusterd_conf_t *priv = THIS->private;
-
- glusterd_get_snapd_pidfile (volinfo, pidfile,
- sizeof (pidfile));
-
- return gf_is_service_running (pidfile, &pid);
-}
-
-int
-glusterd_restart_snapds (glusterd_conf_t *priv)
-{
- glusterd_volinfo_t *volinfo = NULL;
- int ret = 0;
- xlator_t *this = THIS;
-
- list_for_each_entry (volinfo, &priv->volumes, vol_list) {
- if (volinfo->status == GLUSTERD_STATUS_STARTED &&
- glusterd_is_snapd_enabled (volinfo)) {
- ret = glusterd_snapd_start (volinfo,
- _gf_false);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "Couldn't start snapd for "
- "vol: %s", volinfo->volname);
- goto out;
- }
- }
- }
-out:
- return ret;
-}
-
-gf_boolean_t
-glusterd_is_snapd_online (glusterd_volinfo_t *volinfo)
-{
- return volinfo->snapd.online;
-}
-
-void
-glusterd_snapd_set_online_status (glusterd_volinfo_t *volinfo,
- gf_boolean_t status)
-{
- volinfo->snapd.online = status;
-}
-
-static inline void
-glusterd_snapd_set_rpc (glusterd_volinfo_t *volinfo, struct rpc_clnt *rpc)
-{
- volinfo->snapd.rpc = rpc;
-}
-
-int32_t
-glusterd_snapd_connect (glusterd_volinfo_t *volinfo, char *socketpath)
-{
- int ret = 0;
- dict_t *options = NULL;
- struct rpc_clnt *rpc = NULL;
- glusterd_conf_t *priv = THIS->private;
-
- rpc = glusterd_snapd_get_rpc (volinfo);
-
- if (rpc == NULL) {
- /* Setting frame-timeout to 10mins (600seconds).
- * Unix domain sockets ensures that the connection is reliable.
- * The default timeout of 30mins used for unreliable network
- * connections is too long for unix domain socket connections.
- */
- ret = rpc_transport_unix_options_build (&options, socketpath,
- 600);
- if (ret)
- goto out;
-
- ret = dict_set_str(options,
- "transport.socket.ignore-enoent", "on");
- if (ret)
- goto out;
-
- glusterd_volinfo_ref (volinfo);
-
- synclock_unlock (&priv->big_lock);
- ret = glusterd_rpc_create (&rpc, options,
- glusterd_snapd_rpc_notify,
- volinfo);
- synclock_lock (&priv->big_lock);
- if (ret)
- goto out;
-
- (void) glusterd_snapd_set_rpc (volinfo, rpc);
- }
-out:
- return ret;
-}
-
-int32_t
-glusterd_snapd_disconnect (glusterd_volinfo_t *volinfo)
-{
- struct rpc_clnt *rpc = NULL;
- glusterd_conf_t *priv = THIS->private;
-
- rpc = glusterd_snapd_get_rpc (volinfo);
-
- (void) glusterd_snapd_set_rpc (volinfo, NULL);
-
- if (rpc)
- glusterd_rpc_clnt_unref (priv, rpc);
-
- return 0;
-}
-
-int32_t
-glusterd_snapd_start (glusterd_volinfo_t *volinfo, gf_boolean_t wait)
-{
- int32_t ret = -1;
- xlator_t *this = NULL;
- glusterd_conf_t *priv = NULL;
- runner_t runner = {0,};
- char pidfile[PATH_MAX] = {0,};
- char logfile[PATH_MAX] = {0,};
- char logdir[PATH_MAX] = {0,};
- char volfile[PATH_MAX] = {0,};
- char glusterd_uuid[1024] = {0,};
- char rundir[PATH_MAX] = {0,};
- char sockfpath[PATH_MAX] = {0,};
- char volfileid[256] = {0};
- char *volfileserver = NULL;
- char valgrind_logfile[PATH_MAX] = {0};
- int snapd_port = 0;
- char *volname = volinfo->volname;
- char snapd_id[PATH_MAX] = {0,};
- char msg[1024] = {0,};
-
- this = THIS;
- GF_ASSERT(this);
-
- if (glusterd_is_snapd_running (volinfo)) {
- ret = 0;
- goto connect;
- }
-
- priv = this->private;
-
- glusterd_get_snapd_rundir (volinfo, rundir, sizeof (rundir));
- ret = mkdir (rundir, 0777);
-
- if ((ret == -1) && (EEXIST != errno)) {
- gf_log (this->name, GF_LOG_ERROR, "Unable to create rundir %s",
- rundir);
- goto out;
- }
-
- glusterd_get_snapd_pidfile (volinfo, pidfile, sizeof (pidfile));
- glusterd_get_snapd_volfile (volinfo, volfile, sizeof (volfile));
-
- ret = sys_access (volfile, F_OK);
- if (ret) {
- gf_log (this->name, GF_LOG_DEBUG,
- "snapd Volfile %s is not present", volfile);
-
- /* If glusterd is down on one of the nodes and during
- * that time "USS is enabled" for the first time. After some
- * time when the glusterd which was down comes back it tries
- * to look for the snapd volfile and it does not find snapd
- * volfile and because of this starting of snapd fails.
- * Therefore, if volfile is not present then create a fresh
- * volfile.
- */
- ret = glusterd_create_snapd_volfile (volinfo);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Couldn't create "
- "snapd volfile for volume: %s",
- volinfo->volname);
- goto out;
- }
- }
-
- snprintf (logdir, PATH_MAX, "%s/snaps/%s",
- DEFAULT_LOG_FILE_DIRECTORY, volname);
- ret = mkdir_p (logdir, 0755, _gf_true);
- if ((ret == -1) && (EEXIST != errno)) {
- gf_log (this->name, GF_LOG_ERROR, "Unable to create logdir %s",
- logdir);
- goto out;
- }
-
- snprintf (logfile, PATH_MAX, "%s/snapd.log", logdir);
-
- snprintf (volfileid, sizeof (volfileid), "snapd/%s", volname);
- glusterd_set_snapd_socket_filepath (volinfo, sockfpath,
- sizeof (sockfpath));
-
- if (dict_get_str (this->options, "transport.socket.bind-address",
- &volfileserver) != 0) {
- volfileserver = "localhost";
- }
-
- runinit (&runner);
-
- if (priv->valgrind) {
- snprintf (valgrind_logfile, PATH_MAX, "%s/valgrind-snapd.log",
- logdir);
-
- runner_add_args (&runner, "valgrind", "--leak-check=full",
- "--trace-children=yes", "--track-origins=yes",
- NULL);
- runner_argprintf (&runner, "--log-file=%s", valgrind_logfile);
- }
-
- snprintf (snapd_id, sizeof (snapd_id), "snapd-%s", volname);
- runner_add_args (&runner, SBIN_DIR"/glusterfsd",
- "-s", volfileserver,
- "--volfile-id", volfileid,
- "-p", pidfile,
- "-l", logfile,
- "--brick-name", snapd_id,
- "-S", sockfpath, NULL);
-
- snapd_port = volinfo->snapd.port;
- if (!snapd_port) {
- snapd_port = pmap_registry_alloc (THIS);
- if (!snapd_port) {
- snprintf (msg, sizeof (msg), "Could not allocate port "
- "for snapd service for volume %s", volname);
-
- runner_log (&runner, this->name, GF_LOG_DEBUG, msg);
- ret = -1;
- goto out;
- }
- }
-
- runner_add_arg (&runner, "--brick-port");
- runner_argprintf (&runner, "%d", snapd_port);
- runner_add_arg (&runner, "--xlator-option");
- runner_argprintf (&runner, "%s-server.listen-port=%d",
- volname, snapd_port);
- runner_add_arg (&runner, "--no-mem-accounting");
-
- snprintf (msg, sizeof (msg),
- "Starting the snapd service for volume %s", volname);
- runner_log (&runner, this->name, GF_LOG_DEBUG, msg);
-
- if (!wait) {
- ret = runner_run_nowait (&runner);
- } else {
- synclock_unlock (&priv->big_lock);
- {
- ret = runner_run (&runner);
- }
- synclock_lock (&priv->big_lock);
- }
-
- volinfo->snapd.port = snapd_port;
-
-connect:
- if (ret == 0)
- glusterd_snapd_connect (volinfo, sockfpath);
-
-out:
- return ret;
-}
-
-int
-glusterd_snapd_stop (glusterd_volinfo_t *volinfo)
-{
- char pidfile[PATH_MAX] = {0,};
- char sockfpath[PATH_MAX] = {0,};
- glusterd_conf_t *priv = THIS->private;
- int ret = 0;
-
- (void)glusterd_snapd_disconnect (volinfo);
-
- if (!glusterd_is_snapd_running (volinfo))
- goto out;
-
- glusterd_get_snapd_pidfile (volinfo, pidfile, sizeof (pidfile));
- ret = glusterd_service_stop ("snapd", pidfile, SIGTERM, _gf_true);
-
- if (ret == 0) {
- glusterd_set_snapd_socket_filepath (volinfo, sockfpath,
- sizeof (sockfpath));
- (void)glusterd_unlink_file (sockfpath);
- }
-out:
- return ret;
-}
-
-int
-glusterd_handle_snapd_option (glusterd_volinfo_t *volinfo)
-{
- int ret = 0;
- xlator_t *this = THIS;
-
- if (volinfo->is_snap_volume)
- return 0;
-
- ret = glusterd_is_snapd_enabled (volinfo);
- if (ret == -1) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to read volume "
- "options");
- goto out;
- }
-
- if (ret) {
- if (!glusterd_is_volume_started (volinfo)) {
- if (glusterd_is_snapd_running (volinfo)) {
- ret = glusterd_snapd_stop (volinfo);
- if (ret)
- gf_log (this->name, GF_LOG_ERROR,
- "Couldn't stop snapd for "
- "volume: %s",
- volinfo->volname);
- } else {
- /* Since snapd is not running set ret to 0 */
- ret = 0;
- }
- goto out;
- }
-
- ret = glusterd_create_snapd_volfile (volinfo);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Couldn't create "
- "snapd volfile for volume: %s",
- volinfo->volname);
- goto out;
- }
-
- ret = glusterd_snapd_start (volinfo, _gf_false);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Couldn't start "
- "snapd for volume: %s", volinfo->volname);
- goto out;
- }
-
- } else if (glusterd_is_snapd_running (volinfo)) {
- ret = glusterd_snapd_stop (volinfo);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "Couldn't stop snapd for volume: %s",
- volinfo->volname);
- goto out;
- }
- volinfo->snapd.port = 0;
- }
-
-out:
- return ret;
-}
int32_t
glusterd_is_snap_soft_limit_reached (glusterd_volinfo_t *volinfo, dict_t *dict)