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

Coly Li coly.li at suse.de
Sun Dec 14 20:02:49 PST 2008



tristan.ye Wrote:
> On Sat, 2008-12-13 at 05:20 +0800, Coly Li wrote:
[snip]
>> +
>> +
>> +use warnings;
>> +use Fcntl ':flock';
>> +
> you'd better define the file and dir first?
> my file;
> my dir;
> 
Thanks for tell me this :-)

[snip]

>> +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.
> 
Sure, I add parameters.

>> +	$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.
I can remove all files started with test.lock in dir firstly. That's more simple.

>> +
>> +	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?
If failed, here we are in the parent. In this test case, parent can be ignorable.

Thanks for your comments :)

-- 
Coly Li
SuSE PRC Labs



More information about the Ocfs2-test-devel mailing list