Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Liu Bo <bo.li.liu@oracle.com>
To: Nikolay Borisov <nborisov@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 04/10] Btrfs: extent map selftest: buffered write vs dio read
Date: Fri, 22 Dec 2017 10:58:28 -0800	[thread overview]
Message-ID: <20171222185828.GC21643@lim.localdomain> (raw)
In-Reply-To: <703352d3-8b80-1df1-e2ad-192e7e738a8d@suse.com>

On Fri, Dec 22, 2017 at 09:51:24AM +0200, Nikolay Borisov wrote:
> 
> 
> On 22.12.2017 00:42, Liu Bo wrote:
> > This test case simulates the racy situation of buffered write vs dio
> > read, and see if btrfs_get_extent() would return -EEXIST.
> 
> Isn't mixing dio/buffered IO on the same file (range?) considered
> dangerous in any case?

They are, but it is sometimes the way how applications work.

thanks,
-liubo

> 
> > 
> > Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
> > ---
> >  fs/btrfs/tests/extent-map-tests.c | 73 +++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 73 insertions(+)
> > 
> > diff --git a/fs/btrfs/tests/extent-map-tests.c b/fs/btrfs/tests/extent-map-tests.c
> > index 0407396..2adf55f 100644
> > --- a/fs/btrfs/tests/extent-map-tests.c
> > +++ b/fs/btrfs/tests/extent-map-tests.c
> > @@ -181,6 +181,78 @@ static void test_case_2(struct extent_map_tree *em_tree)
> >  	free_extent_map_tree(em_tree);
> >  }
> >  
> > +static void __test_case_3(struct extent_map_tree *em_tree, u64 start)
> > +{
> > +	struct extent_map *em;
> > +	u64 len = SZ_4K;
> > +	int ret;
> > +
> > +	em = alloc_extent_map();
> > +	if (!em)
> > +		/* Skip this test on error. */
> > +		return;
> > +
> > +	/* Add [4K, 8K) */
> > +	em->start = SZ_4K;
> > +	em->len = SZ_4K;
> > +	em->block_start = SZ_4K;
> > +	em->block_len = SZ_4K;
> > +	ret = add_extent_mapping(em_tree, em, 0);
> > +	ASSERT(ret == 0);
> > +	free_extent_map(em);
> > +
> > +	em = alloc_extent_map();
> > +	if (!em)
> > +		goto out;
> > +
> > +	/* Add [0, 16K) */
> > +	em->start = 0;
> > +	em->len = SZ_16K;
> > +	em->block_start = 0;
> > +	em->block_len = SZ_16K;
> > +	ret = btrfs_add_extent_mapping(em_tree, &em, start, len);
> > +	if (ret)
> > +		test_msg("case3 [0x%llx 0x%llx): ret %d\n",
> > +			 start, start + len, ret);
> > +	/*
> > +	 * Since bytes within em are contiguous, em->block_start is identical to
> > +	 * em->start.
> > +	 */
> > +	if (em &&
> > +	    (start < em->start || start + len > extent_map_end(em) ||
> > +	     em->start != em->block_start || em->len != em->block_len))
> > +		test_msg("case3 [0x%llx 0x%llx): ret %d em (start 0x%llx len 0x%llx block_start 0x%llx block_len 0x%llx)\n",
> > +			 start, start + len, ret, em->start, em->len,
> > +			 em->block_start, em->block_len);
> > +	free_extent_map(em);
> > +out:
> > +	/* free memory */
> > +	free_extent_map_tree(em_tree);
> > +}
> > +
> > +/*
> > + * Test scenario:
> > + *
> > + * Suppose that no extent map has been loaded into memory yet.
> > + * There is a file extent [0, 16K), two jobs are running concurrently
> > + * against it, t1 is buffered writing to [4K, 8K) and t2 is doing dio
> > + * read from [0, 4K) or [8K, 12K) or [12K, 16K).
> > + *
> > + * t1 goes ahead of t2 and adds em [4K, 8K) into tree.
> > + *
> > + *         t1                       t2
> > + *  cow_file_range()	     btrfs_get_extent()
> > + *                            -> lookup_extent_mapping()
> > + *   -> add_extent_mapping()
> > + *                            -> add_extent_mapping()
> > + */
> > +static void test_case_3(struct extent_map_tree *em_tree)
> > +{
> > +	__test_case_3(em_tree, 0);
> > +	__test_case_3(em_tree, SZ_8K);
> > +	__test_case_3(em_tree, (12 * 1024ULL));
> > +}
> > +
> >  int btrfs_test_extent_map()
> >  {
> >  	struct extent_map_tree *em_tree;
> > @@ -196,6 +268,7 @@ int btrfs_test_extent_map()
> >  
> >  	test_case_1(em_tree);
> >  	test_case_2(em_tree);
> > +	test_case_3(em_tree);
> >  
> >  	kfree(em_tree);
> >  	return 0;
> > 

  reply	other threads:[~2017-12-22 19:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 22:42 [PATCH 00/10] bugfixes and regression tests of btrfs_get_extent Liu Bo
2017-12-21 22:42 ` [PATCH 01/10] Btrfs: add helper for em merge logic Liu Bo
2017-12-22  7:23   ` Nikolay Borisov
2017-12-22 18:45     ` Liu Bo
2017-12-21 22:42 ` [PATCH 02/10] Btrfs: move extent map specific code to extent_map.c Liu Bo
2017-12-21 22:42 ` [PATCH 03/10] Btrfs: add extent map selftests Liu Bo
2017-12-22  7:42   ` Nikolay Borisov
2017-12-22 18:53     ` Liu Bo
2017-12-21 22:42 ` [PATCH 04/10] Btrfs: extent map selftest: buffered write vs dio read Liu Bo
2017-12-22  7:51   ` Nikolay Borisov
2017-12-22 18:58     ` Liu Bo [this message]
2017-12-21 22:42 ` [PATCH 05/10] Btrfs: extent map selftest: dio " Liu Bo
2017-12-21 22:42 ` [PATCH 06/10] Btrfs: fix incorrect block_len in merge_extent_mapping Liu Bo
2017-12-21 22:42 ` [PATCH 07/10] Btrfs: fix unexpected EEXIST from btrfs_get_extent Liu Bo
2017-12-22 12:10   ` Nikolay Borisov
2017-12-22 19:19     ` Liu Bo
2017-12-21 22:42 ` [PATCH 08/10] Btrfs: add WARN_ONCE to detect unexpected error from merge_extent_mapping Liu Bo
2017-12-22  8:52   ` Nikolay Borisov
2017-12-21 22:42 ` [PATCH 09/10] Btrfs: add tracepoint for em's EEXIST case Liu Bo
2017-12-22  8:56   ` Nikolay Borisov
2017-12-22 19:07     ` Liu Bo
2017-12-23  7:39       ` Nikolay Borisov
2018-01-02 18:02         ` Liu Bo
2017-12-21 22:42 ` [PATCH 10/10] Btrfs: noinline merge_extent_mapping Liu Bo

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=20171222185828.GC21643@lim.localdomain \
    --to=bo.li.liu@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox