[OpenAFS] Re: AFS Locking

Sidney Cammeresi sac@cheesecake.org
Thu, 1 Jun 2006 09:02:25 -0500


--gatW/ieO32f1wygP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Thu, 18 May 2006 at 13.14.31 -0400, Chaskiel M Grundman wrote:
> I suggest switching to fcntl() style locking, which will work if l_whence 
> is SEEK_SET, and l_start and l_len are both 0.

I tried to use fcntl-style locking in the attached C program using Linux
2.6.16 and OpenAFS 1.4.1.  It works perfectly on local files and on AFS
files if I run two processes on the same client.  If I try to lock from
two different clients, however, the first one gets the lock as it should,
then the second one fails, as it should, but the call to fcntl does not
block as I told it to.  Instead, it returns immediately and sets errno
to EAGAIN.  Is this a bug or a feature?  (And if a feature, why?)

-- 
Sidney CAMMERESI
http://www.cheesecake.org/sac/

--gatW/ieO32f1wygP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="foo.c"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

void error (const char *msg)
{
	perror (msg);
	exit (1);
}

int main (void)
{
	int fd;
	struct flock flock;

	if ((fd = open ("/afs/cheesecake.org/user/sac/foo", O_RDWR)) < 0)
		error ("open");
	flock.l_type = F_WRLCK;
	flock.l_whence = SEEK_SET;
	flock.l_start = flock.l_len = 0;
	if (fcntl (fd, F_SETLKW, &flock) < 0)
		error ("fcntl");
	printf ("got the lock, sleeping...\n");
	sleep (60);
	close (fd);
	return 0;
}


--gatW/ieO32f1wygP--