Skip to content

Commit b432163

Browse files
fs/ntfs3: Update inode->i_mapping->a_ops on compression state
Update inode->i_mapping->a_ops when the compression state changes to ensure correct address space operations. Clear ATTR_FLAG_SPARSED/FILE_ATTRIBUTE_SPARSE_FILE when enabling compression to prevent flag conflicts. v2: Additionally, ensure that all dirty pages are flushed and concurrent access to the page cache is blocked. Fixes: 6b39bfa ("fs/ntfs3: Add support for the compression attribute") Reported-by: Kun Hu <huk23@m.fudan.edu.cn>, Jiaji Qin <jjtan24@m.fudan.edu.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent ff35592 commit b432163

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

fs/ntfs3/attrib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2664,8 +2664,9 @@ int attr_set_compress(struct ntfs_inode *ni, bool compr)
26642664
attr->nres.run_off = cpu_to_le16(run_off);
26652665
}
26662666

2667-
/* Update data attribute flags. */
2667+
/* Update attribute flags. */
26682668
if (compr) {
2669+
attr->flags &= ~ATTR_FLAG_SPARSED;
26692670
attr->flags |= ATTR_FLAG_COMPRESSED;
26702671
attr->nres.c_unit = NTFS_LZNT_CUNIT;
26712672
} else {

fs/ntfs3/file.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,26 @@ int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
101101
/* Allowed to change compression for empty files and for directories only. */
102102
if (!is_dedup(ni) && !is_encrypted(ni) &&
103103
(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
104-
/* Change compress state. */
105-
int err = ni_set_compress(inode, flags & FS_COMPR_FL);
104+
int err = 0;
105+
struct address_space *mapping = inode->i_mapping;
106+
107+
/* write out all data and wait. */
108+
filemap_invalidate_lock(mapping);
109+
err = filemap_write_and_wait(mapping);
110+
111+
if (err >= 0) {
112+
/* Change compress state. */
113+
bool compr = flags & FS_COMPR_FL;
114+
err = ni_set_compress(inode, compr);
115+
116+
/* For files change a_ops too. */
117+
if (!err)
118+
mapping->a_ops = compr ? &ntfs_aops_cmpr :
119+
&ntfs_aops;
120+
}
121+
122+
filemap_invalidate_unlock(mapping);
123+
106124
if (err)
107125
return err;
108126
}

fs/ntfs3/frecord.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3434,10 +3434,12 @@ int ni_set_compress(struct inode *inode, bool compr)
34343434
}
34353435

34363436
ni->std_fa = std->fa;
3437-
if (compr)
3437+
if (compr) {
3438+
std->fa &= ~FILE_ATTRIBUTE_SPARSE_FILE;
34383439
std->fa |= FILE_ATTRIBUTE_COMPRESSED;
3439-
else
3440+
} else {
34403441
std->fa &= ~FILE_ATTRIBUTE_COMPRESSED;
3442+
}
34413443

34423444
if (ni->std_fa != std->fa) {
34433445
ni->std_fa = std->fa;

0 commit comments

Comments
 (0)