linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Increment i_size after dio write completes
@ 2020-09-21 19:19 Goldwyn Rodrigues
  2020-10-05 13:14 ` Josef Bacik
  0 siblings, 1 reply; 2+ messages in thread
From: Goldwyn Rodrigues @ 2020-09-21 19:19 UTC (permalink / raw)
  To: linux-btrfs

i_size is incremented when btrfs creates new extents during the start of
a DIO write. If there is a failure until the endio, we will have a file
with incremented filesize but no data. Increment the filesize after the
successful completion of a DIO write.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 18d171b2d544..0f297e9679eb 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7309,13 +7309,6 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
 	len = min(len, em->len - (start - em->start));
 
 skip_cow:
-	/*
-	 * Need to update the i_size under the extent lock so buffered
-	 * readers will get the updated i_size when we unlock.
-	 */
-	if (start + len > i_size_read(inode))
-		i_size_write(inode, start + len);
-
 	dio_data->reserve -= len;
 out:
 	return ret;
@@ -7542,10 +7535,16 @@ static void btrfs_dio_private_put(struct btrfs_dio_private *dip)
 		return;
 
 	if (bio_op(dip->dio_bio) == REQ_OP_WRITE) {
-		__endio_write_update_ordered(BTRFS_I(dip->inode),
-					     dip->logical_offset,
-					     dip->bytes,
-					     !dip->dio_bio->bi_status);
+		u64 offset = dip->logical_offset;
+		u64 length = dip->bytes;
+		bool uptodate = !dip->dio_bio->bi_status;
+
+		/* Increment the filesize iff the DIO write is successful */
+		if (uptodate && i_size_read(dip->inode) < offset + length)
+			i_size_write(dip->inode, offset + length);
+
+		__endio_write_update_ordered(BTRFS_I(dip->inode), offset,
+				length, uptodate);
 	} else {
 		unlock_extent(&BTRFS_I(dip->inode)->io_tree,
 			      dip->logical_offset,

-- 
Goldwyn

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] btrfs: Increment i_size after dio write completes
  2020-09-21 19:19 [PATCH] btrfs: Increment i_size after dio write completes Goldwyn Rodrigues
@ 2020-10-05 13:14 ` Josef Bacik
  0 siblings, 0 replies; 2+ messages in thread
From: Josef Bacik @ 2020-10-05 13:14 UTC (permalink / raw)
  To: Goldwyn Rodrigues, linux-btrfs

On 9/21/20 3:19 PM, Goldwyn Rodrigues wrote:
> i_size is incremented when btrfs creates new extents during the start of
> a DIO write. If there is a failure until the endio, we will have a file
> with incremented filesize but no data. Increment the filesize after the
> successful completion of a DIO write.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 

We can't update the i_size outside of the i_mutex, this isn't ok.  Thanks,

Josef

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-05 13:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21 19:19 [PATCH] btrfs: Increment i_size after dio write completes Goldwyn Rodrigues
2020-10-05 13:14 ` Josef Bacik

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).