[2/6,v2] btrfs: do commit in sync_fs if there are pending changes
diff mbox

Message ID 1415968484-9648-1-git-send-email-dsterba@suse.cz
State Under Review
Headers show

Commit Message

David Sterba Nov. 14, 2014, 12:34 p.m. UTC
If a pending change is requested, it's not processed unless there is a
transaction commit about to happen, not even after sync or SYNC_FS
ioctl. For example a remount that toggles the inode_cache option will
not take effect after sync on a quiescent filesystem.

Signed-off-by: David Sterba <dsterba@suse.cz>
---

v2: catch error from btrfs_start_transaction

 fs/btrfs/super.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Filipe Manana Jan. 16, 2015, 1:29 p.m. UTC | #1
On Fri, Nov 14, 2014 at 12:34 PM, David Sterba <dsterba@suse.cz> wrote:
> If a pending change is requested, it's not processed unless there is a
> transaction commit about to happen, not even after sync or SYNC_FS
> ioctl. For example a remount that toggles the inode_cache option will
> not take effect after sync on a quiescent filesystem.
>
> Signed-off-by: David Sterba <dsterba@suse.cz>
> ---
>
> v2: catch error from btrfs_start_transaction

V2 didn't make it to 3.19:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6b5fe46dfa52441f49c7432b1c1b1cb767834708

>
>  fs/btrfs/super.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 54bd91ece35b..0cf589402d8d 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -993,9 +993,17 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
>         trans = btrfs_attach_transaction_barrier(root);
>         if (IS_ERR(trans)) {
>                 /* no transaction, don't bother */
> -               if (PTR_ERR(trans) == -ENOENT)
> -                       return 0;
> -               return PTR_ERR(trans);
> +               if (PTR_ERR(trans) == -ENOENT) {
> +                       /*
> +                        * Exit unless we have some pending changes
> +                        * that need to go through commit
> +                        */
> +                       if (fs_info->pending_changes == 0)
> +                               return 0;
> +                       trans = btrfs_start_transaction(root, 0);
> +               }
> +               if (IS_ERR(trans))
> +                       return PTR_ERR(trans);
>         }
>         return btrfs_commit_transaction(trans, root);
>  }
> --
> 2.1.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 54bd91ece35b..0cf589402d8d 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -993,9 +993,17 @@  int btrfs_sync_fs(struct super_block *sb, int wait)
 	trans = btrfs_attach_transaction_barrier(root);
 	if (IS_ERR(trans)) {
 		/* no transaction, don't bother */
-		if (PTR_ERR(trans) == -ENOENT)
-			return 0;
-		return PTR_ERR(trans);
+		if (PTR_ERR(trans) == -ENOENT) {
+			/*
+			 * Exit unless we have some pending changes
+			 * that need to go through commit
+			 */
+			if (fs_info->pending_changes == 0)
+				return 0;
+			trans = btrfs_start_transaction(root, 0);
+		}
+		if (IS_ERR(trans))
+			return PTR_ERR(trans);
 	}
 	return btrfs_commit_transaction(trans, root);
 }