Skip to content

cosalib/build: Use workdir tmp/ as tempdir #1097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2020
Merged

Conversation

jlebon
Copy link
Member

@jlebon jlebon commented Feb 3, 2020

We changed this behaviour during the refactor. There's quite a bit of
history here on why do this. But a major one at least is that we want to
be able to just rename(2) the final build artifacts into place. This
saves a bunch of time and I/O.

I noticed this due to the fact that we were losing sparsity from the
output of qemu-img convert because shutil.move doesn't do the
equivalent of cp --sparse=auto. This patch fixes that, though I think
we should also be able to change that call to a simple os.rename() in
a follow-up to make it explicit.

Related: coreos/fedora-coreos-tracker#361

We changed this behaviour during the refactor. There's quite a bit of
history here on why do this. But a major one at least is that we want to
be able to just `rename(2)` the final build artifacts into place. This
saves a bunch of time and I/O.

I noticed this due to the fact that we were losing sparsity from the
output of `qemu-img convert` because `shutil.move` doesn't do the
equivalent of `cp --sparse=auto`. This patch fixes that, though I think
we should also be able to change that call to a simple `os.rename()` in
a follow-up to make it explicit.

Related: coreos/fedora-coreos-tracker#361
@jlebon
Copy link
Member Author

jlebon commented Feb 3, 2020

@cgwalters
Copy link
Member

Oh yes, thanks for fixing this! I thought I saw this bug while reading the code but forgot about it.

Besides just being faster, each GB we avoid writing speeds up development time and increases SSD life.

@@ -96,7 +96,12 @@ def __init__(self, *args, **kwargs):

self._found_files = {}
self._workdir = kwargs.pop("workdir", os.getcwd())
self._tmpdir = tempfile.mkdtemp(prefix="build_tmpd")
tmpdir = os.path.join(self._workdir, "tmp")
os.environ['TMPDIR'] = tmpdir
Copy link
Member

Choose a reason for hiding this comment

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

This isn't new, but... rust-lang/rust#24741

AFAIK cosa isn't multi-threaded today, but it's just a time bomb to be mutating the environment. We can fix as a follow-up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we should probably just set it in the entrypoint instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I think it's trickier than that since the entrypoint has no notion of workdir. So yeah, let's do that as a follow-up!

@darkmuggle
Copy link
Contributor

@darkmuggle
Copy link
Contributor

/lgtm

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: darkmuggle, jlebon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@darkmuggle
Copy link
Contributor

https://github.com/darkmuggle/coreos-assembler/commit/4415410fdc8a2b8178ae8ced09c67d804b1a8aa4
an alternative approach and explains the rationale for why an ephemeral tmp was being used. This would ensure that sparseness is maintained.

Given that this PR is approved, I'd vote we merge this one ASAP since CI is affected.

@jlebon
Copy link
Member Author

jlebon commented Feb 4, 2020

Probably want to whack that too.

Hmm, we still want to clean up the tmpdir though, right?

an alternative approach

I think it's mostly equivalent, I just deduped it with the path we were already building when setting TMPDIR. :) Re. the rationale, yeah I think we could handle error conditions by just re-using the same path name (emptying it beforehand each time) instead of a dynamically allocated one?

OK, going to merge this one manually for now until we sort out the Prow issues!

@jlebon jlebon merged commit 19dae9d into coreos:master Feb 4, 2020
@jlebon jlebon deleted the pr/fix-tmp branch July 6, 2020 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants