Skip to content

Commit 2f56a3f

Browse files
fs/ntfs3: Fixing work with sparse clusters
Simplify logic in ntfs_extend_initialized_size, ntfs_sparse_cluster and ntfs_fallocate. Signed-off-by: Konstantin Komarov <[email protected]>
1 parent ba11892 commit 2f56a3f

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

fs/ntfs3/file.c

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,9 @@ static int ntfs_extend_initialized_size(struct file *file,
128128
goto out;
129129

130130
if (lcn == SPARSE_LCN) {
131-
loff_t vbo = (loff_t)vcn << bits;
132-
loff_t to = vbo + ((loff_t)clen << bits);
133-
134-
if (to <= new_valid) {
135-
ni->i_valid = to;
136-
pos = to;
137-
goto next;
138-
}
139-
140-
if (vbo < pos) {
141-
pos = vbo;
142-
} else {
143-
to = (new_valid >> bits) << bits;
144-
if (pos < to) {
145-
ni->i_valid = to;
146-
pos = to;
147-
goto next;
148-
}
149-
}
131+
pos = ((loff_t)clen + vcn) << bits;
132+
ni->i_valid = pos;
133+
goto next;
150134
}
151135
}
152136

@@ -279,8 +263,9 @@ void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn,
279263
{
280264
struct address_space *mapping = inode->i_mapping;
281265
struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info;
282-
u64 vbo = (u64)vcn << sbi->cluster_bits;
283-
u64 bytes = (u64)len << sbi->cluster_bits;
266+
u8 cluster_bits = sbi->cluster_bits;
267+
u64 vbo = (u64)vcn << cluster_bits;
268+
u64 bytes = (u64)len << cluster_bits;
284269
u32 blocksize = 1 << inode->i_blkbits;
285270
pgoff_t idx0 = page0 ? page0->index : -1;
286271
loff_t vbo_clst = vbo & sbi->cluster_mask_inv;
@@ -329,19 +314,17 @@ void ntfs_sparse_cluster(struct inode *inode, struct page *page0, CLST vcn,
329314

330315
zero_user_segment(page, from, to);
331316

332-
if (!partial) {
333-
if (!PageUptodate(page))
334-
SetPageUptodate(page);
335-
set_page_dirty(page);
336-
}
317+
if (!partial)
318+
SetPageUptodate(page);
319+
flush_dcache_page(page);
320+
set_page_dirty(page);
337321

338322
if (idx != idx0) {
339323
unlock_page(page);
340324
put_page(page);
341325
}
342326
cond_resched();
343327
}
344-
mark_inode_dirty(inode);
345328
}
346329

347330
/*
@@ -588,11 +571,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
588571
u32 frame_size;
589572
loff_t mask, vbo_a, end_a, tmp;
590573

591-
err = filemap_write_and_wait_range(mapping, vbo, end - 1);
592-
if (err)
593-
goto out;
594-
595-
err = filemap_write_and_wait_range(mapping, end, LLONG_MAX);
574+
err = filemap_write_and_wait_range(mapping, vbo, LLONG_MAX);
596575
if (err)
597576
goto out;
598577

@@ -693,7 +672,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
693672
goto out;
694673

695674
if (is_supported_holes) {
696-
CLST vcn_v = ni->i_valid >> sbi->cluster_bits;
675+
CLST vcn_v = bytes_to_cluster(sbi, ni->i_valid);
697676
CLST vcn = vbo >> sbi->cluster_bits;
698677
CLST cend = bytes_to_cluster(sbi, end);
699678
CLST lcn, clen;

fs/ntfs3/inode.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,12 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo,
646646
bh->b_size = block_size;
647647
off = vbo & (PAGE_SIZE - 1);
648648
set_bh_page(bh, page, off);
649-
ll_rw_block(REQ_OP_READ, 1, &bh);
649+
650+
lock_buffer(bh);
651+
bh->b_end_io = end_buffer_read_sync;
652+
get_bh(bh);
653+
submit_bh(REQ_OP_READ, bh);
654+
650655
wait_on_buffer(bh);
651656
if (!buffer_uptodate(bh)) {
652657
err = -EIO;

0 commit comments

Comments
 (0)