Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NFSv4: add flock_owner to open context

An open file description (struct file) in a given process can be
associated with two different lock owners.

It can have a Posix lock owner which will be different in each process
that has a fd on the file.
It can have a Flock owner which will be the same in all processes.

When searching for a lock stateid to use, we need to consider both of these
owners

So add a new "flock_owner" to the "nfs_open_context" (of which there
is one for each open file description).

This flock_owner does not need to be reference-counted as there is a
1-1 relation between 'struct file' and nfs open contexts,
and it will never be part of a list of contexts. So there is no need
for a 'flock_context' - just the owner is enough.

The io_count included in the (Posix) lock_context provides no
guarantee that all read-aheads that could use the state have
completed, so not supporting it for flock locks in not a serious
problem. Synchronization between flock and read-ahead can be added
later if needed.

When creating an open_context for a non-openning create call, we don't have
a 'struct file' to pass in, so the lock context gets initialized with
a NULL owner, but this will never be used.

The flock_owner is not used at all in this patch, that will come later.

Acked-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: NeilBrown <neilb@suse.com>
Reviewed-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>

authored by

NeilBrown and committed by
Trond Myklebust
532d4def b184b5c3

+12 -8
+3 -3
fs/nfs/dir.c
··· 1467 1467 return res; 1468 1468 } 1469 1469 1470 - static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags) 1470 + static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags, struct file *filp) 1471 1471 { 1472 - return alloc_nfs_open_context(dentry, flags_to_mode(open_flags)); 1472 + return alloc_nfs_open_context(dentry, flags_to_mode(open_flags), filp); 1473 1473 } 1474 1474 1475 1475 static int do_open(struct inode *inode, struct file *filp) ··· 1554 1554 return finish_no_open(file, dentry); 1555 1555 } 1556 1556 1557 - ctx = create_nfs_open_context(dentry, open_flags); 1557 + ctx = create_nfs_open_context(dentry, open_flags, file); 1558 1558 err = PTR_ERR(ctx); 1559 1559 if (IS_ERR(ctx)) 1560 1560 goto out;
+5 -2
fs/nfs/inode.c
··· 796 796 } 797 797 EXPORT_SYMBOL_GPL(nfs_close_context); 798 798 799 - struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode) 799 + struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, 800 + fmode_t f_mode, 801 + struct file *filp) 800 802 { 801 803 struct nfs_open_context *ctx; 802 804 struct rpc_cred *cred = rpc_lookup_cred(); ··· 817 815 ctx->mode = f_mode; 818 816 ctx->flags = 0; 819 817 ctx->error = 0; 818 + ctx->flock_owner = (fl_owner_t)filp; 820 819 nfs_init_lock_context(&ctx->lock_context); 821 820 ctx->lock_context.open_context = ctx; 822 821 INIT_LIST_HEAD(&ctx->list); ··· 942 939 { 943 940 struct nfs_open_context *ctx; 944 941 945 - ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode); 942 + ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp); 946 943 if (IS_ERR(ctx)) 947 944 return PTR_ERR(ctx); 948 945 nfs_file_set_open_context(filp, ctx);
+1 -1
fs/nfs/nfs4file.c
··· 57 57 parent = dget_parent(dentry); 58 58 dir = d_inode(parent); 59 59 60 - ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode); 60 + ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp); 61 61 err = PTR_ERR(ctx); 62 62 if (IS_ERR(ctx)) 63 63 goto out;
+1 -1
fs/nfs/nfs4proc.c
··· 4008 4008 struct nfs4_state *state; 4009 4009 int status = 0; 4010 4010 4011 - ctx = alloc_nfs_open_context(dentry, FMODE_READ); 4011 + ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); 4012 4012 if (IS_ERR(ctx)) 4013 4013 return PTR_ERR(ctx); 4014 4014
+2 -1
include/linux/nfs_fs.h
··· 70 70 struct nfs4_state; 71 71 struct nfs_open_context { 72 72 struct nfs_lock_context lock_context; 73 + fl_owner_t flock_owner; 73 74 struct dentry *dentry; 74 75 struct rpc_cred *cred; 75 76 struct nfs4_state *state; ··· 358 357 extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx); 359 358 extern void put_nfs_open_context(struct nfs_open_context *ctx); 360 359 extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode); 361 - extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode); 360 + extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode, struct file *filp); 362 361 extern void nfs_inode_attach_open_context(struct nfs_open_context *ctx); 363 362 extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx); 364 363 extern void nfs_file_clear_open_context(struct file *flip);