Skip to content

Commit c0adf8c

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
iomap: factor out a iomap_last_written_block helper
Split out a pice of logic from iomap_file_buffered_write_punch_delalloc that is useful for all iomap_end implementations. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent 0fb823f commit c0adf8c

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

fs/iomap/buffered-io.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,6 @@ void iomap_file_buffered_write_punch_delalloc(struct inode *inode,
12801280
{
12811281
loff_t start_byte;
12821282
loff_t end_byte;
1283-
unsigned int blocksize = i_blocksize(inode);
12841283

12851284
if (iomap->type != IOMAP_DELALLOC)
12861285
return;
@@ -1289,16 +1288,8 @@ void iomap_file_buffered_write_punch_delalloc(struct inode *inode,
12891288
if (!(iomap->flags & IOMAP_F_NEW))
12901289
return;
12911290

1292-
/*
1293-
* start_byte refers to the first unused block after a short write. If
1294-
* nothing was written, round offset down to point at the first block in
1295-
* the range.
1296-
*/
1297-
if (unlikely(!written))
1298-
start_byte = round_down(pos, blocksize);
1299-
else
1300-
start_byte = round_up(pos + written, blocksize);
1301-
end_byte = round_up(pos + length, blocksize);
1291+
start_byte = iomap_last_written_block(inode, pos, written);
1292+
end_byte = round_up(pos + length, i_blocksize(inode));
13021293

13031294
/* Nothing to do if we've written the entire delalloc extent */
13041295
if (start_byte >= end_byte)

include/linux/iomap.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ static inline const struct iomap *iomap_iter_srcmap(const struct iomap_iter *i)
256256
return &i->iomap;
257257
}
258258

259+
/*
260+
* Return the file offset for the first unchanged block after a short write.
261+
*
262+
* If nothing was written, round @pos down to point at the first block in
263+
* the range, else round up to include the partially written block.
264+
*/
265+
static inline loff_t iomap_last_written_block(struct inode *inode, loff_t pos,
266+
ssize_t written)
267+
{
268+
if (unlikely(!written))
269+
return round_down(pos, i_blocksize(inode));
270+
return round_up(pos + written, i_blocksize(inode));
271+
}
272+
259273
ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from,
260274
const struct iomap_ops *ops, void *private);
261275
int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops);

0 commit comments

Comments
 (0)