qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] block/qcow2: QAPI'fy Qcow2DiscardType
@ 2023-02-24 15:20 Philippe Mathieu-Daudé
  2023-02-24 15:20 ` [PATCH 1/2] block/qcow2: Rename QCOW2_DISCARD_TYPE enum definitions Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-24 15:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-block, Hanna Reitz, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
	Markus Armbruster, Eric Blake, John Snow,
	Philippe Mathieu-Daudé

QAPI seems designed to maintain such enums,
so convert Qcow2DiscardType to be QAPI generated.
Besides, this is how Qcow2CompressionType is maintained.

Philippe Mathieu-Daudé (2):
  block/qcow2: Rename QCOW2_DISCARD_TYPE enum definitions
  block/qcow2: QAPI'fy Qcow2DiscardType

 block/qcow2-bitmap.c   | 12 ++++++------
 block/qcow2-cluster.c  | 32 ++++++++++++++++----------------
 block/qcow2-refcount.c | 36 ++++++++++++++++++------------------
 block/qcow2-snapshot.c |  8 ++++----
 block/qcow2.c          | 26 +++++++++++++-------------
 block/qcow2.h          | 19 +++++--------------
 qapi/block-core.json   | 10 ++++++++++
 7 files changed, 72 insertions(+), 71 deletions(-)

-- 
2.38.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] block/qcow2: Rename QCOW2_DISCARD_TYPE enum definitions
  2023-02-24 15:20 [PATCH 0/2] block/qcow2: QAPI'fy Qcow2DiscardType Philippe Mathieu-Daudé
@ 2023-02-24 15:20 ` Philippe Mathieu-Daudé
  2023-02-24 15:20 ` [PATCH 2/2] block/qcow2: QAPI'fy Qcow2DiscardType Philippe Mathieu-Daudé
  2023-02-24 21:26 ` [PATCH 0/2] " Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-24 15:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-block, Hanna Reitz, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
	Markus Armbruster, Eric Blake, John Snow,
	Philippe Mathieu-Daudé

In order to QAPI'fy Qcow2DiscardType in the next commit,
rename its definitions to a QAPI-ready format.

Mechanical change doing:

  $ sed -i -e 's/QCOW2_DISCARD_/QCOW2_DISCARD_TYPE_/g' \
        $(git grep -l QCOW2_DISCARD_)
  $ sed -i -e 's/QCOW2_DISCARD_TYPE_MAX/QCOW2_DISCARD_TYPE__MAX/g' \
        $(git grep -l QCOW2_DISCARD_TYPE_MAX)

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 block/qcow2-bitmap.c   | 12 ++++++------
 block/qcow2-cluster.c  | 28 ++++++++++++++--------------
 block/qcow2-refcount.c | 26 +++++++++++++-------------
 block/qcow2-snapshot.c |  8 ++++----
 block/qcow2.c          | 26 +++++++++++++-------------
 block/qcow2.h          | 14 +++++++-------
 6 files changed, 57 insertions(+), 57 deletions(-)

diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 5f456a2785..67be9a0b0f 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -216,7 +216,7 @@ static void clear_bitmap_table(BlockDriverState *bs, uint64_t *bitmap_table,
             continue;
         }
 
-        qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_ALWAYS);
+        qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_TYPE_ALWAYS);
         bitmap_table[i] = 0;
     }
 }
@@ -271,7 +271,7 @@ static int free_bitmap_clusters(BlockDriverState *bs, Qcow2BitmapTable *tb)
 
     clear_bitmap_table(bs, bitmap_table, tb->size);
     qcow2_free_clusters(bs, tb->offset, tb->size * BME_TABLE_ENTRY_SIZE,
-                        QCOW2_DISCARD_OTHER);
+                        QCOW2_DISCARD_TYPE_OTHER);
     g_free(bitmap_table);
 
     tb->offset = 0;
@@ -818,7 +818,7 @@ fail:
     g_free(dir);
 
     if (!in_place && dir_offset > 0) {
-        qcow2_free_clusters(bs, dir_offset, dir_size, QCOW2_DISCARD_OTHER);
+        qcow2_free_clusters(bs, dir_offset, dir_size, QCOW2_DISCARD_TYPE_OTHER);
     }
 
     return ret;
@@ -921,14 +921,14 @@ static int update_ext_header_and_dir(BlockDriverState *bs,
     }
 
     if (old_size > 0) {
-        qcow2_free_clusters(bs, old_offset, old_size, QCOW2_DISCARD_OTHER);
+        qcow2_free_clusters(bs, old_offset, old_size, QCOW2_DISCARD_TYPE_OTHER);
     }
 
     return 0;
 
 fail:
     if (new_offset > 0) {
-        qcow2_free_clusters(bs, new_offset, new_size, QCOW2_DISCARD_OTHER);
+        qcow2_free_clusters(bs, new_offset, new_size, QCOW2_DISCARD_TYPE_OTHER);
     }
 
     s->bitmap_directory_offset = old_offset;
@@ -1424,7 +1424,7 @@ fail:
 
     if (tb_offset > 0) {
         qcow2_free_clusters(bs, tb_offset, tb_size * sizeof(tb[0]),
-                            QCOW2_DISCARD_OTHER);
+                            QCOW2_DISCARD_TYPE_OTHER);
     }
 
     g_free(tb);
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 870be106b6..a525afc7c3 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -67,7 +67,7 @@ int coroutine_fn qcow2_shrink_l1_table(BlockDriverState *bs,
             continue;
         }
         qcow2_free_clusters(bs, s->l1_table[i] & L1E_OFFSET_MASK,
-                            s->cluster_size, QCOW2_DISCARD_ALWAYS);
+                            s->cluster_size, QCOW2_DISCARD_TYPE_ALWAYS);
         s->l1_table[i] = 0;
     }
     return 0;
@@ -184,12 +184,12 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
     old_l1_size = s->l1_size;
     s->l1_size = new_l1_size;
     qcow2_free_clusters(bs, old_l1_table_offset, old_l1_size * L1E_SIZE,
-                        QCOW2_DISCARD_OTHER);
+                        QCOW2_DISCARD_TYPE_OTHER);
     return 0;
  fail:
     qemu_vfree(new_l1_table);
     qcow2_free_clusters(bs, new_l1_table_offset, new_l1_size2,
-                        QCOW2_DISCARD_OTHER);
+                        QCOW2_DISCARD_TYPE_OTHER);
     return ret;
 }
 
@@ -373,7 +373,7 @@ fail:
     s->l1_table[l1_index] = old_l2_offset;
     if (l2_offset > 0) {
         qcow2_free_clusters(bs, l2_offset, s->l2_size * l2_entry_size(s),
-                            QCOW2_DISCARD_ALWAYS);
+                            QCOW2_DISCARD_TYPE_ALWAYS);
     }
     return ret;
 }
@@ -792,7 +792,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
         /* Then decrease the refcount of the old table */
         if (l2_offset) {
             qcow2_free_clusters(bs, l2_offset, s->l2_size * l2_entry_size(s),
-                                QCOW2_DISCARD_OTHER);
+                                QCOW2_DISCARD_TYPE_OTHER);
         }
 
         /* Get the offset of the newly-allocated l2 table */
@@ -1113,7 +1113,7 @@ int coroutine_fn qcow2_alloc_cluster_link_l2(BlockDriverState *bs,
      */
     if (!m->keep_old_clusters && j != 0) {
         for (i = 0; i < j; i++) {
-            qcow2_free_any_cluster(bs, old_cluster[i], QCOW2_DISCARD_NEVER);
+            qcow2_free_any_cluster(bs, old_cluster[i], QCOW2_DISCARD_TYPE_NEVER);
         }
     }
 
@@ -1133,7 +1133,7 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m)
     if (!has_data_file(bs) && !m->keep_old_clusters) {
         qcow2_free_clusters(bs, m->alloc_offset,
                             m->nb_clusters << s->cluster_bits,
-                            QCOW2_DISCARD_NEVER);
+                            QCOW2_DISCARD_TYPE_NEVER);
     }
 }
 
@@ -2057,7 +2057,7 @@ static int zero_in_l2_slice(BlockDriverState *bs, uint64_t offset,
 
         /* Then decrease the refcount */
         if (unmap) {
-            qcow2_free_any_cluster(bs, old_l2_entry, QCOW2_DISCARD_REQUEST);
+            qcow2_free_any_cluster(bs, old_l2_entry, QCOW2_DISCARD_TYPE_REQUEST);
         }
     }
 
@@ -2144,7 +2144,7 @@ int coroutine_fn qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset,
     if (s->qcow_version < 3) {
         if (!bs->backing) {
             return qcow2_cluster_discard(bs, offset, bytes,
-                                         QCOW2_DISCARD_REQUEST, false);
+                                         QCOW2_DISCARD_TYPE_REQUEST, false);
         }
         return -ENOTSUP;
     }
@@ -2312,10 +2312,10 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
                         ret = qcow2_update_cluster_refcount(
                             bs, offset >> s->cluster_bits,
                             refcount_diff(1, l2_refcount), false,
-                            QCOW2_DISCARD_OTHER);
+                            QCOW2_DISCARD_TYPE_OTHER);
                         if (ret < 0) {
                             qcow2_free_clusters(bs, offset, s->cluster_size,
-                                                QCOW2_DISCARD_OTHER);
+                                                QCOW2_DISCARD_TYPE_OTHER);
                             goto fail;
                         }
                     }
@@ -2331,7 +2331,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
                         l2_offset, l2_index);
                     if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
                         qcow2_free_clusters(bs, offset, s->cluster_size,
-                                            QCOW2_DISCARD_ALWAYS);
+                                            QCOW2_DISCARD_TYPE_ALWAYS);
                     }
                     ret = -EIO;
                     goto fail;
@@ -2342,7 +2342,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
                 if (ret < 0) {
                     if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
                         qcow2_free_clusters(bs, offset, s->cluster_size,
-                                            QCOW2_DISCARD_ALWAYS);
+                                            QCOW2_DISCARD_TYPE_ALWAYS);
                     }
                     goto fail;
                 }
@@ -2352,7 +2352,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
                 if (ret < 0) {
                     if (cluster_type == QCOW2_CLUSTER_ZERO_PLAIN) {
                         qcow2_free_clusters(bs, offset, s->cluster_size,
-                                            QCOW2_DISCARD_ALWAYS);
+                                            QCOW2_DISCARD_TYPE_ALWAYS);
                     }
                     goto fail;
                 }
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index b092f89da9..94f7bf9a57 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -405,7 +405,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
         /* Described somewhere else. This can recurse at most twice before we
          * arrive at a block that describes itself. */
         ret = update_refcount(bs, new_block, s->cluster_size, 1, false,
-                              QCOW2_DISCARD_NEVER);
+                              QCOW2_DISCARD_TYPE_NEVER);
         if (ret < 0) {
             goto fail;
         }
@@ -723,7 +723,7 @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset,
     /* Free old table. */
     qcow2_free_clusters(bs, old_table_offset,
                         old_table_size * REFTABLE_ENTRY_SIZE,
-                        QCOW2_DISCARD_OTHER);
+                        QCOW2_DISCARD_TYPE_OTHER);
 
     return end_offset;
 
@@ -927,7 +927,7 @@ fail:
     if (ret < 0) {
         int dummy;
         dummy = update_refcount(bs, offset, cluster_offset - offset, addend,
-                                !decrease, QCOW2_DISCARD_NEVER);
+                                !decrease, QCOW2_DISCARD_TYPE_NEVER);
         (void)dummy;
     }
 
@@ -1020,7 +1020,7 @@ int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size)
             return offset;
         }
 
-        ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_NEVER);
+        ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_TYPE_NEVER);
     } while (ret == -EAGAIN);
 
     if (ret < 0) {
@@ -1057,7 +1057,7 @@ int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
 
         /* And then allocate them */
         ret = update_refcount(bs, offset, i << s->cluster_bits, 1, false,
-                              QCOW2_DISCARD_NEVER);
+                              QCOW2_DISCARD_TYPE_NEVER);
     } while (ret == -EAGAIN);
 
     if (ret < 0) {
@@ -1122,7 +1122,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
         }
 
         assert(offset);
-        ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_NEVER);
+        ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_TYPE_NEVER);
         if (ret < 0) {
             offset = 0;
         }
@@ -1331,7 +1331,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
                             ret = update_refcount(
                                 bs, coffset, csize,
                                 abs(addend), addend < 0,
-                                QCOW2_DISCARD_SNAPSHOT);
+                                QCOW2_DISCARD_TYPE_SNAPSHOT);
                             if (ret < 0) {
                                 goto fail;
                             }
@@ -1360,7 +1360,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
                         if (addend != 0) {
                             ret = qcow2_update_cluster_refcount(
                                 bs, cluster_index, abs(addend), addend < 0,
-                                QCOW2_DISCARD_SNAPSHOT);
+                                QCOW2_DISCARD_TYPE_SNAPSHOT);
                             if (ret < 0) {
                                 goto fail;
                             }
@@ -1402,7 +1402,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
                 ret = qcow2_update_cluster_refcount(bs, l2_offset >>
                                                         s->cluster_bits,
                                                     abs(addend), addend < 0,
-                                                    QCOW2_DISCARD_SNAPSHOT);
+                                                    QCOW2_DISCARD_TYPE_SNAPSHOT);
                 if (ret < 0) {
                     goto fail;
                 }
@@ -2346,7 +2346,7 @@ static void compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
                 ret = update_refcount(bs, i << s->cluster_bits, 1,
                                       refcount_diff(refcount1, refcount2),
                                       refcount1 > refcount2,
-                                      QCOW2_DISCARD_ALWAYS);
+                                      QCOW2_DISCARD_TYPE_ALWAYS);
                 if (ret >= 0) {
                     (*num_fixed)++;
                     continue;
@@ -3412,7 +3412,7 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
                 qcow2_free_clusters(
                     bs, new_reftable_offset,
                     allocated_reftable_size * REFTABLE_ENTRY_SIZE,
-                    QCOW2_DISCARD_NEVER);
+                    QCOW2_DISCARD_TYPE_NEVER);
             }
 
             new_reftable_offset = qcow2_alloc_clusters(bs, new_reftable_size *
@@ -3525,7 +3525,7 @@ done:
             uint64_t offset = new_reftable[i] & REFT_OFFSET_MASK;
             if (offset) {
                 qcow2_free_clusters(bs, offset, s->cluster_size,
-                                    QCOW2_DISCARD_OTHER);
+                                    QCOW2_DISCARD_TYPE_OTHER);
             }
         }
         g_free(new_reftable);
@@ -3533,7 +3533,7 @@ done:
         if (new_reftable_offset > 0) {
             qcow2_free_clusters(bs, new_reftable_offset,
                                 new_reftable_size * REFTABLE_ENTRY_SIZE,
-                                QCOW2_DISCARD_OTHER);
+                                QCOW2_DISCARD_TYPE_OTHER);
         }
     }
 
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 62e8a0335d..2fe43ac7bc 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -413,7 +413,7 @@ int qcow2_write_snapshots(BlockDriverState *bs)
 
     /* free the old snapshot table */
     qcow2_free_clusters(bs, s->snapshots_offset, s->snapshots_size,
-                        QCOW2_DISCARD_SNAPSHOT);
+                        QCOW2_DISCARD_TYPE_SNAPSHOT);
     s->snapshots_offset = snapshots_offset;
     s->snapshots_size = snapshots_size;
     return 0;
@@ -421,7 +421,7 @@ int qcow2_write_snapshots(BlockDriverState *bs)
 fail:
     if (snapshots_offset > 0) {
         qcow2_free_clusters(bs, snapshots_offset, snapshots_size,
-                            QCOW2_DISCARD_ALWAYS);
+                            QCOW2_DISCARD_TYPE_ALWAYS);
     }
     return ret;
 }
@@ -737,7 +737,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
      * hurts by causing expensive COW for the next snapshot. */
     qcow2_cluster_discard(bs, qcow2_vm_state_offset(s),
                           ROUND_UP(sn->vm_state_size, s->cluster_size),
-                          QCOW2_DISCARD_NEVER, false);
+                          QCOW2_DISCARD_TYPE_NEVER, false);
 
 #ifdef DEBUG_ALLOC
     {
@@ -964,7 +964,7 @@ int qcow2_snapshot_delete(BlockDriverState *bs,
         return ret;
     }
     qcow2_free_clusters(bs, sn.l1_table_offset, sn.l1_size * L1E_SIZE,
-                        QCOW2_DISCARD_SNAPSHOT);
+                        QCOW2_DISCARD_TYPE_SNAPSHOT);
 
     /* must update the copied flag on the current cluster offsets */
     ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0);
diff --git a/block/qcow2.c b/block/qcow2.c
index ee0e5b45cc..6ffe1ba803 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -967,7 +967,7 @@ typedef struct Qcow2ReopenState {
     int l2_slice_size; /* Number of entries in a slice of the L2 table */
     bool use_lazy_refcounts;
     int overlap_check;
-    bool discard_passthrough[QCOW2_DISCARD_MAX];
+    bool discard_passthrough[QCOW2_DISCARD_TYPE__MAX];
     uint64_t cache_clean_interval;
     QCryptoBlockOpenOptions *crypto_opts; /* Disk encryption runtime options */
 } Qcow2ReopenState;
@@ -1129,14 +1129,14 @@ static int qcow2_update_options_prepare(BlockDriverState *bs,
                               overlap_check_template & (1 << i)) << i;
     }
 
-    r->discard_passthrough[QCOW2_DISCARD_NEVER] = false;
-    r->discard_passthrough[QCOW2_DISCARD_ALWAYS] = true;
-    r->discard_passthrough[QCOW2_DISCARD_REQUEST] =
+    r->discard_passthrough[QCOW2_DISCARD_TYPE_NEVER] = false;
+    r->discard_passthrough[QCOW2_DISCARD_TYPE_ALWAYS] = true;
+    r->discard_passthrough[QCOW2_DISCARD_TYPE_REQUEST] =
         qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_REQUEST,
                           flags & BDRV_O_UNMAP);
-    r->discard_passthrough[QCOW2_DISCARD_SNAPSHOT] =
+    r->discard_passthrough[QCOW2_DISCARD_TYPE_SNAPSHOT] =
         qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_SNAPSHOT, true);
-    r->discard_passthrough[QCOW2_DISCARD_OTHER] =
+    r->discard_passthrough[QCOW2_DISCARD_TYPE_OTHER] =
         qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_OTHER, false);
 
     switch (s->crypt_method_header) {
@@ -1215,7 +1215,7 @@ static void qcow2_update_options_commit(BlockDriverState *bs,
     s->overlap_check = r->overlap_check;
     s->use_lazy_refcounts = r->use_lazy_refcounts;
 
-    for (i = 0; i < QCOW2_DISCARD_MAX; i++) {
+    for (i = 0; i < QCOW2_DISCARD_TYPE__MAX; i++) {
         s->discard_passthrough[i] = r->discard_passthrough[i];
     }
 
@@ -4052,7 +4052,7 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriverState *bs,
     }
 
     qemu_co_mutex_lock(&s->lock);
-    ret = qcow2_cluster_discard(bs, offset, bytes, QCOW2_DISCARD_REQUEST,
+    ret = qcow2_cluster_discard(bs, offset, bytes, QCOW2_DISCARD_TYPE_REQUEST,
                                 false);
     qemu_co_mutex_unlock(&s->lock);
     return ret;
@@ -4266,7 +4266,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
         ret = qcow2_cluster_discard(bs, ROUND_UP(offset, s->cluster_size),
                                     old_length - ROUND_UP(offset,
                                                           s->cluster_size),
-                                    QCOW2_DISCARD_ALWAYS, true);
+                                    QCOW2_DISCARD_TYPE_ALWAYS, true);
         if (ret < 0) {
             error_setg_errno(errp, -ret, "Failed to discard cropped clusters");
             goto fail;
@@ -4463,7 +4463,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
             error_prepend(errp, "Failed to resize underlying file: ");
             qcow2_free_clusters(bs, allocation_start,
                                 nb_new_data_clusters * s->cluster_size,
-                                QCOW2_DISCARD_OTHER);
+                                QCOW2_DISCARD_TYPE_OTHER);
             goto fail;
         }
 
@@ -4498,7 +4498,7 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
                 error_setg_errno(errp, -ret, "Failed to update L2 tables");
                 qcow2_free_clusters(bs, host_offset,
                                     nb_new_data_clusters * s->cluster_size,
-                                    QCOW2_DISCARD_OTHER);
+                                    QCOW2_DISCARD_TYPE_OTHER);
                 goto fail;
             }
 
@@ -4950,12 +4950,12 @@ static int qcow2_make_empty(BlockDriverState *bs)
     end_offset = bs->total_sectors * BDRV_SECTOR_SIZE;
     for (offset = 0; offset < end_offset; offset += step) {
         /* As this function is generally used after committing an external
-         * snapshot, QCOW2_DISCARD_SNAPSHOT seems appropriate. Also, the
+         * snapshot, QCOW2_DISCARD_TYPE_SNAPSHOT seems appropriate. Also, the
          * default action for this kind of discard is to pass the discard,
          * which will ideally result in an actually smaller image file, as
          * is probably desired. */
         ret = qcow2_cluster_discard(bs, offset, MIN(step, end_offset - offset),
-                                    QCOW2_DISCARD_SNAPSHOT, true);
+                                    QCOW2_DISCARD_TYPE_SNAPSHOT, true);
         if (ret < 0) {
             break;
         }
diff --git a/block/qcow2.h b/block/qcow2.h
index 2285f18a73..d6ce7fce32 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -288,12 +288,12 @@ enum {
 };
 
 enum qcow2_discard_type {
-    QCOW2_DISCARD_NEVER = 0,
-    QCOW2_DISCARD_ALWAYS,
-    QCOW2_DISCARD_REQUEST,
-    QCOW2_DISCARD_SNAPSHOT,
-    QCOW2_DISCARD_OTHER,
-    QCOW2_DISCARD_MAX
+    QCOW2_DISCARD_TYPE_NEVER = 0,
+    QCOW2_DISCARD_TYPE_ALWAYS,
+    QCOW2_DISCARD_TYPE_REQUEST,
+    QCOW2_DISCARD_TYPE_SNAPSHOT,
+    QCOW2_DISCARD_TYPE_OTHER,
+    QCOW2_DISCARD_TYPE__MAX
 };
 
 typedef struct Qcow2Feature {
@@ -383,7 +383,7 @@ typedef struct BDRVQcow2State {
     Qcow2GetRefcountFunc *get_refcount;
     Qcow2SetRefcountFunc *set_refcount;
 
-    bool discard_passthrough[QCOW2_DISCARD_MAX];
+    bool discard_passthrough[QCOW2_DISCARD_TYPE__MAX];
 
     int overlap_check; /* bitmask of Qcow2MetadataOverlap values */
     bool signaled_corruption;
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] block/qcow2: QAPI'fy Qcow2DiscardType
  2023-02-24 15:20 [PATCH 0/2] block/qcow2: QAPI'fy Qcow2DiscardType Philippe Mathieu-Daudé
  2023-02-24 15:20 ` [PATCH 1/2] block/qcow2: Rename QCOW2_DISCARD_TYPE enum definitions Philippe Mathieu-Daudé
@ 2023-02-24 15:20 ` Philippe Mathieu-Daudé
  2023-02-24 21:26 ` [PATCH 0/2] " Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-24 15:20 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-block, Hanna Reitz, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
	Markus Armbruster, Eric Blake, John Snow,
	Philippe Mathieu-Daudé

Let QAPI maintain the Qcow2DiscardType enum values.

Mechanical renaming to Qcow2DiscardType doing:

  $ sed -i -e 's/enum qcow2_discard_type/Qcow2DiscardType/g' \
        $(git grep -l qcow2_discard_type)

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 block/qcow2-cluster.c  |  4 ++--
 block/qcow2-refcount.c | 10 +++++-----
 block/qcow2.h          | 17 ++++-------------
 qapi/block-core.json   | 10 ++++++++++
 4 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index a525afc7c3..8e25eec98a 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1898,7 +1898,7 @@ again:
  */
 static int discard_in_l2_slice(BlockDriverState *bs, uint64_t offset,
                                uint64_t nb_clusters,
-                               enum qcow2_discard_type type, bool full_discard)
+                               Qcow2DiscardType type, bool full_discard)
 {
     BDRVQcow2State *s = bs->opaque;
     uint64_t *l2_slice;
@@ -1967,7 +1967,7 @@ static int discard_in_l2_slice(BlockDriverState *bs, uint64_t offset,
 }
 
 int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
-                          uint64_t bytes, enum qcow2_discard_type type,
+                          uint64_t bytes, Qcow2DiscardType type,
                           bool full_discard)
 {
     BDRVQcow2State *s = bs->opaque;
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 94f7bf9a57..cb72c7e213 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -38,7 +38,7 @@ static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size,
 G_GNUC_WARN_UNUSED_RESULT
 static int update_refcount(BlockDriverState *bs,
                            int64_t offset, int64_t length, uint64_t addend,
-                           bool decrease, enum qcow2_discard_type type);
+                           bool decrease, Qcow2DiscardType type);
 
 static uint64_t get_refcount_ro0(const void *refcount_array, uint64_t index);
 static uint64_t get_refcount_ro1(const void *refcount_array, uint64_t index);
@@ -811,7 +811,7 @@ static int update_refcount(BlockDriverState *bs,
                            int64_t length,
                            uint64_t addend,
                            bool decrease,
-                           enum qcow2_discard_type type)
+                           Qcow2DiscardType type)
 {
     BDRVQcow2State *s = bs->opaque;
     int64_t start, last, cluster_offset;
@@ -945,7 +945,7 @@ fail:
 int qcow2_update_cluster_refcount(BlockDriverState *bs,
                                   int64_t cluster_index,
                                   uint64_t addend, bool decrease,
-                                  enum qcow2_discard_type type)
+                                  Qcow2DiscardType type)
 {
     BDRVQcow2State *s = bs->opaque;
     int ret;
@@ -1145,7 +1145,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
 
 void qcow2_free_clusters(BlockDriverState *bs,
                           int64_t offset, int64_t size,
-                          enum qcow2_discard_type type)
+                          Qcow2DiscardType type)
 {
     int ret;
 
@@ -1162,7 +1162,7 @@ void qcow2_free_clusters(BlockDriverState *bs,
  * normal cluster, compressed cluster, etc.)
  */
 void qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry,
-                            enum qcow2_discard_type type)
+                            Qcow2DiscardType type)
 {
     BDRVQcow2State *s = bs->opaque;
     QCow2ClusterType ctype = qcow2_get_cluster_type(bs, l2_entry);
diff --git a/block/qcow2.h b/block/qcow2.h
index d6ce7fce32..280485ed12 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -287,15 +287,6 @@ enum {
                                         | QCOW2_AUTOCLEAR_DATA_FILE_RAW,
 };
 
-enum qcow2_discard_type {
-    QCOW2_DISCARD_TYPE_NEVER = 0,
-    QCOW2_DISCARD_TYPE_ALWAYS,
-    QCOW2_DISCARD_TYPE_REQUEST,
-    QCOW2_DISCARD_TYPE_SNAPSHOT,
-    QCOW2_DISCARD_TYPE_OTHER,
-    QCOW2_DISCARD_TYPE__MAX
-};
-
 typedef struct Qcow2Feature {
     uint8_t type;
     uint8_t bit;
@@ -854,7 +845,7 @@ int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
 
 int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
                                   uint64_t addend, bool decrease,
-                                  enum qcow2_discard_type type);
+                                  Qcow2DiscardType type);
 
 int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t offset,
                             uint64_t additional_clusters, bool exact_size,
@@ -867,9 +858,9 @@ int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
 int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
 void qcow2_free_clusters(BlockDriverState *bs,
                           int64_t offset, int64_t size,
-                          enum qcow2_discard_type type);
+                          Qcow2DiscardType type);
 void qcow2_free_any_cluster(BlockDriverState *bs, uint64_t l2_entry,
-                            enum qcow2_discard_type type);
+                            Qcow2DiscardType type);
 
 int qcow2_update_snapshot_refcount(BlockDriverState *bs,
     int64_t l1_table_offset, int l1_size, int addend);
@@ -922,7 +913,7 @@ int coroutine_fn qcow2_alloc_cluster_link_l2(BlockDriverState *bs,
                                              QCowL2Meta *m);
 void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m);
 int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset,
-                          uint64_t bytes, enum qcow2_discard_type type,
+                          uint64_t bytes, Qcow2DiscardType type,
                           bool full_discard);
 int coroutine_fn qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset,
                                           uint64_t bytes, int flags);
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 7f331eb8ea..8d80e989b5 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -4811,6 +4811,16 @@
 { 'enum': 'Qcow2CompressionType',
   'data': [ 'zlib', { 'name': 'zstd', 'if': 'CONFIG_ZSTD' } ] }
 
+##
+# @Qcow2DiscardType:
+#
+# Determines type of discard request
+#
+# Since: 8.0
+##
+{ 'enum': 'Qcow2DiscardType',
+  'data': [ 'never', 'always', 'request', 'snapshot', 'other' ] }
+
 ##
 # @BlockdevCreateOptionsQcow2:
 #
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] block/qcow2: QAPI'fy Qcow2DiscardType
  2023-02-24 15:20 [PATCH 0/2] block/qcow2: QAPI'fy Qcow2DiscardType Philippe Mathieu-Daudé
  2023-02-24 15:20 ` [PATCH 1/2] block/qcow2: Rename QCOW2_DISCARD_TYPE enum definitions Philippe Mathieu-Daudé
  2023-02-24 15:20 ` [PATCH 2/2] block/qcow2: QAPI'fy Qcow2DiscardType Philippe Mathieu-Daudé
@ 2023-02-24 21:26 ` Richard Henderson
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2023-02-24 21:26 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-block, Hanna Reitz, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
	Markus Armbruster, Eric Blake, John Snow

On 2/24/23 05:20, Philippe Mathieu-Daudé wrote:
> QAPI seems designed to maintain such enums,
> so convert Qcow2DiscardType to be QAPI generated.
> Besides, this is how Qcow2CompressionType is maintained.
> 
> Philippe Mathieu-Daudé (2):
>    block/qcow2: Rename QCOW2_DISCARD_TYPE enum definitions
>    block/qcow2: QAPI'fy Qcow2DiscardType

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-24 21:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-24 15:20 [PATCH 0/2] block/qcow2: QAPI'fy Qcow2DiscardType Philippe Mathieu-Daudé
2023-02-24 15:20 ` [PATCH 1/2] block/qcow2: Rename QCOW2_DISCARD_TYPE enum definitions Philippe Mathieu-Daudé
2023-02-24 15:20 ` [PATCH 2/2] block/qcow2: QAPI'fy Qcow2DiscardType Philippe Mathieu-Daudé
2023-02-24 21:26 ` [PATCH 0/2] " Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).