提交 d2581ad1 编写于 作者: E Ernesto A. Fernández 提交者: Xie XiuQi

direct-io: allow direct writes to empty inodes

[ Upstream commit 8b9433eb4de3c26a9226c981c283f9f4896ae030 ]

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: NJeff Moyer <jmoyer@redhat.com>
Reviewed-by: NJan Kara <jack@suse.cz>
Signed-off-by: NErnesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 432072ce
...@@ -679,6 +679,7 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, ...@@ -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 */ unsigned long fs_count; /* Number of filesystem-sized blocks */
int create; int create;
unsigned int i_blkbits = sdio->blkbits + sdio->blkfactor; unsigned int i_blkbits = sdio->blkbits + sdio->blkfactor;
loff_t i_size;
/* /*
* If there was a memory error and we've overwritten all the * If there was a memory error and we've overwritten all the
...@@ -708,8 +709,8 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, ...@@ -708,8 +709,8 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio,
*/ */
create = dio->op == REQ_OP_WRITE; create = dio->op == REQ_OP_WRITE;
if (dio->flags & DIO_SKIP_HOLES) { if (dio->flags & DIO_SKIP_HOLES) {
if (fs_startblk <= ((i_size_read(dio->inode) - 1) >> i_size = i_size_read(dio->inode);
i_blkbits)) if (i_size && fs_startblk <= (i_size - 1) >> i_blkbits)
create = 0; create = 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册