• Andrew Morton's avatar
    [PATCH] xattr: fine-grained locking · 6abc05cc
    Andrew Morton authored
    From: Andreas Gruenbacher <agruen@suse.de>
    
    This patch removes the dependency on i_sem in the getxattr and
    listxattr iops of ext2 and ext3. In addition, the global ext[23]_xattr
    semaphores go away. Instead of i_sem and the global semaphore, mutual
    exclusion is now ensured by per-inode xattr semaphores, and by locking
    the buffers before modifying them. The detailed locking strategy is
    described in comments in fs/ext[23]/xattr.c.
    
    Due to this change it is no longer necessary to take i_sem in
    ext[23]_permission() for retrieving acls, so the
    ext[23]_permission_locked() functions go away.
    
    Additionally, the patch fixes a race condition in ext[23]_permission:
    Accessing inode->i_acl was protected by the BKL in 2.4; in 2.5 there no
    longer is such protection. Instead, inode->i_acl (and inode->i_default_acl)
    are now accessed under inode->i_lock. (This could be replaced by RCU in
    the future.)
    
    In the ext3 extended attribute code, an new uglines results from locking
    at the buffer head level: The buffer lock must be held between testing
    if an xattr block can be modified and the actual modification to prevent
    races from happening. Before a block can be modified,
    ext3_journal_get_write_access() must be called. But this requies an unlocked
    buffer, so I call ext3_journal_get_write_access() before locking the
    buffer. If it turns out that the buffer cannot be modified,
    journal_release_buffer() is called. Calling ext3_journal_get_write_access
    after the test but while the buffer is still locked would be much better.
    6abc05cc
super.c 29.6 KB