Re: [PATCH] loopback device can't act as its backing store

From: Bodo Eggert
Date: Fri Dec 03 2004 - 19:32:19 EST


Andrew Morton wrote:

> +        /* Avoid recursion */
> +        f = file;
> +        while (is_loop_device(f)) {
> +                struct loop_device *l;
> +
> +                if (f->f_mapping->host == lo_file->f_mapping->host)
> +                        goto out_putf;
> +                l = f->f_mapping->host->i_bdev->bd_disk->private_data;
> +                if (l->lo_state == Lo_unbound)
> +                        break;
> +                f = l->lo_backing_file;
> +        }
>

This seems wrong to me. AFAI can see, this does not address

1) a->b->c->b->... (Maybe it' is catched later after some recursions)
2) the max. recursion problem you mentioned. (Maybe it's catched by
not having enough loop devices and catching (1), but this may change)


I think the real fix is something like: (guess from this patch, untested)

f = file;
i = MAX_LOOP_CHAIN;
while (is_loop_device(f)) {
struct loop_device *l;

/* if MAX_LOOP_CHAIN is high, leaving in the old check might be a nice
shortcut for the common case. Is it?
*/

if(!--i) goto out_putf;
/* off by one? I don't think so, but check it 'cause it's late. */

l = f->f_mapping->host->i_bdev->bd_disk->private_data;
if (l->lo_state == Lo_unbound)
break;
/* shouldn't we generate an error instead?
I guess the error will be generated while recursing, but we just
followed the chain and know the result.
*/
f = l->lo_backing_file;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/