canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.34k stars 930 forks source link

lxc publish expands sparse files #4239

Closed jlec closed 6 years ago

jlec commented 6 years ago

Required information

When publishing a snapshot of a normal sized container which holds a sparse file, the sparse file gets expanded. This creates massive images.

In my image I have the following situation

[root@ipa01 log]# du -h /var/log/lastlog
569K    /var/log/lastlog
[root@ipa01 log]# du -h --apparent-size lastlog
429G    lastlog
[root@ipa01 log]# ls -lsh lastlog
569K -rw-r--r-- 1 root root 429G Feb 10 12:24 lastlog

and the resulting image grows to nearly half a TB.

Steps to reproduce

  1. Launch container and create a large sparse file
  2. lxc snapshot CONTAINER backup
  3. lxc publish CONTAINER/backup and watch /var/lib/lxd/images grow

Information to attach

Log:

        lxc 20180208214634.358 ERROR    lxc_utils - utils.c:safe_mount:1739 - Too many levels of symbolic links - Failed to mount /proc/sys/fs/binfmt_misc onto /usr/lib/x86_64-linux-gnu/lxc/proc/sys/fs/binfmt_misc
 - [x] Container configuration (`lxc config show NAME --expanded`)

architecture: x86_64 config: image.description: SCP Centos 7.3 (2017-09-04) limits.cpu: "8" limits.memory: 8GB raw.lxc: lxc.aa_profile=unconfined security.privileged: "true" user.network-config: | version: 1 config:

stgraber commented 6 years ago

LXD uses the standard Go tar library, there's an issue upstream for support of sparse file. Looks like a fix was first merged in 1.10 (the next Go release) but had to be reverted, hopefully 1.11 will have a working version of this work.

https://github.com/golang/go/issues/13548

stgraber commented 6 years ago

Closing as since we're just using the standard compression library, as soon as this upstream issue is fixed, we'll automatically be handling sparse files correctly.

jlec commented 6 years ago

Thanks @stgraber for the quick triage.

stgraber commented 6 years ago

No worries, I was kinda hoping we were shelling out to tar for that part as it'd have made fixing this a bit easier, but no, since we need to rewrite some file attributes as we add them to the tarball, we've got to use the native golang implementation and so get bitten by this bug.