lock_operations
Subsystems (4)
So... switching locks_remove_posix to use the unlock call was Bad, Evil and Wrong. But I still really want the underlying filesystem to know about what's coming since I don't want it to sleep in fl_remove.
Comments on this patch?
- introduces lock_operations
- splits old f_op->lock method into l_op->set_lock and ->get_lock
- moves fl->fl_insert and fl_remove methods to l_op->lock_insert and l_op->lock_remove
- introduces remove_posix() and remove_flock().
I've fixed up NFS to the point where it will compile. I suspect that it's possible to simplify NFS from here, but that would only clutter this patch.
I think the `nfsd over a clusterfs' problem is solvable with this infrastructure. Introduce a new method that takes whatever information (a pointer to a struct host, i guess?) the fs needs to construct a meaningful owner field. But that's a patch for another day ...
fs/lockd/clntproc.c +27 -2
@@ -462,8 +462,6 @@ nlmclnt_lock(struct nlm_rqst *req, struc fl->fl_u.nfs_fl.state = host->h_state; fl->fl_u.nfs_fl.flags |=NFS_LCK_GRANTED ; fl->fl_u.nfs_fl.host = host; - fl->fl_insert = nlmclnt_insert_lock_callback; - fl->fl_remove = nlmclnt_remove_lock_callback; }return nlm_stat_to_errno (resp->status);
@@ -689,3 +687,30 @@ nlm_stat_to_errno(u32 status)printk (KERN_NOTICE "lockd: unexpected server status %d\n" , status);return -ENOLCK ; } + +static int nlmclnt_set_lock (struct file *filp,struct file_lock *fl) +{ +if (fl->fl_flags &FL_SLEEP ) { +nfs_lock (filp,F_SETLKW , fl); + }else { +nfs_lock (filp,F_SETLK , fl); + } +} + +static int nlmclnt_get_lock (struct file *filp,struct file_lock *fl) +{ +nfs_lock (filp,F_GETLK , fl); +} + +static int nlmclnt_remove_posix (struct file *filp,fl_owner_t id) +{ +printk ("remove posix support not yet implemented\n" ); +} + +struct lock_operations nfs_client_lops = { + .set_lock = nlmclnt_set_lock, + .get_lock = nlmclnt_get_lock, + .remove_posix = nlmclnt_remove_posix, + .lock_insert = nlmclnt_insert_lock_callback, + .lock_remove = nlmclnt_remove_lock_callback, +};
fs/locks.c +88 -109
356 lines not on this page · raw message
include/linux/fs.h +37 -3
@@ -540,8 +540,6 @@ struct file_lock {loff_t fl_end;void (*fl_notify)(struct file_lock *);/* unblock callback */ -void (*fl_insert)(struct file_lock *);/* lock insertion callback */ -void (*fl_remove)(struct file_lock *);/* lock removal callback */ struct fasync_struct * fl_fasync;/* for lease break notifications */ unsigned long fl_break_time;/* for nonblocking lease breaks */
@@ -734,6 +732,42 @@ typedef struct {typedef int (*read_actor_t )(read_descriptor_t *,struct page *,unsigned long ,unsigned long ); +/** +* struct lock_operations - filesystem hooks for file locking +* +* This struct is a work in progress. It is intended to be per-filesystem; +* indeed it could be part of f_ops were it not pure bloat for non-network +* filesystems. I suspect lock_insert and lock_remove are now unnecessary, +* but need feedback from FS maintainers. +* +* @set_lock: +* Attempt to set a new lock. BKL not held, may sleep. +* @get_lock: +* Return any lock which would conflict with the incoming lock. +* No locks held, may sleep. +* @remove_posix: +* A process closed a file descriptor. Any locks on this @filp owned +* by @owner should be removed. BKL not held, may sleep. +* @remove_flock: +* This @filp has been closed. All locks owned by this process should +* be removed. BKL not held, may sleep. +* @lock_insert: +* Notification that @fl, which was previously blocked, is now being +* inserted. BKL might not be held. Must not sleep. +* @lock_remove: +* Notification that @fl, which was an active lock, is now being +* removed from the @filp. BKL might not be held. Must not sleep. +*/ + +struct lock_operations { +int (*set_lock) (struct file *filp,struct file_lock *fl); +int (*get_lock) (struct file *filp,struct file_lock *fl); +void (*remove_posix) (struct file *filp,fl_owner_t owner); +void (*remove_flock) (struct file *filp); +void (*lock_insert) (struct file_lock *fl); +void (*lock_remove) (struct file_lock *fl); +}; +/* * NOTE: * read, write, poll, fsync, readv, writev can be called
@@ -757,7 +791,7 @@ struct file_operations {int (*fsync) (struct file *,struct dentry *,int datasync);int (*aio_fsync) (struct kiocb *,int datasync);int (*fasync) (int ,struct file *,int ); -int (*lock) (struct file *,int ,struct file_lock *); +struct lock_operations *lock;ssize_t (*readv) (struct file *,const struct iovec *,unsigned long ,loff_t *);ssize_t (*writev) (struct file *,const struct iovec *,unsigned long ,loff_t *);ssize_t (*sendfile) (struct file *,loff_t *,size_t ,read_actor_t ,void *);
Signature · 1 line
Revolutions do not require corporate support.
Quoted 2 lines
Comments on this patch?
nfs_client_lops does not really belong in fs/lockd/clntproc.c. That introduces a module dependency between lockd and the NFS client code that may be inappropriate if the user just wants to run a pure NFS server.
Cheers,
Trond
Quoted 4 lines · Trond Myklebust
nfs_client_lopsdoes not really belong infs/lockd/clntproc.c. That introduces a module dependency between lockd and the NFS client code that may be inappropriate if the user just wants to run a pure NFS server.
fair point. in terms of the architecture though, you see no problems?
Signature · 1 line
Revolutions do not require corporate support.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
" " == Matthew Wilcox <[email protected]> writes:
> fair point. in terms of the architecture though, you see no > problems?
Not at the moment. I'm a bit curious, though, as to why you chose to split out get_lock() as a separate callback method, but not unlock(). Isn't that just an optimization?
Cheers,
Trond
Quoted 3 lines · Trond Myklebust
Not at the moment. I'm a bit curious, though, as to why you chose to split out
get_lock()as a separate callback method, but notunlock(). Isn't that just an optimization?
i see get_lock as a fundamentally different operation to set_lock. for one thing it returns a lock which set_lock doesn't.
unlock is the same as setting a lock -- we have to deal with the same broken posix behaviours of removing overlapping locks that we own.
yeah, they're different NLM calls, but that doesn't seem to be a big problem.
Signature · 1 line
Revolutions do not require corporate support.