lkml.org 
[lkml]   [2009]   [Feb]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectGFS2 file locking issues
From
Hi,

I'm trying to understand how the FS locking mechanism should work.

I'm running a clustered GFS2 across two nodes, each node is a Xen domU.
To check if locking works correctly I wrote the simple perl script below.
Basically the script opens a file, locks it to prevent others from
writing into it, writes 20 lines into it, then unlocks and closes.

------------------------------------------------------------------------------
#!/usr/bin/perl

# usage:
# lock.pl filename uniq
# filename - file name being written to
# uniq - an unique label to distinguish output of
different processes

use strict;
use Time::HiRes qw(sleep);
use FileHandle;
use Fcntl ':flock';

my $filename = $ARGV[0];
my $uniq = $ARGV[1];

open FH, '>>', $filename or die $!;
flock(FH,LOCK_EX) or die $!;
FH->autoflush(1);

for (1..20) {
print FH "$uniq\n";
sleep (0.1);
}

flock(FH,LOCK_UN);
close FH;
------------------------------------------------------------------------------

I ran that script on both nodes simultaneously with commands:

vm01# perl lock.pl /gfs2/testfile a
vm02# perl lock.pl /gfs2/testfile b

Then to my surprise "a"s and "b"s are randomly shuffled in the testfile like

...
a
a
b
a
b
b
...

whereas I supposed it should have been like

...
a
a
a
b
b
b
...


It looks like either locking is broken in my GFS2 (I use kernel
2.6.18-92.el5xen for CentOS 5.2) or my understanding of locking isn't
correct.
I also tested the script on GFS1 and OCFS2 and it worked well, i.e.
the output was correct.



Thanks,
Kirill


\
 
 \ /
  Last update: 2009-02-11 12:19    [W:0.079 / U:6.540 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site