Skip to contentSkip to conversation

direct-io: Minor cleanups in do_blockdev_direct_IO

PATCH In review Nikolay Borisov 2 participants 3 messages Feb 26, 2018 – Mar 3, 2018 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 direct-io: Minor cleanups in do_blockdev_direct_IO

We already get the block counts and the calculate the end block at the beginning of the function. Let's use the local variables for consistency and readability. No functional changes

---
Andrew,

Sending to you since this has been languishing on the mailing for quite some time. The patch has been reviewed here:
https://www.mail-archive.com/[email protected]/msg1460544.html

fs/direct-io.c | 5 ++---

 1 file changed, 2 insertions(+), 3 deletions(-)
fs/direct-io.c +2 -3
index a8131087aa1c..a73448a501c2 100644
@@ -1200,7 +1200,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 	}
 
 	/* watch out for a 0 len io from a tricksy fs */
-	if (iov_iter_rw(iter) == READ && !iov_iter_count(iter))
+	if (iov_iter_rw(iter) == READ && !count)
 		return 0;
 
 	dio = kmem_cache_alloc(dio_cache, GFP_KERNEL);
@@ -1316,8 +1316,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 
 	dio->should_dirty = (iter->type == ITER_IOVEC);
 	sdio.iter = iter;
-	sdio.final_block_in_request =
-		(offset + iov_iter_count(iter)) >> blkbits;
+	sdio.final_block_in_request = end >> blkbits;
 
 	/*
 	 * In case of non-aligned buffers, we may need 2 more
Signature · 1 line
2.7.4
#1 lore raw
Quoted 4 lines · On Mon, 26 Feb 2018 11:54:30 +0200 Nikolay Borisov <[email protected]> wrote:

We already get the block counts and the calculate the end block at the beginning of the function. Let's use the local variables for consistency and readability. No functional changes

Fair enough.

Quoted 12 lines
fs/direct-io.c +1 -1
@@ -1200,7 +1200,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 	}
 
 	/* watch out for a 0 len io from a tricksy fs */
-	if (iov_iter_rw(iter) == READ && !iov_iter_count(iter))
+	if (iov_iter_rw(iter) == READ && !count)
 		return 0;
 
 	dio = kmem_cache_alloc(dio_cache, GFP_KERNEL);

fs/direct-io.c do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, · line 1322

Quoted 9 lines
fs/direct-io.c +1 -2
@@ -1316,8 +1316,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 
 	dio->should_dirty = (iter->type == ITER_IOVEC);
 	sdio.iter = iter;
-	sdio.final_block_in_request =
-		(offset + iov_iter_count(iter)) >> blkbits;
+	sdio.final_block_in_request = end >> blkbits;
 
 	/*
 	 * In case of non-aligned buffers, we may need 2 more

It's always scary to see a local being used in this fashion so far away from where it was initialized. However, we can get our warm fuzzy feelings by doing this:

fs/direct-io.c renamed from fs/direct-io.c~direct-io-minor-cleanups-in-do_blockdev_direct_io-fix +2 -2
@@ -1178,9 +1178,9 @@ do_blockdev_direct_IO(struct kiocb *iocb
 	unsigned blkbits = i_blkbits;
 	unsigned blocksize_mask = (1 << blkbits) - 1;
 	ssize_t retval = -EINVAL;
-	size_t count = iov_iter_count(iter);
+	const size_t count = iov_iter_count(iter);
 	loff_t offset = iocb->ki_pos;
-	loff_t end = offset + count;
+	const loff_t end = offset + count;
 	struct dio *dio;
 	struct dio_submit sdio = { 0, };
 	struct buffer_head map_bh = { 0, };

_

#2 lore raw
Quoted 28 lines · Andrew Morton
Quoted 4 lines · On Mon, 26 Feb 2018 11:54:30 +0200 Nikolay Borisov <[email protected]> wrote:

We already get the block counts and the calculate the end block at the beginning of the function. Let's use the local variables for consistency and readability. No functional changes

Fair enough.

Quoted 19 lines
fs/direct-io.c +2 -3
@@ -1200,7 +1200,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 	}
 
 	/* watch out for a 0 len io from a tricksy fs */
-	if (iov_iter_rw(iter) == READ && !iov_iter_count(iter))
+	if (iov_iter_rw(iter) == READ && !count)
 		return 0;
 
 	dio = kmem_cache_alloc(dio_cache, GFP_KERNEL);
@@ -1316,8 +1316,7 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode,
 
 	dio->should_dirty = (iter->type == ITER_IOVEC);
 	sdio.iter = iter;
-	sdio.final_block_in_request =
-		(offset + iov_iter_count(iter)) >> blkbits;
+	sdio.final_block_in_request = end >> blkbits;
 
Quoted 7 lines

fs/direct-io.c do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, · line 1322

Quoted 2 lines
fs/direct-io.c +0 -0
 	/*
 	 * In case of non-aligned buffers, we may need 2 more

It's always scary to see a local being used in this fashion so far away from where it was initialized. However, we can get our warm fuzzy feelings by doing this:

Good point !

Quoted 14 lines
fs/direct-io.c renamed from fs/direct-io.c~direct-io-minor-cleanups-in-do_blockdev_direct_io-fix +2 -2
@@ -1178,9 +1178,9 @@ do_blockdev_direct_IO(struct kiocb *iocb
 	unsigned blkbits = i_blkbits;
 	unsigned blocksize_mask = (1 << blkbits) - 1;
 	ssize_t retval = -EINVAL;
-	size_t count = iov_iter_count(iter);
+	const size_t count = iov_iter_count(iter);
 	loff_t offset = iocb->ki_pos;
-	loff_t end = offset + count;
+	const loff_t end = offset + count;
 	struct dio *dio;
 	struct dio_submit sdio = { 0, };
 	struct buffer_head map_bh = { 0, };
Quoted 1 line

_

I assume you don't want me to resend but will just fold the changes yourself?

Quoted 2 lines