Skip to content

fix(erofs): set TMPDIR for mkfs.erofs on Windows#13008

Merged
mxpv merged 1 commit into
containerd:mainfrom
chelnak:fix-erofs-tmpdir
May 11, 2026
Merged

fix(erofs): set TMPDIR for mkfs.erofs on Windows#13008
mxpv merged 1 commit into
containerd:mainfrom
chelnak:fix-erofs-tmpdir

Conversation

@chelnak

@chelnak chelnak commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Summary

On Windows, mkfs.erofs (MinGW binary) reads TMPDIR for its diskbuf temp files. Windows does not set TMPDIR, so mkfs.erofs falls back to /tmp which resolves to C:\tmp for a native MinGW binary. C:\tmp doesn't exist on most Windows machines — mkstemp fails and erofs_diskbuf_init returns ENOSPC regardless of actual errno, producing a misleading "No space left on device" error even on disks with plenty of free space.

Fix

Set TMPDIR to the snapshot directory (parent of the output layer.erofs file) for all mkfs.erofs invocations on Windows. On Unix, behavior is unchanged (nil env inherits parent process).

Why not os.TempDir()?

On Windows os.TempDir() falls back to C:\Windows\Temp when TMP/TEMP/USERPROFILE are all unset (e.g. service contexts). The snapshot dir is always valid — containerd creates it before calling the differ.

Verified

TMPDIR C:\tmp exists Result
nonexistent dir yes ENOSPC (bug)
valid dir (backslashes) yes OK
valid dir (forward slashes) yes OK
dir with spaces yes OK
unset no ENOSPC (real-world bug)

@hsiangkao

hsiangkao commented Mar 10, 2026

Copy link
Copy Markdown
Member

where is ‘mkfs.erofs (MinGW binary)’?
Do we have some commits so that we could enable windows builds officially?

@dmcgowan

Copy link
Copy Markdown
Member

@hsiangkao I think we could add some instructions. We should add some erofs snapshot/unpack tests that can run on Windows and Mac for erofs without requiring a mount.

@hsiangkao

hsiangkao commented Mar 10, 2026

Copy link
Copy Markdown
Member

@hsiangkao I think we could add some instructions. We should add some erofs snapshot/unpack tests that can run on Windows and Mac for erofs without requiring a mount.

sorry, I meant currently erofs-utils doesn't enable windows builds offically (I never tried MinGW or Cygwin).
I prefer MinGW but never find time to work it out, I mean do you have erofs-utils commits to make MinGW builds work (so I could merge them and even add github windows binary builds when releasing)?

@dmcgowan

Copy link
Copy Markdown
Member

@hsiangkao yeah, I'll collect those and get those over to the upstream to see whether can include that. We would need that before building it for this project it looks like.

github-actions Bot added a commit to dmcgowan/containerd that referenced this pull request Mar 19, 2026
github-actions Bot added a commit to dmcgowan/containerd that referenced this pull request Mar 19, 2026
github-actions Bot added a commit to dmcgowan/containerd that referenced this pull request Apr 1, 2026
github-actions Bot added a commit to dmcgowan/containerd that referenced this pull request Apr 4, 2026
github-actions Bot added a commit to dmcgowan/containerd that referenced this pull request Apr 10, 2026
github-actions Bot added a commit to dmcgowan/containerd that referenced this pull request Apr 11, 2026
Copilot AI review requested due to automatic review settings April 15, 2026 14:59
github-actions Bot added a commit to dmcgowan/containerd that referenced this pull request Apr 15, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Apr 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Sets a Windows-specific environment override for mkfs.erofs so it uses a valid temp directory when creating diskbuf temporary files, preventing misleading ENOSPC failures caused by fallback to C:\tmp.

Changes:

  • Add mkfsEnv(layerPath) helper to inject TMPDIR on Windows.
  • Apply cmd.Env = mkfsEnv(layerPath) for all mkfs.erofs invocations in this package.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +49
func mkfsEnv(layerPath string) []string {
if runtime.GOOS != "windows" {
return nil
}
env := os.Environ()
tmpdir := filepath.Dir(layerPath)
env = append(env, "TMPDIR="+tmpdir)
return env
}

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: the new Windows-only TMPDIR behavior in mkfsEnv() isn’t covered by tests. A small unit test (e.g., mount_windows_test.go with a windows build tag) that asserts mkfsEnv returns an env slice containing TMPDIR= would help prevent regressions.

Copilot uses AI. Check for mistakes.
mkfs.erofs uses TMPDIR for its internal diskbuf temp files. Windows
does not set TMPDIR (only TEMP/TMP), so the MinGW binary falls back
to "/tmp" which resolves to C:\tmp. That directory does not exist on
most Windows machines. mkstemp fails, and erofs_diskbuf_init returns
ENOSPC regardless of actual errno, producing a misleading "No space
left on device" error even on disks with plenty of free space.

Set TMPDIR to the snapshot directory (parent of the output layer file)
for all mkfs.erofs invocations on Windows. This directory is managed
by containerd and guaranteed to exist. On Unix, TMPDIR is left to the
parent process (no change in behavior).

Signed-off-by: Craig Chelnak <[email protected]>
@austinvazquez
austinvazquez marked this pull request as ready for review April 22, 2026 22:08
Copilot AI review requested due to automatic review settings April 22, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +48
func mkfsEnv(layerPath string) []string {
if runtime.GOOS != "windows" {
return nil
}
env := os.Environ()
tmpdir := filepath.Dir(layerPath)
env = append(env, "TMPDIR="+tmpdir)
return env

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says TMPDIR is set for all mkfs.erofs invocations on Windows, but this helper is only applied to layer-generating commands in this file. There is still a mkfs.erofs invocation in SupportGenerateFromTar (mkfs.erofs --help) that does not set Env, and there’s also a mkfs.erofs invocation elsewhere in the repo (plugins/snapshots/erofs/erofs.go generateFsMeta). Either update those call sites (with a suitable TMPDIR, or document why they’re exempt) or adjust the PR description to match the actual scope so the original Windows failure mode can’t persist on other code paths.

Copilot uses AI. Check for mistakes.
@dmcgowan
dmcgowan added this pull request to the merge queue Apr 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 22, 2026
@mxpv
mxpv added this pull request to the merge queue May 11, 2026
args = append(args, layerPath)
cmd := exec.CommandContext(ctx, "mkfs.erofs", args...)
cmd.Stdin = r
cmd.Env = mkfsEnv(layerPath)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should append to cmd.Environ() - at least I recall that has special handling for windows (different from bare os.Environ()); https://pkg.go.dev/os/exec#Cmd.Environ

}
env := os.Environ()
tmpdir := filepath.Dir(layerPath)
env = append(env, "TMPDIR="+tmpdir)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this (also?) set SystemTemp? See moby/moby#52181 and the related ticket.

Merged via the queue into containerd:main with commit a275642 May 11, 2026
96 of 100 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

8 participants