linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kirill Kuvaldin <kirill.kuvaldin@gmail.com>
To: linux-cluster@redhat.com, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: GFS2 file locking issues
Date: Wed, 11 Feb 2009 13:55:08 +0300	[thread overview]
Message-ID: <2d42915c0902110255k3c0741a9s6830765bce6be052@mail.gmail.com> (raw)

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

             reply	other threads:[~2009-02-11 10:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-11 10:55 Kirill Kuvaldin [this message]
2009-02-11 13:36 ` GFS2 file locking issues steve
2009-02-11 14:37   ` Kirill Kuvaldin
2009-02-11 17:18     ` steve
2009-02-11 17:57       ` Kirill Kuvaldin
2009-02-12 11:22         ` steve

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2d42915c0902110255k3c0741a9s6830765bce6be052@mail.gmail.com \
    --to=kirill.kuvaldin@gmail.com \
    --cc=linux-cluster@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).