Skip to content

Commit 1a61d74

Browse files
zhangyi089brauner
authored andcommitted
iomap: use a new variable to handle the written bytes in iomap_write_iter()
In iomap_write_iter(), the status variable used to receive the return value from iomap_write_end() is confusing, replace it with a new written variable to represent the written bytes in each cycle, no logic changes. Signed-off-by: Zhang Yi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 943bc08 commit 1a61d74

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

fs/iomap/buffered-io.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
889889
loff_t length = iomap_length(iter);
890890
size_t chunk = PAGE_SIZE << MAX_PAGECACHE_ORDER;
891891
loff_t pos = iter->pos;
892-
ssize_t written = 0;
892+
ssize_t total_written = 0;
893893
long status = 0;
894894
struct address_space *mapping = iter->inode->i_mapping;
895895
unsigned int bdp_flags = (iter->flags & IOMAP_NOWAIT) ? BDP_ASYNC : 0;
@@ -900,6 +900,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
900900
size_t offset; /* Offset into folio */
901901
size_t bytes; /* Bytes to write to folio */
902902
size_t copied; /* Bytes copied from user */
903+
size_t written; /* Bytes have been written */
903904

904905
bytes = iov_iter_count(i);
905906
retry:
@@ -944,7 +945,7 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
944945
flush_dcache_folio(folio);
945946

946947
copied = copy_folio_from_iter_atomic(folio, offset, bytes, i);
947-
status = iomap_write_end(iter, pos, bytes, copied, folio);
948+
written = iomap_write_end(iter, pos, bytes, copied, folio);
948949

949950
/*
950951
* Update the in-memory inode size after copying the data into
@@ -954,22 +955,22 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
954955
* unlock and release the folio.
955956
*/
956957
old_size = iter->inode->i_size;
957-
if (pos + status > old_size) {
958-
i_size_write(iter->inode, pos + status);
958+
if (pos + written > old_size) {
959+
i_size_write(iter->inode, pos + written);
959960
iter->iomap.flags |= IOMAP_F_SIZE_CHANGED;
960961
}
961-
__iomap_put_folio(iter, pos, status, folio);
962+
__iomap_put_folio(iter, pos, written, folio);
962963

963964
if (old_size < pos)
964965
pagecache_isize_extended(iter->inode, old_size, pos);
965-
if (status < bytes)
966-
iomap_write_failed(iter->inode, pos + status,
967-
bytes - status);
968-
if (unlikely(copied != status))
969-
iov_iter_revert(i, copied - status);
966+
if (written < bytes)
967+
iomap_write_failed(iter->inode, pos + written,
968+
bytes - written);
969+
if (unlikely(copied != written))
970+
iov_iter_revert(i, copied - written);
970971

971972
cond_resched();
972-
if (unlikely(status == 0)) {
973+
if (unlikely(written == 0)) {
973974
/*
974975
* A short copy made iomap_write_end() reject the
975976
* thing entirely. Might be memory poisoning
@@ -983,17 +984,17 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
983984
goto retry;
984985
}
985986
} else {
986-
pos += status;
987-
written += status;
988-
length -= status;
987+
pos += written;
988+
total_written += written;
989+
length -= written;
989990
}
990991
} while (iov_iter_count(i) && length);
991992

992993
if (status == -EAGAIN) {
993-
iov_iter_revert(i, written);
994+
iov_iter_revert(i, total_written);
994995
return -EAGAIN;
995996
}
996-
return written ? written : status;
997+
return total_written ? total_written : status;
997998
}
998999

9991000
ssize_t

0 commit comments

Comments
 (0)