From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsfQc-0003E0-Az for qemu-devel@nongnu.org; Fri, 28 Jun 2013 16:37:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsfQa-0005k1-JR for qemu-devel@nongnu.org; Fri, 28 Jun 2013 16:37:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12250) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsfQa-0005jd-CL for qemu-devel@nongnu.org; Fri, 28 Jun 2013 16:37:56 -0400 Message-ID: <51CDF420.60202@redhat.com> Date: Fri, 28 Jun 2013 14:37:52 -0600 From: Eric Blake MIME-Version: 1.0 References: <1372318700-25103-1-git-send-email-cngesaint@gmail.com> <1372318700-25103-2-git-send-email-cngesaint@gmail.com> In-Reply-To: <1372318700-25103-2-git-send-email-cngesaint@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="----enig2NKDOTSCSHGVXUFRRIMRA" Subject: Re: [Qemu-devel] [PATCH 1/2] Refine and export infinite loop checking in collect_image_info_list() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xu Wang Cc: Xu Wang , qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2NKDOTSCSHGVXUFRRIMRA Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/27/2013 01:38 AM, Xu Wang wrote: > From: Xu Wang >=20 > Signed-off-by: Xu Wang > --- > qemu-img.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++----= -------- > 1 file changed, 89 insertions(+), 21 deletions(-) >=20 > +/** > + * Check backing file chain if there is a loop in it and build list of= > + * ImageInfo if needed. > + * > + * @filename: topmost image filename absolute? relative? > + * @fmt: topmost image format (may be NULL to autodetect) > + * @head: head of ImageInfo list. If not need please set head to null.= > + * @chain: true - enumerate entire backing file chain > + * false - only topmost image file > + * @backing_file: if this value is set, filename will insert into hash= > + * table directly. open and seek backing file start fro= m it. > + * > + * If return true, stands for a backing file loop exists or some error= > + * happend. If return false, everything is ok. s/happend/happened/ > + */ > +static bool backing_file_loop_check(const char *filename, const char *= fmt, > + bool chain, const char *backing_file) { Indentation is off. > + GHashTable *filenames; > + BlockDriverState *bs; > + ImageInfo *info; > + Error *err =3D NULL; > + > + filenames =3D g_hash_table_new_full(g_str_hash, str_equal_func, NU= LL, NULL); > + > + /* If backing file exists, filename will insert into hash table an= d seek > + * the whole backing file chain from @backing_file. > + */ > + if (backing_file) { > + g_hash_table_insert(filenames, (gpointer)filename, NULL); Does this have any false positives (perhaps mishandling due to relative names) or false negatives (perhaps hard links allow different spellings of the same file to create a loop, although the difference in names won't indicate the problem)? I'd really like to see you add a testcase before this patch gets committed, although I agree that a patch along these lines is worthwhile. For example, make sure the following chain is not rejected: /dir1/base.img <- /dir1/wrap.img(relative backing 'base.img') <- /dir2/base.img (absolute backing '/dir1/base.img') <- /dir2/wrap.img(relative backing 'base.img') whether opened in /dir2/ via relative name 'wrap.img' or absolute name '/dir2/wrap.img'. Likewise, make sure you can detect this loop: create directory 'dir' create './dir/b.img' create './b.img' with relative backing 'dir/b.img' remove ./dir/b.img and dir ln -s . dir now 'b.img' refers to itself as backing file, even though the names =2E/b.img and ./dir/b.img are not equal by strcmp. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org ------enig2NKDOTSCSHGVXUFRRIMRA 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/ iQEcBAEBCAAGBQJRzfQgAAoJEKeha0olJ0NqsmIH/1thvPsZwvHSaeu3tIHZ7jbS An9f4hpSXuyM7DDcbk9nhzd32hVa3FYE3YV7nVwu6Fd5t79WSwkf9GZLsZdU0CVn AL94gdQwWArX0+3NavBPCC/ySkG8qziVx6tdkDB8XZKQeIQQtJJ15IX8zxWPiYyB ebwFZpdPz9r442ZasHXTNQNTC/jGLoQTKCnXpOQO+OU8APAzTiSyzjeT+NnA6/EC hLVyosOWeCRS0Aa0/mFl/Zwxk387Ghwn1o9pBiCv+YBgQyOXNnRakMjtCzaU+73G NXU68PcxmFt5Lkirg2kmktYGBEGV6JDdf5kNSClORMjmCQpbdw5mkH7hsY2RYJY= =VHMV -----END PGP SIGNATURE----- ------enig2NKDOTSCSHGVXUFRRIMRA--