summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src
diff options
context:
space:
mode:
authorAnand Subramanian <anands@redhat.com>2014-05-15 08:19:14 +0530
committerVijay Bellur <vbellur@redhat.com>2014-06-15 10:33:23 -0700
commitec845d93e74644bbfe27e0b085a38dbd7c02480f (patch)
treee4e455e9f9d6f75a3426fcad4a6360c885890902 /xlators/mgmt/glusterd/src
parent056b99bfbc181a88579b8139d444f7dd2fa3b19e (diff)
Get snapshot info dynamically via new rpc and infra for snapview-server to refresh snaplist
BUG: 1105439 Change-Id: I4bb312a53d88f6f4955e69a3ef2b4955ec17f26d Signed-off-by: Anand Subramanian <anands@redhat.com> Reviewed-on: http://review.gluster.org/8001 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handshake.c114
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c96
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h7
3 files changed, 213 insertions, 4 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c
index 7be1e9017bd..3cb62624a07 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handshake.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c
@@ -32,6 +32,7 @@ extern struct rpc_clnt_program gd_peer_prog;
extern struct rpc_clnt_program gd_mgmt_prog;
extern struct rpc_clnt_program gd_mgmt_v3_prog;
+
#define TRUSTED_PREFIX "trusted-"
typedef ssize_t (*gfs_serialize_t) (struct iovec outmsg, void *data);
@@ -1046,8 +1047,8 @@ __server_get_volume_info (rpcsvc_request_t *req)
{
int ret = -1;
int32_t op_errno = ENOENT;
- gf_get_volume_info_req vol_info_req = {{0,}};
- gf_get_volume_info_rsp vol_info_rsp = {0,};
+ gf_get_volume_info_req vol_info_req = {{0,}};
+ gf_get_volume_info_rsp vol_info_rsp = {0,};
char *volname = NULL;
glusterd_volinfo_t *volinfo = NULL;
dict_t *dict = NULL;
@@ -1058,7 +1059,7 @@ __server_get_volume_info (rpcsvc_request_t *req)
ret = xdr_to_generic (req->msg[0], &vol_info_req,
(xdrproc_t)xdr_gf_get_volume_info_req);
if (ret < 0) {
- //failed to decode msg;
+ /* failed to decode msg */
req->rpc_err = GARBAGE_ARGS;
goto out;
}
@@ -1098,7 +1099,7 @@ __server_get_volume_info (rpcsvc_request_t *req)
}
if (!flags) {
- //Nothing to query about. Just return success
+ /* Nothing to query about. Just return success */
gf_log (THIS->name, GF_LOG_ERROR, "No flags set");
ret = 0;
goto out;
@@ -1177,11 +1178,116 @@ server_get_volume_info (rpcsvc_request_t *req)
__server_get_volume_info);
}
+
+/*
+ * glusterd function to get the list of snapshot names and uuids
+ */
+int
+__server_get_snap_info (rpcsvc_request_t *req)
+{
+ int ret = -1;
+ int op_errno = ENOENT;
+ gf_getsnap_name_uuid_req snap_info_req = {{0,}};
+ gf_getsnap_name_uuid_rsp snap_info_rsp = {0,};
+ dict_t *dict = NULL;
+ dict_t *dict_rsp = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ char *volname = NULL;
+
+ GF_ASSERT (req);
+
+ ret = xdr_to_generic (req->msg[0], &snap_info_req,
+ (xdrproc_t)xdr_gf_getsnap_name_uuid_req);
+ if (ret < 0) {
+ req->rpc_err = GARBAGE_ARGS;
+ gf_log ("glusterd", GF_LOG_ERROR,
+ "Failed to decode management handshake response");
+ goto out;
+ }
+
+ if (snap_info_req.dict.dict_len) {
+ dict = dict_new ();
+ if (!dict) {
+ op_errno = ENOMEM;
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_unserialize (snap_info_req.dict.dict_val,
+ snap_info_req.dict.dict_len,
+ &dict);
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR,
+ "Failed to unserialize dictionary");
+ op_errno = EINVAL;
+ ret = -1;
+ goto out;
+ } else {
+ dict->extra_stdfree = snap_info_req.dict.dict_val;
+ }
+ }
+
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret) {
+ op_errno = EINVAL;
+ gf_log ("glusterd", GF_LOG_ERROR,
+ "Failed to retrieve volname");
+ ret = -1;
+ goto out;
+ }
+
+ dict_rsp = dict_new ();
+ if (!dict_rsp) {
+ op_errno = ENOMEM;
+ ret = -1;
+ goto out;
+ }
+
+ ret = glusterd_snapshot_get_volnames_uuids (dict_rsp, volname,
+ &snap_info_rsp);
+
+ if (ret) {
+ gf_log ("glusterd", GF_LOG_ERROR,
+ "Error getting snapshot volume names and uuids : %s",
+ volname);
+ op_errno = EINVAL;
+ }
+
+out:
+ snap_info_rsp.op_ret = ret;
+ snap_info_rsp.op_errno = op_errno;
+ snap_info_rsp.op_errstr = "";
+ glusterd_submit_reply (req, &snap_info_rsp, NULL, 0, NULL,
+ (xdrproc_t)xdr_gf_getsnap_name_uuid_rsp);
+
+ if (dict) {
+ dict_unref (dict);
+ }
+
+ if (dict_rsp) {
+ dict_unref (dict_rsp);
+ }
+
+ if (snap_info_rsp.dict.dict_val) {
+ GF_FREE (snap_info_rsp.dict.dict_val);
+ }
+
+ return 0;
+}
+
+int
+server_get_snap_info (rpcsvc_request_t *req)
+{
+ return glusterd_big_locked_handler (req,
+ __server_get_snap_info);
+}
+
rpcsvc_actor_t gluster_handshake_actors[GF_HNDSK_MAXVALUE] = {
[GF_HNDSK_NULL] = {"NULL", GF_HNDSK_NULL, NULL, NULL, 0, DRC_NA},
[GF_HNDSK_GETSPEC] = {"GETSPEC", GF_HNDSK_GETSPEC, server_getspec, NULL, 0, DRC_NA},
[GF_HNDSK_EVENT_NOTIFY] = {"EVENTNOTIFY", GF_HNDSK_EVENT_NOTIFY, server_event_notify, NULL, 0, DRC_NA},
[GF_HNDSK_GET_VOLUME_INFO] = {"GETVOLUMEINFO", GF_HNDSK_GET_VOLUME_INFO, server_get_volume_info, NULL, 0, DRC_NA},
+ [GF_HNDSK_GET_SNAPSHOT_INFO] = {"GETSNAPINFO", GF_HNDSK_GET_SNAPSHOT_INFO, server_get_snap_info, NULL, 0, DRC_NA},
};
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 117004b4452..cca94f17133 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -55,6 +55,8 @@
#include "glusterd-mgmt.h"
#include "glusterd-syncop.h"
+#include "glusterfs3.h"
+
#include "syscall.h"
#include "cli1-xdr.h"
#include "xdr-generic.h"
@@ -7712,3 +7714,97 @@ out:
return ret;
}
+
+
+
+int
+glusterd_snapshot_get_volnames_uuids (dict_t *dict,
+ char *volname,
+ gf_getsnap_name_uuid_rsp *snap_info_rsp)
+{
+ int ret = -1;
+ int snapcount = 0;
+ char key[PATH_MAX] = {0,};
+ glusterd_volinfo_t *snap_vol = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_volinfo_t *tmp_vol = NULL;
+ xlator_t *this = NULL;
+ int op_errno = 0;
+
+ this = THIS;
+ GF_ASSERT (this);
+ GF_ASSERT (volname);
+ GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, dict, out,
+ op_errno, EINVAL);
+ GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, volname, out,
+ op_errno, EINVAL);
+ GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, snap_info_rsp, out,
+ op_errno, EINVAL);
+
+ ret = glusterd_volinfo_find (volname, &volinfo);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to get volinfo of volume %s",
+ volname);
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ list_for_each_entry_safe (snap_vol, tmp_vol, &volinfo->snap_volumes,
+ snapvol_list) {
+ snapcount++;
+
+ /* Set Snap Name */
+ snprintf (key, sizeof (key), "snapname.%d", snapcount);
+ ret = dict_set_dynstr_with_alloc (dict, key,
+ snap_vol->snapshot->snapname);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set "
+ "snap name in dictionary");
+ goto out;
+ }
+
+ /* Set Snap ID */
+ snprintf (key, sizeof (key), "snap-id.%d", snapcount);
+ ret = dict_set_dynstr_with_alloc (dict, key,
+ uuid_utoa(snap_vol->snapshot->snap_id));
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set "
+ "snap id in dictionary");
+ goto out;
+ }
+
+ /* Snap Volname which is used to activate the snap vol */
+ snprintf (key, sizeof (key), "snap-volname.%d", snapcount);
+ ret = dict_set_dynstr_with_alloc (dict, key, snap_vol->volname);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set "
+ "snap id in dictionary");
+ goto out;
+ }
+ }
+
+ ret = dict_set_int32 (dict, "snap-count", snapcount);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set snapcount");
+ op_errno = -ret;
+ goto out;
+ }
+
+ ret = dict_allocate_and_serialize (dict, &snap_info_rsp->dict.dict_val,
+ &snap_info_rsp->dict.dict_len);
+ if (ret) {
+ op_errno = -ret;
+ ret = -1;
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ snap_info_rsp->op_ret = ret;
+ snap_info_rsp->op_errno = op_errno;
+ snap_info_rsp->op_errstr = "";
+
+ return ret;
+}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 1764f642d3f..aae91cdff8d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -28,6 +28,8 @@
#include "rpc-clnt.h"
#include "protocol-common.h"
+#include "glusterfs3-xdr.h"
+
#define GLUSTERD_SOCK_DIR "/var/run"
#define GLUSTERD_ASSIGN_BRICKID_TO_BRICKINFO(brickinfo, volinfo, brickid) do {\
sprintf (brickinfo->brick_id, "%s-client-%d",\
@@ -902,6 +904,11 @@ glusterd_is_snap_soft_limit_reached (glusterd_volinfo_t *volinfo,
int32_t
glusterd_find_brick_mount_path (char *brick_path, int32_t brick_count,
char **brick_mount_path);
+/*
+ * Function to retrieve list of snap volnames and their uuids
+ */
+int glusterd_snapshot_get_volnames_uuids (dict_t *dict,
+ char *volname, gf_getsnap_name_uuid_rsp *snap_info_rsp);
int
glusterd_update_fstype (char *orig_brick_path,