-
Notifications
You must be signed in to change notification settings - Fork 180
Linux 4.7 compat: inode_lock() and friends #549
Conversation
#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) |
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
Let's hope they don't bother to change I_MUTEX_* to I_RWSEM_* |
Agreed. This LGTM. |
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
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
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