summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-utils.c
diff options
context:
space:
mode:
authorAnuradha Talur <atalur@redhat.com>2016-03-16 10:55:09 +0530
committerAtin Mukherjee <amukherj@redhat.com>2016-03-23 03:21:38 -0700
commitf5f43424994859f263165f0cdebedffd5f08fdcc (patch)
treeed694b560f971b01462bfe8c17fbc4af875d572b /xlators/mgmt/glusterd/src/glusterd-utils.c
parent28f5829781dd7c4b16470c1dc4e748d24ace4616 (diff)
glusterd / afr : Enable auto heal when replica count increases
Backport of http://review.gluster.org/12451 In replicate volumes, when a brick is added to a replicate group, heal to the new brick should be triggered. Also, the new brick should not be considered as source for healing till it is up to date. Previously, extended attributes had to be set manually on the bricks for this to happen. This patch is part 1 patch to automate this process. >Change-Id: I29958448618372bfde23bf1dac5dd23dba1ad98f >BUG: 1276203 >Signed-off-by: Anuradha Talur <atalur@redhat.com> >Reviewed-on: http://review.gluster.org/12451 >Reviewed-by: Atin Mukherjee <amukherj@redhat.com> >NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> >CentOS-regression: Gluster Build System <jenkins@build.gluster.com> >Reviewed-by: Ravishankar N <ravishankar@redhat.com> >Smoke: Gluster Build System <jenkins@build.gluster.com> Signed-off-by: Anuradha Talur <atalur@redhat.com> Conflicts: libglusterfs/src/globals.h xlators/mgmt/glusterd/src/glusterd-replace-brick.c Change-Id: Ica83592aab8edbe49e2bb9d8d4824cf5c76324b7 BUG: 1320020 Reviewed-on: http://review.gluster.org/13806 Smoke: Gluster Build System <jenkins@build.gluster.com> Tested-by: Anuradha Talur <atalur@redhat.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-utils.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index cfee26dfe7e..c114f0349c7 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -7097,6 +7097,33 @@ void glusterd_update_tier_status (glusterd_volinfo_t *volinfo) {
}
int
+glusterd_get_dummy_client_filepath (char *filepath,
+ glusterd_volinfo_t *volinfo,
+ gf_transport_type type)
+{
+ int ret = 0;
+ char path[PATH_MAX] = {0,};
+
+ switch (type) {
+ case GF_TRANSPORT_TCP:
+ case GF_TRANSPORT_BOTH_TCP_RDMA:
+ snprintf (filepath, PATH_MAX,
+ "/tmp/%s.tcp-fuse.vol", volinfo->volname);
+ break;
+
+ case GF_TRANSPORT_RDMA:
+ snprintf (filepath, PATH_MAX,
+ "/tmp/%s.rdma-fuse.vol", volinfo->volname);
+ break;
+ default:
+ ret = -1;
+ break;
+ }
+
+ return ret;
+}
+
+int
glusterd_volume_defrag_restart (glusterd_volinfo_t *volinfo, char *op_errstr,
size_t len, int cmd, defrag_cbk_fn_t cbk)
{
@@ -11052,3 +11079,117 @@ gd_get_shd_key (int type)
}
return key;
}
+
+int
+glusterd_handle_replicate_brick_ops (glusterd_volinfo_t *volinfo,
+ glusterd_brickinfo_t *brickinfo,
+ glusterd_op_t op)
+{
+ int32_t ret = -1;
+ char tmpmount[] = "/tmp/mntXXXXXX";
+ char logfile[PATH_MAX] = {0,};
+ int dirty[3] = {0,};
+ runner_t runner = {0};
+ glusterd_conf_t *priv = NULL;
+ char *pid = NULL;
+ char vpath[PATH_MAX] = {0,};
+ char *volfileserver = NULL;
+
+ priv = THIS->private;
+ GF_VALIDATE_OR_GOTO (THIS->name, priv, out);
+
+ dirty[2] = hton32(1);
+
+ ret = sys_lsetxattr (brickinfo->path, GF_AFR_DIRTY, dirty,
+ sizeof (dirty), 0);
+ if (ret == -1) {
+ gf_msg (THIS->name, GF_LOG_ERROR, errno,
+ GD_MSG_SETXATTR_FAIL, "Failed to set extended"
+ " attribute %s : %s.", GF_AFR_DIRTY, strerror (errno));
+ goto out;
+ }
+
+ if (mkdtemp (tmpmount) == NULL) {
+ gf_msg (THIS->name, GF_LOG_ERROR, errno,
+ GD_MSG_DIR_OP_FAILED,
+ "failed to create a temporary mount directory.");
+ ret = -1;
+ goto out;
+ }
+
+ ret = gf_asprintf (&pid, "%d", GF_CLIENT_PID_SELF_HEALD);
+ if (ret < 0)
+ goto out;
+
+ switch (op) {
+ case GD_OP_REPLACE_BRICK:
+ if (dict_get_str (THIS->options, "transport.socket.bind-address",
+ &volfileserver) != 0)
+ volfileserver = "localhost";
+
+ snprintf (logfile, sizeof (logfile),
+ DEFAULT_LOG_FILE_DIRECTORY"/%s-replace-brick-mount.log",
+ volinfo->volname);
+ if (!*logfile) {
+ ret = -1;
+ goto out;
+ }
+ runinit (&runner);
+ runner_add_args (&runner, SBIN_DIR"/glusterfs",
+ "-s", volfileserver,
+ "--volfile-id", volinfo->volname,
+ "--client-pid", pid,
+ "-l", logfile, tmpmount, NULL);
+ break;
+
+ case GD_OP_ADD_BRICK:
+ snprintf (logfile, sizeof (logfile),
+ DEFAULT_LOG_FILE_DIRECTORY"/%s-add-brick-mount.log",
+ volinfo->volname);
+ if (!*logfile) {
+ ret = -1;
+ goto out;
+ }
+ ret = glusterd_get_dummy_client_filepath (vpath, volinfo,
+ volinfo->transport_type);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Failed to get "
+ "volfile path");
+ goto out;
+ }
+ runinit (&runner);
+ runner_add_args (&runner, SBIN_DIR"/glusterfs",
+ "--volfile", vpath,
+ "--client-pid", pid,
+ "-l", logfile, tmpmount, NULL);
+ break;
+ default:
+ break;
+ }
+ synclock_unlock (&priv->big_lock);
+ ret = runner_run (&runner);
+
+ if (ret) {
+ gf_log (THIS->name, GF_LOG_ERROR, "mount command"
+ " failed.");
+ goto lock;
+ }
+ ret = sys_lsetxattr (tmpmount, (op == GD_OP_REPLACE_BRICK) ?
+ GF_AFR_REPLACE_BRICK : GF_AFR_ADD_BRICK,
+ brickinfo->brick_id, sizeof (brickinfo->brick_id),
+ 0);
+ if (ret == -1)
+ gf_msg (THIS->name, GF_LOG_ERROR, errno,
+ GD_MSG_SETXATTR_FAIL, "Failed to set extended"
+ " attribute %s : %s", (op == GD_OP_REPLACE_BRICK) ?
+ GF_AFR_REPLACE_BRICK : GF_AFR_ADD_BRICK,
+ strerror (errno));
+ gf_umount_lazy (THIS->name, tmpmount, 1);
+lock:
+ synclock_lock (&priv->big_lock);
+out:
+ if (pid)
+ GF_FREE (pid);
+ gf_msg_debug ("glusterd", 0, "Returning with ret");
+ return ret;
+}