[Lustre-discuss] Locks in Lustre

Florin Isaila florin.isaila at gmail.com
Thu Oct 4 13:37:26 PDT 2007


Hi,

are locks in Lustre implemented?

Running the program from below on lonestar cluster at TACC on a Lustre
file returns the following error:

lslogin2% ./a.out /work/teragrid/tg458242/locked 0
Locking
after fcntl = err=-1
Lock error: Function not implemented


Thanks
Florin


#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

main(int argc, char **argv){
  struct flock lock;
  int fd, err, pid;

  if (argc < 3) {
    printf("Usage %s file proc_id\n", argv[0]);
    exit(1);
  }
  pid = atoi(argv[2]);

  fd = open(argv[1], O_CREAT|O_RDWR, 0666);
  write(fd, "abcd",4);

  lock.l_type	  = F_WRLCK; // write lock
  lock.l_whence = SEEK_SET;
  lock.l_start  = pid*2;
  lock.l_len	  = pid*2+1;
  printf("Locking\n");

  do {
    err = fcntl(fd, F_SETLK, &lock);
    printf("after fcntl = err=%d\n", err);

  } while (err && (errno == EINTR));

  if (err && (errno != EBADF)) {
    perror("Lock error");
    exit(1);
  }

  printf("Sleeping 5 secs\n");
  sleep(5);
  printf("Unlocking\n");

  lock.l_type	  = F_UNLCK; //free lock
  do {
    err = fcntl(fd, F_SETLK, &lock);
  } while (err && (errno == EINTR));

  if (err && (errno != EBADF)) {
    perror("Unlock error");
    exit(1);
  }
  close(fd);

}




More information about the lustre-discuss mailing list