Skip to contentSkip to conversation

xfstests: 300: diskspace consumption of cloned files on btrfs

DISCUSSION Eric Sandeen 1 participant 1 message Mar 9, 2013 1 message not in the archive Btrfs file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 58 lines · Koen De Wit

---
300 | 84
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  300.out |    4 +++
  2 files changed, 88 insertions(+), 0 deletions(-)

create mode 100644 300
create mode 100644 300.out

300 new file +42 -0
new file mode 100644
index 0000000..a6f706c
@@ -0,0 +1,84 @@
+#! /bin/bash
+# FS QA Test No. 300
+#
+# Diskspace consumption of sparse file clones ("reflinks") on btrfs
+#    - Check that a reflink does not consume space
+#    - Check that a reflink starts to consume space when the original file
+#      is modified
+#    - Check that diskspace is freed up after deleting all files
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2013, Oracle and/or its affiliates.  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.
+#
+# This program is distributed in the hope that it would 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+# creator
[email protected]
+
+seq=`basename $0`
+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.*
+}

300 line 52

Quoted 10 lines
300 new file +10 -0
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+# real QA test starts here
+_supported_fs btrfs
+_supported_os Linux
+
+_require_cp_reflink

need def'n

300 line 54

Quoted 2 lines
300 new file +2 -0
+TESTDIR1=$TEST_DIR/test-$seq.$$
+mkdir $TESTDIR1

possible clash if pids cycle?

300

Quoted 7 lines
300 new file +6 -0
+_free() {
+    _df_dir $TEST_DIR | $AWK_PROG '{ print $5 }'
+}
+
+free_before=`_free`
+$XFS_IO_PROG -f -c "pwrite -S 0x61 0 10m" -c "fsync" $TESTDIR1/original 
 > /dev/null

patch wrapped. FWIW sometimes redirecting to $seq.full rather than /dev/null makes it easier to see what's happened if anything goes wrong.

300

Quoted 7 lines
300 new file +7 -0
+cp --reflink=always $TESTDIR1/original $TESTDIR1/copy1
+cp --reflink=auto $TESTDIR1/copy1 $TESTDIR1/copy2
+btrfs filesystem sync $TEST_DIR > /dev/null
+free_after_creating_reflinks=`_free`
+_within_tolerance "free space after creating 1 file and 2 reflinks" \
+    `expr $free_before - $free_after_creating_reflinks` 10252 512 -v
+

A comment about what's being checked here might help, unfortunately the _within_tolerance helper is a little cryptic.

why should the difference be 10252, out of curiosity? Does that depend on block size or anything?

Quoted 2 lines

+$XFS_IO_PROG -c "pwrite -S 0x62 3m 5m" -c "fsync" $TESTDIR1/original > /dev/null

patch wrapped :)

300

Quoted 6 lines
300 new file +4 -0
+btrfs filesystem sync $TEST_DIR > /dev/null
+free_after_overwriting=`_free`
 
 
+_within_tolerance "free space after overwriting original file" \
+    `expr $free_before - $free_after_overwriting` 15376 512 -v

Ok, so you overwrote 5 megs of the original 10 meg file now.

So this is checking that the difference is within 512 bytes newly-consumed space against . . . 15376 what? It'd just be nice to have a comment for future readers.

I wonder if comparing to $free_after_creating_reflinks would be clearer, so the space used is just that space used for the new data?

300

Quoted 5 lines
300 new file +5 -0
+rm $TESTDIR1/original $TESTDIR1/copy1 $TESTDIR1/copy2
+btrfs filesystem sync $TEST_DIR > /dev/null
+free_after_removing=`_free`
+_within_tolerance "free space after removing all files" \
+    `expr $free_before - $free_after_removing` 0 128 -v

This makes sense, make sure we're back to the original.

Is the 128 slop even necessary?

Need to add this test to groups as well.

Thanks,
-Eric

Quoted 15 lines
300 new file +4 -0
+
+# success, all done
+status=0
+exit
300.out new file +4 -0
new file mode 100644
index 0000000..bbb94f4
@@ -0,0 +1,4 @@
+QA output created by 300
+free space after creating 1 file and 2 reflinks is in range
+free space after overwriting original file is in range
+free space after removing all files is in range