Merge tag 'xfs-4.18-merge-10' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[sfrench/cifs-2.6.git] / fs / xfs / xfs_iops.c
index 3b4be06fdaa57112150770c84d62f048261a00c8..1fce707406c6352175c6218ca6dd09140bedac27 100644 (file)
@@ -1,19 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  * 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.
- *
- * This program is distributed in the hope that it would 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 the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 #include "xfs.h"
 #include "xfs_fs.h"
@@ -1274,6 +1262,14 @@ xfs_setup_inode(
        xfs_diflags_to_iflags(inode, ip);
 
        if (S_ISDIR(inode->i_mode)) {
+               /*
+                * We set the i_rwsem class here to avoid potential races with
+                * lockdep_annotate_inode_mutex_key() reinitialising the lock
+                * after a filehandle lookup has already found the inode in
+                * cache before it has been unlocked via unlock_new_inode().
+                */
+               lockdep_set_class(&inode->i_rwsem,
+                                 &inode->i_sb->s_type->i_mutex_dir_key);
                lockdep_set_class(&ip->i_lock.mr_lock, &xfs_dir_ilock_class);
                ip->d_ops = ip->i_mount->m_dir_inode_ops;
        } else {