Commit b171271a50be01f2690077970fa7e60b8e8eb9d9
Committed by
Anthony Liguori
1 parent
14658cd1
vmdk: Fix backing file handling
Instead of storing the backing file in its own BlockDriverState, VMDK uses the BlockDriverState of the raw image file it opened. This is wrong and breaks functions that access the backing file or protocols. This fix replaces all occurrences of s->hd->backing_* with bs->backing_*. This fixes qemu-iotests failure in 020 (Commit changes to backing file). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
15 additions
and
14 deletions
block/vmdk.c
... | ... | @@ -170,7 +170,7 @@ static int vmdk_is_cid_valid(BlockDriverState *bs) |
170 | 170 | { |
171 | 171 | #ifdef CHECK_CID |
172 | 172 | BDRVVmdkState *s = bs->opaque; |
173 | - BlockDriverState *p_bs = s->hd->backing_hd; | |
173 | + BlockDriverState *p_bs = bs->backing_hd; | |
174 | 174 | uint32_t cur_pcid; |
175 | 175 | |
176 | 176 | if (p_bs) { |
... | ... | @@ -338,26 +338,26 @@ static int vmdk_parent_open(BlockDriverState *bs, const char * filename) |
338 | 338 | p_name += sizeof("parentFileNameHint") + 1; |
339 | 339 | if ((end_name = strchr(p_name,'\"')) == NULL) |
340 | 340 | return -1; |
341 | - if ((end_name - p_name) > sizeof (s->hd->backing_file) - 1) | |
341 | + if ((end_name - p_name) > sizeof (bs->backing_file) - 1) | |
342 | 342 | return -1; |
343 | 343 | |
344 | - pstrcpy(s->hd->backing_file, end_name - p_name + 1, p_name); | |
345 | - if (stat(s->hd->backing_file, &file_buf) != 0) { | |
344 | + pstrcpy(bs->backing_file, end_name - p_name + 1, p_name); | |
345 | + if (stat(bs->backing_file, &file_buf) != 0) { | |
346 | 346 | path_combine(parent_img_name, sizeof(parent_img_name), |
347 | - filename, s->hd->backing_file); | |
347 | + filename, bs->backing_file); | |
348 | 348 | } else { |
349 | 349 | pstrcpy(parent_img_name, sizeof(parent_img_name), |
350 | - s->hd->backing_file); | |
350 | + bs->backing_file); | |
351 | 351 | } |
352 | 352 | |
353 | - s->hd->backing_hd = bdrv_new(""); | |
354 | - if (!s->hd->backing_hd) { | |
353 | + bs->backing_hd = bdrv_new(""); | |
354 | + if (!bs->backing_hd) { | |
355 | 355 | failure: |
356 | 356 | bdrv_close(s->hd); |
357 | 357 | return -1; |
358 | 358 | } |
359 | 359 | parent_open = 1; |
360 | - if (bdrv_open(s->hd->backing_hd, parent_img_name, BDRV_O_RDONLY) < 0) | |
360 | + if (bdrv_open(bs->backing_hd, parent_img_name, BDRV_O_RDONLY) < 0) | |
361 | 361 | goto failure; |
362 | 362 | parent_open = 0; |
363 | 363 | } |
... | ... | @@ -464,13 +464,14 @@ static int get_whole_cluster(BlockDriverState *bs, uint64_t cluster_offset, |
464 | 464 | |
465 | 465 | // we will be here if it's first write on non-exist grain(cluster). |
466 | 466 | // try to read from parent image, if exist |
467 | - if (s->hd->backing_hd) { | |
468 | - BDRVVmdkState *ps = s->hd->backing_hd->opaque; | |
467 | + if (bs->backing_hd) { | |
468 | + BDRVVmdkState *ps = bs->backing_hd->opaque; | |
469 | 469 | |
470 | 470 | if (!vmdk_is_cid_valid(bs)) |
471 | 471 | return -1; |
472 | 472 | |
473 | - parent_cluster_offset = get_cluster_offset(s->hd->backing_hd, NULL, offset, allocate); | |
473 | + parent_cluster_offset = get_cluster_offset(bs->backing_hd, NULL, | |
474 | + offset, allocate); | |
474 | 475 | |
475 | 476 | if (parent_cluster_offset) { |
476 | 477 | BDRVVmdkState *act_s = activeBDRV.hd->opaque; |
... | ... | @@ -621,10 +622,10 @@ static int vmdk_read(BlockDriverState *bs, int64_t sector_num, |
621 | 622 | n = nb_sectors; |
622 | 623 | if (!cluster_offset) { |
623 | 624 | // try to read from parent image, if exist |
624 | - if (s->hd->backing_hd) { | |
625 | + if (bs->backing_hd) { | |
625 | 626 | if (!vmdk_is_cid_valid(bs)) |
626 | 627 | return -1; |
627 | - ret = bdrv_read(s->hd->backing_hd, sector_num, buf, n); | |
628 | + ret = bdrv_read(bs->backing_hd, sector_num, buf, n); | |
628 | 629 | if (ret < 0) |
629 | 630 | return -1; |
630 | 631 | } else { | ... | ... |