#!/usr/bin/perl use strict; use Test; my $g_rootMount = "/tmp/"; if(@ARGV != 2) { print STDERR "Usage: mount_limit PVFS_CLUSTER NUM_MOUNTS\n"; print STDERR "\tPVFS_CLUSTER - The mount info. i.e. pvfs2_server:port/fs_name\n"; print STDERR "\tNUM_MOUNTS - Number of times to mount the cluster\n"; exit(1); } my $g_pvfsCluster = $ARGV[0]; my $g_numMounts = $ARGV[1]; &execute_mounts($g_rootMount, $g_pvfsCluster, $g_numMounts); #------------------------------------------------------------------------------- # Name : execute_mounts # Parameter List : $rootMount - Prefix to use for all mounts # $pvfsCluster - PVFS cluster to mount # $numMounts - Number of mounts to perform # # # Return Values : 0 - Success # 1 - Failed # Comment : #------------------------------------------------------------------------------- sub execute_mounts { my @args = @_; my $rootMount = $args[0]; my $pvfsCluster = $args[1]; my $numMounts = $args[2]; my $numMounted = 0; my $dirPrefix = "mount_limit.".$$; # append the PID to the end for uniqueness # Loop through and perform the mount of PVFS $nunMounts times my $counter; my $retVal; my $validRet = undef; print STDERR "*****Starting PVFS Mounts*****\n"; print STDERR "Parameter List:\n"; print STDERR "\tRoot Mount Dir = $rootMount\n"; print STDERR "\tPVFS Cluster = $pvfsCluster\n"; print STDERR "\tDir prefix = $dirPrefix\n"; print STDERR "\tNumber of Mounts = $numMounts\n"; # Loop through and mount all the directories for($counter=0;$counter<$numMounts;$counter++) { my $dir; # Build the directory $dir= $rootMount.$dirPrefix.$counter; if(&make_dir($dir)) # If we could NOT create the directory { print STDERR "Unable to perform mkdir on $dir\n"; # Unmount and remove all mounts that executed previously &clean_up($counter, $rootMount, $dirPrefix); # QUIT exit(1); } if(&mount_dir($dir, $pvfsCluster)) # If we could not mount the directory { print STDERR "Unable to perform mount #", $counter + 1, " of $pvfsCluster to $dir\n"; # Unmount and remove all mounts that executed previously &clean_up($counter, $rootMount, $dirPrefix); # QUIT exit(1); } $numMounted++; if($numMounted % 100 == 0) { print STDERR "$numMounted mounts completed\n"; } } # Loop through and perform an LS on the directories # This needs to be done after ALL mounts complete, so that the reference count # to the directories doesn't change with each mount. print STDERR "*****Performing ls checks*****\n"; my $counter_increment = 1; if($numMounts > 100) { $counter_increment = 100; } for($counter=0;$counter<$numMounts;$counter+=$counter_increment) { my $dir; # Build the directory $dir= $rootMount.$dirPrefix.$counter; # Perform an ls on the directory $retVal = `ls -laR $dir`; $retVal =~ s/$dir//g; if(!defined $validRet) { $validRet = $retVal; } # Check the ls against the first ls if($retVal ne $validRet) { print STDERR "Unable to verify the LS\n"; print STDERR "Valid LS = $validRet\n"; print STDERR "Current LS = $retVal\n"; # Unmount and remove all mounts that executed previously # Use numMounted - 1 because this is a true counter, not an index &clean_up($numMounted-1, $rootMount, $dirPrefix); # QUIT exit(1); } if( ($counter+1) % 100 == 0 ) { my $numRemoved = $counter+1; print STDERR "$numRemoved ls checks completed\n"; } } print STDERR "*****Removing Mounts*****\n"; # Loop through and remove all mounts and directories for($counter=0;$counter<$numMounts;$counter++) { my $dir; # Build the directory $dir= $rootMount.$dirPrefix.$counter; &unmount_dir($dir); &delete_dir($dir); if( ($counter+1) % 100 == 0 ) { my $numRemoved = $counter+1; print STDERR "$numRemoved un-mounted\n"; } } exit(0); } #------------------------------------------------------------------------------- # Name : make_dir # Parameter List : $dir - Directory to create # Return Values : 0 - Success # 1 - Failed # Comment : #------------------------------------------------------------------------------- sub make_dir { my @args = @_; my $dir = $args[0]; # Test to see if the directory to use for the mount exists if(system("test -d $dir")) # If the directory doesn't exist { if(system("mkdir -p $dir")) # If the mkdir doesn't work { # Couldn't create directory, return failed return 1; } } return 0; } #------------------------------------------------------------------------------- # Name : mount_dir # Parameter List : $dir - Directory to mount to # $pvfsCluster - PVFS Cluster to mount # Return Values : 0 - Success # 1 - Failed # Comment : #------------------------------------------------------------------------------- sub mount_dir { my @args = @_; my $dir = $args[0]; my $pvfsCluster = $args[1]; # Test to see if the directory to use for the mount exists if(system("mount -t pvfs2 $pvfsCluster $dir")) # If the mount doesn't work { # Couldn't mount directory, return failed return 1; } return 0; } #------------------------------------------------------------------------------- # Name : clean_up # Parameter List : $numMounted - The number of pvfs mounts to clean up # $rootMount - The root directory for all mounts # $dirPrefix - The directory prefix for mounts # Return Values : 0 - Success # 1 - Failed # Comment : #------------------------------------------------------------------------------- sub clean_up { my @args = @_; my $numMounted = $args[0]; my $rootMount = $args[1]; my $dirPrefix = $args[2]; my $counter; # Loop through and unmount and remove the directories we have already done for($counter=0;$counter<=$numMounted;$counter++) { my $dir; # Build the directory $dir= $rootMount.$dirPrefix.$counter; &unmount_dir($dir); &delete_dir($dir); } } #------------------------------------------------------------------------------- # Name : unmount_dir # Parameter List : $dir - Directory to unmount # Return Values : 0 - Success # 1 - Failed # Comment : #------------------------------------------------------------------------------- sub unmount_dir { my @args = @_; my $dir = $args[0]; # Test to see if the directory to use for the mount exists if(system("umount $dir")) # If the mount doesn't work { # Couldn't mount directory, return failed return 1; } return 0; } #------------------------------------------------------------------------------- # Name : delete_dir # Parameter List : $dir - Directory to unmount # Return Values : 0 - Success # 1 - Failed # Comment : #------------------------------------------------------------------------------- sub delete_dir { my @args = @_; my $dir = $args[0]; # Test to see if the directory to use for the mount exists if(system("rmdir $dir")) # If the mount doesn't work { # Couldn't mount directory, return failed return 1; } return 0; }