From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cAoic-0002Tf-6N for qemu-devel@nongnu.org; Sat, 26 Nov 2016 20:57:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cAoiZ-000713-58 for qemu-devel@nongnu.org; Sat, 26 Nov 2016 20:57:26 -0500 From: Max Reitz Date: Sun, 27 Nov 2016 02:56:20 +0100 Message-Id: <20161127015622.24105-23-mreitz@redhat.com> In-Reply-To: <20161127015622.24105-1-mreitz@redhat.com> References: <20161127015622.24105-1-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v2 22/24] block: Do not copy exact_filename from format file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Max Reitz , Kevin Wolf , Alberto Garcia , Eric Blake If the a format BDS's file BDS is in turn a format BDS, we cannot simply use the same filename, because when opening a BDS tree based on a filename alone, qemu will create only one format node on top of one protocol node (disregarding a potential backing file). Signed-off-by: Max Reitz --- block.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 187ce10..d2917f1 100644 --- a/block.c +++ b/block.c @@ -4096,9 +4096,20 @@ void bdrv_refresh_filename(BlockDriverState *bs) bs->exact_filename[0] = '\0'; - /* If no specific options have been given for this BDS, the filename of - * the underlying file should suffice for this one as well */ - if (bs->file->bs->exact_filename[0] && !generate_json_filename) { + /* We can use the underlying file's filename if: + * - it has a filename, + * - the file is a protocol BDS, and + * - opening that file (as this BDS's format) will automatically create + * the BDS tree we have right now, that is: + * - the user did not significantly change this BDS's behavior with + * some explicit options + * - no non-file child of this BDS has been overridden by the user + * Both of these conditions are represented by generate_json_filename. + */ + if (bs->file->bs->exact_filename[0] && + (bs->file->bs->open_flags & BDRV_O_PROTOCOL) && + !generate_json_filename) + { strcpy(bs->exact_filename, bs->file->bs->exact_filename); } } -- 2.10.2