All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Xu Wang <cngesaint@gmail.com>
Cc: Xu Wang <cngesaint@outlook.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] Refine and export infinite loop checking in collect_image_info_list()
Date: Fri, 28 Jun 2013 14:37:52 -0600	[thread overview]
Message-ID: <51CDF420.60202@redhat.com> (raw)
In-Reply-To: <1372318700-25103-2-git-send-email-cngesaint@gmail.com>

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

On 06/27/2013 01:38 AM, Xu Wang wrote:
> From: Xu Wang <cngesaint@outlook.com>
> 
> Signed-off-by: Xu Wang <cngesaint@outlook.com>
> ---
>  qemu-img.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++------------
>  1 file changed, 89 insertions(+), 21 deletions(-)
> 

> +/**
> + * 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 from 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 = NULL;
> +
> +    filenames = g_hash_table_new_full(g_str_hash, str_equal_func, NULL, NULL);
> +
> +    /* If backing file exists, filename will insert into hash table and 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
./b.img and ./dir/b.img are not equal by strcmp.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


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

  reply	other threads:[~2013-06-28 20:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-27  7:38 [Qemu-devel] [PATCH 0/2] Add infinite loop checking in img_create() Xu Wang
2013-06-27  7:38 ` [Qemu-devel] [PATCH 1/2] Refine and export infinite loop checking in collect_image_info_list() Xu Wang
2013-06-28 20:37   ` Eric Blake [this message]
2013-07-04 13:00     ` Stefan Hajnoczi
2013-07-08  7:31     ` Xu Wang
2013-06-27  7:38 ` [Qemu-devel] [PATCH 2/2] Check infinite loop in img_create() Xu Wang
2013-06-29 14:32 ` [Qemu-devel] [PATCH 0/2] Add infinite loop checking " Andreas Färber
2013-07-04 13:01   ` 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=51CDF420.60202@redhat.com \
    --to=eblake@redhat.com \
    --cc=cngesaint@gmail.com \
    --cc=cngesaint@outlook.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.