2014-01-20 13:56:37 +11:00
|
|
|
#! /bin/bash
|
2018-06-09 11:35:50 +10:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
# Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
|
|
|
|
|
#
|
2014-01-20 13:56:37 +11:00
|
|
|
# FS QA Test No. 029
|
|
|
|
|
#
|
|
|
|
|
# Check if creating a sparse copy ("reflink") of a file on btrfs
|
|
|
|
|
# expectedly fails when it's done between different filesystems or
|
|
|
|
|
# different mount points of the same filesystem.
|
|
|
|
|
#
|
|
|
|
|
# For both situations, these actions are executed:
|
|
|
|
|
# - Copy a file with the reflink=auto option.
|
|
|
|
|
# A normal copy should be created.
|
|
|
|
|
# - Copy a file with the reflink=always option. Should result in
|
|
|
|
|
# error.
|
|
|
|
|
#
|
|
|
|
|
seq=`basename $0`
|
2014-01-24 12:06:45 +11:00
|
|
|
seqres=$RESULT_DIR/$seq
|
2014-01-20 13:56:37 +11:00
|
|
|
echo "QA output created by $seq"
|
|
|
|
|
|
|
|
|
|
here=`pwd`
|
|
|
|
|
tmp=/tmp/$$
|
|
|
|
|
status=1 # failure is the default!
|
|
|
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
|
|
|
|
|
|
_cleanup()
|
|
|
|
|
{
|
|
|
|
|
cd /
|
|
|
|
|
rm -f $tmp.*
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# get standard environment, filters and checks
|
|
|
|
|
. ./common/rc
|
|
|
|
|
. ./common/filter
|
2015-11-17 08:39:17 +11:00
|
|
|
. ./common/reflink
|
2014-01-20 13:56:37 +11:00
|
|
|
|
|
|
|
|
# real QA test starts here
|
|
|
|
|
_supported_fs btrfs
|
|
|
|
|
_supported_os Linux
|
|
|
|
|
|
2014-08-13 11:08:41 +10:00
|
|
|
_require_test
|
2014-01-20 13:56:37 +11:00
|
|
|
_require_scratch
|
|
|
|
|
_require_cp_reflink
|
|
|
|
|
|
2016-01-11 15:05:20 +11:00
|
|
|
reflink_test_dir=$TEST_DIR/test-$seq
|
|
|
|
|
rm -rf $reflink_test_dir
|
|
|
|
|
mkdir $reflink_test_dir
|
2014-01-20 13:56:37 +11:00
|
|
|
|
|
|
|
|
rm -f $seqres.full
|
|
|
|
|
|
2014-02-03 10:06:41 +11:00
|
|
|
_scratch_mkfs > /dev/null 2>&1
|
2016-01-11 15:05:20 +11:00
|
|
|
_scratch_mount
|
|
|
|
|
$XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $SCRATCH_MNT/original >> $seqres.full
|
2014-01-20 13:56:37 +11:00
|
|
|
|
2016-01-11 15:05:20 +11:00
|
|
|
_create_reflinks()
|
2014-01-20 13:56:37 +11:00
|
|
|
{
|
|
|
|
|
# auto reflink, should fall back to non-reflink
|
2016-01-11 15:05:20 +11:00
|
|
|
rm -rf $2
|
2014-01-20 13:56:37 +11:00
|
|
|
echo "reflink=auto:"
|
2016-01-11 15:05:20 +11:00
|
|
|
cp --reflink=auto $1 $2
|
2017-09-01 14:39:44 +09:00
|
|
|
md5sum $1 | _filter_testdir_and_scratch
|
|
|
|
|
md5sum $2 | _filter_testdir_and_scratch
|
2014-01-20 13:56:37 +11:00
|
|
|
|
|
|
|
|
# always reflink, should fail outright
|
2016-01-11 15:05:20 +11:00
|
|
|
rm -rf $2
|
2014-01-20 13:56:37 +11:00
|
|
|
echo "reflink=always:"
|
2016-01-11 15:05:20 +11:00
|
|
|
cp --reflink=always $1 $2 >> $seqres.full 2>&1 || echo "cp reflink failed"
|
2014-01-20 13:56:37 +11:00
|
|
|
|
|
|
|
|
# The failed target actually gets created by cp:
|
2017-09-01 14:39:44 +09:00
|
|
|
ls $2 | _filter_testdir_and_scratch
|
2014-01-20 13:56:37 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "test reflinks across different devices"
|
2016-01-11 15:05:20 +11:00
|
|
|
_create_reflinks $SCRATCH_MNT/original $reflink_test_dir/copy
|
2014-01-20 13:56:37 +11:00
|
|
|
|
|
|
|
|
echo "test reflinks across different mountpoints of same device"
|
2016-01-11 15:05:20 +11:00
|
|
|
rm -rf $reflink_test_dir/*
|
|
|
|
|
_mount $SCRATCH_DEV $reflink_test_dir
|
|
|
|
|
_create_reflinks $SCRATCH_MNT/original $reflink_test_dir/copy
|
|
|
|
|
$UMOUNT_PROG $reflink_test_dir
|
2014-01-20 13:56:37 +11:00
|
|
|
|
|
|
|
|
# success, all done
|
|
|
|
|
status=0
|
|
|
|
|
exit
|