summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-store.c
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendra@redhat.com>2014-06-19 15:51:39 +0530
committerKaushal M <kaushal@redhat.com>2014-06-30 22:30:58 -0700
commitc6f040524d75011c44dcc9afdfef80c60c78f7f7 (patch)
tree8c1dd960693a98e07088d7026c7e98b7d8b8c8c2 /xlators/mgmt/glusterd/src/glusterd-store.c
parent2417de9c37d83e36567551dc682bb23f851fd2d7 (diff)
mgmt/glusterd: display snapd status as part of volume status
* Made changes to save the port used by snapd in the info file for the volume i.e. <glusterd-working-directory>/vols/<volname>/info This is how the gluster volume status of a volume would look like for which the uss feature is enabled. [root@tatooine ~]# gluster volume status vol Status of volume: vol Gluster process Port Online Pid ------------------------------------------------------------------------------ Brick tatooine:/export1/vol 49155 Y 5041 Snapshot Daemon on localhost 49156 Y 5080 NFS Server on localhost 2049 Y 5087 Task Status of Volume vol ------------------------------------------------------------------------------ There are no active volume tasks Change-Id: I8f3e5d7d764a728497c2a5279a07486317bd7c6d BUG: 1111041 Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-on: http://review.gluster.org/8114 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Kaushal M <kaushal@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-store.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c213
1 files changed, 212 insertions, 1 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 839d77b7f8d..0177ed169fc 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -131,6 +131,24 @@ glusterd_store_brickinfopath_set (glusterd_volinfo_t *volinfo,
snprintf (brickpath, len, "%s/%s", brickdirpath, brickfname);
}
+static void
+glusterd_store_snapd_path_set (glusterd_volinfo_t *volinfo,
+ char *snapd_path, size_t len)
+{
+ char volpath[PATH_MAX] = {0, };
+ glusterd_conf_t *priv = NULL;
+
+ GF_ASSERT (volinfo);
+ GF_ASSERT (len >= PATH_MAX);
+
+ priv = THIS->private;
+ GF_ASSERT (priv);
+
+ GLUSTERD_GET_VOLUME_DIR (volpath, volinfo, priv);
+
+ snprintf (snapd_path, len, "%s/snapd.info", volpath);
+}
+
gf_boolean_t
glusterd_store_is_valid_brickpath (char *volname, char *brick)
{
@@ -249,6 +267,21 @@ glusterd_store_create_brick_shandle_on_absence (glusterd_volinfo_t *volinfo,
return ret;
}
+int32_t
+glusterd_store_create_snapd_shandle_on_absence (glusterd_volinfo_t *volinfo)
+{
+ char snapd_path[PATH_MAX] = {0,};
+ int32_t ret = 0;
+
+ GF_ASSERT (volinfo);
+
+ glusterd_store_snapd_path_set (volinfo, snapd_path,
+ sizeof (snapd_path));
+ ret = gf_store_handle_create_on_absence (&volinfo->snapd.handle,
+ snapd_path);
+ return ret;
+}
+
/* Store the bricks snapshot details only if required
*
* The snapshot details will be stored only if the cluster op-version is
@@ -353,6 +386,30 @@ out:
}
int32_t
+glusterd_store_snapd_write (int fd, glusterd_volinfo_t *volinfo)
+{
+ char value[256] = {0,};
+ int32_t ret = 0;
+ xlator_t *this = NULL;
+
+ GF_ASSERT (volinfo);
+ GF_ASSERT (fd > 0);
+
+ this = THIS;
+ GF_ASSERT (this);
+
+ snprintf (value, sizeof(value), "%d", volinfo->snapd.port);
+ ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAPD_PORT, value);
+ if (ret)
+ gf_log (this->name, GF_LOG_ERROR, "failed to store the snapd "
+ "port of volume %s", volinfo->volname);
+
+
+ gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+int32_t
glusterd_store_perform_brick_store (glusterd_brickinfo_t *brickinfo)
{
int fd = -1;
@@ -377,6 +434,42 @@ out:
}
int32_t
+glusterd_store_perform_snapd_store (glusterd_volinfo_t *volinfo)
+{
+ int fd = -1;
+ int32_t ret = -1;
+ xlator_t *this = NULL;
+
+ GF_ASSERT (volinfo);
+
+ this = THIS;
+ GF_ASSERT (this);
+
+ fd = gf_store_mkstemp (volinfo->snapd.handle);
+ if (fd <= 0) {
+ gf_log (this->name, GF_LOG_ERROR, "failed to create the "
+ "temporary file for the snapd store handle of volume "
+ "%s", volinfo->volname);
+ goto out;
+ }
+
+ ret = glusterd_store_snapd_write (fd, volinfo);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "failed to write snapd port "
+ "info to store handle (volume: %s", volinfo->volname);
+ goto out;
+ }
+
+ ret = gf_store_rename_tmppath (volinfo->snapd.handle);
+
+out:
+ if (ret && (fd > 0))
+ gf_store_unlink_tmppath (volinfo->snapd.handle);
+ gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+int32_t
glusterd_store_brickinfo (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo, int32_t brick_count,
int vol_fd)
@@ -407,6 +500,37 @@ out:
}
int32_t
+glusterd_store_snapd_info (glusterd_volinfo_t *volinfo)
+{
+ int32_t ret = -1;
+ xlator_t *this = NULL;
+
+ GF_ASSERT (volinfo);
+
+ this = THIS;
+ GF_ASSERT (this);
+
+ ret = glusterd_store_create_snapd_shandle_on_absence (volinfo);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "failed to create store "
+ "handle for snapd (volume: %s)", volinfo->volname);
+ goto out;
+ }
+
+ ret = glusterd_store_perform_snapd_store (volinfo);
+ if (ret)
+ gf_log (this->name, GF_LOG_ERROR, "failed to store snapd info "
+ "of the volume %s", volinfo->volname);
+
+out:
+ if (ret)
+ gf_store_unlink_tmppath (volinfo->snapd.handle);
+
+ gf_log (this->name, GF_LOG_DEBUG, "Returning with %d", ret);
+ return ret;
+}
+
+int32_t
glusterd_store_delete_brick (glusterd_brickinfo_t *brickinfo, char *delete_path)
{
int32_t ret = -1;
@@ -654,6 +778,11 @@ glusterd_volume_write_snap_details (int fd, glusterd_volinfo_t *volinfo)
goto out;
}
+ ret = glusterd_store_snapd_info (volinfo);
+ if (ret)
+ gf_log (this->name, GF_LOG_ERROR, "snapd info store failed "
+ "volume: %s", volinfo->volname);
+
out:
if (ret)
gf_log (this->name, GF_LOG_ERROR, "Failed to write snap details"
@@ -1329,6 +1458,8 @@ glusterd_store_volume_cleanup_tmp (glusterd_volinfo_t *volinfo)
gf_store_unlink_tmppath (volinfo->rb_shandle);
gf_store_unlink_tmppath (volinfo->node_state_shandle);
+
+ gf_store_unlink_tmppath (volinfo->snapd.handle);
}
int32_t
@@ -1948,6 +2079,81 @@ out:
return ret;
}
+int
+glusterd_store_retrieve_snapd (glusterd_volinfo_t *volinfo)
+{
+ int ret = -1;
+ int exists = 0;
+ char *key = NULL;
+ char *value = NULL;
+ char volpath[PATH_MAX] = {0,};
+ char path[PATH_MAX] = {0,};
+ xlator_t *this = NULL;
+ glusterd_conf_t *conf = NULL;
+ gf_store_iter_t *iter = NULL;
+ gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
+
+ this = THIS;
+ GF_ASSERT (this);
+ conf = THIS->private;
+ GF_ASSERT (volinfo);
+
+ if (conf->op_version < GD_OP_VERSION_3_6_0) {
+ ret = 0;
+ goto out;
+ }
+
+ GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, conf);
+
+ snprintf (path, sizeof (path), "%s/%s", volpath,
+ GLUSTERD_VOLUME_SNAPD_INFO_FILE);
+
+ ret = gf_store_handle_retrieve (path, &volinfo->snapd.handle);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "volinfo handle is NULL");
+ goto out;
+ }
+
+ ret = gf_store_iter_new (volinfo->snapd.handle, &iter);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get new store "
+ "iter");
+ goto out;
+ }
+
+ ret = gf_store_iter_get_next (iter, &key, &value, &op_errno);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get next store "
+ "iter");
+ goto out;
+ }
+
+ while (!ret) {
+ if (!strncmp (key, GLUSTERD_STORE_KEY_SNAPD_PORT,
+ strlen (GLUSTERD_STORE_KEY_SNAPD_PORT))) {
+ volinfo->snapd.port = atoi (value);
+ }
+
+ ret = gf_store_iter_get_next (iter, &key, &value,
+ &op_errno);
+ }
+
+ if (op_errno != GD_STORE_EOF)
+ goto out;
+
+ ret = gf_store_iter_destroy (iter);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to destroy store "
+ "iter");
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ return ret;
+}
+
int32_t
glusterd_store_retrieve_bricks (glusterd_volinfo_t *volinfo)
{
@@ -2452,7 +2658,8 @@ glusterd_store_update_volinfo (glusterd_volinfo_t *volinfo)
"failed to parse restored snap's uuid");
} else if (!strncmp (key, GLUSTERD_STORE_KEY_PARENT_VOLNAME,
strlen (GLUSTERD_STORE_KEY_PARENT_VOLNAME))) {
- strncpy (volinfo->parent_volname, value, sizeof(volinfo->parent_volname) - 1);
+ strncpy (volinfo->parent_volname, value,
+ sizeof(volinfo->parent_volname) - 1);
} else {
if (is_key_glusterd_hooks_friendly (key)) {
@@ -2598,6 +2805,10 @@ glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap)
if (ret)
goto out;
+ ret = glusterd_store_retrieve_snapd (volinfo);
+ if (ret)
+ goto out;
+
ret = glusterd_compute_cksum (volinfo, _gf_false);
if (ret)
goto out;