diff --git a/fs/inode.c b/fs/inode.c index bf6adf122c68..f97de0aeb3b6 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -567,6 +567,18 @@ EXPORT_SYMBOL(new_inode); void unlock_new_inode(struct inode *inode) { +#ifdef CONFIG_DEBUG_LOCK_ALLOC + struct file_system_type *type = inode->i_sb->s_type; + /* + * ensure nobody is actually holding i_mutex + */ + mutex_destroy(&inode->i_mutex); + mutex_init(&inode->i_mutex); + if (inode->i_mode & S_IFDIR) + lockdep_set_class(&inode->i_mutex, &type->i_mutex_dir_key); + else + lockdep_set_class(&inode->i_mutex, &type->i_mutex_key); +#endif /* * This is special! We do not need the spinlock * when clearing I_LOCK, because we're guaranteed diff --git a/include/linux/fs.h b/include/linux/fs.h index 0cad20e12585..6d760f1ad875 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1308,6 +1308,7 @@ struct file_system_type { struct lock_class_key i_lock_key; struct lock_class_key i_mutex_key; + struct lock_class_key i_mutex_dir_key; struct lock_class_key i_alloc_sem_key; };