From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:36705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVNke-0006q9-Ga for qemu-devel@nongnu.org; Tue, 29 Nov 2011 08:29:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RVNkd-00086s-Gd for qemu-devel@nongnu.org; Tue, 29 Nov 2011 08:29:36 -0500 Received: from mail-fx0-f45.google.com ([209.85.161.45]:51482) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RVNkd-00086j-9U for qemu-devel@nongnu.org; Tue, 29 Nov 2011 08:29:35 -0500 Received: by fabs1 with SMTP id s1so876908fab.4 for ; Tue, 29 Nov 2011 05:29:34 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <4ED46740.3090108@linux.vnet.ibm.com> References: <1322497100-24167-1-git-send-email-stefanha@linux.vnet.ibm.com> <4ED46740.3090108@linux.vnet.ibm.com> Date: Tue, 29 Nov 2011 13:29:31 +0000 Message-ID: From: Stefan Hajnoczi Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] qed: limit to image size in qed_find_cluster() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mark Wu Cc: Kevin Wolf , Stefan Hajnoczi , qemu-devel@nongnu.org On Tue, Nov 29, 2011 at 5:01 AM, Mark Wu wrote: > On 11/29/2011 12:18 AM, Stefan Hajnoczi wrote: >> >> Callers of bdrv_is_allocated() may go beyond the end of the image. =A0Fo= r >> 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 lim= it > 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. =A0If the I/O request for sectors beyond image size comes from gue= st, > it should be dropped in the guest block layer. =A0If the request comes fr= om > 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