summaryrefslogtreecommitdiffstats
path: root/cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/cli-cmd-parser.c7
-rw-r--r--cli/src/cli-rpc-ops.c278
2 files changed, 221 insertions, 64 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 287943777df..5e619f3cd17 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -3532,12 +3532,13 @@ cli_snap_status_parse (dict_t *dict, const char **words, int wordcount)
out:
if (ret == 0) {
- ret = dict_set_int32 (dict, "cmd", cmd);
+ ret = dict_set_int32 (dict, "status-cmd", cmd);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Could not save cmd "
"of snapshot status");
}
}
+
return ret;
}
@@ -3812,7 +3813,9 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
} else if (!strcmp (w, "deactivate")) {
type = GF_SNAP_OPTION_TYPE_DEACTIVATE;
}
- if (type != GF_SNAP_OPTION_TYPE_CONFIG) {
+
+ if (type != GF_SNAP_OPTION_TYPE_CONFIG &&
+ type != GF_SNAP_OPTION_TYPE_STATUS) {
ret = dict_set_int32 (dict, "hold_snap_locks", _gf_true);
if (ret) {
gf_log ("cli", GF_LOG_ERROR,
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 9312f15dc20..37424c68559 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -82,6 +82,9 @@ char *cli_vol_task_status_str[] = {"not started",
};
int32_t
+gf_cli_snapshot (call_frame_t *frame, xlator_t *this, void *data);
+
+int32_t
gf_cli_get_volume (call_frame_t *frame, xlator_t *this,
void *data);
@@ -7636,14 +7639,13 @@ out:
}
int32_t
-cli_snapshot_remove_reply (gf_cli_rsp *rsp, dict_t *dict, call_frame_t *frame)
+cli_snapshot_remove_reply (gf_cli_rsp *rsp, dict_t *dict)
{
int32_t ret = -1;
char *snap_name = NULL;
GF_ASSERT (rsp);
GF_ASSERT (dict);
- GF_ASSERT (frame);
if (rsp->op_ret) {
cli_err("snapshot delete: failed: %s",
@@ -8361,99 +8363,128 @@ out:
}
int
-cli_snap_status_all (dict_t *dict) {
+cli_populate_req_dict_for_status (dict_t *snap_dict, dict_t *dict, int index) {
int ret = -1;
char key[PATH_MAX] = "";
+ char *buffer = NULL;
+ int type = 0;
int snapcount = 0;
- int i = 0;
+ GF_ASSERT (snap_dict);
GF_ASSERT (dict);
- ret = dict_get_int32 (dict, "status.snapcount", &snapcount);
+ ret = dict_set_uint32 (snap_dict, "status-cmd",
+ GF_SNAP_STATUS_TYPE_SNAP);
if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Could not get snapcount");
+ gf_log ("cli", GF_LOG_ERROR, "Could not save command "
+ "type in snap dict");
goto out;
}
- if (snapcount == 0) {
- cli_out ("No snapshots present");
+ ret = snprintf (key, sizeof (key), "status.snap%d.snapname", index);
+ if (ret < 0) {
+ goto out;
+ }
+
+ ret = dict_get_str (dict, key, &buffer);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not get snapname");
+ goto out;
}
- for (i = 0 ; i < snapcount; i++) {
- ret = snprintf (key, sizeof (key), "status.snap%d",i);
- if (ret < 0) {
- goto out;
- }
- ret = cli_get_single_snap_status (dict, key);
+ ret = dict_set_str (snap_dict, "snapname", buffer);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not save snapname "
+ "in snap dict");
+ goto out;
+
}
+
+ ret = dict_set_int32 (snap_dict, "type", GF_SNAP_OPTION_TYPE_STATUS);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "Could not save command type");
+ goto out;
+ }
+
+ ret = dict_set_dynstr_with_alloc (snap_dict, "cmd-str",
+ "snapshot status");
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "Could not save command string as status");
+ goto out;
+ }
+
+ ret = dict_set_int32 (snap_dict, "hold_vol_locks", _gf_false);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "Setting volume lock flag failed");
+ goto out;
+ }
+
out:
return ret;
}
-
int
-cli_snapshot_status_display (dict_t *dict, gf_cli_rsp *rsp)
+cli_snapshot_status (dict_t *dict, gf_cli_rsp *rsp,
+ call_frame_t *frame)
{
char key[PATH_MAX] = "";
int ret = -1;
int status_cmd = -1;
+ cli_local_t *local = NULL;
GF_ASSERT (dict);
GF_ASSERT (rsp);
+ GF_ASSERT (frame);
+
+ local = ((call_frame_t *) frame) -> local;
+ if (!local) {
+ gf_log ("cli", GF_LOG_ERROR, "frame->local is NULL");
+ goto out;
+ }
if (rsp->op_ret) {
- cli_err ("Snapshot Status : failed: %s",
- rsp->op_errstr ? rsp->op_errstr :
- "Please check log file for details");
+ if (rsp->op_errstr) {
+ ret = dict_set_dynstr_with_alloc (local->dict,
+ "op_err_str",
+ rsp->op_errstr);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to set "
+ "op_errstr in local dictionary");
+ goto out;
+ }
+ }
ret = rsp->op_ret;
goto out;
}
- ret = dict_get_int32 (dict, "cmd", &status_cmd);
+ ret = dict_get_int32 (dict, "status-cmd", &status_cmd);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Could not fetch status type");
goto out;
}
- switch (status_cmd) {
- case GF_SNAP_STATUS_TYPE_ALL:
- {
- ret = cli_snap_status_all (dict);
- if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Could not fetch "
- "status of all snap");
- goto out;
- }
- break;
- }
- case GF_SNAP_STATUS_TYPE_SNAP:
- {
- ret = snprintf (key, sizeof (key), "status.snap0");
- if (ret < 0) {
- goto out;
- }
- ret = cli_get_single_snap_status (dict, key);
- if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Could not fetch "
- "status of snap");
- goto out;
- }
- break;
- }
+ if (status_cmd != GF_SNAP_STATUS_TYPE_SNAP) {
+ dict_copy (dict, local->dict);
+ goto out;
+ }
- case GF_SNAP_STATUS_TYPE_VOL:
- {
- ret = cli_snap_status_all (dict);
- if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Could not fetch "
- "status of snap in a volume");
- goto out;
- }
- break;
- }
- default:
- break;
+
+ ret = snprintf (key, sizeof (key), "status.snap0");
+ if (ret < 0) {
+ goto out;
}
+
+ ret = cli_get_single_snap_status (dict, key);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not fetch "
+ "status of snap");
+ goto out;
+ }
+
+ ret = 0;
out:
return ret;
}
@@ -8650,7 +8681,7 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
break;
case GF_SNAP_OPTION_TYPE_DELETE:
- ret = cli_snapshot_remove_reply (&rsp, dict, frame);
+ ret = cli_snapshot_remove_reply (&rsp, dict);
if (ret) {
gf_log ("cli", GF_LOG_ERROR,
"Failed to delete snap");
@@ -8659,7 +8690,7 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
break;
case GF_SNAP_OPTION_TYPE_STATUS:
- ret = cli_snapshot_status_display (dict, &rsp);
+ ret = cli_snapshot_status (dict, &rsp, frame);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Failed to display "
"snapshot status output.");
@@ -8684,23 +8715,146 @@ out:
}
int32_t
+gf_cli_snapshot_for_status (call_frame_t *frame, xlator_t *this,
+ void *data)
+{
+
+ gf_cli_req req = {{0,}};
+ dict_t *options = NULL;
+ int ret = -1;
+ int32_t cmd = -1;
+ cli_local_t *local = NULL;
+ dict_t *snap_dict = NULL;
+ int snapcount = 0;
+ int i = 0;
+
+ if (!frame || !this || !data)
+ goto out;
+
+ if (frame->local) {
+ local = frame->local;
+ } else {
+ goto out;
+ }
+
+ options = data;
+
+ ret = dict_get_int32 (local->dict, "status-cmd", &cmd);
+
+ if (cmd == GF_SNAP_STATUS_TYPE_ALL ||
+ cmd == GF_SNAP_STATUS_TYPE_VOL) {
+
+ ret = dict_get_int32 (local->dict, "status.snapcount",
+ &snapcount);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not get snapcount");
+ goto out;
+ }
+
+ if (snapcount == 0) {
+ cli_out ("No snapshots present");
+ }
+
+ for (i = 0 ; i < snapcount; i++) {
+ ret = -1;
+
+ snap_dict = dict_new();
+ if (!snap_dict)
+ goto out;
+
+ ret = cli_populate_req_dict_for_status (snap_dict,
+ local->dict, i);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not "
+ "populate snap request dictionary");
+ goto out;
+ }
+
+ ret = cli_to_glusterd (&req, frame,
+ gf_cli_snapshot_cbk,
+ (xdrproc_t) xdr_gf_cli_req, snap_dict,
+ GLUSTER_CLI_SNAP, this, cli_rpc_prog,
+ NULL);
+
+ /* Ignore the return value and error for snapshot
+ * status of type "ALL" or "VOL"
+ *
+ * Scenario : There might be case where status command
+ * and delete command might be issued at the same time.
+ * In that case when status tried to fetch detail of
+ * snap which has been deleted by concurrent command,
+ * then it will show snapshot not present. Which will
+ * not be appropriate.
+ */
+ dict_unref (snap_dict);
+ }
+ }
+out:
+ return ret;
+
+ if (ret && snap_dict)
+ dict_unref (snap_dict);
+}
+
+int32_t
gf_cli_snapshot (call_frame_t *frame, xlator_t *this,
void *data)
{
- gf_cli_req req = {{0,}};
- dict_t *options = NULL;
- int ret = -1;
+ gf_cli_req req = {{0,}};
+ dict_t *options = NULL;
+ int ret = -1;
+ int tmp_ret = -1;
+ cli_local_t *local = NULL;
+ char *err_str = NULL;
+ int type = -1;
if (!frame || !this || !data)
goto out;
+ if (frame->local) {
+ local = frame->local;
+ } else {
+ goto out;
+ }
+
options = data;
+ ret = dict_get_int32 (local->dict, "type", &type);
+
+
ret = cli_to_glusterd (&req, frame, gf_cli_snapshot_cbk,
(xdrproc_t) xdr_gf_cli_req, options,
GLUSTER_CLI_SNAP, this, cli_rpc_prog,
NULL);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "cli_to_glusterd for "
+ "snapshot failed");
+ goto out;
+ }
+
+ if (GF_SNAP_OPTION_TYPE_STATUS == type) {
+ ret = gf_cli_snapshot_for_status (frame, this, data);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "cli to glusterd "
+ "for snapshot status command failed");
+ goto out;
+ }
+ }
+
+ ret = 0;
+
out:
+ if (ret && GF_SNAP_OPTION_TYPE_STATUS == type) {
+ tmp_ret = dict_get_str (local->dict, "op_err_str", &err_str);
+ if (err_str) {
+ cli_err ("Snapshot Status : failed: %s", err_str);
+ dict_del (local->dict, "op_err_str");
+ } else {
+ cli_err ("Snapshot Status : failed: %s", "Please "
+ "check log file for details");
+ }
+ }
+
gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
GF_FREE (req.dict.dict_val);
n801' href='#n801'>801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165