summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src
diff options
context:
space:
mode:
authorPranith K <pranithk@gluster.com>2011-03-25 05:58:35 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-03-25 04:38:04 -0700
commit1180b2136f6cf014a08f072f8ecc4aac2b69580f (patch)
tree3989ae8b7e7842a0adc291c7c637543e1a671a94 /xlators/mgmt/glusterd/src
parentfc06afc8cd1a646f71e0ed1713b05b8aa533c6d2 (diff)
mgmt/glusterd: Fix import friend volumes
- Sync transport type of the volume - Stop stale bricks - start new bricks if the volume is started - Restart/Stop nfs server based on the new information Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 2549 (Quota[glusterfs-3.2.1qa3]: enable/disable crashes the glusterd on other node) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2549
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c151
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.h8
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rpc-ops.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.c3
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c25
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c546
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h18
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c9
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.h2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h10
11 files changed, 527 insertions, 251 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index aa37d93f0bb..386496ac733 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -1036,7 +1036,7 @@ out:
if (free_ptr)
GF_FREE(free_ptr);
- glusterd_volume_bricks_delete (&tmpvolinfo);
+ glusterd_volume_brickinfos_delete (&tmpvolinfo);
if (brickinfo)
glusterd_brickinfo_delete (brickinfo);
if (cli_req.volname)
@@ -1459,7 +1459,7 @@ out:
if (free_ptr)
GF_FREE (free_ptr);
- glusterd_volume_bricks_delete (&tmpvolinfo);
+ glusterd_volume_brickinfos_delete (&tmpvolinfo);
if (brickinfo)
glusterd_brickinfo_delete (brickinfo);
if (cli_req.volname)
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 70d65a10912..e6f257aa9aa 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -143,11 +143,11 @@ glusterd_set_volume_status (glusterd_volinfo_t *volinfo,
volinfo->status = status;
}
-static int
+gf_boolean_t
glusterd_is_volume_started (glusterd_volinfo_t *volinfo)
{
GF_ASSERT (volinfo);
- return (!(volinfo->status == GLUSTERD_STATUS_STARTED));
+ return (volinfo->status == GLUSTERD_STATUS_STARTED);
}
gf_boolean_t
@@ -438,7 +438,7 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr)
exists = glusterd_check_volume_exists (volname);
if (!exists) {
- snprintf (msg, 2048, "Volume %s does not exist", volname);
+ snprintf (msg, sizeof (msg), "Volume %s does not exist", volname);
gf_log ("", GF_LOG_ERROR, "%s",
msg);
*op_errstr = gf_strdup (msg);
@@ -470,12 +470,10 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr)
}
if (!(flags & GF_CLI_FLAG_OP_FORCE)) {
- ret = glusterd_is_volume_started (volinfo);
- if (!ret) {
- snprintf (msg, 2048, "Volume %s already started",
- volname);
- gf_log ("glusterd", GF_LOG_ERROR,
- "%s", msg);
+ if (glusterd_is_volume_started (volinfo)) {
+ snprintf (msg, sizeof (msg), "Volume %s already"
+ "started", volname);
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
*op_errstr = gf_strdup (msg);
ret = -1;
goto out;
@@ -523,9 +521,7 @@ glusterd_op_stage_stop_volume (dict_t *dict, char **op_errstr)
goto out;
if (!(flags & GF_CLI_FLAG_OP_FORCE)) {
- ret = glusterd_is_volume_started (volinfo);
-
- if (ret) {
+ if (_gf_false == glusterd_is_volume_started (volinfo)) {
snprintf (msg, sizeof(msg), "Volume %s "
"is not in the started state", volname);
gf_log ("", GF_LOG_ERROR, "Volume %s "
@@ -577,9 +573,7 @@ glusterd_op_stage_delete_volume (dict_t *dict, char **op_errstr)
if (ret)
goto out;
- ret = glusterd_is_volume_started (volinfo);
-
- if (!ret) {
+ if (glusterd_is_volume_started (volinfo)) {
snprintf (msg, sizeof (msg), "Volume %s has been started."
"Volume needs to be stopped before deletion.",
volname);
@@ -1130,9 +1124,7 @@ glusterd_op_stage_log_rotate (dict_t *dict, char **op_errstr)
goto out;
}
- ret = glusterd_is_volume_started (volinfo);
-
- if (ret) {
+ if (_gf_false == glusterd_is_volume_started (volinfo)) {
snprintf (msg, sizeof (msg), "Volume %s needs to be started before"
" log rotate.", volname);
gf_log ("", GF_LOG_ERROR, "%s", msg);
@@ -1408,12 +1400,7 @@ glusterd_op_perform_remove_brick (glusterd_volinfo_t *volinfo, char *brick)
goto out;
}
}
-
- glusterd_delete_volfile (volinfo, brickinfo);
- glusterd_store_delete_brick (volinfo, brickinfo);
- glusterd_brickinfo_delete (brickinfo);
- volinfo->brick_count--;
-
+ glusterd_delete_brick (volinfo, brickinfo);
out:
if (dup_brick)
GF_FREE (dup_brick);
@@ -1458,7 +1445,7 @@ glusterd_op_perform_replace_brick (glusterd_volinfo_t *volinfo,
if (ret)
goto out;
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret)
goto out;
@@ -1522,7 +1509,7 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count,
if (count)
brick = strtok_r (brick_list+1, " \n", &saveptr);
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret)
goto out;
@@ -2067,7 +2054,7 @@ glusterd_op_stage_stats_volume (dict_t *dict, char **op_errstr)
}
if (GF_CLI_STATS_INFO == stats_op) {
- if (glusterd_is_volume_started (volinfo)) {
+ if (_gf_false == glusterd_is_volume_started (volinfo)) {
snprintf (msg, sizeof (msg), "volume %s is not started.",
volinfo->volname);
gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
@@ -2103,7 +2090,7 @@ glusterd_op_stage_stats_volume (dict_t *dict, char **op_errstr)
goto out;
}
} else if (GF_CLI_STATS_TOP == stats_op) {
- if (glusterd_is_volume_started (volinfo)) {
+ if (_gf_false == glusterd_is_volume_started (volinfo)) {
snprintf (msg, sizeof (msg), "volume %s is not started.",
volinfo->volname);
gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
@@ -2255,7 +2242,7 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr)
if (ret)
goto out;
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret)
goto out;
@@ -2326,12 +2313,8 @@ glusterd_op_add_brick (dict_t *dict, char **op_errstr)
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
if (GLUSTERD_STATUS_STARTED == volinfo->status)
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
out:
return ret;
@@ -3412,13 +3395,13 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
gf_log ("", GF_LOG_CRITICAL, "Unable to add "
"dst-brick: %s to volume: %s",
dst_brick, volinfo->volname);
- (void) glusterd_check_generate_start_nfs (volinfo);
+ (void) glusterd_check_generate_start_nfs ();
goto out;
}
volinfo->defrag_status = 0;
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
if (ret) {
gf_log ("", GF_LOG_CRITICAL,
"Failed to generate nfs volume file");
@@ -3430,10 +3413,6 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
ret = glusterd_fetchspec_notify (THIS);
glusterd_set_rb_status (volinfo, GF_RB_STATUS_NONE);
glusterd_brickinfo_delete (volinfo->dst_brick);
@@ -3548,7 +3527,7 @@ glusterd_options_reset (glusterd_volinfo_t *volinfo)
dict_foreach (volinfo->dict, _delete_reconfig_opt, volinfo->dict);
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to create volfile for"
@@ -3561,12 +3540,8 @@ glusterd_options_reset (glusterd_volinfo_t *volinfo)
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
if (GLUSTERD_STATUS_STARTED == volinfo->status)
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
if (ret)
goto out;
@@ -3893,7 +3868,7 @@ glusterd_marker_create_volfile (glusterd_volinfo_t *volinfo)
{
int32_t ret = 0;
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to create volfile"
" for setting of marker while 'gsync start'");
@@ -3905,12 +3880,8 @@ glusterd_marker_create_volfile (glusterd_volinfo_t *volinfo)
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
if (GLUSTERD_STATUS_STARTED == volinfo->status)
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
ret = 0;
out:
return ret;
@@ -4600,7 +4571,7 @@ glusterd_op_quota (dict_t *dict, char **op_errstr)
goto out;
}
create_vol:
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to re-create volfile for"
" 'quota'");
@@ -4612,12 +4583,8 @@ create_vol:
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
if (GLUSTERD_STATUS_STARTED == volinfo->status)
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
ret = 0;
@@ -4638,7 +4605,7 @@ out:
return ret;
}
-static int
+int
glusterd_stop_bricks (glusterd_volinfo_t *volinfo)
{
glusterd_brickinfo_t *brickinfo = NULL;
@@ -4651,7 +4618,7 @@ glusterd_stop_bricks (glusterd_volinfo_t *volinfo)
return 0;
}
-static int
+int
glusterd_start_bricks (glusterd_volinfo_t *volinfo)
{
glusterd_brickinfo_t *brickinfo = NULL;
@@ -4794,7 +4761,7 @@ glusterd_op_set_volume (dict_t *dict)
}
if (!global_opt) {
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to create volfile for"
" 'volume set'");
@@ -4813,12 +4780,8 @@ glusterd_op_set_volume (dict_t *dict)
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
if (GLUSTERD_STATUS_STARTED == volinfo->status) {
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
if (ret) {
gf_log ("", GF_LOG_WARNING,
"Unable to restart NFS-Server");
@@ -4830,7 +4793,7 @@ glusterd_op_set_volume (dict_t *dict)
else {
list_for_each_entry (voliter, &priv->volumes, vol_list) {
volinfo = voliter;
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to create volfile for"
" 'volume set'");
@@ -4850,12 +4813,8 @@ glusterd_op_set_volume (dict_t *dict)
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
if (GLUSTERD_STATUS_STARTED == volinfo->status) {
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
if (ret) {
gf_log ("", GF_LOG_WARNING,
"Unable to restart NFS-Server");
@@ -4922,7 +4881,7 @@ glusterd_op_remove_brick (dict_t *dict)
i++;
}
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret)
goto out;
@@ -4933,12 +4892,8 @@ glusterd_op_remove_brick (dict_t *dict)
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
if (GLUSTERD_STATUS_STARTED == volinfo->status)
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
out:
return ret;
@@ -4970,17 +4925,9 @@ glusterd_op_delete_volume (dict_t *dict)
if (ret)
goto out;
- ret = glusterd_store_delete_volume (volinfo);
-
- if (ret)
- goto out;
-
- ret = glusterd_volinfo_delete (volinfo);
-
- if (ret)
- goto out;
-
+ ret = glusterd_delete_volume (volinfo);
out:
+ gf_log ("", GF_LOG_DEBUG, "returning %d", ret);
return ret;
}
@@ -5013,11 +4960,7 @@ glusterd_op_start_volume (dict_t *dict, char **op_errstr)
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
out:
gf_log ("", GF_LOG_DEBUG, "returning %d ", ret);
@@ -5294,8 +5237,6 @@ glusterd_op_stop_volume (dict_t *dict)
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
-
if (glusterd_are_all_volumes_stopped ()) {
if (glusterd_is_nfs_started ()) {
ret = glusterd_nfs_server_stop ();
@@ -5303,7 +5244,7 @@ glusterd_op_stop_volume (dict_t *dict)
goto out;
}
} else {
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
}
out:
@@ -5500,7 +5441,7 @@ glusterd_op_stats_volume (dict_t *dict, char **op_errstr,
volinfo->volname, fd_stats_key, fd_stats_value);
goto out;
}
- ret = glusterd_create_volfiles (volinfo);
+ ret = glusterd_create_volfiles_and_notify_services (volinfo);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to create volfile for"
@@ -5514,12 +5455,8 @@ glusterd_op_stats_volume (dict_t *dict, char **op_errstr,
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
- if (ret)
- goto out;
-
if (GLUSTERD_STATUS_STARTED == volinfo->status)
- ret = glusterd_check_generate_start_nfs (volinfo);
+ ret = glusterd_check_generate_start_nfs ();
ret = 0;
@@ -6840,7 +6777,7 @@ glusterd_bricks_select_stop_volume (dict_t *dict, char **op_errstr)
goto out;
list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
- if (!glusterd_is_brick_started (brickinfo)) {
+ if (glusterd_is_brick_started (brickinfo)) {
pending_node = GF_CALLOC (1, sizeof (*pending_node),
gf_gld_mt_pending_node_t);
if (!pending_node) {
@@ -6904,7 +6841,7 @@ glusterd_bricks_select_remove_brick (dict_t *dict, char **op_errstr)
&brickinfo);
if (ret)
goto out;
- if (!glusterd_is_brick_started (brickinfo)) {
+ if (glusterd_is_brick_started (brickinfo)) {
pending_node = GF_CALLOC (1, sizeof (*pending_node),
gf_gld_mt_pending_node_t);
if (!pending_node) {
@@ -6971,7 +6908,7 @@ glusterd_bricks_select_profile_volume (dict_t *dict, char **op_errstr)
break;
case GF_CLI_STATS_INFO:
list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
- if (!glusterd_is_brick_started (brickinfo)) {
+ if (glusterd_is_brick_started (brickinfo)) {
pending_node = GF_CALLOC (1, sizeof (*pending_node),
gf_gld_mt_pending_node_t);
if (!pending_node) {
@@ -7010,7 +6947,7 @@ glusterd_bricks_select_profile_volume (dict_t *dict, char **op_errstr)
}
ret = 0;
list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
- if (!glusterd_is_brick_started (brickinfo)) {
+ if (glusterd_is_brick_started (brickinfo)) {
pending_node = GF_CALLOC (1, sizeof (*pending_node),
gf_gld_mt_pending_node_t);
if (!pending_node) {
@@ -7025,7 +6962,7 @@ glusterd_bricks_select_profile_volume (dict_t *dict, char **op_errstr)
}
}
break;
-
+
default:
GF_ASSERT (0);
gf_log ("glusterd", GF_LOG_ERROR, "Invalid profile op: %d",
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
index 206418df845..5e1106bc1e2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
@@ -278,4 +278,12 @@ glusterd_volume_stats_read_perf (char *brick_path, int32_t blk_size,
int32_t
glusterd_volume_stats_write_perf (char *brick_path, int32_t blk_size,
int32_t blk_count, double *throughput, double *time);
+gf_boolean_t
+glusterd_is_volume_started (glusterd_volinfo_t *volinfo);
+int
+glusterd_start_bricks (glusterd_volinfo_t *volinfo);
+gf_boolean_t
+glusterd_are_all_volumes_stopped ();
+int
+glusterd_stop_bricks (glusterd_volinfo_t *volinfo);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
index ca4201422ee..43a0f22c71c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
@@ -1759,7 +1759,7 @@ glusterd3_1_brick_op (call_frame_t *frame, xlator_t *this,
if (!dummy_frame)
continue;
- if (glusterd_is_brick_started (brickinfo))
+ if (_gf_false == glusterd_is_brick_started (brickinfo))
continue;
ret = glusterd_brick_op_build_payload (req_ctx->op, brickinfo,
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
index a0c25f521b3..ce15ffdfc72 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
@@ -616,8 +616,7 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)
if (GLUSTERD_VOL_COMP_RJT != status) {
event_type = GD_FRIEND_EVENT_LOCAL_ACC;
op_ret = 0;
- }
- else {
+ } else {
event_type = GD_FRIEND_EVENT_LOCAL_RJT;
op_errno = GF_PROBE_VOLUME_CONFLICT;
op_ret = -1;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index bb8b6b17c64..96af05d802e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -536,8 +536,9 @@ glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo)
goto out;
out:
- gf_log ("", GF_LOG_ERROR, "Unable to write volume values"
- " for %s", volinfo->volname);
+ if (ret)
+ gf_log ("", GF_LOG_ERROR, "Unable to write volume values"
+ " for %s", volinfo->volname);
return ret;
}
@@ -694,6 +695,7 @@ glusterd_store_volinfo (glusterd_volinfo_t *volinfo, glusterd_volinfo_ver_ac_t a
GF_ASSERT (volinfo);
+ glusterd_perform_volinfo_version_action (volinfo, ac);
ret = glusterd_store_create_volume_dir (volinfo);
if (ret)
goto out;
@@ -705,7 +707,10 @@ glusterd_store_volinfo (glusterd_volinfo_t *volinfo, glusterd_volinfo_ver_ac_t a
ret = glusterd_store_perform_volume_store (volinfo);
if (ret)
goto out;
- glusterd_perform_volinfo_version_action (volinfo, ac);
+ //checksum should be computed at the end
+ ret = glusterd_volume_compute_cksum (volinfo);
+ if (ret)
+ goto out;
out:
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
@@ -728,7 +733,7 @@ glusterd_store_delete_volume (glusterd_volinfo_t *volinfo)
priv = THIS->private;
GF_ASSERT (priv);
- snprintf (pathname, 1024, "%s/vols/%s", priv->workdir,
+ snprintf (pathname, sizeof (pathname), "%s/vols/%s", priv->workdir,
volinfo->volname);
dir = opendir (pathname);
@@ -737,7 +742,8 @@ glusterd_store_delete_volume (glusterd_volinfo_t *volinfo)
ret = glusterd_store_remove_bricks (volinfo);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Remove bricks failed");
+ gf_log ("", GF_LOG_ERROR, "Remove bricks failed for %s",
+ volinfo->volname);
}
glusterd_for_each_entry (entry, dir);
@@ -768,14 +774,14 @@ stat_failed:
ret = closedir (dir);
if (ret) {
- gf_log ("", GF_LOG_NORMAL, "Failed to close dir, errno:%d",
+ gf_log ("", GF_LOG_ERROR, "Failed to close dir, errno:%d",
errno);
}
ret = rmdir (pathname);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Failed to rmdir: %s, errno: %d",
- pathname, errno);
+ gf_log ("", GF_LOG_ERROR, "Failed to rmdir: %s, err: %s",
+ pathname, strerror (errno));
}
@@ -1457,8 +1463,7 @@ glusterd_store_retrieve_volume (char *volname)
volinfo->status = atoi (value);
} else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_VERSION,
strlen (GLUSTERD_STORE_KEY_VOL_VERSION))) {
- if (gf_string2uint32 (value, &volinfo->version))
- gf_log ("", GF_LOG_ERROR, "%s", strerror(errno));
+ volinfo->version = atoi (value);
} else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_PORT,
strlen (GLUSTERD_STORE_KEY_VOL_PORT))) {
volinfo->port = atoi (value);
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 2b62c13cc3e..bd32380e262 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -550,11 +550,11 @@ glusterd_brickinfo_delete (glusterd_brickinfo_t *brickinfo)
}
int32_t
-glusterd_volume_bricks_delete (glusterd_volinfo_t *volinfo)
+glusterd_volume_brickinfos_delete (glusterd_volinfo_t *volinfo)
{
glusterd_brickinfo_t *brickinfo = NULL;
glusterd_brickinfo_t *tmp = NULL;
- int32_t ret = -1;
+ int32_t ret = 0;
GF_ASSERT (volinfo);
@@ -579,7 +579,7 @@ glusterd_volinfo_delete (glusterd_volinfo_t *volinfo)
list_del_init (&volinfo->vol_list);
- ret = glusterd_volume_bricks_delete (volinfo);
+ ret = glusterd_volume_brickinfos_delete (volinfo);
if (ret)
goto out;
dict_unref (volinfo->dict);
@@ -932,6 +932,40 @@ glusterd_set_brick_socket_filepath (glusterd_volinfo_t *volinfo,
snprintf (sockpath, len, "%s/%s.socket", glusterd_sock_dir, md5_sum);
}
+/* connection happens only if it is not aleady connected,
+ * reconnections are taken care by rpc-layer
+ */
+int32_t
+glusterd_brick_connect (glusterd_volinfo_t *volinfo,
+ glusterd_brickinfo_t *brickinfo)
+{
+ int ret = 0;
+ char socketpath[PATH_MAX] = {0};
+ dict_t *options = NULL;
+ struct rpc_clnt *rpc = NULL;
+
+ GF_ASSERT (volinfo);
+ GF_ASSERT (brickinfo);
+
+ if (brickinfo->rpc == NULL) {
+ glusterd_set_brick_socket_filepath (volinfo, brickinfo,
+ socketpath,
+ sizeof (socketpath));
+ ret = rpc_clnt_transport_unix_options_build (&options, socketpath);
+ if (ret)
+ goto out;
+ ret = glusterd_rpc_create (&rpc, options,
+ glusterd_brick_rpc_notify,
+ brickinfo);
+ if (ret)
+ goto out;
+ brickinfo->rpc = rpc;
+ }
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
int32_t
glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo)
@@ -949,9 +983,7 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
int port = 0;
FILE *file = NULL;
gf_boolean_t is_locked = _gf_false;
- dict_t *options = NULL;
char socketpath[PATH_MAX] = {0};
- struct rpc_clnt *rpc = NULL;
GF_ASSERT (volinfo);
GF_ASSERT (brickinfo);
@@ -1048,17 +1080,9 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
}
connect:
- if (brickinfo->rpc == NULL) {
- ret = rpc_clnt_transport_unix_options_build (&options, socketpath);
- if (ret)
- goto out;
- ret = glusterd_rpc_create (&rpc, options,
- glusterd_brick_rpc_notify,
- brickinfo);
- if (ret)
- goto out;
- brickinfo->rpc = rpc;
- }
+ ret = glusterd_brick_connect (volinfo, brickinfo);
+ if (ret)
+ goto out;
out:
if (is_locked && file)
lockf (fileno (file), F_ULOCK, 0);
@@ -1097,6 +1121,19 @@ glusterd_brick_unlink_socket_file (glusterd_volinfo_t *volinfo,
return ret;
}
+
+int32_t
+glusterd_brick_disconnect (glusterd_brickinfo_t *brickinfo)
+{
+ GF_ASSERT (brickinfo);
+
+ if (brickinfo->rpc) {
+ rpc_clnt_unref (brickinfo->rpc);
+ brickinfo->rpc = NULL;
+ }
+ return 0;
+}
+
int32_t
glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo)
@@ -1114,11 +1151,8 @@ glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo,
GF_ASSERT (this);
priv = this->private;
+ (void) glusterd_brick_disconnect (brickinfo);
- if (brickinfo->rpc) {
- rpc_clnt_unref (brickinfo->rpc);
- brickinfo->rpc = NULL;
- }
GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv);
GLUSTERD_GET_BRICK_PIDFILE (pidfile, path, brickinfo->hostname,
brickinfo->path);
@@ -1333,12 +1367,18 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo,
if (ret)
goto out;
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "volume%d.transport_type", count);
+ ret = dict_set_uint32 (dict, key, volinfo->transport_type);
+ if (ret)
+ goto out;
+
volume_id_str = gf_strdup (uuid_utoa (volinfo->volume_id));
if (!volume_id_str)
goto out;
memset (key, 0, sizeof (key));
- snprintf (key, 256, "volume%d.volume_id", count);
+ snprintf (key, sizeof (key), "volume%d.volume_id", count);
ret = dict_set_dynstr (dict, key, volume_id_str);
if (ret)
goto out;
@@ -1491,8 +1531,7 @@ out:
int32_t
glusterd_import_friend_volume_opts (dict_t *vols, int count,
- glusterd_volinfo_t *volinfo,
- int new_volinfo)
+ glusterd_volinfo_t *volinfo)
{
char key[512] = {0,};
int32_t ret = -1;
@@ -1501,183 +1540,404 @@ glusterd_import_friend_volume_opts (dict_t *vols, int count,
char *opt_key = NULL;
char *opt_val = NULL;
char *dup_opt_val = NULL;
+ char msg[2048] = {0};
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.opt-count", count);
ret = dict_get_int32 (vols, key, &opt_count);
- if (ret)
+ if (ret) {
+ snprintf (msg, sizeof (msg), "Volume option count not "
+ "specified for %s", volinfo->volname);
goto out;
- if (!new_volinfo) {
- ret = glusterd_options_reset (volinfo);
- if (ret) {
- gf_log ("", GF_LOG_ERROR, "options reset failed");
- goto out;
- }
}
while (i <= opt_count) {
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.key%d",
count, i);
ret = dict_get_str (vols, key, &opt_key);
- if (ret)
+ if (ret) {
+ snprintf (msg, sizeof (msg), "Volume option key not "
+ "specified for %s", volinfo->volname);
goto out;
+ }
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.value%d",
count, i);
ret = dict_get_str (vols, key, &opt_val);
- if (ret)
+ if (ret) {
+ snprintf (msg, sizeof (msg), "Volume option value not "
+ "specified for %s", volinfo->volname);
goto out;
+ }
dup_opt_val = gf_strdup (opt_val);
if (!dup_opt_val) {
ret = -1;
goto out;
}
ret = dict_set_dynstr (volinfo->dict, opt_key, dup_opt_val);
- if (ret)
+ if (ret) {
+ snprintf (msg, sizeof (msg), "Volume set %s %s "
+ "unsuccessful for %s", opt_key, dup_opt_val,
+ volinfo->volname);
goto out;
+ }
i++;
}
out:
+ if (msg[0])
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
return ret;
}
int32_t
-glusterd_import_friend_volume (dict_t *vols, int count)
+glusterd_import_new_brick (dict_t *vols, int32_t vol_count,
+ int32_t brick_count,
+ glusterd_brickinfo_t **brickinfo)
{
-
- int32_t ret = -1;
- glusterd_conf_t *priv = NULL;
char key[512] = {0,};
- glusterd_volinfo_t *volinfo = NULL;
- char *volname = NULL;
+ int ret = -1;
char *hostname = NULL;
char *path = NULL;
- glusterd_brickinfo_t *brickinfo = NULL;
- glusterd_brickinfo_t *tmp = NULL;
- int new_volinfo = 0;
- int i = 1;
- char *volume_id_str = NULL;
+ glusterd_brickinfo_t *new_brickinfo = NULL;
+ char msg[2048] = {0};
GF_ASSERT (vols);
+ GF_ASSERT (vol_count >= 0);
+ GF_ASSERT (brickinfo);
- snprintf (key, sizeof (key), "volume%d.name", count);
- ret = dict_get_str (vols, key, &volname);
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "volume%d.brick%d.hostname",
+ vol_count, brick_count);
+ ret = dict_get_str (vols, key, &hostname);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload", key);
+ goto out;
+ }
+
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "volume%d.brick%d.path",
+ vol_count, brick_count);
+ ret = dict_get_str (vols, key, &path);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload", key);
+ goto out;
+ }
+
+ ret = glusterd_brickinfo_new (&new_brickinfo);
if (ret)
goto out;
- priv = THIS->private;
+ strcpy (new_brickinfo->path, path);
+ strcpy (new_brickinfo->hostname, hostname);
+ //peerinfo might not be added yet
+ (void) glusterd_resolve_brick (new_brickinfo);
+ ret = 0;
+ *brickinfo = new_brickinfo;
+out:
+ if (msg[0])
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
+ gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+ return ret;
+}
- ret = glusterd_volinfo_find (volname, &volinfo);
+int32_t
+glusterd_import_bricks (dict_t *vols, int32_t vol_count,
+ glusterd_volinfo_t *new_volinfo)
+{
+ int ret = -1;
+ int brick_count = 1;
+ glusterd_brickinfo_t *new_brickinfo = NULL;
- if (ret) {
- ret = glusterd_volinfo_new (&volinfo);
+ GF_ASSERT (vols);
+ GF_ASSERT (vol_count >= 0);
+ GF_ASSERT (new_volinfo);
+ while (brick_count <= new_volinfo->brick_count) {
+
+ ret = glusterd_import_new_brick (vols, vol_count, brick_count,
+ &new_brickinfo);
if (ret)
goto out;
- strncpy (volinfo->volname, volname, sizeof (volinfo->volname));
- new_volinfo = 1;
+ list_add_tail (&new_brickinfo->brick_list, &new_volinfo->bricks);
+ brick_count++;
}
+ ret = 0;
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+ return ret;
+}
+
+int32_t
+glusterd_import_volinfo (dict_t *vols, int count,
+ glusterd_volinfo_t **volinfo)
+{
+ int ret = -1;
+ char key[256] = {0};
+ char *volname = NULL;
+ glusterd_volinfo_t *new_volinfo = NULL;
+ char *volume_id_str = NULL;
+ char msg[2048] = {0};
+
+ GF_ASSERT (vols);
+ GF_ASSERT (volinfo);
+
+ snprintf (key, sizeof (key), "volume%d.name", count);
+ ret = dict_get_str (vols, key, &volname);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload", key);
+ goto out;
+ }
+
+ ret = glusterd_volinfo_new (&new_volinfo);
+ if (ret)
+ goto out;
+ strncpy (new_volinfo->volname, volname, sizeof (new_volinfo->volname));
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.type", count);
- ret = dict_get_int32 (vols, key, &volinfo->type);
- if (ret)
+ ret = dict_get_int32 (vols, key, &new_volinfo->type);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload for %s",
+ key, volname);
goto out;
+ }
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.brick_count", count);
- ret = dict_get_int32 (vols, key, &volinfo->brick_count);
- if (ret)
+ ret = dict_get_int32 (vols, key, &new_volinfo->brick_count);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload for %s",
+ key, volname);
goto out;
+ }
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.version", count);
- ret = dict_get_uint32 (vols, key, &volinfo->version);
- if (ret)
+ ret = dict_get_int32 (vols, key, &new_volinfo->version);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload for %s",
+ key, volname);
goto out;
+ }
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.status", count);
- ret = dict_get_int32 (vols, key, (int32_t *)&volinfo->status);
- if (ret)
+ ret = dict_get_int32 (vols, key, (int32_t *)&new_volinfo->status);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload for %s",
+ key, volname);
goto out;
+ }
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.sub_count", count);
- ret = dict_get_int32 (vols, key, &volinfo->sub_count);
- if (ret)
+ ret = dict_get_int32 (vols, key, &new_volinfo->sub_count);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload for %s",
+ key, volname);
goto out;
+ }
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.ckusm", count);
- ret = dict_get_uint32 (vols, key, &volinfo->cksum);
- if (ret)
+ ret = dict_get_uint32 (vols, key, &new_volinfo->cksum);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload for %s",
+ key, volname);
goto out;
+ }
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.volume_id", count);
ret = dict_get_str (vols, key, &volume_id_str);
- if (ret)
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload for %s",
+ key, volname);
goto out;
- uuid_parse (volume_id_str, volinfo->volume_id);
+ }
- list_for_each_entry_safe (brickinfo, tmp, &volinfo->bricks,
- brick_list) {
- glusterd_delete_volfile (volinfo, brickinfo);
- glusterd_store_delete_brick (volinfo, brickinfo);
- ret = glusterd_brickinfo_delete (brickinfo);
- if (ret)
- goto out;
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "volume%d.transport_type", count);
+ ret = dict_get_uint32 (vols, key, &new_volinfo->transport_type);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "%s missing in payload for %s",
+ key, volname);
+ goto out;
}
- while (i <= volinfo->brick_count) {
+ uuid_parse (volume_id_str, new_volinfo->volume_id);
- memset (key, 0, sizeof (key));
- snprintf (key, sizeof (key), "volume%d.brick%d.hostname",
- count, i);
- ret = dict_get_str (vols, key, &hostname);
- if (ret)
- goto out;
+ ret = glusterd_import_friend_volume_opts (vols, count, new_volinfo);
+ if (ret)
+ goto out;
+ ret = glusterd_import_bricks (vols, count, new_volinfo);
+ if (ret)
+ goto out;
+ *volinfo = new_volinfo;
+out:
+ if (msg[0])
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
+ gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+ return ret;
+}
- memset (key, 0, sizeof (key));
- snprintf (key, sizeof (key), "volume%d.brick%d.path",
- count, i);
- ret = dict_get_str (vols, key, &path);
- if (ret)
- goto out;
+int32_t
+glusterd_volume_disconnect_all_bricks (glusterd_volinfo_t *volinfo)
+{
+ int ret = 0;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ GF_ASSERT (volinfo);
- ret = glusterd_brickinfo_new (&brickinfo);
- if (ret)
- goto out;
+ list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
+ if (glusterd_is_brick_started (brickinfo)) {
+ ret = glusterd_brick_disconnect (brickinfo);
+ if (ret) {
+ gf_log ("glusterd", GF_LOG_ERROR, "Failed to "
+ "disconnect %s:%s", brickinfo->hostname,
+ brickinfo->path);
+ break;
+ }
+ }
+ }
- strcpy (brickinfo->path, path);
- strcpy (brickinfo->hostname, hostname);
- glusterd_resolve_brick (brickinfo);
+ return ret;
+}
- list_add_tail (&brickinfo->brick_list, &volinfo->bricks);
+int32_t
+glusterd_volinfo_copy_brick_portinfo (glusterd_volinfo_t *new_volinfo,
+ glusterd_volinfo_t *old_volinfo)
+{
+ glusterd_brickinfo_t *new_brickinfo = NULL;
+ glusterd_brickinfo_t *old_brickinfo = NULL;
+
+ int ret = 0;
+ GF_ASSERT (new_volinfo);
+ GF_ASSERT (old_volinfo);
+ if (_gf_false == glusterd_is_volume_started (new_volinfo))
+ goto out;
+ list_for_each_entry (new_brickinfo, &new_volinfo->bricks, brick_list) {
+ ret = glusterd_volume_brickinfo_get (new_brickinfo->uuid,
+ new_brickinfo->hostname,
+ new_brickinfo->path,
+ old_volinfo, &old_brickinfo);
+ if ((0 == ret) && glusterd_is_brick_started (old_brickinfo)) {
+ new_brickinfo->port = old_brickinfo->port;
+ }
+ }
+out:
+ ret = 0;
+ return ret;
+}
- i++;
+int32_t
+glusterd_volinfo_stop_stale_bricks (glusterd_volinfo_t *new_volinfo,
+ glusterd_volinfo_t *old_volinfo)
+{
+ glusterd_brickinfo_t *new_brickinfo = NULL;
+ glusterd_brickinfo_t *old_brickinfo = NULL;
+
+ int ret = 0;
+ GF_ASSERT (new_volinfo);
+ GF_ASSERT (old_volinfo);
+ if (_gf_false == glusterd_is_volume_started (old_volinfo))
+ goto out;
+ list_for_each_entry (old_brickinfo, &old_volinfo->bricks, brick_list) {
+ ret = glusterd_volume_brickinfo_get (old_brickinfo->uuid,
+ old_brickinfo->hostname,
+ old_brickinfo->path,
+ new_volinfo, &new_brickinfo);
+ if (ret) {
+ ret = glusterd_brick_stop (old_volinfo, old_brickinfo);
+ if (ret)
+ gf_log ("glusterd", GF_LOG_ERROR, "Failed to "
+ "stop brick %s:%s", old_brickinfo->hostname,
+ old_brickinfo->path);
+ }
}
+ ret = 0;
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+ return ret;
+}
- ret = glusterd_import_friend_volume_opts (vols, count, volinfo,
- new_volinfo);
- if (ret)
- goto out;
- if (new_volinfo)
- list_add_tail (&volinfo->vol_list, &priv->volumes);
- ret = glusterd_store_volinfo (volinfo, GLUSTERD_VOLINFO_VER_AC_NONE);
+int32_t
+glusterd_delete_stale_volume (glusterd_volinfo_t *stale_volinfo,
+ glusterd_volinfo_t *valid_volinfo)
+{
+ GF_ASSERT (stale_volinfo);
+ GF_ASSERT (valid_volinfo);
+
+ /* If stale volume is in started state, copy the port numbers of the
+ * local bricks if they exist in the valid volume information.
+ * stop stale bricks. Stale volume information is going to be deleted.
+ * Which deletes the valid brick information inside stale volinfo.
+ * We dont want brick_rpc_notify to access already deleted brickinfo.
+ * Disconnect valid bricks.
+ */
+ if (glusterd_is_volume_started (stale_volinfo)) {
+ if (glusterd_is_volume_started (valid_volinfo)) {
+ (void) glusterd_volinfo_stop_stale_bricks (valid_volinfo,
+ stale_volinfo);
+ //Only valid bricks will be running now.
+ (void) glusterd_volinfo_copy_brick_portinfo (valid_volinfo,
+ stale_volinfo);
+ (void) glusterd_volume_disconnect_all_bricks (stale_volinfo);
+ } else {
+ (void) glusterd_stop_bricks (stale_volinfo);
+ }
+ }
+ /* Delete all the bricks and stores and vol files. They will be created
+ * again by the valid_volinfo. Volume store delete should not be
+ * performed because some of the bricks could still be running,
+ * keeping pid files under run directory
+ */
+ (void) glusterd_delete_all_bricks (stale_volinfo);
+ if (stale_volinfo->shandle) {
+ unlink (stale_volinfo->shandle->path);
+ (void) glusterd_store_handle_destroy (stale_volinfo->shandle);
+ stale_volinfo->shandle = NULL;
+ }
+ (void) glusterd_volinfo_delete (stale_volinfo);
+ return 0;
+}
+
+int32_t
+glusterd_import_friend_volume (dict_t *vols, size_t count)
+{
+
+ int32_t ret = -1;
+ glusterd_conf_t *priv = NULL;
+ xlator_t *this = NULL;
+ glusterd_volinfo_t *old_volinfo = NULL;
+ glusterd_volinfo_t *new_volinfo = NULL;
- ret = glusterd_create_volfiles (volinfo);
+ GF_ASSERT (vols);
+
+ this = THIS;
+ GF_ASSERT (this);
+ priv = this->private;
+ GF_ASSERT (priv);
+ ret = glusterd_import_volinfo (vols, count, &new_volinfo);
if (ret)
goto out;
- ret = glusterd_volume_compute_cksum (volinfo);
+ ret = glusterd_volinfo_find (new_volinfo->volname, &old_volinfo);
+ if (0 == ret) {
+ (void) glusterd_delete_stale_volume (old_volinfo, new_volinfo);
+ }
+
+ if (glusterd_is_volume_started (new_volinfo)) {
+ (void) glusterd_start_bricks (new_volinfo);
+ }
+
+ ret = glusterd_store_volinfo (new_volinfo, GLUSTERD_VOLINFO_VER_AC_NONE);
+ ret = glusterd_create_volfiles_and_notify_services (new_volinfo);
if (ret)
goto out;
-
+ list_add_tail (&new_volinfo->vol_list, &priv->volumes);
out:
gf_log ("", GF_LOG_DEBUG, "Returning with ret: %d", ret);
return ret;
@@ -1715,6 +1975,7 @@ glusterd_compare_friend_data (dict_t *vols, int32_t *status)
int32_t count = 0;
int i = 1;
gf_boolean_t update = _gf_false;
+ gf_boolean_t stale_nfs = _gf_false;
GF_ASSERT (vols);
GF_ASSERT (status);
@@ -1739,9 +2000,17 @@ glusterd_compare_friend_data (dict_t *vols, int32_t *status)
}
if (update) {
+ if (glusterd_is_nfs_started ())
+ stale_nfs = _gf_true;
ret = glusterd_import_friend_volumes (vols);
if (ret)
goto out;
+ if (_gf_false == glusterd_are_all_volumes_stopped ()) {
+ ret = glusterd_check_generate_start_nfs ();
+ } else {
+ if (stale_nfs)
+ glusterd_nfs_server_stop ();
+ }
}
out:
@@ -1890,16 +2159,10 @@ glusterd_remote_hostname_get (rpcsvc_request_t *req, char *remote_host, int len)
}
int
-glusterd_check_generate_start_nfs (glusterd_volinfo_t *volinfo)
+glusterd_check_generate_start_nfs ()
{
int ret = -1;
- if (!volinfo) {
- gf_log ("", GF_LOG_ERROR, "Invalid Arguments");
- goto out;
- }
-
-
ret = glusterd_create_nfs_volfile ();
if (ret)
goto out;
@@ -2024,14 +2287,14 @@ glusterd_restart_bricks (glusterd_conf_t *conf)
brick_list) {
glusterd_brick_start (volinfo, brickinfo);
}
- glusterd_check_generate_start_nfs (volinfo);
+ glusterd_check_generate_start_nfs ();
}
}
return ret;
}
int
-glusterd_get_brickinfo (xlator_t *this, const char *brickname, int port,
+glusterd_get_brickinfo (xlator_t *this, const char *brickname, int port,
gf_boolean_t localhost, glusterd_brickinfo_t **brickinfo)
{
glusterd_conf_t *priv = NULL;
@@ -2073,11 +2336,11 @@ glusterd_set_brick_status (glusterd_brickinfo_t *brickinfo,
}
}
-int
+gf_boolean_t
glusterd_is_brick_started (glusterd_brickinfo_t *brickinfo)
{
GF_ASSERT (brickinfo);
- return (!(brickinfo->status == GF_BRICK_STARTED));
+ return (brickinfo->status == GF_BRICK_STARTED);
}
int
@@ -2810,3 +3073,56 @@ glusterd_peerinfo_is_uuid_unknown (glusterd_peerinfo_t *peerinfo)
return _gf_true;
return _gf_false;
}
+
+int32_t
+glusterd_delete_volume (glusterd_volinfo_t *volinfo)
+{
+ int ret = -1;
+ GF_ASSERT (volinfo);
+
+ ret = glusterd_store_delete_volume (volinfo);
+
+ if (ret)
+ goto out;
+
+ ret = glusterd_volinfo_delete (volinfo);
+out:
+ gf_log ("", GF_LOG_DEBUG, "returning %d", ret);
+ return ret;
+}
+
+int32_t
+glusterd_delete_brick (glusterd_volinfo_t* volinfo,
+ glusterd_brickinfo_t *brickinfo)
+{
+ int ret = 0;
+ GF_ASSERT (volinfo);
+ GF_ASSERT (brickinfo);
+
+#ifdef DEBUG
+ ret = glusterd_volume_brickinfo_get (brickinfo->uuid,
+ brickinfo->hostname,
+ brickinfo->path, volinfo, NULL);
+ GF_ASSERT (0 == ret);
+#endif
+ glusterd_delete_volfile (volinfo, brickinfo);
+ glusterd_store_delete_brick (volinfo, brickinfo);
+ glusterd_brickinfo_delete (brickinfo);
+ volinfo->brick_count--;
+ return ret;
+}
+
+int32_t
+glusterd_delete_all_bricks (glusterd_volinfo_t* volinfo)
+{
+ int ret = 0;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ glusterd_brickinfo_t *tmp = NULL;
+
+ GF_ASSERT (volinfo);
+
+ list_for_each_entry_safe (brickinfo, tmp, &volinfo->bricks, brick_list) {
+ ret = glusterd_delete_brick (volinfo, brickinfo);
+ }
+ return ret;
+}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index e42d467f65b..ffb9e971aff 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -157,7 +157,7 @@ void
glusterd_set_volume_status (glusterd_volinfo_t *volinfo,
glusterd_volume_status status);
int
-glusterd_check_generate_start_nfs (glusterd_volinfo_t *volinfo);
+glusterd_check_generate_start_nfs (void);
int32_t
glusterd_volume_count_get (void);
int32_t
@@ -172,7 +172,7 @@ void
glusterd_set_brick_status (glusterd_brickinfo_t *brickinfo,
gf_brick_status_t status);
-int
+gf_boolean_t
glusterd_is_brick_started (glusterd_brickinfo_t *brickinfo);
int
@@ -206,7 +206,7 @@ int
glusterd_new_brick_validate (char *brick, glusterd_brickinfo_t *brickinfo,
char *op_errstr, size_t len);
int32_t
-glusterd_volume_bricks_delete (glusterd_volinfo_t *volinfo);
+glusterd_volume_brickinfos_delete (glusterd_volinfo_t *volinfo);
int32_t
glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path,
glusterd_volinfo_t *volinfo,
@@ -257,4 +257,16 @@ int
glusterd_clear_pending_nodes (struct list_head *list);
gf_boolean_t
glusterd_peerinfo_is_uuid_unknown (glusterd_peerinfo_t *peerinfo);
+int32_t
+glusterd_brick_connect (glusterd_volinfo_t *volinfo,
+ glusterd_brickinfo_t *brickinfo);
+int32_t
+glusterd_brick_disconnect (glusterd_brickinfo_t *brickinfo);
+int32_t
+glusterd_delete_volume (glusterd_volinfo_t *volinfo);
+int32_t
+glusterd_delete_brick (glusterd_volinfo_t* volinfo,
+ glusterd_brickinfo_t *brickinfo);
+int32_t
+glusterd_delete_all_bricks (glusterd_volinfo_t* volinfo);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 036502bdb56..33911d5209d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -1945,7 +1945,7 @@ glusterd_create_rb_volfiles (glusterd_volinfo_t *volinfo,
}
int
-glusterd_create_volfiles (glusterd_volinfo_t *volinfo)
+glusterd_create_volfiles_and_notify_services (glusterd_volinfo_t *volinfo)
{
int ret = -1;
@@ -2004,13 +2004,18 @@ int
glusterd_delete_volfile (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo)
{
+ int ret = 0;
char filename[PATH_MAX] = {0,};
GF_ASSERT (volinfo);
GF_ASSERT (brickinfo);
get_brick_filepath (filename, volinfo, brickinfo);
- return unlink (filename);
+ ret = unlink (filename);
+ if (ret)
+ gf_log ("glusterd", GF_LOG_ERROR, "failed to delete file: %s, "
+ "reason: %s", filename, strerror (errno));
+ return ret;
}
int
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h
index 3e56b562869..26861150147 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.h
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h
@@ -30,7 +30,7 @@
int glusterd_create_rb_volfiles (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo);
-int glusterd_create_volfiles (glusterd_volinfo_t *volinfo);
+int glusterd_create_volfiles_and_notify_services (glusterd_volinfo_t *volinfo);
void glusterd_get_nfs_filepath (char *filename);
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index a4b6b49b784..821a2ca46f2 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -198,7 +198,7 @@ struct glusterd_volinfo_ {
glusterd_brickinfo_t *src_brick;
glusterd_brickinfo_t *dst_brick;
- uint32_t version;
+ int version;
uint32_t cksum;
gf_transport_type transport_type;
@@ -402,9 +402,6 @@ glusterd_handle_friend_update (rpcsvc_request_t *req);
int
glusterd_handle_cli_stop_volume (rpcsvc_request_t *req);
-int32_t
-glusterd_delete_volume (rpcsvc_request_t *req, char *volname, int flags);
-
int
glusterd_handle_cli_delete_volume (rpcsvc_request_t *req);
@@ -417,9 +414,6 @@ glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags);
int
glusterd_handle_add_brick (rpcsvc_request_t *req);
-int32_t
-glusterd_replace_brick (rpcsvc_request_t *req, dict_t *dict);
-
int
glusterd_handle_replace_brick (rpcsvc_request_t *req);
@@ -484,7 +478,7 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo,
dict_t *volumes, int count);
int
-glusterd_restart_bricks(glusterd_conf_t *conf);
+glusterd_restart_bricks (glusterd_conf_t *conf);
int32_t
glusterd_volume_txn (rpcsvc_request_t *req, char *volname, int flags,