4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
34 #include <linux/sched.h>
35 #include <linux/quotaops.h>
36 #include <linux/kernel.h>
38 #define DEBUG_SUBSYSTEM S_LLITE
40 #include <obd_support.h>
41 #include <lustre_dlm.h>
43 #include "llite_internal.h"
45 static void free_dentry_data(struct rcu_head *head)
47 struct ll_dentry_data *lld;
49 lld = container_of(head, struct ll_dentry_data, lld_rcu_head);
53 /* should NOT be called with the dcache lock, see fs/dcache.c */
54 static void ll_release(struct dentry *de)
56 struct ll_dentry_data *lld;
60 if (lld == NULL) /* NFS copies the de->d_op methods (bug 4655) */
64 call_rcu(&lld->lld_rcu_head, free_dentry_data);
70 * Called when last reference to a dentry is dropped and dcache wants to know
71 * whether or not it should cache it:
72 * - return 1 to delete the dentry immediately
73 * - return 0 to cache the dentry
74 * Should NOT be called with the dcache lock, see fs/dcache.c
76 static int ll_ddelete(const struct dentry *de)
81 CDEBUG(D_DENTRY, "%s dentry %.*s (%p, parent %p, inode %p) %s%s\n",
82 d_lustre_invalid((struct dentry *)de) ? "deleting" : "keeping",
83 de->d_name.len, de->d_name.name, de, de->d_parent, de->d_inode,
84 d_unhashed((struct dentry *)de) ? "" : "hashed,",
85 list_empty(&de->d_subdirs) ? "" : "subdirs");
87 /* kernel >= 2.6.38 last refcount is decreased after this function. */
88 LASSERT(ll_d_count(de) == 1);
90 if (d_lustre_invalid((struct dentry *)de))
95 int ll_d_init(struct dentry *de)
100 CDEBUG(D_DENTRY, "ldd on dentry %.*s (%p) parent %p inode %p refc %d\n",
101 de->d_name.len, de->d_name.name, de, de->d_parent, de->d_inode,
104 if (de->d_fsdata == NULL) {
105 struct ll_dentry_data *lld;
108 if (likely(lld != NULL)) {
109 spin_lock(&de->d_lock);
110 if (likely(de->d_fsdata == NULL)) {
112 __d_lustre_invalidate(de);
116 spin_unlock(&de->d_lock);
121 LASSERT(de->d_op == &ll_d_ops);
126 void ll_intent_drop_lock(struct lookup_intent *it)
128 if (it->it_op && it->it_lock_mode) {
129 struct lustre_handle handle;
131 handle.cookie = it->it_lock_handle;
133 CDEBUG(D_DLMTRACE, "releasing lock with cookie %#llx from it %p\n",
135 ldlm_lock_decref(&handle, it->it_lock_mode);
137 /* bug 494: intent_release may be called multiple times, from
138 * this thread and we don't want to double-decref this lock */
139 it->it_lock_mode = 0;
140 if (it->it_remote_lock_mode != 0) {
141 handle.cookie = it->it_remote_lock_handle;
144 "releasing remote lock with cookie %#llx from it %p\n",
146 ldlm_lock_decref(&handle,
147 it->it_remote_lock_mode);
148 it->it_remote_lock_mode = 0;
153 void ll_intent_release(struct lookup_intent *it)
157 CDEBUG(D_INFO, "intent %p released\n", it);
158 ll_intent_drop_lock(it);
159 /* We are still holding extra reference on a request, need to free it */
160 if (it_disposition(it, DISP_ENQ_OPEN_REF))
161 ptlrpc_req_finished(it->it_request); /* ll_file_open */
163 if (it_disposition(it, DISP_ENQ_CREATE_REF)) /* create rec */
164 ptlrpc_req_finished(it->it_request);
166 it->it_disposition = 0;
167 it->it_request = NULL;
171 void ll_invalidate_aliases(struct inode *inode)
173 struct dentry *dentry;
176 LASSERT(inode != NULL);
178 CDEBUG(D_INODE, "marking dentries for inode "DFID"(%p) invalid\n",
179 PFID(ll_inode2fid(inode)), inode);
181 spin_lock(&inode->i_lock);
182 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
183 CDEBUG(D_DENTRY, "dentry in drop %.*s (%p) parent %p "
184 "inode %p flags %d\n", dentry->d_name.len,
185 dentry->d_name.name, dentry, dentry->d_parent,
186 dentry->d_inode, dentry->d_flags);
188 d_lustre_invalidate(dentry, 0);
190 spin_unlock(&inode->i_lock);
195 int ll_revalidate_it_finish(struct ptlrpc_request *request,
196 struct lookup_intent *it,
205 if (it_disposition(it, DISP_LOOKUP_NEG))
208 rc = ll_prep_inode(&de->d_inode, request, NULL, it);
213 void ll_lookup_finish_locks(struct lookup_intent *it, struct dentry *dentry)
216 LASSERT(dentry != NULL);
218 if (it->it_lock_mode && dentry->d_inode != NULL) {
219 struct inode *inode = dentry->d_inode;
220 struct ll_sb_info *sbi = ll_i2sbi(dentry->d_inode);
222 CDEBUG(D_DLMTRACE, "setting l_data to inode "DFID"(%p)\n",
223 PFID(ll_inode2fid(inode)), inode);
224 ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
227 /* drop lookup or getattr locks immediately */
228 if (it->it_op == IT_LOOKUP || it->it_op == IT_GETATTR) {
229 /* on 2.6 there are situation when several lookups and
230 * revalidations may be requested during single operation.
231 * therefore, we don't release intent here -bzzz */
232 ll_intent_drop_lock(it);
236 static int ll_revalidate_dentry(struct dentry *dentry,
237 unsigned int lookup_flags)
239 struct inode *dir = dentry->d_parent->d_inode;
241 CDEBUG(D_VFSTRACE, "VFS Op:name=%s, flags=%u\n",
242 dentry->d_name.name, lookup_flags);
244 /* mountpoint is always valid */
245 if (d_mountpoint((struct dentry *)dentry))
248 /* No lock -> invalid dentry */
249 if (d_lustre_invalid(dentry))
252 /* If this is intermediate component path lookup and we were able to get
253 * to this dentry, then its lock has not been revoked and the
254 * path component is valid. */
255 if (lookup_flags & (LOOKUP_CONTINUE | LOOKUP_PARENT))
258 /* Symlink - always valid as long as the dentry was found */
259 #ifdef HAVE_IOP_GET_LINK
260 if (dentry->d_inode && dentry->d_inode->i_op->get_link)
262 if (dentry->d_inode && dentry->d_inode->i_op->follow_link)
267 * VFS warns us that this is the second go around and previous
268 * operation failed (most likely open|creat), so this time
269 * we better talk to the server via the lookup path by name,
272 if (lookup_flags & LOOKUP_REVAL)
275 if (lookup_flags & LOOKUP_RCU)
278 if (dentry_may_statahead(dir, dentry))
279 ll_statahead(dir, &dentry, dentry->d_inode == NULL);
284 const struct dentry_operations ll_d_ops = {
285 .d_revalidate = ll_revalidate_dentry,
286 .d_release = ll_release,
287 .d_delete = ll_ddelete,