<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/reftable/stack.c, branch v2.48.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.48.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.48.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2024-12-28T16:00:44Z</updated>
<entry>
<title>reftable: avoid leaks on realloc error</title>
<updated>2024-12-28T16:00:44Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2024-12-28T09:47:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8db127d43f5b0eff254a851f9c966b7b85d91992'/>
<id>urn:sha1:8db127d43f5b0eff254a851f9c966b7b85d91992</id>
<content type='text'>
When realloc(3) fails, it returns NULL and keeps the original allocation
intact.  REFTABLE_ALLOC_GROW overwrites both the original pointer and
the allocation count variable in that case, simultaneously leaking the
original allocation and misrepresenting the number of storable items.

parse_names() and reftable_buf_add() avoid leaking by restoring the
original pointer value on failure, but all other callers seem to be OK
with losing the old allocation.  Add a new variant of the macro,
REFTABLE_ALLOC_GROW_OR_NULL, which plugs the leak and zeros the
allocation counter.  Use it for those callers.

Signed-off-by: René Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'ps/reftable-alloc-failures-zalloc-fix'</title>
<updated>2024-12-23T17:32:06Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-12-23T17:32:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3151e6a1214b583552ca39c57d429a8eaa8923e8'/>
<id>urn:sha1:3151e6a1214b583552ca39c57d429a8eaa8923e8</id>
<content type='text'>
Recent reftable updates mistook a NULL return from a request for
0-byte allocation as OOM and died unnecessarily, which has been
corrected.

* ps/reftable-alloc-failures-zalloc-fix:
  reftable/basics: return NULL on zero-sized allocations
  reftable/stack: fix zero-sized allocation when there are no readers
  reftable/merged: fix zero-sized allocation when there are no readers
  reftable/stack: don't perform auto-compaction with less than two tables
</content>
</entry>
<entry>
<title>reftable/stack: fix zero-sized allocation when there are no readers</title>
<updated>2024-12-22T08:58:23Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-12-22T07:24:30Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=2d3cb4b4b5401e2fd5a40600277f424032fc72f0'/>
<id>urn:sha1:2d3cb4b4b5401e2fd5a40600277f424032fc72f0</id>
<content type='text'>
Similar as the preceding commit, we may try to do a zero-sized
allocation when reloading a reftable stack that ain't got any tables.
It is implementation-defined whether malloc(3p) returns a NULL pointer
in that case or a zero-sized object. In case it does return a NULL
pointer though it causes us to think we have run into an out-of-memory
situation, and thus we return an error.

Fix this by only allocating arrays when they have at least one entry.

Reported-by: Randall S. Becker &lt;rsbecker@nexbridge.com&gt;
Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: don't perform auto-compaction with less than two tables</title>
<updated>2024-12-22T08:58:23Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-12-22T07:24:28Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8e27ee9220883cf5a0629c752e1642daaba4ce14'/>
<id>urn:sha1:8e27ee9220883cf5a0629c752e1642daaba4ce14</id>
<content type='text'>
In order to compact tables we need at least two tables. Bail out early
from `reftable_stack_auto_compact()` in case we have less than two
tables.

In the original, `stack_table_sizes_for_compaction()` yields an array
that has the same length as the number of tables. This array is then
passed on to `suggest_compaction_segment()`, which returns an empty
segment in case we have less than two tables. The segment is then passed
to `segment_size()`, which will return `0` because both start and end of
the segment are `0`. And because we only call `stack_compact_range()` in
case we have a positive segment size we don't perform auto-compaction at
all. Consequently, this change does not result in a user-visible change
in behaviour when called with a single table.

But when called with no tables this protects us against a potential
out-of-memory error: `stack_table_sizes_for_compaction()` would try to
allocate a zero-byte object when there aren't any tables, and that may
lead to a `NULL` pointer on some platforms like NonStop which causes us
to bail out with an out-of-memory error.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: add mechanism to notify callers on reload</title>
<updated>2024-11-26T08:18:38Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-11-26T06:42:59Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=eb22c1b46b85f7fac8467f991890d50853e4ca4d'/>
<id>urn:sha1:eb22c1b46b85f7fac8467f991890d50853e4ca4d</id>
<content type='text'>
Reftable stacks are reloaded in two cases:

  - When calling `reftable_stack_reload()`, if the stat-cache tells us
    that the stack has been modified.

  - When committing a reftable addition.

While callers can figure out the second case, they do not have a
mechanism to figure out whether `reftable_stack_reload()` led to an
actual reload of the on-disk data. All they can do is thus to assume
that data is always being reloaded in that case.

Improve the situation by introducing a new `on_reload()` callback to the
reftable options. If provided, the function will be invoked every time
the stack has indeed been reloaded. This allows callers to invalidate
data that depends on the current stack data.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: add accessor for the hash ID</title>
<updated>2024-11-26T08:18:36Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-11-26T06:42:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c9f76fc7d197d9ed2624400d5fc34d6ab53b7a22'/>
<id>urn:sha1:c9f76fc7d197d9ed2624400d5fc34d6ab53b7a22</id>
<content type='text'>
Add an accessor function that allows callers to access the hash ID of a
reftable stack. This function will be used in a subsequent commit.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/system: provide thin wrapper for lockfile subsystem</title>
<updated>2024-11-19T03:23:11Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-11-18T15:34:08Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=988e7f5e952bbb7b6ae885f4da744f536f22693f'/>
<id>urn:sha1:988e7f5e952bbb7b6ae885f4da744f536f22693f</id>
<content type='text'>
We use the lockfile subsystem to write lockfiles for "tables.list". As
with the tempfile subsystem, the lockfile subsystem also hooks into our
infrastructure to prune stale locks via atexit(3p) or signal handlers.

Furthermore, the lockfile subsystem also handles locking timeouts, which
do add quite a bit of logic. Having to reimplement that in the context
of Git wouldn't make a whole lot of sense, and it is quite likely that
downstream users of the reftable library may have a better idea for how
exactly to implement timeouts.

So again, provide a thin wrapper for the lockfile subsystem instead such
that the compatibility shim is fully self-contained.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: drop only use of `get_locked_file_path()`</title>
<updated>2024-11-19T03:23:10Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-11-18T15:34:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6361226b79d24eb93a14e0b7d25f584269f9d5e6'/>
<id>urn:sha1:6361226b79d24eb93a14e0b7d25f584269f9d5e6</id>
<content type='text'>
We've got a single callsite where we call `get_locked_file_path()`. As
we're about to convert our usage of the lockfile subsystem to instead be
used via a compatibility shim we'd have to implement more logic for this
single callsite. While that would be okay if Git was the only supposed
user of the reftable library, it's a bit more awkward when considering
that we have to reimplement this functionality for every user of the
library eventually.

Refactor the code such that we don't call `get_locked_file_path()`
anymore.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/system: provide thin wrapper for tempfile subsystem</title>
<updated>2024-11-19T03:23:10Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-11-18T15:34:03Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=01e49941d6560dfebfac39a2ffe49d3d24b35069'/>
<id>urn:sha1:01e49941d6560dfebfac39a2ffe49d3d24b35069</id>
<content type='text'>
We use the tempfile subsystem to write temporary tables, but given that
we're in the process of converting the reftable library to become
standalone we cannot use this subsystem directly anymore. While we could
in theory convert the code to use mkstemp(3p) instead, we'd lose access
to our infrastructure that automatically prunes tempfiles via atexit(3p)
or signal handlers.

Provide a thin wrapper for the tempfile subsystem instead. Like this,
the compatibility shim is fully self-contained in "reftable/system.c".
Downstream users of the reftable library would have to implement their
own tempfile shims by replacing "system.c" with a custom version.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>reftable/stack: stop using `fsync_component()` directly</title>
<updated>2024-11-19T03:23:10Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-11-18T15:34:00Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=86b770b0bbf1aba3c8e43401936258c58648703a'/>
<id>urn:sha1:86b770b0bbf1aba3c8e43401936258c58648703a</id>
<content type='text'>
We're executing `fsync_component()` directly in the reftable library so
that we can fsync data to disk depending on "core.fsync". But as we're
in the process of converting the reftable library to become standalone
we cannot use that function in the library anymore.

Refactor the code such that users of the library can inject a custom
fsync function via the write options. This allows us to get rid of the
dependency on "write-or-die.h".

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
