xref: /openbmc/linux/fs/9p/vfs_dentry.c (revision bd238fb431f31989898423c8b6496bc8c4204a86)
1e69e7fe5SEric Van Hensbergen /*
2e69e7fe5SEric Van Hensbergen  *  linux/fs/9p/vfs_dentry.c
3e69e7fe5SEric Van Hensbergen  *
4e69e7fe5SEric Van Hensbergen  * This file contians vfs dentry ops for the 9P2000 protocol.
5e69e7fe5SEric Van Hensbergen  *
6e69e7fe5SEric Van Hensbergen  *  Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7e69e7fe5SEric Van Hensbergen  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8e69e7fe5SEric Van Hensbergen  *
9e69e7fe5SEric Van Hensbergen  *  This program is free software; you can redistribute it and/or modify
1042e8c509SEric Van Hensbergen  *  it under the terms of the GNU General Public License version 2
1142e8c509SEric Van Hensbergen  *  as published by the Free Software Foundation.
12e69e7fe5SEric Van Hensbergen  *
13e69e7fe5SEric Van Hensbergen  *  This program is distributed in the hope that it will be useful,
14e69e7fe5SEric Van Hensbergen  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15e69e7fe5SEric Van Hensbergen  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16e69e7fe5SEric Van Hensbergen  *  GNU General Public License for more details.
17e69e7fe5SEric Van Hensbergen  *
18e69e7fe5SEric Van Hensbergen  *  You should have received a copy of the GNU General Public License
19e69e7fe5SEric Van Hensbergen  *  along with this program; if not, write to:
20e69e7fe5SEric Van Hensbergen  *  Free Software Foundation
21e69e7fe5SEric Van Hensbergen  *  51 Franklin Street, Fifth Floor
22e69e7fe5SEric Van Hensbergen  *  Boston, MA  02111-1301  USA
23e69e7fe5SEric Van Hensbergen  *
24e69e7fe5SEric Van Hensbergen  */
25e69e7fe5SEric Van Hensbergen 
26e69e7fe5SEric Van Hensbergen #include <linux/module.h>
27e69e7fe5SEric Van Hensbergen #include <linux/errno.h>
28e69e7fe5SEric Van Hensbergen #include <linux/fs.h>
29e69e7fe5SEric Van Hensbergen #include <linux/file.h>
30e69e7fe5SEric Van Hensbergen #include <linux/pagemap.h>
31e69e7fe5SEric Van Hensbergen #include <linux/stat.h>
32e69e7fe5SEric Van Hensbergen #include <linux/string.h>
33e69e7fe5SEric Van Hensbergen #include <linux/inet.h>
34e69e7fe5SEric Van Hensbergen #include <linux/namei.h>
35e69e7fe5SEric Van Hensbergen #include <linux/idr.h>
36e8edc6e0SAlexey Dobriyan #include <linux/sched.h>
37*bd238fb4SLatchesar Ionkov #include <net/9p/9p.h>
38*bd238fb4SLatchesar Ionkov #include <net/9p/client.h>
39e69e7fe5SEric Van Hensbergen 
40e69e7fe5SEric Van Hensbergen #include "v9fs.h"
41e69e7fe5SEric Van Hensbergen #include "v9fs_vfs.h"
42e69e7fe5SEric Van Hensbergen #include "fid.h"
43e69e7fe5SEric Van Hensbergen 
44e69e7fe5SEric Van Hensbergen /**
4546f6dac2SEric Van Hensbergen  * v9fs_dentry_delete - called when dentry refcount equals 0
4646f6dac2SEric Van Hensbergen  * @dentry:  dentry in question
47e69e7fe5SEric Van Hensbergen  *
4846f6dac2SEric Van Hensbergen  * By returning 1 here we should remove cacheing of unused
4946f6dac2SEric Van Hensbergen  * dentry components.
50e69e7fe5SEric Van Hensbergen  *
51e69e7fe5SEric Van Hensbergen  */
52e69e7fe5SEric Van Hensbergen 
535174fdabSLatchesar Ionkov static int v9fs_dentry_delete(struct dentry *dentry)
54e69e7fe5SEric Van Hensbergen {
55*bd238fb4SLatchesar Ionkov 	P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
56e03abc0cSEric Van Hensbergen 
57e69e7fe5SEric Van Hensbergen 	return 1;
58e69e7fe5SEric Van Hensbergen }
59e69e7fe5SEric Van Hensbergen 
60e69e7fe5SEric Van Hensbergen /**
61e03abc0cSEric Van Hensbergen  * v9fs_cached_dentry_delete - called when dentry refcount equals 0
62e03abc0cSEric Van Hensbergen  * @dentry:  dentry in question
63e03abc0cSEric Van Hensbergen  *
64e03abc0cSEric Van Hensbergen  * Only return 1 if our inode is invalid.  Only non-synthetic files
65e03abc0cSEric Van Hensbergen  * (ones without mtime == 0) should be calling this function.
66e03abc0cSEric Van Hensbergen  *
67e03abc0cSEric Van Hensbergen  */
68e03abc0cSEric Van Hensbergen 
69e03abc0cSEric Van Hensbergen static int v9fs_cached_dentry_delete(struct dentry *dentry)
70e03abc0cSEric Van Hensbergen {
71e03abc0cSEric Van Hensbergen 	struct inode *inode = dentry->d_inode;
72*bd238fb4SLatchesar Ionkov 	P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
73e03abc0cSEric Van Hensbergen 
74e03abc0cSEric Van Hensbergen 	if(!inode)
75e03abc0cSEric Van Hensbergen 		return 1;
76e03abc0cSEric Van Hensbergen 
77e03abc0cSEric Van Hensbergen 	return 0;
78e03abc0cSEric Van Hensbergen }
79e03abc0cSEric Van Hensbergen 
80e03abc0cSEric Van Hensbergen /**
81e69e7fe5SEric Van Hensbergen  * v9fs_dentry_release - called when dentry is going to be freed
82e69e7fe5SEric Van Hensbergen  * @dentry:  dentry that is being release
83e69e7fe5SEric Van Hensbergen  *
84e69e7fe5SEric Van Hensbergen  */
85e69e7fe5SEric Van Hensbergen 
86e69e7fe5SEric Van Hensbergen void v9fs_dentry_release(struct dentry *dentry)
87e69e7fe5SEric Van Hensbergen {
88*bd238fb4SLatchesar Ionkov 	struct v9fs_dentry *dent;
89*bd238fb4SLatchesar Ionkov 	struct p9_fid *temp, *current_fid;
903cf6429aSLatchesar Ionkov 
91*bd238fb4SLatchesar Ionkov 	P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
92*bd238fb4SLatchesar Ionkov 	dent = dentry->d_fsdata;
93*bd238fb4SLatchesar Ionkov 	if (dent) {
94*bd238fb4SLatchesar Ionkov 		list_for_each_entry_safe(current_fid, temp, &dent->fidlist,
95*bd238fb4SLatchesar Ionkov 									dlist) {
96*bd238fb4SLatchesar Ionkov 			p9_client_clunk(current_fid);
97e69e7fe5SEric Van Hensbergen 		}
98e69e7fe5SEric Van Hensbergen 
99*bd238fb4SLatchesar Ionkov 		kfree(dent);
100*bd238fb4SLatchesar Ionkov 		dentry->d_fsdata = NULL;
101e69e7fe5SEric Van Hensbergen 	}
102e69e7fe5SEric Van Hensbergen }
103e69e7fe5SEric Van Hensbergen 
104e03abc0cSEric Van Hensbergen struct dentry_operations v9fs_cached_dentry_operations = {
105e03abc0cSEric Van Hensbergen 	.d_delete = v9fs_cached_dentry_delete,
106e03abc0cSEric Van Hensbergen 	.d_release = v9fs_dentry_release,
107e03abc0cSEric Van Hensbergen };
108e03abc0cSEric Van Hensbergen 
109e69e7fe5SEric Van Hensbergen struct dentry_operations v9fs_dentry_operations = {
11046f6dac2SEric Van Hensbergen 	.d_delete = v9fs_dentry_delete,
111e69e7fe5SEric Van Hensbergen 	.d_release = v9fs_dentry_release,
112e69e7fe5SEric Van Hensbergen };
113