scripts/setup: Check if target block device is hold by other devices

Change-Id: Ie072e00b980095c5c794a189c0886e128b7377c9
Signed-off-by: Michal Berger <michallinuxstuff@gmail.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11109
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Michal Berger 2022-01-15 15:35:00 +01:00 committed by Tomasz Zawadzki
parent 7610bc38dc
commit bb4657c7c6
2 changed files with 25 additions and 5 deletions

View File

@ -204,15 +204,24 @@ function get_block_dev_from_bdf() {
function get_mounted_part_dev_from_bdf_block() {
local bdf=$1
local blocks block dev mount
local blocks block blockp dev mount holder
hash lsblk || return 1
blocks=($(get_block_dev_from_bdf "$bdf"))
for block in "${blocks[@]}"; do
# Check if the device is hold by some other, regardless if it's mounted
# or not.
for holder in "/sys/class/block/$block"*/holders/*; do
[[ -e $holder ]] || continue
blockp=${holder%/holders*} blockp=${blockp##*/}
if [[ -e $holder/slaves/$blockp ]]; then
echo "holder@$blockp:${holder##*/}"
fi
done
while read -r dev mount; do
if [[ -e $mount ]]; then
echo "$block:$dev"
echo "mount@$block:$dev"
fi
done < <(lsblk -l -n -o NAME,MOUNTPOINT "/dev/$block")
done
@ -302,7 +311,7 @@ function verify_bdf_mounts() {
if ((${#blknames[@]} > 0)); then
local IFS=","
pci_dev_echo "$bdf" "Active mountpoints on ${blknames[*]}, so not binding PCI dev"
pci_dev_echo "$bdf" "Active mountpoints|holders: ${blknames[*]}, so not binding PCI dev"
return 1
fi
}

View File

@ -50,17 +50,21 @@ verify() {
local found=0
: > "$test_file"
if [[ -n $test_file ]]; then
: > "$test_file"
fi
local pci status
while read -r pci _ _ status; do
if [[ $pci == "$dev" && \
$status == *"Active mountpoints on $mounts"* ]]; then
$status == *"Active mountpoints|holders: "*"$mounts"* ]]; then
found=1
fi
done < <(PCI_ALLOWED="$dev" setup output config)
((found == 1))
[[ -n $mount_point ]] || return 0
# Does the mount still exist?
mountpoint -q "$mount_point"
# Does the test file still exist?
@ -160,6 +164,13 @@ dm_mount() {
"$dm_mount" \
"$dm_dummy_test_file"
# umount the dm device and verify again - device should not be
# touched when it's actively being hold, regardless if it's mounted
# or not.
umount "$dm_mount"
verify "${blocks_to_pci["$pv"]}" "holder@$pv0:$dm,holder@$pv1:$dm" "" ""
# All done, start tiding up
cleanup_dm
}