Skip to contentSkip to conversation

direct-io: allow direct writes to empty inodes

PATCH In review Ernesto A. Fernández 3 participants 8 messages Oct 9, 2018 – Jan 22, 2019 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 direct-io: allow direct writes to empty inodes

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.

---
 fs/direct-io.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/direct-io.c +3 -2
index 093fb54cd316..9a7b91a3b7a7 100644
@@ -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
@@ -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;
 		}
 
Signature · 1 line
2.11.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ernesto A. Fern�ndez

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.

Good catch. The patch looks good. You can add:

Also Jens often picks up patches for direct IO code so added him to CC. Jens?

Honza

Quoted 30 lines
---
 fs/direct-io.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/direct-io.c +3 -2
index 093fb54cd316..9a7b91a3b7a7 100644
@@ -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
@@ -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;
 		}
 
Signature · 1 line
2.11.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#2 lore raw
Quoted 11 lines · Jan Kara
Quoted 10 lines · Ernesto A. Fernández

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.

Quoted 8 lines
Quoted 1 line

Good catch. The patch looks good. You can add:

Also Jens often picks up patches for direct IO code so added him to CC. Jens?

Looks good to me. Ernesto, did you run this through xfstests as well?

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 14 lines · Jens Axboe
Quoted 13 lines · Jan Kara
Quoted 11 lines · Ernesto A. Fernández

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.

Quoted 8 lines
Quoted 6 lines

Good catch. The patch looks good. You can add:

Also Jens often picks up patches for direct IO code so added him to CC. Jens?

Looks good to me. Ernesto, did you run this through xfstests as well?

I only ran the quick tests for ext2. Also for hfsplus, but those are not very meaningful because too many are failing.

Quoted 4 lines
Signature · 2 lines
-- 
Jens Axboe
#4 lore raw
Quoted 19 lines · Ernesto A. Fernández
Quoted 18 lines · Jens Axboe
Quoted 17 lines · Jan Kara
Quoted 11 lines · Ernesto A. Fernández

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.

Good catch. The patch looks good. You can add:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Also Jens often picks up patches for direct IO code so added him to CC. Jens?

Looks good to me. Ernesto, did you run this through xfstests as well?

I only ran the quick tests for ext2. Also for hfsplus, but those are not very meaningful because too many are failing.

OK, that's useful. I'll run it through the whole thing just in case, but I don't expect to find anything.

Signature · 1 line
Jens Axboe
#5 lore raw
Quoted 23 lines · Jens Axboe
Quoted 22 lines · Ernesto A. Fernández
Quoted 21 lines · Jens Axboe
Quoted 19 lines · Jan Kara
Quoted 11 lines · Ernesto A. Fernández

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.

Good catch. The patch looks good. You can add:

Also Jens often picks up patches for direct IO code so added him to CC. Jens?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Looks good to me. Ernesto, did you run this through xfstests as well?

I only ran the quick tests for ext2. Also for hfsplus, but those are not very meaningful because too many are failing.

OK, that's useful. I'll run it through the whole thing just in case, but I don't expect to find anything.

So what happened with this patch? Any issues?

Quoted 4 lines
Signature · 2 lines
-- 
Jens Axboe
#6 lore raw
Quoted 26 lines · Ernesto A. Fernández
Quoted 25 lines · Jens Axboe
Quoted 24 lines · Ernesto A. Fernández
Quoted 22 lines · Jens Axboe
Quoted 11 lines · Jan Kara
Quoted 10 lines · Ernesto A. Fernández

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.

Quoted 8 lines
Quoted 1 line

Good catch. The patch looks good. You can add:

Also Jens often picks up patches for direct IO code so added him to CC. Jens?

Looks good to me. Ernesto, did you run this through xfstests as well?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I only ran the quick tests for ext2. Also for hfsplus, but those are not very meaningful because too many are failing.

OK, that's useful. I'll run it through the whole thing just in case, but I don't expect to find anything.

So what happened with this patch? Any issues?

Ping?

Quoted 5 lines
Quoted 5 lines
Signature · 2 lines
-- 
Jens Axboe
#7 lore raw
Quoted 30 lines · Ernesto A. Fernández
Quoted 29 lines · Ernesto A. Fernández
Quoted 28 lines · Jens Axboe
Quoted 26 lines · Ernesto A. Fernández
Quoted 14 lines · Jens Axboe
Quoted 13 lines · Jan Kara
Quoted 11 lines · Ernesto A. Fernández

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.

Quoted 8 lines
Quoted 6 lines

Good catch. The patch looks good. You can add:

Also Jens often picks up patches for direct IO code so added him to CC. Jens?

Looks good to me. Ernesto, did you run this through xfstests as well?

I only ran the quick tests for ext2. Also for hfsplus, but those are not very meaningful because too many are failing.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

OK, that's useful. I'll run it through the whole thing just in case, but I don't expect to find anything.

So what happened with this patch? Any issues?

Ping?

Sorry, I dropped this one on the floor. Now queued up, thanks for the ping!

Signature · 1 line
Jens Axboe