From patchwork Wed Sep 24 19:48:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 393081 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 CEF95140140 for ; Thu, 25 Sep 2014 05:50:44 +1000 (EST) Received: from localhost ([::1]:34114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWsaI-0006VV-MX for incoming@patchwork.ozlabs.org; Wed, 24 Sep 2014 15:50:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWsYV-00032M-Vi for qemu-devel@nongnu.org; Wed, 24 Sep 2014 15:48:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XWsYP-0008SJ-Of for qemu-devel@nongnu.org; Wed, 24 Sep 2014 15:48:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23687) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWsYP-0008Ja-GZ for qemu-devel@nongnu.org; Wed, 24 Sep 2014 15:48:45 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8OJmduH006653 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 24 Sep 2014 15:48:40 -0400 Received: from localhost (ovpn-116-84.ams2.redhat.com [10.36.116.84]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8OJmbGf006511 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Wed, 24 Sep 2014 15:48:39 -0400 From: Max Reitz To: qemu-devel@nongnu.org Date: Wed, 24 Sep 2014 21:48:25 +0200 Message-Id: <1411588107-4275-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1411588107-4275-1-git-send-email-mreitz@redhat.com> References: <1411588107-4275-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH 2/4] 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 qemu-img's map command, we should be using the filename field; but since this commit prepares to remove that field, using exact_filename is fine, too (this is the only user of BlockDriverState.filename which frequently queries that field). Finally, in some other places there a buffer is available whose content equals that of BlockDriverState.filename; use that buffer instead. Signed-off-by: Max Reitz --- block.c | 4 ++-- block/gluster.c | 2 +- block/qapi.c | 2 +- block/raw-posix.c | 8 ++++---- block/raw-win32.c | 4 ++-- qemu-img.c | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index 4cf7620..9311cef 100644 --- a/block.c +++ b/block.c @@ -992,8 +992,8 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *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/qapi.c b/block/qapi.c index 9733ebd..682109e 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -213,7 +213,7 @@ void bdrv_query_image_info(BlockDriverState *bs, #ifdef __linux__ /* get NOCOW info */ - fd = qemu_open(bs->filename, O_RDONLY | O_NONBLOCK); + fd = qemu_open(info->filename, O_RDONLY | O_NONBLOCK); if (fd >= 0) { if (ioctl(fd, FS_IOC_GETFLAGS, &attr) == 0 && (attr & FS_NOCOW_FL)) { info->has_nocow = true; diff --git a/block/raw-posix.c b/block/raw-posix.c index a253697..3bee169 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -578,7 +578,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) { assert(!(raw_s->open_flags & O_CREAT)); - raw_s->fd = qemu_open(state->bs->filename, raw_s->open_flags); + raw_s->fd = qemu_open(state->bs->exact_filename, raw_s->open_flags); if (raw_s->fd == -1) { error_setg_errno(errp, errno, "Could not reopen file"); ret = -1; @@ -1896,7 +1896,7 @@ static int fd_open(BlockDriverState *bs) #endif return -EIO; } - s->fd = qemu_open(bs->filename, s->open_flags & ~O_NONBLOCK); + s->fd = qemu_open(bs->exact_filename, s->open_flags & ~O_NONBLOCK); if (s->fd < 0) { s->fd_error_time = get_clock(); s->fd_got_error = 1; @@ -2188,7 +2188,7 @@ static void floppy_eject(BlockDriverState *bs, bool eject_flag) qemu_close(s->fd); s->fd = -1; } - fd = qemu_open(bs->filename, s->open_flags | O_NONBLOCK); + fd = qemu_open(bs->exact_filename, s->open_flags | O_NONBLOCK); if (fd >= 0) { if (ioctl(fd, FDEJECT, 0) < 0) perror("FDEJECT"); @@ -2412,7 +2412,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 9bf8225..9afc4d1 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -416,7 +416,7 @@ static void raw_close(BlockDriverState *bs) CloseHandle(s->hfile); if (bs->open_flags & BDRV_O_TEMPORARY) { - unlink(bs->filename); + unlink(bs->exact_filename); } } @@ -484,7 +484,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"), diff --git a/qemu-img.c b/qemu-img.c index dbf0904..ec42f21 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2009,7 +2009,7 @@ static void dump_map_entry(OutputFormat output_format, MapEntry *e, } if ((e->flags & (BDRV_BLOCK_DATA|BDRV_BLOCK_ZERO)) == BDRV_BLOCK_DATA) { printf("%#-16"PRIx64"%#-16"PRIx64"%#-16"PRIx64"%s\n", - e->start, e->length, e->offset, e->bs->filename); + e->start, e->length, e->offset, e->bs->exact_filename); } /* This format ignores the distinction between 0, ZERO and ZERO|DATA. * Modify the flags here to allow more coalescing.