From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jycuz-0007Bt-Ko for qemu-devel@nongnu.org; Tue, 20 May 2008 21:15:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jycuy-0007B4-PY for qemu-devel@nongnu.org; Tue, 20 May 2008 21:15:01 -0400 Received: from [199.232.76.173] (port=33924 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jycuy-0007Au-LO for qemu-devel@nongnu.org; Tue, 20 May 2008 21:15:00 -0400 Received: from yw-out-1718.google.com ([74.125.46.154]:46397) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Jycuy-0008FH-8A for qemu-devel@nongnu.org; Tue, 20 May 2008 21:15:00 -0400 Received: by yw-out-1718.google.com with SMTP id 6so1612411ywa.82 for ; Tue, 20 May 2008 18:14:59 -0700 (PDT) Message-ID: <4833778C.4030209@codemonkey.ws> Date: Tue, 20 May 2008 20:14:52 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: [PATCH][v2] Align file accesses with cache=off (O_DIRECT) References: <1211283126.4314.70.camel@frecb07144> <200805202352.17807.paul@codesourcery.com> <483373BA.6090108@codemonkey.ws> <200805210205.37432.paul@codesourcery.com> In-Reply-To: <200805210205.37432.paul@codesourcery.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paul Brook Cc: Blue Swirl , Laurent Vivier , qemu-devel@nongnu.org, Kevin Wolf Paul Brook wrote: > On Wednesday 21 May 2008, Anthony Liguori wrote: > >> Paul Brook wrote: >> >>>> When sector-aligned guest offsets are converted to sector-unaligned >>>> writes (e.g. due to qcow2 etc.), that property is no longer satisfied, >>>> and power failure of the host disk can cause more damage than the >>>> guest is designed to be resistant to. >>>> >>> Seems like the easiest solution would be to have qcow always align its >>> writes. We don't do on the fly compression, so it should be fairly easy >>> to make this happen with minimal overhead. >>> >> That's not sufficient. O_DIRECT imposes not only offset alignment >> requirements but also requirements on the buffer being read to. Most of >> the code in QEMU does not properly align the read/write buffers. >> > > In that case you need both. For correct operation the qcow layer needs to > ensure that all file offsets are block aligned (amongst other things, I > wouldn't be surprised if there are more subtle problems with metadata > updates). > > The memory buffer alignment can occur wherever is most convenient, that's > trivially atomic w.r.t. unexpected interruptions. > Yes, I don't think qcow is very safe at all wrt unexpected power events. If we're going to support O_DIRECT, then it's important that underlying block device emulate accesses that don't meet the requirements of O_DIRECT. IMHO, this should all happen within block-raw-posix.c. Keep in mind, the requirements for O_DIRECT since 2.5 is hard sector size (which is usually 512 bytes, but not always) for offset, buffer, and size. Pre-2.5, the requirement is soft sector size which on a filesystem is usually 4k. I don't think it's that important to try and guess the right alignment size, 512 is probably usually sufficient, but spreading alignment requirements of 512 throughout QEMU code is a bad idea because this is something that's very hardware/OS specific. For people that care about data integrity, we should be using O_SYNC, not O_DIRECT anyway. Regards, Anthony Liguori > Paul >