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: 1151041 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id B2E9C3FE80 for ; Tue, 3 Jul 2012 13:21:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933026Ab2GCNVK (ORCPT ); Tue, 3 Jul 2012 09:21:10 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:58414 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933034Ab2GCNVH (ORCPT ); Tue, 3 Jul 2012 09:21:07 -0400 Received: by yenl2 with SMTP id l2so5235948yen.19 for ; Tue, 03 Jul 2012 06:21:07 -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 Cc: kvm@vger.kernel.org, mst@redhat.com, anthony@codemonkey.ws, kwolf@redhat.com, rusty@rustcorp.com.au Subject: [PATCH 2/2] virtio-blk: disable write cache if not negotiated 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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;