Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Linux 4.7 compat: inode_lock() and friends #549

Closed
wants to merge 1 commit into from
Closed

Conversation

tuxoko
Copy link
Contributor

@tuxoko tuxoko commented May 18, 2016

Linux 4.7 changes i_mutex to i_rwsem, and we should used inode_lock and
inode_lock_shared to do exclusive and shared lock respectively.

We use spl_inode_lock{,_shared}() to hide the difference. Note that on older
kernel you'll always take an exclusive lock.

Signed-off-by: Chunwei Chen david.chen@osnexus.com

#define spl_inode_lock(ip) mutex_lock_nested(&(ip)->i_mutex, I_MUTEX_PARENT)
#define spl_inode_unlock(ip) mutex_unlock(&(ip)->i_mutex)
#define spl_inode_lock_shared(ip) mutex_lock(&(ip)->i_mutex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared version should also use mutex_lock_nested() and pass I_MUTEX_PARENT for the reason listed in 628fc52. This way we won't get lockdep warnings on older kernels running newer versions of ZFS which use spl_inode_lock_shared().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently have only one user of spl_inode_lock_shared(llseek hole), and it's not nested so it should fine. Hard coding I_MUTEX_PARENT looks like a hacky work around anyway, so we should leave it alone until we need it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment it's fine, but I suspect it will bite us some day. This raises a related point, it would be prudent to establish spl_ wrappers now for all of the inode lock variants to avoid future potential spl/zfs compatibility issues.

spl_inode_lock
spl_inode_unlock
spl_inode_lock_shared
spl_inode_unlock_shared
spl_inode_trylock
spl_inode_trylock_shared
spl_inode_is_locked
spl_inode_lock_nested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an interesting thing that there's no inode_lock_shared_nested. Perhaps, they haven't found out a need to nest a shared lock. So for consistency, I'd still want to keep spl_inode_lock_shared non-nested.

Do you think I should map spl_inode_lock to non-nested and change the required users to spl_inode_lock_nested?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think now would be the right time to make that change.

Linux 4.7 changes i_mutex to i_rwsem, and we should used inode_lock and
inode_lock_shared to do exclusive and shared lock respectively.

We use spl_inode_lock{,_shared}() to hide the difference. Note that on older
kernel you'll always take an exclusive lock.

We also add all other inode_lock friends. And nested users now should
explicitly call spl_inode_lock_nested with correct subclass.

Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
@tuxoko
Copy link
Contributor Author

tuxoko commented May 20, 2016

Let's hope they don't bother to change I_MUTEX_* to I_RWSEM_*

@behlendorf
Copy link
Contributor

Agreed. This LGTM.

nedbass pushed a commit to nedbass/spl that referenced this pull request Aug 26, 2016
Linux 4.7 changes i_mutex to i_rwsem, and we should used inode_lock and
inode_lock_shared to do exclusive and shared lock respectively.

We use spl_inode_lock{,_shared}() to hide the difference. Note that on older
kernel you'll always take an exclusive lock.

We also add all other inode_lock friends. And nested users now should
explicitly call spl_inode_lock_nested with correct subclass.

Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue openzfs/zfs#4665
Closes openzfs#549
tuxoko pushed a commit to tuxoko/spl that referenced this pull request Sep 8, 2016
Linux 4.7 changes i_mutex to i_rwsem, and we should used inode_lock and
inode_lock_shared to do exclusive and shared lock respectively.

We use spl_inode_lock{,_shared}() to hide the difference. Note that on older
kernel you'll always take an exclusive lock.

We also add all other inode_lock friends. And nested users now should
explicitly call spl_inode_lock_nested with correct subclass.

Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue openzfs/zfs#4665
Closes openzfs#549
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants