All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
To: fstests@vger.kernel.org
Cc: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Subject: [PATCH] ext4/035: Verify directory shrinking
Date: Wed, 27 Feb 2019 16:03:16 -0800	[thread overview]
Message-ID: <20190228000316.238620-1-harshadshirwadkar@gmail.com> (raw)

Add test to verify that directory shrinking works for ext4 and also
doing so repeatedly does not introduce any errors in file system.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
---
 tests/ext4/035     | 109 +++++++++++++++++++++++++++++++++++++++++++++
 tests/ext4/035.out |   9 ++++
 tests/ext4/group   |   1 +
 3 files changed, 119 insertions(+)
 create mode 100644 tests/ext4/035
 create mode 100644 tests/ext4/035.out

diff --git a/tests/ext4/035 b/tests/ext4/035
new file mode 100644
index 00000000..46898d99
--- /dev/null
+++ b/tests/ext4/035
@@ -0,0 +1,109 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Google, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 035
+#
+# Verify that directory shrinking works and that it does not introduce any
+# errors.
+#
+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.*
+}
+
+_make_files()
+{
+    dirname=$1
+    num_files=$2
+    for x in `seq 1 $num_files`; do
+        fname="$(printf "%.255s\n" "$(perl -e "print \"${x}_\" x 500;")")"
+        touch "${dirname}/${fname}"
+    done
+}
+
+_make_dirs_and_files()
+{
+    parent_dir=$1
+    num_dirs=$2
+    num_files=$3
+    for x in `seq 1 $num_dirs`; do
+	mkdir ${parent_dir}/${x}
+        _make_files "${parent_dir}/${x}" $num_files
+    done
+}
+
+_remove_dirs()
+{
+    parent_dir=$1
+    num_dirs=$2
+    for x in `seq 1 $num_dirs`; do
+        find ${parent_dir}/${x} -type f -exec rm '{}' \;
+    done
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/attr
+
+# real QA test starts here
+_supported_fs ext4
+_supported_os Linux
+
+_require_scratch
+# test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
+_require_attrs
+
+rm -f $seqres.full
+TESTDIR="${SCRATCH_MNT}/scratchdir"
+TESTFILE="${TESTDIR}/testfile"
+
+echo "+ create scratch fs"
+_scratch_mkfs_ext4 > /dev/null 2>&1
+
+echo "+ mount fs image"
+_scratch_mount
+
+mkdir -p ${SCRATCH_MNT}/test
+
+echo "+ create files"
+blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
+_make_files ${SCRATCH_MNT}/test $((blksz * 4 / 256))
+
+size_before=$(du -s "${SCRATCH_MNT}/test" | gawk '{print $1}')
+
+echo "+ remove files"
+rm ${SCRATCH_MNT}/test/*
+
+size_after=$(du -s "${SCRATCH_MNT}/test" | gawk '{print $1}')
+
+if [ $size_after -lt $size_before ]; then
+  echo "+ directory shrinked"
+else
+  _fail "directory did not shrink"
+fi
+
+echo "+ create many directories and files"
+_make_dirs_and_files ${SCRATCH_MNT} 4 10240
+
+echo "+ empty dirs"
+_remove_dirs ${SCRATCH_MNT} 4
+
+umount "${SCRATCH_MNT}"
+
+echo "+ check fs"
+e2fsck -fn ${SCRATCH_DEV} >> $seqres.full 2>&1 || _fail "fsck should not fail"
+
+status=0
+exit
diff --git a/tests/ext4/035.out b/tests/ext4/035.out
new file mode 100644
index 00000000..2d9a34e1
--- /dev/null
+++ b/tests/ext4/035.out
@@ -0,0 +1,9 @@
+QA output created by 035
++ create scratch fs
++ mount fs image
++ create files
++ remove files
++ directory shrinked
++ create many directories and files
++ empty dirs
++ check fs
diff --git a/tests/ext4/group b/tests/ext4/group
index eb744a12..c25205dd 100644
--- a/tests/ext4/group
+++ b/tests/ext4/group
@@ -37,6 +37,7 @@
 032 auto quick ioctl resize
 033 auto ioctl resize
 034 auto quick quota
+035 auto
 271 auto rw quick
 301 aio auto ioctl rw stress defrag
 302 aio auto ioctl rw stress defrag
-- 
2.21.0.rc2.261.ga7da99ff1b-goog

             reply	other threads:[~2019-02-28  0:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-28  0:03 Harshad Shirwadkar [this message]
2019-03-02 16:08 ` [PATCH] ext4/035: Verify directory shrinking Eryu Guan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190228000316.238620-1-harshadshirwadkar@gmail.com \
    --to=harshadshirwadkar@gmail.com \
    --cc=fstests@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.