git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 4/7] reftable/stack: stop using `fsync_component()` directly

From
Justin Tobler <jltobler@gmail.com>
Date
Nov 8, 2024, 02:09 UTC
Message-ID
<6ghxx5fmuzujegducuva77vpybihz6b5cnk75wdgv4pv2knac5@m3trfmg2dk5s>
In-Reply-To
<86269fc4fcad9a97709aa0d080c4c077a85ca667.1729677003.git.ps@pks.im>

On 24/10/23 11:56AM, Patrick Steinhardt wrote: [snip]

Show 29 quoted lines
> diff --git a/reftable/stack.c b/reftable/stack.c
> index 9ae716ff375..df4f3237007 100644
> --- a/reftable/stack.c
> +++ b/reftable/stack.c
> @@ -8,7 +8,6 @@ license that can be found in the LICENSE file or at
>  
>  #include "stack.h"
>  
> -#include "../write-or-die.h"
>  #include "system.h"
>  #include "constants.h"
>  #include "merged.h"
> @@ -43,17 +42,28 @@ static int stack_filename(struct reftable_buf *dest, struct reftable_stack *st,
>  	return 0;
>  }
>  
> -static ssize_t reftable_fd_write(void *arg, const void *data, size_t sz)
> +static int stack_fsync(struct reftable_stack *st, int fd)
>  {
> -	int *fdp = (int *)arg;
> -	return write_in_full(*fdp, data, sz);
> +	if (st->opts.fsync)
> +		return st->opts.fsync(fd);
> +	return fsync(fd);
>  }
>  
> -static int reftable_fd_flush(void *arg)
> +struct fd_writer {
> +	struct reftable_stack *stack;

Out of curiousity, from the stack I think we only need the callback in the options. Any reason we provide the whole stack here?

Show 11 quoted lines
> +	int fd;
> +};
> +
> +static ssize_t fd_writer_write(void *arg, const void *data, size_t sz)
>  {
> -	int *fdp = (int *)arg;
> +	struct fd_writer *writer = arg;
> +	return write_in_full(writer->fd, data, sz);
> +}
>  
> -	return fsync_component(FSYNC_COMPONENT_REFERENCE, *fdp);

Previously when the writer was flushed it would invoke `fsync_component()`. Now that a callback can be configured in the stack options, the callback needs to also be propagated to `fd_writer_write()` in addition to the file descriptor being synced. This explains why `fd_writer` is now used.

The rest of the patch updates writer configuration and fsync call sites. Looks good.

-Justin
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 10 of 43 in “reftable: stop using Git subsystems”
  1. 0/7 reftable: stop using Git subsystemsPatrick Steinhardt, Oct 23, 2024
  2. 1/7 reftable/system: move "dir.h" to its only userPatrick Steinhardt, Oct 23, 2024
  3. Eric SunshineOct 24, 2024
  4. 2/7 reftable: explicitly handle hash format IDsPatrick Steinhardt, Oct 23, 2024
  5. Justin ToblerNov 7, 2024
  6. 3/7 reftable/system: stop depending on "hash.h"Patrick Steinhardt, Oct 23, 2024
  7. Justin ToblerNov 8, 2024
  8. Patrick SteinhardtNov 8, 2024
  9. 4/7 reftable/stack: stop using `fsync_component()` directlyPatrick Steinhardt, Oct 23, 2024
  10. Justin ToblerNov 8, 2024
  11. Patrick SteinhardtNov 8, 2024
  12. 5/7 reftable/system: provide thin wrapper for tempfile subsystemPatrick Steinhardt, Oct 23, 2024
  13. 6/7 reftable/stack: drop only use of `get_locked_file_path()`Patrick Steinhardt, Oct 23, 2024
  14. 7/7 reftable/system: provide thin wrapper for lockfile subsystemPatrick Steinhardt, Oct 23, 2024
  15. 0/7 reftable: stop using Git subsystemsPatrick Steinhardt, Nov 8, 2024
  16. 1/7 reftable/system: move "dir.h" to its only userPatrick Steinhardt, Nov 8, 2024
  17. 2/7 reftable: explicitly handle hash format IDsPatrick Steinhardt, Nov 8, 2024
  18. karthik nayakNov 18, 2024
  19. 3/7 reftable/system: stop depending on "hash.h"Patrick Steinhardt, Nov 8, 2024
  20. Junio C HamanoNov 12, 2024
  21. karthik nayakNov 18, 2024
  22. 4/7 reftable/stack: stop using `fsync_component()` directlyPatrick Steinhardt, Nov 8, 2024
  23. karthik nayakNov 18, 2024
  24. Patrick SteinhardtNov 18, 2024
  25. 5/7 reftable/system: provide thin wrapper for tempfile subsystemPatrick Steinhardt, Nov 8, 2024
  26. karthik nayakNov 18, 2024
  27. karthik nayakNov 18, 2024
  28. 6/7 reftable/stack: drop only use of `get_locked_file_path()`Patrick Steinhardt, Nov 8, 2024
  29. 7/7 reftable/system: provide thin wrapper for lockfile subsystemPatrick Steinhardt, Nov 8, 2024
  30. Justin ToblerNov 8, 2024
  31. Junio C HamanoNov 11, 2024
  32. karthik nayakNov 18, 2024
  33. Patrick SteinhardtNov 18, 2024
  34. 0/7 reftable: stop using Git subsystemsPatrick Steinhardt, Nov 18, 2024
  35. 1/7 reftable/system: move "dir.h" to its only userPatrick Steinhardt, Nov 18, 2024
  36. 2/7 reftable: explicitly handle hash format IDsPatrick Steinhardt, Nov 18, 2024
  37. 3/7 reftable/system: stop depending on "hash.h"Patrick Steinhardt, Nov 18, 2024
  38. 4/7 reftable/stack: stop using `fsync_component()` directlyPatrick Steinhardt, Nov 18, 2024
  39. 5/7 reftable/system: provide thin wrapper for tempfile subsystemPatrick Steinhardt, Nov 18, 2024
  40. 6/7 reftable/stack: drop only use of `get_locked_file_path()`Patrick Steinhardt, Nov 18, 2024
  41. 7/7 reftable/system: provide thin wrapper for lockfile subsystemPatrick Steinhardt, Nov 18, 2024
  42. karthik nayakNov 19, 2024
  43. Junio C HamanoNov 20, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.