Received: from eggs.gnu.org ([2001:4830:134:3::10]:46173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhD2d-00026O-7u for qemu-devel@nongnu.org; Fri, 15 Nov 2013 01:38:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VhD2T-000796-JK for qemu-devel@nongnu.org; Fri, 15 Nov 2013 01:38:07 -0500 Received: from mail-oa0-x234.google.com ([2607:f8b0:4003:c02::234]:43356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhD2T-00078x-EO for qemu-devel@nongnu.org; Fri, 15 Nov 2013 01:37:57 -0500 Received: by mail-oa0-f52.google.com with SMTP id o6so3447505oag.39 for ; Thu, 14 Nov 2013 22:37:56 -0800 (PST) From: Xu Wang Date: Fri, 15 Nov 2013 01:37:22 -0500 Message-Id: <1384497443-17292-4-git-send-email-gesaint@linux.vnet.ibm.com> In-Reply-To: <1384497443-17292-1-git-send-email-gesaint@linux.vnet.ibm.com> References: <1384497443-17292-1-git-send-email-gesaint@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH V8 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: qemu-devel@nongnu.org Cc: kwolf@redhat.com, famz@redhat.com, stefanha@gmail.com, Xu Wang , wdongxu@linux.vnet.ibm.com, xiawenc@linux.vnet.ibm.com 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 6fbc702..2d58f12 100644 --- a/block.c +++ b/block.c @@ -2068,6 +2068,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 @@ -2076,6 +2077,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 */ @@ -2083,6 +2085,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, backing_fmt, bs->filename, + &local_err)) { + error_report("Backing file check: %s", error_get_pretty(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