From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: qemu-devel@nongnu.org
Cc: dgilbert@redhat.com, kwolf@redhat.com, mreitz@redhat.com,
armbru@redhat.com, muriloo@linux.ibm.com,
Daniel Henrique Barboza <danielhb413@gmail.com>
Subject: [Qemu-devel] [PATCH v2 3/3] qcow2-snapshot: remove redundant find_snapshot_by_id_and_name call
Date: Thu, 6 Sep 2018 08:11:07 -0300 [thread overview]
Message-ID: <20180906111107.30684-4-danielhb413@gmail.com> (raw)
In-Reply-To: <20180906111107.30684-1-danielhb413@gmail.com>
In qcow2_snapshot_create there is the following code block:
/* Generate an ID */
find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str));
/* Check that the ID is unique */
if (find_snapshot_by_id_and_name(bs, sn_info->id_str, NULL) >= 0) {
return -EEXIST;
}
find_new_snapshot_id cycles through all snapshots, getting the id_str
as an unsigned long int, calculating the max id_max value of all the
existing id_strs and writing in the id_str pointer id_max + 1:
for(i = 0; i < s->nb_snapshots; i++) {
sn = s->snapshots + i;
id = strtoul(sn->id_str, NULL, 10);
if (id > id_max)
id_max = id;
}
snprintf(id_str, id_str_size, "%lu", id_max + 1);
Here, sn_info->id_str will have the unique value id_max + 1. Right
after that, find_snapshot_by_id_and_name is called with
id = sn_info->id_str and name = NULL. This will cause the function
to execute the following:
} else if (id) {
for (i = 0; i < s->nb_snapshots; i++) {
if (!strcmp(s->snapshots[i].id_str, id)) {
return i;
}
}
}
In short, we're searching the existing snapshots to see if sn_info->id_str
matches any existing id, right after we set in the previous line a
sn_info->id_str value that is already unique.
The first code block goes way back to commit 585f8587ad, a 2006 commit from
Fabrice Bellard that simply says "new qcow2 disk image format". No more
info is provided about this logic in any subsequent commits that moved
this code block around.
I can't say about the original design, but the current logic is redundant.
bdrv_snapshot_create is called in aio_context lock, forbidding any
concurrent call to accidentally create a new snapshot between
the find_new_snapshot_id and find_snapshot_by_id_and_name calls. What
we're ending up doing is to cycle through the snapshots two times
for no viable reason.
This patch eliminates the redundancy by removing the 'id is unique'
check that calls find_snapshot_by_id_and_name.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
block/qcow2-snapshot.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index bb6a5b7516..20e8472191 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -358,11 +358,6 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
/* Generate an ID */
find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str));
- /* Check that the ID is unique */
- if (find_snapshot_by_id_and_name(bs, sn_info->id_str, NULL) >= 0) {
- return -EEXIST;
- }
-
/* Populate sn with passed data */
sn->id_str = g_strdup(sn_info->id_str);
sn->name = g_strdup(sn_info->name);
--
2.17.1
next prev parent reply other threads:[~2018-09-06 11:11 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-06 11:11 [Qemu-devel] [PATCH v2 0/3] HMP/snapshot changes - do not use ID anymore Daniel Henrique Barboza
2018-09-06 11:11 ` [Qemu-devel] [PATCH v2 1/3] block/snapshot.c: eliminate use of ID input in snapshot operations Daniel Henrique Barboza
2018-09-06 11:11 ` [Qemu-devel] [PATCH v2 2/3] block/snapshot: remove bdrv_snapshot_delete_by_id_or_name Daniel Henrique Barboza
2018-09-06 11:11 ` Daniel Henrique Barboza [this message]
2018-10-08 18:13 ` [Qemu-devel] [PATCH v2 0/3] HMP/snapshot changes - do not use ID anymore Daniel Henrique Barboza
[not found] ` <20180921122954.GD2842@work-vm>
[not found] ` <355a1147-c0d0-88fc-7b68-4391bab25c54@gmail.com>
2018-10-09 17:34 ` Markus Armbruster
2018-10-10 7:56 ` [Qemu-devel] [libvirt] " Peter Krempa
2018-10-11 12:06 ` Dr. David Alan Gilbert
2018-10-11 12:35 ` Peter Krempa
2019-01-09 14:10 ` [Qemu-devel] " Max Reitz
2019-01-09 14:21 ` Kevin Wolf
2019-01-09 14:27 ` Max Reitz
2019-01-09 14:48 ` Kevin Wolf
2019-01-09 14:54 ` Max Reitz
2019-01-09 15:13 ` Kevin Wolf
2019-01-09 15:25 ` Dr. David Alan Gilbert
2019-01-09 16:25 ` Markus Armbruster
2019-01-09 16:27 ` Max Reitz
2019-01-09 16:45 ` Kevin Wolf
2019-01-09 16:58 ` Max Reitz
2019-01-09 18:19 ` Daniel Henrique Barboza
2019-01-09 16:57 ` Daniel Henrique Barboza
2019-01-09 17:05 ` Max Reitz
2019-01-09 17:20 ` Kevin Wolf
2019-01-09 17:38 ` Max Reitz
2019-01-09 17:52 ` Eric Blake
2019-01-09 19:00 ` Kevin Wolf
2019-01-11 12:35 ` Max Reitz
2019-01-09 17:55 ` Eric Blake
2019-01-09 18:51 ` Kevin Wolf
2019-01-09 19:02 ` Eric Blake
2019-01-10 11:25 ` Kevin Wolf
2019-01-10 11:41 ` Dr. David Alan Gilbert
2019-01-10 13:03 ` Daniel Henrique Barboza
2019-01-10 15:11 ` Kevin Wolf
2019-01-10 17:06 ` Dr. David Alan Gilbert
2019-01-10 18:22 ` Eric Blake
2019-01-11 12:14 ` Kevin Wolf
2019-01-11 13:22 ` Max Reitz
2019-01-11 14:33 ` Kevin Wolf
2019-01-11 15:23 ` Max Reitz
2019-01-09 17:32 ` Daniel Henrique Barboza
2019-01-09 17:07 ` 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=20180906111107.30684-4-danielhb413@gmail.com \
--to=danielhb413@gmail.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=muriloo@linux.ibm.com \
--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).