All of lore.kernel.org
 help / color / mirror / Atom feed
From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
To: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Cc: Chris Mason <clm@fb.com>, Filipe Manana <fdmanana@suse.com>
Subject: [PATCH 4/4] btrfs: Fix compression related ioctl to run atomic operations in one transaction
Date: Fri, 19 Sep 2014 18:05:08 +0900	[thread overview]
Message-ID: <541BF1C4.1050000@jp.fujitsu.com> (raw)
In-Reply-To: <541BEEC1.9030606@jp.fujitsu.com>

From: Naohiro Aota <naota@elisp.net>

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()
     at all. 

Signed-off-by: Naohiro Aota <naota@elisp.net>
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
---
 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..47ac6da 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, 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 


  reply	other threads:[~2014-09-19  9:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-19  8:45 [PATCH 1/4] btrfs: correct empty compression property behavior Satoru Takeuchi
2014-09-19  8:48 ` [PATCH 2/4] btrfs: introduce new compression property to disable compression at all Satoru Takeuchi
2014-09-19  8:52   ` [PATCH 3/4] btrfs: export __btrfs_set_prop Satoru Takeuchi
2014-09-19  9:05     ` Satoru Takeuchi [this message]
2014-09-25  5:57       ` [PATCH v2 4/4] btrfs: Fix compression related ioctl to run atomic operations in one transaction Satoru Takeuchi
2014-09-22 12:01     ` [PATCH 3/4] btrfs: export __btrfs_set_prop David Sterba
2014-09-25  5:55       ` [PATCH v2 3/4] btrfs: Rename and export __btrfs_set_prop to be called from running transaction Satoru Takeuchi
2014-09-29 16:23         ` David Sterba
2014-09-29 16:36 ` [PATCH 1/4] btrfs: correct empty compression property behavior David Sterba
2014-10-16  1:37   ` Satoru Takeuchi
2014-10-16  7:01     ` Filipe David Manana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=541BF1C4.1050000@jp.fujitsu.com \
    --to=takeuchi_satoru@jp.fujitsu.com \
    --cc=clm@fb.com \
    --cc=fdmanana@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.