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