Revision 72893756 block/qcow2-cluster.c

b/block/qcow2-cluster.c
28 28
#include "block_int.h"
29 29
#include "block/qcow2.h"
30 30

  
31
int qcow2_grow_l1_table(BlockDriverState *bs, int min_size)
31
int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size)
32 32
{
33 33
    BDRVQcowState *s = bs->opaque;
34 34
    int new_l1_size, new_l1_size2, ret, i;
......
36 36
    int64_t new_l1_table_offset;
37 37
    uint8_t data[12];
38 38

  
39
    new_l1_size = s->l1_size;
40
    if (min_size <= new_l1_size)
39
    if (min_size <= s->l1_size)
41 40
        return 0;
42
    if (new_l1_size == 0) {
43
        new_l1_size = 1;
44
    }
45
    while (min_size > new_l1_size) {
46
        new_l1_size = (new_l1_size * 3 + 1) / 2;
41

  
42
    if (exact_size) {
43
        new_l1_size = min_size;
44
    } else {
45
        /* Bump size up to reduce the number of times we have to grow */
46
        new_l1_size = s->l1_size;
47
        if (new_l1_size == 0) {
48
            new_l1_size = 1;
49
        }
50
        while (min_size > new_l1_size) {
51
            new_l1_size = (new_l1_size * 3 + 1) / 2;
52
        }
47 53
    }
54

  
48 55
#ifdef DEBUG_ALLOC2
49 56
    printf("grow l1_table from %d to %d\n", s->l1_size, new_l1_size);
50 57
#endif
......
550 557

  
551 558
    l1_index = offset >> (s->l2_bits + s->cluster_bits);
552 559
    if (l1_index >= s->l1_size) {
553
        ret = qcow2_grow_l1_table(bs, l1_index + 1);
560
        ret = qcow2_grow_l1_table(bs, l1_index + 1, false);
554 561
        if (ret < 0) {
555 562
            return ret;
556 563
        }

Also available in: Unified diff