[OpenAFS] Re: openafs does not put a [correct] value in fsinfo.f_type?

Adam Megacz megacz@cs.berkeley.edu
Mon, 25 Dec 2006 19:44:36 -0800


Jeffrey Altman <jaltman@secure-endpoints.com> writes:
>> Absolutely.  In fact, I'd already implemented that.  The only problem
>> is that it doesn't work on Linux since the Linux AFS client does a
>> more elaborate job of faking the byte-range locks.

> The AFS Linux client does not implement this functionality.

We must be talking about different things here.  When I run the
program below on MacOS, it prints "parent and child both got locks";
when I run it on Linux, it prints "parent got lock, child did not".
Both are running OpenAFS 1.4.2.

  $ gcc main.c 
  $ ./a.out /afs/...any_file...

  - a

..............................................................................
/* main.c */
#include <sys/fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
  struct flock lock;
  int fd, result;
  fd = open(argv[1], O_RDWR | O_TRUNC);
  if (fd<0) { printf("error\n"); return; }

  /* write some junk */
  write(fd, &fd, 4);

  lock.l_type = F_WRLCK;
  lock.l_len = 1;
  lock.l_start = 0;
  lock.l_whence = SEEK_SET;
  
  result = fcntl(fd, F_SETLK, &lock);
  if (result) {
    printf("parent could not get the lock\n");
    return;
  }
  
  if (fork()) {
    wait(&result);
    if (!result) {
      printf("parent and child both got locks\n");
    } else {
      printf("parent got lock, child did not\n");
    }
    
  } else {
    exit(fcntl(fd, F_SETLK, &lock));
  }
}