|
|
12a457 |
From 2b95b8fad1c35aaa995c664cf668a9be0d8c621b Mon Sep 17 00:00:00 2001
|
|
|
12a457 |
From: Anuradha Talur <atalur@redhat.com>
|
|
|
12a457 |
Date: Wed, 16 Mar 2016 10:55:09 +0530
|
|
|
12a457 |
Subject: [PATCH 44/80] glusterd / afr : Enable auto heal when replica count increases
|
|
|
12a457 |
|
|
|
12a457 |
Backport of http://review.gluster.org/13806
|
|
|
12a457 |
|
|
|
12a457 |
In replicate volumes, when a brick is added to a replicate
|
|
|
12a457 |
group, heal to the new brick should be triggered.
|
|
|
12a457 |
Also, the new brick should not be considered as source for
|
|
|
12a457 |
healing till it is up to date.
|
|
|
12a457 |
|
|
|
12a457 |
Previously, extended attributes had to be set manually on
|
|
|
12a457 |
the bricks for this to happen. This patch is part 1 patch
|
|
|
12a457 |
to automate this process.
|
|
|
12a457 |
|
|
|
12a457 |
>Change-Id: Ica83592aab8edbe49e2bb9d8d4824cf5c76324b7
|
|
|
12a457 |
>BUG: 1320020
|
|
|
12a457 |
>Reviewed-on: http://review.gluster.org/13806
|
|
|
12a457 |
>Smoke: Gluster Build System <jenkins@build.gluster.com>
|
|
|
12a457 |
>Tested-by: Anuradha Talur <atalur@redhat.com>
|
|
|
12a457 |
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
|
|
|
12a457 |
>CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
|
|
|
12a457 |
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
|
|
|
12a457 |
|
|
|
12a457 |
Change-Id: I183fd491d94534cf72e0bcc691911555b350fa17
|
|
|
12a457 |
BUG: 1248998
|
|
|
12a457 |
Signed-off-by: Anuradha Talur <atalur@redhat.com>
|
|
|
12a457 |
Reviewed-on: https://code.engineering.redhat.com/gerrit/71424
|
|
|
12a457 |
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
|
|
|
12a457 |
---
|
|
|
12a457 |
libglusterfs/src/globals.h | 2 +-
|
|
|
12a457 |
libglusterfs/src/glusterfs.h | 1 +
|
|
|
12a457 |
xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 86 ++++++++++---
|
|
|
12a457 |
xlators/mgmt/glusterd/src/glusterd-replace-brick.c | 76 +----------
|
|
|
12a457 |
xlators/mgmt/glusterd/src/glusterd-utils.c | 141 ++++++++++++++++++++
|
|
|
12a457 |
xlators/mgmt/glusterd/src/glusterd-utils.h | 10 ++
|
|
|
12a457 |
xlators/mgmt/glusterd/src/glusterd-volgen.c | 52 +++++++
|
|
|
12a457 |
xlators/mgmt/glusterd/src/glusterd-volgen.h | 3 +
|
|
|
12a457 |
8 files changed, 280 insertions(+), 91 deletions(-)
|
|
|
12a457 |
|
|
|
12a457 |
diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h
|
|
|
12a457 |
index ad0aef8..4fe4bcb 100644
|
|
|
12a457 |
--- a/libglusterfs/src/globals.h
|
|
|
12a457 |
+++ b/libglusterfs/src/globals.h
|
|
|
12a457 |
@@ -42,7 +42,7 @@
|
|
|
12a457 |
*/
|
|
|
12a457 |
#define GD_OP_VERSION_MIN 1 /* MIN is the fresh start op-version, mostly
|
|
|
12a457 |
should not change */
|
|
|
12a457 |
-#define GD_OP_VERSION_MAX GD_OP_VERSION_3_7_7 /* MAX VERSION is the maximum
|
|
|
12a457 |
+#define GD_OP_VERSION_MAX GD_OP_VERSION_3_7_10 /* MAX VERSION is the maximum
|
|
|
12a457 |
count in VME table, should
|
|
|
12a457 |
keep changing with
|
|
|
12a457 |
introduction of newer
|
|
|
12a457 |
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
|
|
|
12a457 |
index 81caf12..d1db087 100644
|
|
|
12a457 |
--- a/libglusterfs/src/glusterfs.h
|
|
|
12a457 |
+++ b/libglusterfs/src/glusterfs.h
|
|
|
12a457 |
@@ -176,6 +176,7 @@
|
|
|
12a457 |
#define GF_AFR_SBRAIN_CHOICE "replica.split-brain-choice"
|
|
|
12a457 |
#define GF_AFR_SPB_CHOICE_TIMEOUT "replica.split-brain-choice-timeout"
|
|
|
12a457 |
#define GF_AFR_SBRAIN_RESOLVE "replica.split-brain-heal-finalize"
|
|
|
12a457 |
+#define GF_AFR_ADD_BRICK "trusted.add-brick"
|
|
|
12a457 |
#define GF_AFR_REPLACE_BRICK "trusted.replace-brick"
|
|
|
12a457 |
#define GF_AFR_DIRTY "trusted.afr.dirty"
|
|
|
12a457 |
|
|
|
12a457 |
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
|
|
|
12a457 |
index 859795b..540f8f7 100644
|
|
|
12a457 |
--- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
|
|
|
12a457 |
+++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
|
|
|
12a457 |
@@ -26,6 +26,7 @@
|
|
|
12a457 |
#include "glusterd-messages.h"
|
|
|
12a457 |
#include "glusterd-server-quorum.h"
|
|
|
12a457 |
#include "run.h"
|
|
|
12a457 |
+#include "glusterd-volgen.h"
|
|
|
12a457 |
#include <sys/signal.h>
|
|
|
12a457 |
|
|
|
12a457 |
/* misc */
|
|
|
12a457 |
@@ -1238,6 +1239,7 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count,
|
|
|
12a457 |
char *brick_mount_dir = NULL;
|
|
|
12a457 |
xlator_t *this = NULL;
|
|
|
12a457 |
glusterd_conf_t *conf = NULL;
|
|
|
12a457 |
+ gf_boolean_t is_valid_add_brick = _gf_false;
|
|
|
12a457 |
|
|
|
12a457 |
this = THIS;
|
|
|
12a457 |
GF_ASSERT (this);
|
|
|
12a457 |
@@ -1325,6 +1327,7 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count,
|
|
|
12a457 |
/* Gets changed only if the options are given in add-brick cli */
|
|
|
12a457 |
if (type)
|
|
|
12a457 |
volinfo->type = type;
|
|
|
12a457 |
+
|
|
|
12a457 |
if (replica_count) {
|
|
|
12a457 |
volinfo->replica_count = replica_count;
|
|
|
12a457 |
}
|
|
|
12a457 |
@@ -1360,6 +1363,27 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count,
|
|
|
12a457 |
CAPS_OFFLOAD_COPY | CAPS_OFFLOAD_SNAPSHOT;
|
|
|
12a457 |
#endif
|
|
|
12a457 |
|
|
|
12a457 |
+ /* This check needs to be added to distinguish between
|
|
|
12a457 |
+ * attach-tier commands and add-brick commands.
|
|
|
12a457 |
+ * When a tier is attached, adding is done via add-brick
|
|
|
12a457 |
+ * and setting of pending xattrs shouldn't be done for
|
|
|
12a457 |
+ * attach-tiers as they are virtually new volumes.
|
|
|
12a457 |
+ */
|
|
|
12a457 |
+ if (glusterd_is_volume_replicate (volinfo)) {
|
|
|
12a457 |
+ if (replica_count &&
|
|
|
12a457 |
+ !dict_get (dict, "attach-tier") &&
|
|
|
12a457 |
+ conf->op_version >= GD_OP_VERSION_3_7_10) {
|
|
|
12a457 |
+ is_valid_add_brick = _gf_true;
|
|
|
12a457 |
+ ret = generate_dummy_client_volfiles (volinfo);
|
|
|
12a457 |
+ if (ret) {
|
|
|
12a457 |
+ gf_msg (THIS->name, GF_LOG_ERROR, 0,
|
|
|
12a457 |
+ GD_MSG_VOLFILE_CREATE_FAIL,
|
|
|
12a457 |
+ "Failed to create volfile.");
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+
|
|
|
12a457 |
while (i <= count) {
|
|
|
12a457 |
ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo,
|
|
|
12a457 |
&brickinfo);
|
|
|
12a457 |
@@ -1391,6 +1415,16 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count,
|
|
|
12a457 |
}
|
|
|
12a457 |
}
|
|
|
12a457 |
|
|
|
12a457 |
+ /* if the volume is a replicate volume, do: */
|
|
|
12a457 |
+ if (is_valid_add_brick) {
|
|
|
12a457 |
+ if (!gf_uuid_compare (brickinfo->uuid, MY_UUID)) {
|
|
|
12a457 |
+ ret = glusterd_handle_replicate_brick_ops (
|
|
|
12a457 |
+ volinfo, brickinfo,
|
|
|
12a457 |
+ GD_OP_ADD_BRICK);
|
|
|
12a457 |
+ if (ret < 0)
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ }
|
|
|
12a457 |
ret = glusterd_brick_start (volinfo, brickinfo,
|
|
|
12a457 |
_gf_true);
|
|
|
12a457 |
if (ret)
|
|
|
12a457 |
@@ -1519,22 +1553,6 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
|
|
|
12a457 |
conf = this->private;
|
|
|
12a457 |
GF_ASSERT (conf);
|
|
|
12a457 |
|
|
|
12a457 |
- ret = dict_get_int32 (dict, "replica-count", &replica_count);
|
|
|
12a457 |
- if (ret) {
|
|
|
12a457 |
- gf_msg_debug (THIS->name, 0,
|
|
|
12a457 |
- "Unable to get replica count");
|
|
|
12a457 |
- }
|
|
|
12a457 |
-
|
|
|
12a457 |
- if (replica_count > 0) {
|
|
|
12a457 |
- ret = op_version_check (this, GD_OP_VER_PERSISTENT_AFR_XATTRS,
|
|
|
12a457 |
- msg, sizeof(msg));
|
|
|
12a457 |
- if (ret) {
|
|
|
12a457 |
- gf_msg (this->name, GF_LOG_ERROR, 0,
|
|
|
12a457 |
- GD_MSG_OP_VERSION_MISMATCH, "%s", msg);
|
|
|
12a457 |
- *op_errstr = gf_strdup (msg);
|
|
|
12a457 |
- goto out;
|
|
|
12a457 |
- }
|
|
|
12a457 |
- }
|
|
|
12a457 |
ret = dict_get_str (dict, "volname", &volname);
|
|
|
12a457 |
if (ret) {
|
|
|
12a457 |
gf_msg (THIS->name, GF_LOG_ERROR, errno,
|
|
|
12a457 |
@@ -1555,6 +1573,42 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
|
|
|
12a457 |
if (ret)
|
|
|
12a457 |
goto out;
|
|
|
12a457 |
|
|
|
12a457 |
+ ret = dict_get_int32 (dict, "replica-count", &replica_count);
|
|
|
12a457 |
+ if (ret) {
|
|
|
12a457 |
+ gf_msg_debug (THIS->name, 0,
|
|
|
12a457 |
+ "Unable to get replica count");
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+
|
|
|
12a457 |
+ if (replica_count > 0) {
|
|
|
12a457 |
+ ret = op_version_check (this, GD_OP_VER_PERSISTENT_AFR_XATTRS,
|
|
|
12a457 |
+ msg, sizeof(msg));
|
|
|
12a457 |
+ if (ret) {
|
|
|
12a457 |
+ gf_msg (this->name, GF_LOG_ERROR, 0,
|
|
|
12a457 |
+ GD_MSG_OP_VERSION_MISMATCH, "%s", msg);
|
|
|
12a457 |
+ *op_errstr = gf_strdup (msg);
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+
|
|
|
12a457 |
+ /* Do not allow add-brick for stopped volumes when replica-count
|
|
|
12a457 |
+ * is being increased.
|
|
|
12a457 |
+ */
|
|
|
12a457 |
+ if (glusterd_is_volume_replicate (volinfo)) {
|
|
|
12a457 |
+ if (conf->op_version >= GD_OP_VERSION_3_7_10 &&
|
|
|
12a457 |
+ !dict_get (dict, "attach-tier") &&
|
|
|
12a457 |
+ replica_count &&
|
|
|
12a457 |
+ GLUSTERD_STATUS_STOPPED == volinfo->status) {
|
|
|
12a457 |
+ ret = -1;
|
|
|
12a457 |
+ snprintf (msg, sizeof (msg), " Volume must not be in"
|
|
|
12a457 |
+ " stopped state when replica-count needs to "
|
|
|
12a457 |
+ " be increased.");
|
|
|
12a457 |
+ gf_msg (THIS->name, GF_LOG_ERROR, 0,
|
|
|
12a457 |
+ GD_MSG_BRICK_ADD_FAIL, "%s", msg);
|
|
|
12a457 |
+ *op_errstr = gf_strdup (msg);
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+
|
|
|
12a457 |
if (conf->op_version > GD_OP_VERSION_3_7_5 &&
|
|
|
12a457 |
is_origin_glusterd (dict)) {
|
|
|
12a457 |
ret = glusterd_validate_quorum (this, GD_OP_ADD_BRICK, dict,
|
|
|
12a457 |
diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
|
|
|
12a457 |
index d0a1126..ecfdc0a 100644
|
|
|
12a457 |
--- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
|
|
|
12a457 |
+++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
|
|
|
12a457 |
@@ -44,78 +44,6 @@ glusterd_mgmt_v3_initiate_replace_brick_cmd_phases (rpcsvc_request_t *req,
|
|
|
12a457 |
glusterd_op_t op,
|
|
|
12a457 |
dict_t *dict);
|
|
|
12a457 |
int
|
|
|
12a457 |
-glusterd_handle_replicate_replace_brick (glusterd_volinfo_t *volinfo,
|
|
|
12a457 |
- glusterd_brickinfo_t *brickinfo)
|
|
|
12a457 |
-{
|
|
|
12a457 |
- int32_t ret = -1;
|
|
|
12a457 |
- char tmpmount[] = "/tmp/mntXXXXXX";
|
|
|
12a457 |
- char logfile[PATH_MAX] = {0,};
|
|
|
12a457 |
- int dirty[3] = {0,};
|
|
|
12a457 |
- runner_t runner = {0};
|
|
|
12a457 |
- glusterd_conf_t *priv = NULL;
|
|
|
12a457 |
- char *pid = NULL;
|
|
|
12a457 |
-
|
|
|
12a457 |
- priv = THIS->private;
|
|
|
12a457 |
-
|
|
|
12a457 |
- dirty[2] = hton32(1);
|
|
|
12a457 |
-
|
|
|
12a457 |
- ret = sys_lsetxattr (brickinfo->path, GF_AFR_DIRTY, dirty,
|
|
|
12a457 |
- sizeof (dirty), 0);
|
|
|
12a457 |
- if (ret == -1) {
|
|
|
12a457 |
- gf_msg (THIS->name, GF_LOG_ERROR, errno,
|
|
|
12a457 |
- GD_MSG_SETXATTR_FAIL, "Failed to set extended"
|
|
|
12a457 |
- " attribute %s : %s.", GF_AFR_DIRTY, strerror (errno));
|
|
|
12a457 |
- goto out;
|
|
|
12a457 |
- }
|
|
|
12a457 |
-
|
|
|
12a457 |
- if (mkdtemp (tmpmount) == NULL) {
|
|
|
12a457 |
- gf_msg (THIS->name, GF_LOG_ERROR, errno,
|
|
|
12a457 |
- GD_MSG_DIR_OP_FAILED,
|
|
|
12a457 |
- "failed to create a temporary mount directory.");
|
|
|
12a457 |
- ret = -1;
|
|
|
12a457 |
- goto out;
|
|
|
12a457 |
- }
|
|
|
12a457 |
- snprintf (logfile, sizeof (logfile),
|
|
|
12a457 |
- DEFAULT_LOG_FILE_DIRECTORY"/%s-replace-brick-mount.log",
|
|
|
12a457 |
- volinfo->volname);
|
|
|
12a457 |
-
|
|
|
12a457 |
- ret = gf_asprintf (&pid, "%d", GF_CLIENT_PID_SELF_HEALD);
|
|
|
12a457 |
- if (ret < 0)
|
|
|
12a457 |
- goto out;
|
|
|
12a457 |
-
|
|
|
12a457 |
- runinit (&runner);
|
|
|
12a457 |
- runner_add_args (&runner, SBIN_DIR"/glusterfs",
|
|
|
12a457 |
- "-s", "localhost",
|
|
|
12a457 |
- "--volfile-id", volinfo->volname,
|
|
|
12a457 |
- "--client-pid", pid,
|
|
|
12a457 |
- "-l", logfile, tmpmount, NULL);
|
|
|
12a457 |
- synclock_unlock (&priv->big_lock);
|
|
|
12a457 |
- ret = runner_run (&runner);
|
|
|
12a457 |
-
|
|
|
12a457 |
- if (ret) {
|
|
|
12a457 |
- runner_log (&runner, THIS->name, GF_LOG_ERROR, "mount command"
|
|
|
12a457 |
- "failed.");
|
|
|
12a457 |
- goto lock;
|
|
|
12a457 |
- }
|
|
|
12a457 |
- ret = sys_lsetxattr (tmpmount, GF_AFR_REPLACE_BRICK,
|
|
|
12a457 |
- brickinfo->brick_id, sizeof (brickinfo->brick_id),
|
|
|
12a457 |
- 0);
|
|
|
12a457 |
- if (ret == -1)
|
|
|
12a457 |
- gf_msg (THIS->name, GF_LOG_ERROR, errno,
|
|
|
12a457 |
- GD_MSG_SETXATTR_FAIL, "Failed to set extended"
|
|
|
12a457 |
- " attribute %s : %s", GF_AFR_REPLACE_BRICK,
|
|
|
12a457 |
- strerror (errno));
|
|
|
12a457 |
- gf_umount_lazy (THIS->name, tmpmount, 1);
|
|
|
12a457 |
-lock:
|
|
|
12a457 |
- synclock_lock (&priv->big_lock);
|
|
|
12a457 |
-out:
|
|
|
12a457 |
- if (pid)
|
|
|
12a457 |
- GF_FREE (pid);
|
|
|
12a457 |
- gf_msg_debug ("glusterd", 0, "Returning with ret");
|
|
|
12a457 |
- return ret;
|
|
|
12a457 |
-}
|
|
|
12a457 |
-
|
|
|
12a457 |
-int
|
|
|
12a457 |
__glusterd_handle_replace_brick (rpcsvc_request_t *req)
|
|
|
12a457 |
{
|
|
|
12a457 |
int32_t ret = -1;
|
|
|
12a457 |
@@ -659,8 +587,8 @@ glusterd_op_perform_replace_brick (glusterd_volinfo_t *volinfo,
|
|
|
12a457 |
/* if the volume is a replicate volume, do: */
|
|
|
12a457 |
if (glusterd_is_volume_replicate (volinfo)) {
|
|
|
12a457 |
if (!gf_uuid_compare (new_brickinfo->uuid, MY_UUID)) {
|
|
|
12a457 |
- ret = glusterd_handle_replicate_replace_brick
|
|
|
12a457 |
- (volinfo, new_brickinfo);
|
|
|
12a457 |
+ ret = glusterd_handle_replicate_brick_ops (volinfo,
|
|
|
12a457 |
+ new_brickinfo, GD_OP_REPLACE_BRICK);
|
|
|
12a457 |
if (ret < 0)
|
|
|
12a457 |
goto out;
|
|
|
12a457 |
}
|
|
|
12a457 |
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
|
|
|
12a457 |
index bc4f7ae..639404a 100644
|
|
|
12a457 |
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
|
|
|
12a457 |
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
|
|
|
12a457 |
@@ -7102,6 +7102,33 @@ void glusterd_update_tier_status (glusterd_volinfo_t *volinfo) {
|
|
|
12a457 |
}
|
|
|
12a457 |
|
|
|
12a457 |
int
|
|
|
12a457 |
+glusterd_get_dummy_client_filepath (char *filepath,
|
|
|
12a457 |
+ glusterd_volinfo_t *volinfo,
|
|
|
12a457 |
+ gf_transport_type type)
|
|
|
12a457 |
+{
|
|
|
12a457 |
+ int ret = 0;
|
|
|
12a457 |
+ char path[PATH_MAX] = {0,};
|
|
|
12a457 |
+
|
|
|
12a457 |
+ switch (type) {
|
|
|
12a457 |
+ case GF_TRANSPORT_TCP:
|
|
|
12a457 |
+ case GF_TRANSPORT_BOTH_TCP_RDMA:
|
|
|
12a457 |
+ snprintf (filepath, PATH_MAX,
|
|
|
12a457 |
+ "/tmp/%s.tcp-fuse.vol", volinfo->volname);
|
|
|
12a457 |
+ break;
|
|
|
12a457 |
+
|
|
|
12a457 |
+ case GF_TRANSPORT_RDMA:
|
|
|
12a457 |
+ snprintf (filepath, PATH_MAX,
|
|
|
12a457 |
+ "/tmp/%s.rdma-fuse.vol", volinfo->volname);
|
|
|
12a457 |
+ break;
|
|
|
12a457 |
+ default:
|
|
|
12a457 |
+ ret = -1;
|
|
|
12a457 |
+ break;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+
|
|
|
12a457 |
+ return ret;
|
|
|
12a457 |
+}
|
|
|
12a457 |
+
|
|
|
12a457 |
+int
|
|
|
12a457 |
glusterd_volume_defrag_restart (glusterd_volinfo_t *volinfo, char *op_errstr,
|
|
|
12a457 |
size_t len, int cmd, defrag_cbk_fn_t cbk)
|
|
|
12a457 |
{
|
|
|
12a457 |
@@ -11057,3 +11084,117 @@ gd_get_shd_key (int type)
|
|
|
12a457 |
}
|
|
|
12a457 |
return key;
|
|
|
12a457 |
}
|
|
|
12a457 |
+
|
|
|
12a457 |
+int
|
|
|
12a457 |
+glusterd_handle_replicate_brick_ops (glusterd_volinfo_t *volinfo,
|
|
|
12a457 |
+ glusterd_brickinfo_t *brickinfo,
|
|
|
12a457 |
+ glusterd_op_t op)
|
|
|
12a457 |
+{
|
|
|
12a457 |
+ int32_t ret = -1;
|
|
|
12a457 |
+ char tmpmount[] = "/tmp/mntXXXXXX";
|
|
|
12a457 |
+ char logfile[PATH_MAX] = {0,};
|
|
|
12a457 |
+ int dirty[3] = {0,};
|
|
|
12a457 |
+ runner_t runner = {0};
|
|
|
12a457 |
+ glusterd_conf_t *priv = NULL;
|
|
|
12a457 |
+ char *pid = NULL;
|
|
|
12a457 |
+ char vpath[PATH_MAX] = {0,};
|
|
|
12a457 |
+ char *volfileserver = NULL;
|
|
|
12a457 |
+
|
|
|
12a457 |
+ priv = THIS->private;
|
|
|
12a457 |
+ GF_VALIDATE_OR_GOTO (THIS->name, priv, out);
|
|
|
12a457 |
+
|
|
|
12a457 |
+ dirty[2] = hton32(1);
|
|
|
12a457 |
+
|
|
|
12a457 |
+ ret = sys_lsetxattr (brickinfo->path, GF_AFR_DIRTY, dirty,
|
|
|
12a457 |
+ sizeof (dirty), 0);
|
|
|
12a457 |
+ if (ret == -1) {
|
|
|
12a457 |
+ gf_msg (THIS->name, GF_LOG_ERROR, errno,
|
|
|
12a457 |
+ GD_MSG_SETXATTR_FAIL, "Failed to set extended"
|
|
|
12a457 |
+ " attribute %s : %s.", GF_AFR_DIRTY, strerror (errno));
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+
|
|
|
12a457 |
+ if (mkdtemp (tmpmount) == NULL) {
|
|
|
12a457 |
+ gf_msg (THIS->name, GF_LOG_ERROR, errno,
|
|
|
12a457 |
+ GD_MSG_DIR_OP_FAILED,
|
|
|
12a457 |
+ "failed to create a temporary mount directory.");
|
|
|
12a457 |
+ ret = -1;
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+
|
|
|
12a457 |
+ ret = gf_asprintf (&pid, "%d", GF_CLIENT_PID_SELF_HEALD);
|
|
|
12a457 |
+ if (ret < 0)
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+
|
|
|
12a457 |
+ switch (op) {
|
|
|
12a457 |
+ case GD_OP_REPLACE_BRICK:
|
|
|
12a457 |
+ if (dict_get_str (THIS->options, "transport.socket.bind-address",
|
|
|
12a457 |
+ &volfileserver) != 0)
|
|
|
12a457 |
+ volfileserver = "localhost";
|
|
|
12a457 |
+
|
|
|
12a457 |
+ snprintf (logfile, sizeof (logfile),
|
|
|
12a457 |
+ DEFAULT_LOG_FILE_DIRECTORY"/%s-replace-brick-mount.log",
|
|
|
12a457 |
+ volinfo->volname);
|
|
|
12a457 |
+ if (!*logfile) {
|
|
|
12a457 |
+ ret = -1;
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ runinit (&runner);
|
|
|
12a457 |
+ runner_add_args (&runner, SBIN_DIR"/glusterfs",
|
|
|
12a457 |
+ "-s", volfileserver,
|
|
|
12a457 |
+ "--volfile-id", volinfo->volname,
|
|
|
12a457 |
+ "--client-pid", pid,
|
|
|
12a457 |
+ "-l", logfile, tmpmount, NULL);
|
|
|
12a457 |
+ break;
|
|
|
12a457 |
+
|
|
|
12a457 |
+ case GD_OP_ADD_BRICK:
|
|
|
12a457 |
+ snprintf (logfile, sizeof (logfile),
|
|
|
12a457 |
+ DEFAULT_LOG_FILE_DIRECTORY"/%s-add-brick-mount.log",
|
|
|
12a457 |
+ volinfo->volname);
|
|
|
12a457 |
+ if (!*logfile) {
|
|
|
12a457 |
+ ret = -1;
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ ret = glusterd_get_dummy_client_filepath (vpath, volinfo,
|
|
|
12a457 |
+ volinfo->transport_type);
|
|
|
12a457 |
+ if (ret) {
|
|
|
12a457 |
+ gf_log ("", GF_LOG_ERROR, "Failed to get "
|
|
|
12a457 |
+ "volfile path");
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ runinit (&runner);
|
|
|
12a457 |
+ runner_add_args (&runner, SBIN_DIR"/glusterfs",
|
|
|
12a457 |
+ "--volfile", vpath,
|
|
|
12a457 |
+ "--client-pid", pid,
|
|
|
12a457 |
+ "-l", logfile, tmpmount, NULL);
|
|
|
12a457 |
+ break;
|
|
|
12a457 |
+ default:
|
|
|
12a457 |
+ break;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ synclock_unlock (&priv->big_lock);
|
|
|
12a457 |
+ ret = runner_run (&runner);
|
|
|
12a457 |
+
|
|
|
12a457 |
+ if (ret) {
|
|
|
12a457 |
+ gf_log (THIS->name, GF_LOG_ERROR, "mount command"
|
|
|
12a457 |
+ " failed.");
|
|
|
12a457 |
+ goto lock;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+ ret = sys_lsetxattr (tmpmount, (op == GD_OP_REPLACE_BRICK) ?
|
|
|
12a457 |
+ GF_AFR_REPLACE_BRICK : GF_AFR_ADD_BRICK,
|
|
|
12a457 |
+ brickinfo->brick_id, sizeof (brickinfo->brick_id),
|
|
|
12a457 |
+ 0);
|
|
|
12a457 |
+ if (ret == -1)
|
|
|
12a457 |
+ gf_msg (THIS->name, GF_LOG_ERROR, errno,
|
|
|
12a457 |
+ GD_MSG_SETXATTR_FAIL, "Failed to set extended"
|
|
|
12a457 |
+ " attribute %s : %s", (op == GD_OP_REPLACE_BRICK) ?
|
|
|
12a457 |
+ GF_AFR_REPLACE_BRICK : GF_AFR_ADD_BRICK,
|
|
|
12a457 |
+ strerror (errno));
|
|
|
12a457 |
+ gf_umount_lazy (THIS->name, tmpmount, 1);
|
|
|
12a457 |
+lock:
|
|
|
12a457 |
+ synclock_lock (&priv->big_lock);
|
|
|
12a457 |
+out:
|
|
|
12a457 |
+ if (pid)
|
|
|
12a457 |
+ GF_FREE (pid);
|
|
|
12a457 |
+ gf_msg_debug ("glusterd", 0, "Returning with ret");
|
|
|
12a457 |
+ return ret;
|
|
|
12a457 |
+}
|
|
|
12a457 |
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
|
|
|
12a457 |
index e6380f5..6b74e90 100644
|
|
|
12a457 |
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
|
|
|
12a457 |
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
|
|
|
12a457 |
@@ -695,4 +695,14 @@ int
|
|
|
12a457 |
glusterd_volume_brick_for_each (glusterd_volinfo_t *volinfo, void *data,
|
|
|
12a457 |
int (*fn) (glusterd_volinfo_t *, glusterd_brickinfo_t *,
|
|
|
12a457 |
dict_t *mod_dict, void *));
|
|
|
12a457 |
+
|
|
|
12a457 |
+int
|
|
|
12a457 |
+glusterd_get_dummy_client_filepath (char *filepath,
|
|
|
12a457 |
+ glusterd_volinfo_t *volinfo,
|
|
|
12a457 |
+ gf_transport_type type);
|
|
|
12a457 |
+
|
|
|
12a457 |
+int
|
|
|
12a457 |
+glusterd_handle_replicate_brick_ops (glusterd_volinfo_t *volinfo,
|
|
|
12a457 |
+ glusterd_brickinfo_t *brickinfo,
|
|
|
12a457 |
+ glusterd_op_t op);
|
|
|
12a457 |
#endif
|
|
|
12a457 |
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
|
|
|
12a457 |
index 8a86ab5..086f053 100644
|
|
|
12a457 |
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
|
|
|
12a457 |
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
|
|
|
12a457 |
@@ -5167,6 +5167,58 @@ enumerate_transport_reqs (gf_transport_type type, char **types)
|
|
|
12a457 |
}
|
|
|
12a457 |
|
|
|
12a457 |
int
|
|
|
12a457 |
+generate_dummy_client_volfiles (glusterd_volinfo_t *volinfo)
|
|
|
12a457 |
+{
|
|
|
12a457 |
+ int i = 0;
|
|
|
12a457 |
+ int ret = -1;
|
|
|
12a457 |
+ char filepath[PATH_MAX] = {0,};
|
|
|
12a457 |
+ char *types[] = {NULL, NULL, NULL};
|
|
|
12a457 |
+ dict_t *dict = NULL;
|
|
|
12a457 |
+ xlator_t *this = NULL;
|
|
|
12a457 |
+ gf_transport_type type = GF_TRANSPORT_TCP;
|
|
|
12a457 |
+
|
|
|
12a457 |
+ this = THIS;
|
|
|
12a457 |
+
|
|
|
12a457 |
+ enumerate_transport_reqs (volinfo->transport_type, types);
|
|
|
12a457 |
+ dict = dict_new ();
|
|
|
12a457 |
+ if (!dict)
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ for (i = 0; types[i]; i++) {
|
|
|
12a457 |
+ memset (filepath, 0, sizeof (filepath));
|
|
|
12a457 |
+ ret = dict_set_str (dict, "client-transport-type", types[i]);
|
|
|
12a457 |
+ if (ret)
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ type = transport_str_to_type (types[i]);
|
|
|
12a457 |
+
|
|
|
12a457 |
+ ret = dict_set_uint32 (dict, "trusted-client", GF_CLIENT_OTHER);
|
|
|
12a457 |
+ if (ret)
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+
|
|
|
12a457 |
+ ret = glusterd_get_dummy_client_filepath (filepath,
|
|
|
12a457 |
+ volinfo, type);
|
|
|
12a457 |
+ if (ret) {
|
|
|
12a457 |
+ gf_msg (this->name, GF_LOG_ERROR, EINVAL,
|
|
|
12a457 |
+ GD_MSG_INVALID_ENTRY,
|
|
|
12a457 |
+ "Received invalid transport-type.");
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+
|
|
|
12a457 |
+ ret = generate_single_transport_client_volfile (volinfo,
|
|
|
12a457 |
+ filepath,
|
|
|
12a457 |
+ dict);
|
|
|
12a457 |
+ if (ret)
|
|
|
12a457 |
+ goto out;
|
|
|
12a457 |
+ }
|
|
|
12a457 |
+
|
|
|
12a457 |
+out:
|
|
|
12a457 |
+ if (dict)
|
|
|
12a457 |
+ dict_unref (dict);
|
|
|
12a457 |
+
|
|
|
12a457 |
+ gf_msg_trace ("glusterd", 0, "Returning %d", ret);
|
|
|
12a457 |
+ return ret;
|
|
|
12a457 |
+}
|
|
|
12a457 |
+
|
|
|
12a457 |
+int
|
|
|
12a457 |
generate_client_volfiles (glusterd_volinfo_t *volinfo,
|
|
|
12a457 |
glusterd_client_type_t client_type)
|
|
|
12a457 |
{
|
|
|
12a457 |
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h
|
|
|
12a457 |
index f1dc823..c86a87b 100644
|
|
|
12a457 |
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.h
|
|
|
12a457 |
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h
|
|
|
12a457 |
@@ -293,4 +293,7 @@ glusterd_volopt_validate (glusterd_volinfo_t *volinfo, dict_t *dict, char *key,
|
|
|
12a457 |
gf_boolean_t
|
|
|
12a457 |
gd_is_self_heal_enabled (glusterd_volinfo_t *volinfo, dict_t *dict);
|
|
|
12a457 |
|
|
|
12a457 |
+int
|
|
|
12a457 |
+generate_dummy_client_volfiles (glusterd_volinfo_t *volinfo);
|
|
|
12a457 |
+
|
|
|
12a457 |
#endif
|
|
|
12a457 |
--
|
|
|
12a457 |
1.7.1
|
|
|
12a457 |
|