Skip to content

Commit

Permalink
direct-io: allow direct writes to empty inodes
Browse files Browse the repository at this point in the history
On a DIO_SKIP_HOLES filesystem, the ->get_block() method is currently
not allowed to create blocks for an empty inode.  This confusion comes
from trying to bit shift a negative number, so check the size of the
inode first.

The problem is most visible for hfsplus, because the fallback to
buffered I/O doesn't happen and the write fails with EIO.  This is in
part the fault of the module, because it gives a wrong return value on
->get_block(); that will be fixed in a separate patch.

Reviewed-by: Jeff Moyer <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
Signed-off-by: Ernesto A. Fernández <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
eafer authored and axboe committed Jan 22, 2019
1 parent 38197ca commit 8b9433e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fs/direct-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
unsigned long fs_count; /* Number of filesystem-sized blocks */
int create;
unsigned int i_blkbits = sdio->blkbits + sdio->blkfactor;
loff_t i_size;

/*
* If there was a memory error and we've overwritten all the
Expand Down Expand Up @@ -708,8 +709,8 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
*/
create = dio->op == REQ_OP_WRITE;
if (dio->flags & DIO_SKIP_HOLES) {
if (fs_startblk <= ((i_size_read(dio->inode) - 1) >>
i_blkbits))
i_size = i_size_read(dio->inode);
if (i_size && fs_startblk <= (i_size - 1) >> i_blkbits)
create = 0;
}

Expand Down

0 comments on commit 8b9433e

Please sign in to comment.