^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/9p/vfs_dentry.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This file contians vfs dentry ops for the 9P2000 protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/9p/9p.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <net/9p/client.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "v9fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "v9fs_vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "fid.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * v9fs_cached_dentry_delete - called when dentry refcount equals 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @dentry: dentry in question
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int v9fs_cached_dentry_delete(const struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) dentry, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Don't cache negative dentries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (d_really_is_negative(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * v9fs_dentry_release - called when dentry is going to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * @dentry: dentry that is being release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static void v9fs_dentry_release(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct hlist_node *p, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) dentry, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) hlist_for_each_safe(p, n, (struct hlist_head *)&dentry->d_fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) p9_client_clunk(hlist_entry(p, struct p9_fid, dlist));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) dentry->d_fsdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int v9fs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct p9_fid *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct v9fs_inode *v9inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (flags & LOOKUP_RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return -ECHILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) goto out_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) v9inode = V9FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (v9inode->cache_validity & V9FS_INO_INVALID_ATTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct v9fs_session_info *v9ses;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) fid = v9fs_fid_lookup(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (IS_ERR(fid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return PTR_ERR(fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) v9ses = v9fs_inode2v9ses(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (v9fs_proto_dotl(v9ses))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) retval = v9fs_refresh_inode_dotl(fid, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) retval = v9fs_refresh_inode(fid, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (retval == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) out_valid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) const struct dentry_operations v9fs_cached_dentry_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .d_revalidate = v9fs_lookup_revalidate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .d_weak_revalidate = v9fs_lookup_revalidate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .d_delete = v9fs_cached_dentry_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .d_release = v9fs_dentry_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) const struct dentry_operations v9fs_dentry_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .d_delete = always_delete_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .d_release = v9fs_dentry_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };