On Tue, Nov 29, 2011 at 5:01 AM, Mark Wu <wu...@linux.vnet.ibm.com> wrote: > On 11/29/2011 12:18 AM, Stefan Hajnoczi wrote: >> >> Callers of bdrv_is_allocated() may go beyond the end of the image. For >> general robustness we should limit to the end of the image so that >> callers don't end up using out-of-range sector counts and receive -EIO. > > It seems the same problem exists in qcow/qcow2, why do we not add the limit > in bdrv_is_allocated? Then it can cover all formats. > > Actually, I can't figure out how the caller can go beyond the end of the > image. If the I/O request for sectors beyond image size comes from guest, > it should be dropped in the guest block layer. If the request comes from > qemu, like block streaming, it should also honor the image size, right?
Today's bdrv_is_allocated() implementation limits to the end of device if BlockDriver.bdrv_is_allocated is NULL (there is a default implementation). This is a hint that callers may pass pnum values beyond the end of the image. Why is it useful to allow this? Because it makes the caller's job simpler. They can pass in their buffer size directly instead of checking for end of device. The result from bdrv_is_allocated() should limit to the end of device and the caller can safely use it. I think we should preserve this behavior. I like your idea of making it generic and will do that in a new patch. Stefan