[Gluster-devel] Locking a new file fails

Kevan Benson kbenson at a-1networks.com
Thu Aug 9 20:16:59 UTC 2007

When opening and flocking a new file (that is, one that doesn't pre-exist), a 
second client trying to open and lock a file of the same name does not block 
waiting for the lock.  If the file already exists, the second file lock 
blocks as expected.

Two processes on the same client do correctly block on the file if it's on a 
glusterfs mount.

volume share
        type storage/posix
        option directory /exports/test

volume brick
        type features/posix-locks
        subvolumes share

volume server
        type protocol/server
        option transport-type tcp/server
        option listen-port 6996
        subvolumes brick
        option auth.ip.brick.allow *

volume brick
        type protocol/client
        option transport-type tcp/client
        option remote-host
        option remote-port 6996
        option remote-subvolume brick

Test program:

$| = 1;
use Fcntl ':flock';

my $file = shift or "./testlockfile";
my $delay = shift or 10;
my $hostname = `hostname`;
print "opening file\n";
open(my $testfile, '>>', $file) or die("$!\n");
print localtime(time())." :: opened file\n";
print localtime(time())." :: locking file\n";
flock($testfile, LOCK_EX);
print localtime(time())." :: locked file\n";
print $testfile "$hostname start ".localtime(time())."\n";
sleep $delay;
print $testfile "$hostname end ".localtime(time())."\n";
flock($testfile, LOCK_UN);
print localtime(time())." :: unlocked file\n";
exit 0;

Command line (run from each client):
/mnt/glusterfs/testlock.pl /mnt/glusterfs/testfile7 5

- Kevan Benson
- A-1 Networks

More information about the Gluster-devel mailing list