From: Naohiro Aota <naota@xxxxxxxxx>
Fix the following two problems in compression related ioctl() code.
a) Updating compression flags and updating inode attribute
in two separated transaction. So, if something bad happens
after the former, and before the latter, file system
would become inconsistent state.
This patch move them into one transaction.
b) It updates compression flags here and calls btrfs_set_prop()
after that. However flags are also updated in this function.
This patch removes the duplicated code for updating flags
from ioctl code and aggregates this work to
btrfs_set_prop_trans() at all.
Signed-off-by: Naohiro Aota <naota@xxxxxxxxx>
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@xxxxxxxxxxxxxx>
---
changelog
v1->v2: Reflect the following comment from David
https://www.mail-archive.com/linux-btrfs@xxxxxxxxxxxxxxx/msg37513.html
---
fs/btrfs/ioctl.c | 32 +++++++++++---------------------
1 file changed, 11 insertions(+), 21 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0ff2127..40a0fdd 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -221,6 +221,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
u64 ip_oldflags;
unsigned int i_oldflags;
umode_t mode;
+ const char *comp;
if (!inode_owner_or_capable(inode))
return -EPERM;
@@ -310,40 +311,29 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
* things smaller.
*/
if (flags & FS_NOCOMP_FL) {
- ip->flags &= ~BTRFS_INODE_COMPRESS;
- ip->flags |= BTRFS_INODE_NOCOMPRESS;
-
- ret = btrfs_set_prop(inode, "btrfs.compression", NULL, 0, 0);
- if (ret && ret != -ENODATA)
- goto out_drop;
+ comp = "off";
} else if (flags & FS_COMPR_FL) {
- const char *comp;
-
- ip->flags |= BTRFS_INODE_COMPRESS;
- ip->flags &= ~BTRFS_INODE_NOCOMPRESS;
-
if (root->fs_info->compress_type == BTRFS_COMPRESS_LZO)
comp = "lzo";
else
comp = "zlib";
- ret = btrfs_set_prop(inode, "btrfs.compression",
- comp, strlen(comp), 0);
- if (ret)
- goto out_drop;
-
} else {
- ret = btrfs_set_prop(inode, "btrfs.compression", NULL, 0, 0);
- if (ret && ret != -ENODATA)
- goto out_drop;
- ip->flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS);
+ comp = "";
}
- trans = btrfs_start_transaction(root, 1);
+ trans = btrfs_start_transaction(root, 2);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
goto out_drop;
}
+ ret = btrfs_set_prop_trans(trans, inode, "btrfs.compression", comp,
+ strlen(comp), 0);
+ if (ret && ret != -ENODATA) {
+ btrfs_end_transaction(trans, root);
+ goto out_drop;
+ }
+
btrfs_update_iflags(inode);
inode_inc_iversion(inode);
inode->i_ctime = CURRENT_TIME;
-- 1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html