diff mbox series

[2/2] generic: add test for race between getxattr and setxattr

Message ID 20200717084447.66402-3-houtao1@huawei.com (mailing list archive)
State New, archived
Headers show
Series add tests for race between xattr read and write | expand

Commit Message

Hou Tao July 17, 2020, 8:44 a.m. UTC
Add reproducer for a bug on UBIFS where getxattr() may fail
the assertions about the size of xattr value when the xattr
is being modified or deleted simultaneously.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 tests/generic/999     | 68 +++++++++++++++++++++++++++++++++++++++++++
 tests/generic/999.out |  2 ++
 tests/generic/group   |  1 +
 3 files changed, 71 insertions(+)
 create mode 100644 tests/generic/999
 create mode 100644 tests/generic/999.out
diff mbox series

Patch

diff --git a/tests/generic/999 b/tests/generic/999
new file mode 100644
index 00000000..5223d4aa
--- /dev/null
+++ b/tests/generic/999
@@ -0,0 +1,68 @@ 
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Huawei. All Rights Reserved.
+#
+# FS QA Test 999
+#
+# Test race between getxattr() and setxattr(). It reproduces a bug
+# on UBIFS where getxattr() may fail the assertions about the size of
+# xattr value when the xattr is being modified or deleted simultaneously.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+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.*
+	rm -f $TEST_DIR/$seq
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/attr
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_attrs
+
+target=$TEST_DIR/$seq
+touch $target
+
+xattr=user.test
+${SETFATTR_PROG} -n $xattr -v 1 $target
+
+# start a background getxattr
+runfile="$tmp.getxattr"
+touch $runfile
+while [ -e $runfile ]; do
+	${GETFATTR_PROG} -n $xattr $target >/dev/null 2>&1
+done &
+
+# modify and remove xattr repeatedly
+largeval=`for i in $(seq 0 128); do echo -n a; done`
+for i in $(seq 0 99); do
+	${SETFATTR_PROG} -n $xattr -v $largeval $target
+	${SETFATTR_PROG} -x $xattr $target
+	${SETFATTR_PROG} -n $xattr -v 1 $target
+done
+
+rm -f $runfile
+wait > /dev/null 2>&1
+rm -f $target
+
+echo Silence is golden
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/999.out b/tests/generic/999.out
new file mode 100644
index 00000000..3b276ca8
--- /dev/null
+++ b/tests/generic/999.out
@@ -0,0 +1,2 @@ 
+QA output created by 999
+Silence is golden
diff --git a/tests/generic/group b/tests/generic/group
index 62697ac5..368399f1 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -606,3 +606,4 @@ 
 601 auto quick quota
 602 auto quick encrypt
 998 auto quick attr
+999 auto quick attr