diff options
author | Ilya Dryomov <ilya.dryomov@inktank.com> | 2014-03-21 13:05:27 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2014-04-05 00:07:50 -0400 |
commit | 433fbdd31db267564bab20420bd8f161a7c69e4d (patch) | |
tree | df5ba6f6f6f2c02fc2b1530d2c8150950301cd94 /net | |
parent | 0f70c7eedbbbd245398fc74b4b020f3b800f071c (diff) |
libceph: introduce decode{,_new}_pools() and switch to them
Consolidate pools (full map, map<u64, pg_pool_t>) and new_pools (inc
map, same) decoding logic into a common helper and switch to it.
Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/ceph/osdmap.c | 94 |
1 files changed, 57 insertions, 37 deletions
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c index 39938d79756c..0ba3062d3317 100644 --- a/net/ceph/osdmap.c +++ b/net/ceph/osdmap.c | |||
@@ -681,6 +681,55 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max) | |||
681 | return 0; | 681 | return 0; |
682 | } | 682 | } |
683 | 683 | ||
684 | static int __decode_pools(void **p, void *end, struct ceph_osdmap *map, | ||
685 | bool incremental) | ||
686 | { | ||
687 | u32 n; | ||
688 | |||
689 | ceph_decode_32_safe(p, end, n, e_inval); | ||
690 | while (n--) { | ||
691 | struct ceph_pg_pool_info *pi; | ||
692 | u64 pool; | ||
693 | int ret; | ||
694 | |||
695 | ceph_decode_64_safe(p, end, pool, e_inval); | ||
696 | |||
697 | pi = __lookup_pg_pool(&map->pg_pools, pool); | ||
698 | if (!incremental || !pi) { | ||
699 | pi = kzalloc(sizeof(*pi), GFP_NOFS); | ||
700 | if (!pi) | ||
701 | return -ENOMEM; | ||
702 | |||
703 | pi->id = pool; | ||
704 | |||
705 | ret = __insert_pg_pool(&map->pg_pools, pi); | ||
706 | if (ret) { | ||
707 | kfree(pi); | ||
708 | return ret; | ||
709 | } | ||
710 | } | ||
711 | |||
712 | ret = decode_pool(p, end, pi); | ||
713 | if (ret) | ||
714 | return ret; | ||
715 | } | ||
716 | |||
717 | return 0; | ||
718 | |||
719 | e_inval: | ||
720 | return -EINVAL; | ||
721 | } | ||
722 | |||
723 | static int decode_pools(void **p, void *end, struct ceph_osdmap *map) | ||
724 | { | ||
725 | return __decode_pools(p, end, map, false); | ||
726 | } | ||
727 | |||
728 | static int decode_new_pools(void **p, void *end, struct ceph_osdmap *map) | ||
729 | { | ||
730 | return __decode_pools(p, end, map, true); | ||
731 | } | ||
732 | |||
684 | /* | 733 | /* |
685 | * decode a full map. | 734 | * decode a full map. |
686 | */ | 735 | */ |
@@ -692,7 +741,6 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map) | |||
692 | u32 max; | 741 | u32 max; |
693 | u32 len, i; | 742 | u32 len, i; |
694 | int err; | 743 | int err; |
695 | struct ceph_pg_pool_info *pi; | ||
696 | 744 | ||
697 | dout("%s %p to %p len %d\n", __func__, *p, end, (int)(end - *p)); | 745 | dout("%s %p to %p len %d\n", __func__, *p, end, (int)(end - *p)); |
698 | 746 | ||
@@ -714,22 +762,10 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map) | |||
714 | ceph_decode_copy(p, &map->created, sizeof(map->created)); | 762 | ceph_decode_copy(p, &map->created, sizeof(map->created)); |
715 | ceph_decode_copy(p, &map->modified, sizeof(map->modified)); | 763 | ceph_decode_copy(p, &map->modified, sizeof(map->modified)); |
716 | 764 | ||
717 | ceph_decode_32_safe(p, end, max, e_inval); | 765 | /* pools */ |
718 | while (max--) { | 766 | err = decode_pools(p, end, map); |
719 | ceph_decode_need(p, end, 8 + 2, e_inval); | 767 | if (err) |
720 | pi = kzalloc(sizeof(*pi), GFP_NOFS); | 768 | goto bad; |
721 | if (!pi) { | ||
722 | err = -ENOMEM; | ||
723 | goto bad; | ||
724 | } | ||
725 | pi->id = ceph_decode_64(p); | ||
726 | err = decode_pool(p, end, pi); | ||
727 | if (err < 0) { | ||
728 | kfree(pi); | ||
729 | goto bad; | ||
730 | } | ||
731 | __insert_pg_pool(&map->pg_pools, pi); | ||
732 | } | ||
733 | 769 | ||
734 | /* pool_name */ | 770 | /* pool_name */ |
735 | err = decode_pool_names(p, end, map); | 771 | err = decode_pool_names(p, end, map); |
@@ -934,26 +970,10 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, | |||
934 | newcrush = NULL; | 970 | newcrush = NULL; |
935 | } | 971 | } |
936 | 972 | ||
937 | /* new_pool */ | 973 | /* new_pools */ |
938 | ceph_decode_32_safe(p, end, len, e_inval); | 974 | err = decode_new_pools(p, end, map); |
939 | while (len--) { | 975 | if (err) |
940 | struct ceph_pg_pool_info *pi; | 976 | goto bad; |
941 | |||
942 | ceph_decode_64_safe(p, end, pool, e_inval); | ||
943 | pi = __lookup_pg_pool(&map->pg_pools, pool); | ||
944 | if (!pi) { | ||
945 | pi = kzalloc(sizeof(*pi), GFP_NOFS); | ||
946 | if (!pi) { | ||
947 | err = -ENOMEM; | ||
948 | goto bad; | ||
949 | } | ||
950 | pi->id = pool; | ||
951 | __insert_pg_pool(&map->pg_pools, pi); | ||
952 | } | ||
953 | err = decode_pool(p, end, pi); | ||
954 | if (err < 0) | ||
955 | goto bad; | ||
956 | } | ||
957 | 977 | ||
958 | /* new_pool_names */ | 978 | /* new_pool_names */ |
959 | err = decode_pool_names(p, end, map); | 979 | err = decode_pool_names(p, end, map); |