qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: phrdina@redhat.com, famz@redhat.com, armbru@redhat.com,
	qemu-devel@nongnu.org, lcapitulino@redhat.com,
	stefanha@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com
Subject: Re: [Qemu-devel] [PATCH V5 2/8] snapshot: distinguish id and name in snapshot delete
Date: Fri, 19 Jul 2013 17:13:00 +0800	[thread overview]
Message-ID: <51E9031C.2010609@linux.vnet.ibm.com> (raw)
In-Reply-To: <20130718114839.GI3582@dhcp-200-207.str.redhat.com>

于 2013-7-18 19:48, Kevin Wolf 写道:
> Am 11.07.2013 um 07:46 hat Wenchao Xia geschrieben:
>> Snapshot creation actually already distinguish id and name since it take
>> a structured parameter *sn, but delete can't. Later an accurate delete
>> is needed in qmp_transaction abort and blockdev-snapshot-delete-sync,
>> so change its prototype. Also *errp is added to tip error, but return
>> value is kepted to let caller check what kind of error happens. Existing
>> caller for it are savevm, delvm and qemu-img, they are not impacted by
>> check the return value and do the operations again.
>>
>> Before this patch:
>>    For qcow2, it search id first then name to find the one to delete.
>>    For rbd, it search name.
>>    For sheepdog, it does nothing.
>>
>> After this patch:
>>    For qcow2, logic is the same by call it twice in caller.
>>    For rbd, it always fails in delete with id, but still search for name
>> in second try, no change for user.
>>
>> Some code for *errp is based on Pavel's patch.
>>
>> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
>> ---
>>   block/qcow2-snapshot.c    |   66 ++++++++++++++++++++++++++++++++++-----------
>>   block/qcow2.h             |    5 +++-
>>   block/rbd.c               |   23 +++++++++++++++-
>>   block/sheepdog.c          |    5 +++-
>>   block/snapshot.c          |   36 ++++++++++++++++++++++--
>>   include/block/block_int.h |    5 +++-
>>   include/block/snapshot.h  |    5 +++-
>>   include/qemu-common.h     |    3 ++
>>   qemu-img.c                |    5 +++-
>>   savevm.c                  |   10 +++++-
>>   10 files changed, 136 insertions(+), 27 deletions(-)
>
>> @@ -531,15 +547,23 @@ fail:
>>       return ret;
>>   }
>>
>> -int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
>> +int qcow2_snapshot_delete(BlockDriverState *bs,
>> +                          const char *snapshot_id,
>> +                          const char *name,
>> +                          Error **errp)
>>   {
>>       BDRVQcowState *s = bs->opaque;
>>       QCowSnapshot sn;
>>       int snapshot_index, ret;
>> +    const char *device = bdrv_get_device_name(bs);
>>
>>       /* Search the snapshot */
>> -    snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id);
>> +    snapshot_index = find_snapshot_by_id_and_name(bs, snapshot_id, name);
>>       if (snapshot_index < 0) {
>> +        error_setg(errp,
>> +                   "Can't find a snapshot with ID '%s' and name '%s' "
>> +                   "on device '%s'",
>> +                   STR_PRINT_CHAR(snapshot_id), STR_PRINT_CHAR(name), device);
>
> At least the "on device '%s'" part should be removed from the error
> messages. It is something the caller can add if there is any ambiguity.
>
   will remove.

>> --- a/qemu-img.c
>> +++ b/qemu-img.c
>> @@ -1883,7 +1883,10 @@ static int img_snapshot(int argc, char **argv)
>>           break;
>>
>>       case SNAPSHOT_DELETE:
>> -        ret = bdrv_snapshot_delete(bs, snapshot_name);
>> +        ret = bdrv_snapshot_delete(bs, snapshot_name, NULL, NULL);
>> +        if (ret == -ENOENT || ret == -EINVAL) {
>> +            ret = bdrv_snapshot_delete(bs, NULL, snapshot_name, NULL);
>> +        }
>>           if (ret) {
>>               error_report("Could not delete snapshot '%s': %d (%s)",
>>                   snapshot_name, ret, strerror(-ret));
>
> Why don't you use the new error messages?
>
>> diff --git a/savevm.c b/savevm.c
>> index e0491e7..56afebb 100644
>> --- a/savevm.c
>> +++ b/savevm.c
>> @@ -2332,7 +2332,10 @@ static int del_existing_snapshots(Monitor *mon, const char *name)
>>           if (bdrv_can_snapshot(bs) &&
>>               bdrv_snapshot_find(bs, snapshot, name) >= 0)
>>           {
>> -            ret = bdrv_snapshot_delete(bs, name);
>> +            ret = bdrv_snapshot_delete(bs, name, NULL, NULL);
>> +            if (ret == -ENOENT || ret == -EINVAL) {
>> +                ret = bdrv_snapshot_delete(bs, NULL, name, NULL);
>> +            }
>>               if (ret < 0) {
>>                   monitor_printf(mon,
>>                                  "Error while deleting snapshot on '%s'\n",
>> @@ -2562,7 +2565,10 @@ void do_delvm(Monitor *mon, const QDict *qdict)
>>       bs1 = NULL;
>>       while ((bs1 = bdrv_next(bs1))) {
>>           if (bdrv_can_snapshot(bs1)) {
>> -            ret = bdrv_snapshot_delete(bs1, name);
>> +            ret = bdrv_snapshot_delete(bs1, name, NULL, NULL);
>> +            if (ret == -ENOENT || ret == -EINVAL) {
>> +                ret = bdrv_snapshot_delete(bs, NULL, name, NULL);
>> +            }
>>               if (ret < 0) {
>>                   if (ret == -ENOTSUP)
>>                       monitor_printf(mon,
>
> Same thing here.
>
> Kevin
>


-- 
Best Regards

Wenchao Xia

  reply	other threads:[~2013-07-19  9:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-11  5:46 [Qemu-devel] [PATCH V5 0/8] add internal snapshot support at block device level Wenchao Xia
2013-07-11  5:46 ` [Qemu-devel] [PATCH V5 1/8] snapshot: new function bdrv_snapshot_find_by_id_and_name() Wenchao Xia
2013-07-11  5:46 ` [Qemu-devel] [PATCH V5 2/8] snapshot: distinguish id and name in snapshot delete Wenchao Xia
2013-07-18 11:07   ` Stefan Hajnoczi
2013-07-19  9:12     ` Wenchao Xia
2013-07-18 11:48   ` Kevin Wolf
2013-07-19  9:13     ` Wenchao Xia [this message]
2013-07-11  5:46 ` [Qemu-devel] [PATCH V5 3/8] qmp: add internal snapshot support in qmp_transaction Wenchao Xia
2013-07-18 12:22   ` Kevin Wolf
2013-07-19  9:19     ` Wenchao Xia
2013-07-19 10:13       ` Kevin Wolf
2013-07-20  0:09         ` Wenchao Xia
2013-07-11  5:47 ` [Qemu-devel] [PATCH V5 4/8] qmp: add interface blockdev-snapshot-internal-sync Wenchao Xia
2013-07-11  5:47 ` [Qemu-devel] [PATCH V5 5/8] qmp: add interface blockdev-snapshot-delete-internal-sync Wenchao Xia
2013-07-11  5:47 ` [Qemu-devel] [PATCH V5 6/8] hmp: add interface hmp_snapshot_blkdev_internal Wenchao Xia
2013-07-11  5:47 ` [Qemu-devel] [PATCH V5 7/8] hmp: add interface hmp_snapshot_delete_blkdev_internal Wenchao Xia
2013-07-11  5:47 ` [Qemu-devel] [PATCH V5 8/8] qemu-iotests: add 056 internal snapshot for block device test case Wenchao Xia
2013-07-18 11:09 ` [Qemu-devel] [PATCH V5 0/8] add internal snapshot support at block device level Stefan Hajnoczi
2013-07-18 12:34 ` Kevin Wolf
2013-07-19  5:32   ` Stefan Hajnoczi

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=51E9031C.2010609@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=armbru@redhat.com \
    --cc=dietmar@proxmox.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=phrdina@redhat.com \
    --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).