From 218669e55de18313cb31e9f67c5b7b73f0fa755e Mon Sep 17 00:00:00 2001 From: Pierre Equoy Date: Thu, 16 Feb 2017 15:04:59 +0800 Subject: Automatically mount drives when running storage tests When running disk/storage_device_* jobs, if the drive is not mounted, we now check if it can be mounted (i.e. if it has a partition) and if possible we mount it to a dedicated temporary location in order to perform the storage tests. LP: #1660386 --- bin/storage_test | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/bin/storage_test b/bin/storage_test index ef19c5e..40cc3f2 100755 --- a/bin/storage_test +++ b/bin/storage_test @@ -30,6 +30,34 @@ function run_bonnie() { fi } +# Find the largest partition that holds a supported filesystem on $disk_device. +# This code is adapted from a similar function in `disk_stress_ng`. +# Output: +# $largest_part -- Device filename of largest qualifying partition or logical volume +# $largest_size -- Size of largest qualifying partition or logical volume +# $largest_fs -- Filesystem (ext4, etc.) used on largest qualifying partition or logical volume +# $unsupported_fs -- Empty or contains name of unsupported filesystem found on disk +find_largest_partition() { + largest_part="" + largest_size=0 + partitions=$(lsblk -b -l -n -o NAME,SIZE,TYPE,MOUNTPOINT $disk | grep part | tr -s " ") + unsupported_fs="" + for partition in $(echo "$partitions" | cut -d " " -f 1) ; do + part_size=$(echo "$partitions" | grep "$partition " | cut -d " " -f 2) + local blkid_info=$(blkid -s TYPE /dev/$partition | grep -E ext2\|ext3\|ext4\|xfs\|jfs\|btrfs) + if [ "$part_size" -gt "$largest_size" ] && [ -n "$blkid_info" ] ; then + largest_size=$part_size + largest_part="/dev/$partition" + largest_fs=$(blkid -s TYPE "/dev/$partition" | cut -d "=" -f 2) + fi + local blkid_info=$(blkid -s TYPE /dev/$partition | grep -E ntfs\|vfat\|hfs) + if [ -n "$blkid_info" ] ; then + # If there's an NTFS, HFS+, or FAT filesystem on the disk make note of it.... + unsupported_fs=$(blkid -s TYPE "/dev/$partition" | cut -d "=" -f 2) + fi + done +} # find_largest_partition() + disk=/dev/$1 if [ -b $disk ] @@ -62,7 +90,17 @@ then echo "$disk is mounted, proceeding." else echo "$disk is not mounted. It must be mounted before testing." - exit 1 + find_largest_partition + if [ -n "$largest_part" ] + then + dest=/tmp/drive/$partition + echo "Mounting $largest_part into $dest..." + mkdir -p $dest + mount $largest_part $dest + else + echo "$disk has no partition. Please format this drive and re-launch the test." + exit 1 + fi fi -- cgit v1.2.3