Skip to contentSkip to conversation

Questions about qgroup_lock and qgroup_ioctl_lock in enable/disable quota

DISCUSSION Sidong Yang 1 participant 1 message Mar 3, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Hi.

As a newbie, I have some questions about qgroup_ioctl_lock and qgroup_lock in enable/disable quota.

I'm reading btrfs_quota_enable() in qgroup.c, I'm confused about qgroup_ioctl_lock. It seems that in the begining of the function, it checkes fs_info->quota_root with qgroup_ioctl_lock locked. And I feel like that fs_info->qgroup_ioctl_lock protects fs_info->quota_root. After that it releases qgroup_ioctl_lock and starts transaction in line 1005.

I understand that there was problem about deadlock between qgroup_ioctl_lock and the vfs freeze semaphores. And it also lock qgroup_ioctl_locki again. Just after that, There is code checkes fs_info->quota_root like below.

lock qgroup_ioctl_lock => check fs_info->quota_root => unlock qgroup_ioctl_lock => unlock qgroup_ioctl_lock => start transaction => check fs_info->quota_root

I think there is no need to double checks. Is it right?

And the end of the function, It seems that the code as below.

unlock qgroup_ioctl_lock => commit transaction => lock qgroup_ioctl_lock => lock qgroup_lock => set fs_info->quota_root => unlock qgroup_lock => unlock qgroup_ioctl_lock

For the beginning of the function, there was no qgroup_lock for check fs_info->quota_root. It should be protected?

I think the typical pattern below works and it's simple for the function.

start transaction => lock qgroup_ioctl_lock => unlock qgroup_ioctl_lock => commit transaction

Will there be any problems with this implementation?