All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/fallocate04: Fix on Btrfs
Date: Fri, 26 Aug 2016 14:17:53 +0300	[thread overview]
Message-ID: <57C02561.8000608@oracle.com> (raw)
In-Reply-To: <20160825165354.GA13281@rei>

Hi,

On 08/25/2016 07:53 PM, Cyril Hrubis wrote:
> The size of a file can double on Btrfs temporarily even when we write
> into a preallocated space because of internal Btrfs caches, at least
> that is what I've been told by Btrfs devs. The internal caches are then
> freed after some time, or can be force freed by syncing the file, which
> is what this patch does.
> 
> Technically we are not guaranteed that the file size will not change after
> writing to preallocated space. We are only guaranteed that subsequent writes to
> the region will not fail with ENOSPC. So this behavior, while uncommon, is not
> really a bug.
> 
> Before the patch the test fails with:
> 
> fallocate04    0  TINFO  :  allocate '12288' bytes
> fallocate04    1  TPASS  :  test-case succeeded
> fallocate04    0  TINFO  :  read allocated file size '24576'
> fallocate04    0  TINFO  :  make a hole with FALLOC_FL_PUNCH_HOLE
> fallocate04    0  TINFO  :  check that file has a hole with lseek(,,SEEK_HOLE)
> fallocate04    0  TINFO  :  found a hole at '4096' offset
> fallocate04    0  TINFO  :  allocated file size before '24576' and after '12288'
> fallocate04    2  TFAIL  :  fallocate04.c:184: not expected allocated size
> 

Tested this on SPARC:

* without the patch

a 2.6.39-based kernel:

[root@skholman-m7 fallocate]# TMPDIR=/mnt ./fallocate04
fallocate04 0 TINFO : allocate '24576' bytes
fallocate04 1 TPASS : test-case succeeded
fallocate04 0 TINFO : read allocated file size '49152'
fallocate04 0 TINFO : make a hole with FALLOC_FL_PUNCH_HOLE
fallocate04 0 TINFO : check that file has a hole with lseek(,,SEEK_HOLE)
fallocate04 0 TINFO : lseek() doesn't support SEEK_HOLE, this is
expected for < 3.1 kernels
fallocate04 0 TINFO : allocated file size before '49152' and after '24576'
fallocate04 2 TFAIL : fallocate04.c:184: not expected allocated size
[root@skholman-m7 fallocate]#

a 4.1-based kernel:

[root@skholman-m7 fallocate]# TMPDIR=/mnt ./fallocate04
fallocate04 0 TINFO : allocate '24576' bytes
fallocate04 1 TPASS : test-case succeeded
fallocate04 0 TINFO : read allocated file size '49152'
fallocate04 0 TINFO : make a hole with FALLOC_FL_PUNCH_HOLE
fallocate04 0 TINFO : check that file has a hole with lseek(,,SEEK_HOLE)
fallocate04 0 TINFO : found a hole at '8192' offset
fallocate04 0 TINFO : allocated file size before '49152' and after '24576'
fallocate04 2 TFAIL : fallocate04.c:184: not expected allocated size
[root@skholman-m7 fallocate]#

* with your patch

a 2.6.39-based kernel:

[root@skholman-m7 fallocate]# TMPDIR=/mnt ./fallocate04
fallocate04 0 TINFO : allocate '24576' bytes
fallocate04 1 TPASS : test-case succeeded
fallocate04 0 TINFO : read allocated file size '24576'
fallocate04 0 TINFO : make a hole with FALLOC_FL_PUNCH_HOLE
fallocate04 0 TINFO : check that file has a hole with lseek(,,SEEK_HOLE)
fallocate04 0 TINFO : lseek() doesn't support SEEK_HOLE, this is
expected for < 3.1 kernels
fallocate04 0 TINFO : allocated file size before '24576' and after '16384'
fallocate04 0 TINFO : reading the file, compare with expected buffer
fallocate04 2 TPASS : test-case succeeded
fallocate04 0 TINFO : zeroing file space with FALLOC_FL_ZERO_RANGE
fallocate04 3 TCONF : fallocate04.c:204: FALLOC_FL_ZERO_RANGE needs
Linux 3.15 or newer
fallocate04 4 TCONF : fallocate04.c:204: Remaining cases not appropriate
for configuration
[root@skholman-m7 fallocate]#

a 4.1-based kernel:

[root@skholman-m7 fallocate]# TMPDIR=/mnt ./fallocate04
fallocate04 0 TINFO : allocate '24576' bytes
fallocate04 1 TPASS : test-case succeeded
fallocate04 0 TINFO : read allocated file size '24576'
fallocate04 0 TINFO : make a hole with FALLOC_FL_PUNCH_HOLE
fallocate04 0 TINFO : check that file has a hole with lseek(,,SEEK_HOLE)
fallocate04 0 TINFO : found a hole@'8192' offset
fallocate04 0 TINFO : allocated file size before '24576' and after '16384'
fallocate04 0 TINFO : reading the file, compare with expected buffer
fallocate04 2 TPASS : test-case succeeded
fallocate04 0 TINFO : zeroing file space with FALLOC_FL_ZERO_RANGE
fallocate04 0 TINFO : read current allocated file size '16384'
fallocate04 3 TCONF : fallocate04.c:215: FALLOC_FL_ZERO_RANGE not supported
fallocate04 4 TCONF : fallocate04.c:215: Remaining cases not appropriate
for configuration
[root@skholman-m7 fallocate]#

Thanks for solving this problem.


> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  testcases/kernel/syscalls/fallocate/fallocate04.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/testcases/kernel/syscalls/fallocate/fallocate04.c b/testcases/kernel/syscalls/fallocate/fallocate04.c
> index 2b904e4..f204188 100644
> --- a/testcases/kernel/syscalls/fallocate/fallocate04.c
> +++ b/testcases/kernel/syscalls/fallocate/fallocate04.c
> @@ -75,6 +75,8 @@ static size_t get_allocsize(void)
>  {
>  	struct stat file_stat;
>  
> +	fsync(fd);
> +
>  	SAFE_FSTAT(cleanup, fd, &file_stat);
>  
>  	return file_stat.st_blocks * 512;
> 

  reply	other threads:[~2016-08-26 11:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-25 16:53 [LTP] [PATCH] syscalls/fallocate04: Fix on Btrfs Cyril Hrubis
2016-08-26 11:17 ` Stanislav Kholmanskikh [this message]
2016-08-26 12:08   ` Alexey Kodanev
2016-08-29  9:44     ` Cyril Hrubis
2016-08-29 12:16       ` Alexey Kodanev
2016-08-29 12:36         ` Cyril Hrubis
2016-08-31 14:07 ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57C02561.8000608@oracle.com \
    --to=stanislav.kholmanskikh@oracle.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.