From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: <ntfs3@lists.linux.dev>
Cc: <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>
Subject: [PATCH 01/14] fs/ntfs3: Fixing work with sparse clusters
Date: Fri, 28 Oct 2022 20:01:47 +0300 [thread overview]
Message-ID: <f34ec7a5-0b16-6de0-509c-34c17e780db1@paragon-software.com> (raw)
In-Reply-To: <fc5957cc-a71b-cfa3-f291-cb63b23800d1@paragon-software.com>
Simplify logic in ntfs_extend_initialized_size, ntfs_sparse_cluster
and ntfs_fallocate.
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
fs/ntfs3/file.c | 45 ++++++++++++---------------------------------
fs/ntfs3/inode.c | 7 ++++++-
2 files changed, 18 insertions(+), 34 deletions(-)
diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index 4f2ffc7ef296..96ba3f5a8470 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -128,25 +128,9 @@ static int ntfs_extend_initialized_size(struct file *file,
goto out;
if (lcn == SPARSE_LCN) {
- loff_t vbo = (loff_t)vcn << bits;
- loff_t to = vbo + ((loff_t)clen << bits);
-
- if (to <= new_valid) {
- ni->i_valid = to;
- pos = to;
- goto next;
- }
-
- if (vbo < pos) {
- pos = vbo;
- } else {
- to = (new_valid >> bits) << bits;
- if (pos < to) {
- ni->i_valid = to;
- pos = to;
- goto next;
- }
- }
+ pos = ((loff_t)clen + vcn) << bits;
+ ni->i_valid = pos;
+ goto next;
}
}
@@ -279,8 +263,9 @@ void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn,
{
struct address_space *mapping = inode->i_mapping;
struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info;
- u64 vbo = (u64)vcn << sbi->cluster_bits;
- u64 bytes = (u64)len << sbi->cluster_bits;
+ u8 cluster_bits = sbi->cluster_bits;
+ u64 vbo = (u64)vcn << cluster_bits;
+ u64 bytes = (u64)len << cluster_bits;
u32 blocksize = 1 << inode->i_blkbits;
pgoff_t idx0 = page0 ? page0->index : -1;
loff_t vbo_clst = vbo & sbi->cluster_mask_inv;
@@ -329,11 +314,10 @@ void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn,
zero_user_segment(page, from, to);
- if (!partial) {
- if (!PageUptodate(page))
- SetPageUptodate(page);
- set_page_dirty(page);
- }
+ if (!partial)
+ SetPageUptodate(page);
+ flush_dcache_page(page);
+ set_page_dirty(page);
if (idx != idx0) {
unlock_page(page);
@@ -341,7 +325,6 @@ void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn,
}
cond_resched();
}
- mark_inode_dirty(inode);
}
/*
@@ -588,11 +571,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
u32 frame_size;
loff_t mask, vbo_a, end_a, tmp;
- err = filemap_write_and_wait_range(mapping, vbo, end - 1);
- if (err)
- goto out;
-
- err = filemap_write_and_wait_range(mapping, end, LLONG_MAX);
+ err = filemap_write_and_wait_range(mapping, vbo, LLONG_MAX);
if (err)
goto out;
@@ -693,7 +672,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
goto out;
if (is_supported_holes) {
- CLST vcn_v = ni->i_valid >> sbi->cluster_bits;
+ CLST vcn_v = bytes_to_cluster(sbi, ni->i_valid);
CLST vcn = vbo >> sbi->cluster_bits;
CLST cend = bytes_to_cluster(sbi, end);
CLST lcn, clen;
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index e9cf00d14733..f487d36c9b78 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -645,7 +645,12 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo,
bh->b_size = block_size;
off = vbo & (PAGE_SIZE - 1);
set_bh_page(bh, page, off);
- ll_rw_block(REQ_OP_READ, 1, &bh);
+
+ lock_buffer(bh);
+ bh->b_end_io = end_buffer_read_sync;
+ get_bh(bh);
+ submit_bh(REQ_OP_READ, bh);
+
wait_on_buffer(bh);
if (!buffer_uptodate(bh)) {
err = -EIO;
--
2.37.0
next prev parent reply other threads:[~2022-10-28 17:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-28 17:00 [PATCH 00/14] fs/ntfs3: Additional bugfix and refactoring Konstantin Komarov
2022-10-28 17:01 ` Konstantin Komarov [this message]
2022-10-28 17:02 ` [PATCH 02/14] fs/ntfs3: Change new sparse cluster processing Konstantin Komarov
2022-10-28 17:02 ` [PATCH 03/14] fs/ntfs3: Fix wrong indentations Konstantin Komarov
2022-10-28 17:03 ` [PATCH 04/14] fs/ntfs3: atomic_open implementation Konstantin Komarov
2022-10-28 17:03 ` [PATCH 05/14] fs/ntfs3: Fixing wrong logic in attr_set_size and ntfs_fallocate Konstantin Komarov
2022-10-28 17:04 ` [PATCH 06/14] fs/ntfs3: Changing locking in ntfs_rename Konstantin Komarov
2022-10-28 17:04 ` [PATCH 07/14] fs/ntfs3: Restore correct state after ENOSPC in attr_data_get_block Konstantin Komarov
2022-10-28 17:05 ` [PATCH 08/14] fs/ntfs3: Correct ntfs_check_for_free_space Konstantin Komarov
2022-10-28 17:05 ` [PATCH 09/14] fs/ntfs3: Check fields while reading Konstantin Komarov
2023-06-19 9:41 ` Lee Jones
2023-06-27 13:49 ` Lee Jones
2022-10-28 17:06 ` [PATCH 10/14] fs/ntfs3: Fix incorrect if in ntfs_set_acl_ex Konstantin Komarov
2022-10-28 17:06 ` [PATCH 11/14] fs/ntfs3: Use ALIGN kernel macro Konstantin Komarov
2022-10-28 17:07 ` [PATCH 12/14] fs/ntfs3: Fix wrong if in hdr_first_de Konstantin Komarov
2022-10-28 17:07 ` [PATCH 13/14] fs/ntfs3: Improve checking of bad clusters Konstantin Komarov
2022-10-28 17:08 ` [PATCH 14/14] fs/ntfs3: Make if more readable Konstantin Komarov
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=f34ec7a5-0b16-6de0-509c-34c17e780db1@paragon-software.com \
--to=almaz.alexandrovich@paragon-software.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
/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 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).