qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Eric Blake <eblake@redhat.com>, qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/7] block: Add Error parameter to bdrv_amend_options
Date: Wed, 2 May 2018 20:08:59 +0200	[thread overview]
Message-ID: <496ae9da-458d-1308-48ae-17326586b670@redhat.com> (raw)
In-Reply-To: <c1b70360-a112-2d7c-33df-0ed5ec0ec3f9@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 5286 bytes --]

On 2018-05-02 19:52, Eric Blake wrote:
> On 04/21/2018 11:54 AM, Max Reitz wrote:
>> Looking at the qcow2 code that is riddled with error_report() calls,
>> this is really how it should have been from the start.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
> 
>> +++ b/block/qcow2.c
>> @@ -4049,7 +4049,8 @@ static int qcow2_load_vmstate(BlockDriverState
>> *bs, QEMUIOVector *qiov,
>>    * have to be removed.
>>    */
>>   static int qcow2_downgrade(BlockDriverState *bs, int target_version,
>> -                           BlockDriverAmendStatusCB *status_cb, void
>> *cb_opaque)
>> +                           BlockDriverAmendStatusCB *status_cb, void
>> *cb_opaque,
>> +                           Error **errp)
>>   {
>>       BDRVQcow2State *s = bs->opaque;
>>       int current_version = s->qcow_version;
>> @@ -4058,13 +4059,17 @@ static int qcow2_downgrade(BlockDriverState
>> *bs, int target_version,
>>       if (target_version == current_version) {
>>           return 0;
>>       } else if (target_version > current_version) {
>> +        error_setg(errp, "Cannot downgrade an image from version %i
>> to %i",
> 
> %i is unusual compared to %d, but as they do the same, I won't make you
> change it, if we keep it.  That said, this function is static; and the
> lone caller qcow2_amend_options is already doing sanity checks, right?
> (Yes - it does qemu_opt_get(opts, BLOCK_OPT_COMPAT_LEVEL), and then
> validates that the user's information is in range, which already filters
> out everything but v2 and v3; then _this_ function is called exactly for
> 3 downto 2).  So this should be an assert() instead of an error message.

OK, I'll change it to an assertion.

>> +                   current_version, target_version);
>>           return -EINVAL;
>>       } else if (target_version != 2) {
>> +        error_setg(errp, "Cannot downgrade an image to version %i
>> (only "
>> +                   "target version 2 is supported)", target_version);
> 
> And again.
> 
>> @@ -4072,6 +4077,8 @@ static int qcow2_downgrade(BlockDriverState *bs,
>> int target_version,
>>       if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) {
>>           ret = qcow2_mark_clean(bs);
>>           if (ret < 0) {
>> +            error_setg(errp, "Failed to make the image clean: %s",
>> +                       strerror(-ret));
> 
> error_setg_errno(), please.

Right, forgot we had that...

>> @@ -4094,6 +4103,8 @@ static int qcow2_downgrade(BlockDriverState *bs,
>> int target_version,
>>         ret = qcow2_expand_zero_clusters(bs, status_cb, cb_opaque);
>>       if (ret < 0) {
>> +        error_setg(errp, "Failed to turn zero into data clusters: %s",
>> +                   strerror(-ret));
> 
> and again
> 
>>           return ret;
>>       }
>>   @@ -4101,6 +4112,8 @@ static int qcow2_downgrade(BlockDriverState
>> *bs, int target_version,
>>       ret = qcow2_update_header(bs);
>>       if (ret < 0) {
>>           s->qcow_version = current_version;
>> +        error_setg(errp, "Failed to update the image header: %s",
>> +                   strerror(-ret));
> 
> etc.  I'll quit pointing it out, but there are more.
> 
>> @@ -4293,18 +4311,17 @@ static int
>> qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts,
>>           int refcount_order = ctz32(refcount_bits);
>>             if (new_version < 3 && refcount_bits != 16) {
>> -            error_report("Different refcount widths than 16 bits
>> require "
>> -                         "compatibility level 1.1 or above (use
>> compat=1.1 or "
>> -                         "greater)");
>> +            error_setg(errp, "Different refcount widths than 16 bits
>> require "
>> +                       "compatibility level 1.1 or above (use
>> compat=1.1 or "
>> +                       "greater)");
> 
> Not your fault, but that reads poorly.  Better would be:
> 
> Refcount widths other than 16 bits require compatibility level 1.1 or above

Sure it's my fault, I wrote this in the first place. :-)

Max

>> +++ b/qemu-img.c
>> @@ -3730,10 +3730,10 @@ static int img_amend(int argc, char **argv)
>>         /* In case the driver does not call amend_status_cb() */
>>       qemu_progress_print(0.f, 0);
>> -    ret = bdrv_amend_options(bs, opts, &amend_status_cb, NULL);
>> +    ret = bdrv_amend_options(bs, opts, &amend_status_cb, NULL, &err);
>>       qemu_progress_print(100.f, 0);
>>       if (ret < 0) {
>> -        error_report("Error while amending options: %s",
>> strerror(-ret));
>> +        error_report_err(err);
> 
> Definitely nicer, but does change various outputs; glad you fixed
> iotests to match.
> 
> Overall a nice patch, looking forward to v2.
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2018-05-02 18:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-21 16:54 [Qemu-devel] [PATCH 0/7] qemu-img: Improve option help for amend Max Reitz
2018-04-21 16:54 ` [Qemu-devel] [PATCH 1/7] qemu-img: Amendment support implies create_opts Max Reitz
2018-05-02 17:35   ` Eric Blake
2018-04-21 16:54 ` [Qemu-devel] [PATCH 2/7] block: Add Error parameter to bdrv_amend_options Max Reitz
2018-05-01 22:49   ` [Qemu-devel] [Qemu-block] " John Snow
2018-05-02 17:52   ` [Qemu-devel] " Eric Blake
2018-05-02 18:08     ` Max Reitz [this message]
2018-04-21 16:54 ` [Qemu-devel] [PATCH 3/7] qemu-option: Pull out "Supported options" print Max Reitz
2018-05-02 18:09   ` Eric Blake
2018-04-21 16:54 ` [Qemu-devel] [PATCH 4/7] qemu-img: Add print_amend_option_help() Max Reitz
2018-05-02 18:13   ` Eric Blake
2018-04-21 16:54 ` [Qemu-devel] [PATCH 5/7] qemu-img: Recognize no creation support in -o help Max Reitz
2018-05-02 17:40   ` [Qemu-devel] [Qemu-block] " John Snow
2018-05-02 18:15   ` [Qemu-devel] " Eric Blake
2018-04-21 16:54 ` [Qemu-devel] [PATCH 6/7] iotests: Test help option for unsupporting formats Max Reitz
2018-05-02 18:00   ` [Qemu-devel] [Qemu-block] " John Snow
2018-05-02 18:17   ` [Qemu-devel] " Eric Blake
2018-04-21 16:54 ` [Qemu-devel] [PATCH 7/7] iotests: Rework 113 Max Reitz
2018-05-02 18:03   ` [Qemu-devel] [Qemu-block] " John Snow
2018-05-02 18:13     ` Max Reitz
2018-05-02 18:18       ` John Snow
2018-05-02 18:48         ` Max Reitz
2018-05-02 18:24   ` [Qemu-devel] " Eric Blake
2018-05-02 18:35     ` Max Reitz

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=496ae9da-458d-1308-48ae-17326586b670@redhat.com \
    --to=mreitz@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).