^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * (C) 2001 Clemson University and The University of Chicago
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * See COPYING in top-level directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Implementation of dentry (directory cache) functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "protocol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "orangefs-kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /* Returns 1 if dentry can still be trusted, else 0. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static int orangefs_revalidate_lookup(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct dentry *parent_dentry = dget_parent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct inode *parent_inode = parent_dentry->d_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct orangefs_inode_s *parent = ORANGEFS_I(parent_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct inode *inode = dentry->d_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct orangefs_kernel_op_s *new_op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) gossip_debug(GOSSIP_DCACHE_DEBUG, "%s: attempting lookup.\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (!new_op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) goto out_put_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) new_op->upcall.req.lookup.parent_refn = parent->refn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) strncpy(new_op->upcall.req.lookup.d_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ORANGEFS_NAME_MAX - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) gossip_debug(GOSSIP_DCACHE_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) "%s:%s:%d interrupt flag [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) __FILE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __LINE__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) get_interruptible_flag(parent_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) err = service_operation(new_op, "orangefs_lookup",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) get_interruptible_flag(parent_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* Positive dentry: reject if error or not the same inode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) gossip_debug(GOSSIP_DCACHE_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) "%s:%s:%d lookup failure.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) __FILE__, __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) goto out_drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (!match_handle(new_op->downcall.resp.lookup.refn.khandle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) gossip_debug(GOSSIP_DCACHE_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) "%s:%s:%d no match.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) __FILE__, __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) goto out_drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* Negative dentry: reject if success or error other than ENOENT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) gossip_debug(GOSSIP_DCACHE_DEBUG, "%s: negative dentry.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!err || err != -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (new_op->downcall.status != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) gossip_debug(GOSSIP_DCACHE_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) "%s:%s:%d lookup failure.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) __FILE__, __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) goto out_drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) orangefs_set_timeout(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) out_release_op:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) op_release(new_op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) out_put_parent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) dput(parent_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) out_drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) gossip_debug(GOSSIP_DCACHE_DEBUG, "%s:%s:%d revalidate failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) __FILE__, __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) goto out_release_op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * Verify that dentry is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * Should return 1 if dentry can still be trusted, else 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static int orangefs_d_revalidate(struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned long time = (unsigned long) dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (time_before(jiffies, time))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (flags & LOOKUP_RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return -ECHILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) gossip_debug(GOSSIP_DCACHE_DEBUG, "%s: called on dentry %p.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) __func__, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* skip root handle lookups. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (dentry->d_inode && is_root_handle(dentry->d_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * If this passes, the positive dentry still exists or the negative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * dentry still does not exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (!orangefs_revalidate_lookup(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* We do not need to continue with negative dentries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!dentry->d_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) gossip_debug(GOSSIP_DCACHE_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) "%s: negative dentry or positive dentry and inode valid.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* Now we must perform a getattr to validate the inode contents. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ret = orangefs_inode_check_changed(dentry->d_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) gossip_debug(GOSSIP_DCACHE_DEBUG, "%s:%s:%d getattr failure.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) __FILE__, __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return !ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) const struct dentry_operations orangefs_dentry_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .d_revalidate = orangefs_d_revalidate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };