Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > problem with sysopen() on nfs

Reply
Thread Tools

problem with sysopen() on nfs

 
 
Michele Dondi
Guest
Posts: n/a
 
      09-18-2004
I want to implement a locking system for a script that shouldn't allow
more than one instance on each machine of a cluster by means of a
lockfile. The relevant code snippet is:

my $lockfile = "$lockdir/$pfx-$host";
sysopen my $lock, $lockfile, O_CREAT | O_EXCL
or die "$0 already running on $host";

Now I'm aware that file operations on nfs are not atomic, but this is
not a big issue since *in this case* the probability of collisions if
ridiculously small.

However it seems that I have another problem, and a more serious one.
Namely the lockfile is actually created in the specified directory,
but it is named .nfs* (I mean, it matches that wildcard...)

Am I missing something obvious? Any workaround/alternative strategy?


TIA
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      09-19-2004
Michele Dondi wrote:
> However it seems that I have another problem, and a more serious one.
> Namely the lockfile is actually created in the specified directory,
> but it is named .nfs* (I mean, it matches that wildcard...)
>
> Am I missing something obvious? Any workaround/alternative strategy?


The workaround is to not delete the file while it is open for reading.

When a local file is openned for reading, and it then deleted (unlinked),
the file is still there even though it does not have a directory entry.
So the process that openned the file can continue reading this now
nameless file.

When a file on an NFS mount is openned for reading, and then is deleted
on the NFS client, the client tells the NFS server to rename the file
to be .nfs{something}, so it can still be read on the client.

To avoid the symptoms you're seeing, just be sure to close all open
file handles that reference the lockfile before deleting the lockfile.
-Joe
 
Reply With Quote
 
 
 
 
Michele Dondi
Guest
Posts: n/a
 
      09-19-2004
On Sun, 19 Sep 2004 03:57:19 GMT, Joe Smith <(E-Mail Removed)>
wrote:

>> Am I missing something obvious? Any workaround/alternative strategy?

>
>The workaround is to not delete the file while it is open for reading.


Huh?!? I don't *think* I'm deleting it anywhere. Granted, I've set a
pair of signal handlers and an END block in which I do delete it
(before closing it). But they shouldn't have been called at all...

[snip explanation]

>To avoid the symptoms you're seeing, just be sure to close all open
>file handles that reference the lockfile before deleting the lockfile.


D'Oh! Now that I think of it I make my program C<fork and exit> to go
in bg, so the END block *is* executed. I'll have to change the logic
of the script.


TY,
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Omni-NFS NFS Server Buffer Overflow Ron Martell Computer Support 0 11-07-2006 09:02 PM
ECLIPSE WORKSPACE PROBLEM ON NFS ganimede70@tiscali.it Java 0 09-26-2006 01:42 PM
Dell NAS Windows 2003 r2 NFS mapping problem =?Utf-8?B?QmFuYW5uYQ==?= Windows 64bit 0 08-31-2006 09:21 AM
NFS shares (Windows to Unix) chown issues =?Utf-8?B?U3RvcmFnZSBlbmdpbmVlciB3aXRoIHF1ZXN0aW9ucw==?= Microsoft Certification 0 03-17-2005 09:37 PM
NFS Issue Matt Cisco 1 03-01-2004 11:25 PM



Advertisments