From patchwork Mon Oct 19 18:49:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 532510 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40C3514016A for ; Tue, 20 Oct 2015 05:51:52 +1100 (AEDT) Received: from localhost ([::1]:41638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoFXC-0001R2-6O for incoming@patchwork.ozlabs.org; Mon, 19 Oct 2015 14:51:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoFUo-00077i-Ey for qemu-devel@nongnu.org; Mon, 19 Oct 2015 14:49:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoFUk-0007Fn-Mr for qemu-devel@nongnu.org; Mon, 19 Oct 2015 14:49:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoFUg-0007F2-T3; Mon, 19 Oct 2015 14:49:15 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 8E37091C16; Mon, 19 Oct 2015 18:49:14 +0000 (UTC) Received: from localhost (ovpn-116-133.ams2.redhat.com [10.36.116.133]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9JInCnf010979 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 19 Oct 2015 14:49:13 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 19 Oct 2015 20:49:02 +0200 Message-Id: <1445280546-26226-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1445280546-26226-1-git-send-email-mreitz@redhat.com> References: <1445280546-26226-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Subject: [Qemu-devel] [PATCH v5 2/6] block: Avoid BlockDriverState.filename X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In places which directly pass a filename to the OS, we should not use the filename field at all but exact_filename instead (although the former currently equals the latter if that is set). In raw_open_common(), we do not need to access BDS.filename because we already have a local variable pointing to the filename. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 5 +++-- block/gluster.c | 2 +- block/raw-posix.c | 8 ++++---- block/raw-win32.c | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index 60f9450..0f08d7c 100644 --- a/block.c +++ b/block.c @@ -913,8 +913,9 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file, if (ret < 0) { if (local_err) { error_propagate(errp, local_err); - } else if (bs->filename[0]) { - error_setg_errno(errp, -ret, "Could not open '%s'", bs->filename); + } else if (bs->exact_filename[0]) { + error_setg_errno(errp, -ret, "Could not open '%s'", + bs->exact_filename); } else { error_setg_errno(errp, -ret, "Could not open image"); } diff --git a/block/gluster.c b/block/gluster.c index 1eb3a8c..176682b 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -358,7 +358,7 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state, gconf = g_new0(GlusterConf, 1); - reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename, errp); + reop_s->glfs = qemu_gluster_init(gconf, state->bs->exact_filename, errp); if (reop_s->glfs == NULL) { ret = -errno; goto exit; diff --git a/block/raw-posix.c b/block/raw-posix.c index 918c756..9cb7ebd 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -505,7 +505,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, "specified. Falling back to aio=threads.\n" " This will become an error condition in " "future QEMU versions.\n", - bs->filename); + filename); } #else if (bdrv_flags & BDRV_O_NATIVE_AIO) { @@ -667,7 +667,7 @@ static int raw_reopen_prepare(BDRVReopenState *state, /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */ if (raw_s->fd == -1) { - const char *normalized_filename = state->bs->filename; + const char *normalized_filename = state->bs->exact_filename; ret = raw_normalize_devicepath(&normalized_filename); if (ret < 0) { error_setg_errno(errp, -ret, "Could not normalize device path"); @@ -2099,7 +2099,7 @@ static bool hdev_is_sg(BlockDriverState *bs) struct sg_scsi_id scsiid; int sg_version; - if (stat(bs->filename, &st) >= 0 && S_ISCHR(st.st_mode) && + if (stat(bs->exact_filename, &st) >= 0 && S_ISCHR(st.st_mode) && !bdrv_ioctl(bs, SG_GET_VERSION_NUM, &sg_version) && !bdrv_ioctl(bs, SG_GET_SCSI_ID, &scsiid)) { DPRINTF("SG device found: type=%d, version=%d\n", @@ -2518,7 +2518,7 @@ static int cdrom_reopen(BlockDriverState *bs) */ if (s->fd >= 0) qemu_close(s->fd); - fd = qemu_open(bs->filename, s->open_flags, 0644); + fd = qemu_open(bs->exact_filename, s->open_flags, 0644); if (fd < 0) { s->fd = -1; return -EIO; diff --git a/block/raw-win32.c b/block/raw-win32.c index 2d0907a..e2bbe24 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -417,7 +417,7 @@ static void raw_close(BlockDriverState *bs) CloseHandle(s->hfile); if (bs->open_flags & BDRV_O_TEMPORARY) { - unlink(bs->filename); + unlink(bs->exact_filename); } } @@ -485,7 +485,7 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs) DWORD * high); get_compressed_t get_compressed; struct _stati64 st; - const char *filename = bs->filename; + const char *filename = bs->exact_filename; /* WinNT support GetCompressedFileSize to determine allocate size */ get_compressed = (get_compressed_t) GetProcAddress(GetModuleHandle("kernel32"),