2005-12-16 05:31:24 +07:00
|
|
|
/* -*- mode: c; c-basic-offset: 8; -*-
|
|
|
|
* vim: noexpandtab sw=8 ts=8 sts=0:
|
|
|
|
*
|
|
|
|
* dcache.c
|
|
|
|
*
|
|
|
|
* dentry cache handling code
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002, 2004 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/namei.h>
|
|
|
|
|
|
|
|
#include <cluster/masklog.h>
|
|
|
|
|
|
|
|
#include "ocfs2.h"
|
|
|
|
|
|
|
|
#include "alloc.h"
|
|
|
|
#include "dcache.h"
|
2006-09-09 04:43:18 +07:00
|
|
|
#include "dlmglue.h"
|
2005-12-16 05:31:24 +07:00
|
|
|
#include "file.h"
|
|
|
|
#include "inode.h"
|
2009-01-13 05:20:31 +07:00
|
|
|
#include "super.h"
|
2011-02-23 21:51:49 +07:00
|
|
|
#include "ocfs2_trace.h"
|
2005-12-16 05:31:24 +07:00
|
|
|
|
2010-06-28 22:04:32 +07:00
|
|
|
void ocfs2_dentry_attach_gen(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
unsigned long gen =
|
|
|
|
OCFS2_I(dentry->d_parent->d_inode)->ip_dir_lock_gen;
|
|
|
|
BUG_ON(dentry->d_inode);
|
|
|
|
dentry->d_fsdata = (void *)gen;
|
|
|
|
}
|
|
|
|
|
2006-09-09 04:43:18 +07:00
|
|
|
|
2012-06-11 03:03:43 +07:00
|
|
|
static int ocfs2_dentry_revalidate(struct dentry *dentry, unsigned int flags)
|
2005-12-16 05:31:24 +07:00
|
|
|
{
|
2011-01-07 13:49:57 +07:00
|
|
|
struct inode *inode;
|
2005-12-16 05:31:24 +07:00
|
|
|
int ret = 0; /* if all else fails, just return false */
|
2011-01-07 13:49:57 +07:00
|
|
|
struct ocfs2_super *osb;
|
|
|
|
|
2012-06-11 03:03:43 +07:00
|
|
|
if (flags & LOOKUP_RCU)
|
2011-01-07 13:49:57 +07:00
|
|
|
return -ECHILD;
|
|
|
|
|
|
|
|
inode = dentry->d_inode;
|
|
|
|
osb = OCFS2_SB(dentry->d_sb);
|
2005-12-16 05:31:24 +07:00
|
|
|
|
2011-02-23 21:51:49 +07:00
|
|
|
trace_ocfs2_dentry_revalidate(dentry, dentry->d_name.len,
|
|
|
|
dentry->d_name.name);
|
2005-12-16 05:31:24 +07:00
|
|
|
|
2010-06-28 22:04:32 +07:00
|
|
|
/* For a negative dentry -
|
|
|
|
* check the generation number of the parent and compare with the
|
|
|
|
* one stored in the inode.
|
|
|
|
*/
|
2005-12-16 05:31:24 +07:00
|
|
|
if (inode == NULL) {
|
2010-06-28 22:04:32 +07:00
|
|
|
unsigned long gen = (unsigned long) dentry->d_fsdata;
|
|
|
|
unsigned long pgen =
|
|
|
|
OCFS2_I(dentry->d_parent->d_inode)->ip_dir_lock_gen;
|
2011-02-23 21:51:49 +07:00
|
|
|
|
|
|
|
trace_ocfs2_dentry_revalidate_negative(dentry->d_name.len,
|
|
|
|
dentry->d_name.name,
|
|
|
|
pgen, gen);
|
2010-06-28 22:04:32 +07:00
|
|
|
if (gen != pgen)
|
|
|
|
goto bail;
|
|
|
|
goto valid;
|
2005-12-16 05:31:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
BUG_ON(!osb);
|
|
|
|
|
2006-09-09 04:43:18 +07:00
|
|
|
if (inode == osb->root_inode || is_bad_inode(inode))
|
|
|
|
goto bail;
|
|
|
|
|
|
|
|
spin_lock(&OCFS2_I(inode)->ip_lock);
|
|
|
|
/* did we or someone else delete this inode? */
|
|
|
|
if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED) {
|
2005-12-16 05:31:24 +07:00
|
|
|
spin_unlock(&OCFS2_I(inode)->ip_lock);
|
2011-02-23 21:51:49 +07:00
|
|
|
trace_ocfs2_dentry_revalidate_delete(
|
|
|
|
(unsigned long long)OCFS2_I(inode)->ip_blkno);
|
2006-09-09 04:43:18 +07:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
spin_unlock(&OCFS2_I(inode)->ip_lock);
|
2005-12-16 05:31:24 +07:00
|
|
|
|
2006-09-09 04:43:18 +07:00
|
|
|
/*
|
|
|
|
* We don't need a cluster lock to test this because once an
|
|
|
|
* inode nlink hits zero, it never goes back.
|
|
|
|
*/
|
|
|
|
if (inode->i_nlink == 0) {
|
2011-02-23 21:51:49 +07:00
|
|
|
trace_ocfs2_dentry_revalidate_orphaned(
|
|
|
|
(unsigned long long)OCFS2_I(inode)->ip_blkno,
|
|
|
|
S_ISDIR(inode->i_mode));
|
2006-09-09 04:43:18 +07:00
|
|
|
goto bail;
|
2005-12-16 05:31:24 +07:00
|
|
|
}
|
|
|
|
|
2009-08-27 13:46:56 +07:00
|
|
|
/*
|
|
|
|
* If the last lookup failed to create dentry lock, let us
|
|
|
|
* redo it.
|
|
|
|
*/
|
|
|
|
if (!dentry->d_fsdata) {
|
2011-02-23 21:51:49 +07:00
|
|
|
trace_ocfs2_dentry_revalidate_nofsdata(
|
|
|
|
(unsigned long long)OCFS2_I(inode)->ip_blkno);
|
2009-08-27 13:46:56 +07:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
2010-06-28 22:04:32 +07:00
|
|
|
valid:
|
2005-12-16 05:31:24 +07:00
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
bail:
|
2011-02-23 21:51:49 +07:00
|
|
|
trace_ocfs2_dentry_revalidate_ret(ret);
|
2005-12-16 05:31:24 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-09-09 04:43:18 +07:00
|
|
|
static int ocfs2_match_dentry(struct dentry *dentry,
|
|
|
|
u64 parent_blkno,
|
|
|
|
int skip_unhashed)
|
|
|
|
{
|
|
|
|
struct inode *parent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ocfs2_lookup() does a d_splice_alias() _before_ attaching
|
|
|
|
* to the lock data, so we skip those here, otherwise
|
|
|
|
* ocfs2_dentry_attach_lock() will get its original dentry
|
|
|
|
* back.
|
|
|
|
*/
|
|
|
|
if (!dentry->d_fsdata)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!dentry->d_parent)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (skip_unhashed && d_unhashed(dentry))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
parent = dentry->d_parent->d_inode;
|
|
|
|
/* Negative parent dentry? */
|
|
|
|
if (!parent)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Name is in a different directory. */
|
|
|
|
if (OCFS2_I(parent)->ip_blkno != parent_blkno)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk the inode alias list, and find a dentry which has a given
|
|
|
|
* parent. ocfs2_dentry_attach_lock() wants to find _any_ alias as it
|
2007-09-25 05:56:19 +07:00
|
|
|
* is looking for a dentry_lock reference. The downconvert thread is
|
|
|
|
* looking to unhash aliases, so we allow it to skip any that already
|
|
|
|
* have that property.
|
2006-09-09 04:43:18 +07:00
|
|
|
*/
|
|
|
|
struct dentry *ocfs2_find_local_alias(struct inode *inode,
|
|
|
|
u64 parent_blkno,
|
|
|
|
int skip_unhashed)
|
|
|
|
{
|
2012-06-10 00:09:15 +07:00
|
|
|
struct dentry *dentry;
|
2006-09-09 04:43:18 +07:00
|
|
|
|
2011-01-07 13:50:06 +07:00
|
|
|
spin_lock(&inode->i_lock);
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 08:06:00 +07:00
|
|
|
hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
|
2011-01-07 13:49:33 +07:00
|
|
|
spin_lock(&dentry->d_lock);
|
2006-09-09 04:43:18 +07:00
|
|
|
if (ocfs2_match_dentry(dentry, parent_blkno, skip_unhashed)) {
|
2011-02-23 21:51:49 +07:00
|
|
|
trace_ocfs2_find_local_alias(dentry->d_name.len,
|
|
|
|
dentry->d_name.name);
|
2006-09-09 04:43:18 +07:00
|
|
|
|
2011-01-07 13:49:43 +07:00
|
|
|
dget_dlock(dentry);
|
2011-01-07 13:49:33 +07:00
|
|
|
spin_unlock(&dentry->d_lock);
|
2012-06-10 00:09:15 +07:00
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
return dentry;
|
2006-09-09 04:43:18 +07:00
|
|
|
}
|
2011-01-07 13:49:33 +07:00
|
|
|
spin_unlock(&dentry->d_lock);
|
2006-09-09 04:43:18 +07:00
|
|
|
}
|
2011-01-07 13:50:06 +07:00
|
|
|
spin_unlock(&inode->i_lock);
|
2012-06-10 00:09:15 +07:00
|
|
|
return NULL;
|
2006-09-09 04:43:18 +07:00
|
|
|
}
|
|
|
|
|
2006-09-09 04:14:34 +07:00
|
|
|
DEFINE_SPINLOCK(dentry_attach_lock);
|
|
|
|
|
2006-09-09 04:43:18 +07:00
|
|
|
/*
|
|
|
|
* Attach this dentry to a cluster lock.
|
|
|
|
*
|
|
|
|
* Dentry locks cover all links in a given directory to a particular
|
|
|
|
* inode. We do this so that ocfs2 can build a lock name which all
|
|
|
|
* nodes in the cluster can agree on at all times. Shoving full names
|
|
|
|
* in the cluster lock won't work due to size restrictions. Covering
|
|
|
|
* links inside of a directory is a good compromise because it still
|
|
|
|
* allows us to use the parent directory lock to synchronize
|
|
|
|
* operations.
|
|
|
|
*
|
|
|
|
* Call this function with the parent dir semaphore and the parent dir
|
|
|
|
* cluster lock held.
|
|
|
|
*
|
|
|
|
* The dir semaphore will protect us from having to worry about
|
|
|
|
* concurrent processes on our node trying to attach a lock at the
|
|
|
|
* same time.
|
|
|
|
*
|
|
|
|
* The dir cluster lock (held at either PR or EX mode) protects us
|
|
|
|
* from unlink and rename on other nodes.
|
|
|
|
*
|
|
|
|
* A dput() can happen asynchronously due to pruning, so we cover
|
|
|
|
* attaching and detaching the dentry lock with a
|
|
|
|
* dentry_attach_lock.
|
|
|
|
*
|
|
|
|
* A node which has done lookup on a name retains a protected read
|
|
|
|
* lock until final dput. If the user requests and unlink or rename,
|
|
|
|
* the protected read is upgraded to an exclusive lock. Other nodes
|
|
|
|
* who have seen the dentry will then be informed that they need to
|
|
|
|
* downgrade their lock, which will involve d_delete on the
|
|
|
|
* dentry. This happens in ocfs2_dentry_convert_worker().
|
|
|
|
*/
|
|
|
|
int ocfs2_dentry_attach_lock(struct dentry *dentry,
|
|
|
|
struct inode *inode,
|
2006-09-22 06:51:28 +07:00
|
|
|
u64 parent_blkno)
|
2006-09-09 04:43:18 +07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct dentry *alias;
|
|
|
|
struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
|
|
|
|
|
2011-02-23 21:51:49 +07:00
|
|
|
trace_ocfs2_dentry_attach_lock(dentry->d_name.len, dentry->d_name.name,
|
|
|
|
(unsigned long long)parent_blkno, dl);
|
2006-09-09 04:43:18 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Negative dentry. We ignore these for now.
|
|
|
|
*
|
|
|
|
* XXX: Could we can improve ocfs2_dentry_revalidate() by
|
|
|
|
* tracking these?
|
|
|
|
*/
|
|
|
|
if (!inode)
|
|
|
|
return 0;
|
|
|
|
|
2010-06-28 22:04:32 +07:00
|
|
|
if (!dentry->d_inode && dentry->d_fsdata) {
|
|
|
|
/* Converting a negative dentry to positive
|
|
|
|
Clear dentry->d_fsdata */
|
|
|
|
dentry->d_fsdata = dl = NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-09 04:43:18 +07:00
|
|
|
if (dl) {
|
|
|
|
mlog_bug_on_msg(dl->dl_parent_blkno != parent_blkno,
|
|
|
|
" \"%.*s\": old parent: %llu, new: %llu\n",
|
|
|
|
dentry->d_name.len, dentry->d_name.name,
|
|
|
|
(unsigned long long)parent_blkno,
|
|
|
|
(unsigned long long)dl->dl_parent_blkno);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
alias = ocfs2_find_local_alias(inode, parent_blkno, 0);
|
|
|
|
if (alias) {
|
|
|
|
/*
|
|
|
|
* Great, an alias exists, which means we must have a
|
|
|
|
* dentry lock already. We can just grab the lock off
|
|
|
|
* the alias and add it to the list.
|
|
|
|
*
|
|
|
|
* We're depending here on the fact that this dentry
|
|
|
|
* was found and exists in the dcache and so must have
|
|
|
|
* a reference to the dentry_lock because we can't
|
|
|
|
* race creates. Final dput() cannot happen on it
|
|
|
|
* since we have it pinned, so our reference is safe.
|
|
|
|
*/
|
|
|
|
dl = alias->d_fsdata;
|
2006-09-22 06:51:28 +07:00
|
|
|
mlog_bug_on_msg(!dl, "parent %llu, ino %llu\n",
|
2006-09-09 04:43:18 +07:00
|
|
|
(unsigned long long)parent_blkno,
|
2006-09-22 06:51:28 +07:00
|
|
|
(unsigned long long)OCFS2_I(inode)->ip_blkno);
|
2006-09-09 04:43:18 +07:00
|
|
|
|
|
|
|
mlog_bug_on_msg(dl->dl_parent_blkno != parent_blkno,
|
|
|
|
" \"%.*s\": old parent: %llu, new: %llu\n",
|
|
|
|
dentry->d_name.len, dentry->d_name.name,
|
|
|
|
(unsigned long long)parent_blkno,
|
|
|
|
(unsigned long long)dl->dl_parent_blkno);
|
|
|
|
|
2011-02-23 21:51:49 +07:00
|
|
|
trace_ocfs2_dentry_attach_lock_found(dl->dl_lockres.l_name,
|
|
|
|
(unsigned long long)parent_blkno,
|
|
|
|
(unsigned long long)OCFS2_I(inode)->ip_blkno);
|
2006-09-09 04:43:18 +07:00
|
|
|
|
|
|
|
goto out_attach;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are no other aliases
|
|
|
|
*/
|
|
|
|
dl = kmalloc(sizeof(*dl), GFP_NOFS);
|
|
|
|
if (!dl) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
mlog_errno(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
dl->dl_count = 0;
|
|
|
|
/*
|
|
|
|
* Does this have to happen below, for all attaches, in case
|
2007-09-25 05:56:19 +07:00
|
|
|
* the struct inode gets blown away by the downconvert thread?
|
2006-09-09 04:43:18 +07:00
|
|
|
*/
|
|
|
|
dl->dl_inode = igrab(inode);
|
|
|
|
dl->dl_parent_blkno = parent_blkno;
|
|
|
|
ocfs2_dentry_lock_res_init(dl, parent_blkno, inode);
|
|
|
|
|
|
|
|
out_attach:
|
|
|
|
spin_lock(&dentry_attach_lock);
|
|
|
|
dentry->d_fsdata = dl;
|
|
|
|
dl->dl_count++;
|
|
|
|
spin_unlock(&dentry_attach_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This actually gets us our PRMODE level lock. From now on,
|
|
|
|
* we'll have a notification if one of these names is
|
|
|
|
* destroyed on another node.
|
|
|
|
*/
|
|
|
|
ret = ocfs2_dentry_lock(dentry, 0);
|
2006-09-22 06:51:28 +07:00
|
|
|
if (!ret)
|
|
|
|
ocfs2_dentry_unlock(dentry, 0);
|
|
|
|
else
|
2006-09-09 04:43:18 +07:00
|
|
|
mlog_errno(ret);
|
|
|
|
|
2009-04-21 11:34:18 +07:00
|
|
|
/*
|
|
|
|
* In case of error, manually free the allocation and do the iput().
|
|
|
|
* We need to do this because error here means no d_instantiate(),
|
|
|
|
* which means iput() will not be called during dput(dentry).
|
|
|
|
*/
|
|
|
|
if (ret < 0 && !alias) {
|
|
|
|
ocfs2_lock_res_free(&dl->dl_lockres);
|
|
|
|
BUG_ON(dl->dl_count != 1);
|
|
|
|
spin_lock(&dentry_attach_lock);
|
|
|
|
dentry->d_fsdata = NULL;
|
|
|
|
spin_unlock(&dentry_attach_lock);
|
|
|
|
kfree(dl);
|
|
|
|
iput(inode);
|
|
|
|
}
|
|
|
|
|
2006-09-09 04:43:18 +07:00
|
|
|
dput(alias);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-20 17:12:36 +07:00
|
|
|
DEFINE_SPINLOCK(dentry_list_lock);
|
2009-01-13 05:20:31 +07:00
|
|
|
|
|
|
|
/* We limit the number of dentry locks to drop in one go. We have
|
|
|
|
* this limit so that we don't starve other users of ocfs2_wq. */
|
|
|
|
#define DL_INODE_DROP_COUNT 64
|
|
|
|
|
|
|
|
/* Drop inode references from dentry locks */
|
2009-07-20 17:12:36 +07:00
|
|
|
static void __ocfs2_drop_dl_inodes(struct ocfs2_super *osb, int drop_count)
|
2009-01-13 05:20:31 +07:00
|
|
|
{
|
|
|
|
struct ocfs2_dentry_lock *dl;
|
|
|
|
|
|
|
|
spin_lock(&dentry_list_lock);
|
2009-07-20 17:12:36 +07:00
|
|
|
while (osb->dentry_lock_list && (drop_count < 0 || drop_count--)) {
|
2009-01-13 05:20:31 +07:00
|
|
|
dl = osb->dentry_lock_list;
|
|
|
|
osb->dentry_lock_list = dl->dl_next;
|
|
|
|
spin_unlock(&dentry_list_lock);
|
|
|
|
iput(dl->dl_inode);
|
|
|
|
kfree(dl);
|
|
|
|
spin_lock(&dentry_list_lock);
|
|
|
|
}
|
2009-07-20 17:12:36 +07:00
|
|
|
spin_unlock(&dentry_list_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ocfs2_drop_dl_inodes(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ocfs2_super *osb = container_of(work, struct ocfs2_super,
|
|
|
|
dentry_lock_work);
|
|
|
|
|
|
|
|
__ocfs2_drop_dl_inodes(osb, DL_INODE_DROP_COUNT);
|
|
|
|
/*
|
|
|
|
* Don't queue dropping if umount is in progress. We flush the
|
|
|
|
* list in ocfs2_dismount_volume
|
|
|
|
*/
|
|
|
|
spin_lock(&dentry_list_lock);
|
|
|
|
if (osb->dentry_lock_list &&
|
|
|
|
!ocfs2_test_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED))
|
2009-01-13 05:20:31 +07:00
|
|
|
queue_work(ocfs2_wq, &osb->dentry_lock_work);
|
|
|
|
spin_unlock(&dentry_list_lock);
|
|
|
|
}
|
|
|
|
|
2009-07-20 17:12:36 +07:00
|
|
|
/* Flush the whole work queue */
|
|
|
|
void ocfs2_drop_all_dl_inodes(struct ocfs2_super *osb)
|
|
|
|
{
|
|
|
|
__ocfs2_drop_dl_inodes(osb, -1);
|
|
|
|
}
|
|
|
|
|
2006-09-09 04:43:18 +07:00
|
|
|
/*
|
|
|
|
* ocfs2_dentry_iput() and friends.
|
|
|
|
*
|
|
|
|
* At this point, our particular dentry is detached from the inodes
|
|
|
|
* alias list, so there's no way that the locking code can find it.
|
|
|
|
*
|
|
|
|
* The interesting stuff happens when we determine that our lock needs
|
|
|
|
* to go away because this is the last subdir alias in the
|
|
|
|
* system. This function needs to handle a couple things:
|
|
|
|
*
|
|
|
|
* 1) Synchronizing lock shutdown with the downconvert threads. This
|
|
|
|
* is already handled for us via the lockres release drop function
|
|
|
|
* called in ocfs2_release_dentry_lock()
|
|
|
|
*
|
|
|
|
* 2) A race may occur when we're doing our lock shutdown and
|
|
|
|
* another process wants to create a new dentry lock. Right now we
|
|
|
|
* let them race, which means that for a very short while, this
|
|
|
|
* node might have two locks on a lock resource. This should be a
|
|
|
|
* problem though because one of them is in the process of being
|
|
|
|
* thrown out.
|
|
|
|
*/
|
|
|
|
static void ocfs2_drop_dentry_lock(struct ocfs2_super *osb,
|
|
|
|
struct ocfs2_dentry_lock *dl)
|
|
|
|
{
|
|
|
|
ocfs2_simple_drop_lockres(osb, &dl->dl_lockres);
|
|
|
|
ocfs2_lock_res_free(&dl->dl_lockres);
|
2009-01-13 05:20:31 +07:00
|
|
|
|
|
|
|
/* We leave dropping of inode reference to ocfs2_wq as that can
|
|
|
|
* possibly lead to inode deletion which gets tricky */
|
|
|
|
spin_lock(&dentry_list_lock);
|
2009-07-20 17:12:36 +07:00
|
|
|
if (!osb->dentry_lock_list &&
|
|
|
|
!ocfs2_test_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED))
|
2009-01-13 05:20:31 +07:00
|
|
|
queue_work(ocfs2_wq, &osb->dentry_lock_work);
|
|
|
|
dl->dl_next = osb->dentry_lock_list;
|
|
|
|
osb->dentry_lock_list = dl;
|
|
|
|
spin_unlock(&dentry_list_lock);
|
2006-09-09 04:43:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ocfs2_dentry_lock_put(struct ocfs2_super *osb,
|
|
|
|
struct ocfs2_dentry_lock *dl)
|
|
|
|
{
|
2009-01-13 05:20:31 +07:00
|
|
|
int unlock;
|
2006-09-09 04:43:18 +07:00
|
|
|
|
|
|
|
BUG_ON(dl->dl_count == 0);
|
|
|
|
|
|
|
|
spin_lock(&dentry_attach_lock);
|
|
|
|
dl->dl_count--;
|
|
|
|
unlock = !dl->dl_count;
|
|
|
|
spin_unlock(&dentry_attach_lock);
|
|
|
|
|
|
|
|
if (unlock)
|
|
|
|
ocfs2_drop_dentry_lock(osb, dl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ocfs2_dentry_iput(struct dentry *dentry, struct inode *inode)
|
|
|
|
{
|
|
|
|
struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
|
|
|
|
|
2007-11-08 07:35:14 +07:00
|
|
|
if (!dl) {
|
|
|
|
/*
|
|
|
|
* No dentry lock is ok if we're disconnected or
|
|
|
|
* unhashed.
|
|
|
|
*/
|
|
|
|
if (!(dentry->d_flags & DCACHE_DISCONNECTED) &&
|
|
|
|
!d_unhashed(dentry)) {
|
|
|
|
unsigned long long ino = 0ULL;
|
|
|
|
if (inode)
|
|
|
|
ino = (unsigned long long)OCFS2_I(inode)->ip_blkno;
|
|
|
|
mlog(ML_ERROR, "Dentry is missing cluster lock. "
|
|
|
|
"inode: %llu, d_flags: 0x%x, d_name: %.*s\n",
|
|
|
|
ino, dentry->d_flags, dentry->d_name.len,
|
|
|
|
dentry->d_name.name);
|
|
|
|
}
|
2006-09-09 04:43:18 +07:00
|
|
|
|
|
|
|
goto out;
|
2007-11-08 07:35:14 +07:00
|
|
|
}
|
2006-09-09 04:43:18 +07:00
|
|
|
|
|
|
|
mlog_bug_on_msg(dl->dl_count == 0, "dentry: %.*s, count: %u\n",
|
|
|
|
dentry->d_name.len, dentry->d_name.name,
|
|
|
|
dl->dl_count);
|
|
|
|
|
|
|
|
ocfs2_dentry_lock_put(OCFS2_SB(dentry->d_sb), dl);
|
|
|
|
|
|
|
|
out:
|
|
|
|
iput(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* d_move(), but keep the locks in sync.
|
|
|
|
*
|
|
|
|
* When we are done, "dentry" will have the parent dir and name of
|
|
|
|
* "target", which will be thrown away.
|
|
|
|
*
|
|
|
|
* We manually update the lock of "dentry" if need be.
|
|
|
|
*
|
|
|
|
* "target" doesn't have it's dentry lock touched - we allow the later
|
|
|
|
* dput() to handle this for us.
|
|
|
|
*
|
|
|
|
* This is called during ocfs2_rename(), while holding parent
|
|
|
|
* directory locks. The dentries have already been deleted on other
|
|
|
|
* nodes via ocfs2_remote_dentry_delete().
|
|
|
|
*
|
2007-10-20 04:10:43 +07:00
|
|
|
* Normally, the VFS handles the d_move() for the file system, after
|
2006-09-09 04:43:18 +07:00
|
|
|
* the ->rename() callback. OCFS2 wants to handle this internally, so
|
|
|
|
* the new lock can be created atomically with respect to the cluster.
|
|
|
|
*/
|
|
|
|
void ocfs2_dentry_move(struct dentry *dentry, struct dentry *target,
|
|
|
|
struct inode *old_dir, struct inode *new_dir)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct ocfs2_super *osb = OCFS2_SB(old_dir->i_sb);
|
|
|
|
struct inode *inode = dentry->d_inode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move within the same directory, so the actual lock info won't
|
|
|
|
* change.
|
|
|
|
*
|
|
|
|
* XXX: Is there any advantage to dropping the lock here?
|
|
|
|
*/
|
|
|
|
if (old_dir == new_dir)
|
2006-09-09 04:22:54 +07:00
|
|
|
goto out_move;
|
2006-09-09 04:43:18 +07:00
|
|
|
|
|
|
|
ocfs2_dentry_lock_put(osb, dentry->d_fsdata);
|
|
|
|
|
|
|
|
dentry->d_fsdata = NULL;
|
2006-09-22 06:51:28 +07:00
|
|
|
ret = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(new_dir)->ip_blkno);
|
2006-09-09 04:43:18 +07:00
|
|
|
if (ret)
|
|
|
|
mlog_errno(ret);
|
2006-09-09 04:22:54 +07:00
|
|
|
|
|
|
|
out_move:
|
|
|
|
d_move(dentry, target);
|
2006-09-09 04:43:18 +07:00
|
|
|
}
|
|
|
|
|
2009-02-20 13:00:26 +07:00
|
|
|
const struct dentry_operations ocfs2_dentry_ops = {
|
2005-12-16 05:31:24 +07:00
|
|
|
.d_revalidate = ocfs2_dentry_revalidate,
|
2006-09-09 04:43:18 +07:00
|
|
|
.d_iput = ocfs2_dentry_iput,
|
2005-12-16 05:31:24 +07:00
|
|
|
};
|