2 # Ensure that creating many partitions works.
4 # Copyright (C) 2010-2012 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/init.sh"; path_prepend_ ../parted
22 require_scsi_debug_module_
24 grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
25 skip_ 'this system lacks a new-enough libblkid'
28 partition_sectors=256 # sectors per partition
29 n_partitions=60 # how many partitions to create
30 start=2048 # start sector for the first partition
31 gpt_slop=34 # sectors at end of disk reserved for GPT
33 n_sectors=$(($start + n_partitions * partition_sectors + gpt_slop))
35 sectors_per_MiB=$((1024 * 1024 / ss))
36 n_MiB=$(((n_sectors + sectors_per_MiB - 1) / sectors_per_MiB))
37 # create memory-backed device
38 scsi_debug_setup_ sector_size=$ss dev_size_mb=$n_MiB > dev-name ||
39 skip_ 'failed to create scsi_debug device'
40 scsi_dev=$(cat dev-name)
42 n=$((n_MiB * sectors_per_MiB))
43 printf "BYT;\n$scsi_dev:${n}s:scsi:$ss:$ss:gpt:Linux scsi_debug;\n" \
46 parted -s $scsi_dev mklabel gpt || fail=1
47 parted -s $scsi_dev u s p || fail=1
52 end=$((start + partition_sectors - 1))
53 parted -s $scsi_dev mkpart p$i ${start}s ${end}s || fail=1
54 printf "$i:${start}s:${end}s:${partition_sectors}s::p$i:;\n" >> exp
55 test $i = $n_partitions && break
56 start=$((start + partition_sectors))
59 t_final=$(date +%s.%N)
61 # Fail the test if it takes too long.
62 # On Fedora 13, it takes about 15 seconds.
63 # With older kernels, it typically takes more than 150 seconds.
64 $AWK "BEGIN {d = $t_final - $t0; n = $n_partitions; st = 60 < d;"\
65 ' printf "created %d partitions in %.2f seconds\n", n, d; exit st }' /dev/null \
68 parted -m -s $scsi_dev u s p > out || fail=1
69 compare exp out || fail=1
71 # We must remove these partitions before terminating.
72 # Otherwise, even though cleanup-driven rmmod will eventually cause
73 # them to be removed, they may continue to be removed long after
74 # the rmmod cleanup lock has been released, and such removals
75 # can (and regularly did) interfere with the following test.
78 parted -s $scsi_dev rm $i || fail=1
79 test $i = $n_partitions && break