Skip to contentSkip to conversation

block: allow commit to unmap zero blocks

PATCH Superseded Vincent Vanlaer 2 participants 11 messages Sep 1, 2024 – Oct 2, 2024 Block layer

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover block: allow commit to unmap zero blocks

This patch series adds support for zero blocks in non-active commits. The first three patches in the series contains the actual changes to the commit code, the last patch adds a test for the new functionality.

---

Changes since v2:
- moved main loop of commit_run to a separate function and refactored the error handling.
- call blk_co_pwrite_zero even if the size of the zero region does not align with the sectors of the base image. This removes the need for the CommitMethod enum

Changes since v1:
- split up the implementation in three separate commits
- removed accidentally left over includes from testing

Vincent Vanlaer (5):
block: get type of block allocation in commit_run
block: move commit_run loop to separate function
block: refactor error handling of commit_iteration
block: allow commit to unmap zero blocks
block: add test non-active commit with zeroed data

 block/commit.c             | 108 +++++++++++++++++++++++++------------
 tests/qemu-iotests/315     |  95 ++++++++++++++++++++++++++++++++
 tests/qemu-iotests/315.out |  54 +++++++++++++++++++
 3 files changed, 223 insertions(+), 34 deletions(-)
 create mode 100755 tests/qemu-iotests/315
 create mode 100644 tests/qemu-iotests/315.out
Signature · 1 line
2.44.1
#1 lore raw

PATCH v3 1/5 block: get type of block allocation in commit_run

bdrv_co_common_block_status_above not only returns whether the block is allocated, but also if it contains zeroes.

---
 block/commit.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
block/commit.c +9 -3
index 7c3fdcb0ca..8dee25b313 100644
@@ -15,6 +15,8 @@
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "trace.h"
+#include "block/block-common.h"
+#include "block/coroutines.h"
 #include "block/block_int.h"
 #include "block/blockjob_int.h"
 #include "qapi/error.h"
@@ -167,9 +169,13 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
             break;
         }
         /* Copy if allocated above the base */
-        ret = blk_co_is_allocated_above(s->top, s->base_overlay, true,
-                                        offset, COMMIT_BUFFER_SIZE, &n);
-        copy = (ret > 0);
+        WITH_GRAPH_RDLOCK_GUARD() {
+            ret = bdrv_co_common_block_status_above(blk_bs(s->top),
+                s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE,
+                &n, NULL, NULL, NULL);
+        }
+
+        copy = (ret >= 0 && ret & BDRV_BLOCK_ALLOCATED);
         trace_commit_one_iteration(s, offset, n, ret);
         if (copy) {
             assert(n < SIZE_MAX);
Signature · 1 line
2.44.1
#2 lore raw

PATCH v3 2/5 block: move commit_run loop to separate function

In reply to Vincent Vanlaer
---
 block/commit.c | 85 ++++++++++++++++++++++++++++----------------------
 1 file changed, 48 insertions(+), 37 deletions(-)
block/commit.c +48 -37
index 8dee25b313..9eedd1fa47 100644
@@ -128,6 +128,51 @@ static void commit_clean(Job *job)
     blk_unref(s->top);
 }
 
+static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void *buf) {
+    int ret = 0;
+    bool copy;
+    bool error_in_source = true;
+
+    /* Copy if allocated above the base */
+    WITH_GRAPH_RDLOCK_GUARD() {
+        ret = bdrv_co_common_block_status_above(blk_bs(s->top),
+            s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE,
+            n, NULL, NULL, NULL);
+    }
+
+    copy = (ret >= 0 && ret & BDRV_BLOCK_ALLOCATED);
+    trace_commit_one_iteration(s, offset, *n, ret);
+    if (copy) {
+        assert(*n < SIZE_MAX);
+
+        ret = blk_co_pread(s->top, offset, *n, buf, 0);
+        if (ret >= 0) {
+            ret = blk_co_pwrite(s->base, offset, *n, buf, 0);
+            if (ret < 0) {
+                error_in_source = false;
+            }
+        }
+    }
+    if (ret < 0) {
+        BlockErrorAction action = block_job_error_action(&s->common, s->on_error,
+                                                         error_in_source, -ret);
+        if (action == BLOCK_ERROR_ACTION_REPORT) {
+            return ret;
+        } else {
+            *n = 0;
+            return 0;
+        }
+    }
+    /* Publish progress */
+    job_progress_update(&s->common.job, *n);
+
+    if (copy) {
+        block_job_ratelimit_processed_bytes(&s->common, *n);
+    }
+
+    return 0;
+}
+
 static int coroutine_fn commit_run(Job *job, Error **errp)
 {
     CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
@@ -158,9 +203,6 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
     buf = blk_blockalign(s->top, COMMIT_BUFFER_SIZE);
 
     for (offset = 0; offset < len; offset += n) {
-        bool copy;
-        bool error_in_source = true;
-
         /* Note that even when no rate limit is applied we need to yield
          * with no pending I/O here so that bdrv_drain_all() returns.
          */
@@ -168,42 +210,11 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
         if (job_is_cancelled(&s->common.job)) {
             break;
         }
-        /* Copy if allocated above the base */
-        WITH_GRAPH_RDLOCK_GUARD() {
-            ret = bdrv_co_common_block_status_above(blk_bs(s->top),
-                s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE,
-                &n, NULL, NULL, NULL);
-        }
 
-        copy = (ret >= 0 && ret & BDRV_BLOCK_ALLOCATED);
-        trace_commit_one_iteration(s, offset, n, ret);
-        if (copy) {
-            assert(n < SIZE_MAX);
-
-            ret = blk_co_pread(s->top, offset, n, buf, 0);
-            if (ret >= 0) {
-                ret = blk_co_pwrite(s->base, offset, n, buf, 0);
-                if (ret < 0) {
-                    error_in_source = false;
-                }
-            }
-        }
-        if (ret < 0) {
-            BlockErrorAction action =
-                block_job_error_action(&s->common, s->on_error,
-                                       error_in_source, -ret);
-            if (action == BLOCK_ERROR_ACTION_REPORT) {
-                return ret;
-            } else {
-                n = 0;
-                continue;
-            }
-        }
-        /* Publish progress */
-        job_progress_update(&s->common.job, n);
+        ret = commit_iteration(s, offset, &n, buf);
 
-        if (copy) {
-            block_job_ratelimit_processed_bytes(&s->common, n);
+        if (ret < 0) {
+            return ret;
         }
     }
 
Signature · 1 line
2.44.1
Reviewed-by on v3 2/5
#3 lore raw

Re: [PATCH v3 2/5] block: move commit_run loop to separate function

Quoted 19 lines · Vincent Vanlaer
---
  block/commit.c | 85 ++++++++++++++++++++++++++++----------------------
  1 file changed, 48 insertions(+), 37 deletions(-)
block/commit.c +6 -0
index 8dee25b313..9eedd1fa47 100644
@@ -128,6 +128,51 @@ static void commit_clean(Job *job)
      blk_unref(s->top);
  }
 
+static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void *buf) {
+    int ret = 0;
+    bool copy;
+    bool error_in_source = true;
+
+    /* Copy if allocated above the base */

block/commit.c static void commit_clean(Job *job) · line 146

Quoted 10 lines
block/commit.c +10 -0
+    WITH_GRAPH_RDLOCK_GUARD() {
+        ret = bdrv_co_common_block_status_above(blk_bs(s->top),
+            s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE,
+            n, NULL, NULL, NULL);
+    }
+
+    copy = (ret >= 0 && ret & BDRV_BLOCK_ALLOCATED);
+    trace_commit_one_iteration(s, offset, *n, ret);
+    if (copy) {
+        assert(*n < SIZE_MAX);

Probably a matter of taste, but I'd prefer working with local variable instead of dereferencing the pointer on every line. Like this:

commit_iteration(..., int64_t bytes, int64_t *done, ...) {

... work with bytes variable ...

out:
*done = bytes;
return 0;
}

anyway:

Quoted 88 lines
block/commit.c +32 -37
+
+        ret = blk_co_pread(s->top, offset, *n, buf, 0);
+        if (ret >= 0) {
+            ret = blk_co_pwrite(s->base, offset, *n, buf, 0);
+            if (ret < 0) {
+                error_in_source = false;
+            }
+        }
+    }
+    if (ret < 0) {
+        BlockErrorAction action = block_job_error_action(&s->common, s->on_error,
+                                                         error_in_source, -ret);
+        if (action == BLOCK_ERROR_ACTION_REPORT) {
+            return ret;
+        } else {
+            *n = 0;
+            return 0;
+        }
+    }
+    /* Publish progress */
+    job_progress_update(&s->common.job, *n);
+
+    if (copy) {
+        block_job_ratelimit_processed_bytes(&s->common, *n);
+    }
+
+    return 0;
+}
+
  static int coroutine_fn commit_run(Job *job, Error **errp)
  {
      CommitBlockJob *s = container_of(job, CommitBlockJob, common.job);
@@ -158,9 +203,6 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
      buf = blk_blockalign(s->top, COMMIT_BUFFER_SIZE);
 
      for (offset = 0; offset < len; offset += n) {
-        bool copy;
-        bool error_in_source = true;
-
          /* Note that even when no rate limit is applied we need to yield
           * with no pending I/O here so that bdrv_drain_all() returns.
           */
@@ -168,42 +210,11 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
          if (job_is_cancelled(&s->common.job)) {
              break;
          }
-        /* Copy if allocated above the base */
-        WITH_GRAPH_RDLOCK_GUARD() {
-            ret = bdrv_co_common_block_status_above(blk_bs(s->top),
-                s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE,
-                &n, NULL, NULL, NULL);
-        }
 
-        copy = (ret >= 0 && ret & BDRV_BLOCK_ALLOCATED);
-        trace_commit_one_iteration(s, offset, n, ret);
-        if (copy) {
-            assert(n < SIZE_MAX);
-
-            ret = blk_co_pread(s->top, offset, n, buf, 0);
-            if (ret >= 0) {
-                ret = blk_co_pwrite(s->base, offset, n, buf, 0);
-                if (ret < 0) {
-                    error_in_source = false;
-                }
-            }
-        }
-        if (ret < 0) {
-            BlockErrorAction action =
-                block_job_error_action(&s->common, s->on_error,
-                                       error_in_source, -ret);
-            if (action == BLOCK_ERROR_ACTION_REPORT) {
-                return ret;
-            } else {
-                n = 0;
-                continue;
-            }
-        }
-        /* Publish progress */
-        job_progress_update(&s->common.job, n);
+        ret = commit_iteration(s, offset, &n, buf);
 
-        if (copy) {
-            block_job_ratelimit_processed_bytes(&s->common, n);
+        if (ret < 0) {
+            return ret;
          }
      }
 
Signature · 2 lines
Best regards,
Vladimir
#4 lore raw

Re: [PATCH v3 2/5] block: move commit_run loop to separate function

In reply to Vincent Vanlaer
Quoted 1 line · Vincent Vanlaer

+static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void *buf) {

Hmm over-80 line. Didn't you forget run ./checkpatch.pl ?

Signature · 2 lines
Best regards,
Vladimir
#5 lore raw

PATCH v3 3/5 block: refactor error handling of commit_iteration

In reply to Vincent Vanlaer
---
 block/commit.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)
block/commit.c +22 -15
index 9eedd1fa47..288e413be3 100644
@@ -130,7 +130,6 @@ static void commit_clean(Job *job)
 
 static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void *buf) {
     int ret = 0;
-    bool copy;
     bool error_in_source = true;
 
     /* Copy if allocated above the base */
@@ -140,19 +139,34 @@ static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void
             n, NULL, NULL, NULL);
     }
 
-    copy = (ret >= 0 && ret & BDRV_BLOCK_ALLOCATED);
+    if (ret < 0) {
+        goto handle_error;
+    }
+
     trace_commit_one_iteration(s, offset, *n, ret);
-    if (copy) {
+
+    if (ret & BDRV_BLOCK_ALLOCATED) {
         assert(*n < SIZE_MAX);
 
         ret = blk_co_pread(s->top, offset, *n, buf, 0);
-        if (ret >= 0) {
-            ret = blk_co_pwrite(s->base, offset, *n, buf, 0);
-            if (ret < 0) {
-                error_in_source = false;
-            }
+        if (ret < 0) {
+            goto handle_error;
         }
+
+        ret = blk_co_pwrite(s->base, offset, *n, buf, 0);
+        if (ret < 0) {
+            error_in_source = false;
+            goto handle_error;
+        }
+
+        block_job_ratelimit_processed_bytes(&s->common, *n);
     }
+
+    /* Publish progress */
+
+    job_progress_update(&s->common.job, *n);
+
+handle_error:
     if (ret < 0) {
         BlockErrorAction action = block_job_error_action(&s->common, s->on_error,
                                                          error_in_source, -ret);
@@ -160,15 +174,8 @@ static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void
             return ret;
         } else {
             *n = 0;
-            return 0;
         }
     }
-    /* Publish progress */
-    job_progress_update(&s->common.job, *n);
-
-    if (copy) {
-        block_job_ratelimit_processed_bytes(&s->common, *n);
-    }
 
     return 0;
 }
Signature · 1 line
2.44.1
#6 lore raw

Re: [PATCH v3 3/5] block: refactor error handling of commit_iteration

Quoted 18 lines · Vincent Vanlaer
---
  block/commit.c | 37 ++++++++++++++++++++++---------------
  1 file changed, 22 insertions(+), 15 deletions(-)
block/commit.c +0 -1
index 9eedd1fa47..288e413be3 100644
@@ -130,7 +130,6 @@ static void commit_clean(Job *job)
 
  static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void *buf) {
      int ret = 0;
-    bool copy;
      bool error_in_source = true;
 
      /* Copy if allocated above the base */

block/commit.c static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void · line 146

Quoted 9 lines
block/commit.c +4 -1
@@ -140,19 +139,34 @@ static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void
              n, NULL, NULL, NULL);
      }
 
-    copy = (ret >= 0 && ret & BDRV_BLOCK_ALLOCATED);
+    if (ret < 0) {
+        goto handle_error;
+    }
+
      trace_commit_one_iteration(s, offset, *n, ret);

this way we loose trace point for error case. Let's move trace_... above "if (ret.."

Quoted 18 lines
block/commit.c +8 -6
-    if (copy) {
+
+    if (ret & BDRV_BLOCK_ALLOCATED) {
          assert(*n < SIZE_MAX);
 
          ret = blk_co_pread(s->top, offset, *n, buf, 0);
-        if (ret >= 0) {
-            ret = blk_co_pwrite(s->base, offset, *n, buf, 0);
-            if (ret < 0) {
-                error_in_source = false;
-            }
+        if (ret < 0) {
+            goto handle_error;
          }
+
+        ret = blk_co_pwrite(s->base, offset, *n, buf, 0);
+        if (ret < 0) {
+            error_in_source = false;

block/commit.c static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void · line 168

Quoted 10 lines
block/commit.c +9 -0
+            goto handle_error;
+        }
+
+        block_job_ratelimit_processed_bytes(&s->common, *n);
      }
+
+    /* Publish progress */
+
+    job_progress_update(&s->common.job, *n);
+

it looks a bit strange to fallthrough to "handle_error" from success path

I suggest:

@@ -166,17 +166,17 @@ static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void

     job_progress_update(&s->common.job, *n);

-handle_error:
- if (ret < 0) {
- BlockErrorAction action = block_job_error_action(&s->common, s->on_error,
- error_in_source, -ret);
- if (action == BLOCK_ERROR_ACTION_REPORT) {
- return ret;
- } else {
- *n = 0;
- }
+ return 0;
+
+fail:
+ BlockErrorAction action = block_job_error_action(&s->common, s->on_error,
+ error_in_source, -ret);
+ if (action == BLOCK_ERROR_ACTION_REPORT) {

+        return ret;
     }

+ /* Retry iteration */

+    *n = 0;
     return 0;

}

(also, "fail" name is more popular for such labels:

$ git grep 'goto fail' | wc -l
1334
)
Quoted 20 lines
block/commit.c +1 -7
+handle_error:
      if (ret < 0) {
          BlockErrorAction action = block_job_error_action(&s->common, s->on_error,
                                                           error_in_source, -ret);
@@ -160,15 +174,8 @@ static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void
              return ret;
          } else {
              *n = 0;
-            return 0;
          }
      }
-    /* Publish progress */
-    job_progress_update(&s->common.job, *n);
-
-    if (copy) {
-        block_job_ratelimit_processed_bytes(&s->common, *n);
-    }
 
      return 0;
  }
Signature · 2 lines
Best regards,
Vladimir
#7 lore raw

PATCH v3 4/5 block: allow commit to unmap zero blocks

In reply to Vincent Vanlaer

Non-active block commits do not discard blocks only containing zeros, causing images to lose sparseness after the commit. This commit fixes that by writing zero blocks using blk_co_pwrite_zeroes rather than writing them out as any other arbitrary data.

---
 block/commit.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
block/commit.c +25 -9
index 288e413be3..2594917a74 100644
@@ -146,19 +146,35 @@ static int commit_iteration(CommitBlockJob *s, int64_t offset, int64_t *n, void
     trace_commit_one_iteration(s, offset, *n, ret);
 
     if (ret & BDRV_BLOCK_ALLOCATED) {
-        assert(*n < SIZE_MAX);
+        if (ret & BDRV_BLOCK_ZERO) {
+            /* If the top (sub)clusters are smaller than the base
+             * (sub)clusters, this will not unmap unless the underlying device
+             * does some tracking of these requests. Ideally, we would find
+             * the maximal extent of the zero clusters. */
+            ret = blk_co_pwrite_zeroes(s->base, offset, *n,
+                                       BDRV_REQ_MAY_UNMAP);
+            if (ret < 0) {
+                error_in_source = false;
+                goto handle_error;
+            }
+        } else {
+            assert(*n < SIZE_MAX);
 
-        ret = blk_co_pread(s->top, offset, *n, buf, 0);
-        if (ret < 0) {
-            goto handle_error;
-        }
+            ret = blk_co_pread(s->top, offset, *n, buf, 0);
+            if (ret < 0) {
+                goto handle_error;
+            }
 
-        ret = blk_co_pwrite(s->base, offset, *n, buf, 0);
-        if (ret < 0) {
-            error_in_source = false;
-            goto handle_error;
+            ret = blk_co_pwrite(s->base, offset, *n, buf, 0);
+            if (ret < 0) {
+                error_in_source = false;
+                goto handle_error;
+            }
         }
 
+        /* Whether zeroes actually end up on disk depends on the details of
+         * the underlying driver. Therefore, this might rate limit more than
+         * is necessary. */
         block_job_ratelimit_processed_bytes(&s->common, *n);
     }
 
Signature · 1 line
2.44.1
Reviewed-by on v3 4/5
#8 lore raw
Quoted 6 lines · Vincent Vanlaer

Non-active block commits do not discard blocks only containing zeros, causing images to lose sparseness after the commit. This commit fixes that by writing zero blocks using blk_co_pwrite_zeroes rather than writing them out as any other arbitrary data.

Signature · 2 lines
Best regards,
Vladimir
#9 lore raw

PATCH v3 5/5 block: add test non-active commit with zeroed data

In reply to Vincent Vanlaer
---
 tests/qemu-iotests/315     | 95 ++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/315.out | 54 ++++++++++++++++++++++
 2 files changed, 149 insertions(+)
 create mode 100755 tests/qemu-iotests/315
 create mode 100644 tests/qemu-iotests/315.out
tests/qemu-iotests/315 new file +95 -0
new file mode 100755
index 0000000000..84865f8001
@@ -0,0 +1,95 @@
+#!/usr/bin/env bash
+# group: rw quick
+#
+# Test for commit of discarded blocks
+#
+# This tests committing a live snapshot where some of the blocks that
+# are present in the base image are discarded in the intermediate image.
+# This intends to check that these blocks are also discarded in the base
+# image after the commit.
+#
+# Copyright (C) 2024 Vincent Vanlaer.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# creator
[email protected]
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+status=1	# failure is the default!
+
+_cleanup()
+{
+    _cleanup_qemu
+    _rm_test_img "${TEST_IMG}.base"
+    _rm_test_img "${TEST_IMG}.mid"
+    _cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+. ./common.qemu
+
+_supported_fmt qcow2
+_supported_proto file
+
+size="1M"
+
+TEST_IMG="$TEST_IMG.base" _make_test_img $size
+TEST_IMG="$TEST_IMG.mid" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $size
+_make_test_img -b "${TEST_IMG}.mid" -F $IMGFMT $size
+
+$QEMU_IO -c "write -P 0x01 64k 128k" "$TEST_IMG.base" | _filter_qemu_io
+$QEMU_IO -c "discard 64k 64k" "$TEST_IMG.mid" | _filter_qemu_io
+
+echo
+echo "=== Base image info before commit ==="
+TEST_IMG="${TEST_IMG}.base" _img_info | _filter_img_info
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
+
+echo
+echo "=== Middle image info before commit ==="
+TEST_IMG="${TEST_IMG}.mid" _img_info | _filter_img_info
+$QEMU_IMG map --output=json "$TEST_IMG.mid" | _filter_qemu_img_map
+
+echo
+echo === Running QEMU Live Commit Test ===
+echo
+
+qemu_comm_method="qmp"
+_launch_qemu -drive file="${TEST_IMG}",if=virtio,id=test
+h=$QEMU_HANDLE
+
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" "return"
+
+_send_qemu_cmd $h "{ 'execute': 'block-commit',
+                                 'arguments': { 'device': 'test',
+                                 'top': '"${TEST_IMG}.mid"',
+                                 'base': '"${TEST_IMG}.base"'} }" '"status": "null"'
+
+_cleanup_qemu
+
+echo
+echo "=== Base image info after commit ==="
+TEST_IMG="${TEST_IMG}.base" _img_info | _filter_img_info
+$QEMU_IMG map --output=json "$TEST_IMG.base" | _filter_qemu_img_map
+
+# success, all done
+echo "*** done"
+rm -f $seq.full
+status=0
tests/qemu-iotests/315.out new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.44.1
Tested-by Reviewed-by on v3 5/5
#10 lore raw

Re: [PATCH v3 5/5] block: add test non-active commit with zeroed data

Quoted 4 lines · Vincent Vanlaer
---
  tests/qemu-iotests/315     | 95 ++++++++++++++++++++++++++++++++++++++
  tests/qemu-iotests/315.out | 54 ++++++++++++++++++++++

Please place new tests in tests/qemu-iotests/tests, with human readable name, something like commit-zeroes or what you want.

Quoted 43 lines
  2 files changed, 149 insertions(+)

create mode 100755 tests/qemu-iotests/315
create mode 100644 tests/qemu-iotests/315.out

tests/qemu-iotests/315 new file +33 -0
new file mode 100755
index 0000000000..84865f8001
@@ -0,0 +1,95 @@
+#!/usr/bin/env bash
+# group: rw quick
+#
+# Test for commit of discarded blocks
+#
+# This tests committing a live snapshot where some of the blocks that
+# are present in the base image are discarded in the intermediate image.
+# This intends to check that these blocks are also discarded in the base
+# image after the commit.
+#
+# Copyright (C) 2024 Vincent Vanlaer.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# creator
[email protected]
+
+seq=`basename $0`
+echo "QA output created by $seq"
+
+status=1	# failure is the default!
+

tests/qemu-iotests/315 line 43

Quoted 10 lines
tests/qemu-iotests/315 new file +10 -0
+_cleanup()
+{
+    _cleanup_qemu
+    _rm_test_img "${TEST_IMG}.base"
+    _rm_test_img "${TEST_IMG}.mid"
+    _cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks

Example of bash test in tests is tests/qemu-iotests/tests/qemu-img-bitmaps, so you'll need "cd .." here, before ". ./common.rc"

I know, this all looks not optimal, but still, human-readable names are much better than numbers.

With that:

Quoted 4 lines
tests/qemu-iotests/315 new file +4 -0
+. ./common.rc
+. ./common.filter
+. ./common.qemu
+
Signature · 2 lines
Best regards,
Vladimir