• Miao Xie's avatar
    Btrfs: serialize unlocked dio reads with truncate · 2e60a51e
    Miao Xie authored
    Currently, we can do unlocked dio reads, but the following race
    is possible:
    
    dio_read_task			truncate_task
    				->btrfs_setattr()
    ->btrfs_direct_IO
        ->__blockdev_direct_IO
          ->btrfs_get_block
    				  ->btrfs_truncate()
    				 #alloc truncated blocks
    				 #to other inode
          ->submit_io()
         #INFORMATION LEAK
    
    In order to avoid this problem, we must serialize unlocked dio reads with
    truncate. There are two approaches:
    - use extent lock to protect the extent that we truncate
    - use inode_dio_wait() to make sure the truncating task will wait for
      the read DIO.
    
    If we use the 1st one, we will meet the endless truncation problem due to
    the nonlocked read DIO after we implement the nonlocked write DIO. It is
    because we still need invoke inode_dio_wait() avoid the race between write
    DIO and truncation. By that time, we have to introduce
    
      btrfs_inode_{block, resume}_nolock_dio()
    
    again. That is we have to implement this patch again, so I choose the 2nd
    way to fix the problem.
    Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
    Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
    2e60a51e
btrfs_inode.h 6.38 KB