git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, newren@gmail.com,
	Derrick Stolee <stolee@gmail.com>,
	Derrick Stolee <derrickstolee@github.com>,
	Derrick Stolee <dstolee@microsoft.com>
Subject: Re: [PATCH v2 3/8] fsmonitor: de-duplicate BUG()s around dirty bits
Date: Fri, 22 Jan 2021 11:18:42 -0800	[thread overview]
Message-ID: <xmqqh7n893vx.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <31095f9aa0ecd29193cc4d612d1953653c04b8ae.1611320639.git.gitgitgadget@gmail.com> (Derrick Stolee via GitGitGadget's message of "Fri, 22 Jan 2021 13:03:54 +0000")

"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Derrick Stolee <dstolee@microsoft.com>
>
> The index has an fsmonitor_dirty bitmap that records which index entries
> are "dirty" based on the response from the FSMonitor. If this bitmap
> ever grows larger than the index, then there was an error in how it was
> constructed, and it was probably a developer's bug.
>
> There are several BUG() statements that are very similar, so replace
> these uses with a simpler assert_index_minimum(). Since there is one
> caller that uses a custom 'pos' value instead of the bit_size member, we
> cannot simplify it too much. However, the error string is identical in
> each, so this simplifies things.

Also that single caller with a custom 'pos' used to allow 'pos' to
point one beyond the end of istate->cache[] array, but now it is
forbidden.  If this is a strict bugfix, it probably deserves a
mention here.

> The end result is that the code is simpler to read while also preserving
> these assertions for developers in the FSMonitor space.
>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  fsmonitor.c | 27 +++++++++++++--------------
>  1 file changed, 13 insertions(+), 14 deletions(-)
>
> diff --git a/fsmonitor.c b/fsmonitor.c
> index ca031c3abb8..52a50a9545a 100644
> --- a/fsmonitor.c
> +++ b/fsmonitor.c
> @@ -13,14 +13,19 @@
>  
>  struct trace_key trace_fsmonitor = TRACE_KEY_INIT(FSMONITOR);
>  
> +static void assert_index_minimum(struct index_state *istate, size_t pos)
> +{
> +	if (pos > istate->cache_nr)
> +		BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" > %u)",
> +		    (uintmax_t)pos, istate->cache_nr);
> +}
> +
>  static void fsmonitor_ewah_callback(size_t pos, void *is)
>  {
>  	struct index_state *istate = (struct index_state *)is;
>  	struct cache_entry *ce;
>  
> -	if (pos >= istate->cache_nr)
> -		BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" >= %u)",
> -		    (uintmax_t)pos, istate->cache_nr);
> +	assert_index_minimum(istate, pos);
>  
>  	ce = istate->cache[pos];
>  	ce->ce_flags &= ~CE_FSMONITOR_VALID;
> @@ -82,10 +87,8 @@ int read_fsmonitor_extension(struct index_state *istate, const void *data,
>  	}
>  	istate->fsmonitor_dirty = fsmonitor_dirty;
>  
> -	if (!istate->split_index &&
> -	    istate->fsmonitor_dirty->bit_size > istate->cache_nr)
> -		BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" > %u)",
> -		    (uintmax_t)istate->fsmonitor_dirty->bit_size, istate->cache_nr);
> +	if (!istate->split_index)
> +		assert_index_minimum(istate, istate->fsmonitor_dirty->bit_size);
>  
>  	trace_printf_key(&trace_fsmonitor, "read fsmonitor extension successful");
>  	return 0;
> @@ -110,10 +113,8 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate)
>  	uint32_t ewah_size = 0;
>  	int fixup = 0;
>  
> -	if (!istate->split_index &&
> -	    istate->fsmonitor_dirty->bit_size > istate->cache_nr)
> -		BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" > %u)",
> -		    (uintmax_t)istate->fsmonitor_dirty->bit_size, istate->cache_nr);
> +	if (!istate->split_index)
> +		assert_index_minimum(istate, istate->fsmonitor_dirty->bit_size);
>  
>  	put_be32(&hdr_version, INDEX_EXTENSION_VERSION2);
>  	strbuf_add(sb, &hdr_version, sizeof(uint32_t));
> @@ -335,9 +336,7 @@ void tweak_fsmonitor(struct index_state *istate)
>  			}
>  
>  			/* Mark all previously saved entries as dirty */
> -			if (istate->fsmonitor_dirty->bit_size > istate->cache_nr)
> -				BUG("fsmonitor_dirty has more entries than the index (%"PRIuMAX" > %u)",
> -				    (uintmax_t)istate->fsmonitor_dirty->bit_size, istate->cache_nr);
> +			assert_index_minimum(istate, istate->fsmonitor_dirty->bit_size);
>  			ewah_each_bit(istate->fsmonitor_dirty, fsmonitor_ewah_callback, istate);
>  
>  			refresh_fsmonitor(istate);

  reply	other threads:[~2021-01-22 22:32 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 16:53 [PATCH 0/9] More index cleanups Derrick Stolee via GitGitGadget
2021-01-20 16:53 ` [PATCH 1/9] cache-tree: clean up cache_tree_update() Derrick Stolee via GitGitGadget
2021-01-20 17:21   ` Elijah Newren
2021-01-20 19:10     ` Derrick Stolee
2021-01-20 16:53 ` [PATCH 2/9] cache-tree: extract subtree_pos() Derrick Stolee via GitGitGadget
2021-01-20 17:23   ` Elijah Newren
2021-01-20 16:53 ` [PATCH 3/9] fsmonitor: de-duplicate BUG()s around dirty bits Derrick Stolee via GitGitGadget
2021-01-20 17:26   ` Elijah Newren
2021-01-21 12:53   ` Chris Torek
2021-01-21 15:56     ` Derrick Stolee
2021-01-20 16:53 ` [PATCH 4/9] repository: add repo reference to index_state Derrick Stolee via GitGitGadget
2021-01-20 17:46   ` Elijah Newren
2021-01-20 19:16     ` Derrick Stolee
2021-01-20 19:50       ` Elijah Newren
2021-01-20 16:53 ` [PATCH 5/9] name-hash: use trace2 regions for init Derrick Stolee via GitGitGadget
2021-01-20 17:47   ` Elijah Newren
2021-01-20 16:53 ` [PATCH 6/9] sparse-checkout: load sparse-checkout patterns Derrick Stolee via GitGitGadget
2021-01-20 17:54   ` Elijah Newren
2021-01-20 16:53 ` [PATCH 7/9] sparse-checkout: hold pattern list in index Derrick Stolee via GitGitGadget
2021-01-20 18:03   ` Elijah Newren
2021-01-20 19:22     ` Derrick Stolee
2021-01-20 16:53 ` [PATCH 8/9] test-lib: test_region looks for trace2 regions Derrick Stolee via GitGitGadget
2021-01-20 18:20   ` Elijah Newren
2021-01-20 19:24     ` Derrick Stolee
2021-01-20 16:53 ` [PATCH 9/9] t1092: test interesting sparse-checkout scenarios Derrick Stolee via GitGitGadget
2021-01-20 19:40   ` Elijah Newren
2021-01-21 11:59     ` Derrick Stolee
2021-01-22 13:03 ` [PATCH v2 0/8] More index cleanups Derrick Stolee via GitGitGadget
2021-01-22 13:03   ` [PATCH v2 1/8] cache-tree: clean up cache_tree_update() Derrick Stolee via GitGitGadget
2021-01-22 19:11     ` Junio C Hamano
2021-01-22 13:03   ` [PATCH v2 2/8] cache-tree: extract subtree_pos() Derrick Stolee via GitGitGadget
2021-01-22 13:03   ` [PATCH v2 3/8] fsmonitor: de-duplicate BUG()s around dirty bits Derrick Stolee via GitGitGadget
2021-01-22 19:18     ` Junio C Hamano [this message]
2021-01-22 13:03   ` [PATCH v2 4/8] repository: add repo reference to index_state Derrick Stolee via GitGitGadget
2021-01-22 19:23     ` Junio C Hamano
2021-01-22 13:03   ` [PATCH v2 5/8] name-hash: use trace2 regions for init Derrick Stolee via GitGitGadget
2021-01-22 13:03   ` [PATCH v2 6/8] sparse-checkout: load sparse-checkout patterns Derrick Stolee via GitGitGadget
2021-01-22 13:03   ` [PATCH v2 7/8] test-lib: test_region looks for trace2 regions Derrick Stolee via GitGitGadget
2021-01-22 19:42     ` Junio C Hamano
2021-01-23 18:36       ` Derrick Stolee
2021-01-23 18:50         ` Junio C Hamano
2021-01-22 13:03   ` [PATCH v2 8/8] t1092: test interesting sparse-checkout scenarios Derrick Stolee via GitGitGadget
2021-01-22 19:49   ` [PATCH v2 0/8] More index cleanups Elijah Newren
2021-01-23 18:47     ` Derrick Stolee
2021-01-23 19:58   ` [PATCH v3 0/9] " Derrick Stolee via GitGitGadget
2021-01-23 19:58     ` [PATCH v3 1/9] cache-tree: clean up cache_tree_update() Derrick Stolee via GitGitGadget
2021-01-23 19:58     ` [PATCH v3 2/9] cache-tree: simplify verify_cache() prototype Derrick Stolee via GitGitGadget
2021-01-23 20:24       ` Elijah Newren
2021-01-23 21:02         ` Derrick Stolee
2021-01-23 21:10           ` Elijah Newren
2021-01-23 21:41           ` Junio C Hamano
2021-01-23 21:10         ` Junio C Hamano
2021-01-23 21:14           ` Derrick Stolee
2021-01-23 19:58     ` [PATCH v3 3/9] cache-tree: extract subtree_pos() Derrick Stolee via GitGitGadget
2021-01-23 19:58     ` [PATCH v3 4/9] fsmonitor: de-duplicate BUG()s around dirty bits Derrick Stolee via GitGitGadget
2021-01-23 19:58     ` [PATCH v3 5/9] repository: add repo reference to index_state Derrick Stolee via GitGitGadget
2021-01-23 19:58     ` [PATCH v3 6/9] name-hash: use trace2 regions for init Derrick Stolee via GitGitGadget
2021-01-23 19:58     ` [PATCH v3 7/9] sparse-checkout: load sparse-checkout patterns Derrick Stolee via GitGitGadget
2021-01-23 19:58     ` [PATCH v3 8/9] test-lib: test_region looks for trace2 regions Derrick Stolee via GitGitGadget
2021-01-23 21:07       ` Derrick Stolee
2021-01-23 19:58     ` [PATCH v3 9/9] t1092: test interesting sparse-checkout scenarios Derrick Stolee via GitGitGadget
2021-01-25 18:45       ` Elijah Newren
2021-01-23 20:29     ` [PATCH v3 0/9] More index cleanups Elijah Newren
2021-01-23 21:05       ` Derrick Stolee
2021-01-23 21:42         ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqh7n893vx.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=derrickstolee@github.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=newren@gmail.com \
    --cc=stolee@gmail.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).