Lines Matching refs:ctx
891 static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx)
895 list_for_each_entry_rcu(pos, &ctx->lock_context.list, list) {
904 struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx)
907 struct inode *inode = d_inode(ctx->dentry);
910 res = __nfs_find_lock_context(ctx);
918 res = __nfs_find_lock_context(ctx);
920 new->open_context = get_nfs_open_context(ctx);
923 &ctx->lock_context.list);
938 struct nfs_open_context *ctx = l_ctx->open_context;
939 struct inode *inode = d_inode(ctx->dentry);
945 put_nfs_open_context(ctx);
952 * @ctx: pointer to context
959 void nfs_close_context(struct nfs_open_context *ctx, int is_sync)
965 if (!(ctx->mode & FMODE_WRITE))
969 inode = d_inode(ctx->dentry);
990 struct nfs_open_context *ctx;
992 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
993 if (!ctx)
996 ctx->dentry = dget(dentry);
998 ctx->cred = get_cred(filp->f_cred);
1000 ctx->cred = get_current_cred();
1001 ctx->ll_cred = NULL;
1002 ctx->state = NULL;
1003 ctx->mode = f_mode;
1004 ctx->flags = 0;
1005 ctx->error = 0;
1006 ctx->flock_owner = (fl_owner_t)filp;
1007 nfs_init_lock_context(&ctx->lock_context);
1008 ctx->lock_context.open_context = ctx;
1009 INIT_LIST_HEAD(&ctx->list);
1010 ctx->mdsthreshold = NULL;
1011 return ctx;
1015 struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
1017 if (ctx != NULL && refcount_inc_not_zero(&ctx->lock_context.count))
1018 return ctx;
1023 static void __put_nfs_open_context(struct nfs_open_context *ctx, int is_sync)
1025 struct inode *inode = d_inode(ctx->dentry);
1026 struct super_block *sb = ctx->dentry->d_sb;
1028 if (!refcount_dec_and_test(&ctx->lock_context.count))
1030 if (!list_empty(&ctx->list)) {
1032 list_del_rcu(&ctx->list);
1036 NFS_PROTO(inode)->close_context(ctx, is_sync);
1037 put_cred(ctx->cred);
1038 dput(ctx->dentry);
1040 put_rpccred(ctx->ll_cred);
1041 kfree(ctx->mdsthreshold);
1042 kfree_rcu(ctx, rcu_head);
1045 void put_nfs_open_context(struct nfs_open_context *ctx)
1047 __put_nfs_open_context(ctx, 0);
1051 static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
1053 __put_nfs_open_context(ctx, 1);
1060 void nfs_inode_attach_open_context(struct nfs_open_context *ctx)
1062 struct inode *inode = d_inode(ctx->dentry);
1070 list_add_tail_rcu(&ctx->list, &nfsi->open_files);
1075 void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
1077 filp->private_data = get_nfs_open_context(ctx);
1078 set_bit(NFS_CONTEXT_FILE_OPEN, &ctx->flags);
1079 if (list_empty(&ctx->list))
1080 nfs_inode_attach_open_context(ctx);
1090 struct nfs_open_context *pos, *ctx = NULL;
1100 ctx = get_nfs_open_context(pos);
1101 if (ctx)
1105 return ctx;
1110 struct nfs_open_context *ctx = nfs_file_open_context(filp);
1112 if (ctx) {
1113 struct inode *inode = d_inode(ctx->dentry);
1115 clear_bit(NFS_CONTEXT_FILE_OPEN, &ctx->flags);
1120 if (ctx->error < 0)
1123 put_nfs_open_context_sync(ctx);
1132 struct nfs_open_context *ctx;
1134 ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp);
1135 if (IS_ERR(ctx))
1136 return PTR_ERR(ctx);
1137 nfs_file_set_open_context(filp, ctx);
1138 put_nfs_open_context(ctx);