summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRajesh Joseph <rjoseph@redhat.com>2013-12-02 00:46:48 -0800
committerGerrit Code Review <review@dev.gluster.org>2013-12-02 00:46:48 -0800
commitca5659d13f7ea63e9b6f9ee7cd9152ae1750ae54 (patch)
treea493e2251c9e5419ff0b28ecb898357fbeae0a4c
parent5fb7e741c746bf32162967720daceda04d56f615 (diff)
parente5838eeea0ccc4ff6af6457be6d7ac8736ee748e (diff)
Merge "mgmt/glusterd : snapshot list, minor fixes." into development
-rw-r--r--cli/src/cli-rpc-ops.c81
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c99
2 files changed, 134 insertions, 46 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index c625cc9..830bd76 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7534,13 +7534,14 @@ out:
/*Function to list the snap "gluster snapshot list" */
static int
list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
- int64_t snapcount_total = -1 ;
- int64_t snapcount = -1 ;
- char buffer[PATH_MAX] = "" ;
- char *get_buffer = NULL;
- int8_t detail = 0 ;
- int64_t i = 0 ;
- int ret = -1 ;
+ uint64_t snapcount_total = 0 ;
+ uint64_t snapcount = 0 ;
+ char buffer[PATH_MAX] = "" ;
+ char *get_buffer = NULL;
+ int8_t detail = 0 ;
+ uint64_t i = 0 ;
+ int ret = -1 ;
+ uint64_t snap_available = 0 ;
GF_ASSERT (dict_n);
GF_ASSERT (prefix_str);
@@ -7574,7 +7575,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
ret = 0;
goto out;
}
- cli_out ("Vol Name : %s", get_buffer);
+ cli_out ("\nVolume Name : %s", get_buffer);
/* if Volume is present then get the snapcount.
* string is "snaplist.vol{0..}.snap-count.
*/
@@ -7583,7 +7584,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
if (ret < 0) { /* Negative value is an error */
goto out;
}
- ret = dict_get_int64 (dict_n, buffer, &snapcount);
+ ret = dict_get_uint64 (dict_n, buffer, &snapcount);
if (ret) {
gf_log("", GF_LOG_ERROR, "Could not fetch snapcount");
goto out;
@@ -7596,17 +7597,37 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) {
goto out;
}
+ /* "snap-count-total" holds number of snapshots taken
+ * whereas "snap-count" holds number of snapshots to
+ * be displayed
+ * Ex : gluster snapshot list vol1 -s snap1
+ * Here "snap-count-total" contains number of snapshots
+ * of volume "vol1", whereas "snap-count" is 1 here,
+ * as we are displaying details of only 1 snap "snap1"
+ */
ret = snprintf (buffer, sizeof (buffer),
"%s.snap-count-total", prefix_str);
if (ret < 0) {
goto out;
}
- ret = dict_get_int64 (dict_n, buffer, &snapcount_total);
+ ret = dict_get_uint64 (dict_n, buffer, &snapcount_total);
if (!ret)
- cli_out ("Total Snap Count : %ld", snapcount_total);
+ cli_out ("Number of snaps taken : %ld", snapcount_total);
else
gf_log ("", GF_LOG_ERROR, "Failed to get snapcount total");
+ ret = snprintf (buffer, sizeof (buffer),
+ "%s.snap-available", prefix_str);
+ if (ret < 0) {
+ goto out;
+ }
+ ret = dict_get_uint64 (dict_n, buffer, &snap_available);
+ if (!ret)
+ cli_out ("Number of snaps available : %ld",
+ snap_available);
+ else
+ gf_log ("", GF_LOG_ERROR, "Failed to get snap-available");
+
for (i = 0 ; i < snapcount; i++) {
/* get snapname "snaplist.vol-{0..}.snap-{0..}.snapname" */
ret = snprintf (buffer, sizeof(buffer),
@@ -7707,8 +7728,8 @@ list_snap_of_cg (dict_t *dict) {
int8_t detail = 0 ;
char *get_buffer = NULL;
char cg_name_list[PATH_MAX] = "" ;
- int64_t cg_volcount = -1 ;
- int64_t i = -1 ;
+ int64_t cg_volcount = 0 ;
+ uint64_t i = 0 ;
GF_ASSERT(dict);
@@ -7786,8 +7807,8 @@ out :
static int
call_list_snap_of_volume(dict_t *dict){
int ret = -1;
- int64_t volcount = -1;
- int64_t i = -1;
+ int64_t volcount = 0;
+ uint64_t i = 0;
char vol_name_prefix[PATH_MAX] = "";
ret = dict_get_int64 (dict, "snaplist.vol-count", &volcount);
@@ -7947,17 +7968,33 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
*/
ret = dict_get_int64 (dict, "snaplist.vol-count", &volcount);
if (ret){
- gf_log("", GF_LOG_ERROR, "Could not fetch volcount");
- ret = -1;
+ /* if "snaplist.vol-count" is not present then check
+ * whether "snaplist.cg-0.vol-count" is present
+ */
+ ret = dict_get_int64 (dict, "snaplist.cg-0.vol-count",
+ &volcount);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Could not fetch"
+ " cg-volcount");
+ goto out;
+ }
+ ret = list_snap_of_cg (dict);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR,
+ "Could not list snaps present in CG");
+ }
goto out;
}
if (volcount >= 1) {
ret = call_list_snap_of_volume (dict);
- } else {
- /* get the volumes present in CG
- * and list snap of each volume
- */
- ret = list_snap_of_cg (dict);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR,
+ "Could not list snaps of volume");
+ goto out;
+ }
+ }
+ else {
+ cli_out ("Snapshots not present");
}
break;
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 82335e8..afe2251 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -657,7 +657,7 @@ glusterd_new_snap_object()
glusterd_snap_cg_t*
glusterd_new_snap_cg_object(int64_t volume_count)
{
- glusterd_snap_cg_t *cg = NULL;
+ glusterd_snap_cg_t *cg = NULL;
glusterd_volinfo_t *volinfo = NULL;
if (volume_count < 0) {
@@ -1279,13 +1279,16 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
glusterd_volinfo_t *volinfo,
char *snapname, int8_t detail)
{
- int ret = -1;
- ssize_t index = -1;
- glusterd_snap_t *entry = NULL;
- glusterd_snap_t *tmp = NULL;
- xlator_t *this = NULL;
- char *value = NULL;
+ int ret = -1;
+ uint64_t index = 0;
+ glusterd_snap_t *entry = NULL;
+ glusterd_snap_t *tmp = NULL;
+ xlator_t *this = NULL;
+ char *value = NULL;
char key[256];
+ glusterd_conf_t *conf = NULL;
+ uint64_t snap_limit = 0;
+ char err_str[PATH_MAX];
this = THIS;
@@ -1295,6 +1298,9 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
GF_ASSERT (keyprefix);
GF_ASSERT (volinfo);
+ conf = this->private;
+ GF_ASSERT (conf);
+
value = gf_strdup (volinfo->volname);
if (NULL == value) {
goto out;
@@ -1319,7 +1325,36 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
ret = dict_set_int64 (dict, key, volinfo->snap_count);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to set total snap count");
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set total"
+ " snap count");
+ goto out;
+ }
+ ret = snprintf (key, sizeof (key), "%s.snap-available", keyprefix);
+ if (ret < 0) {
+ goto out;
+ }
+
+ if (conf->snap_max_limit < volinfo->snap_max_limit) {
+ snap_limit = conf->snap_max_limit;
+ gf_log(this->name, GF_LOG_DEBUG, "system snap_limit is "
+ "lesser than volume snap_limit, snap_limit value "
+ "is set to %ld",snap_limit);
+ }
+ else {
+ snap_limit = volinfo->snap_max_limit ;
+ gf_log(this->name, GF_LOG_DEBUG, "volume snap_limit is "
+ "lesser than system snap_limit, snap_limit value "
+ "is set to %ld",snap_limit);
+ }
+
+ if (snap_limit > volinfo->snap_count)
+ ret = dict_set_int64 (dict, key,
+ snap_limit - volinfo->snap_count);
+ else
+ ret = dict_set_int64 (dict, key, 0);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to set available snaps");
goto out;
}
/* Ownership of value transferred to dict. Therefore we must initalize
@@ -1329,12 +1364,12 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
/* snapshot taken first should be displayed first */
list_for_each_entry_safe (entry, tmp, &volinfo->snaps,
snap_list) {
- ++index;
- ret = snprintf (key, sizeof (key), "%s.snap-%ld", keyprefix, index);
+ ret = snprintf (key, sizeof (key), "%s.snap-%ld", keyprefix,
+ index);
if (ret < 0) { /* Only negative value is error */
goto out;
}
-
+ ++index;
/* If snapname is NULL then get all the snaps
* for the given volume */
if (NULL == snapname) {
@@ -1376,14 +1411,13 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
* added to the dictionary. If snapshot name is passed
* as argument then we would send only one snap object.
* Therefore index should be reset to 0. */
- index = 0;
+ index = 1;
break; /* Found the snap */
}
/* If all the snap is written into the dictionary then write the
* snap count into the dictionary */
if (0 == ret) {
- ++index; /* To get count increment index by 1*/
ret = snprintf (key, sizeof (key), "%s.snap-count", keyprefix);
if (ret < 0) { /* Only negative value is error */
goto out;
@@ -1399,6 +1433,22 @@ glusterd_snapshot_vol_get_snaplist_lk (dict_t *dict, char *keyprefix,
} else if (NULL != snapname) {
gf_log (this->name, GF_LOG_ERROR, "Snap (%s) not found",
snapname);
+ ret = snprintf (key, sizeof (key), "%s.err_str",
+ keyprefix);
+ if (ret < 0) {
+ goto out;
+ }
+ ret = snprintf (err_str, sizeof (err_str), "Snapshot %s"
+ " not found", snapname);
+ if (ret < 0) {
+ goto out;
+ }
+ ret = dict_set_str (dict, key, err_str);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to"
+ "set error string");
+ goto out;
+ }
}
out:
@@ -1600,7 +1650,6 @@ glusterd_snapshot_cg_get_snaplist_lk (dict_t *dict, glusterd_snap_cg_t *cg,
if (ret < 0) { /* Only negative value is error */
goto out;
}
-
ret = glusterd_snapshot_vol_get_snaplist (dict, key,
&(cg->volumes[i]), NULL, detail);
if (ret) {
@@ -1699,7 +1748,8 @@ out:
*/
static int
glusterd_snapshot_cg_get_snaplist (dict_t *dict, char *keyprefix,
- char *cgname, int8_t detail)
+ char *cgname, int8_t detail,
+ char *err_str, size_t len)
{
int ret = -1; /* Failure */
glusterd_conf_t *conf = NULL;
@@ -1721,8 +1771,9 @@ glusterd_snapshot_cg_get_snaplist (dict_t *dict, char *keyprefix,
cg = glusterd_find_snap_cg_by_name (conf, cgname);
if (NULL == cg) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s CG", cgname);
+ snprintf (err_str, len, "CG %s not found", cgname);
+ gf_log (this->name, GF_LOG_WARNING, "%s", err_str);
+ ret = -1;
goto out;
}
@@ -1868,7 +1919,7 @@ out:
*/
int
glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
- dict_t *dict)
+ dict_t *dict, char *err_str, size_t len)
{
int ret = -1;
int64_t volcount = 0;
@@ -1877,7 +1928,6 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
char *keyprefix = "snaplist";
char *cgname = NULL;
char *snapname = NULL;
- char *err_str = "Operation failed";
dict_t *voldict = NULL;
xlator_t *this = NULL;
char key[256] = {0,};
@@ -1928,8 +1978,8 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
goto out;
}
- ret = glusterd_snapshot_cg_get_snaplist (dict, key,
- cgname, detail);
+ ret = glusterd_snapshot_cg_get_snaplist (dict, key, cgname,
+ detail, err_str, len);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to get "
"snapshot list for %s CG", cgname);
@@ -2945,11 +2995,12 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr,
glusterd_volinfo_t *volinfo = NULL;
glusterd_snap_cg_t *cg = NULL;
glusterd_conf_t *priv = NULL;
- uuid_t cg_id;
+ uuid_t cg_id;
glusterd_snap_t *snap = NULL;
char err_str[PATH_MAX] = {0, };
this = THIS;
+ priv = this->private;
ret = dict_get_int64 (dict, "volcount", &volume_count);
if (ret) {
@@ -3041,7 +3092,6 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr,
"consistency group %s", name);
goto out;
}
-
uuid_copy (cg->cg_id, cg_id);
strncpy (cg->cg_name, name, sizeof (cg->cg_name));
ret = glusterd_add_snap_cg (priv, cg);
@@ -3362,7 +3412,8 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req)
break;
case GF_SNAP_OPTION_TYPE_LIST:
- ret = glusterd_handle_snapshot_list (req, cli_op, dict);
+ ret = glusterd_handle_snapshot_list (req, cli_op, dict,
+ err_str, sizeof (err_str));
if (ret) {
gf_log (this->name, GF_LOG_WARNING, "Snapshot list "
"failed");