diff options
-rw-r--r-- | libglusterfs/src/list.h | 15 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 3 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 13 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.h | 3 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 3 |
5 files changed, 34 insertions, 3 deletions
diff --git a/libglusterfs/src/list.h b/libglusterfs/src/list.h index 7f3712b51b4..794586e35f6 100644 --- a/libglusterfs/src/list.h +++ b/libglusterfs/src/list.h @@ -46,6 +46,21 @@ list_add_tail (struct list_head *new, struct list_head *head) static inline void +list_add_order (struct list_head *new, struct list_head *head, + int (*compare)(struct list_head *, struct list_head *)) +{ + struct list_head *pos = head->next; + + while ( pos != head ) { + if (compare(new, pos) <= 0) + break; + pos = pos->next; + } + + list_add_tail(new, pos); +} + +static inline void list_del (struct list_head *old) { old->prev->next = old->next; diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 2c2fc6fb482..0ee430969cb 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -2085,7 +2085,8 @@ glusterd_store_retrieve_volume (char *volname) goto out; - list_add_tail (&volinfo->vol_list, &priv->volumes); + list_add_order (&volinfo->vol_list, &priv->volumes, + glusterd_compare_volume_name); out: gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret); diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 9fb2ab31e04..78593d14e3b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -3529,7 +3529,8 @@ glusterd_import_friend_volume (dict_t *vols, size_t count) if (ret) goto out; - list_add_tail (&new_volinfo->vol_list, &priv->volumes); + list_add_order (&new_volinfo->vol_list, &priv->volumes, + glusterd_compare_volume_name); out: gf_log ("", GF_LOG_DEBUG, "Returning with ret: %d", ret); return ret; @@ -9337,3 +9338,13 @@ glusterd_rpc_clnt_unref (glusterd_conf_t *conf, rpc_clnt_t *rpc) return ret; } +int32_t +glusterd_compare_volume_name(struct list_head *list1, struct list_head *list2) +{ + glusterd_volinfo_t *volinfo1 = NULL; + glusterd_volinfo_t *volinfo2 = NULL; + + volinfo1 = list_entry(list1, glusterd_volinfo_t, vol_list); + volinfo2 = list_entry(list2, glusterd_volinfo_t, vol_list); + return strcmp(volinfo1->volname, volinfo2->volname); +} diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 05d5c7172b2..6b0d77b9f5d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -644,4 +644,7 @@ gd_stop_rebalance_process (glusterd_volinfo_t *volinfo); rpc_clnt_t * glusterd_rpc_clnt_unref (glusterd_conf_t *conf, rpc_clnt_t *rpc); + +int32_t +glusterd_compare_volume_name(struct list_head *, struct list_head *); #endif diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index 051e7d7569e..4acea768662 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -1708,7 +1708,8 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) } volinfo->rebal.defrag_status = 0; - list_add_tail (&volinfo->vol_list, &priv->volumes); + list_add_order (&volinfo->vol_list, &priv->volumes, + glusterd_compare_volume_name); vol_added = _gf_true; out: |