Skip to contentSkip to conversation

OFD ("file private") locks and NFS

DISCUSSION Michael Kerrisk (man-pages) 4 participants 7 messages Apr 29, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Jeff,

I've been looking a bit at the fcntl() documentation of traditional (F_SETLK) record locking, and a question just jumped out at me. Is it worth considering some future-proofing in the design of OFD locks ("open file description locks", formerly known as "file-private locks")?

What I am thinking of here is that on some systems, the traditional 'struct flock' has a nonstandard field, l_sysid, that is used on F_GETLK to identify the remote system on which a lock is held. Should the design of OFD locks allow for such a field (now, or in the future), which might be useful in the context of locking on network file systems such as NFS.

Put more simply, should the new OFD locking system be using a new structure for describing locks, rather than the traditional 'struct flock'? Defining a new structure, might be useful to allow for future extensions to the API.

Cheers,

Michael

Signature · 3 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
#1 lore raw

[CC+= linux-nfs@]

Quoted 13 lines · Michael Kerrisk (man-pages)

Hi Jeff,

I've been looking a bit at the fcntl() documentation of traditional (F_SETLK) record locking, and a question just jumped out at me. Is it worth considering some future-proofing in the design of OFD locks ("open file description locks", formerly known as "file-private locks")?

What I am thinking of here is that on some systems, the traditional 'struct flock' has a nonstandard field, l_sysid, that is used on F_GETLK to identify the remote system on which a lock is held. Should the design of OFD locks allow for such a field (now, or in the future), which might be useful in the context of locking on network file systems such as NFS.

Quoted 4 lines

Put more simply, should the new OFD locking system be using a new structure for describing locks, rather than the traditional 'struct flock'? Defining a new structure, might be useful to allow for future extensions to the API.

Just add one further detail here. What I'm thinking is, maybe instead there should be something like:

struct flockx {
    int flags;
    /* Other fields like 'struct flock' */
    char reserved[32];	/* Or some suitable value */
}

That flags field might always be zero for now, but in the future it could be used on the setlk and getlk operations to indicate the presence of additional fields in the structure.

Cheers,

Michael

Signature · 3 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
#2 lore raw
Quoted 30 lines · On Tue, 29 Apr 2014 10:47:07 +0200 "Michael Kerrisk (man-pages)"…

[CC+= linux-nfs@]

Quoted 13 lines · Michael Kerrisk (man-pages)

Hi Jeff,

I've been looking a bit at the fcntl() documentation of traditional (F_SETLK) record locking, and a question just jumped out at me. Is it worth considering some future-proofing in the design of OFD locks ("open file description locks", formerly known as "file-private locks")?

What I am thinking of here is that on some systems, the traditional 'struct flock' has a nonstandard field, l_sysid, that is used on F_GETLK to identify the remote system on which a lock is held. Should the design of OFD locks allow for such a field (now, or in the future), which might be useful in the context of locking on network file systems such as NFS.

Quoted 4 lines

Put more simply, should the new OFD locking system be using a new structure for describing locks, rather than the traditional 'struct flock'? Defining a new structure, might be useful to allow for future extensions to the API.

Just add one further detail here. What I'm thinking is, maybe instead there should be something like:

struct flockx {
    int flags;
    /* Other fields like 'struct flock' */
    char reserved[32];	/* Or some suitable value */
}
Quoted 8 lines

That flags field might always be zero for now, but in the future it could be used on the setlk and getlk operations to indicate the presence of additional fields in the structure.

Cheers,

Michael

I considered that early on when I did this, but I don't think it's really helpful. I'm just not a fan of padding out structs when it's not clear what would eventually go in there.

The problem is that once actually go to try to convert those from "reserved" to something usable, it becomes a nightmare for userland to figure that out. How do I know whether my kernel supports the stuff I put in those fields or will just ignore them?

If we really find later that we need to do something like this, I think we'd be better off adding a new set of cmd values along with the "extended" struct, or possibly a new syscall. Some of the samba folks were interested in an async locking mechanism too, so something like that could be added in conjunction with such an interface.

Signature · 5 lines
Jeff Layton <[email protected]>
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

Hi Jeff,

Quoted 37 lines · Jeff Layton
Quoted 34 lines · On Tue, 29 Apr 2014 10:47:07 +0200 "Michael Kerrisk (man-pages)"…

[CC+= linux-nfs@]

Quoted 13 lines · Michael Kerrisk (man-pages)

Hi Jeff,

I've been looking a bit at the fcntl() documentation of traditional (F_SETLK) record locking, and a question just jumped out at me. Is it worth considering some future-proofing in the design of OFD locks ("open file description locks", formerly known as "file-private locks")?

What I am thinking of here is that on some systems, the traditional 'struct flock' has a nonstandard field, l_sysid, that is used on F_GETLK to identify the remote system on which a lock is held. Should the design of OFD locks allow for such a field (now, or in the future), which might be useful in the context of locking on network file systems such as NFS.

Quoted 4 lines

Put more simply, should the new OFD locking system be using a new structure for describing locks, rather than the traditional 'struct flock'? Defining a new structure, might be useful to allow for future extensions to the API.

Just add one further detail here. What I'm thinking is, maybe instead there should be something like:

struct flockx {
    int flags;
    /* Other fields like 'struct flock' */
    char reserved[32];        /* Or some suitable value */
}

That flags field might always be zero for now, but in the future it could be used on the setlk and getlk operations to indicate the presence of additional fields in the structure.

Quoted 8 lines
Quoted 4 lines

Cheers,

Michael

I considered that early on when I did this, but I don't think it's really helpful. I'm just not a fan of padding out structs when it's not clear what would eventually go in there.

Okay.

Quoted 4 lines

The problem is that once actually go to try to convert those from "reserved" to something usable, it becomes a nightmare for userland to figure that out. How do I know whether my kernel supports the stuff I put in those fields or will just ignore them?

(That was my purpose with the "flags" field.)

Quoted 5 lines

If we really find later that we need to do something like this, I think we'd be better off adding a new set of cmd values along with the "extended" struct, or possibly a new syscall. Some of the samba folks were interested in an async locking mechanism too, so something like that could be added in conjunction with such an interface.

Sounds reasonable. I just thought it worth checking. Thanks for the quick response.

Cheers,

Michael

Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw
In reply to Jeff Layton

Hi Jeff,

Something which came up on the last Ganesha conn call is that we have a pretty strong need for some ability to wait on a set of locks, and perhaps receive events. Frank Filz believed that you had made a proposal which would cover this. Can you elaborate on that?

Thanks,

Matt

Quoted 8 lines · ----- "Jeff Layton

If we really find later that we need to do something like this, I think
we'd be better off adding a new set of cmd values along with the "extended" struct, or possibly a new syscall. Some of the samba folks were interested in an async locking mechanism too, so something like that could be added in conjunction with such an interface.

Signature · 14 lines
Matt Benjamin
The Linux Box
206 South Fifth Ave. Suite 150
Ann Arbor, MI  48104

http://linuxbox.com

tel.  734-761-4689 
fax.  734-769-8938 
cel.  734-216-5309 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
Quoted 11 lines · On Tue, 29 Apr 2014 07:40:08 -0400 (EDT) "Matt W. Benjamin"…

Hi Jeff,

Something which came up on the last Ganesha conn call is that we have a pretty strong need for some ability to wait on a set of locks, and perhaps receive events. Frank Filz believed that you had made a proposal which would cover this. Can you elaborate on that?

Thanks,

Matt

No, there's no mechanism to wait on a set of locks from within the context of a single thread of execution or to receive "events". Again, that would be a new API beyond what I've been proposing over the last several months.

Signature · 5 lines
Jeff Layton <[email protected]>
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
Quoted 10 lines
Quoted 7 lines · On Tue, 29 Apr 2014 07:40:08 -0400 (EDT) "Matt W. Benjamin"…

Hi Jeff,

Something which came up on the last Ganesha conn call is that we have a pretty strong need for some ability to wait on a set of locks, and perhaps receive events. Frank Filz believed that you had made a proposal which would cover this. Can you elaborate on that?

Quoted 6 lines
Quoted 4 lines

Thanks,

Matt

No, there's no mechanism to wait on a set of locks from within the context

of

Quoted 1 line

a single thread of execution or to receive "events". Again, that would be

a

Quoted 1 line

new API beyond what I've been proposing over the last several months.

Some kind of facility to enable one user space thread to wait on multiple blocked locks would definitely be helpful to user space servers.

Our current plan is to have a pool of threads, and dispatch blocking locks to them. If that pool is exhausted, all further locks would be dispatched to a single thread that would poll for locks.

Frank

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html