diff mbox series

[1/2] ocfs2: dlmfs: not clear USER_LOCK_ATTACHED when destroy lock

Message ID 20220510232213.23435-1-junxiao.bi@oracle.com (mailing list archive)
State New
Headers show
Series [1/2] ocfs2: dlmfs: not clear USER_LOCK_ATTACHED when destroy lock | expand

Commit Message

Junxiao Bi May 10, 2022, 11:22 p.m. UTC
The following function is the only place that check USER_LOCK_ATTACHED,
this flag is set when lock request is granted through user_bast() and
only the following function will clear it.

Checking of this flag here is to make sure ocfs2_dlm_unlock is not
issued if this lock is never granted. For example, lock file is created
and then get removed, open file never happens.

Clearing the flag here is not necessary because this is the only function
that checks it, if another flow is executing user_dlm_destroy_lock(), it
will bail out at the beginning because of USER_LOCK_IN_TEARDOWN and never
check USER_LOCK_ATTACHED.
Drop the clear, so we don't need take care it for the following
error handling patch.

int user_dlm_destroy_lock(struct user_lock_res *lockres)
{
    ...

    status = 0;
    if (!(lockres->l_flags & USER_LOCK_ATTACHED)) {
        spin_unlock(&lockres->l_lock);
        goto bail;
    }

    lockres->l_flags &= ~USER_LOCK_ATTACHED;
    lockres->l_flags |= USER_LOCK_BUSY;
    spin_unlock(&lockres->l_lock);

	status = ocfs2_dlm_unlock(conn, &lockres->l_lksb, DLM_LKF_VALBLK);
    if (status) {
        user_log_dlm_error("ocfs2_dlm_unlock", status, lockres);
        goto bail;
    }
	...
}

Cc: <stable@vger.kernel.org>
Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
---
 fs/ocfs2/dlmfs/userdlm.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Joseph Qi May 13, 2022, 2:05 a.m. UTC | #1
On 5/11/22 7:22 AM, Junxiao Bi wrote:
> The following function is the only place that check USER_LOCK_ATTACHED,
> this flag is set when lock request is granted through user_bast() and
> only the following function will clear it.
> 
user_ast?

> Checking of this flag here is to make sure ocfs2_dlm_unlock is not
> issued if this lock is never granted. For example, lock file is created
> and then get removed, open file never happens.
> 
> Clearing the flag here is not necessary because this is the only function
> that checks it, if another flow is executing user_dlm_destroy_lock(), it
> will bail out at the beginning because of USER_LOCK_IN_TEARDOWN and never
> check USER_LOCK_ATTACHED.
> Drop the clear, so we don't need take care it for the following
> error handling patch.
> 
Seems it depends on initializing lockres every time, but it seems this
is not true for directory now.

Thanks,
Joseph

> int user_dlm_destroy_lock(struct user_lock_res *lockres)
> {
>     ...
> 
>     status = 0;
>     if (!(lockres->l_flags & USER_LOCK_ATTACHED)) {
>         spin_unlock(&lockres->l_lock);
>         goto bail;
>     }
> 
>     lockres->l_flags &= ~USER_LOCK_ATTACHED;
>     lockres->l_flags |= USER_LOCK_BUSY;
>     spin_unlock(&lockres->l_lock);
> 
> 	status = ocfs2_dlm_unlock(conn, &lockres->l_lksb, DLM_LKF_VALBLK);
>     if (status) {
>         user_log_dlm_error("ocfs2_dlm_unlock", status, lockres);
>         goto bail;
>     }
> 	...
> }
> 
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
> ---
>  fs/ocfs2/dlmfs/userdlm.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/fs/ocfs2/dlmfs/userdlm.c b/fs/ocfs2/dlmfs/userdlm.c
> index 29f183a15798..af0be612589c 100644
> --- a/fs/ocfs2/dlmfs/userdlm.c
> +++ b/fs/ocfs2/dlmfs/userdlm.c
> @@ -619,7 +619,6 @@ int user_dlm_destroy_lock(struct user_lock_res *lockres)
>  		goto bail;
>  	}
>  
> -	lockres->l_flags &= ~USER_LOCK_ATTACHED;
>  	lockres->l_flags |= USER_LOCK_BUSY;
>  	spin_unlock(&lockres->l_lock);
>
Junxiao Bi May 13, 2022, 4:27 p.m. UTC | #2
On 5/12/22 7:05 PM, Joseph Qi wrote:

>
> On 5/11/22 7:22 AM, Junxiao Bi wrote:
>> The following function is the only place that check USER_LOCK_ATTACHED,
>> this flag is set when lock request is granted through user_bast() and
>> only the following function will clear it.
>>
> user_ast?
Good catch, that's a typo, should be user_ast.
>
>> Checking of this flag here is to make sure ocfs2_dlm_unlock is not
>> issued if this lock is never granted. For example, lock file is created
>> and then get removed, open file never happens.
>>
>> Clearing the flag here is not necessary because this is the only function
>> that checks it, if another flow is executing user_dlm_destroy_lock(), it
>> will bail out at the beginning because of USER_LOCK_IN_TEARDOWN and never
>> check USER_LOCK_ATTACHED.
>> Drop the clear, so we don't need take care it for the following
>> error handling patch.
>>
> Seems it depends on initializing lockres every time, but it seems this
> is not true for directory now.

Sorry, i didn't get this. Can you elaborate this?

Thanks,

Junxiao.

>
> Thanks,
> Joseph
>
>> int user_dlm_destroy_lock(struct user_lock_res *lockres)
>> {
>>      ...
>>
>>      status = 0;
>>      if (!(lockres->l_flags & USER_LOCK_ATTACHED)) {
>>          spin_unlock(&lockres->l_lock);
>>          goto bail;
>>      }
>>
>>      lockres->l_flags &= ~USER_LOCK_ATTACHED;
>>      lockres->l_flags |= USER_LOCK_BUSY;
>>      spin_unlock(&lockres->l_lock);
>>
>> 	status = ocfs2_dlm_unlock(conn, &lockres->l_lksb, DLM_LKF_VALBLK);
>>      if (status) {
>>          user_log_dlm_error("ocfs2_dlm_unlock", status, lockres);
>>          goto bail;
>>      }
>> 	...
>> }
>>
>> Cc: <stable@vger.kernel.org>
>> Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
>> ---
>>   fs/ocfs2/dlmfs/userdlm.c | 1 -
>>   1 file changed, 1 deletion(-)
>>
>> diff --git a/fs/ocfs2/dlmfs/userdlm.c b/fs/ocfs2/dlmfs/userdlm.c
>> index 29f183a15798..af0be612589c 100644
>> --- a/fs/ocfs2/dlmfs/userdlm.c
>> +++ b/fs/ocfs2/dlmfs/userdlm.c
>> @@ -619,7 +619,6 @@ int user_dlm_destroy_lock(struct user_lock_res *lockres)
>>   		goto bail;
>>   	}
>>   
>> -	lockres->l_flags &= ~USER_LOCK_ATTACHED;
>>   	lockres->l_flags |= USER_LOCK_BUSY;
>>   	spin_unlock(&lockres->l_lock);
>>
Joseph Qi May 15, 2022, 2:57 p.m. UTC | #3
On 5/14/22 12:27 AM, Junxiao Bi wrote:
> On 5/12/22 7:05 PM, Joseph Qi wrote:
> 
>>
>> On 5/11/22 7:22 AM, Junxiao Bi wrote:
>>> The following function is the only place that check USER_LOCK_ATTACHED,
>>> this flag is set when lock request is granted through user_bast() and
>>> only the following function will clear it.
>>>
>> user_ast?
> Good catch, that's a typo, should be user_ast.
>>
>>> Checking of this flag here is to make sure ocfs2_dlm_unlock is not
>>> issued if this lock is never granted. For example, lock file is created
>>> and then get removed, open file never happens.
>>>
>>> Clearing the flag here is not necessary because this is the only function
>>> that checks it, if another flow is executing user_dlm_destroy_lock(), it
>>> will bail out at the beginning because of USER_LOCK_IN_TEARDOWN and never
>>> check USER_LOCK_ATTACHED.
>>> Drop the clear, so we don't need take care it for the following
>>> error handling patch.
>>>
>> Seems it depends on initializing lockres every time, but it seems this
>> is not true for directory now.
> 
> Sorry, i didn't get this. Can you elaborate this?
> 
lockres may be reused and if we don't reinitialized, the left flag can
cause unexpected behavior.

Thanks,
Joseph
Junxiao Bi May 16, 2022, 4:30 p.m. UTC | #4
On 5/15/22 7:57 AM, Joseph Qi wrote:
>
> On 5/14/22 12:27 AM, Junxiao Bi wrote:
>> On 5/12/22 7:05 PM, Joseph Qi wrote:
>>
>>> On 5/11/22 7:22 AM, Junxiao Bi wrote:
>>>> The following function is the only place that check USER_LOCK_ATTACHED,
>>>> this flag is set when lock request is granted through user_bast() and
>>>> only the following function will clear it.
>>>>
>>> user_ast?
>> Good catch, that's a typo, should be user_ast.
>>>> Checking of this flag here is to make sure ocfs2_dlm_unlock is not
>>>> issued if this lock is never granted. For example, lock file is created
>>>> and then get removed, open file never happens.
>>>>
>>>> Clearing the flag here is not necessary because this is the only function
>>>> that checks it, if another flow is executing user_dlm_destroy_lock(), it
>>>> will bail out at the beginning because of USER_LOCK_IN_TEARDOWN and never
>>>> check USER_LOCK_ATTACHED.
>>>> Drop the clear, so we don't need take care it for the following
>>>> error handling patch.
>>>>
>>> Seems it depends on initializing lockres every time, but it seems this
>>> is not true for directory now.
>> Sorry, i didn't get this. Can you elaborate this?
>>
> lockres may be reused and if we don't reinitialized, the left flag can
> cause unexpected behavior.

I don't know how it could get reused since it's going to be removed. 
Anyway USER_LOCK_IN_TEARDOWN is still set in lockres. All the flow will 
bail out because of this flag.

Thanks,

Junxiao.

>
> Thanks,
> Joseph
Joseph Qi May 17, 2022, 1:58 a.m. UTC | #5
On 5/17/22 12:30 AM, Junxiao Bi wrote:
> 
> On 5/15/22 7:57 AM, Joseph Qi wrote:
>>
>> On 5/14/22 12:27 AM, Junxiao Bi wrote:
>>> On 5/12/22 7:05 PM, Joseph Qi wrote:
>>>
>>>> On 5/11/22 7:22 AM, Junxiao Bi wrote:
>>>>> The following function is the only place that check USER_LOCK_ATTACHED,
>>>>> this flag is set when lock request is granted through user_bast() and
>>>>> only the following function will clear it.
>>>>>
>>>> user_ast?
>>> Good catch, that's a typo, should be user_ast.
>>>>> Checking of this flag here is to make sure ocfs2_dlm_unlock is not
>>>>> issued if this lock is never granted. For example, lock file is created
>>>>> and then get removed, open file never happens.
>>>>>
>>>>> Clearing the flag here is not necessary because this is the only function
>>>>> that checks it, if another flow is executing user_dlm_destroy_lock(), it
>>>>> will bail out at the beginning because of USER_LOCK_IN_TEARDOWN and never
>>>>> check USER_LOCK_ATTACHED.
>>>>> Drop the clear, so we don't need take care it for the following
>>>>> error handling patch.
>>>>>
>>>> Seems it depends on initializing lockres every time, but it seems this
>>>> is not true for directory now.
>>> Sorry, i didn't get this. Can you elaborate this?
>>>
>> lockres may be reused and if we don't reinitialized, the left flag can
>> cause unexpected behavior.
> 
> I don't know how it could get reused since it's going to be removed. Anyway USER_LOCK_IN_TEARDOWN is still set in lockres. All the flow will bail out because of this flag.
> 

dlmfs_inode_private is allocated from kmem_cache.
The case I'm thinking about is, calling user_dlm_destroy_lock() without
a valid ast comming before. So checking USER_LOCK_ATTACHED here may be
incorrect.
But look more closer, it seems that lockres is unused for directories.
So it won't be a real issue.
Could you please send a new version with update description?

Thanks,
Joseph
Junxiao Bi May 17, 2022, 4:12 p.m. UTC | #6
On 5/16/22 6:58 PM, Joseph Qi wrote:
>
> On 5/17/22 12:30 AM, Junxiao Bi wrote:
>> On 5/15/22 7:57 AM, Joseph Qi wrote:
>>> On 5/14/22 12:27 AM, Junxiao Bi wrote:
>>>> On 5/12/22 7:05 PM, Joseph Qi wrote:
>>>>
>>>>> On 5/11/22 7:22 AM, Junxiao Bi wrote:
>>>>>> The following function is the only place that check USER_LOCK_ATTACHED,
>>>>>> this flag is set when lock request is granted through user_bast() and
>>>>>> only the following function will clear it.
>>>>>>
>>>>> user_ast?
>>>> Good catch, that's a typo, should be user_ast.
>>>>>> Checking of this flag here is to make sure ocfs2_dlm_unlock is not
>>>>>> issued if this lock is never granted. For example, lock file is created
>>>>>> and then get removed, open file never happens.
>>>>>>
>>>>>> Clearing the flag here is not necessary because this is the only function
>>>>>> that checks it, if another flow is executing user_dlm_destroy_lock(), it
>>>>>> will bail out at the beginning because of USER_LOCK_IN_TEARDOWN and never
>>>>>> check USER_LOCK_ATTACHED.
>>>>>> Drop the clear, so we don't need take care it for the following
>>>>>> error handling patch.
>>>>>>
>>>>> Seems it depends on initializing lockres every time, but it seems this
>>>>> is not true for directory now.
>>>> Sorry, i didn't get this. Can you elaborate this?
>>>>
>>> lockres may be reused and if we don't reinitialized, the left flag can
>>> cause unexpected behavior.
>> I don't know how it could get reused since it's going to be removed. Anyway USER_LOCK_IN_TEARDOWN is still set in lockres. All the flow will bail out because of this flag.
>>
> dlmfs_inode_private is allocated from kmem_cache.
> The case I'm thinking about is, calling user_dlm_destroy_lock() without
> a valid ast comming before. So checking USER_LOCK_ATTACHED here may be
> incorrect.
> But look more closer, it seems that lockres is unused for directories.
> So it won't be a real issue.
Yes, lock is only for file, not direcotry.
> Could you please send a new version with update description?

Sorry, little confused, which part of description needs update?

Thanks,

Junxiao.

>
> Thanks,
> Joseph
Joseph Qi May 18, 2022, 1:54 a.m. UTC | #7
On 5/18/22 12:12 AM, Junxiao Bi wrote:
> 
> On 5/16/22 6:58 PM, Joseph Qi wrote:
>>
>> On 5/17/22 12:30 AM, Junxiao Bi wrote:
>>> On 5/15/22 7:57 AM, Joseph Qi wrote:
>>>> On 5/14/22 12:27 AM, Junxiao Bi wrote:
>>>>> On 5/12/22 7:05 PM, Joseph Qi wrote:
>>>>>
>>>>>> On 5/11/22 7:22 AM, Junxiao Bi wrote:
>>>>>>> The following function is the only place that check USER_LOCK_ATTACHED,
>>>>>>> this flag is set when lock request is granted through user_bast() and
>>>>>>> only the following function will clear it.
>>>>>>>
>>>>>> user_ast?
>>>>> Good catch, that's a typo, should be user_ast.
>>>>>>> Checking of this flag here is to make sure ocfs2_dlm_unlock is not
>>>>>>> issued if this lock is never granted. For example, lock file is created
>>>>>>> and then get removed, open file never happens.
>>>>>>>
>>>>>>> Clearing the flag here is not necessary because this is the only function
>>>>>>> that checks it, if another flow is executing user_dlm_destroy_lock(), it
>>>>>>> will bail out at the beginning because of USER_LOCK_IN_TEARDOWN and never
>>>>>>> check USER_LOCK_ATTACHED.
>>>>>>> Drop the clear, so we don't need take care it for the following
>>>>>>> error handling patch.
>>>>>>>
>>>>>> Seems it depends on initializing lockres every time, but it seems this
>>>>>> is not true for directory now.
>>>>> Sorry, i didn't get this. Can you elaborate this?
>>>>>
>>>> lockres may be reused and if we don't reinitialized, the left flag can
>>>> cause unexpected behavior.
>>> I don't know how it could get reused since it's going to be removed. Anyway USER_LOCK_IN_TEARDOWN is still set in lockres. All the flow will bail out because of this flag.
>>>
>> dlmfs_inode_private is allocated from kmem_cache.
>> The case I'm thinking about is, calling user_dlm_destroy_lock() without
>> a valid ast comming before. So checking USER_LOCK_ATTACHED here may be
>> incorrect.
>> But look more closer, it seems that lockres is unused for directories.
>> So it won't be a real issue.
> Yes, lock is only for file, not direcotry.
>> Could you please send a new version with update description?
> 
> Sorry, little confused, which part of description needs update?
> 

The typo that user_ast() is for granting lock request. And better to include
the information we discussed above.
Junxiao Bi May 18, 2022, 3:54 p.m. UTC | #8
On 5/17/22 6:54 PM, Joseph Qi wrote:
>
> On 5/18/22 12:12 AM, Junxiao Bi wrote:
>> On 5/16/22 6:58 PM, Joseph Qi wrote:
>>> On 5/17/22 12:30 AM, Junxiao Bi wrote:
>>>> On 5/15/22 7:57 AM, Joseph Qi wrote:
>>>>> On 5/14/22 12:27 AM, Junxiao Bi wrote:
>>>>>> On 5/12/22 7:05 PM, Joseph Qi wrote:
>>>>>>
>>>>>>> On 5/11/22 7:22 AM, Junxiao Bi wrote:
>>>>>>>> The following function is the only place that check USER_LOCK_ATTACHED,
>>>>>>>> this flag is set when lock request is granted through user_bast() and
>>>>>>>> only the following function will clear it.
>>>>>>>>
>>>>>>> user_ast?
>>>>>> Good catch, that's a typo, should be user_ast.
>>>>>>>> Checking of this flag here is to make sure ocfs2_dlm_unlock is not
>>>>>>>> issued if this lock is never granted. For example, lock file is created
>>>>>>>> and then get removed, open file never happens.
>>>>>>>>
>>>>>>>> Clearing the flag here is not necessary because this is the only function
>>>>>>>> that checks it, if another flow is executing user_dlm_destroy_lock(), it
>>>>>>>> will bail out at the beginning because of USER_LOCK_IN_TEARDOWN and never
>>>>>>>> check USER_LOCK_ATTACHED.
>>>>>>>> Drop the clear, so we don't need take care it for the following
>>>>>>>> error handling patch.
>>>>>>>>
>>>>>>> Seems it depends on initializing lockres every time, but it seems this
>>>>>>> is not true for directory now.
>>>>>> Sorry, i didn't get this. Can you elaborate this?
>>>>>>
>>>>> lockres may be reused and if we don't reinitialized, the left flag can
>>>>> cause unexpected behavior.
>>>> I don't know how it could get reused since it's going to be removed. Anyway USER_LOCK_IN_TEARDOWN is still set in lockres. All the flow will bail out because of this flag.
>>>>
>>> dlmfs_inode_private is allocated from kmem_cache.
>>> The case I'm thinking about is, calling user_dlm_destroy_lock() without
>>> a valid ast comming before. So checking USER_LOCK_ATTACHED here may be
>>> incorrect.
>>> But look more closer, it seems that lockres is unused for directories.
>>> So it won't be a real issue.
>> Yes, lock is only for file, not direcotry.
>>> Could you please send a new version with update description?
>> Sorry, little confused, which part of description needs update?
>>
> The typo that user_ast() is for granting lock request. And better to include
> the information we discussed above.

got it, will send a v2

Thanks,

Junxiao.
diff mbox series

Patch

diff --git a/fs/ocfs2/dlmfs/userdlm.c b/fs/ocfs2/dlmfs/userdlm.c
index 29f183a15798..af0be612589c 100644
--- a/fs/ocfs2/dlmfs/userdlm.c
+++ b/fs/ocfs2/dlmfs/userdlm.c
@@ -619,7 +619,6 @@  int user_dlm_destroy_lock(struct user_lock_res *lockres)
 		goto bail;
 	}
 
-	lockres->l_flags &= ~USER_LOCK_ATTACHED;
 	lockres->l_flags |= USER_LOCK_BUSY;
 	spin_unlock(&lockres->l_lock);