From: Ian Jackson Subject: Re: [PATCH 1/3] qemu-xen-traditional: use O_DIRECT to open disk images for IDE Date: Thu, 29 Mar 2012 15:20:48 +0100 Message-ID: <20340.28608.642720.913130@mariner.uk.xensource.com> References: <1332514289-28129-1-git-send-email-stefano.stabellini@eu.citrix.com> <20337.63345.79209.977387@mariner.uk.xensource.com> <1332925851.7702.9.camel@zakaz.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1332925851.7702.9.camel@zakaz.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: "Zhang, Yang Z" , "xen-devel@lists.xensource.com" , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Ian Campbell writes ("Re: [Xen-devel] [PATCH 1/3] qemu-xen-traditional: use O_DIRECT to open disk images for IDE"): > commit 82787c6f689d869ad349df83ec3f58702afe00fe > Author: Ian Jackson > Date: Mon Mar 2 11:21:51 2009 +0000 > > Override default cache mode for disk images to write-back > > Upstream qemu changed the default cache mode to write-through (ie, > O_DSYNC) which is much slower. We do not need this as we have > explicit control of cacheing with the IDE cache control commands. ... OK, so the reason for this is as follows: There are IDE commands for controlling cacheing in the disk. These are the commands 0x02 and 0x82 (near l.2666 of hw/ide.c in qemu-xen-unstable). If the host has enabled the write cache, the disk is allowed to buffer written data in its own ram. The host is expected to either disable the cache, or flush the cache (WIN_FLUSH_CACHE, near l.2717) as and when appropriate. We implement this in qemu-xen-unstable as follows: The bdrv_write calls are expected to be write-back cached. The cache enable/disable commands set a variable write_cache in the ide code. If write_cache is 0, we run bdrv_flush after each write. In any case we run bdrv_flush when we get a cache flush command. bdrv_flush calls, effectively, fsync(). So I think qemu-xen-unstable the use of write-back cacheing for bdrv_write is correct. (Apart from the wrinkle that the emulated drive cache, write_cache, is enabled by default - but I wouldn't be surprised if that accurately emulated the behaviour of real disks.) How is this done in qemu-upstream ? Ian.