xref: /openbmc/linux/fs/9p/vfs_dentry.c (revision ba2929159000dc7015cc01cdf7bb72542e19952a)
11f327613SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2e69e7fe5SEric Van Hensbergen /*
3e69e7fe5SEric Van Hensbergen  * This file contians vfs dentry ops for the 9P2000 protocol.
4e69e7fe5SEric Van Hensbergen  *
5e69e7fe5SEric Van Hensbergen  *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
6e69e7fe5SEric Van Hensbergen  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
7e69e7fe5SEric Van Hensbergen  */
8e69e7fe5SEric Van Hensbergen 
9e69e7fe5SEric Van Hensbergen #include <linux/module.h>
10e69e7fe5SEric Van Hensbergen #include <linux/errno.h>
11e69e7fe5SEric Van Hensbergen #include <linux/fs.h>
12e69e7fe5SEric Van Hensbergen #include <linux/file.h>
13e69e7fe5SEric Van Hensbergen #include <linux/pagemap.h>
14e69e7fe5SEric Van Hensbergen #include <linux/stat.h>
15e69e7fe5SEric Van Hensbergen #include <linux/string.h>
16e69e7fe5SEric Van Hensbergen #include <linux/namei.h>
17e8edc6e0SAlexey Dobriyan #include <linux/sched.h>
185a0e3ad6STejun Heo #include <linux/slab.h>
19bd238fb4SLatchesar Ionkov #include <net/9p/9p.h>
20bd238fb4SLatchesar Ionkov #include <net/9p/client.h>
21e69e7fe5SEric Van Hensbergen 
22e69e7fe5SEric Van Hensbergen #include "v9fs.h"
23e69e7fe5SEric Van Hensbergen #include "v9fs_vfs.h"
24e69e7fe5SEric Van Hensbergen #include "fid.h"
25e69e7fe5SEric Van Hensbergen 
26e69e7fe5SEric Van Hensbergen /**
27e03abc0cSEric Van Hensbergen  * v9fs_cached_dentry_delete - called when dentry refcount equals 0
28e03abc0cSEric Van Hensbergen  * @dentry:  dentry in question
29e03abc0cSEric Van Hensbergen  *
30e03abc0cSEric Van Hensbergen  */
v9fs_cached_dentry_delete(const struct dentry * dentry)31fe15ce44SNick Piggin static int v9fs_cached_dentry_delete(const struct dentry *dentry)
32e03abc0cSEric Van Hensbergen {
334b8e9923SAl Viro 	p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
344b8e9923SAl Viro 		 dentry, dentry);
35e03abc0cSEric Van Hensbergen 
36a950a652SAneesh Kumar K.V 	/* Don't cache negative dentries */
372b0143b5SDavid Howells 	if (d_really_is_negative(dentry))
38e03abc0cSEric Van Hensbergen 		return 1;
39e03abc0cSEric Van Hensbergen 	return 0;
40e03abc0cSEric Van Hensbergen }
41e03abc0cSEric Van Hensbergen 
42e03abc0cSEric Van Hensbergen /**
43e69e7fe5SEric Van Hensbergen  * v9fs_dentry_release - called when dentry is going to be freed
44e69e7fe5SEric Van Hensbergen  * @dentry:  dentry that is being release
45e69e7fe5SEric Van Hensbergen  *
46e69e7fe5SEric Van Hensbergen  */
47e69e7fe5SEric Van Hensbergen 
v9fs_dentry_release(struct dentry * dentry)4898cd3fb0SAl Viro static void v9fs_dentry_release(struct dentry *dentry)
49e69e7fe5SEric Van Hensbergen {
50aaeb7ecfSAl Viro 	struct hlist_node *p, *n;
51*f0c5c944SDominique Martinet 	struct hlist_head head;
526e195b0fSDominique Martinet 
534b8e9923SAl Viro 	p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
544b8e9923SAl Viro 		 dentry, dentry);
55*f0c5c944SDominique Martinet 
56*f0c5c944SDominique Martinet 	spin_lock(&dentry->d_lock);
57*f0c5c944SDominique Martinet 	hlist_move_list((struct hlist_head *)&dentry->d_fsdata, &head);
58*f0c5c944SDominique Martinet 	spin_unlock(&dentry->d_lock);
59*f0c5c944SDominique Martinet 
60*f0c5c944SDominique Martinet 	hlist_for_each_safe(p, n, &head)
61b48dbb99SDominique Martinet 		p9_fid_put(hlist_entry(p, struct p9_fid, dlist));
62e69e7fe5SEric Van Hensbergen }
63e69e7fe5SEric Van Hensbergen 
v9fs_lookup_revalidate(struct dentry * dentry,unsigned int flags)640b728e19SAl Viro static int v9fs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
65b3cbea03SAneesh Kumar K.V {
66b3cbea03SAneesh Kumar K.V 	struct p9_fid *fid;
67b3cbea03SAneesh Kumar K.V 	struct inode *inode;
68b3cbea03SAneesh Kumar K.V 	struct v9fs_inode *v9inode;
69b3cbea03SAneesh Kumar K.V 
700b728e19SAl Viro 	if (flags & LOOKUP_RCU)
71b3cbea03SAneesh Kumar K.V 		return -ECHILD;
72b3cbea03SAneesh Kumar K.V 
732b0143b5SDavid Howells 	inode = d_inode(dentry);
74b3cbea03SAneesh Kumar K.V 	if (!inode)
75b3cbea03SAneesh Kumar K.V 		goto out_valid;
76b3cbea03SAneesh Kumar K.V 
77b3cbea03SAneesh Kumar K.V 	v9inode = V9FS_I(inode);
78b3cbea03SAneesh Kumar K.V 	if (v9inode->cache_validity & V9FS_INO_INVALID_ATTR) {
79b3cbea03SAneesh Kumar K.V 		int retval;
80b3cbea03SAneesh Kumar K.V 		struct v9fs_session_info *v9ses;
816e195b0fSDominique Martinet 
82b3cbea03SAneesh Kumar K.V 		fid = v9fs_fid_lookup(dentry);
83b3cbea03SAneesh Kumar K.V 		if (IS_ERR(fid))
84b3cbea03SAneesh Kumar K.V 			return PTR_ERR(fid);
85b3cbea03SAneesh Kumar K.V 
86b3cbea03SAneesh Kumar K.V 		v9ses = v9fs_inode2v9ses(inode);
87b3cbea03SAneesh Kumar K.V 		if (v9fs_proto_dotl(v9ses))
88b3cbea03SAneesh Kumar K.V 			retval = v9fs_refresh_inode_dotl(fid, inode);
89b3cbea03SAneesh Kumar K.V 		else
90b3cbea03SAneesh Kumar K.V 			retval = v9fs_refresh_inode(fid, inode);
91b48dbb99SDominique Martinet 		p9_fid_put(fid);
926636b6dcSJianyong Wu 
93f2eda2c6SAneesh Kumar K.V 		if (retval == -ENOENT)
94f2eda2c6SAneesh Kumar K.V 			return 0;
95f2eda2c6SAneesh Kumar K.V 		if (retval < 0)
96b3cbea03SAneesh Kumar K.V 			return retval;
97b3cbea03SAneesh Kumar K.V 	}
98b3cbea03SAneesh Kumar K.V out_valid:
99b3cbea03SAneesh Kumar K.V 	return 1;
100b3cbea03SAneesh Kumar K.V }
101b3cbea03SAneesh Kumar K.V 
102a488257cSAl Viro const struct dentry_operations v9fs_cached_dentry_operations = {
103b3cbea03SAneesh Kumar K.V 	.d_revalidate = v9fs_lookup_revalidate,
104ecf3d1f1SJeff Layton 	.d_weak_revalidate = v9fs_lookup_revalidate,
105e03abc0cSEric Van Hensbergen 	.d_delete = v9fs_cached_dentry_delete,
106e03abc0cSEric Van Hensbergen 	.d_release = v9fs_dentry_release,
107e03abc0cSEric Van Hensbergen };
108e03abc0cSEric Van Hensbergen 
109a488257cSAl Viro const struct dentry_operations v9fs_dentry_operations = {
110b26d4cd3SAl Viro 	.d_delete = always_delete_dentry,
111e69e7fe5SEric Van Hensbergen 	.d_release = v9fs_dentry_release,
112e69e7fe5SEric Van Hensbergen };
113