From 1da62d67ce4d4c78b98bc947c9367a10f1bdba9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P <at> draigBrady.com>
Date: Fri, 4 Feb 2011 22:05:20 +0000
Subject: [PATCH] test: improve the fiemap_capable_ check
* tests/cp/fiemap-2: Enable the fiemap check for files, which
will enable the test on ext3.
* tests/cp/fiemap-perf: Comment why we're not enabling for ext3.
* tests/cp/sparse-fiemap: Ditto.
* tests/fiemap-capable: A new python script to determine
if a specified path supports fiemap.
* tests/init.cfg (fiemap_capable_): Use the new python script.
* tests/Makefile.am (EXTRA_DIST): Include the new python script.
---
tests/Makefile.am | 1 +
tests/cp/fiemap-2 | 3 ++-
tests/cp/fiemap-perf | 2 ++
tests/cp/sparse-fiemap | 12 ++++++++----
tests/fiemap-capable | 16 ++++++++++++++++
tests/init.cfg | 9 ++++-----
6 files changed, 33 insertions(+), 10 deletions(-)
create mode 100644 tests/fiemap-capable
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 751b327..8aa56cd 100644
a
|
b
|
EXTRA_DIST = \
|
11 | 11 | check.mk \ |
12 | 12 | envvar-check \ |
13 | 13 | filefrag-extent-compare \ |
| 14 | fiemap-capable \ |
14 | 15 | init.cfg \ |
15 | 16 | init.sh \ |
16 | 17 | lang-default \ |
diff --git a/tests/cp/fiemap-2 b/tests/cp/fiemap-2
index a17076c..691ead2 100755
a
|
b
|
|
20 | 20 | print_ver_ cp |
21 | 21 | |
22 | 22 | # Require a fiemap-enabled FS. |
23 | | fiemap_capable_ . \ |
| 23 | touch fiemap_chk # check a file rather than current dir for best coverage |
| 24 | fiemap_capable_ fiemap_chk \ |
24 | 25 | || skip_ "this file system lacks FIEMAP support" |
25 | 26 | |
26 | 27 | # Exercise the code that handles a file ending in a hole. |
diff --git a/tests/cp/fiemap-perf b/tests/cp/fiemap-perf
index 7369a7d..dbb2a81 100755
a
|
b
|
|
20 | 20 | print_ver_ cp |
21 | 21 | |
22 | 22 | # Require a fiemap-enabled FS. |
| 23 | # Note we don't check a file here as that could enable |
| 24 | # the test on ext3 where emulated extent scanning can be slow. |
23 | 25 | fiemap_capable_ . \ |
24 | 26 | || skip_ "this file system lacks FIEMAP support" |
25 | 27 | |
diff --git a/tests/cp/sparse-fiemap b/tests/cp/sparse-fiemap
index f224b5b..fc27869 100755
a
|
b
|
|
19 | 19 | . "${srcdir=.}/init.sh"; path_prepend_ ../src |
20 | 20 | print_ver_ cp |
21 | 21 | |
| 22 | # Note we don't check a file here as that could enable |
| 23 | # the test on ext3 where this test is seen to fail. |
22 | 24 | if fiemap_capable_ . ; then |
23 | 25 | : # Current dir is on a partition with working extents. Good! |
24 | 26 | else |
… |
… |
for i in $(seq 1 2 21); do
|
66 | 68 | $PERL -e 'BEGIN { $n = '$i' * 1024; *F = *STDOUT }' \ |
67 | 69 | -e 'for (1..'$j') { sysseek (*F, $n, 1)' \ |
68 | 70 | -e '&& syswrite (*F, chr($_)x$n) or die "$!"}' > j1 || fail=1 |
69 | | # sync |
| 71 | |
| 72 | # Note the explicit fdatasync is used here as |
| 73 | # it was seen that `filefrag -s` (FIEMAP_FLAG_SYNC) was |
| 74 | # ineffective on ext4 loopback on Linux 2.6.35.10-72.fc14.i686 |
| 75 | dd if=/dev/null of=j1 conv=notrunc,fdatasync |
70 | 76 | cp --sparse=always j1 j2 || fail=1 |
71 | | # sync |
72 | | # Technically we may need the 'sync' uses above, but |
73 | | # uncommenting them makes this test take much longer. |
| 77 | dd if=/dev/null of=j2 conv=notrunc,fdatasync |
74 | 78 | |
75 | 79 | cmp j1 j2 || fail=1 |
76 | 80 | filefrag -v j1 | grep extent \ |
diff --git a/tests/fiemap-capable b/tests/fiemap-capable
new file mode 100644
index 0000000..05c6926
-
|
+
|
|
| 1 | import struct, fcntl, sys, os |
| 2 | |
| 3 | def sizeof(t): return struct.calcsize(t) |
| 4 | IOCPARM_MASK = 0x7f |
| 5 | IOC_OUT = 0x40000000 |
| 6 | IOC_IN = 0x80000000 |
| 7 | IOC_INOUT = (IOC_IN|IOC_OUT) |
| 8 | def _IOWR(x,y,t): return (IOC_INOUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|y) |
| 9 | |
| 10 | try: |
| 11 | fd = os.open (len (sys.argv) == 2 and sys.argv[1] or '.', os.O_RDONLY) |
| 12 | struct_fiemap = '=qqllll' |
| 13 | FS_IOC_FIEMAP = _IOWR (ord ('f'), 11, struct_fiemap) |
| 14 | fcntl.ioctl (fd, FS_IOC_FIEMAP, struct.pack(struct_fiemap, 0,~0,0,0,0,0)) |
| 15 | except: |
| 16 | sys.exit (1) |
diff --git a/tests/init.cfg b/tests/init.cfg
index b2d1bab..f49c5cf 100644
a
|
b
|
require_proc_pid_status_()
|
295 | 295 | kill $pid |
296 | 296 | } |
297 | 297 | |
298 | | # Return nonzero if the specified directory is on a file system for |
299 | | # which FIEMAP support exists, and the file system type is new enough |
300 | | # (unlike ext2 and ext3) that it is hard to find an instance *without* |
301 | | # FIEMAP support. |
| 298 | # Return nonzero if the specified path is on a file system for |
| 299 | # which FIEMAP support exists. Note some file systems (like ext3) |
| 300 | # only support FIEMAP for files, not directories. |
302 | 301 | fiemap_capable_() |
303 | 302 | { |
304 | | df -T -t btrfs -t xfs -t ext4 -t ocfs2 -t gfs2 "$@" |
| 303 | python $abs_srcdir/fiemap-capable "$@" |
305 | 304 | } |
306 | 305 | |
307 | 306 | # Does the current (working-dir) file system support sparse files? |