Sparse file unittests fail on zfs
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-
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=
Changed in ubuntu-image: | |
status: | In Progress → Fix Committed |
Changed in ubuntu-image: | |
status: | Fix Committed → Fix Released |
I think the following code will do the correct thing on both file systems:
try: lseek(fp. fileno( ), 0, os.SEEK_DATA)
os.
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.