Skip to content
  • Wengang Wang's avatar
    fs/ocfs2: fix race in ocfs2_dentry_attach_lock() · be99ca27
    Wengang Wang authored
    ocfs2_dentry_attach_lock() can be executed in parallel threads against the
    same dentry.  Make that race safe.  The race is like this:
    
                thread A                               thread B
    
    (A1) enter ocfs2_dentry_attach_lock,
    seeing dentry->d_fsdata is NULL,
    and no alias found by
    ocfs2_find_local_alias, so kmalloc
    a new ocfs2_dentry_lock structure
    to local variable "dl", dl1
    
                   .....
    
                                        (B1) enter ocfs2_dentry_attach_lock,
                                        seeing dentry->d_fsdata is NULL,
                                        and no alias found by
                                        ocfs2_find_local_alias so kmalloc
                                        a new ocfs2_dentry_lock structure
                                        to local variable "dl", dl2.
    
                                                       ......
    
    (A2) set dentry->d_fsdata with dl1,
    call ocfs2_dentry_lock() and increase
    dl1->dl_lockres.l_ro_hol...
    be99ca27