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

Add support for exporting and importing file flags on FreeBSD #1378

Merged
merged 7 commits into from
Oct 20, 2022

Conversation

dfr
Copy link
Contributor

@dfr dfr commented Oct 1, 2022

The implementation could be shared with darwin and other BSDs if needed but initially is only enabled on FreeBSD. This uses the SCHILY.fflags PAX option to encode flags which is supported by libarchive (bsdtar) and star. The flag save/restore entry points are exported, allowing them to be used by buildah/copier.

To support applying diffs to trees with flags, I added logic to reset immutable flags during the UnpackLayer process - this is slightly complicated by the desire to support immutable directories which needs to defer setting fiags on directories to after all modifications to the directory contents. Fortunately, something similar is already in place for setting directory modify times.

@dfr dfr force-pushed the freebsd-chflags branch 2 times, most recently from 2d00e72 to f820350 Compare October 3, 2022 09:17
Copy link
Member

@rhatdan rhatdan left a comment

Choose a reason for hiding this comment

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

One question
LGTM

@rhatdan
Copy link
Member

rhatdan commented Oct 7, 2022

@dfr
Copy link
Contributor Author

dfr commented Oct 7, 2022

Rebased

@dfr dfr force-pushed the freebsd-chflags branch 2 times, most recently from d3e97d2 to 8bd87e9 Compare October 12, 2022 14:06
@rhatdan
Copy link
Member

rhatdan commented Oct 13, 2022

@flouthoc
Copy link
Collaborator

flouthoc commented Oct 13, 2022

There are some commits in archive on which and I don't have lot of idea on archive part, but they will affect buildah and podman afaics on *nix as well. I'd defer review for this to @nalind @giuseppe.

@flouthoc
Copy link
Collaborator

@dfr commit 8bd87e9 adds changes to *nix counterpart as well right ? But commit only talks about FreeBSD. Could we split commit which affects *nix into subcommits ?

Please ignore my concern if i understood this wrong :)

@dfr
Copy link
Contributor Author

dfr commented Oct 13, 2022

@flouthoc that commit could be split into functional parts, e.g.:

  • Adding fflags_*.go with entry points to encode/decode flags
  • Adding support for detecting flag changes in changes_unix.go and changes_bsd_test.go
  • Adding calls to those encode/decode flags in archive.go and diff.go

Would that help to clarify?

@flouthoc
Copy link
Collaborator

@flouthoc that commit could be split into functional parts, e.g.:

* Adding fflags_*.go with entry points to encode/decode flags

* Adding support for detecting flag changes in changes_unix.go and changes_bsd_test.go

* Adding calls to those encode/decode flags in archive.go and diff.go

Would that help to clarify?

@dfr Yes I think that would be really helpful thanks for considering my comment :) .

@dfr
Copy link
Contributor Author

dfr commented Oct 13, 2022

I split the pkg/archive commit along the lines I suggested - hope that helps.

@dfr
Copy link
Contributor Author

dfr commented Oct 13, 2022

Rebased

@rhatdan
Copy link
Member

rhatdan commented Oct 14, 2022

@flouthoc PTAL

@rhatdan
Copy link
Member

rhatdan commented Oct 15, 2022

@dfr
Copy link
Contributor Author

dfr commented Oct 19, 2022

Rebased

@rhatdan
Copy link
Member

rhatdan commented Oct 19, 2022

@flouthoc
Copy link
Collaborator

There are some commits in archive on which and I don't have lot of idea on archive part, but they will affect buildah and podman afaics on *nix as well. I'd defer review for this to @nalind @giuseppe.

PR LGTM but I'd like @nalind @giuseppe @mtrmac @vrothberg to take a look for above reason.

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

LGTM — I’m really not that familiar with pkg/archive, but at least the added tests add quite a bit of confidence.

Just a few optional stylistic nits.

pkg/archive/fflags_bsd.go Outdated Show resolved Hide resolved
pkg/archive/fflags_bsd.go Outdated Show resolved Hide resolved
@rhatdan
Copy link
Member

rhatdan commented Oct 19, 2022

Could you fix the two issues @mtrmac found.

This also adds an integration test for deleting containers with
immutable files.

Signed-off-by: Doug Rabson <dfr@rabson.org>
Note: these are likely to be identical on other BSDs, including darwin,
but I'm keeping this for just FreeBSD to start with.

Signed-off-by: Doug Rabson <dfr@rabson.org>
This will also probably work on other BSD derived platforms including
darwin.

Signed-off-by: Doug Rabson <dfr@rabson.org>
This adds platform-specific entry points to encode and decode file
flags. These are exported so that they can be used in buildah/copier. A
function which can be used to optionally reset the immutable flag on a
file or directory is also added and this will be used when applying
layer changes to trees with immutable files or directories.

These new entry points are implemented for FreeBSD and are noop stubs on
other platforms. The chflags approach could be used on darwin and other
BSD-derived platforms if needed.

On FreeBSD, file flag information is encoded for import/export using the
PAX SCHILY.fflags option. This is compatible with bsdtar (see
https://github.com/libarchive/libarchive). Reading the code for
libarchive, it also has support for encoding/decoding Linux file flags
so this seems like a good reference.

Signed-off-by: Doug Rabson <dfr@rabson.org>
Note: the Flags method of system.StatT always returns zero on
non-FreeBSD platforms so this should have no functional change for those
platforms.

Signed-off-by: Doug Rabson <dfr@rabson.org>
This encodes flag information into the tar stream using
ReadFileFlagsToTarHeader and decodes with WriteFileFlagsFromTarHeader.

To support applying diffs to trees with flags, this adds logic to
reset immutable flags during the UnpackLayer process.  To support
immutable directories, we also need to defer setting flags on
directories until after all modifications to the directory contents.
Fortunately, something similar is already in place for setting
directory modify times.

Signed-off-by: Doug Rabson <dfr@rabson.org>
@dfr
Copy link
Contributor Author

dfr commented Oct 20, 2022

Could you fix the two issues @mtrmac found.

Done, thanks!

@rhatdan
Copy link
Member

rhatdan commented Oct 20, 2022

LGTM

@rhatdan rhatdan merged commit db44035 into containers:main Oct 20, 2022
@dfr dfr deleted the freebsd-chflags branch October 20, 2022 16:49
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