From patchwork Tue Apr 26 21:32:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 615329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qvc5H3Xkdz9t5Z for ; Wed, 27 Apr 2016 07:42:43 +1000 (AEST) Received: from localhost ([::1]:39828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avAkj-0002Zc-8q for incoming@patchwork.ozlabs.org; Tue, 26 Apr 2016 17:42:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avAbG-0007J1-H7 for qemu-devel@nongnu.org; Tue, 26 Apr 2016 17:32:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avAbF-00041S-IK for qemu-devel@nongnu.org; Tue, 26 Apr 2016 17:32:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avAbB-00040A-0a; Tue, 26 Apr 2016 17:32:49 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A750F8112A; Tue, 26 Apr 2016 21:32:48 +0000 (UTC) Received: from localhost (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3QLWkX6001014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 26 Apr 2016 17:32:47 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 26 Apr 2016 23:32:11 +0200 Message-Id: <1461706338-20219-13-git-send-email-mreitz@redhat.com> In-Reply-To: <1461706338-20219-1-git-send-email-mreitz@redhat.com> References: <1461706338-20219-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/19] block: Fix bdrv_find_backing_image() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" bdrv_find_backing_image() should use bdrv_get_full_backing_filename() or bdrv_make_absolute_filename() instead of trying to do what those functions do by itself. path_combine_deprecated() can now be dropped, so let's do that. Signed-off-by: Max Reitz --- block.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index 49dc2cb..6e89abd 100644 --- a/block.c +++ b/block.c @@ -192,15 +192,6 @@ char *path_combine(const char *base_path, const char *filename) return result; } -static void path_combine_deprecated(char *dest, int dest_size, - const char *base_path, - const char *filename) -{ - char *combined = path_combine(base_path, filename); - pstrcpy(dest, dest_size, combined); - g_free(combined); -} - char *bdrv_get_full_backing_filename_from_filename(const char *backed, const char *backing, Error **errp) @@ -3147,7 +3138,6 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, filename_full = g_malloc(PATH_MAX); backing_file_full = g_malloc(PATH_MAX); - filename_tmp = g_malloc(PATH_MAX); is_protocol = path_has_protocol(backing_file); @@ -3163,22 +3153,31 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, } else { /* If not an absolute filename path, make it relative to the current * image's filename path */ - path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filename, - backing_file); + filename_tmp = bdrv_make_absolute_filename(curr_bs, backing_file, + NULL); + if (!filename_tmp) { + continue; + } /* We are going to compare absolute pathnames */ if (!realpath(filename_tmp, filename_full)) { + g_free(filename_tmp); continue; } + g_free(filename_tmp); /* We need to make sure the backing filename we are comparing against * is relative to the current image filename (or absolute) */ - path_combine_deprecated(filename_tmp, PATH_MAX, curr_bs->filename, - curr_bs->backing_file); + filename_tmp = bdrv_get_full_backing_filename(curr_bs, NULL); + if (!filename_tmp) { + continue; + } if (!realpath(filename_tmp, backing_file_full)) { + g_free(filename_tmp); continue; } + g_free(filename_tmp); if (strcmp(backing_file_full, filename_full) == 0) { retval = curr_bs->backing->bs; @@ -3189,7 +3188,6 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, g_free(filename_full); g_free(backing_file_full); - g_free(filename_tmp); return retval; }