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

Re: [PATCH 2/2] packfile: replace lseek+read with pread

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 26, 2019, 18:23 UTC
Message-ID
<xmqqzhffkku2.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20191226104220.27325-3-e@80x24.org>
Eric Wong <e@80x24.org> writes:
Show 6 quoted lines
> We already have pread emulation for portability, so there's
> there's no reason to make two syscalls where one suffices.
>
> Furthermore, readers of the packfile will be using mmap
> (or pread to emulate mmap), anyways, so the file description
> offset does not matter in this case.
s/description/descriptor/ probably.

After seeking to the packfile trailer and reading the pack id hash using lseek+read, this helper function does not read from the file descriptor, and the sole caller of it closes the file descriptor immediately after it returns, which means the read file offset after reading the packfile trailer does not matter.

So this conversion is correct.  Thanks for a careful analysis.
Will queue both patches.
Show 21 quoted lines
> Signed-off-by: Eric Wong <e@80x24.org>
> ---
>  packfile.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/packfile.c b/packfile.c
> index 1821cb7a3d..7e7c04e4d8 100644
> --- a/packfile.c
> +++ b/packfile.c
> @@ -576,9 +576,8 @@ static int open_packed_git_1(struct packed_git *p)
>  			     " while index indicates %"PRIu32" objects",
>  			     p->pack_name, ntohl(hdr.hdr_entries),
>  			     p->num_objects);
> -	if (lseek(p->pack_fd, p->pack_size - hashsz, SEEK_SET) == -1)
> -		return error("end of packfile %s is unavailable", p->pack_name);
> -	read_result = read_in_full(p->pack_fd, hash, hashsz);
> +	read_result = pread_in_full(p->pack_fd, hash, hashsz,
> +					p->pack_size - hashsz);
>  	if (read_result < 0)
>  		return error_errno("error reading from %s", p->pack_name);
>  	if (read_result != hashsz)
Previous: Eric WongNext: Junio C Hamano
Message 4 of 6 in “packfile: small syscall reductions”
  1. 0/2 packfile: small syscall reductionsEric Wong, Dec 26, 2019
  2. 1/2 packfile: remove redundant fcntl F_GETFD/F_SETFDEric Wong, Dec 26, 2019
  3. 2/2 packfile: replace lseek+read with preadEric Wong, Dec 26, 2019
  4. Junio C HamanoDec 26, 2019
  5. Junio C HamanoDec 26, 2019
  6. Eric WongDec 26, 2019

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.