Why is my lock only called for unlocking?

124 views
Skip to first unread message

Jean-Noel Moyne

unread,
Aug 26, 2013, 8:20:15 PM8/26/13
to osxfus...@googlegroups.com
I have a problem that I hope someone here can help me with. Implementing a file system using OSXFuse I need this file system to implement file locking (as done through a fcntl call) . So I implemented a lock() function, but the function does not seem to be called when a process locks a file, but only when it's unlocking the file.

To explain I created the very small test program below:

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

void main()
{
    FILE *fh;

    fh = fopen ("test", "r");

    struct flock fl; int err;
    fl.l_type = F_WRLCK; fl.l_whence = 0; fl.l_start = 0; fl.l_len = 0;
    err = fcntl(fh, F_SETLK, &fl);

    fl.l_type = F_UNLCK; fl.l_whence = 0; fl.l_start = 0; fl.l_len = 0;
    err = fcntl(fh, F_SETLK, &fl);

    fclose (fh);

}


I run this program on a file called 'test' in my mounted file system and here's my problem:

the call:
    fl.l_type = F_WRLCK; fl.l_whence = 0; fl.l_start = 0; fl.l_len = 0;
    err = fcntl(fh, F_SETLK, &fl);

does NOT call my lock() function in my implementation of the file system ... it does not seem to do anything (using -d in FUSE does not show anything when that call is being invoked)

If that matters, the second call:
    fl.l_type = F_UNLCK; fl.l_whence = 0; fl.l_start = 0; fl.l_len = 0;
    err = fcntl(fh, F_SETLK, &fl);

does call my lock() function with l_type being equal to F_UNLCK


So, can anyone explain to me why lock() is not called when locking the file from a fcntl call???



Benjamin Fleischer

unread,
Aug 27, 2013, 3:47:18 AM8/27/13
to osxfus...@googlegroups.com
Are you referring to the getlk and setlk FUSE callbacks? The corresponding FUSE requests FUSE_GETLK and FUSE_SETLK are not implemented in OSXFUSE.

--
You received this message because you are subscribed to the Google Groups "OSXFUSE" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osxfuse-grou...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jean-Noel Moyne

unread,
Aug 27, 2013, 8:17:14 PM8/27/13
to osxfus...@googlegroups.com
Well, I'm referring to the FUSE lock callback, which is defined in fuse.h as below:

/**

* Perform POSIX file locking operation

*

* The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.

*

* For the meaning of fields in 'struct flock' see the man page

* for fcntl(2).  The l_whence field will always be set to

* SEEK_SET.

*

* For checking lock ownership, the 'fuse_file_info->owner'

* argument must be used.

*

* For F_GETLK operation, the library will first check currently

* held locks, and if a conflicting lock is found it will return

* information without calling this method. This ensures, that

* for local locks the l_pid field is correctly filled in. The

* results may not be accurate in case of race conditions and in

* the presence of hard links, but it's unlikly that an

* application would rely on accurate GETLK results in these

* cases.  If a conflicting lock is not found, this method will be

* called, and the filesystem may fill out l_pid by a meaningful

* value, or it may leave this field zero.

*

* For F_SETLK and F_SETLKW the l_pid field will be set to the pid

* of the process performing the locking operation.

*

* Note: if this method is not implemented, the kernel will still

* allow file locking to work locally.  Hence it is only

* interesting for network filesystems and similar.

*

* Introduced in version 2.6

*/

int (*lock) (const char *, struct fuse_file_info *, int cmd,

    struct flock *);

Barry....@primebase.org

unread,
Jun 20, 2018, 6:46:58 PM6/20/18
to OSXFUSE
I have the exact same question.

Was this ever resolved?
Reply all
Reply to author
Forward
0 new messages