45NhhVPko5txKuuzDPqhyK changeset

Changeset633936356530 (b)
Parent353336633239 (a)
ab
00diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
...
1-index 3f180b857e20..eea7d68fdcf2 100644
1+index 3f180b857e20..1e7f2e2ba4f0 100644
...
22--- a/fs/btrfs/inode.c
33+++ b/fs/btrfs/inode.c
...
4-@@ -2928,7 +2928,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
4-        int compress_type = 0;
4-        int ret = 0;
4-        u64 logical_len = ordered_extent->len;
4--       bool nolock;
4-+       bool nolock = false;
4-        bool truncated = false;
4-        bool range_locked = false;
4-        bool clear_new_delalloc_bytes = false;
4-@@ -2939,7 +2939,16 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
4-            !test_bit(BTRFS_ORDERED_DIRECT, &ordered_extent->flags))
4-                clear_new_delalloc_bytes = true;
4+@@ -2912,6 +2912,26 @@ static void btrfs_release_delalloc_bytes(struct btrfs_fs_info *fs_info,
4+        btrfs_put_block_group(cache);
4+ }
...
1616 
...
17--       nolock = btrfs_is_free_space_inode(BTRFS_I(inode));
17-+       if (btrfs_is_free_space_inode(BTRFS_I(inode))) {
17-+               nolock = true;
17-+       } else if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
17-+               spin_lock(&fs_info->trans_lock);
17-+               if (fs_info->running_transaction &&
17-+                   (fs_info->running_transaction->state >=
17-+                    TRANS_STATE_COMMIT_START))
17-+                       nolock = true;
17-+               spin_unlock(&fs_info->trans_lock);
17-+       }
17++static struct btrfs_trans_handle *finish_io_join_trans(struct inode *inode)
17++{
17++       struct btrfs_root *root = BTRFS_I(inode)->root;
17++       bool nolock = false;
17++
17++       if (btrfs_is_free_space_inode(BTRFS_I(inode))) {
17++               nolock = true;
17++       } else if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
17++               spin_lock(&fs_info->trans_lock);
17++               if (fs_info->running_transaction)
17++                       nolock = true;
17++               spin_unlock(&fs_info->trans_lock);
17++       }
17++
17++       if (nolock)
17++               return btrfs_join_transaction_nolock(root);
17++
17++       return btrfs_join_transaction(root);
17++}
17++
17+ /* as ordered data IO finishes, this gets called so we can finish
17+  * an ordered extent if the range of bytes in the file it covers are
17+  * fully written.
17+@@ -2928,7 +2948,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
17+        int compress_type = 0;
17+        int ret = 0;
17+        u64 logical_len = ordered_extent->len;
17+-       bool nolock;
17+        bool truncated = false;
17+        bool range_locked = false;
17+        bool clear_new_delalloc_bytes = false;
17+@@ -2939,8 +2958,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
17+            !test_bit(BTRFS_ORDERED_DIRECT, &ordered_extent->flags))
17+                clear_new_delalloc_bytes = true;
...
2828 
...
29-        if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) {
29-                ret = -EIO;
29+-       nolock = btrfs_is_free_space_inode(BTRFS_I(inode));
29+-
29+        if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) {
29+                ret = -EIO;
29+                goto out;
29+@@ -2970,10 +2987,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
29+                btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset,
29+                                       ordered_extent->len);
29+                btrfs_ordered_update_i_size(inode, 0, ordered_extent);
29+-               if (nolock)
29+-                       trans = btrfs_join_transaction_nolock(root);
29+-               else
29+-                       trans = btrfs_join_transaction(root);
29++               trans = finish_io_join_trans(inode);
29+                if (IS_ERR(trans)) {
29+                        ret = PTR_ERR(trans);
29+                        trans = NULL;
29+@@ -3005,10 +3019,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
29+                        EXTENT_DEFRAG, 0, 0, &cached_state);
29+        }
29+ 
29+-       if (nolock)
29+-               trans = btrfs_join_transaction_nolock(root);
29+-       else
29+-               trans = btrfs_join_transaction(root);
29++       trans = finish_io_join_trans(inode);
29+        if (IS_ERR(trans)) {
29+                ret = PTR_ERR(trans);
29+                trans = NULL;
...
3131diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
...
32-index acdad6d658f5..42d756267e9a 100644
32+index acdad6d658f5..d776990fe8e5 100644
...
3333--- a/fs/btrfs/transaction.c
3434+++ b/fs/btrfs/transaction.c
3535@@ -1888,17 +1888,8 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
--- Revision 353336633239
+++ Revision 633936356530
@@ -1,54 +1,95 @@
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
-index 3f180b857e20..eea7d68fdcf2 100644
+index 3f180b857e20..1e7f2e2ba4f0 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
-@@ -2928,7 +2928,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
- int compress_type = 0;
- int ret = 0;
- u64 logical_len = ordered_extent->len;
-- bool nolock;
-+ bool nolock = false;
- bool truncated = false;
- bool range_locked = false;
- bool clear_new_delalloc_bytes = false;
-@@ -2939,7 +2939,16 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
- !test_bit(BTRFS_ORDERED_DIRECT, &ordered_extent->flags))
- clear_new_delalloc_bytes = true;
+@@ -2912,6 +2912,26 @@ static void btrfs_release_delalloc_bytes(struct btrfs_fs_info *fs_info,
+ btrfs_put_block_group(cache);
+ }
-- nolock = btrfs_is_free_space_inode(BTRFS_I(inode));
-+ if (btrfs_is_free_space_inode(BTRFS_I(inode))) {
-+ nolock = true;
-+ } else if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
-+ spin_lock(&fs_info->trans_lock);
-+ if (fs_info->running_transaction &&
-+ (fs_info->running_transaction->state >=
-+ TRANS_STATE_COMMIT_START))
-+ nolock = true;
-+ spin_unlock(&fs_info->trans_lock);
-+ }
++static struct btrfs_trans_handle *finish_io_join_trans(struct inode *inode)
++{
++ struct btrfs_root *root = BTRFS_I(inode)->root;
++ bool nolock = false;
++
++ if (btrfs_is_free_space_inode(BTRFS_I(inode))) {
++ nolock = true;
++ } else if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
++ spin_lock(&fs_info->trans_lock);
++ if (fs_info->running_transaction)
++ nolock = true;
++ spin_unlock(&fs_info->trans_lock);
++ }
++
++ if (nolock)
++ return btrfs_join_transaction_nolock(root);
++
++ return btrfs_join_transaction(root);
++}
++
+ /* as ordered data IO finishes, this gets called so we can finish
+ * an ordered extent if the range of bytes in the file it covers are
+ * fully written.
+@@ -2928,7 +2948,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
+ int compress_type = 0;
+ int ret = 0;
+ u64 logical_len = ordered_extent->len;
+- bool nolock;
+ bool truncated = false;
+ bool range_locked = false;
+ bool clear_new_delalloc_bytes = false;
+@@ -2939,8 +2958,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
+ !test_bit(BTRFS_ORDERED_DIRECT, &ordered_extent->flags))
+ clear_new_delalloc_bytes = true;
- if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) {
- ret = -EIO;
+- nolock = btrfs_is_free_space_inode(BTRFS_I(inode));
+-
+ if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) {
+ ret = -EIO;
+ goto out;
+@@ -2970,10 +2987,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
+ btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset,
+ ordered_extent->len);
+ btrfs_ordered_update_i_size(inode, 0, ordered_extent);
+- if (nolock)
+- trans = btrfs_join_transaction_nolock(root);
+- else
+- trans = btrfs_join_transaction(root);
++ trans = finish_io_join_trans(inode);
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
+ trans = NULL;
+@@ -3005,10 +3019,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
+ EXTENT_DEFRAG, 0, 0, &cached_state);
+ }
+
+- if (nolock)
+- trans = btrfs_join_transaction_nolock(root);
+- else
+- trans = btrfs_join_transaction(root);
++ trans = finish_io_join_trans(inode);
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
+ trans = NULL;
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
-index acdad6d658f5..42d756267e9a 100644
+index acdad6d658f5..d776990fe8e5 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1888,17 +1888,8 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
{
-- /*
-- * We use writeback_inodes_sb here because if we used
-- * btrfs_start_delalloc_roots we would deadlock with fs freeze.
-- * Currently are holding the fs freeze lock, if we do an async flush
-- * we'll do btrfs_join_transaction() and deadlock because we need to
-- * wait for the fs freeze lock. Using the direct flushing we benefit
-- * from already being in a transaction and our join_transaction doesn't
-- * have to re-take the fs freeze lock.
-- */
- if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
-- writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
-+ return btrfs_start_delalloc_roots(fs_info, -1);
- return 0;
+- /*
+- * We use writeback_inodes_sb here because if we used
+- * btrfs_start_delalloc_roots we would deadlock with fs freeze.
+- * Currently are holding the fs freeze lock, if we do an async flush
+- * we'll do btrfs_join_transaction() and deadlock because we need to
+- * wait for the fs freeze lock. Using the direct flushing we benefit
+- * from already being in a transaction and our join_transaction doesn't
+- * have to re-take the fs freeze lock.
+- */
+ if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
+- writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
++ return btrfs_start_delalloc_roots(fs_info, -1);
+ return 0;
}