Merge branch 'wip-http-engine' of https://github.com/l-mb/fio
[fio.git] / lib / axmap.c
index e4e40bf063fcd5297716d490a1f24d8269b71642..454af0b9d0361806bbf515c2e9c5c94776db3891 100644 (file)
@@ -156,10 +156,10 @@ static bool axmap_handler(struct axmap *axmap, uint64_t bit_nr,
                          void *), void *data)
 {
        struct axmap_level *al;
+       uint64_t index = bit_nr;
        int i;
 
        for (i = 0; i < axmap->nr_levels; i++) {
-               unsigned long index = ulog64(bit_nr, i);
                unsigned long offset = index >> UNIT_SHIFT;
                unsigned int bit = index & BLOCKS_PER_UNIT_MASK;
 
@@ -167,6 +167,9 @@ static bool axmap_handler(struct axmap *axmap, uint64_t bit_nr,
 
                if (func(al, offset, bit, data))
                        return true;
+
+               if (index)
+                       index >>= UNIT_SHIFT;
        }
 
        return false;
@@ -227,15 +230,18 @@ static bool axmap_set_fn(struct axmap_level *al, unsigned long offset,
         * Mask off any potential overlap, only sets contig regions
         */
        overlap = al->map[offset] & mask;
-       if (overlap == mask)
+       if (overlap == mask) {
+done:
+               data->set_bits = 0;
                return true;
+       }
 
        if (overlap) {
                const int __bit = ffz(~overlap);
 
                nr_bits = __bit - bit;
                if (!nr_bits)
-                       return true;
+                       goto done;
 
                mask = bit_masks[nr_bits] << bit;
        }
@@ -300,7 +306,7 @@ unsigned int axmap_set_nr(struct axmap *axmap, uint64_t bit_nr,
                unsigned int max_bits, this_set;
 
                max_bits = BLOCKS_PER_UNIT - (bit_nr & BLOCKS_PER_UNIT_MASK);
-               if (max_bits < nr_bits)
+               if (nr_bits > max_bits)
                        data.nr_bits = max_bits;
 
                this_set = data.nr_bits;