qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, armbru@redhat.com,
	eblake@redhat.com, jsnow@redhat.com, famz@redhat.com,
	den@openvz.org, stefanha@redhat.com, vsementsov@virtuozzo.com,
	pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH 25/25] qcow2-bitmap: improve check_constraints_on_bitmap
Date: Tue, 14 Feb 2017 19:59:39 +0300	[thread overview]
Message-ID: <1487091579-67092-26-git-send-email-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <1487091579-67092-1-git-send-email-vsementsov@virtuozzo.com>

Add detailed error messages.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block/qcow2-bitmap.c | 63 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 7ad1f7c..113d48c 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -160,28 +160,49 @@ static int check_table_entry(uint64_t entry, int cluster_size)
 
 static int check_constraints_on_bitmap(BlockDriverState *bs,
                                        const char *name,
-                                       uint32_t granularity)
+                                       uint32_t granularity,
+                                       Error **errp)
 {
     BDRVQcow2State *s = bs->opaque;
     int granularity_bits = ctz32(granularity);
     int64_t len = bdrv_getlength(bs);
-    bool fail;
 
     assert(granularity > 0);
     assert((granularity & (granularity - 1)) == 0);
 
     if (len < 0) {
+        error_setg_errno(errp, -len, "Failed to get size of '%s'",
+                         bdrv_get_device_or_node_name(bs));
         return len;
     }
 
-    fail = (granularity_bits > BME_MAX_GRANULARITY_BITS) ||
-           (granularity_bits < BME_MIN_GRANULARITY_BITS) ||
-           (len > (uint64_t)BME_MAX_PHYS_SIZE << granularity_bits) ||
-           (len > (uint64_t)BME_MAX_TABLE_SIZE * s->cluster_size <<
-                  granularity_bits) ||
-           (strlen(name) > BME_MAX_NAME_SIZE);
+    if (granularity_bits > BME_MAX_GRANULARITY_BITS) {
+        error_setg(errp, "Granularity exceeds maximum (%u bytes)",
+                   1 << BME_MAX_GRANULARITY_BITS);
+        return -EINVAL;
+    }
+    if (granularity_bits < BME_MIN_GRANULARITY_BITS) {
+        error_setg(errp, "Granularity is under minimum (%u bytes)",
+                   1 << BME_MIN_GRANULARITY_BITS);
+        return -EINVAL;
+    }
 
-    return fail ? -EINVAL : 0;
+    if ((len > (uint64_t)BME_MAX_PHYS_SIZE << granularity_bits) ||
+        (len > (uint64_t)BME_MAX_TABLE_SIZE * s->cluster_size <<
+               granularity_bits))
+    {
+        error_setg(errp, "Too much space will be occupied by the bitmap. "
+                   "Use larger granularity");
+        return -EINVAL;
+    }
+
+    if (strlen(name) > BME_MAX_NAME_SIZE) {
+        error_setg(errp, "Name length exceeds maximum (%u characters)",
+                   BME_MAX_NAME_SIZE);
+        return -EINVAL;
+    }
+
+    return 0;
 }
 
 static void clear_bitmap_table(BlockDriverState *bs, uint64_t *bitmap_table,
@@ -1142,9 +1163,9 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp)
             continue;
         }
 
-        if (check_constraints_on_bitmap(bs, name, granularity) < 0) {
-            error_setg(errp, "Bitmap '%s' doesn't satisfy the constraints",
-                       name);
+        if (check_constraints_on_bitmap(bs, name, granularity, errp) < 0) {
+            error_prepend(errp, "Bitmap '%s' doesn't satisfy the constraints: ",
+                          name);
             goto fail;
         }
 
@@ -1230,13 +1251,11 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs,
                                       Error **errp)
 {
     BDRVQcow2State *s = bs->opaque;
-    const char *reason = NULL;
     bool found;
     Qcow2BitmapList *bm_list;
 
-    if (check_constraints_on_bitmap(bs, name, granularity) != 0) {
-        reason = "it doesn't satisfy the constraints";
-        goto common_errp;
+    if (check_constraints_on_bitmap(bs, name, granularity, errp) != 0) {
+        goto fail;
     }
 
     if (s->nb_bitmaps == 0) {
@@ -1246,21 +1265,21 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs,
     bm_list = bitmap_list_load(bs, s->bitmap_directory_offset,
                                s->bitmap_directory_size, errp);
     if (bm_list == NULL) {
-        return false;
+        goto fail;
     }
 
     found = find_bitmap_by_name(bm_list, name);
     bitmap_list_free(bm_list);
     if (found) {
-        reason = "bitmap with the same name is already stored";
-        goto common_errp;
+        error_setg(errp, "Bitmap with the same name is already stored");
+        goto fail;
     }
 
     return true;
 
-common_errp:
-    error_setg(errp, "Can't make bitmap '%s' persistent in '%s', as %s.",
-               name, bdrv_get_device_or_node_name(bs), reason);
+fail:
+    error_prepend(errp, "Can't make bitmap '%s' persistent in '%s': ",
+                  name, bdrv_get_device_or_node_name(bs));
     return false;
 }
 
-- 
1.8.3.1

  parent reply	other threads:[~2017-02-14 16:59 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14 16:59 [Qemu-devel] [PATCH v14 00/24] qcow2: persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 01/25] specs/qcow2: fix bitmap granularity qemu-specific note Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 02/25] specs/qcow2: do not use wording 'bitmap header' Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 03/25] hbitmap: improve dirty iter Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 04/25] tests: add hbitmap iter test Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 05/25] block: fix bdrv_dirty_bitmap_granularity signature Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 06/25] block/dirty-bitmap: add deserialize_ones func Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 07/25] qcow2: add bitmaps extension Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 08/25] block: introduce auto-loading bitmaps Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 09/25] qcow2: add .bdrv_load_autoloading_dirty_bitmaps Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 10/25] block/dirty-bitmap: add autoload field to BdrvDirtyBitmap Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 11/25] block: introduce persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 12/25] block/dirty-bitmap: add bdrv_dirty_bitmap_next() Vladimir Sementsov-Ogievskiy
2017-02-14 16:59 ` [Qemu-devel] [PATCH 13/25] qcow2: add .bdrv_store_persistent_dirty_bitmaps() Vladimir Sementsov-Ogievskiy
2017-02-14 19:22   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 14/25] block: add bdrv_can_store_new_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-02-14 21:27   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 15/25] qcow2: add .bdrv_can_store_new_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-02-14 22:07   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 16/25] qmp: add persistent flag to block-dirty-bitmap-add Vladimir Sementsov-Ogievskiy
2017-02-14 22:37   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 17/25] qmp: add autoload parameter " Vladimir Sementsov-Ogievskiy
2017-02-14 22:43   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 18/25] qmp: add x-debug-block-dirty-bitmap-sha256 Vladimir Sementsov-Ogievskiy
2017-02-14 22:46   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 19/25] iotests: test qcow2 persistent dirty bitmap Vladimir Sementsov-Ogievskiy
2017-02-14 23:01   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 20/25] qcow2-refcount: rename inc_refcounts() and make it public Vladimir Sementsov-Ogievskiy
2017-02-14 23:08   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 21/25] qcow2-bitmap: refcounts Vladimir Sementsov-Ogievskiy
2017-02-14 23:22   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 22/25] block/dirty-bitmap: add bdrv_remove_persistent_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-02-14 23:43   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 23/25] qcow2: add .bdrv_remove_persistent_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-02-15  0:19   ` John Snow
2017-02-14 16:59 ` [Qemu-devel] [PATCH 24/25] qmp: block-dirty-bitmap-remove: remove persistent Vladimir Sementsov-Ogievskiy
2017-02-15  0:29   ` John Snow
2017-02-14 16:59 ` Vladimir Sementsov-Ogievskiy [this message]
2017-02-15  0:35   ` [Qemu-devel] [PATCH 25/25] qcow2-bitmap: improve check_constraints_on_bitmap John Snow
2017-02-14 19:02 ` [Qemu-devel] [PATCH v14 00/24] qcow2: persistent dirty bitmaps John Snow
2017-02-14 21:44   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1487091579-67092-26-git-send-email-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).