From: Cyril Hrubis Date: Thu, 16 Feb 2017 14:12:39 +0100 Subject: [LTP] [PATCH 1/2] ltp-aiodio/dio_sparse: Fix write in dio_sparse() In-Reply-To: <58A2C580.7050401@cn.fujitsu.com> References: <1484818349-30539-1-git-send-email-fenggw-fnst@cn.fujitsu.com> <20170124134057.GC29054@rei.lan> <58882AA5.90906@cn.fujitsu.com> <589C2EA5.6040707@cn.fujitsu.com> <20170209093152.GA12673@rei.lan> <58A2C580.7050401@cn.fujitsu.com> Message-ID: <20170216131239.GA8731@rei.lan> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: ltp@lists.linux.it Hi! > >> As the second case of kernel commit 9ecd10b says: > >> 2. Direct writes starting from or beyong i_size (not inside i_size) > >> also could trigger block allocation and expose stale data. For > >> example, consider a sparse file with i_size of 2k, and a write to > >> offset 2k or 3k into the file, with a filesystem block size of 4k. > >> (Thanks to Jeff Moyer for pointing this case out in his review.) > > > > Ah, looking at the git log, the offset was just added recently, that's > > why the code is confusing, previously the filesize was size of the > > file... > > Yes, it seems that the code get confusing after the offset was added, > and yes, previously the filesize was the size of the file, but sorry, > according to my understanding it still represents the size of the file now. Ok we are mixing two things together. One is how much size the file actually takes on a filesystem and second one is the file length. > > > > So what about we rename the writesize to blocksize and filesize to > > writesize so that it's clear what the function dio_sparse does. > > > > int dio_sparse(char *filename, int align, int blocksize, int writesize, int offset) > > > > Also shouldn't we truncate the file to offset + filesize rather than > > just filesize? And then pass the size to the children as offset + > > filesize as well? > > In my humble opinion, there was no problem at all in the code before > the offset was added, and look at the commit message of adding offset, > the aim is to achieve the second case of kernel commit 9ecd10b above, > make it to direct write from or beyond the end of the file. The patch is correct, there is no doubt about that. > So, I think the writesize, filesize and offset should be independent of > each other, the "offset" here is not filesize's offset (i.e. filesize > does not calculate with offset), but only to decide where we write start from. Okay, but still the writesize should be rename to something as block_size. -- Cyril Hrubis chrubis@suse.cz