Skip to content

Overlayfs testing

Amir Goldstein edited this page Aug 27, 2018 · 16 revisions

Table of Contents

Unionmount testsuite

The unionmount test suite was originally developed by David Howells to test for union file system correctness.

The test suite was enhanced to be able to setup overlayfs over xfs+reflink and instrumented with more overlayfs validation tests.

Following are instructions how to setup and run the test suite.

Basic overlayfs testing

Setup unionmount testsuite

Clone the enhanced unionmount-testsuite sources from github:

# git clone https://github.com/amir73il/unionmount-testsuite.git
# cd unionmount-testsuite

To setup overlayfs where both lower and upper are different tmpfs, run:

# mkdir -p /lower /upper /mnt
# ./run --ov -s
# mount |tail -3
lower_layer on /lower type tmpfs (rw,relatime)
lower_layer on /upper type tmpfs (rw,relatime)
overlay on /mnt type overlay (rw,relatime,lowerdir=/lower,upperdir=/upper/0/u,workdir=/upper/0/w)

To setup overlayfs where lower is squashfs and upper is tmpfs, run:

# mkdir -p /lower /upper /mnt
# ./run --ov --squashfs -s
# mount |tail -3
/lower/a.img on /lower type squashfs (ro,relatime)
lower_layer on /upper type tmpfs (rw,relatime)
overlay on /mnt type overlay (rw,relatime,lowerdir=/lower,upperdir=/upper/0/u,workdir=/upper/0/w)

To setup overlayfs where both layers are on the same tmpfs run:

# mkdir -p /base /lower /upper /mnt
# ./run --ov --samefs -s
# mount |tail -4
lower_layer on /base type tmpfs (rw,relatime)
lower_layer on /lower type tmpfs (rw,relatime)
lower_layer on /upper type tmpfs (rw,relatime)
overlay on /mnt type overlay (rw,relatime,lowerdir=/lower,upperdir=/upper/0/u,workdir=/upper/0/w)
  • /base is the common file system for /lower and /upper
  • /lower and /upper are bind mounts into /base
  • /lower contains an initial setup of files and dirs for the different tests
  • /upper contains empty upper layer 0 and work dir
  • /mnt is the overlayfs mount
unionmount-testsuite does not provide a way to configure those paths.

Run overlayfs tests

To execute all unionmount tests, run:

# ./run --ov
***
*** ./run --ov --ts=0 open-plain
***
TEST open-plain.py:10: Open O_RDONLY
 ./run --open-file /mnt/a/foo100 -r -R :xxx:yyy:zzz
 ./run --open-file /mnt/a/foo100 -r -R :xxx:yyy:zzz
...

The test run will abort on the first failure it encounters.

To execute all unionmount tests while checking for constant inode numbers across copy up on same fs setup, run:

# ./run --ov --samefs --verify
***
*** ./run --ov --samefs --ts=0 open-plain
***
TEST open-plain.py:10: Open O_RDONLY
 ./run --open-file /mnt/a/foo100 -r -R :xxx:yyy:zzz
 ./run --open-file /mnt/a/foo100 -r -R :xxx:yyy:zzz
...

NOTE that the --verify option automatically enables the "index" and "xino" features on kernels where they are supported. Constant inode number verification will fail on kernels < v4.12 with --samefs setup and on kernels < v4.16 without --samefs setup. Constant inode number verification will also fail with --squashfs setup, because a squashfs does not have a UUID, overlayfs cannot store reliable origin file handle references to lower inode in upper inode.

Run overlayfs tests with multiple lower layers

To execute a specific test (e.g. mkdir) with a up to 10 middle layers, 2 of which are on a unique filesystem, run:

# ./run --ov=10 --maxfs=2 -v mkdir
***
*** ./run --ov=10 --maxfs=2 --ts=0 mkdir
***
TEST mkdir.py:10: Create directory
...
# dmesg |tail -n 50

dmesg output will give you a sense of what was going on while the test was running. After every successful mkdir() or rename() operation, the testsuite creates a new upper layer and rotates the current upper layer to the top of the lower layers stack. For example:

TEST mkdir.py:114: Create directory over dangling sym
mount -t overlay overlay /mnt -orw,lowerdir=/upper/2/u:/upper/1/u:/upper/0/u:/lower,upperdir=/upper/3/u,workdir=/upper/3/w

The feature of rotating upper layers was added to test the "redirect_dir" feature, which supports directory redirects on upper as well as middle layers.

NOTE that the test run --ov=10 --samefs --verify rename-mass-5 will fail on kernels < v4.13, because when hard links from middle layer are broken on copy up, their inode number changes.

Advanced overlayfs testing

Overlayfs performs better in a setup where all layers are the same fs and that fs supports the clone_file_range() operation. In that case, files will be cloned up instead of copied up. clone_file_range() is a metadata operation that is much faster than copy data for large files.

From the filesystems that are supported as overlayfs upper fs, btrfs supports clone_file_range() and xfs supports clone_file_range() when formatted with experimental reflink support.

Download and build xfsprogs with XFS reflink support

Clone the latest xfsprogs sources from kernel.org.

Build and install the latest xfsprogs with XFS reflink support.

Setup overlayfs mount over XFS with reflink support

xfs reflink was an experimental feature until kernel v4.16, so make sure you use a recent upstream kernel or latest v4.9.y stable kernel.

Following example creates a test volume named 'lower_layer' formatted with XFS with reflink support:

# lvcreate -n lower_layer -L 5g ssd
# mkfs.xfs -m reflink=1 /dev/mapper/ssd-lower_layer 
meta-data=/dev/mapper/ssd-lower_layer isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=0, rmapbt=0, reflink=1
...
# echo /dev/mapper/ssd-lower_layer /base xfs noauto >> /etc/fstab

NOTE that the name of the volume must end with 'lower_layer' as this is how the testsuite setup recognizes this mount.

To cleanup old tmpfs mounts and setup overlayfs snapshots over the newly created test volume, run:

# umount /mnt /lower /upper /base
# ./run --ov --samefs -s
# mount |tail -4
/dev/mapper/ssd-lower_layer on /base type xfs (rw,relatime,attr2,inode64,noquota)
/dev/mapper/ssd-lower_layer on /lower type xfs (ro,relatime,attr2,inode64,noquota)
/dev/mapper/ssd-lower_layer on /upper type xfs (rw,relatime,attr2,inode64,noquota)
overlay on /mnt type overlay (rw,relatime,lowerdir=/lower,upperdir=/upper/0/u,workdir=/upper/0/w)

The testsuite setup recognizes the fstab entry for /base and mounts it as the common file system for /upper and /lower instead of mounting a tmpfs.