[OpenAFS] locking in OpenAFS 1.2.6 and 1.2.7

Jack Neely slack@quackmaster.net
Thu, 3 Oct 2002 15:43:59 -0400


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

Hi,

I've noticed some differences is the locking behavior between 1.2.6 and
1.2.7 using simple fcntl() locking.  1.2.6 had a patch that seemed to
fix previous locking problems and it passed my locking tests.  1.2.7 has
the same patch but my locking tests do not aquire a lock.

My locking test is attached.  It's pretty much verbatim out of the
openafs bug tracking system.  

Does any one know what's up here?

Thanks
Jack Neely

-- 
Jack Neely <slack@quackmaster.net>
Linux Realm Kit Administration and Development 
PAMS Computer Operations at NC State University
GPG Fingerprint: 1917 5AC1 E828 9337 7AA4  EA6B 213B 765F 3B6A 5B89

--NzB8fVQJ5HfG6fxh
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="locking_test.c"

#include <fcntl.h>
#include <sys/file.h>
#include <stdio.h>

#define	LOCKTYPE(t)	(((t) == F_RDLCK) ? "read" : "write")

main(argc, argv)
int argc;
char *argv[];
{
    int fd;
    int i;

    printf("My pid=%d\n", getpid());

    for (i=1; i<argc; i++) {
	fd = open(argv[i], O_RDONLY, 0664);
	if (fd < 0) {
	    perror(argv[i]);
	    continue;
	}

	checklock(fd, F_RDLCK, argv[i]);
	checklock(fd, F_WRLCK, argv[i]);

	close(fd);
    }
}

checklock(fd, type, name)
int fd;
int type;
char *name;
{
    struct flock flk;
    extern int errno;

    flk.l_type = type;
    flk.l_whence = SEEK_SET;
    flk.l_start = 0;
    flk.l_len = 0;
    if (fcntl(fd, F_GETLK, &flk) < 0) {
	perror(name);
    }
    else {
	printf("%s (%s lock check) is ", name, LOCKTYPE(type));
	
	if (flk.l_type == F_UNLCK) {
	    printf("unlocked for %s\n", LOCKTYPE(type));
	}
	else {
	    printf("locked by pid %d for %s\n",
		   flk.l_pid, LOCKTYPE(flk.l_type));
	}
    }
}



--NzB8fVQJ5HfG6fxh--