##/bin/bash
-# Routines for reflinking, deduping, and comparing parts of files.
-#-----------------------------------------------------------------------
-# Copyright (c) 2015 Oracle. All Rights Reserved.
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2015 Oracle. All Rights Reserved.
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
-# USA
-#
-# Contact information: Oracle Corporation, 500 Oracle Parkway,
-# Redwood Shores, CA 94065, USA, or: http://www.oracle.com/
-#-----------------------------------------------------------------------
+# Routines for reflinking, deduping, and comparing parts of files.
# Check that cp has a reflink argument
_require_cp_reflink()
_notrun "This test requires a cp with --reflink support."
}
+# Can we reflink between arbitrary file sets?
+# i.e. if we reflink a->b and c->d, can we later share
+# blocks between b & c?
+_supports_arbitrary_fileset_reflink()
+{
+ test "$FSTYP" != "ocfs2"
+}
+
+_require_arbitrary_fileset_reflink()
+{
+ _supports_arbitrary_fileset_reflink ||
+ _notrun "reflink between arbitrary file groups not supported in $FSTYP"
+}
+
# Given 2 files, verify that they have the same mapping but different
# inodes - i.e. an undisturbed reflink
# Silent if so, make noise if not
_scratch_unmount
}
+# this test requires duperemove working for the file system
+_require_scratch_duperemove()
+{
+ _require_scratch
+ _require_command "$DUPEREMOVE_PROG" duperemove
+
+ _scratch_mkfs > /dev/null
+ _scratch_mount
+ dd if=/dev/zero of="$SCRATCH_MNT/file1" bs=128k count=1 >& /dev/null
+ dd if=/dev/zero of="$SCRATCH_MNT/file2" bs=128k count=1 >& /dev/null
+ if ! "$DUPEREMOVE_PROG" -d "$SCRATCH_MNT/file1" \
+ "$SCRATCH_MNT/file2" >& /dev/null ; then
+ _scratch_unmount
+ _notrun "duperemove does not support file system type: $FSTYP"
+ fi
+ _scratch_unmount
+}
+
# this test requires scratch fs to report explicit SHARED flag
# e.g.
# 0 4K 8K
_require_scratch_explicit_shared_extents()
{
_require_scratch
- _require_fiemap
+ _require_xfs_io_command "fiemap"
_require_scratch_reflink
_require_xfs_io_command "reflink"
local nr_extents
$XFS_IO_PROG -f -c "pwrite -S 0x61 0 65536" "$SCRATCH_MNT/file2" > /dev/null
testio="$($XFS_IO_PROG -f -c "dedupe $SCRATCH_MNT/file1 0 0 65536" "$SCRATCH_MNT/file2" 2>&1)"
echo $testio | grep -q "Operation not supported" && \
- _notrun "Dedupe not supported by test filesystem type: $FSTYP"
+ _notrun "Dedupe not supported by scratch filesystem type: $FSTYP"
echo $testio | grep -q "Inappropriate ioctl for device" && \
- _notrun "Dedupe not supported by test filesystem type: $FSTYP"
+ _notrun "Dedupe not supported by scratch filesystem type: $FSTYP"
echo $testio | grep -q "Invalid argument" && \
- _notrun "Dedupe not supported by test filesystem type: $FSTYP"
+ _notrun "Dedupe not supported by scratch filesystem type: $FSTYP"
_scratch_unmount
}
file1="$1"
file2="$2"
- cp --reflink=always -p "$file1" "$file2"
+ cp --reflink=always -p -f "$file1" "$file2"
}
# Reflink some file1 into file2
$XFS_IO_PROG $xfs_io_args -f -c "dedupe $file1 $offset1 $offset2 $len" "$file2"
}
+# Unify xfs_io dedupe ioctl error message prefix
+_filter_dedupe_error()
+{
+ sed -e 's/^dedupe:/XFS_IOC_FILE_EXTENT_SAME:/g'
+}
+
# Create a file of interleaved unwritten and reflinked blocks
_weave_reflink_unwritten() {
blksz=$1