From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtkGp-00035D-5Y for qemu-devel@nongnu.org; Thu, 19 Dec 2013 15:32:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtkGi-00020z-Q4 for qemu-devel@nongnu.org; Thu, 19 Dec 2013 15:32:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtkGi-0001yu-HK for qemu-devel@nongnu.org; Thu, 19 Dec 2013 15:32:28 -0500 Date: Thu, 19 Dec 2013 11:13:36 -0500 From: Jeff Cody Message-ID: <20131219161336.GC4699@localhost.localdomain> References: <1385447913-19004-1-git-send-email-gesaint@linux.vnet.ibm.com> <1385447913-19004-4-git-send-email-gesaint@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1385447913-19004-4-git-send-email-gesaint@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH V9 3/4] block: Add backing file loop check in change_backing_file() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Xu Wang Cc: kwolf@redhat.com, stefanha@gmail.com, famz@redhat.com, qemu-devel@nongnu.org, wdongxu@linux.vnet.ibm.com On Tue, Nov 26, 2013 at 01:38:32AM -0500, Xu Wang wrote: > Backing file loop should be checked before calling change_backing_ > file(). If loop appeared, this calling should be stopped and an > error printed. > > Signed-off-by: Xu Wang > --- > block.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/block.c b/block.c > index b8cea1c..87f7018 100644 > --- a/block.c > +++ b/block.c > @@ -2075,6 +2075,7 @@ static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs, > * Return values: > * 0 - success > * -EINVAL - backing format specified, but no file > + * -EIO - generic I/O error (may happen for all errors) > * -ENOSPC - can't update the backing file because no space is left in the > * image file header > * -ENOTSUP - format driver doesn't support changing the backing file > @@ -2083,6 +2084,7 @@ int bdrv_change_backing_file(BlockDriverState *bs, > const char *backing_file, const char *backing_fmt) > { > BlockDriver *drv = bs->drv; > + Error *local_err = NULL; > int ret; > > /* Backing file format doesn't make sense without a backing file */ > @@ -2090,6 +2092,13 @@ int bdrv_change_backing_file(BlockDriverState *bs, > return -EINVAL; > } > > + /* Check if loop exists in backing files chain after change */ > + if (!bdrv_backing_chain_okay(backing_file, NULL, bs->filename, > + &local_err)) { > + error_report("Backing file check: %s", error_get_pretty(local_err)); You need to free local_err before returning (i.e. error_free(local_err)). > + return -EIO; > + } > + > if (drv->bdrv_change_backing_file != NULL) { > ret = drv->bdrv_change_backing_file(bs, backing_file, backing_fmt); > } else { > -- > 1.8.1.4 > >