Sparse file unittests fail on zfs

Bug #1656371 reported by Barry Warsaw
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu Image
Fix Released
High
Barry Warsaw

Bug Description

The unittests have two tests for sparse file behavior, test_sparse_copy() and test_copy_symlink() both in test_helpers.py. These will fail when the tempdir is a zfs file system (e.g. as is the case when building the binary packages on an lxc container built with autopkgtest-build-lxd).

From what I can gather so far, this is simply a difference in behavior on zfs and ext4, but there isn't actually a standard for what that behavior should be. For example, try the following in a shell:

$ truncate -s 1000000 /tmp/a
$ stat /tmp/a

Look at the number of blocks reported for /tmp/a. On ext4 you will get 0 blocks, but on zfs you will get 1. The test assumes a block size of 0 will be reported, so the tests fail.

Sparse file detection is actually a bit of a black art, and the heuristic currently used may be making bad assumptions. Although I haven't tried it yet, it might be more reliable to use lseek(whence=SEEK_HOLE).

Revision history for this message
Barry Warsaw (barry) wrote :

I think the following code will do the correct thing on both file systems:

try:
    os.lseek(fp.fileno(), 0, os.SEEK_DATA)
except OSError as error:
    if error.errno != errno.ENXIO:
        raise
    # OK! There is no data in the file.
else:
    # BAD! There is unexpected data in the file.

Changed in ubuntu-image:
milestone: none → 0.14
status: New → In Progress
importance: Undecided → High
assignee: nobody → Barry Warsaw (barry)
Barry Warsaw (barry)
Changed in ubuntu-image:
status: In Progress → Fix Committed
Barry Warsaw (barry)
Changed in ubuntu-image:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.