提交 eec63c65 编写于 作者: D David Sterba

btrfs: separate defrag and property compression

Add new value for compression to distinguish between defrag and
property. Previously, a single variable was used and this caused clashes
when the per-file 'compression' was set and a defrag -c was called.

The property-compression is loaded when the file is open, defrag will
overwrite the same variable and reset to 0 (ie. NONE) at when the file
defragmentaion is finished. That's considered a usability bug.

Now we won't touch the property value, use the defrag-compression. The
precedence of defrag is higher than for property (and whole-filesystem).
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 b52aa8c9
...@@ -182,6 +182,11 @@ struct btrfs_inode { ...@@ -182,6 +182,11 @@ struct btrfs_inode {
* Cached values of inode properties * Cached values of inode properties
*/ */
unsigned prop_compress; /* per-file compression algorithm */ unsigned prop_compress; /* per-file compression algorithm */
/*
* Force compression on the file using the defrag ioctl, could be
* different from prop_compress and takes precedence if set
*/
unsigned defrag_compress;
struct btrfs_delayed_node *delayed_node; struct btrfs_delayed_node *delayed_node;
......
...@@ -402,6 +402,9 @@ static inline int inode_need_compress(struct inode *inode, u64 start, u64 end) ...@@ -402,6 +402,9 @@ static inline int inode_need_compress(struct inode *inode, u64 start, u64 end)
/* bad compression ratios */ /* bad compression ratios */
if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) if (BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS)
return 0; return 0;
/* defrag ioctl */
if (BTRFS_I(inode)->defrag_compress)
return 1;
if (btrfs_test_opt(fs_info, COMPRESS) || if (btrfs_test_opt(fs_info, COMPRESS) ||
BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS || BTRFS_I(inode)->flags & BTRFS_INODE_COMPRESS ||
BTRFS_I(inode)->prop_compress) BTRFS_I(inode)->prop_compress)
...@@ -511,7 +514,9 @@ static noinline void compress_file_range(struct inode *inode, ...@@ -511,7 +514,9 @@ static noinline void compress_file_range(struct inode *inode,
goto cont; goto cont;
} }
if (BTRFS_I(inode)->prop_compress) if (BTRFS_I(inode)->defrag_compress)
compress_type = BTRFS_I(inode)->defrag_compress;
else if (BTRFS_I(inode)->prop_compress)
compress_type = BTRFS_I(inode)->prop_compress; compress_type = BTRFS_I(inode)->prop_compress;
/* /*
...@@ -9434,6 +9439,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) ...@@ -9434,6 +9439,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
ei->runtime_flags = 0; ei->runtime_flags = 0;
ei->prop_compress = BTRFS_COMPRESS_NONE; ei->prop_compress = BTRFS_COMPRESS_NONE;
ei->defrag_compress = BTRFS_COMPRESS_NONE;
ei->delayed_node = NULL; ei->delayed_node = NULL;
......
...@@ -1371,7 +1371,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, ...@@ -1371,7 +1371,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
inode_lock(inode); inode_lock(inode);
if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)
BTRFS_I(inode)->prop_compress = compress_type; BTRFS_I(inode)->defrag_compress = compress_type;
ret = cluster_pages_for_defrag(inode, pages, i, cluster); ret = cluster_pages_for_defrag(inode, pages, i, cluster);
if (ret < 0) { if (ret < 0) {
inode_unlock(inode); inode_unlock(inode);
...@@ -1442,7 +1442,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, ...@@ -1442,7 +1442,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
out_ra: out_ra:
if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) { if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) {
inode_lock(inode); inode_lock(inode);
BTRFS_I(inode)->prop_compress = BTRFS_COMPRESS_NONE; BTRFS_I(inode)->defrag_compress = BTRFS_COMPRESS_NONE;
inode_unlock(inode); inode_unlock(inode);
} }
if (!file) if (!file)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册