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

scripts/setup: Skip devices which have any valid data present



This is done to make sure we don't miss more complex setups where
target devices are not mounted but still hold some valid data that
shouldn't be touched in any way.

Also, adjust function names so they clearly indicate what is being
checked.

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


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>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
parent bb4657c7
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -202,9 +202,10 @@ function get_block_dev_from_bdf() {
	done
}

function get_mounted_part_dev_from_bdf_block() {
function get_used_bdf_block_devs() {
	local bdf=$1
	local blocks block blockp dev mount holder
	local used

	hash lsblk || return 1
	blocks=($(get_block_dev_from_bdf "$bdf"))
@@ -216,15 +217,27 @@ function get_mounted_part_dev_from_bdf_block() {
			[[ -e $holder ]] || continue
			blockp=${holder%/holders*} blockp=${blockp##*/}
			if [[ -e $holder/slaves/$blockp ]]; then
				echo "holder@$blockp:${holder##*/}"
				used+=("holder@$blockp:${holder##*/}")
			fi
		done
		while read -r dev mount; do
			if [[ -e $mount ]]; then
				echo "mount@$block:$dev"
				used+=("mount@$block:$dev")
			fi
		done < <(lsblk -l -n -o NAME,MOUNTPOINT "/dev/$block")
		if ((${#used[@]} == 0)); then
			# Make sure we check if there's any valid data present on the target device
			# regardless if it's being actively used or not. This is mainly done to make
			# sure we don't miss more complex setups like ZFS pools, etc.
			if block_in_use "$block" > /dev/null; then
				used+=("data@$block")
			fi
		fi
	done

	if ((${#used[@]} > 0)); then
		printf '%s\n' "${used[@]}"
	fi
}

function collect_devices() {
@@ -253,7 +266,7 @@ function collect_devices() {
					in_use=1
				fi
				if [[ $dev_type == nvme || $dev_type == virtio ]]; then
					if ! verify_bdf_mounts "$bdf"; then
					if ! verify_bdf_block_devs "$bdf"; then
						in_use=1
					fi
				fi
@@ -304,14 +317,14 @@ function collect_driver() {
	echo "$driver"
}

function verify_bdf_mounts() {
function verify_bdf_block_devs() {
	local bdf=$1
	local blknames
	blknames=($(get_mounted_part_dev_from_bdf_block "$bdf")) || return 1
	blknames=($(get_used_bdf_block_devs "$bdf")) || return 1

	if ((${#blknames[@]} > 0)); then
		local IFS=","
		pci_dev_echo "$bdf" "Active mountpoints|holders: ${blknames[*]}, so not binding PCI dev"
		pci_dev_echo "$bdf" "Active devices: ${blknames[*]}, so not binding PCI dev"
		return 1
	fi
}
+7 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ verify() {
	local pci status
	while read -r pci _ _ status; do
		if [[ $pci == "$dev" && \
			$status == *"Active mountpoints|holders: "*"$mounts"* ]]; then
			$status == *"Active devices: "*"$mounts"* ]]; then
			found=1
		fi
	done < <(PCI_ALLOWED="$dev" setup output config)
@@ -116,6 +116,12 @@ nvme_mount() {
		"$nvme_mount" \
		"$nvme_dummy_test_file"

	# umount the nvme device and verify again - device should not be touched
	# when a valid fs is still present.
	umount "$nvme_mount"

	verify "${blocks_to_pci["$nvme_disk"]}" "data@$nvme_disk" "" ""

	# All done, final cleanup
	cleanup_nvme
}