All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: <linux-fsdevel@vger.kernel.org>
Cc: Jan Kara <jack@suse.cz>
Subject: [PATCH 5/7] udf: Move setting of i_lenExtents into udf_do_extend_file()
Date: Thu, 22 Dec 2022 11:16:02 +0100	[thread overview]
Message-ID: <20221222101612.18814-5-jack@suse.cz> (raw)
In-Reply-To: <20221222101300.12679-1-jack@suse.cz>

When expanding file for a write into a hole, we were not updating total
length of inode's extents properly. Move the update of i_lenExtents into
udf_do_extend_file() so that both expanding of file by truncate and
expanding of file by writing beyond EOF properly update the length of
extents. As a bonus, we also correctly update the length of extents when
only part of extents can be written.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/udf/inode.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 15b3e529854b..fe5b0ba600fa 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -419,6 +419,7 @@ static int udf_do_extend_file(struct inode *inode,
 			~(sb->s_blocksize - 1);
 	}
 
+	add = 0;
 	/* Can we merge with the previous extent? */
 	if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
 					EXT_NOT_RECORDED_NOT_ALLOCATED) {
@@ -451,6 +452,7 @@ static int udf_do_extend_file(struct inode *inode,
 		if (new_block_bytes)
 			udf_next_aext(inode, last_pos, &tmploc, &tmplen, 0);
 	}
+	iinfo->i_lenExtents += add;
 
 	/* Managed to do everything necessary? */
 	if (!new_block_bytes)
@@ -469,6 +471,7 @@ static int udf_do_extend_file(struct inode *inode,
 				   last_ext->extLength, 1);
 		if (err)
 			goto out_err;
+		iinfo->i_lenExtents += add;
 		count++;
 	}
 	if (new_block_bytes) {
@@ -478,6 +481,7 @@ static int udf_do_extend_file(struct inode *inode,
 				   last_ext->extLength, 1);
 		if (err)
 			goto out_err;
+		iinfo->i_lenExtents += new_block_bytes;
 		count++;
 	}
 
@@ -585,7 +589,6 @@ static int udf_extend_file(struct inode *inode, loff_t newsize)
 	if (err < 0)
 		goto out;
 	err = 0;
-	iinfo->i_lenExtents = newsize;
 out:
 	brelse(epos.bh);
 	return err;
-- 
2.35.3


  parent reply	other threads:[~2022-12-22 10:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-22 10:15 [PATCH 0/7] udf: Couple more fixes for extent and directory handling Jan Kara
2022-12-22 10:15 ` [PATCH 1/7] udf: Handle error when expanding directory Jan Kara
2022-12-22 10:15 ` [PATCH 2/7] udf: Handle error when adding extent to symlink Jan Kara
2022-12-22 10:16 ` [PATCH 3/7] udf: Handle error when adding extent to a file Jan Kara
2022-12-26  4:28   ` Nathan Chancellor
2023-01-02 12:51     ` Jan Kara
2022-12-22 10:16 ` [PATCH 4/7] udf: Allocate name buffer in directory iterator on heap Jan Kara
2022-12-22 10:16 ` Jan Kara [this message]
2022-12-22 10:16 ` [PATCH 6/7] udf: Fix extension of the last extent in the file Jan Kara
2022-12-22 10:16 ` [PATCH 7/7] udf: Keep i_lenExtents consistent with the total length of extents Jan Kara

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=20221222101612.18814-5-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.