Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1 | /* |
| 2 | * GPL HEADER START |
| 3 | * |
| 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 only, |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License version 2 for more details (a copy is included |
| 14 | * in the LICENSE file that accompanied this code). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * version 2 along with this program; If not, see |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 20 | * GPL HEADER END |
| 21 | */ |
| 22 | /* |
| 23 | * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
| 24 | * Use is subject to license terms. |
| 25 | * |
Andreas Dilger | 1dc563a | 2015-11-08 18:09:37 -0500 | [diff] [blame] | 26 | * Copyright (c) 2011, 2015, Intel Corporation. |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 27 | */ |
| 28 | /* |
| 29 | * This file is part of Lustre, http://www.lustre.org/ |
| 30 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 31 | */ |
| 32 | |
| 33 | #include <linux/fs.h> |
| 34 | #include <linux/sched.h> |
| 35 | #include <linux/quotaops.h> |
| 36 | |
| 37 | #define DEBUG_SUBSYSTEM S_LLITE |
| 38 | |
Greg Kroah-Hartman | 67a235f | 2014-07-11 21:51:41 -0700 | [diff] [blame] | 39 | #include "../include/obd_support.h" |
Greg Kroah-Hartman | 67a235f | 2014-07-11 21:51:41 -0700 | [diff] [blame] | 40 | #include "../include/lustre/lustre_idl.h" |
| 41 | #include "../include/lustre_dlm.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 42 | |
| 43 | #include "llite_internal.h" |
| 44 | |
| 45 | static void free_dentry_data(struct rcu_head *head) |
| 46 | { |
| 47 | struct ll_dentry_data *lld; |
| 48 | |
| 49 | lld = container_of(head, struct ll_dentry_data, lld_rcu_head); |
Julia Lawall | 97903a2 | 2015-04-12 22:55:02 +0200 | [diff] [blame] | 50 | kfree(lld); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /* should NOT be called with the dcache lock, see fs/dcache.c */ |
| 54 | static void ll_release(struct dentry *de) |
| 55 | { |
| 56 | struct ll_dentry_data *lld; |
Greg Kroah-Hartman | 29aaf49 | 2013-08-02 18:14:51 +0800 | [diff] [blame] | 57 | |
Oleg Drokin | 6e16818 | 2016-02-16 00:46:46 -0500 | [diff] [blame] | 58 | LASSERT(de); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 59 | lld = ll_d2d(de); |
Bhumika Goyal | 61382aa | 2016-01-23 18:41:53 +0530 | [diff] [blame] | 60 | if (!lld) /* NFS copies the de->d_op methods (bug 4655) */ |
Greg Kroah-Hartman | e05e02e | 2013-08-02 18:20:34 +0800 | [diff] [blame] | 61 | return; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 62 | |
| 63 | if (lld->lld_it) { |
| 64 | ll_intent_release(lld->lld_it); |
Julia Lawall | 97903a2 | 2015-04-12 22:55:02 +0200 | [diff] [blame] | 65 | kfree(lld->lld_it); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 66 | } |
John L. Hammond | 2d95f10 | 2014-04-27 13:07:05 -0400 | [diff] [blame] | 67 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 68 | de->d_fsdata = NULL; |
| 69 | call_rcu(&lld->lld_rcu_head, free_dentry_data); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* Compare if two dentries are the same. Don't match if the existing dentry |
| 73 | * is marked invalid. Returns 1 if different, 0 if the same. |
| 74 | * |
| 75 | * This avoids a race where ll_lookup_it() instantiates a dentry, but we get |
| 76 | * an AST before calling d_revalidate_it(). The dentry still exists (marked |
| 77 | * INVALID) so d_lookup() matches it, but we have no lock on it (so |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 78 | * lock_match() fails) and we spin around real_lookup(). |
| 79 | */ |
Al Viro | 6fa67e7 | 2016-07-31 16:37:25 -0400 | [diff] [blame] | 80 | static int ll_dcompare(const struct dentry *dentry, |
John L. Hammond | 2d95f10 | 2014-04-27 13:07:05 -0400 | [diff] [blame] | 81 | unsigned int len, const char *str, |
| 82 | const struct qstr *name) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 83 | { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 84 | if (len != name->len) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 85 | return 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 86 | |
| 87 | if (memcmp(str, name->name, len)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 88 | return 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 89 | |
| 90 | CDEBUG(D_DENTRY, "found name %.*s(%p) flags %#x refc %d\n", |
| 91 | name->len, name->name, dentry, dentry->d_flags, |
Al Viro | 193deee | 2013-07-05 19:06:16 +0400 | [diff] [blame] | 92 | d_count(dentry)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 93 | |
| 94 | /* mountpoint is always valid */ |
| 95 | if (d_mountpoint((struct dentry *)dentry)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 96 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 97 | |
| 98 | if (d_lustre_invalid(dentry)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 99 | return 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 100 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 101 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 102 | } |
| 103 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 104 | /** |
| 105 | * Called when last reference to a dentry is dropped and dcache wants to know |
| 106 | * whether or not it should cache it: |
| 107 | * - return 1 to delete the dentry immediately |
| 108 | * - return 0 to cache the dentry |
| 109 | * Should NOT be called with the dcache lock, see fs/dcache.c |
| 110 | */ |
| 111 | static int ll_ddelete(const struct dentry *de) |
| 112 | { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 113 | LASSERT(de); |
| 114 | |
Al Viro | 09561a5 | 2014-05-07 21:10:24 -0400 | [diff] [blame] | 115 | CDEBUG(D_DENTRY, "%s dentry %pd (%p, parent %p, inode %p) %s%s\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 116 | d_lustre_invalid((struct dentry *)de) ? "deleting" : "keeping", |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 117 | de, de, de->d_parent, d_inode(de), |
Al Viro | 09561a5 | 2014-05-07 21:10:24 -0400 | [diff] [blame] | 118 | d_unhashed(de) ? "" : "hashed,", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 119 | list_empty(&de->d_subdirs) ? "" : "subdirs"); |
| 120 | |
| 121 | /* kernel >= 2.6.38 last refcount is decreased after this function. */ |
Al Viro | 193deee | 2013-07-05 19:06:16 +0400 | [diff] [blame] | 122 | LASSERT(d_count(de) == 1); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 123 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 124 | if (d_lustre_invalid((struct dentry *)de)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 125 | return 1; |
| 126 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 127 | } |
| 128 | |
Lai Siyao | 3ea8f3b | 2014-01-22 21:36:12 +0800 | [diff] [blame] | 129 | int ll_d_init(struct dentry *de) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 130 | { |
Al Viro | 09561a5 | 2014-05-07 21:10:24 -0400 | [diff] [blame] | 131 | CDEBUG(D_DENTRY, "ldd on dentry %pd (%p) parent %p inode %p refc %d\n", |
Oleg Drokin | e15ba45 | 2016-02-26 01:49:49 -0500 | [diff] [blame] | 132 | de, de, de->d_parent, d_inode(de), d_count(de)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 133 | |
Bhumika Goyal | 61382aa | 2016-01-23 18:41:53 +0530 | [diff] [blame] | 134 | if (!de->d_fsdata) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 135 | struct ll_dentry_data *lld; |
| 136 | |
Julia Lawall | 496a51b | 2014-09-18 22:24:02 +0200 | [diff] [blame] | 137 | lld = kzalloc(sizeof(*lld), GFP_NOFS); |
| 138 | if (likely(lld)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 139 | spin_lock(&de->d_lock); |
Bhumika Goyal | 61382aa | 2016-01-23 18:41:53 +0530 | [diff] [blame] | 140 | if (likely(!de->d_fsdata)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 141 | de->d_fsdata = lld; |
Lai Siyao | 3ea8f3b | 2014-01-22 21:36:12 +0800 | [diff] [blame] | 142 | __d_lustre_invalidate(de); |
| 143 | } else { |
Julia Lawall | 97903a2 | 2015-04-12 22:55:02 +0200 | [diff] [blame] | 144 | kfree(lld); |
Lai Siyao | 3ea8f3b | 2014-01-22 21:36:12 +0800 | [diff] [blame] | 145 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 146 | spin_unlock(&de->d_lock); |
| 147 | } else { |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 148 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 149 | } |
| 150 | } |
Lai Siyao | 3ea8f3b | 2014-01-22 21:36:12 +0800 | [diff] [blame] | 151 | LASSERT(de->d_op == &ll_d_ops); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 152 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 153 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 154 | } |
| 155 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 156 | void ll_intent_drop_lock(struct lookup_intent *it) |
| 157 | { |
John L. Hammond | e476f2e | 2016-06-20 16:55:38 -0400 | [diff] [blame] | 158 | if (it->it_op && it->it_lock_mode) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 159 | struct lustre_handle handle; |
| 160 | |
John L. Hammond | e476f2e | 2016-06-20 16:55:38 -0400 | [diff] [blame] | 161 | handle.cookie = it->it_lock_handle; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 162 | |
Greg Kroah-Hartman | 55f5a82 | 2014-07-12 20:26:07 -0700 | [diff] [blame] | 163 | CDEBUG(D_DLMTRACE, "releasing lock with cookie %#llx from it %p\n", |
| 164 | handle.cookie, it); |
John L. Hammond | e476f2e | 2016-06-20 16:55:38 -0400 | [diff] [blame] | 165 | ldlm_lock_decref(&handle, it->it_lock_mode); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 166 | |
| 167 | /* bug 494: intent_release may be called multiple times, from |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 168 | * this thread and we don't want to double-decref this lock |
| 169 | */ |
John L. Hammond | e476f2e | 2016-06-20 16:55:38 -0400 | [diff] [blame] | 170 | it->it_lock_mode = 0; |
| 171 | if (it->it_remote_lock_mode != 0) { |
| 172 | handle.cookie = it->it_remote_lock_handle; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 173 | |
Greg Kroah-Hartman | 55f5a82 | 2014-07-12 20:26:07 -0700 | [diff] [blame] | 174 | CDEBUG(D_DLMTRACE, "releasing remote lock with cookie%#llx from it %p\n", |
| 175 | handle.cookie, it); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 176 | ldlm_lock_decref(&handle, |
John L. Hammond | e476f2e | 2016-06-20 16:55:38 -0400 | [diff] [blame] | 177 | it->it_remote_lock_mode); |
| 178 | it->it_remote_lock_mode = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | void ll_intent_release(struct lookup_intent *it) |
| 184 | { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 185 | CDEBUG(D_INFO, "intent %p released\n", it); |
| 186 | ll_intent_drop_lock(it); |
| 187 | /* We are still holding extra reference on a request, need to free it */ |
| 188 | if (it_disposition(it, DISP_ENQ_OPEN_REF)) |
John L. Hammond | 8bf86fd | 2016-06-20 16:55:40 -0400 | [diff] [blame] | 189 | ptlrpc_req_finished(it->it_request); /* ll_file_open */ |
John L. Hammond | 2d95f10 | 2014-04-27 13:07:05 -0400 | [diff] [blame] | 190 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 191 | if (it_disposition(it, DISP_ENQ_CREATE_REF)) /* create rec */ |
John L. Hammond | 8bf86fd | 2016-06-20 16:55:40 -0400 | [diff] [blame] | 192 | ptlrpc_req_finished(it->it_request); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 193 | |
John L. Hammond | e476f2e | 2016-06-20 16:55:38 -0400 | [diff] [blame] | 194 | it->it_disposition = 0; |
John L. Hammond | 8bf86fd | 2016-06-20 16:55:40 -0400 | [diff] [blame] | 195 | it->it_request = NULL; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | void ll_invalidate_aliases(struct inode *inode) |
| 199 | { |
| 200 | struct dentry *dentry; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 201 | |
James Nunez | 97a075c | 2016-04-27 18:21:01 -0400 | [diff] [blame] | 202 | CDEBUG(D_INODE, "marking dentries for ino "DFID"(%p) invalid\n", |
| 203 | PFID(ll_inode2fid(inode)), inode); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 204 | |
Oleg Drokin | 2bbec0e | 2016-06-20 16:55:26 -0400 | [diff] [blame] | 205 | spin_lock(&inode->i_lock); |
Oleg Drokin | 9d5be52 | 2015-07-31 19:42:57 -0400 | [diff] [blame] | 206 | hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) { |
Linus Torvalds | dab363f | 2014-12-15 18:06:13 -0800 | [diff] [blame] | 207 | CDEBUG(D_DENTRY, "dentry in drop %pd (%p) parent %p inode %p flags %d\n", |
| 208 | dentry, dentry, dentry->d_parent, |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 209 | d_inode(dentry), dentry->d_flags); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 210 | |
Peng Tao | b1d2a12 | 2013-06-03 21:58:15 +0800 | [diff] [blame] | 211 | d_lustre_invalidate(dentry, 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 212 | } |
Oleg Drokin | 2bbec0e | 2016-06-20 16:55:26 -0400 | [diff] [blame] | 213 | spin_unlock(&inode->i_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | int ll_revalidate_it_finish(struct ptlrpc_request *request, |
| 217 | struct lookup_intent *it, |
Al Viro | dbca51d | 2015-01-18 23:31:19 -0500 | [diff] [blame] | 218 | struct inode *inode) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 219 | { |
| 220 | int rc = 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 221 | |
| 222 | if (!request) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 223 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 224 | |
| 225 | if (it_disposition(it, DISP_LOOKUP_NEG)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 226 | return -ENOENT; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 227 | |
Al Viro | dbca51d | 2015-01-18 23:31:19 -0500 | [diff] [blame] | 228 | rc = ll_prep_inode(&inode, request, NULL, it); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 229 | |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 230 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 231 | } |
| 232 | |
Al Viro | dbca51d | 2015-01-18 23:31:19 -0500 | [diff] [blame] | 233 | void ll_lookup_finish_locks(struct lookup_intent *it, struct inode *inode) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 234 | { |
John L. Hammond | e476f2e | 2016-06-20 16:55:38 -0400 | [diff] [blame] | 235 | if (it->it_lock_mode && inode) { |
Al Viro | dbca51d | 2015-01-18 23:31:19 -0500 | [diff] [blame] | 236 | struct ll_sb_info *sbi = ll_i2sbi(inode); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 237 | |
James Nunez | 97a075c | 2016-04-27 18:21:01 -0400 | [diff] [blame] | 238 | CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"(%p)\n", |
| 239 | PFID(ll_inode2fid(inode)), inode); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 240 | ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL); |
| 241 | } |
| 242 | |
| 243 | /* drop lookup or getattr locks immediately */ |
| 244 | if (it->it_op == IT_LOOKUP || it->it_op == IT_GETATTR) { |
| 245 | /* on 2.6 there are situation when several lookups and |
| 246 | * revalidations may be requested during single operation. |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 247 | * therefore, we don't release intent here -bzzz |
| 248 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 249 | ll_intent_drop_lock(it); |
| 250 | } |
| 251 | } |
| 252 | |
Lai Siyao | f236f69 | 2014-02-28 21:16:38 -0500 | [diff] [blame] | 253 | static int ll_revalidate_dentry(struct dentry *dentry, |
| 254 | unsigned int lookup_flags) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 255 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 256 | struct inode *dir = d_inode(dentry->d_parent); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 257 | |
Oleg Drokin | aae5d55 | 2016-06-20 16:55:46 -0400 | [diff] [blame] | 258 | /* If this is intermediate component path lookup and we were able to get |
| 259 | * to this dentry, then its lock has not been revoked and the |
| 260 | * path component is valid. |
| 261 | */ |
| 262 | if (lookup_flags & LOOKUP_PARENT) |
| 263 | return 1; |
| 264 | |
| 265 | /* Symlink - always valid as long as the dentry was found */ |
| 266 | if (dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode)) |
| 267 | return 1; |
| 268 | |
Lai Siyao | f236f69 | 2014-02-28 21:16:38 -0500 | [diff] [blame] | 269 | /* |
| 270 | * if open&create is set, talk to MDS to make sure file is created if |
| 271 | * necessary, because we can't do this in ->open() later since that's |
| 272 | * called on an inode. return 0 here to let lookup to handle this. |
| 273 | */ |
| 274 | if ((lookup_flags & (LOOKUP_OPEN | LOOKUP_CREATE)) == |
| 275 | (LOOKUP_OPEN | LOOKUP_CREATE)) |
| 276 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 277 | |
Lai Siyao | f236f69 | 2014-02-28 21:16:38 -0500 | [diff] [blame] | 278 | if (lookup_flags & (LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE)) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 279 | return 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 280 | |
Lai Siyao | 5231f76 | 2016-09-18 16:38:09 -0400 | [diff] [blame] | 281 | if (!dentry_may_statahead(dir, dentry)) |
Lai Siyao | f236f69 | 2014-02-28 21:16:38 -0500 | [diff] [blame] | 282 | return 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 283 | |
Lai Siyao | f236f69 | 2014-02-28 21:16:38 -0500 | [diff] [blame] | 284 | if (lookup_flags & LOOKUP_RCU) |
| 285 | return -ECHILD; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 286 | |
Lai Siyao | 5231f76 | 2016-09-18 16:38:09 -0400 | [diff] [blame] | 287 | ll_statahead(dir, &dentry, !d_inode(dentry)); |
Lai Siyao | f236f69 | 2014-02-28 21:16:38 -0500 | [diff] [blame] | 288 | return 1; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* |
| 292 | * Always trust cached dentries. Update statahead window if necessary. |
| 293 | */ |
John L. Hammond | 2d95f10 | 2014-04-27 13:07:05 -0400 | [diff] [blame] | 294 | static int ll_revalidate_nd(struct dentry *dentry, unsigned int flags) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 295 | { |
Al Viro | 09561a5 | 2014-05-07 21:10:24 -0400 | [diff] [blame] | 296 | CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, flags=%u\n", |
| 297 | dentry, flags); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 298 | |
Aya Mahfouz | 5a091a1 | 2015-02-27 15:07:58 +0200 | [diff] [blame] | 299 | return ll_revalidate_dentry(dentry, flags); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 300 | } |
| 301 | |
John L. Hammond | 2d95f10 | 2014-04-27 13:07:05 -0400 | [diff] [blame] | 302 | const struct dentry_operations ll_d_ops = { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 303 | .d_revalidate = ll_revalidate_nd, |
| 304 | .d_release = ll_release, |
| 305 | .d_delete = ll_ddelete, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 306 | .d_compare = ll_dcompare, |
| 307 | }; |