From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxF3i-0003K4-HP for qemu-devel@nongnu.org; Thu, 20 Oct 2016 11:15:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxF3e-0007At-IG for qemu-devel@nongnu.org; Thu, 20 Oct 2016 11:15:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxF3e-0007Aj-A1 for qemu-devel@nongnu.org; Thu, 20 Oct 2016 11:15:02 -0400 Date: Thu, 20 Oct 2016 17:14:58 +0200 From: Igor Mammedov Message-ID: <20161020171458.1657c23b@nial.brq.redhat.com> In-Reply-To: <20161020150029.GB5057@thinpad.lan.raisama.net> References: <20161020061301.31372-1-haozhong.zhang@intel.com> <20161020143412.5ea6b564@nial.brq.redhat.com> <20161020132159.GU5057@thinpad.lan.raisama.net> <20161020133353.qfscowwx5bldzvdc@hz-desktop> <20161020154732.5f0a87a8@nial.brq.redhat.com> <20161020135711.GZ5057@thinpad.lan.raisama.net> <20161020161820.3bcfce3a@nial.brq.redhat.com> <20161020150029.GB5057@thinpad.lan.raisama.net> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] hostmem-file: add a property 'notrunc' to avoid data corruption List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: Haozhong Zhang , qemu-devel@nongnu.org, Paolo Bonzini , Peter Crosthwaite , Richard Henderson , Xiao Guangrong , kwolf@redhat.com, mreitz@redhat.com On Thu, 20 Oct 2016 13:00:29 -0200 Eduardo Habkost wrote: > On Thu, Oct 20, 2016 at 04:18:20PM +0200, Igor Mammedov wrote: > > On Thu, 20 Oct 2016 11:57:11 -0200 > > Eduardo Habkost wrote: > > > > > On Thu, Oct 20, 2016 at 03:47:32PM +0200, Igor Mammedov wrote: > > > > On Thu, 20 Oct 2016 21:33:53 +0800 > > > > Haozhong Zhang wrote: > > > > > > > > > On 10/20/16 11:21 -0200, Eduardo Habkost wrote: > > > > > >On Thu, Oct 20, 2016 at 02:34:12PM +0200, Igor Mammedov wrote: > > > > > >> On Thu, 20 Oct 2016 14:13:01 +0800 > > > > > >> Haozhong Zhang wrote: > > > > > >> > > > > > >> > If a file is used as the backend of memory-backend-file and its size is > > > > > >> > not identical to the property 'size', the file will be truncated. For a > > > > > >> > file used as the backend of vNVDIMM, its data is expected to be > > > > > >> > persistent and the truncation may corrupt the existing data. > > > > > >> I wonder if it's possible just skip 'size' property in your case instead > > > > > >> 'notrunc' property. That way if size is not present one'd get actual size > > > > > >> using get_file_size() and set 'size' to it? > > > > > >> And if 'size' is provided and 'size' != file_size then error out. > > > > > > > > > > > >I think it is valid to start with a zero-size file and then let > > > > > >QEMU extend it. > > > > > > > > > > For vNVDIMM, extending from zero-size file can be valid when a file is > > > > > first used. However, it's not valid for the second and following use > > > > > of the same file. > > > > I'd avoid 0 sized backend files and enforce non 0 size value > > > > with exact match to actual file size. i.e. let mgmt side take care of > > > > proper backend file allocation. > > > > > > This would break compatibility with existing setups that rely on > > > the ftruncate() behavior. > > > > Question is what exactly rely on truncate behavior? > > hugetlbfs or tmpfs + mempolicy would work only if a sparse file > used (otherwise memory would be already allocated before running > QEMU). That means it is easier to simply not set file size before > running QEMU. > > I don't know what's libvirt behavior, but I wouldn't want to > break existing scripts that rely on it. We can probably do something like this if (file_size == 0 && explicitly_asked_size > file_size) do allocation