~ubuntu-branches/ubuntu/trusty/ceph/trusty-proposed

« back to all changes in this revision

Viewing changes to src/crush/builder.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-01-23 16:29:08 UTC
  • mfrom: (0.3.21)
  • Revision ID: package-import@ubuntu.com-20150123162908-5rsgaz037l7f3nqs
Tags: 0.80.8-0ubuntu0.14.04.1
New upstream stable point release (LP: #1413917).

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
                for (r=0; r < map->max_rules; r++)
64
64
                        if (map->rules[r] == 0)
65
65
                                break;
66
 
                assert(r <= INT_MAX);
 
66
                assert(r < CRUSH_MAX_RULES);
67
67
        }
68
68
        else
69
69
                r = ruleno;
72
72
                /* expand array */
73
73
                int oldsize;
74
74
                void *_realloc = NULL;
 
75
                if (map->max_rules +1 > CRUSH_MAX_RULES)
 
76
                        return -ENOSPC;
75
77
                oldsize = map->max_rules;
76
78
                map->max_rules = r+1;
77
79
                if ((_realloc = realloc(map->rules, map->max_rules * sizeof(map->rules[0]))) == NULL) {
744
746
        for (j = i; j < bucket->h.size; j++)
745
747
                bucket->h.items[j] = bucket->h.items[j+1];
746
748
        newsize = --bucket->h.size;
747
 
        bucket->h.weight -= bucket->item_weight;
 
749
        if (bucket->item_weight < bucket->h.weight)
 
750
                bucket->h.weight -= bucket->item_weight;
 
751
        else
 
752
                bucket->h.weight = 0;
748
753
 
749
754
        if ((_realloc = realloc(bucket->h.items, sizeof(__s32)*newsize)) == NULL) {
750
755
                return -ENOMEM;
777
782
                bucket->item_weights[j] = bucket->item_weights[j+1];
778
783
                bucket->sum_weights[j] = bucket->sum_weights[j+1] - weight;
779
784
        }
780
 
        bucket->h.weight -= weight;
 
785
        if (weight < bucket->h.weight)
 
786
                bucket->h.weight -= weight;
 
787
        else
 
788
                bucket->h.weight = 0;
781
789
        newsize = --bucket->h.size;
782
790
        
783
791
        void *_realloc = NULL;
828
836
                        bucket->node_weights[node] -= weight;
829
837
                        printf(" node %d weight %d\n", node, bucket->node_weights[node]);
830
838
                }
831
 
                bucket->h.weight -= weight;
 
839
                if (weight < bucket->h.weight)
 
840
                        bucket->h.weight -= weight;
 
841
                else
 
842
                        bucket->h.weight = 0;
832
843
                break;
833
844
        }
834
845
        if (i == bucket->h.size)
883
894
        for (i = 0; i < bucket->h.size; i++) {
884
895
                if (bucket->h.items[i] == item) {
885
896
                        bucket->h.size--;
886
 
                        bucket->h.weight -= bucket->item_weights[i];
 
897
                        if (bucket->item_weights[i] < bucket->h.weight)
 
898
                                bucket->h.weight -= bucket->item_weights[i];
 
899
                        else
 
900
                                bucket->h.weight = 0;
887
901
                        for (j = i; j < bucket->h.size; j++) {
888
902
                                bucket->h.items[j] = bucket->h.items[j+1];
889
903
                                bucket->item_weights[j] = bucket->item_weights[j+1];