diff options
author | Sage Weil <sage@newdream.net> | 2009-04-02 16:59:01 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2009-04-02 16:59:01 -0400 |
commit | dccae99995089641fbac452ebc7f0cab18751ddb (patch) | |
tree | c8f3611cc62baa6fa02baff18374d8f3a61b06bf | |
parent | 3a5e14048a0a81276d284cbda441507a17e26147 (diff) |
Btrfs: add flushoncommit mount option
The 'flushoncommit' mount option forces any data dirtied by a write in a
prior transaction to commit as part of the current commit. This makes
the committed state a fully consistent view of the file system from the
application's perspective (i.e., it includes all completed file system
operations). This was previously the behavior only when a snapshot is
created.
This is used by Ceph to ensure that completed writes make it to the
platter along with the metadata operations they are bound to (by
BTRFS_IOC_TRANS_{START,END}).
Signed-off-by: Sage Weil <sage@newdream.net>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r-- | fs/btrfs/ctree.h | 1 | ||||
-rw-r--r-- | fs/btrfs/super.c | 14 | ||||
-rw-r--r-- | fs/btrfs/transaction.c | 5 |
3 files changed, 15 insertions, 5 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 1e99a9948637..bb6ac5b87652 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -1037,6 +1037,7 @@ struct btrfs_root { | |||
1037 | #define BTRFS_MOUNT_DEGRADED (1 << 4) | 1037 | #define BTRFS_MOUNT_DEGRADED (1 << 4) |
1038 | #define BTRFS_MOUNT_COMPRESS (1 << 5) | 1038 | #define BTRFS_MOUNT_COMPRESS (1 << 5) |
1039 | #define BTRFS_MOUNT_NOTREELOG (1 << 6) | 1039 | #define BTRFS_MOUNT_NOTREELOG (1 << 6) |
1040 | #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7) | ||
1040 | 1041 | ||
1041 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) | 1042 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) |
1042 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | 1043 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) |
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 3baa2c109e55..9744af9d71e9 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -68,7 +68,7 @@ enum { | |||
68 | Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, | 68 | Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, |
69 | Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, | 69 | Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, |
70 | Opt_ssd, Opt_thread_pool, Opt_noacl, Opt_compress, Opt_notreelog, | 70 | Opt_ssd, Opt_thread_pool, Opt_noacl, Opt_compress, Opt_notreelog, |
71 | Opt_err, | 71 | Opt_flushoncommit, Opt_err, |
72 | }; | 72 | }; |
73 | 73 | ||
74 | static match_table_t tokens = { | 74 | static match_table_t tokens = { |
@@ -86,6 +86,7 @@ static match_table_t tokens = { | |||
86 | {Opt_ssd, "ssd"}, | 86 | {Opt_ssd, "ssd"}, |
87 | {Opt_noacl, "noacl"}, | 87 | {Opt_noacl, "noacl"}, |
88 | {Opt_notreelog, "notreelog"}, | 88 | {Opt_notreelog, "notreelog"}, |
89 | {Opt_flushoncommit, "flushoncommit"}, | ||
89 | {Opt_err, NULL}, | 90 | {Opt_err, NULL}, |
90 | }; | 91 | }; |
91 | 92 | ||
@@ -229,6 +230,10 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) | |||
229 | printk(KERN_INFO "btrfs: disabling tree log\n"); | 230 | printk(KERN_INFO "btrfs: disabling tree log\n"); |
230 | btrfs_set_opt(info->mount_opt, NOTREELOG); | 231 | btrfs_set_opt(info->mount_opt, NOTREELOG); |
231 | break; | 232 | break; |
233 | case Opt_flushoncommit: | ||
234 | printk(KERN_INFO "btrfs: turning on flush-on-commit\n"); | ||
235 | btrfs_set_opt(info->mount_opt, FLUSHONCOMMIT); | ||
236 | break; | ||
232 | default: | 237 | default: |
233 | break; | 238 | break; |
234 | } | 239 | } |
@@ -370,9 +375,8 @@ fail_close: | |||
370 | int btrfs_sync_fs(struct super_block *sb, int wait) | 375 | int btrfs_sync_fs(struct super_block *sb, int wait) |
371 | { | 376 | { |
372 | struct btrfs_trans_handle *trans; | 377 | struct btrfs_trans_handle *trans; |
373 | struct btrfs_root *root; | 378 | struct btrfs_root *root = btrfs_sb(sb); |
374 | int ret; | 379 | int ret; |
375 | root = btrfs_sb(sb); | ||
376 | 380 | ||
377 | if (sb->s_flags & MS_RDONLY) | 381 | if (sb->s_flags & MS_RDONLY) |
378 | return 0; | 382 | return 0; |
@@ -419,7 +423,9 @@ static int btrfs_show_options(struct seq_file *seq, struct vfsmount *vfs) | |||
419 | if (btrfs_test_opt(root, SSD)) | 423 | if (btrfs_test_opt(root, SSD)) |
420 | seq_puts(seq, ",ssd"); | 424 | seq_puts(seq, ",ssd"); |
421 | if (btrfs_test_opt(root, NOTREELOG)) | 425 | if (btrfs_test_opt(root, NOTREELOG)) |
422 | seq_puts(seq, ",notreelog"); | 426 | seq_puts(seq, ",no-treelog"); |
427 | if (btrfs_test_opt(root, FLUSHONCOMMIT)) | ||
428 | seq_puts(seq, ",flush-on-commit"); | ||
423 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) | 429 | if (!(root->fs_info->sb->s_flags & MS_POSIXACL)) |
424 | seq_puts(seq, ",noacl"); | 430 | seq_puts(seq, ",noacl"); |
425 | return 0; | 431 | return 0; |
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 3e8225de4e9d..2869b3361eb6 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -972,6 +972,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, | |||
972 | int ret; | 972 | int ret; |
973 | int should_grow = 0; | 973 | int should_grow = 0; |
974 | unsigned long now = get_seconds(); | 974 | unsigned long now = get_seconds(); |
975 | int flush_on_commit = btrfs_test_opt(root, FLUSHONCOMMIT); | ||
975 | 976 | ||
976 | btrfs_run_ordered_operations(root, 0); | 977 | btrfs_run_ordered_operations(root, 0); |
977 | 978 | ||
@@ -1051,7 +1052,9 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, | |||
1051 | 1052 | ||
1052 | mutex_unlock(&root->fs_info->trans_mutex); | 1053 | mutex_unlock(&root->fs_info->trans_mutex); |
1053 | 1054 | ||
1054 | if (snap_pending) { | 1055 | if (flush_on_commit || snap_pending) { |
1056 | if (flush_on_commit) | ||
1057 | btrfs_start_delalloc_inodes(root); | ||
1055 | ret = btrfs_wait_ordered_extents(root, 1); | 1058 | ret = btrfs_wait_ordered_extents(root, 1); |
1056 | BUG_ON(ret); | 1059 | BUG_ON(ret); |
1057 | } | 1060 | } |