|
| 1 | +#!/bin/bash -x |
| 2 | + |
| 3 | +# SPDX-License-Identifier: GPL-2.0 |
| 4 | +# Copyright(c) 2015-2019 Intel Corporation. All rights reserved. |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +SKIP=77 |
| 9 | +FAIL=1 |
| 10 | +SUCCESS=0 |
| 11 | + |
| 12 | +. ./common |
| 13 | + |
| 14 | +check_min_kver "5.2" || do_skip "may lack align sub-section hotplug support" |
| 15 | + |
| 16 | +MNT=test_dax_mnt |
| 17 | +mkdir -p $MNT |
| 18 | + |
| 19 | +TEST_SIZE=$((16<<20)) |
| 20 | +MIN_AVAIL=$((TEST_SIZE*4)) |
| 21 | +MAX_NS=10 |
| 22 | +NAME="subsection-test" |
| 23 | + |
| 24 | +ndctl list -N | jq -r ".[] | select(.name==\"subsection-test\") | .dev" |
| 25 | + |
| 26 | +rc=$FAIL |
| 27 | +cleanup() { |
| 28 | + if [ $rc -ne $SUCCESS ]; then |
| 29 | + echo "test/sub-section.sh: failed at line $1" |
| 30 | + fi |
| 31 | + if mountpoint -q $MNT; then |
| 32 | + umount $MNT |
| 33 | + fi |
| 34 | + rmdir $MNT |
| 35 | + # opportunistic cleanup, not fatal if these fail |
| 36 | + namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev") |
| 37 | + for i in $namespaces |
| 38 | + do |
| 39 | + if ! $NDCTL destroy-namespace -f $i; then |
| 40 | + echo "test/sub-section.sh: cleanup() failed to destroy $i" |
| 41 | + fi |
| 42 | + done |
| 43 | + exit $rc |
| 44 | +} |
| 45 | + |
| 46 | +trap 'err $LINENO cleanup' ERR |
| 47 | + |
| 48 | +json=$($NDCTL list -R -b ACPI.NFIT) |
| 49 | +region=$(echo $json | jq -r "[.[] | select(.available_size >= $MIN_AVAIL)][0].dev") |
| 50 | +avail=$(echo $json | jq -r "[.[] | select(.available_size >= $MIN_AVAIL)][0].available_size") |
| 51 | +if [ -z $region ]; then |
| 52 | + exit $SKIP |
| 53 | +fi |
| 54 | + |
| 55 | +iter=$((avail/TEST_SIZE)) |
| 56 | +if [ $iter -gt $MAX_NS ]; then |
| 57 | + iter=$MAX_NS; |
| 58 | +fi |
| 59 | + |
| 60 | +for i in $(seq 1 $iter) |
| 61 | +do |
| 62 | + json=$($NDCTL create-namespace -s $TEST_SIZE --no-autorecover -r $region -n "$NAME") |
| 63 | + dev=$(echo $json | jq -r ".blockdev") |
| 64 | + mkfs.ext4 -b 4096 /dev/$dev |
| 65 | + mount -o dax /dev/$dev $MNT |
| 66 | + umount $MNT |
| 67 | +done |
| 68 | + |
| 69 | +namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev") |
| 70 | +for i in $namespaces |
| 71 | +do |
| 72 | + $NDCTL disable-namespace $i |
| 73 | + $NDCTL enable-namespace $i |
| 74 | + $NDCTL destroy-namespace $i -f |
| 75 | +done |
| 76 | + |
| 77 | +rc=$SUCCESS |
| 78 | +cleanup $LINENO |
0 commit comments