]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
populate: create hardlinks for parent pointers
authorDarrick J. Wong <djwong@kernel.org>
Thu, 20 Jun 2024 20:57:58 +0000 (13:57 -0700)
committerZorro Lang <zlang@kernel.org>
Sun, 23 Jun 2024 15:04:36 +0000 (23:04 +0800)
Create some hardlinked files so that we can exercise parent pointers.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/populate
src/popdir.pl

index 15f8055c2ca85c222a67e4309219a53c9d7eb153..9fda19df06a5097918d95f5c099b3ed2ba61ffa0 100644 (file)
@@ -464,6 +464,48 @@ _scratch_xfs_populate() {
                cp --reflink=always "${SCRATCH_MNT}/REFCOUNTBT" "${SCRATCH_MNT}/REFCOUNTBT2"
        fi
 
+       # Parent pointers
+       is_pptr="$(_xfs_has_feature "$SCRATCH_MNT" parent -v)"
+       if [ $is_pptr -gt 0 ]; then
+               echo "+ parent pointers"
+
+               # Create a couple of parent pointers
+               __populate_create_dir "${SCRATCH_MNT}/PPTRS" 1 '' \
+                       --hardlink --format "two_%d"
+
+               # Create one xattr leaf block of parent pointers
+               nr="$((blksz * 2 / 16))"
+               __populate_create_dir "${SCRATCH_MNT}/PPTRS" ${nr} '' \
+                       --hardlink --format "many%04d"
+
+               # Create multiple xattr leaf blocks of large parent pointers
+               nr="$((blksz * 16 / 16))"
+               __populate_create_dir "${SCRATCH_MNT}/PPTRS" ${nr} '' \
+                       --hardlink --format "y%0254d"
+
+               # Create multiple paths to a file
+               local moof="${SCRATCH_MNT}/PPTRS/moofile"
+               touch "${moof}"
+               for ((i = 0; i < 4; i++)); do
+                       mkdir -p "${SCRATCH_MNT}/PPTRS/SUB${i}"
+                       ln "${moof}" "${SCRATCH_MNT}/PPTRS/SUB${i}/moofile"
+               done
+
+               # Create parent pointers of various lengths
+               touch "${SCRATCH_MNT}/PPTRS/vlength"
+               local len_len
+               local tst
+               local fname
+               ln "${SCRATCH_MNT}/PPTRS/vlength" "${SCRATCH_MNT}/PPTRS/b"
+               for len in 32 64 96 128 160 192 224 250 255; do
+                       len_len="${#len}"
+                       tst="$(perl -e "print \"b\" x (${len} - (${len_len} + 1))")"
+                       fname="v${tst}${len}"
+                       ln "${SCRATCH_MNT}/PPTRS/vlength" \
+                               "${SCRATCH_MNT}/PPTRS/${fname}"
+               done
+       fi
+
        # Copy some real files (xfs tests, I guess...)
        echo "+ real files"
        test $fill -ne 0 && __populate_fill_fs "${SCRATCH_MNT}" 5
index e89095aafe0b8e0aca89fe9c4a6793f8fc5badb6..0104957a3c941efc2a6d5cdc337abda17cf60b18 100755 (executable)
@@ -17,6 +17,7 @@ GetOptions("start=i" => \$start,
           "dir=s" => \$dir,
           "remove!" => \$remove,
           "help!" => \$help,
+          "hardlink!" => \$hardlink,
           "verbose!" => \$verbose);
 
 
@@ -35,6 +36,7 @@ Options:
   --format=str      printf formatting string for file name ("%08d")
   --verbose         verbose output
   --help            this help screen
+  --hardlink        hardlink subsequent files to the first one created
 EOF
   exit(1) unless defined $help;
   # otherwise...
@@ -56,12 +58,21 @@ if ($file_pct < 0) {
        $file_pct = 100;
 }
 
+if ($hardlink) {
+       $file_pct = 100;
+       $link_fname = sprintf($format, $start);
+}
+
 for ($i = $start; $i <= $end; $i += $incr) {
        $fname = sprintf($format, $i);
 
        if ($remove) {
                $verbose && print "rm $fname\n";
                unlink($fname) or rmdir($fname) or die("unlink $fname");
+       } elsif ($hardlink && $i > $start) {
+               # hardlink everything after the first file
+               $verbose && print "ln $link_fname $fname\n";
+               link $link_fname, $fname;
        } elsif (($i % 100) < $file_pct) {
                # create a file
                $verbose && print "touch $fname\n";