Repository navigation
Conversation
On Linux, replace the tar process in the zstd | tar restore pipeline with an in-process extractor that writes file contents from a pool of goroutines while keeping GNU tar's -xp semantics and archive order. Other platforms keep the zstd | tar pipeline. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b29e4305c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
- Read inode identity from syscall.Stat_t, which is what os returns, so replaced placeholders and freed inodes are detected. - Treat a directory reached through a symlink as possibly aliased, so its delayed metadata is applied before an entry under the real path. - Apply PAX global headers to later members, as GNU tar does. - Reject empty archives and archives cut off inside member padding. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f2aaec296b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Release binaries are built with CGO_ENABLED=0, where os/user only reads /etc/passwd and /etc/group. GNU tar resolves names with getpwnam, so as root it maps LDAP or SSSD names that os/user misses. Look names up with getent first, which queries NSS, and fall back to os/user when it is unavailable. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff04f9c952
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…celled lookups A directory member named "d/." kept that name on the directory stack, so the next entry "d/file" looked like it was outside it. A read-only "d" got its mode before the file was created and the restore failed, and a writable one lost its archived mtime. The trailing "/." is now stripped, as GNU tar ends up doing, and an unlisted parent skips its final chmod when it was created with the archived mode, since GNU tar compares against the mode it cached at creation. Paths were passed to the kernel as destination + member name, so a member whose name fits in PATH_MAX failed under a long destination. All filesystem calls now go through a descriptor for the destination with the *at syscalls, as GNU tar does after -C. getent lookups ran without the Extract context, so a cancelled restore still waited on a slow NSS backend. They now use exec.CommandContext and stop before the os/user fallback. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
f113eff to
8a7a55f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a7a55f182
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…and NSS aliases Open the destination exactly as the caller passed it. Cleaning it first turned "base/link/../dest" into "base/dest", while tar -C resolves the symlink and then "..", so members landed in a different directory. Handle a member name ending in "/." the way GNU tar does. For a directory, mkdir resolves a symlink at the parent component, so a link to a directory is kept and members are written through it, while a dangling link or a file fails. Every non-directory at such a name fails, because nothing but a directory can exist there. A hard link whose target ends in "/" or "/." fails with ENOTDIR. Accept the record NSS returns for a user or group name even when it is spelled differently (an alias resolving to its canonical entry). The name check is still applied to keys getent would treat as numeric IDs, which getpwnam and getgrnam don't. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 11246ab167
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…ore writing through symlinks A deferred link's placeholder can also be removed through a symlinked path (alias -> ., then alias/u). Only the literal path marked it replaced, so if a later file reused the freed inode number, the final pass mistook it for the placeholder and replaced it with the link. Forget a placeholder whenever it is removed, whatever path reached it. When an entry's path goes through a symlink, directories GNU tar has already finished were applied only after missing parents had been created through the link. A new subdirectory decides its setgid bit and group at mkdir, so under a setgid directory reached through a symlink it missed both. Apply finished directories as soon as the symlink is found. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
…nly path A placeholder created through a symlinked path is recorded under that path, so two cases still missed it: - A regular file written to the literal path goes to a writer goroutine, which removes the placeholder without forgetting it. If the new file reused the freed inode number, the final pass turned it back into the link. Once any placeholder has been made through a symlink, check the target's inode before queueing the write. - When a duplicate deferred link finds a placeholder already in place, keepDelayed revived the newest replaced entry with the same path, which could be one removed earlier through an alias. Only undo the claim the current entry made. GNU tar has the same exposure when inodes are reused; on tmpfs, which never reuses them, it produces the results the new tests expect. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dfa38f9d9c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…odes Two directory-mode differences from GNU tar 1.35 with -p: - When the umask masks owner bits, the chmod that undoes it dropped a set-group-ID bit inherited from the parent, so the directory lost it and its subdirectories lost the group. Keep the inherited special bits. - GNU tar skips a directory's final chmod when the archived mode equals the mode it last saw for that record: the mode it made it with or, for an existing directory, the mode it found. Records of existing directories now keep that mode too, read after finished directories are applied. A missing "d/." is created the way GNU tar does, as a missing parent whose record then takes the entry's metadata. Repeated "d/./" headers, or a revisited directory followed by "d/./", now end with GNU tar's mode. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e6fccfc454
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…read When the umask masks owner bits, the chmod that undoes it cannot keep an inherited set-group-ID bit for a caller outside the directory's group: Linux clears S_ISGID on chmod by a non-member, so subdirectories and files lose the group. GNU tar avoids this because -p clears the umask before mkdir. Directories whose mode the umask would change are now created by a locked thread that unshares its filesystem attributes and clears its own umask, so the process umask is untouched. Missing parents follow GNU tar's make_directories and get owner rwx while children are written. Where unshare is refused, such as under Docker's default seccomp profile, extraction keeps the previous mkdir and chmod path. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d66fe6529e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
… and links Two differences from GNU tar 1.35 with -p for directories created as missing parents: - A default POSIX ACL replaces the umask when a directory is created, so reading the mode back after mkdir could leave a parent group- or world-writable. GNU tar's make_directories computes the mode from the umask instead; do the same, and read it back only when the umask can't be read. - From the first directory held back for deferred links, GNU tar rereads each directory's mode before restoring it. Implicit parents skipped that when the mode matched the one they were created with, so a later header for the same directory under another name could leave its mode in place. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad86f0bda6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
GNU tar 1.35 ignores an empty path value and keeps the member's own name, so an archive whose global header sets path= extracts normally. Applying it cleared every later member's name, which then resolved to the destination and failed the restore. Signed-off-by: Ravi Agarwal <ravi@perplexity.ai> Co-authored-by: Perplexity <noreply@perplexity.ai>
|
@codex review Created with Perplexity |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
Can you try this on a much larger tarball? eg. the Linux kernel? This is a lot of code, and is much more complex, so the performance gains would have to be significant to warrant it. A 0.2s difference doesn't really justify it. |
Agreed, the gain doesn't justify this much code, so I'm closing this. Most of the restore time on the trees I measured is decompression. Snapshots are written with I think @worstell already has it on |
client.Extractrestores every snapshot, including git snapshots throughinternal/snapshot, by pipingzstd -dcintotar -xpf -. For trees with many files,taris the slow step, because it creates, writes, chmods and closes each file one at a time on a single thread. Decoding a 651 MB git snapshot of golang/go takes 0.28s on its own, while the full restore takes 0.65s, so most of the restore is spent waiting ontar.On Linux, this PR replaces the
tarprocess with an in-process extractor that writes files in parallel.zstdstill does the decoding. Other platforms keep thezstd | tarpipeline unchanged, inextract_other.go.Relation to #448
#448 removed the in-process extractor from #418 because it was slower than system
taron trees of many small files, and because it rejected absolute and out-of-tree symlinks. This extractor doesn't have either problem:..symlinks are restored as GNU tar restores them, andExtractkeeps the trusted-input contract that fix(client): restore system tar for extraction #448 documented.TestArchiveExtractPreservesOutOfTreeSymlinks, the test fix(client): restore system tar for extraction #448 added, passes unchanged.zstd | taron the trees below. fix(client): restore system tar for extraction #448's benchmark was on macOS, which this PR doesn't change.Change
archive/tarand handles directories, links, devices, FIFOs and metadata in archive order. File contents are written concurrently:min(GOMAXPROCS, 8)writer goroutines.delay_set_stat. This lets read-only directories, such as Hermit package trees, extract correctly...target, and hard links to them, are created as placeholder files and turned into links at the end, as GNU tar does. A later entry therefore can't write through them.*atsyscalls, relative to a descriptor for the destination directory, as GNU tar does after-C...in it resolves as it does fortar -C.PATH_MAX, so a deep member under a long destination path still extracts.getent, so LDAP and SSSD users, and aliases that NSS maps to a canonical entry, resolve as they do for GNU tar. This holds even in static builds, whereos/useronly reads/etc/passwdand/etc/group.Extractcontext, so a cancelled restore doesn't wait on a slow NSS backend.golang.org/x/sysmoves from an indirect to a direct dependency.Compatibility with
tar -xpThe extractor targets the
-xpbehaviour of GNU tar 1.35, which is what the existing pipeline gets on a typical Linux host. It covers:/and..prefixes, trailing slashes, trailing.components);/.(a directory there follows a symlink to a directory; anything else fails);Empty and truncated archives fail, as they do with GNU tar.
Known differences:
Extractreturns an error.-pclears the umask. Doing that for the whole process would affect every other goroutine, so the extractor reads the umask from/proc/self/statusand applies each archived mode with an explicit chmod.CLONE_FS) and clears only its own umask. New subdirectories and files then inherit a setgid directory's group, as they do with GNU tar.unshareis refused, as under Docker's default seccomp profile, those directories are chmodded after creation, keeping any set-group-ID bit they inherited. Linux clears that bit on chmod when the caller isn't in the directory's group, so in that case new subdirectories and files don't inherit the group.sizeorGNU.sparse.*record is rejected, becausearchive/tarhas already sized each member from its own header.--xattrs,--aclsand--selinux, which the current pipeline doesn't pass.Performance
Median of 7 restores into an empty directory on Linux x86_64 (Xeon Platinum 8488C, ext4 on NVMe, zstd 1.5.7):
zstd | tar-Tsays. Decoding is now most of that restore, so a parallel decoder would be a separate follow-up.Testing
TestExtractMatchesGNUTarbuilds archives, extracts each one with the system GNU tar and withExtract, and compares the resulting trees by type, mode, link count, content hash, link target and mtime. It is skipped whentarisn't GNU tar, and when running as root. Its cases cover:..links;pathrecord;/.: repeated ones, ones through symlinks to directories, dangling symlinks and files, and files, symlinks, FIFOs and hard links at such names, plus hard links to names ending in/or/.;TestExtractLongMemberNamesruns the same comparison for members whose names fit inPATH_MAXbut whose full paths under the destination don't.TestExtractOpensDestinationAsGivencovers a destination path with..after a symlink.TestExtractKeepsSetgidGroupForNonMemberruns as root and re-runs the test binary as an unprivileged user outside the group of a setgid destination, under a umask that masks owner bits. It checks that new directories and files keep the group.TestUnmaskedMkdirKeepsProcessUmaskchecks that the private thread leaves the process umask alone.TestMkdirWithoutUnmaskedThreadKeepsInheritedSetgidcovers the chmod fallback, andTestImplicitParentWithUnreadableUmaskKeepsCreatedModecovers missing parents when the umask can't be read.TestExtractRejectsIncompleteArchiveandTestExtractRejectsGlobalDataLayoutRecordscover the archives that must fail.TestOwnerLookupUsesNSScovers owner names that only NSS knows, aliases NSS resolves to a canonical name, and numeric keys.TestOwnerLookupStopsWhenCancelledcovers a lookup that hangs until the context is cancelled. Both use a stubgetent.TestExtractLaterEntryReplacesUnsafeSymlinkcovers a later entry that replaces a deferred unsafe symlink, including when the placeholder's inode number is reused and when the placeholder is created or replaced through a symlinked path.Created with Perplexity