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 18/22] udf: Protect truncate and file type conversion with invalidate_lock
Date: Tue, 24 Jan 2023 13:18:04 +0100	[thread overview]
Message-ID: <20230124121814.25951-18-jack@suse.cz> (raw)
In-Reply-To: <20230124120835.21728-1-jack@suse.cz>

Protect truncate and file type conversion in udf_file_write_iter() with
invalidate lock. That will allow us to serialize these paths with page
faults so that the page fault can determine the file type in a racefree
way.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/udf/file.c  |  2 ++
 fs/udf/inode.c | 15 +++++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/fs/udf/file.c b/fs/udf/file.c
index 596d703fb6c8..cf050bdffd9e 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -150,7 +150,9 @@ static ssize_t udf_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB &&
 	    inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
 				 iocb->ki_pos + iov_iter_count(from))) {
+		filemap_invalidate_lock(inode->i_mapping);
 		retval = udf_expand_file_adinicb(inode);
+		filemap_invalidate_unlock(inode->i_mapping);
 		if (retval)
 			goto out;
 	}
diff --git a/fs/udf/inode.c b/fs/udf/inode.c
index 3ffeb5651689..7109adcceefe 100644
--- a/fs/udf/inode.c
+++ b/fs/udf/inode.c
@@ -1145,7 +1145,7 @@ struct buffer_head *udf_bread(struct inode *inode, udf_pblk_t block,
 
 int udf_setsize(struct inode *inode, loff_t newsize)
 {
-	int err;
+	int err = 0;
 	struct udf_inode_info *iinfo;
 	unsigned int bsize = i_blocksize(inode);
 
@@ -1155,6 +1155,7 @@ int udf_setsize(struct inode *inode, loff_t newsize)
 	if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
 		return -EPERM;
 
+	filemap_invalidate_lock(inode->i_mapping);
 	iinfo = UDF_I(inode);
 	if (newsize > inode->i_size) {
 		if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
@@ -1167,11 +1168,11 @@ int udf_setsize(struct inode *inode, loff_t newsize)
 			}
 			err = udf_expand_file_adinicb(inode);
 			if (err)
-				return err;
+				goto out_unlock;
 		}
 		err = udf_extend_file(inode, newsize);
 		if (err)
-			return err;
+			goto out_unlock;
 set_size:
 		truncate_setsize(inode, newsize);
 	} else {
@@ -1189,14 +1190,14 @@ int udf_setsize(struct inode *inode, loff_t newsize)
 		err = block_truncate_page(inode->i_mapping, newsize,
 					  udf_get_block);
 		if (err)
-			return err;
+			goto out_unlock;
 		truncate_setsize(inode, newsize);
 		down_write(&iinfo->i_data_sem);
 		udf_clear_extent_cache(inode);
 		err = udf_truncate_extents(inode);
 		up_write(&iinfo->i_data_sem);
 		if (err)
-			return err;
+			goto out_unlock;
 	}
 update_time:
 	inode->i_mtime = inode->i_ctime = current_time(inode);
@@ -1204,7 +1205,9 @@ int udf_setsize(struct inode *inode, loff_t newsize)
 		udf_sync_inode(inode);
 	else
 		mark_inode_dirty(inode);
-	return 0;
+out_unlock:
+	filemap_invalidate_unlock(inode->i_mapping);
+	return err;
 }
 
 /*
-- 
2.35.3


  parent reply	other threads:[~2023-01-24 12:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 12:17 [PATCH 0/22] udf: Fix couple of preallocation related bugs Jan Kara
2023-01-24 12:17 ` [PATCH 01/22] udf: Unify types in anchor block detection Jan Kara
2023-01-24 12:17 ` [PATCH 02/22] udf: Drop VARCONV support Jan Kara
2023-01-24 12:17 ` [PATCH 03/22] udf: Move incrementing of goal block directly into inode_getblk() Jan Kara
2023-01-24 12:17 ` [PATCH 04/22] udf: Factor out block mapping into udf_map_block() Jan Kara
2023-01-24 12:17 ` [PATCH 05/22] udf: Use udf_bread() in udf_get_pblock_virt15() Jan Kara
2023-01-24 12:17 ` [PATCH 06/22] udf: Use udf_bread() in udf_load_vat() Jan Kara
2023-01-24 12:17 ` [PATCH 07/22] udf: Do not call udf_block_map() on ICB files Jan Kara
2023-01-24 12:17 ` [PATCH 08/22] udf: Convert udf_symlink_filler() to use udf_bread() Jan Kara
2023-01-24 12:17 ` [PATCH 09/22] udf: Fold udf_block_map() into udf_map_block() Jan Kara
2023-01-24 12:17 ` [PATCH 10/22] udf: Pass mapping request into inode_getblk() Jan Kara
2023-01-24 12:17 ` [PATCH 11/22] udf: Add flag to disable block preallocation Jan Kara
2023-01-24 12:17 ` [PATCH 12/22] udf: Use udf_map_block() in udf_getblk() Jan Kara
2023-01-24 12:17 ` [PATCH 13/22] udf: Fold udf_getblk() into udf_bread() Jan Kara
2023-01-24 12:18 ` [PATCH 14/22] udf: Protect rename against modification of moved directory Jan Kara
2023-01-24 12:18 ` [PATCH 15/22] udf: Push i_data_sem locking into udf_expand_file_adinicb() Jan Kara
2023-01-24 12:18 ` [PATCH 16/22] udf: Push i_data_sem locking into udf_extend_file() Jan Kara
2023-01-24 12:18 ` [PATCH 17/22] udf: Simplify error handling in udf_file_write_iter() Jan Kara
2023-01-24 12:18 ` Jan Kara [this message]
2023-01-24 12:18 ` [PATCH 19/22] udf: Allocate blocks on write page fault Jan Kara
2023-01-24 12:18 ` [PATCH 20/22] udf: Do not allocate blocks on page writeback Jan Kara
2023-01-24 12:18 ` [PATCH 21/22] udf: Fix file corruption when appending just after end of preallocated extent Jan Kara
2023-01-24 12:18 ` [PATCH 22/22] udf: Fix off-by-one error when discarding preallocation 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=20230124121814.25951-18-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.