Revision 2eaa8f63
b/block/qcow2-refcount.c | ||
---|---|---|
228 | 228 |
} |
229 | 229 |
|
230 | 230 |
/* Allocate the refcount block itself and mark it as used */ |
231 |
uint64_t new_block = alloc_clusters_noref(bs, s->cluster_size); |
|
231 |
int64_t new_block = alloc_clusters_noref(bs, s->cluster_size); |
|
232 |
if (new_block < 0) { |
|
233 |
return new_block; |
|
234 |
} |
|
232 | 235 |
|
233 | 236 |
#ifdef DEBUG_ALLOC2 |
234 | 237 |
fprintf(stderr, "qcow2: Allocate refcount block %d for %" PRIx64 |
... | ... | |
579 | 582 |
static int64_t alloc_clusters_noref(BlockDriverState *bs, int64_t size) |
580 | 583 |
{ |
581 | 584 |
BDRVQcowState *s = bs->opaque; |
582 |
int i, nb_clusters; |
|
585 |
int i, nb_clusters, refcount;
|
|
583 | 586 |
|
584 | 587 |
nb_clusters = size_to_clusters(s, size); |
585 | 588 |
retry: |
586 | 589 |
for(i = 0; i < nb_clusters; i++) { |
587 | 590 |
int64_t next_cluster_index = s->free_cluster_index++; |
588 |
if (get_refcount(bs, next_cluster_index) != 0) |
|
591 |
refcount = get_refcount(bs, next_cluster_index); |
|
592 |
|
|
593 |
if (refcount < 0) { |
|
594 |
return refcount; |
|
595 |
} else if (refcount != 0) { |
|
589 | 596 |
goto retry; |
597 |
} |
|
590 | 598 |
} |
591 | 599 |
#ifdef DEBUG_ALLOC2 |
592 | 600 |
printf("alloc_clusters: size=%" PRId64 " -> %" PRId64 "\n", |
... | ... | |
603 | 611 |
|
604 | 612 |
BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_ALLOC); |
605 | 613 |
offset = alloc_clusters_noref(bs, size); |
614 |
if (offset < 0) { |
|
615 |
return offset; |
|
616 |
} |
|
617 |
|
|
606 | 618 |
ret = update_refcount(bs, offset, size, 1); |
607 | 619 |
if (ret < 0) { |
608 | 620 |
return ret; |
Also available in: Unified diff