From 760dfb6e8aebc44b419e8943e4e3895591097b8b Mon Sep 17 00:00:00 2001 From: vmallika Date: Thu, 14 Apr 2016 17:51:19 +0530 Subject: cli/quota: Sort the list output alphabetically by path Change-Id: I0b124e119d167817be2ae3eb52ac6c80fc7db5d1 BUG: 1320716 Signed-off-by: vmallika Reviewed-on: http://review.gluster.org/14000 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Kaushal M --- libglusterfs/src/common-utils.c | 48 +++++++++++++++++++++++++++++++++++++++++ libglusterfs/src/common-utils.h | 9 ++++++++ libglusterfs/src/mem-types.h | 1 + 3 files changed, 58 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index ef48aca056b..21fe3841be9 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -4214,6 +4214,54 @@ _unmask_cancellation (void) (void) pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); } +/* This is a wrapper function to add a pointer to a list, + * which doesn't contain list member + */ +struct list_node* +_list_node_add (void *ptr, struct list_head *list, + int (*compare)(struct list_head *, struct list_head *)) +{ + struct list_node *node = NULL; + + if (ptr == NULL || list == NULL) + goto out; + + node = GF_CALLOC (1, sizeof (struct list_node), gf_common_list_node); + + if (node == NULL) + goto out; + + node->ptr = ptr; + if (compare) + list_add_order (&node->list, list, compare); + else + list_add_tail (&node->list, list); +out: + return node; +} + +struct list_node* +list_node_add (void *ptr, struct list_head *list) +{ + return _list_node_add (ptr, list, NULL); +} + +struct list_node* +list_node_add_order (void *ptr, struct list_head *list, + int (*compare)(struct list_head *, struct list_head *)) +{ + return _list_node_add (ptr, list, compare); +} + +void +list_node_del (struct list_node *node) +{ + if (node == NULL) + return; + + list_del_init (&node->list); + GF_FREE (node); +} const char * fop_enum_to_pri_string (glusterfs_fop_t fop) diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index acd5cb5303e..58889ca9a5c 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -188,7 +188,16 @@ struct dnscache6 { struct addrinfo *next; }; +struct list_node { + void *ptr; + struct list_head list; +}; +struct list_node *list_node_add (void *ptr, struct list_head *list); +struct list_node *list_node_add_order (void *ptr, struct list_head *list, + int (*compare)(struct list_head *, + struct list_head *)); +void list_node_del (struct list_node *node); struct dnscache *gf_dnscache_init (time_t ttl); struct dnscache_entry *gf_dnscache_entry_init (); diff --git a/libglusterfs/src/mem-types.h b/libglusterfs/src/mem-types.h index 63fffeeafab..639ba3721f1 100644 --- a/libglusterfs/src/mem-types.h +++ b/libglusterfs/src/mem-types.h @@ -158,6 +158,7 @@ enum gf_common_mem_types_ { gf_common_mt_syncstack, gf_common_mt_syncenv, gf_common_mt_scan_data, + gf_common_list_node, gf_common_mt_end }; #endif -- cgit