Revision 72893756

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
        }
b/block/qcow2-snapshot.c
327 327
    if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) < 0)
328 328
        goto fail;
329 329

  
330
    if (qcow2_grow_l1_table(bs, sn->l1_size) < 0)
330
    if (qcow2_grow_l1_table(bs, sn->l1_size, true) < 0)
331 331
        goto fail;
332 332

  
333 333
    s->l1_size = sn->l1_size;
b/block/qcow2.c
1154 1154
    }
1155 1155

  
1156 1156
    new_l1_size = size_to_l1(s, offset);
1157
    ret = qcow2_grow_l1_table(bs, new_l1_size);
1157
    ret = qcow2_grow_l1_table(bs, new_l1_size, true);
1158 1158
    if (ret < 0) {
1159 1159
        return ret;
1160 1160
    }
b/block/qcow2.h
188 188
int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res);
189 189

  
190 190
/* qcow2-cluster.c functions */
191
int qcow2_grow_l1_table(BlockDriverState *bs, int min_size);
191
int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size);
192 192
void qcow2_l2_cache_reset(BlockDriverState *bs);
193 193
int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
194 194
void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,

Also available in: Unified diff