Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

[mv] Flock Locking over NFS



******    message to minivend-users from "Kevin Walsh" <kevin@cursor-software.co.uk>     ******

MiniVend currently uses flock to lock its files but flock is not
supported on Linux when locking files over NFS.

The following patch adds a fcntl locking mechanism that is
supported on Linux/NFS.  Perhaps someone other than us will find
it useful when setting up a MiniVend farm with a shared session
database.

The patch is for lib/Vend/Util.pm (MV 4.04).

-------------------CUT HERE-----------------------------
908a909,944
> ### fcntl locking
> 
> sub fcntl_lock {
>     my ($fh, $excl, $wait) = @_;
>     my $flag = $excl ? F_WRLCK : F_RDLCK;
>     my $buf = pack("ssLL",$flag,0,0,0);
> 
>     LOCKLOOP:{
>         if ($wait) {
>             if (! fcntl($fh, F_SETLKW, $buf)) {
>                 redo LOCKLOOP if $! =~ m/^Interrupted/;
>                 die "Could not lock file: $!\n";
>             }
>         }
>         else {
>             if (! fcntl($fh, F_SETLK, $buf)) {
>                 redo LOCKLOOP if $! =~ m/^Interrupted/;
>                 if ($! =~ m/^Try again/
>                     or $! =~ m/^Resource temporarily unavailable/
>                     or $! =~ m/^Operation would block/) {
>                     return 0;
>                 }
>                 die "Could not lock file: $!\n";
>             }
>         }
>         return 1;
>     }
> }
> 
> sub fcntl_unlock {
>     my ($fh) = @_;
>     my $buf = pack("ssLL",F_WRLCK,0,0,0);
>     fcntl($fh, F_UNLCK, $buf) or die "Could not unlock file: $!\n";
> }
> 
> 
917c953
<         $use = 'flock';
---
>         $use = 'fcntl';
926a963,966
> }
> elsif ($use eq 'fcntl') {
>     $lock_function = \&fcntl_lock;
>     $unlock_function = \&fcntl_unlock;
-------------------CUT HERE-----------------------------

Have the appropriate amount of fun :-)

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/  K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/   kevin@cursor-software.co.uk
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/

-
To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list


Search for: Match: Format: Sort by: