From patchwork Tue Jul 6 15:33:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 58028 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 293A4B6EF0 for ; Wed, 7 Jul 2010 01:35:11 +1000 (EST) Received: from localhost ([127.0.0.1]:35588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OWAAu-0006My-Jn for incoming@patchwork.ozlabs.org; Tue, 06 Jul 2010 11:35:08 -0400 Received: from [140.186.70.92] (port=39356 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OWA9Y-0006Lr-77 for qemu-devel@nongnu.org; Tue, 06 Jul 2010 11:33:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OWA9W-000083-Ed for qemu-devel@nongnu.org; Tue, 06 Jul 2010 11:33:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14544) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OWA9W-00007g-7v for qemu-devel@nongnu.org; Tue, 06 Jul 2010 11:33:42 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o66FXdB7013684 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 6 Jul 2010 11:33:40 -0400 Received: from localhost.localdomain (dhcp-5-217.str.redhat.com [10.32.5.217]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o66FXTsn012071; Tue, 6 Jul 2010 11:33:38 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Tue, 6 Jul 2010 17:33:15 +0200 Message-Id: <1278430406-18667-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1278430406-18667-1-git-send-email-kwolf@redhat.com> References: <1278430406-18667-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 06/17] raw-posix: Fix test for host CD-ROM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Markus Armbruster raw_pread_aligned() retries up to two times if the block device backs a virtual CD-ROM (a drive with media=cdrom and if=ide, scsi, xen or none). This makes no sense. Whether retrying reads can correct read errors can only depend on what we're reading, not on how the result gets used. We need to check what whether we're reading from a physical CD-ROM or floppy here. I doubt retrying is useful even then. Left for another day. Impact: * Virtual CD-ROM backed by host_cdrom behaves the same. * Virtual CD-ROM backed by file or host_device no longer retries. * A drive backed by host_cdrom now retries even if it's not a virtual CD-ROM. * Any drive backed by host_floppy now retries. While there, clean up gratuitous use of goto. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- block/raw-posix.c | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 3f0701b..291699f 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -242,15 +242,14 @@ static int raw_pread_aligned(BlockDriverState *bs, int64_t offset, ret = pread(s->fd, buf, count, offset); if (ret == count) - goto label__raw_read__success; + return ret; /* Allow reads beyond the end (needed for pwrite) */ if ((ret == 0) && bs->growable) { int64_t size = raw_getlength(bs); if (offset >= size) { memset(buf, 0, count); - ret = count; - goto label__raw_read__success; + return count; } } @@ -260,13 +259,13 @@ static int raw_pread_aligned(BlockDriverState *bs, int64_t offset, bs->total_sectors, ret, errno, strerror(errno)); /* Try harder for CDrom. */ - if (bs->type == BDRV_TYPE_CDROM) { + if (s->type != FTYPE_FILE) { ret = pread(s->fd, buf, count, offset); if (ret == count) - goto label__raw_read__success; + return ret; ret = pread(s->fd, buf, count, offset); if (ret == count) - goto label__raw_read__success; + return ret; DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] retry read failed %d : %d = %s\n", @@ -274,8 +273,6 @@ static int raw_pread_aligned(BlockDriverState *bs, int64_t offset, bs->total_sectors, ret, errno, strerror(errno)); } -label__raw_read__success: - return (ret < 0) ? -errno : ret; } @@ -298,15 +295,13 @@ static int raw_pwrite_aligned(BlockDriverState *bs, int64_t offset, ret = pwrite(s->fd, buf, count, offset); if (ret == count) - goto label__raw_write__success; + return ret; DEBUG_BLOCK_PRINT("raw_pwrite(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] write failed %d : %d = %s\n", s->fd, bs->filename, offset, buf, count, bs->total_sectors, ret, errno, strerror(errno)); -label__raw_write__success: - return (ret < 0) ? -errno : ret; }