Skip to content

Commit c09767a

Browse files
osandovkdave
authored andcommitted
btrfs: use correct count in btrfs_file_write_iter()
generic_write_checks() may modify iov_iter_count(), so we must get the count after the call, not before. Using the wrong one has a couple of consequences: 1. We check a longer range in check_can_nocow() for nowait than we're actually writing. 2. We create extra hole extent maps in btrfs_cont_expand(). As far as I can tell, this is harmless, but I might be missing something. These issues are pretty minor, but let's fix it before something more important trips on it. Fixes: edf064e ("btrfs: nowait aio support") Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Omar Sandoval <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c82f823 commit c09767a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/btrfs/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,
18851885
bool sync = (file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host);
18861886
ssize_t err;
18871887
loff_t pos;
1888-
size_t count = iov_iter_count(from);
1888+
size_t count;
18891889
loff_t oldsize;
18901890
int clean_page = 0;
18911891

@@ -1906,6 +1906,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,
19061906
}
19071907

19081908
pos = iocb->ki_pos;
1909+
count = iov_iter_count(from);
19091910
if (iocb->ki_flags & IOCB_NOWAIT) {
19101911
/*
19111912
* We will allocate space in case nodatacow is not set,

0 commit comments

Comments
 (0)