dcavalca / rpms / qemu

Forked from rpms/qemu 11 months ago
Clone

Blame 0004-Revert-block-avoid-recursive-block_status-call-if-po.patch

f4c127
From: Cole Robinson <crobinso@redhat.com>
f4c127
Date: Thu, 24 Oct 2019 11:32:46 -0400
f4c127
Subject: [PATCH] Revert "block: avoid recursive block_status call if possible"
f4c127
f4c127
This reverts commit 69f47505ee66afaa513305de0c1895a224e52c45.
f4c127
f4c127
Workaround for qcow2 triggered XFS corruption, bug 1763519
f4c127
---
f4c127
 block/io.c                 |  9 +--------
f4c127
 block/qcow2-refcount.c     | 32 --------------------------------
f4c127
 block/qcow2.c              | 11 -----------
f4c127
 block/qcow2.h              |  4 ----
f4c127
 include/block/block.h      |  8 +-------
f4c127
 tests/qemu-iotests/102     |  2 +-
f4c127
 tests/qemu-iotests/102.out |  3 +--
f4c127
 tests/qemu-iotests/141.out |  2 +-
f4c127
 tests/qemu-iotests/144.out |  2 +-
f4c127
 9 files changed, 6 insertions(+), 67 deletions(-)
f4c127
f4c127
diff --git a/block/io.c b/block/io.c
f4c127
index 06305c6ea6..ef057ba5db 100644
f4c127
--- a/block/io.c
f4c127
+++ b/block/io.c
f4c127
@@ -2156,12 +2156,6 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
f4c127
      */
f4c127
     assert(*pnum && QEMU_IS_ALIGNED(*pnum, align) &&
f4c127
            align > offset - aligned_offset);
f4c127
-    if (ret & BDRV_BLOCK_RECURSE) {
f4c127
-        assert(ret & BDRV_BLOCK_DATA);
f4c127
-        assert(ret & BDRV_BLOCK_OFFSET_VALID);
f4c127
-        assert(!(ret & BDRV_BLOCK_ZERO));
f4c127
-    }
f4c127
-
f4c127
     *pnum -= offset - aligned_offset;
f4c127
     if (*pnum > bytes) {
f4c127
         *pnum = bytes;
f4c127
@@ -2192,8 +2186,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs,
f4c127
         }
f4c127
     }
f4c127
 
f4c127
-    if (want_zero && ret & BDRV_BLOCK_RECURSE &&
f4c127
-        local_file && local_file != bs &&
f4c127
+    if (want_zero && local_file && local_file != bs &&
f4c127
         (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
f4c127
         (ret & BDRV_BLOCK_OFFSET_VALID)) {
f4c127
         int64_t file_pnum;
f4c127
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
f4c127
index ef965d7895..81ecb88f9c 100644
f4c127
--- a/block/qcow2-refcount.c
f4c127
+++ b/block/qcow2-refcount.c
f4c127
@@ -3448,35 +3448,3 @@ int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size)
f4c127
                             "There are no references in the refcount table.");
f4c127
     return -EIO;
f4c127
 }
f4c127
-
f4c127
-int qcow2_detect_metadata_preallocation(BlockDriverState *bs)
f4c127
-{
f4c127
-    BDRVQcow2State *s = bs->opaque;
f4c127
-    int64_t i, end_cluster, cluster_count = 0, threshold;
f4c127
-    int64_t file_length, real_allocation, real_clusters;
f4c127
-
f4c127
-    file_length = bdrv_getlength(bs->file->bs);
f4c127
-    if (file_length < 0) {
f4c127
-        return file_length;
f4c127
-    }
f4c127
-
f4c127
-    real_allocation = bdrv_get_allocated_file_size(bs->file->bs);
f4c127
-    if (real_allocation < 0) {
f4c127
-        return real_allocation;
f4c127
-    }
f4c127
-
f4c127
-    real_clusters = real_allocation / s->cluster_size;
f4c127
-    threshold = MAX(real_clusters * 10 / 9, real_clusters + 2);
f4c127
-
f4c127
-    end_cluster = size_to_clusters(s, file_length);
f4c127
-    for (i = 0; i < end_cluster && cluster_count < threshold; i++) {
f4c127
-        uint64_t refcount;
f4c127
-        int ret = qcow2_get_refcount(bs, i, &refcount);
f4c127
-        if (ret < 0) {
f4c127
-            return ret;
f4c127
-        }
f4c127
-        cluster_count += !!refcount;
f4c127
-    }
f4c127
-
f4c127
-    return cluster_count >= threshold;
f4c127
-}
f4c127
diff --git a/block/qcow2.c b/block/qcow2.c
f4c127
index 039bdc2f7e..86e88f6af4 100644
f4c127
--- a/block/qcow2.c
f4c127
+++ b/block/qcow2.c
f4c127
@@ -1895,12 +1895,6 @@ static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs,
f4c127
     unsigned int bytes;
f4c127
     int status = 0;
f4c127
 
f4c127
-    if (!s->metadata_preallocation_checked) {
f4c127
-        ret = qcow2_detect_metadata_preallocation(bs);
f4c127
-        s->metadata_preallocation = (ret == 1);
f4c127
-        s->metadata_preallocation_checked = true;
f4c127
-    }
f4c127
-
f4c127
     bytes = MIN(INT_MAX, count);
f4c127
     qemu_co_mutex_lock(&s->lock);
f4c127
     ret = qcow2_get_cluster_offset(bs, offset, &bytes, &cluster_offset);
f4c127
@@ -1923,11 +1917,6 @@ static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs,
f4c127
     } else if (ret != QCOW2_CLUSTER_UNALLOCATED) {
f4c127
         status |= BDRV_BLOCK_DATA;
f4c127
     }
f4c127
-    if (s->metadata_preallocation && (status & BDRV_BLOCK_DATA) &&
f4c127
-        (status & BDRV_BLOCK_OFFSET_VALID))
f4c127
-    {
f4c127
-        status |= BDRV_BLOCK_RECURSE;
f4c127
-    }
f4c127
     return status;
f4c127
 }
f4c127
 
f4c127
diff --git a/block/qcow2.h b/block/qcow2.h
f4c127
index fc1b0d3c1e..567375e56c 100644
f4c127
--- a/block/qcow2.h
f4c127
+++ b/block/qcow2.h
f4c127
@@ -356,9 +356,6 @@ typedef struct BDRVQcow2State {
f4c127
     int nb_threads;
f4c127
 
f4c127
     BdrvChild *data_file;
f4c127
-
f4c127
-    bool metadata_preallocation_checked;
f4c127
-    bool metadata_preallocation;
f4c127
 } BDRVQcow2State;
f4c127
 
f4c127
 typedef struct Qcow2COWRegion {
f4c127
@@ -658,7 +655,6 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
f4c127
                                 void *cb_opaque, Error **errp);
f4c127
 int qcow2_shrink_reftable(BlockDriverState *bs);
f4c127
 int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size);
f4c127
-int qcow2_detect_metadata_preallocation(BlockDriverState *bs);
f4c127
 
f4c127
 /* qcow2-cluster.c functions */
f4c127
 int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
f4c127
diff --git a/include/block/block.h b/include/block/block.h
f4c127
index 50a07c1c33..269c0931e7 100644
f4c127
--- a/include/block/block.h
f4c127
+++ b/include/block/block.h
f4c127
@@ -156,15 +156,10 @@ typedef struct HDGeometry {
f4c127
  * BDRV_BLOCK_EOF: the returned pnum covers through end of file for this
f4c127
  *                 layer, set by block layer
f4c127
  *
f4c127
- * Internal flags:
f4c127
+ * Internal flag:
f4c127
  * BDRV_BLOCK_RAW: for use by passthrough drivers, such as raw, to request
f4c127
  *                 that the block layer recompute the answer from the returned
f4c127
  *                 BDS; must be accompanied by just BDRV_BLOCK_OFFSET_VALID.
f4c127
- * BDRV_BLOCK_RECURSE: request that the block layer will recursively search for
f4c127
- *                     zeroes in file child of current block node inside
f4c127
- *                     returned region. Only valid together with both
f4c127
- *                     BDRV_BLOCK_DATA and BDRV_BLOCK_OFFSET_VALID. Should not
f4c127
- *                     appear with BDRV_BLOCK_ZERO.
f4c127
  *
f4c127
  * If BDRV_BLOCK_OFFSET_VALID is set, the map parameter represents the
f4c127
  * host offset within the returned BDS that is allocated for the
f4c127
@@ -189,7 +184,6 @@ typedef struct HDGeometry {
f4c127
 #define BDRV_BLOCK_RAW          0x08
f4c127
 #define BDRV_BLOCK_ALLOCATED    0x10
f4c127
 #define BDRV_BLOCK_EOF          0x20
f4c127
-#define BDRV_BLOCK_RECURSE      0x40
f4c127
 #define BDRV_BLOCK_OFFSET_MASK  BDRV_SECTOR_MASK
f4c127
 
f4c127
 typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue;
f4c127
diff --git a/tests/qemu-iotests/102 b/tests/qemu-iotests/102
f4c127
index b898df436f..749ff66b8a 100755
f4c127
--- a/tests/qemu-iotests/102
f4c127
+++ b/tests/qemu-iotests/102
f4c127
@@ -55,7 +55,7 @@ $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io
f4c127
 $QEMU_IMG resize -f raw --shrink "$TEST_IMG" $((5 * 64 * 1024))
f4c127
 
f4c127
 $QEMU_IO -c map "$TEST_IMG"
f4c127
-$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map
f4c127
+$QEMU_IMG map "$TEST_IMG"
f4c127
 
f4c127
 echo
f4c127
 echo '=== Testing map on an image file truncated outside of qemu ==='
f4c127
diff --git a/tests/qemu-iotests/102.out b/tests/qemu-iotests/102.out
f4c127
index cd2fdc7f96..4401b08fee 100644
f4c127
--- a/tests/qemu-iotests/102.out
f4c127
+++ b/tests/qemu-iotests/102.out
f4c127
@@ -7,8 +7,7 @@ wrote 65536/65536 bytes at offset 0
f4c127
 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
f4c127
 Image resized.
f4c127
 64 KiB (0x10000) bytes     allocated at offset 0 bytes (0x0)
f4c127
-Offset          Length          File
f4c127
-0               0x10000         TEST_DIR/t.IMGFMT
f4c127
+Offset          Length          Mapped to       File
f4c127
 
f4c127
 === Testing map on an image file truncated outside of qemu ===
f4c127
 
f4c127
diff --git a/tests/qemu-iotests/141.out b/tests/qemu-iotests/141.out
f4c127
index 4d71d9dcae..41c7291258 100644
f4c127
--- a/tests/qemu-iotests/141.out
f4c127
+++ b/tests/qemu-iotests/141.out
f4c127
@@ -42,9 +42,9 @@ Formatting 'TEST_DIR/o.IMGFMT', fmt=IMGFMT size=1048576 backing_file=TEST_DIR/t.
f4c127
 {"return": {}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "job0"}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "job0"}}
f4c127
-{"return": {}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "job0"}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "job0", "len": 0, "offset": 0, "speed": 0, "type": "commit"}}
f4c127
+{"return": {}}
f4c127
 {"error": {"class": "GenericError", "desc": "Node 'drv0' is busy: block device is in use by block job: commit"}}
f4c127
 {"return": {}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "job0"}}
f4c127
diff --git a/tests/qemu-iotests/144.out b/tests/qemu-iotests/144.out
f4c127
index a9a8216bea..55299201e4 100644
f4c127
--- a/tests/qemu-iotests/144.out
f4c127
+++ b/tests/qemu-iotests/144.out
f4c127
@@ -14,10 +14,10 @@ Formatting 'TEST_DIR/tmp.qcow2', fmt=qcow2 size=536870912 backing_file=TEST_DIR/
f4c127
 
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "created", "id": "virtio0"}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "running", "id": "virtio0"}}
f4c127
-{"return": {}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "ready", "id": "virtio0"}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "virtio0", "len": 0, "offset": 0, "speed": 0, "type": "commit"}}
f4c127
 {"return": {}}
f4c127
+{"return": {}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "waiting", "id": "virtio0"}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "JOB_STATUS_CHANGE", "data": {"status": "pending", "id": "virtio0"}}
f4c127
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "virtio0", "len": 0, "offset": 0, "speed": 0, "type": "commit"}}