[Ocfs2-test-devel] [RFC][PATCH] ocfs2-test: add concurrent flock() test case, v2

tristan.ye tristan.ye at oracle.com
Sun Dec 14 18:41:16 PST 2008


On Sat, 2008-12-13 at 05:20 +0800, Coly Li wrote:
> This script is initialized by Sunil, to verify lockres mastery race in flock(). For further
> information of the lockres mastery race issue, read Novell bugzilla page:
> https://bugzilla.novell.com/show_bug.cgi?id=425491
> 
> Sunil, Marcos and Tristan, this version add directory path checking, could you kindly give me a SOB ?
> 
> Signed-off-by: Coly Li <coly.li at suse.de>
> ---
>  programs/flock_tests/Makefile                 |    2 +-
>  programs/flock_tests/concurrent_flock_test.pl |   54 +++++++++++++++++++++++++
>  2 files changed, 55 insertions(+), 1 deletions(-)
> 
> diff --git a/programs/flock_tests/Makefile b/programs/flock_tests/Makefile
> index 8b6bc5c..82659ec 100644
> --- a/programs/flock_tests/Makefile
> +++ b/programs/flock_tests/Makefile
> @@ -15,7 +15,7 @@ DIST_FILES = $(SOURCES)
> 
>  BIN_PROGRAMS = flock_unit_test
> 
> -BIN_EXTRA = run_flock_unit_test.py
> +BIN_EXTRA = run_flock_unit_test.py concurrent_flock_test.pl
> 
>  flock_unit_test: $(OBJECTS)
>  	$(LINK)
> diff --git a/programs/flock_tests/concurrent_flock_test.pl
> b/programs/flock_tests/concurrent_flock_test.pl
> new file mode 100644
> index 0000000..45baad0
> --- /dev/null
> +++ b/programs/flock_tests/concurrent_flock_test.pl
> @@ -0,0 +1,54 @@
> +#!/usr/bin/perl
> +#
> +# concurrent_flock_test.pl - A handy tool to test concurrent flock() on single
> +#                            node
> +#
> +# Initialized by Sunil Mushran <sunil.mushran at oracle.com>
> +# Modified by Coly Li <coly.li at suse.de>
> +#
> +# Usage: concurrent_flock_test.pl <dir>
> +#
> +# Example: concurrent_flock_test.pl /mnt/test/
> +#           /mnt/test is directory within mounted ocfs2 volume
> +#
> +# the perl script encloses the 20 fork loop into another loop that changes the
> +# filename. To startwith, touch 5000 files(test.flock%d). umount and mount
> +# again. This will drop the caches. Now before running any ls, run flock.pl.
> +# It will spawn 20 processes to flock() each file and wait till the 20 forks
> +# have exited before letting loose another 20 for the next file. (Makesure
> +# you have another node or two or more that have just mounted that volume.).
> +#
> +
> +
> +use warnings;
> +use Fcntl ':flock';
> +
you'd better define the file and dir first?
my file;
my dir;

> +$| = 1;
> +$dir=$ARGV[0];
> +if (! $dir) {
> +	print "Usage: concurrent_flock_test.pl <dir>\n";
> +	exit(1);
> +}
> +if (! -d $dir) {
> +	print "$dir is not directory.\n";
> +	exit(1);
> +}
> +
> +for (my $y = 0; $y < 5000; $y ++) {
The iteration 5000 and fork number 20 should also should be argumentable
here in case we need a flexsible testing load.

> +	$file = $dir . "/test.lock" . $y;
According to your comments, file should be touched first, so we may need
to check the existence of this regular file here.
> +
> +	printf "[%s] %s\n", $$, $file;
> +
> +	for (my $x = 0; $x < 20; $x ++) {
> +		my $pid = fork();
> +		if ($pid == 0) {
> +			my $fh;
> +			open($fh, ">> $file") or die("Can't open '$file': $!");
> +			printf "[%s] lock %s: %s\n", $$, $file,
> +			flock($fh, LOCK_EX) ? 'done' : $!;
> +			close($fh);
> +			exit(0);
> +		}
How about fork() failed here? retry or bypass?
> +	}
> +	while (wait > 0) { ; }
> +}

Tristan.

> 




More information about the Ocfs2-test-devel mailing list