File: sub-section.sh

package info (click to toggle)
ndctl 81-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,436 kB
  • sloc: ansic: 41,432; sh: 3,931; makefile: 28
file content (77 lines) | stat: -rwxr-xr-x 1,704 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash -x
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2015-2020 Intel Corporation. All rights reserved.

set -e

SKIP=77
FAIL=1
SUCCESS=0

. $(dirname $0)/common

check_min_kver "5.3" || do_skip "may lack align sub-section hotplug support"

MNT=test_dax_mnt
mkdir -p $MNT

TEST_SIZE=$((16<<20))
MIN_AVAIL=$((TEST_SIZE*4))
MAX_NS=10
NAME="subsection-test"

ndctl list -N | jq -r ".[] | select(.name==\"subsection-test\") | .dev"

rc=$FAIL
cleanup() {
	if [ $rc -ne $SUCCESS ]; then
		echo "test/sub-section.sh: failed at line $1"
	fi
	if mountpoint -q $MNT; then
		umount $MNT
	fi
	rm -rf $MNT
	# opportunistic cleanup, not fatal if these fail
	namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev")
	for i in $namespaces
	do
		if ! $NDCTL destroy-namespace -f $i; then
			echo "test/sub-section.sh: cleanup() failed to destroy $i"
		fi
	done
	exit $rc
}

trap 'err $LINENO cleanup' ERR

json=$($NDCTL list -R -b ACPI.NFIT)
region=$(echo $json | jq -r "[.[] | select(.available_size >= $MIN_AVAIL)][0].dev")
avail=$(echo $json | jq -r "[.[] | select(.available_size >= $MIN_AVAIL)][0].available_size")
if [ -z $region ]; then
	exit $SKIP
fi

iter=$((avail/TEST_SIZE))
if [ $iter -gt $MAX_NS ]; then
	iter=$MAX_NS;
fi

for i in $(seq 1 $iter)
do
	json=$($NDCTL create-namespace -s $TEST_SIZE --no-autorecover -r $region -n "$NAME")
	dev=$(echo $json | jq -r ".blockdev")
	mkfs.ext4 -b 4096 /dev/$dev
	mount -o dax /dev/$dev $MNT
	umount $MNT
done

namespaces=$($NDCTL list -N | jq -r ".[] | select(.name==\"$NAME\") | .dev")
for i in $namespaces
do
	$NDCTL disable-namespace $i
	$NDCTL enable-namespace $i
	$NDCTL destroy-namespace $i -f
done

rc=$SUCCESS
cleanup $LINENO