• Andreas Gruenbacher's avatar
    gfs2: Rework read and page fault locking · 20f82999
    Andreas Gruenbacher authored
    So far, gfs2 has taken the inode glocks inside the ->readpage and
    ->readahead address space operations.  Since commit d4388340 ("fs:
    convert mpage_readpages to mpage_readahead"), gfs2_readahead is passed
    the pages to read ahead locked.  With that, the current holder of the
    inode glock may be trying to lock one of those pages while
    gfs2_readahead is trying to take the inode glock, resulting in a
    deadlock.
    
    Fix that by moving the lock taking to the higher-level ->read_iter file
    and ->fault vm operations.  This also gets rid of an ugly lock inversion
    workaround in gfs2_readpage.
    
    The cache consistency model of filesystems like gfs2 is such that if
    data is found in the page cache, the data is up to date and can be used
    without taking any filesystem locks.  If a page is not cached,
    filesystem locks must be taken before populating the page cache.
    
    To avoid taking the inode glock when the data is already cached,
    gfs2_file_read_iter first tries to read the data with the IOCB_NOIO flag
    set.  If that fails, the inode glock is taken and the operation is
    retried with the IOCB_NOIO flag cleared.
    Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
    20f82999
aops.c 20.5 KB