gobolinux / Compile

The GoboLinux build tool
52 stars 15 forks source link

Unexpected behavior of Compile with overlayfs #43

Closed lucasvr closed 3 years ago

lucasvr commented 3 years ago

When using overlayfs as unionfs implementation Compile may misbehave depending on the order of the dependencies listed in the Dependencies file. The problem goes down to the way in which overlayfs merges two given directories. For instance:

$ mount -t overlay overlay -o lowerdir=/Programs/LibXFCE4Util/4.14.0/include:/Programs/XFConf/4.14.3/include,upperdir=/tmp/upper_layer/include,workdir=/tmp/write_layer/include /Mount
$ ls /Mount/
xfce4
$ ls /Mount/xfce4 
libxfce4util

When the arguments are swapped then the contents of both packages are shown under the mountpoint:

$ mount -t overlay overlay -o lowerdir=/Programs/XFConf/4.14.3/include:/Programs/LibXFCE4Util/4.14.0/include,upperdir=/tmp/upper_layer/include,workdir=/tmp/write_layer/include /Mount
$ ls /Mount/
xfce4
$ ls /Mount/xfce4
libxfce4util  xfconf-0

This is with kernel 5.6.10-Gobo. We need to test with a recent version before contacting upstream or coming up with changes to our tools.

lucasvr commented 3 years ago

Just confirmed that the problem persists on kernel 5.9.6.

lucasvr commented 3 years ago

This has to do with our union sandbox. The files we copy from the work directory to /Programs have certain extended attributes that should not be there, such as "trusted.overlay.impure" and "trusted.overlay.opaque" (which instructs overlayfs to ignore that directory when it's in the lower filesystem).

To workaround, we can simply have a cleanup function like this incorporated into UnionSandbox:

fname=
xattr_pattern="trusted.overlay."
getfattr -P -R -d -m "$xattr_pattern" --absolute-names "$target" | while read i
do
   if echo "$i" | grep -q "^# file:"
   then
      fname="$(echo "$i" | awk {'print $3'})"
   elif echo "$i" | grep -q "^${xattr_pattern}"
   then
      xattr="$(echo "$i" | cut -d= -f1)"
      setfattr --remove "$xattr" "$fname"
   fi
done

Another option is to experiment with plain cp -dR instead of cp -a so that extended attributes are not copied as part of the installation process.

ermo commented 3 years ago

Or maybe just cp -a --no-preserve=xattr?

https://gist.github.com/ermo/46f705592ce2e2a0e9cdc28584fe9454