From patchwork Tue Jul 3 13:20:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 168810 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2D2272C00C4 for ; Tue, 3 Jul 2012 23:21:51 +1000 (EST) Received: from localhost ([::1]:56576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sm337-0000yJ-1g for incoming@patchwork.ozlabs.org; Tue, 03 Jul 2012 09:21:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sm32c-00082f-5x for qemu-devel@nongnu.org; Tue, 03 Jul 2012 09:21:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sm32R-0000wn-UE for qemu-devel@nongnu.org; Tue, 03 Jul 2012 09:21:17 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:39732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sm32R-0000s0-LG for qemu-devel@nongnu.org; Tue, 03 Jul 2012 09:21:07 -0400 Received: by mail-pb0-f45.google.com with SMTP id ro12so10303706pbb.4 for ; Tue, 03 Jul 2012 06:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=2t2DHhBO0E1V+tpLfvDBsXIGLUvZ3u6YeQoEuui5BNE=; b=QYDGT2YRP9IJU/locRtjFjI+sK5fmiihPeM1Vd65TVJxJYC6dxXBXRGbGFSwC+yjdl H847RYfQaLYkhvWZkxU5nFHwRtSS2QLaxI+RpRD8y4fLLKd3YnQOITDYpmuDMAF7rfZ7 AK0Vq6aYTYY3K6GkWZoVYfD1haK7pJPnCCJd4bl3Hss5fZiQkfueYCFmlKLv7aBWhMeY 8ZNAYmbTAWSWQyiN4iJHjUniKYen/p28T5c7Y/d4+pwLc7TuYUv84EJNKSbkUldc3HG0 Sv8gSquznLT1BYVhI32fcxh0IYrtgV5wDI7mM0EmbophwvHIOqP9URQbUZ/5BYct922d 3/9A== Received: by 10.68.203.73 with SMTP id ko9mr7199691pbc.66.1341321666735; Tue, 03 Jul 2012 06:21:06 -0700 (PDT) Received: from yakj.usersys.redhat.com (net-93-71-25-153.cust.dsl.vodafone.it. [93.71.25.153]) by mx.google.com with ESMTPS id hw6sm15562494pbc.73.2012.07.03.06.21.02 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 03 Jul 2012 06:21:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 3 Jul 2012 15:20:42 +0200 Message-Id: <1341321642-24598-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.2 In-Reply-To: <1341321642-24598-1-git-send-email-pbonzini@redhat.com> References: <1341321642-24598-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: kwolf@redhat.com, rusty@rustcorp.com.au, anthony@codemonkey.ws, kvm@vger.kernel.org, mst@redhat.com Subject: [Qemu-devel] [PATCH 2/2] virtio-blk: disable write cache if not negotiated 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 If the guest does not support flushes, we should run in writethrough mode. The setting is temporary until the next reset, so that for example the BIOS will run in writethrough mode while Linux will run with a writeback cache. VIRTIO_BLK_F_FLUSH has been introduced in Linux 2.6.32 (in 2009) and was backported to RHEL/CentOS 5.6 (in 2010). The Windows drivers have two bugs, which I reported on the Red Hat Bugzilla as bugs 837321 and 837324. With these patches they will suffer a performance hit but gain correctness. Signed-off-by: Paolo Bonzini --- hw/virtio-blk.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 280f96d..500e026 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -543,6 +543,19 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features) return features; } +static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status) +{ + VirtIOBlock *s = to_virtio_blk(vdev); + uint32_t features; + + if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) { + return; + } + + features = vdev->guest_features; + bdrv_set_enable_write_cache(s->bs, !!(features & (1 << VIRTIO_BLK_F_WCE))); +} + static void virtio_blk_save(QEMUFile *f, void *opaque) { VirtIOBlock *s = opaque; @@ -628,6 +641,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) s->vdev.get_config = virtio_blk_update_config; s->vdev.set_config = virtio_blk_set_config; s->vdev.get_features = virtio_blk_get_features; + s->vdev.set_status = virtio_blk_set_status; s->vdev.reset = virtio_blk_reset; s->bs = blk->conf.bs; s->conf = &blk->conf;