blob: 7d6f69aefd45dcffcf544e2aa611637e69757530 [file] [log] [blame]
Thomas Gleixner1f327612019-05-28 09:57:16 -07001// SPDX-License-Identifier: GPL-2.0-only
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -07002/*
3 * linux/fs/9p/vfs_dentry.c
4 *
5 * This file contians vfs dentry ops for the 9P2000 protocol.
6 *
7 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -07009 */
10
11#include <linux/module.h>
12#include <linux/errno.h>
13#include <linux/fs.h>
14#include <linux/file.h>
15#include <linux/pagemap.h>
16#include <linux/stat.h>
17#include <linux/string.h>
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070018#include <linux/inet.h>
19#include <linux/namei.h>
20#include <linux/idr.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040021#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050023#include <net/9p/9p.h>
24#include <net/9p/client.h>
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070025
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070026#include "v9fs.h"
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070027#include "v9fs_vfs.h"
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070028#include "fid.h"
29
30/**
Eric Van Hensbergene03abc02007-02-11 13:21:39 -060031 * v9fs_cached_dentry_delete - called when dentry refcount equals 0
32 * @dentry: dentry in question
33 *
Eric Van Hensbergene03abc02007-02-11 13:21:39 -060034 */
Nick Pigginfe15ce42011-01-07 17:49:23 +110035static int v9fs_cached_dentry_delete(const struct dentry *dentry)
Eric Van Hensbergene03abc02007-02-11 13:21:39 -060036{
Al Viro4b8e9922014-08-19 20:17:38 -040037 p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
38 dentry, dentry);
Eric Van Hensbergene03abc02007-02-11 13:21:39 -060039
Aneesh Kumar K.Va950a652011-02-28 17:03:58 +053040 /* Don't cache negative dentries */
David Howells2b0143b2015-03-17 22:25:59 +000041 if (d_really_is_negative(dentry))
Eric Van Hensbergene03abc02007-02-11 13:21:39 -060042 return 1;
Eric Van Hensbergene03abc02007-02-11 13:21:39 -060043 return 0;
44}
45
46/**
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070047 * v9fs_dentry_release - called when dentry is going to be freed
48 * @dentry: dentry that is being release
49 *
50 */
51
Al Viro98cd3fb2011-01-12 17:10:55 -050052static void v9fs_dentry_release(struct dentry *dentry)
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070053{
Al Viroaaeb7ec2013-02-28 01:13:19 -050054 struct hlist_node *p, *n;
Al Viro4b8e9922014-08-19 20:17:38 -040055 p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
56 dentry, dentry);
Al Viroaaeb7ec2013-02-28 01:13:19 -050057 hlist_for_each_safe(p, n, (struct hlist_head *)&dentry->d_fsdata)
58 p9_client_clunk(hlist_entry(p, struct p9_fid, dlist));
59 dentry->d_fsdata = NULL;
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -070060}
61
Al Viro0b728e12012-06-10 16:03:43 -040062static int v9fs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
Aneesh Kumar K.Vb3cbea02011-02-28 17:04:06 +053063{
64 struct p9_fid *fid;
65 struct inode *inode;
66 struct v9fs_inode *v9inode;
67
Al Viro0b728e12012-06-10 16:03:43 -040068 if (flags & LOOKUP_RCU)
Aneesh Kumar K.Vb3cbea02011-02-28 17:04:06 +053069 return -ECHILD;
70
David Howells2b0143b2015-03-17 22:25:59 +000071 inode = d_inode(dentry);
Aneesh Kumar K.Vb3cbea02011-02-28 17:04:06 +053072 if (!inode)
73 goto out_valid;
74
75 v9inode = V9FS_I(inode);
76 if (v9inode->cache_validity & V9FS_INO_INVALID_ATTR) {
77 int retval;
78 struct v9fs_session_info *v9ses;
79 fid = v9fs_fid_lookup(dentry);
80 if (IS_ERR(fid))
81 return PTR_ERR(fid);
82
83 v9ses = v9fs_inode2v9ses(inode);
84 if (v9fs_proto_dotl(v9ses))
85 retval = v9fs_refresh_inode_dotl(fid, inode);
86 else
87 retval = v9fs_refresh_inode(fid, inode);
Aneesh Kumar K.Vf2eda2c2011-03-23 19:48:16 +053088 if (retval == -ENOENT)
89 return 0;
90 if (retval < 0)
Aneesh Kumar K.Vb3cbea02011-02-28 17:04:06 +053091 return retval;
92 }
93out_valid:
94 return 1;
95}
96
Al Viroa488257c2009-02-20 05:55:46 +000097const struct dentry_operations v9fs_cached_dentry_operations = {
Aneesh Kumar K.Vb3cbea02011-02-28 17:04:06 +053098 .d_revalidate = v9fs_lookup_revalidate,
Jeff Laytonecf3d1f2013-02-20 11:19:05 -050099 .d_weak_revalidate = v9fs_lookup_revalidate,
Eric Van Hensbergene03abc02007-02-11 13:21:39 -0600100 .d_delete = v9fs_cached_dentry_delete,
101 .d_release = v9fs_dentry_release,
102};
103
Al Viroa488257c2009-02-20 05:55:46 +0000104const struct dentry_operations v9fs_dentry_operations = {
Al Virob26d4cd2013-10-25 18:47:37 -0400105 .d_delete = always_delete_dentry,
Eric Van Hensbergene69e7fe2005-09-09 13:04:18 -0700106 .d_release = v9fs_dentry_release,
107};