diff options
Diffstat (limited to 'fs/btrfs/tree-log.c')
-rw-r--r-- | fs/btrfs/tree-log.c | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 7827841b55c..741666a7676 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -137,11 +137,20 @@ static int start_log_trans(struct btrfs_trans_handle *trans, | |||
137 | 137 | ||
138 | mutex_lock(&root->log_mutex); | 138 | mutex_lock(&root->log_mutex); |
139 | if (root->log_root) { | 139 | if (root->log_root) { |
140 | if (!root->log_start_pid) { | ||
141 | root->log_start_pid = current->pid; | ||
142 | root->log_multiple_pids = false; | ||
143 | } else if (root->log_start_pid != current->pid) { | ||
144 | root->log_multiple_pids = true; | ||
145 | } | ||
146 | |||
140 | root->log_batch++; | 147 | root->log_batch++; |
141 | atomic_inc(&root->log_writers); | 148 | atomic_inc(&root->log_writers); |
142 | mutex_unlock(&root->log_mutex); | 149 | mutex_unlock(&root->log_mutex); |
143 | return 0; | 150 | return 0; |
144 | } | 151 | } |
152 | root->log_multiple_pids = false; | ||
153 | root->log_start_pid = current->pid; | ||
145 | mutex_lock(&root->fs_info->tree_log_mutex); | 154 | mutex_lock(&root->fs_info->tree_log_mutex); |
146 | if (!root->fs_info->log_root_tree) { | 155 | if (!root->fs_info->log_root_tree) { |
147 | ret = btrfs_init_log_root_tree(trans, root->fs_info); | 156 | ret = btrfs_init_log_root_tree(trans, root->fs_info); |
@@ -1971,6 +1980,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
1971 | int ret; | 1980 | int ret; |
1972 | struct btrfs_root *log = root->log_root; | 1981 | struct btrfs_root *log = root->log_root; |
1973 | struct btrfs_root *log_root_tree = root->fs_info->log_root_tree; | 1982 | struct btrfs_root *log_root_tree = root->fs_info->log_root_tree; |
1983 | u64 log_transid = 0; | ||
1974 | 1984 | ||
1975 | mutex_lock(&root->log_mutex); | 1985 | mutex_lock(&root->log_mutex); |
1976 | index1 = root->log_transid % 2; | 1986 | index1 = root->log_transid % 2; |
@@ -1987,10 +1997,11 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
1987 | 1997 | ||
1988 | while (1) { | 1998 | while (1) { |
1989 | unsigned long batch = root->log_batch; | 1999 | unsigned long batch = root->log_batch; |
1990 | mutex_unlock(&root->log_mutex); | 2000 | if (root->log_multiple_pids) { |
1991 | schedule_timeout_uninterruptible(1); | 2001 | mutex_unlock(&root->log_mutex); |
1992 | mutex_lock(&root->log_mutex); | 2002 | schedule_timeout_uninterruptible(1); |
1993 | 2003 | mutex_lock(&root->log_mutex); | |
2004 | } | ||
1994 | wait_for_writer(trans, root); | 2005 | wait_for_writer(trans, root); |
1995 | if (batch == root->log_batch) | 2006 | if (batch == root->log_batch) |
1996 | break; | 2007 | break; |
@@ -2003,14 +2014,19 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2003 | goto out; | 2014 | goto out; |
2004 | } | 2015 | } |
2005 | 2016 | ||
2006 | ret = btrfs_write_and_wait_marked_extents(log, &log->dirty_log_pages); | 2017 | /* we start IO on all the marked extents here, but we don't actually |
2018 | * wait for them until later. | ||
2019 | */ | ||
2020 | ret = btrfs_write_marked_extents(log, &log->dirty_log_pages); | ||
2007 | BUG_ON(ret); | 2021 | BUG_ON(ret); |
2008 | 2022 | ||
2009 | btrfs_set_root_node(&log->root_item, log->node); | 2023 | btrfs_set_root_node(&log->root_item, log->node); |
2010 | 2024 | ||
2011 | root->log_batch = 0; | 2025 | root->log_batch = 0; |
2026 | log_transid = root->log_transid; | ||
2012 | root->log_transid++; | 2027 | root->log_transid++; |
2013 | log->log_transid = root->log_transid; | 2028 | log->log_transid = root->log_transid; |
2029 | root->log_start_pid = 0; | ||
2014 | smp_mb(); | 2030 | smp_mb(); |
2015 | /* | 2031 | /* |
2016 | * log tree has been flushed to disk, new modifications of | 2032 | * log tree has been flushed to disk, new modifications of |
@@ -2036,6 +2052,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2036 | 2052 | ||
2037 | index2 = log_root_tree->log_transid % 2; | 2053 | index2 = log_root_tree->log_transid % 2; |
2038 | if (atomic_read(&log_root_tree->log_commit[index2])) { | 2054 | if (atomic_read(&log_root_tree->log_commit[index2])) { |
2055 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | ||
2039 | wait_log_commit(trans, log_root_tree, | 2056 | wait_log_commit(trans, log_root_tree, |
2040 | log_root_tree->log_transid); | 2057 | log_root_tree->log_transid); |
2041 | mutex_unlock(&log_root_tree->log_mutex); | 2058 | mutex_unlock(&log_root_tree->log_mutex); |
@@ -2055,6 +2072,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2055 | * check the full commit flag again | 2072 | * check the full commit flag again |
2056 | */ | 2073 | */ |
2057 | if (root->fs_info->last_trans_log_full_commit == trans->transid) { | 2074 | if (root->fs_info->last_trans_log_full_commit == trans->transid) { |
2075 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | ||
2058 | mutex_unlock(&log_root_tree->log_mutex); | 2076 | mutex_unlock(&log_root_tree->log_mutex); |
2059 | ret = -EAGAIN; | 2077 | ret = -EAGAIN; |
2060 | goto out_wake_log_root; | 2078 | goto out_wake_log_root; |
@@ -2063,6 +2081,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2063 | ret = btrfs_write_and_wait_marked_extents(log_root_tree, | 2081 | ret = btrfs_write_and_wait_marked_extents(log_root_tree, |
2064 | &log_root_tree->dirty_log_pages); | 2082 | &log_root_tree->dirty_log_pages); |
2065 | BUG_ON(ret); | 2083 | BUG_ON(ret); |
2084 | btrfs_wait_marked_extents(log, &log->dirty_log_pages); | ||
2066 | 2085 | ||
2067 | btrfs_set_super_log_root(&root->fs_info->super_for_commit, | 2086 | btrfs_set_super_log_root(&root->fs_info->super_for_commit, |
2068 | log_root_tree->node->start); | 2087 | log_root_tree->node->start); |
@@ -2082,9 +2101,14 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, | |||
2082 | * the running transaction open, so a full commit can't hop | 2101 | * the running transaction open, so a full commit can't hop |
2083 | * in and cause problems either. | 2102 | * in and cause problems either. |
2084 | */ | 2103 | */ |
2085 | write_ctree_super(trans, root->fs_info->tree_root, 2); | 2104 | write_ctree_super(trans, root->fs_info->tree_root, 1); |
2086 | ret = 0; | 2105 | ret = 0; |
2087 | 2106 | ||
2107 | mutex_lock(&root->log_mutex); | ||
2108 | if (root->last_log_commit < log_transid) | ||
2109 | root->last_log_commit = log_transid; | ||
2110 | mutex_unlock(&root->log_mutex); | ||
2111 | |||
2088 | out_wake_log_root: | 2112 | out_wake_log_root: |
2089 | atomic_set(&log_root_tree->log_commit[index2], 0); | 2113 | atomic_set(&log_root_tree->log_commit[index2], 0); |
2090 | smp_mb(); | 2114 | smp_mb(); |
@@ -2852,6 +2876,21 @@ out: | |||
2852 | return ret; | 2876 | return ret; |
2853 | } | 2877 | } |
2854 | 2878 | ||
2879 | static int inode_in_log(struct btrfs_trans_handle *trans, | ||
2880 | struct inode *inode) | ||
2881 | { | ||
2882 | struct btrfs_root *root = BTRFS_I(inode)->root; | ||
2883 | int ret = 0; | ||
2884 | |||
2885 | mutex_lock(&root->log_mutex); | ||
2886 | if (BTRFS_I(inode)->logged_trans == trans->transid && | ||
2887 | BTRFS_I(inode)->last_sub_trans <= root->last_log_commit) | ||
2888 | ret = 1; | ||
2889 | mutex_unlock(&root->log_mutex); | ||
2890 | return ret; | ||
2891 | } | ||
2892 | |||
2893 | |||
2855 | /* | 2894 | /* |
2856 | * helper function around btrfs_log_inode to make sure newly created | 2895 | * helper function around btrfs_log_inode to make sure newly created |
2857 | * parent directories also end up in the log. A minimal inode and backref | 2896 | * parent directories also end up in the log. A minimal inode and backref |
@@ -2891,6 +2930,11 @@ int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | |||
2891 | if (ret) | 2930 | if (ret) |
2892 | goto end_no_trans; | 2931 | goto end_no_trans; |
2893 | 2932 | ||
2933 | if (inode_in_log(trans, inode)) { | ||
2934 | ret = BTRFS_NO_LOG_SYNC; | ||
2935 | goto end_no_trans; | ||
2936 | } | ||
2937 | |||
2894 | start_log_trans(trans, root); | 2938 | start_log_trans(trans, root); |
2895 | 2939 | ||
2896 | ret = btrfs_log_inode(trans, root, inode, inode_only); | 2940 | ret = btrfs_log_inode(trans, root, inode, inode_only); |