qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

qcow2: try load bitmaps only once

Checking reopen by existence of some bitmaps is wrong, as it may be
some other bitmaps, or on the other hand, user may remove bitmaps. This
criteria is bad. To simplify things and make behavior more predictable
let's just add a flag to remember, that we've already tried to load
bitmaps on open and do not want do it again.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-id: 20180411122606.367301-2-vsementsov@virtuozzo.com
[mreitz: Changed comment wording according to Eric Blake's suggestion]
Signed-off-by: Max Reitz <mreitz@redhat.com>

authored by

Vladimir Sementsov-Ogievskiy and committed by
Max Reitz
605bc8be ae2b1b4e

+9 -8
+8 -8
block/qcow2.c
··· 1142 1142 uint64_t ext_end; 1143 1143 uint64_t l1_vm_state_index; 1144 1144 bool update_header = false; 1145 + bool header_updated = false; 1145 1146 1146 1147 ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); 1147 1148 if (ret < 0) { ··· 1480 1481 s->autoclear_features &= QCOW2_AUTOCLEAR_MASK; 1481 1482 } 1482 1483 1483 - if (bdrv_dirty_bitmap_next(bs, NULL)) { 1484 - /* It's some kind of reopen with already existing dirty bitmaps. There 1485 - * are no known cases where we need loading bitmaps in such situation, 1486 - * so it's safer don't load them. 1484 + if (s->dirty_bitmaps_loaded) { 1485 + /* It's some kind of reopen. There are no known cases where we need to 1486 + * reload bitmaps in such a situation, so it's safer to skip them. 1487 1487 * 1488 1488 * Moreover, if we have some readonly bitmaps and we are reopening for 1489 1489 * rw we should reopen bitmaps correspondingly. ··· 1491 1491 if (bdrv_has_readonly_bitmaps(bs) && 1492 1492 !bdrv_is_read_only(bs) && !(bdrv_get_flags(bs) & BDRV_O_INACTIVE)) 1493 1493 { 1494 - bool header_updated = false; 1495 1494 qcow2_reopen_bitmaps_rw_hint(bs, &header_updated, &local_err); 1496 - update_header = update_header && !header_updated; 1497 1495 } 1498 - } else if (qcow2_load_dirty_bitmaps(bs, &local_err)) { 1499 - update_header = false; 1496 + } else { 1497 + header_updated = qcow2_load_dirty_bitmaps(bs, &local_err); 1498 + s->dirty_bitmaps_loaded = true; 1500 1499 } 1500 + update_header = update_header && !header_updated; 1501 1501 if (local_err != NULL) { 1502 1502 error_propagate(errp, local_err); 1503 1503 ret = -EINVAL;
+1
block/qcow2.h
··· 298 298 uint32_t nb_bitmaps; 299 299 uint64_t bitmap_directory_size; 300 300 uint64_t bitmap_directory_offset; 301 + bool dirty_bitmaps_loaded; 301 302 302 303 int flags; 303 304 int qcow_version;