Revision db3a964f
b/block/qcow2-refcount.c | ||
---|---|---|
269 | 269 |
} |
270 | 270 |
|
271 | 271 |
/* XXX: cache several refcount block clusters ? */ |
272 |
static int update_refcount(BlockDriverState *bs, |
|
273 |
int64_t offset, int64_t length, |
|
274 |
int addend) |
|
272 |
static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, |
|
273 |
int64_t offset, int64_t length, int addend) |
|
275 | 274 |
{ |
276 | 275 |
BDRVQcowState *s = bs->opaque; |
277 | 276 |
int64_t start, last, cluster_offset; |
... | ... | |
415 | 414 |
int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size) |
416 | 415 |
{ |
417 | 416 |
int64_t offset; |
417 |
int ret; |
|
418 | 418 |
|
419 | 419 |
offset = alloc_clusters_noref(bs, size); |
420 |
update_refcount(bs, offset, size, 1); |
|
420 |
ret = update_refcount(bs, offset, size, 1); |
|
421 |
if (ret < 0) { |
|
422 |
return ret; |
|
423 |
} |
|
421 | 424 |
return offset; |
422 | 425 |
} |
423 | 426 |
|
... | ... | |
464 | 467 |
void qcow2_free_clusters(BlockDriverState *bs, |
465 | 468 |
int64_t offset, int64_t size) |
466 | 469 |
{ |
467 |
update_refcount(bs, offset, size, -1); |
|
470 |
int ret; |
|
471 |
|
|
472 |
ret = update_refcount(bs, offset, size, -1); |
|
473 |
if (ret < 0) { |
|
474 |
fprintf(stderr, "qcow2_free_clusters failed: %s\n", strerror(-ret)); |
|
475 |
abort(); |
|
476 |
} |
|
468 | 477 |
} |
469 | 478 |
|
470 | 479 |
/* |
... | ... | |
573 | 582 |
if (offset & QCOW_OFLAG_COMPRESSED) { |
574 | 583 |
nb_csectors = ((offset >> s->csize_shift) & |
575 | 584 |
s->csize_mask) + 1; |
576 |
if (addend != 0) |
|
577 |
update_refcount(bs, (offset & s->cluster_offset_mask) & ~511, |
|
578 |
nb_csectors * 512, addend); |
|
585 |
if (addend != 0) { |
|
586 |
int ret; |
|
587 |
ret = update_refcount(bs, |
|
588 |
(offset & s->cluster_offset_mask) & ~511, |
|
589 |
nb_csectors * 512, addend); |
|
590 |
if (ret < 0) { |
|
591 |
goto fail; |
|
592 |
} |
|
593 |
} |
|
579 | 594 |
/* compressed clusters are never modified */ |
580 | 595 |
refcount = 2; |
581 | 596 |
} else { |
Also available in: Unified diff