Bug 9857

Summary: sstate install doesn't preserve extended attributes on files
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Joshua Lock <joshuagloe>
Component: coreAssignee: Joshua Lock <joshuagloe>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: Medium+ CC: meta.mr.watcher, meta.watcher, ross.burton, sgw
Version: 2.2   
Target Milestone: 2.2 M3   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)
Bug Depends on: 9317, 9929    
Bug Blocks: 9858    

Description Joshua Lock 2016-06-30 14:09:02 UTC
Files installed via sstate lose any extended attributes which have been set on them when they are copied to their installed target destination.

This is because copyhardlinktree in turn calls copytree which uses a tar pipe to perform the actual file copying. This tar pipe doesn't include switches to force tar to preserve extended attributes.

A fix to oe.path.copytree() to preserve extended attributes is simple enough, though made marginally more complicated by the fact that tar versions prior to 1.27 don't support the tar options to preserve extended attributes.
Comment 1 Joshua Lock 2016-06-30 14:19:22 UTC
Looking at "older" distros in SANITY_TESTED_DISTROS I see that:
* Ubuntu 14.04 shipped tar 1.27.1 http://packages.ubuntu.com/trusty/tar
* Debian 7 shipped tar 1.26 https://packages.debian.org/wheezy/tar
* CentOS 6 shipped tar 1.23 http://mirror.centos.org/centos/6/os/x86_64/Packages/tar-1.23-14.el6.x86_64.rpm
* Fedora 21 shipped tar 1.27.1 http://pkgs.fedoraproject.org/cgit/rpms/tar.git/tree/tar.spec?h=f21
Comment 2 Ross Burton 2016-06-30 15:00:33 UTC
Can you also fix image.bbclass to add the attr options to tar there?

(and write a test case)
Comment 3 Joshua Lock 2016-06-30 16:16:05 UTC
(In reply to comment #2)
> Can you also fix image.bbclass to add the attr options to tar there?
> 
> (and write a test case)

image_types.bbclass -- I'll fix that.
Comment 4 Joshua Lock 2016-07-04 19:42:28 UTC
I've got WIP some patches that update meta/classes/image_types.bbclass and meta/lib/oe/path.py to preserve extended attributes. Unfortunately on a system with SELinux not disabled (in this case, running in Permissive mode) a tar pipe call in copytree() and copyhardlinktree() fails when expanding the archive with: "Cannot open: Permission denied"

If I disable SELinux on the host the build proceeds as usual and the extended attributes in my sstate objects are preserved when their contents are installed.
Comment 5 Joshua Lock 2016-07-05 12:31:31 UTC
An updated copyhardlinktree() requires a version of pseudo with the xattr semantics for hardlinks fixed -- setting "Depends on" to #9317
Comment 6 Joshua Lock 2016-07-14 20:54:12 UTC
After banging my head against the "Cannot open: Permission denied" issue for far too long I took to #selinux on Freenode to seek advice, as the error only occurs when SELinux is enabled yet occurs regardless of whether SELinux is in Permissive or Enforcing mode.

After performing various analysis of the involved files, etc we discovered that most files untar fine but that the ones that didn't all had a mode of --r--r--r.

This didn't actually help us determine a root cause and the #selinux occupants were suspicious of tar itself. I am in the process of testing with bsdtar instead of gnu tar.
Comment 7 Joshua Lock 2016-07-15 14:40:20 UTC
With bsdtar this series works without issue, even on SELinux using systems.

I'm not sure whether use of bsdtar will be an acceptable change, but I plan to make it conditional on the use of an "xattr" DISTRO_FEATURE before proposing patches for inclusion.

Either way this change is blocked by the pseudo 1.8.1 slowdown with xattrs, reverting to pre 1.8.x pseudo isn't an option as they don't support xattrs on hardlinks and we rely on hardlinks during sstate install to minimise the disk impact.
Comment 8 Ross Burton 2016-07-15 14:49:18 UTC
I wonder if GNU tar is detecting that selinux is enabled and changing its behaviour in some way.  It would be interesting to replicate with just tar outside of OE/pseudo and see if strace shows any difference in behaviour with SELinux in permissive or disabled.
Comment 9 Joshua Lock 2016-08-30 14:31:24 UTC
Patches submitted to OE-Core to preserve xattr in oe.path.copytree():

http://lists.openembedded.org/pipermail/openembedded-core/2016-August/125933.html
Comment 10 Joshua Lock 2016-09-07 15:41:14 UTC
Patches merged