Commit bb4657c7 authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

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



Change-Id: Ie072e00b980095c5c794a189c0886e128b7377c9
Signed-off-by: default avatarMichal Berger <michallinuxstuff@gmail.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11109


Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 7610bc38
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -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
}
+13 −2
Original line number Diff line number Diff line
@@ -50,17 +50,21 @@ verify() {

	local found=0

	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
}