Skip to content
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] libglnx porting: Migrate to new tempfile code #369

Closed
wants to merge 1 commit into from

Conversation

cgwalters
Copy link
Member

In general this is even cleaner now, though it was better after I
extracted a helper function for the "write tempfile with contents"
bits that were shared between metadata and regular file codepaths.

Depends on GNOME/libglnx#17

@cgwalters
Copy link
Member Author

Committed the libglnx dependency (though more review is welcome) and rebased 🏄

@cgwalters
Copy link
Member Author

I saw locally open(O_TMPFILE): Too many open files

@cgwalters
Copy link
Member Author

In the big picture, I am now thinking that O_TMPFILE is going to be a good opportunity to re-pursue O_OBJECT by instead having a special ioctl that at least XFS knows that can only be used for O_TMPFILE. The model would be a lot clearer because the file wouldn't exist for other processes to see until the final link, so there'd be no visible-elsewhere mutable state.

@cgwalters
Copy link
Member Author

Hum interesting...test-delta.sh passes here. I wonder whether this is a tempfile fallback issue. Will look.

@cgwalters
Copy link
Member Author

This turns out to be that the untrusted-delta codepath explicitly tries to re-open the tempfile path, mmap it, and checksum it. We can't do that with O_TMPFILE.

The right thing instead is to compute the checksum while writing, just like we do in write_object().

cgwalters added a commit to cgwalters/ostree that referenced this pull request Jul 12, 2016
When reworking the ostree core [to use O_TMPFILE](ostreedev#369),
I hit an issue in the way the untrusted delta codepath ends up trying
to re-open the file to checksum it.  That's not possible with
`O_TMPFILE` since the fd (which we opened `O_WRONLY`) is the only
accessible reference to the content.

Fix this by changing the delta processing code to update a checksum as
we're doing writes, which is also faster, and ends up simplifying the
code as well.

What would be an even larger simplification here is if we e.g. used a
separate thread calling `write_object()` or something like that; the
main issue I see there is somehow bridging the fact that function
wants a `GInputStream*` but the delta code is generating stream of
writes.
@rh-atomic-bot
Copy link

☔ The latest upstream changes (presumably f3cbe86) made this pull request unmergeable. Please resolve the merge conflicts.

cgwalters added a commit to cgwalters/ostree that referenced this pull request Jul 29, 2016
When reworking the ostree core [to use O_TMPFILE](ostreedev#369),
I hit an issue in the way the untrusted delta codepath ends up trying
to re-open the file to checksum it.  That's not possible with
`O_TMPFILE` since the fd (which we opened `O_WRONLY`) is the only
accessible reference to the content.

Fix this by changing the delta processing code to update a checksum as
we're doing writes, which is also faster, and ends up simplifying the
code as well.

What would be an even larger simplification here is if we e.g. used a
separate thread calling `write_object()` or something like that; the
main issue I see there is somehow bridging the fact that function
wants a `GInputStream*` but the delta code is generating stream of
writes.
rh-atomic-bot pushed a commit that referenced this pull request Jul 29, 2016
When reworking the ostree core [to use O_TMPFILE](#369),
I hit an issue in the way the untrusted delta codepath ends up trying
to re-open the file to checksum it.  That's not possible with
`O_TMPFILE` since the fd (which we opened `O_WRONLY`) is the only
accessible reference to the content.

Fix this by changing the delta processing code to update a checksum as
we're doing writes, which is also faster, and ends up simplifying the
code as well.

What would be an even larger simplification here is if we e.g. used a
separate thread calling `write_object()` or something like that; the
main issue I see there is somehow bridging the fact that function
wants a `GInputStream*` but the delta code is generating stream of
writes.

Closes: #392
Approved by: jlebon
@jlebon
Copy link
Member

jlebon commented Jul 29, 2016

@cgwalters Can you rebase?

In general this is even cleaner now, though it was better after I
extracted a helper function for the "write tempfile with contents"
bits that were shared between metadata and regular file codepaths.
@cgwalters
Copy link
Member Author

🏄

@cgwalters
Copy link
Member Author

One risk of this is that now there are two pretty different ways to handle tmpfiles, and specifically CentOS 7.2 xfs doesn't do O_TMPFILE. But I think ultimately the benefit is going to be worth it.

@jlebon
Copy link
Member

jlebon commented Jul 29, 2016

OK, these makes sense. I was a bit confused why libglnx needed the missing syscall tidbit, but I see the RHEL/CentOS kernels have renameat2 backported.

@rh-atomic-bot r+ e105ee9

Overall, the O_TMPFILE approach is really nice. And this sets us up even better for when (hopefully) linkat can address the replace case too.

It might be interesting to add a new type in libglnx to encapsulate the pattern a bit more and have e.g. a variation on glnx_fd_close that also does the linkat bit. And maybe also another variation that opens an output stream for you.

@rh-atomic-bot
Copy link

⌛ Testing commit e105ee9 with merge 6d310db...

@rh-atomic-bot
Copy link

☀️ Test successful - status-atomicjenkins
Approved by: jlebon
Pushing 6d310db to master...

@rh-atomic-bot rh-atomic-bot changed the title libglnx porting: Migrate to new tempfile code [merged] libglnx porting: Migrate to new tempfile code Jul 29, 2016
@hadess
Copy link
Contributor

hadess commented Aug 2, 2016

This regresses use of ostree on filesystems that don't support O_TMPFILE, such as ubifs, which is the root filesystem on quite a few eMMC/NAND block devices such as the ones used in ARM or "reduced functionality" Intel compatible platforms.

See https://bugzilla.gnome.org/show_bug.cgi?id=769453

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.

None yet

4 participants