mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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: 6b39bfaeec ("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>
			
			
This commit is contained in:
		
							parent
							
								
									ff35592644
								
							
						
					
					
						commit
						b432163ebd
					
				
					 3 changed files with 26 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -2664,8 +2664,9 @@ int attr_set_compress(struct ntfs_inode *ni, bool compr)
 | 
			
		|||
		attr->nres.run_off = cpu_to_le16(run_off);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* Update data attribute flags. */
 | 
			
		||||
	/* Update attribute flags. */
 | 
			
		||||
	if (compr) {
 | 
			
		||||
		attr->flags &= ~ATTR_FLAG_SPARSED;
 | 
			
		||||
		attr->flags |= ATTR_FLAG_COMPRESSED;
 | 
			
		||||
		attr->nres.c_unit = NTFS_LZNT_CUNIT;
 | 
			
		||||
	} else {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -101,8 +101,26 @@ int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
 | 
			
		|||
	/* Allowed to change compression for empty files and for directories only. */
 | 
			
		||||
	if (!is_dedup(ni) && !is_encrypted(ni) &&
 | 
			
		||||
	    (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) {
 | 
			
		||||
		int err = 0;
 | 
			
		||||
		struct address_space *mapping = inode->i_mapping;
 | 
			
		||||
 | 
			
		||||
		/* write out all data and wait. */
 | 
			
		||||
		filemap_invalidate_lock(mapping);
 | 
			
		||||
		err = filemap_write_and_wait(mapping);
 | 
			
		||||
 | 
			
		||||
		if (err >= 0) {
 | 
			
		||||
			/* Change compress state. */
 | 
			
		||||
		int err = ni_set_compress(inode, flags & FS_COMPR_FL);
 | 
			
		||||
			bool compr = flags & FS_COMPR_FL;
 | 
			
		||||
			err = ni_set_compress(inode, compr);
 | 
			
		||||
 | 
			
		||||
			/* For files change a_ops too. */
 | 
			
		||||
			if (!err)
 | 
			
		||||
				mapping->a_ops = compr ? &ntfs_aops_cmpr :
 | 
			
		||||
							 &ntfs_aops;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		filemap_invalidate_unlock(mapping);
 | 
			
		||||
 | 
			
		||||
		if (err)
 | 
			
		||||
			return err;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3434,10 +3434,12 @@ int ni_set_compress(struct inode *inode, bool compr)
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	ni->std_fa = std->fa;
 | 
			
		||||
	if (compr)
 | 
			
		||||
	if (compr) {
 | 
			
		||||
		std->fa &= ~FILE_ATTRIBUTE_SPARSE_FILE;
 | 
			
		||||
		std->fa |= FILE_ATTRIBUTE_COMPRESSED;
 | 
			
		||||
	else
 | 
			
		||||
	} else {
 | 
			
		||||
		std->fa &= ~FILE_ATTRIBUTE_COMPRESSED;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (ni->std_fa != std->fa) {
 | 
			
		||||
		ni->std_fa = std->fa;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue