linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fabian Frederick <fabf@skynet.be>
To: tytso@mit.edu, Andreas Dilger <adilger.kernel@dilger.ca>
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, fabf@skynet.be
Subject: [PATCH 3/6 linux-next] ext4: create EXT4_MAX_BLOCKS() macro
Date: Wed, 24 Aug 2016 22:03:17 +0200	[thread overview]
Message-ID: <1472069000-18897-4-git-send-email-fabf@skynet.be> (raw)
In-Reply-To: <1472069000-18897-1-git-send-email-fabf@skynet.be>

Create a macro to calculate length + offset -> maximum blocks
This adds more readability.

Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 fs/ext4/ext4.h    |  3 +++
 fs/ext4/extents.c | 15 +++------------
 fs/ext4/file.c    |  3 +--
 3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index ea31931..6e98f3f 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -262,6 +262,9 @@ struct ext4_io_submit {
 				 (s)->s_first_ino)
 #endif
 #define EXT4_BLOCK_ALIGN(size, blkbits)		ALIGN((size), (1 << (blkbits)))
+#define EXT4_MAX_BLOCKS(size, offset, blkbits) \
+	((EXT4_BLOCK_ALIGN(size + offset, blkbits) >> blkbits) - (offset >> \
+								  blkbits))
 
 /* Translate a block number to a cluster number */
 #define EXT4_B2C(sbi, blk)	((blk) >> (sbi)->s_cluster_bits)
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 4f1cca8..ac54907 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4960,13 +4960,8 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
 
 	trace_ext4_fallocate_enter(inode, offset, len, mode);
 	lblk = offset >> blkbits;
-	/*
-	 * We can't just convert len to max_blocks because
-	 * If blocksize = 4096 offset = 3072 and len = 2048
-	 */
-	max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits)
-		- lblk;
 
+	max_blocks = EXT4_MAX_BLOCKS(len, offset, blkbits);
 	flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT;
 	if (mode & FALLOC_FL_KEEP_SIZE)
 		flags |= EXT4_GET_BLOCKS_KEEP_SIZE;
@@ -5029,12 +5024,8 @@ int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
 	unsigned int credits, blkbits = inode->i_blkbits;
 
 	map.m_lblk = offset >> blkbits;
-	/*
-	 * We can't just convert len to max_blocks because
-	 * If blocksize = 4096 offset = 3072 and len = 2048
-	 */
-	max_blocks = ((EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) -
-		      map.m_lblk);
+	max_blocks = EXT4_MAX_BLOCKS(len, offset, blkbits);
+
 	/*
 	 * This is somewhat ugly but the idea is clear: When transaction is
 	 * reserved, everything goes into it. Otherwise we rather start several
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 261ac37..34acda7 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -144,8 +144,7 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
 			int err, len;
 
 			map.m_lblk = pos >> blkbits;
-			map.m_len = (EXT4_BLOCK_ALIGN(pos + length, blkbits) >> blkbits)
-				- map.m_lblk;
+			map.m_len = EXT4_MAX_BLOCKS(length, pos, blkbits);
 			len = map.m_len;
 
 			err = ext4_map_blocks(NULL, inode, &map, 0);
-- 
2.8.1

  parent reply	other threads:[~2016-08-24 20:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-24 20:03 [PATCH 0/6 linux-next] ext4: fix extent leaking and clean-up Fabian Frederick
2016-08-24 20:03 ` [PATCH 1/6 linux-next] ext4: avoid EXT4_INODE_EXTENTS double checking Fabian Frederick
2016-09-15 15:43   ` Theodore Ts'o
2016-08-24 20:03 ` [PATCH 2/6 linux-next] ext4: remove unneeded test in ext4_alloc_file_blocks() Fabian Frederick
2016-09-15 15:52   ` Theodore Ts'o
2016-08-24 20:03 ` Fabian Frederick [this message]
2016-09-15 15:55   ` [PATCH 3/6 linux-next] ext4: create EXT4_MAX_BLOCKS() macro Theodore Ts'o
2016-08-24 20:03 ` [PATCH 4/6 linux-next] ext4: use bool for check in ext4_ext_space_() Fabian Frederick
2016-09-15 15:57   ` Theodore Ts'o
2016-08-24 20:03 ` [PATCH 5/6 linux-next] ext4: remove unused definition Fabian Frederick
2016-09-15 15:59   ` Theodore Ts'o
2016-08-24 20:03 ` [PATCH 6/6 linux-next] ext4: fix memory leak in ext4_insert_range() Fabian Frederick
2016-09-15 15:40   ` Theodore Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472069000-18897-4-git-send-email-fabf@skynet.be \
    --to=fabf@skynet.be \
    --cc=adilger.kernel@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).