summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorvmallika <vmallika@redhat.com>2016-04-25 16:23:29 +0530
committerVijaikumar Mallikarjuna <vmallika@redhat.com>2016-04-27 09:46:50 -0700
commit7433fcfdf7a663ab228de67099e8a53fed526fb0 (patch)
treee9f7b6eeb0d3731dc743e63cc2d9e3d8492ac943 /cli
parentfa78b755e9c58328c1df4ef1bfeb752d47534a4a (diff)
cli/quota: Sort the list output alphabetically by path
This is a backport of http://review.gluster.org/14000 > Change-Id: I0b124e119d167817be2ae3eb52ac6c80fc7db5d1 > BUG: 1320716 > Signed-off-by: vmallika <vmallika@redhat.com> > Reviewed-on: http://review.gluster.org/14000 > Smoke: Gluster Build System <jenkins@build.gluster.com> > NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> > CentOS-regression: Gluster Build System <jenkins@build.gluster.com> > Reviewed-by: Kaushal M <kaushal@redhat.com> Change-Id: I87e12d58c8e267b2af67e287998e7313efc70af4 BUG: 1330018 Signed-off-by: vmallika <vmallika@redhat.com> Reviewed-on: http://review.gluster.org/14061 Smoke: Gluster Build System <jenkins@build.gluster.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd-volume.c36
-rw-r--r--cli/src/cli-rpc-ops.c66
-rw-r--r--cli/src/cli.c1
-rw-r--r--cli/src/cli.h1
4 files changed, 99 insertions, 5 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 26936c2..39a6e7d 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -1230,6 +1230,7 @@ cli_cmd_quota_handle_list_all (const char **words, dict_t *options)
int32_t type = 0;
char gfid_type = 0;
float version = 0.0f;
+ int32_t max_count = 0;
xdata = dict_new ();
if (!xdata) {
@@ -1324,6 +1325,41 @@ cli_cmd_quota_handle_list_all (const char **words, dict_t *options)
ret = -1;
goto out;
}
+
+ for (count = 0;; count++) {
+ ret = quota_conf_read_gfid (fd, buf, &gfid_type, version);
+ if (ret == 0) {
+ break;
+ } else if (ret < 0) {
+ gf_log (THIS->name, GF_LOG_CRITICAL, "Quota "
+ "configuration store may be corrupt.");
+ goto out;
+ }
+
+ if ((type == GF_QUOTA_OPTION_TYPE_LIST &&
+ gfid_type == GF_QUOTA_CONF_TYPE_OBJECTS) ||
+ (type == GF_QUOTA_OPTION_TYPE_LIST_OBJECTS &&
+ gfid_type == GF_QUOTA_CONF_TYPE_USAGE))
+ continue;
+
+ max_count++;
+ }
+ ret = dict_set_int32 (xdata, "max_count", max_count);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to set max_count");
+ goto out;
+ }
+
+ ret = sys_lseek (fd, 0L, SEEK_SET);
+ if (ret < 0) {
+ gf_log (THIS->name, GF_LOG_ERROR, "failed to move offset to "
+ "the beginning: %s", strerror (errno));
+ goto out;
+ }
+ ret = quota_conf_read_version (fd, &version);
+ if (ret)
+ goto out;
+
for (count = 0;; count++) {
ret = quota_conf_read_gfid (fd, buf, &gfid_type, version);
if (ret == 0) {
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index a2519e8..1d507f7 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -3474,6 +3474,35 @@ cli_cmd_broadcast_response_detached (void *opaque)
return NULL;
}
+int32_t
+cli_quota_compare_path (struct list_head *list1,
+ struct list_head *list2)
+{
+ struct list_node *node1 = NULL;
+ struct list_node *node2 = NULL;
+ dict_t *dict1 = NULL;
+ dict_t *dict2 = NULL;
+ char *path1 = NULL;
+ char *path2 = NULL;
+ int ret = 0;
+
+ node1 = list_entry (list1, struct list_node, list);
+ node2 = list_entry (list2, struct list_node, list);
+
+ dict1 = node1->ptr;
+ dict2 = node2->ptr;
+
+ ret = dict_get_str (dict1, GET_ANCESTRY_PATH_KEY, &path1);
+ if (ret < 0)
+ return 0;
+
+ ret = dict_get_str (dict2, GET_ANCESTRY_PATH_KEY, &path2);
+ if (ret < 0)
+ return 0;
+
+ return strcmp (path1, path2);
+}
+
int
cli_quotad_getlimit_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
@@ -3482,11 +3511,14 @@ cli_quotad_getlimit_cbk (struct rpc_req *req, struct iovec *iov,
gf_cli_rsp rsp = {0,};
int ret = -1;
dict_t *dict = NULL;
+ struct list_node *node = NULL;
+ struct list_node *tmpnode = NULL;
call_frame_t *frame = NULL;
cli_local_t *local = NULL;
dict_t *gd_rsp_dict = NULL;
int32_t list_count = 0;
pthread_t th_id = {0, };
+ int32_t max_count = 0;
frame = myframe;
GF_ASSERT (frame);
@@ -3500,8 +3532,10 @@ cli_quotad_getlimit_cbk (struct rpc_req *req, struct iovec *iov,
&list_count);
if (ret)
list_count = 0;
+
+ list_count++;
ret = dict_set_int32 (gd_rsp_dict, "quota-list-count",
- list_count + 1);
+ list_count);
}
UNLOCK (&local->lock);
@@ -3549,7 +3583,32 @@ cli_quotad_getlimit_cbk (struct rpc_req *req, struct iovec *iov,
goto out;
}
- print_quota_list_from_quotad (frame, dict);
+ ret = dict_get_int32 (local->dict, "max_count",
+ &max_count);
+ if (ret < 0) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "failed to get max_count");
+ goto out;
+ }
+
+ node = list_node_add_order (dict, &local->dict_list,
+ cli_quota_compare_path);
+ if (node == NULL) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "failed to add node to the list");
+ dict_unref (dict);
+ goto out;
+ }
+
+ if (list_count == max_count) {
+ list_for_each_entry_safe (node, tmpnode,
+ &local->dict_list, list) {
+ dict = node->ptr;
+ print_quota_list_from_quotad (frame, dict);
+ list_node_del (node);
+ dict_unref (dict);
+ }
+ }
}
out:
@@ -3579,9 +3638,6 @@ out:
cli_cmd_broadcast_response (ret);
}
- if (dict)
- dict_unref (dict);
-
free (rsp.dict.dict_val);
return ret;
}
diff --git a/cli/src/cli.c b/cli/src/cli.c
index 9650e36..7ab6fb2 100644
--- a/cli/src/cli.c
+++ b/cli/src/cli.c
@@ -658,6 +658,7 @@ cli_local_get ()
local = GF_CALLOC (1, sizeof (*local), cli_mt_cli_local_t);
LOCK_INIT (&local->lock);
+ INIT_LIST_HEAD (&local->dict_list);
return local;
}
diff --git a/cli/src/cli.h b/cli/src/cli.h
index c508f1c..7d9a1d4 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -161,6 +161,7 @@ struct cli_local {
int vol_count;
#endif
gf_lock_t lock;
+ struct list_head dict_list;
};
struct cli_volume_status {