Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * dcache.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * dentry cache handling code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
^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 <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <cluster/masklog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "ocfs2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "alloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "dcache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "dlmglue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "file.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "ocfs2_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) void ocfs2_dentry_attach_gen(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	unsigned long gen =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		OCFS2_I(d_inode(dentry->d_parent))->ip_dir_lock_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	BUG_ON(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	dentry->d_fsdata = (void *)gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int ocfs2_dentry_revalidate(struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int ret = 0;    /* if all else fails, just return false */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct ocfs2_super *osb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (flags & LOOKUP_RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		return -ECHILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	osb = OCFS2_SB(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	trace_ocfs2_dentry_revalidate(dentry, dentry->d_name.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 				      dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/* For a negative dentry -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 * check the generation number of the parent and compare with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 * one stored in the inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (inode == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		unsigned long gen = (unsigned long) dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		unsigned long pgen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		spin_lock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		pgen = OCFS2_I(d_inode(dentry->d_parent))->ip_dir_lock_gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		spin_unlock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		trace_ocfs2_dentry_revalidate_negative(dentry->d_name.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 						       dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 						       pgen, gen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		if (gen != pgen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		goto valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	BUG_ON(!osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (inode == osb->root_inode || is_bad_inode(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	spin_lock(&OCFS2_I(inode)->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* did we or someone else delete this inode? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		spin_unlock(&OCFS2_I(inode)->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		trace_ocfs2_dentry_revalidate_delete(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				(unsigned long long)OCFS2_I(inode)->ip_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	spin_unlock(&OCFS2_I(inode)->ip_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * We don't need a cluster lock to test this because once an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 * inode nlink hits zero, it never goes back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (inode->i_nlink == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		trace_ocfs2_dentry_revalidate_orphaned(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			(unsigned long long)OCFS2_I(inode)->ip_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			S_ISDIR(inode->i_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 * If the last lookup failed to create dentry lock, let us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 * redo it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (!dentry->d_fsdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		trace_ocfs2_dentry_revalidate_nofsdata(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				(unsigned long long)OCFS2_I(inode)->ip_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		goto bail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) valid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) bail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	trace_ocfs2_dentry_revalidate_ret(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int ocfs2_match_dentry(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			      u64 parent_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			      int skip_unhashed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct inode *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * ocfs2_lookup() does a d_splice_alias() _before_ attaching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 * to the lock data, so we skip those here, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 * ocfs2_dentry_attach_lock() will get its original dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (!dentry->d_fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (!dentry->d_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (skip_unhashed && d_unhashed(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	parent = d_inode(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	/* Negative parent dentry? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (!parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	/* Name is in a different directory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (OCFS2_I(parent)->ip_blkno != parent_blkno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * Walk the inode alias list, and find a dentry which has a given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * parent. ocfs2_dentry_attach_lock() wants to find _any_ alias as it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * is looking for a dentry_lock reference. The downconvert thread is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * looking to unhash aliases, so we allow it to skip any that already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * have that property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct dentry *ocfs2_find_local_alias(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				      u64 parent_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				      int skip_unhashed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		spin_lock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (ocfs2_match_dentry(dentry, parent_blkno, skip_unhashed)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			trace_ocfs2_find_local_alias(dentry->d_name.len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 						     dentry->d_name.name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			dget_dlock(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			spin_unlock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		spin_unlock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) DEFINE_SPINLOCK(dentry_attach_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * Attach this dentry to a cluster lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * Dentry locks cover all links in a given directory to a particular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * inode. We do this so that ocfs2 can build a lock name which all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * nodes in the cluster can agree on at all times. Shoving full names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * in the cluster lock won't work due to size restrictions. Covering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * links inside of a directory is a good compromise because it still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * allows us to use the parent directory lock to synchronize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  * operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * Call this function with the parent dir semaphore and the parent dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * cluster lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * The dir semaphore will protect us from having to worry about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * concurrent processes on our node trying to attach a lock at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * same time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * The dir cluster lock (held at either PR or EX mode) protects us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * from unlink and rename on other nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * A dput() can happen asynchronously due to pruning, so we cover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * attaching and detaching the dentry lock with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * dentry_attach_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * A node which has done lookup on a name retains a protected read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * lock until final dput. If the user requests and unlink or rename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * the protected read is upgraded to an exclusive lock. Other nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * who have seen the dentry will then be informed that they need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * downgrade their lock, which will involve d_delete on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * dentry. This happens in ocfs2_dentry_convert_worker().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int ocfs2_dentry_attach_lock(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			     struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			     u64 parent_blkno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct dentry *alias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	trace_ocfs2_dentry_attach_lock(dentry->d_name.len, dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 				       (unsigned long long)parent_blkno, dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	 * Negative dentry. We ignore these for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 * XXX: Could we can improve ocfs2_dentry_revalidate() by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 * tracking these?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (d_really_is_negative(dentry) && dentry->d_fsdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		/* Converting a negative dentry to positive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		   Clear dentry->d_fsdata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		dentry->d_fsdata = dl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (dl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		mlog_bug_on_msg(dl->dl_parent_blkno != parent_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 				" \"%pd\": old parent: %llu, new: %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				(unsigned long long)parent_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				(unsigned long long)dl->dl_parent_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	alias = ocfs2_find_local_alias(inode, parent_blkno, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (alias) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		 * Great, an alias exists, which means we must have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		 * dentry lock already. We can just grab the lock off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		 * the alias and add it to the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		 * We're depending here on the fact that this dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		 * was found and exists in the dcache and so must have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		 * a reference to the dentry_lock because we can't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		 * race creates. Final dput() cannot happen on it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		 * since we have it pinned, so our reference is safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		dl = alias->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		mlog_bug_on_msg(!dl, "parent %llu, ino %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				(unsigned long long)parent_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 				(unsigned long long)OCFS2_I(inode)->ip_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		mlog_bug_on_msg(dl->dl_parent_blkno != parent_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				" \"%pd\": old parent: %llu, new: %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 				dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 				(unsigned long long)parent_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				(unsigned long long)dl->dl_parent_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		trace_ocfs2_dentry_attach_lock_found(dl->dl_lockres.l_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				(unsigned long long)parent_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				(unsigned long long)OCFS2_I(inode)->ip_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		goto out_attach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	 * There are no other aliases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	dl = kmalloc(sizeof(*dl), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (!dl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	dl->dl_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 * Does this have to happen below, for all attaches, in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 * the struct inode gets blown away by the downconvert thread?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	dl->dl_inode = igrab(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	dl->dl_parent_blkno = parent_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	ocfs2_dentry_lock_res_init(dl, parent_blkno, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) out_attach:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	spin_lock(&dentry_attach_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	if (unlikely(dentry->d_fsdata && !alias)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		/* d_fsdata is set by a racing thread which is doing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		 * the same thing as this thread is doing. Leave the racing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		 * thread going ahead and we return here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		spin_unlock(&dentry_attach_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		iput(dl->dl_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		ocfs2_lock_res_free(&dl->dl_lockres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		kfree(dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	dentry->d_fsdata = dl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	dl->dl_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	spin_unlock(&dentry_attach_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	 * This actually gets us our PRMODE level lock. From now on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	 * we'll have a notification if one of these names is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	 * destroyed on another node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	ret = ocfs2_dentry_lock(dentry, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		ocfs2_dentry_unlock(dentry, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	 * In case of error, manually free the allocation and do the iput().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	 * We need to do this because error here means no d_instantiate(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	 * which means iput() will not be called during dput(dentry).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (ret < 0 && !alias) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		ocfs2_lock_res_free(&dl->dl_lockres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		BUG_ON(dl->dl_count != 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		spin_lock(&dentry_attach_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		dentry->d_fsdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		spin_unlock(&dentry_attach_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		kfree(dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	dput(alias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  * ocfs2_dentry_iput() and friends.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  * At this point, our particular dentry is detached from the inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * alias list, so there's no way that the locking code can find it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  * The interesting stuff happens when we determine that our lock needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * to go away because this is the last subdir alias in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * system. This function needs to handle a couple things:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * 1) Synchronizing lock shutdown with the downconvert threads. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  *    is already handled for us via the lockres release drop function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  *    called in ocfs2_release_dentry_lock()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  * 2) A race may occur when we're doing our lock shutdown and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  *    another process wants to create a new dentry lock. Right now we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  *    let them race, which means that for a very short while, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  *    node might have two locks on a lock resource. This should be a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  *    problem though because one of them is in the process of being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)  *    thrown out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static void ocfs2_drop_dentry_lock(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 				   struct ocfs2_dentry_lock *dl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	iput(dl->dl_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	ocfs2_simple_drop_lockres(osb, &dl->dl_lockres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	ocfs2_lock_res_free(&dl->dl_lockres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	kfree(dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) void ocfs2_dentry_lock_put(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			   struct ocfs2_dentry_lock *dl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	int unlock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	BUG_ON(dl->dl_count == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	spin_lock(&dentry_attach_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	dl->dl_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	unlock = !dl->dl_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	spin_unlock(&dentry_attach_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (unlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		ocfs2_drop_dentry_lock(osb, dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static void ocfs2_dentry_iput(struct dentry *dentry, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (!dl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		 * No dentry lock is ok if we're disconnected or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		 * unhashed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		if (!(dentry->d_flags & DCACHE_DISCONNECTED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		    !d_unhashed(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			unsigned long long ino = 0ULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 				ino = (unsigned long long)OCFS2_I(inode)->ip_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			mlog(ML_ERROR, "Dentry is missing cluster lock. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			     "inode: %llu, d_flags: 0x%x, d_name: %pd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			     ino, dentry->d_flags, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	mlog_bug_on_msg(dl->dl_count == 0, "dentry: %pd, count: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 			dentry, dl->dl_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	ocfs2_dentry_lock_put(OCFS2_SB(dentry->d_sb), dl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * d_move(), but keep the locks in sync.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  * When we are done, "dentry" will have the parent dir and name of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  * "target", which will be thrown away.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  * We manually update the lock of "dentry" if need be.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  * "target" doesn't have it's dentry lock touched - we allow the later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)  * dput() to handle this for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)  * This is called during ocfs2_rename(), while holding parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  * directory locks. The dentries have already been deleted on other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  * nodes via ocfs2_remote_dentry_delete().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  * Normally, the VFS handles the d_move() for the file system, after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  * the ->rename() callback. OCFS2 wants to handle this internally, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  * the new lock can be created atomically with respect to the cluster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) void ocfs2_dentry_move(struct dentry *dentry, struct dentry *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		       struct inode *old_dir, struct inode *new_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	struct ocfs2_super *osb = OCFS2_SB(old_dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	 * Move within the same directory, so the actual lock info won't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	 * change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	 * XXX: Is there any advantage to dropping the lock here?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (old_dir == new_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		goto out_move;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	ocfs2_dentry_lock_put(osb, dentry->d_fsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	dentry->d_fsdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	ret = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(new_dir)->ip_blkno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		mlog_errno(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) out_move:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	d_move(dentry, target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) const struct dentry_operations ocfs2_dentry_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	.d_revalidate		= ocfs2_dentry_revalidate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	.d_iput			= ocfs2_dentry_iput,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) };