From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TutdG-0002KX-E8 for qemu-devel@nongnu.org; Mon, 14 Jan 2013 18:40:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tutd6-0005OC-6W for qemu-devel@nongnu.org; Mon, 14 Jan 2013 18:39:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tutd5-0005NQ-Uc for qemu-devel@nongnu.org; Mon, 14 Jan 2013 18:39:48 -0500 Message-ID: <50F4973F.4090608@redhat.com> Date: Mon, 14 Jan 2013 16:39:43 -0700 From: Eric Blake MIME-Version: 1.0 References: <1358147387-8221-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1358147387-8221-8-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1358147387-8221-8-git-send-email-xiawenc@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2NMGMAHCAIBCFKRRTNIAE" Subject: Re: [Qemu-devel] [PATCH V3 07/11] block: export function bdrv_find_snapshot() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: aliguori@us.ibm.com, phrdina@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, pbonzini@redhat.com, armbru@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2NMGMAHCAIBCFKRRTNIAE Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 01/14/2013 12:09 AM, Wenchao Xia wrote: > This patch move it from savevm.c to block.c and export it. >=20 > Signed-off-by: Wenchao Xia > --- > block.c | 23 +++++++++++++++++++++++ > include/block/block.h | 2 ++ > savevm.c | 22 ---------------------- > 3 files changed, 25 insertions(+), 22 deletions(-) >=20 > diff --git a/block.c b/block.c > index 8192d8e..b7d2f03 100644 > --- a/block.c > +++ b/block.c > @@ -3351,6 +3351,29 @@ int bdrv_snapshot_load_tmp(BlockDriverState *bs,= > return -ENOTSUP; > } > =20 > +int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info= , > + const char *name) > +{ > + QEMUSnapshotInfo *sn_tab, *sn; > + int nb_sns, i, ret; > + > + ret =3D -ENOENT; > + nb_sns =3D bdrv_snapshot_list(bs, &sn_tab); > + if (nb_sns < 0) { > + return ret; > + } > + for (i =3D 0; i < nb_sns; i++) { > + sn =3D &sn_tab[i]; > + if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) { It is possible (albeit probably stupid) to create a qcow2 file where snapshot names are merely numeric strings. In fact, just to see what would happen, I once[1] created a file where: snapshot id '1' was named '2' snapshot id '2' was named 'foo' This code comparison favors ids over names; so if I request to delvm 2, I end up removing the second snapshot, not the first. This is okay, but probably worth documenting, and probably worth making sure that all code that looks up a snapshot by name or id goes through this function so that we get the same behavior everywhere. My experiment was done several months ago, but my recollection was that at the time, there was an inconsistency where 'qemu-img snapshot' picked a different snapshot for the request of '2' than the online 'delvm' monitor command of qemu; making it unsafe to rely on either behavior in that version of qemu source code. [1]https://bugzilla.redhat.com/show_bug.cgi?id=3D733143 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2NMGMAHCAIBCFKRRTNIAE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJQ9Jc/AAoJEKeha0olJ0Nqj2EH/i9U4OcKvA/qQgAHozmVWp3c yRCfF8IRD0mtrdK21zC6IyQJYAJVlES6WzXbFXYQbu+naeOMeqNotfUIEmhcdu9f 3kWwKqqa8I0trtQZWdnGAIW2ipwoTgqW1el/zvtCIHDuFD/t9YHjcicAAyz/XbWU FU8b6zCKZvkwTycWxhF3V3z20NVpqjVt2HdTd1l9zPRtmqr1UfXIyv2y6RNHrkfD oGSBXiVOXxUcSFPsZ5CRINAsi+ZEDuEoACyYNXnpvTzTseLoVlaRndtrPy5Uiybt Z1FAN/DogjCIsrPVxmF2Qbmo7a/E/jacPqKyNw5Bbq3c6RCwrNSPEgapGFqNvow= =0fKz -----END PGP SIGNATURE----- ------enig2NMGMAHCAIBCFKRRTNIAE--