diff options
author | Chris Mason <clm@fb.com> | 2015-04-04 20:14:42 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2015-04-10 17:07:11 -0400 |
commit | c9dc4c6578502c2085705347375b82089aad18d0 (patch) | |
tree | 2d6264a45e412e612dba1357cf6754dc680c2fd4 /fs | |
parent | 4c6d1d85ad89fd8e32dc9204b7f944854399bda9 (diff) |
Btrfs: two stage dirty block group writeout
Block group cache writeout is currently waiting on the pages for each
block group cache before moving on to writing the next one. This commit
switches things around to send down all the caches and then wait on them
in batches.
The end result is much faster, since we're keeping the disk pipeline
full.
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/ctree.h | 6 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 57 | ||||
-rw-r--r-- | fs/btrfs/free-space-cache.c | 131 | ||||
-rw-r--r-- | fs/btrfs/free-space-cache.h | 8 |
4 files changed, 170 insertions, 32 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index e305ccd731fe..1df0d9db5332 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -1261,9 +1261,12 @@ struct btrfs_io_ctl { | |||
1261 | struct page *page; | 1261 | struct page *page; |
1262 | struct page **pages; | 1262 | struct page **pages; |
1263 | struct btrfs_root *root; | 1263 | struct btrfs_root *root; |
1264 | struct inode *inode; | ||
1264 | unsigned long size; | 1265 | unsigned long size; |
1265 | int index; | 1266 | int index; |
1266 | int num_pages; | 1267 | int num_pages; |
1268 | int entries; | ||
1269 | int bitmaps; | ||
1267 | unsigned check_crcs:1; | 1270 | unsigned check_crcs:1; |
1268 | }; | 1271 | }; |
1269 | 1272 | ||
@@ -1332,6 +1335,9 @@ struct btrfs_block_group_cache { | |||
1332 | 1335 | ||
1333 | /* For dirty block groups */ | 1336 | /* For dirty block groups */ |
1334 | struct list_head dirty_list; | 1337 | struct list_head dirty_list; |
1338 | struct list_head io_list; | ||
1339 | |||
1340 | struct btrfs_io_ctl io_ctl; | ||
1335 | }; | 1341 | }; |
1336 | 1342 | ||
1337 | /* delayed seq elem */ | 1343 | /* delayed seq elem */ |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 3d4b3d680fea..40c95135d037 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3388,7 +3388,11 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, | |||
3388 | struct btrfs_block_group_cache *cache; | 3388 | struct btrfs_block_group_cache *cache; |
3389 | struct btrfs_transaction *cur_trans = trans->transaction; | 3389 | struct btrfs_transaction *cur_trans = trans->transaction; |
3390 | int ret = 0; | 3390 | int ret = 0; |
3391 | int should_put; | ||
3391 | struct btrfs_path *path; | 3392 | struct btrfs_path *path; |
3393 | LIST_HEAD(io); | ||
3394 | int num_started = 0; | ||
3395 | int num_waited = 0; | ||
3392 | 3396 | ||
3393 | if (list_empty(&cur_trans->dirty_bgs)) | 3397 | if (list_empty(&cur_trans->dirty_bgs)) |
3394 | return 0; | 3398 | return 0; |
@@ -3407,16 +3411,60 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, | |||
3407 | cache = list_first_entry(&cur_trans->dirty_bgs, | 3411 | cache = list_first_entry(&cur_trans->dirty_bgs, |
3408 | struct btrfs_block_group_cache, | 3412 | struct btrfs_block_group_cache, |
3409 | dirty_list); | 3413 | dirty_list); |
3414 | |||
3415 | /* | ||
3416 | * this can happen if cache_save_setup re-dirties a block | ||
3417 | * group that is already under IO. Just wait for it to | ||
3418 | * finish and then do it all again | ||
3419 | */ | ||
3420 | if (!list_empty(&cache->io_list)) { | ||
3421 | list_del_init(&cache->io_list); | ||
3422 | btrfs_wait_cache_io(root, trans, cache, | ||
3423 | &cache->io_ctl, path, | ||
3424 | cache->key.objectid); | ||
3425 | btrfs_put_block_group(cache); | ||
3426 | num_waited++; | ||
3427 | } | ||
3428 | |||
3410 | list_del_init(&cache->dirty_list); | 3429 | list_del_init(&cache->dirty_list); |
3430 | should_put = 1; | ||
3431 | |||
3411 | if (cache->disk_cache_state == BTRFS_DC_CLEAR) | 3432 | if (cache->disk_cache_state == BTRFS_DC_CLEAR) |
3412 | cache_save_setup(cache, trans, path); | 3433 | cache_save_setup(cache, trans, path); |
3434 | |||
3413 | if (!ret) | 3435 | if (!ret) |
3414 | ret = btrfs_run_delayed_refs(trans, root, | 3436 | ret = btrfs_run_delayed_refs(trans, root, (unsigned long) -1); |
3415 | (unsigned long) -1); | 3437 | |
3416 | if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) | 3438 | if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) { |
3417 | btrfs_write_out_cache(root, trans, cache, path); | 3439 | cache->io_ctl.inode = NULL; |
3440 | ret = btrfs_write_out_cache(root, trans, cache, path); | ||
3441 | if (ret == 0 && cache->io_ctl.inode) { | ||
3442 | num_started++; | ||
3443 | should_put = 0; | ||
3444 | list_add_tail(&cache->io_list, &io); | ||
3445 | } else { | ||
3446 | /* | ||
3447 | * if we failed to write the cache, the | ||
3448 | * generation will be bad and life goes on | ||
3449 | */ | ||
3450 | ret = 0; | ||
3451 | } | ||
3452 | } | ||
3418 | if (!ret) | 3453 | if (!ret) |
3419 | ret = write_one_cache_group(trans, root, path, cache); | 3454 | ret = write_one_cache_group(trans, root, path, cache); |
3455 | |||
3456 | /* if its not on the io list, we need to put the block group */ | ||
3457 | if (should_put) | ||
3458 | btrfs_put_block_group(cache); | ||
3459 | } | ||
3460 | |||
3461 | while (!list_empty(&io)) { | ||
3462 | cache = list_first_entry(&io, struct btrfs_block_group_cache, | ||
3463 | io_list); | ||
3464 | list_del_init(&cache->io_list); | ||
3465 | num_waited++; | ||
3466 | btrfs_wait_cache_io(root, trans, cache, | ||
3467 | &cache->io_ctl, path, cache->key.objectid); | ||
3420 | btrfs_put_block_group(cache); | 3468 | btrfs_put_block_group(cache); |
3421 | } | 3469 | } |
3422 | 3470 | ||
@@ -9013,6 +9061,7 @@ btrfs_create_block_group_cache(struct btrfs_root *root, u64 start, u64 size) | |||
9013 | INIT_LIST_HEAD(&cache->bg_list); | 9061 | INIT_LIST_HEAD(&cache->bg_list); |
9014 | INIT_LIST_HEAD(&cache->ro_list); | 9062 | INIT_LIST_HEAD(&cache->ro_list); |
9015 | INIT_LIST_HEAD(&cache->dirty_list); | 9063 | INIT_LIST_HEAD(&cache->dirty_list); |
9064 | INIT_LIST_HEAD(&cache->io_list); | ||
9016 | btrfs_init_free_space_ctl(cache); | 9065 | btrfs_init_free_space_ctl(cache); |
9017 | atomic_set(&cache->trimming, 0); | 9066 | atomic_set(&cache->trimming, 0); |
9018 | 9067 | ||
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 47c2adb3ddf3..6886ae063483 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -170,13 +170,13 @@ static int __create_free_space_inode(struct btrfs_root *root, | |||
170 | key.objectid = BTRFS_FREE_SPACE_OBJECTID; | 170 | key.objectid = BTRFS_FREE_SPACE_OBJECTID; |
171 | key.offset = offset; | 171 | key.offset = offset; |
172 | key.type = 0; | 172 | key.type = 0; |
173 | |||
174 | ret = btrfs_insert_empty_item(trans, root, path, &key, | 173 | ret = btrfs_insert_empty_item(trans, root, path, &key, |
175 | sizeof(struct btrfs_free_space_header)); | 174 | sizeof(struct btrfs_free_space_header)); |
176 | if (ret < 0) { | 175 | if (ret < 0) { |
177 | btrfs_release_path(path); | 176 | btrfs_release_path(path); |
178 | return ret; | 177 | return ret; |
179 | } | 178 | } |
179 | |||
180 | leaf = path->nodes[0]; | 180 | leaf = path->nodes[0]; |
181 | header = btrfs_item_ptr(leaf, path->slots[0], | 181 | header = btrfs_item_ptr(leaf, path->slots[0], |
182 | struct btrfs_free_space_header); | 182 | struct btrfs_free_space_header); |
@@ -296,6 +296,7 @@ static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode, | |||
296 | io_ctl->num_pages = num_pages; | 296 | io_ctl->num_pages = num_pages; |
297 | io_ctl->root = root; | 297 | io_ctl->root = root; |
298 | io_ctl->check_crcs = check_crcs; | 298 | io_ctl->check_crcs = check_crcs; |
299 | io_ctl->inode = inode; | ||
299 | 300 | ||
300 | return 0; | 301 | return 0; |
301 | } | 302 | } |
@@ -303,6 +304,7 @@ static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode, | |||
303 | static void io_ctl_free(struct btrfs_io_ctl *io_ctl) | 304 | static void io_ctl_free(struct btrfs_io_ctl *io_ctl) |
304 | { | 305 | { |
305 | kfree(io_ctl->pages); | 306 | kfree(io_ctl->pages); |
307 | io_ctl->pages = NULL; | ||
306 | } | 308 | } |
307 | 309 | ||
308 | static void io_ctl_unmap_page(struct btrfs_io_ctl *io_ctl) | 310 | static void io_ctl_unmap_page(struct btrfs_io_ctl *io_ctl) |
@@ -1092,6 +1094,61 @@ cleanup_write_cache_enospc(struct inode *inode, | |||
1092 | GFP_NOFS); | 1094 | GFP_NOFS); |
1093 | } | 1095 | } |
1094 | 1096 | ||
1097 | int btrfs_wait_cache_io(struct btrfs_root *root, | ||
1098 | struct btrfs_trans_handle *trans, | ||
1099 | struct btrfs_block_group_cache *block_group, | ||
1100 | struct btrfs_io_ctl *io_ctl, | ||
1101 | struct btrfs_path *path, u64 offset) | ||
1102 | { | ||
1103 | int ret; | ||
1104 | struct inode *inode = io_ctl->inode; | ||
1105 | |||
1106 | root = root->fs_info->tree_root; | ||
1107 | |||
1108 | /* Flush the dirty pages in the cache file. */ | ||
1109 | ret = flush_dirty_cache(inode); | ||
1110 | if (ret) | ||
1111 | goto out; | ||
1112 | |||
1113 | /* Update the cache item to tell everyone this cache file is valid. */ | ||
1114 | ret = update_cache_item(trans, root, inode, path, offset, | ||
1115 | io_ctl->entries, io_ctl->bitmaps); | ||
1116 | out: | ||
1117 | io_ctl_free(io_ctl); | ||
1118 | if (ret) { | ||
1119 | invalidate_inode_pages2(inode->i_mapping); | ||
1120 | BTRFS_I(inode)->generation = 0; | ||
1121 | if (block_group) { | ||
1122 | #ifdef DEBUG | ||
1123 | btrfs_err(root->fs_info, | ||
1124 | "failed to write free space cache for block group %llu", | ||
1125 | block_group->key.objectid); | ||
1126 | #endif | ||
1127 | } | ||
1128 | } | ||
1129 | btrfs_update_inode(trans, root, inode); | ||
1130 | |||
1131 | if (block_group) { | ||
1132 | spin_lock(&block_group->lock); | ||
1133 | |||
1134 | /* | ||
1135 | * only mark this as written if we didn't get put back on | ||
1136 | * the dirty list while waiting for IO. | ||
1137 | */ | ||
1138 | if (!ret && list_empty(&block_group->dirty_list)) | ||
1139 | block_group->disk_cache_state = BTRFS_DC_WRITTEN; | ||
1140 | else if (ret) | ||
1141 | block_group->disk_cache_state = BTRFS_DC_ERROR; | ||
1142 | |||
1143 | spin_unlock(&block_group->lock); | ||
1144 | io_ctl->inode = NULL; | ||
1145 | iput(inode); | ||
1146 | } | ||
1147 | |||
1148 | return ret; | ||
1149 | |||
1150 | } | ||
1151 | |||
1095 | /** | 1152 | /** |
1096 | * __btrfs_write_out_cache - write out cached info to an inode | 1153 | * __btrfs_write_out_cache - write out cached info to an inode |
1097 | * @root - the root the inode belongs to | 1154 | * @root - the root the inode belongs to |
@@ -1108,20 +1165,22 @@ cleanup_write_cache_enospc(struct inode *inode, | |||
1108 | static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, | 1165 | static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, |
1109 | struct btrfs_free_space_ctl *ctl, | 1166 | struct btrfs_free_space_ctl *ctl, |
1110 | struct btrfs_block_group_cache *block_group, | 1167 | struct btrfs_block_group_cache *block_group, |
1168 | struct btrfs_io_ctl *io_ctl, | ||
1111 | struct btrfs_trans_handle *trans, | 1169 | struct btrfs_trans_handle *trans, |
1112 | struct btrfs_path *path, u64 offset) | 1170 | struct btrfs_path *path, u64 offset) |
1113 | { | 1171 | { |
1114 | struct extent_state *cached_state = NULL; | 1172 | struct extent_state *cached_state = NULL; |
1115 | struct btrfs_io_ctl io_ctl; | ||
1116 | LIST_HEAD(bitmap_list); | 1173 | LIST_HEAD(bitmap_list); |
1117 | int entries = 0; | 1174 | int entries = 0; |
1118 | int bitmaps = 0; | 1175 | int bitmaps = 0; |
1119 | int ret; | 1176 | int ret; |
1177 | int must_iput = 0; | ||
1120 | 1178 | ||
1121 | if (!i_size_read(inode)) | 1179 | if (!i_size_read(inode)) |
1122 | return -1; | 1180 | return -1; |
1123 | 1181 | ||
1124 | ret = io_ctl_init(&io_ctl, inode, root, 1); | 1182 | WARN_ON(io_ctl->pages); |
1183 | ret = io_ctl_init(io_ctl, inode, root, 1); | ||
1125 | if (ret) | 1184 | if (ret) |
1126 | return -1; | 1185 | return -1; |
1127 | 1186 | ||
@@ -1134,22 +1193,23 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, | |||
1134 | up_write(&block_group->data_rwsem); | 1193 | up_write(&block_group->data_rwsem); |
1135 | BTRFS_I(inode)->generation = 0; | 1194 | BTRFS_I(inode)->generation = 0; |
1136 | ret = 0; | 1195 | ret = 0; |
1196 | must_iput = 1; | ||
1137 | goto out; | 1197 | goto out; |
1138 | } | 1198 | } |
1139 | spin_unlock(&block_group->lock); | 1199 | spin_unlock(&block_group->lock); |
1140 | } | 1200 | } |
1141 | 1201 | ||
1142 | /* Lock all pages first so we can lock the extent safely. */ | 1202 | /* Lock all pages first so we can lock the extent safely. */ |
1143 | io_ctl_prepare_pages(&io_ctl, inode, 0); | 1203 | io_ctl_prepare_pages(io_ctl, inode, 0); |
1144 | 1204 | ||
1145 | lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, | 1205 | lock_extent_bits(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, |
1146 | 0, &cached_state); | 1206 | 0, &cached_state); |
1147 | 1207 | ||
1148 | io_ctl_set_generation(&io_ctl, trans->transid); | 1208 | io_ctl_set_generation(io_ctl, trans->transid); |
1149 | 1209 | ||
1150 | mutex_lock(&ctl->cache_writeout_mutex); | 1210 | mutex_lock(&ctl->cache_writeout_mutex); |
1151 | /* Write out the extent entries in the free space cache */ | 1211 | /* Write out the extent entries in the free space cache */ |
1152 | ret = write_cache_extent_entries(&io_ctl, ctl, | 1212 | ret = write_cache_extent_entries(io_ctl, ctl, |
1153 | block_group, &entries, &bitmaps, | 1213 | block_group, &entries, &bitmaps, |
1154 | &bitmap_list); | 1214 | &bitmap_list); |
1155 | if (ret) { | 1215 | if (ret) { |
@@ -1162,7 +1222,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, | |||
1162 | * they will be added into free space cache after the transaction is | 1222 | * they will be added into free space cache after the transaction is |
1163 | * committed, we shouldn't lose them. | 1223 | * committed, we shouldn't lose them. |
1164 | */ | 1224 | */ |
1165 | ret = write_pinned_extent_entries(root, block_group, &io_ctl, &entries); | 1225 | ret = write_pinned_extent_entries(root, block_group, io_ctl, &entries); |
1166 | if (ret) { | 1226 | if (ret) { |
1167 | mutex_unlock(&ctl->cache_writeout_mutex); | 1227 | mutex_unlock(&ctl->cache_writeout_mutex); |
1168 | goto out_nospc; | 1228 | goto out_nospc; |
@@ -1173,16 +1233,16 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, | |||
1173 | * locked while doing it because a concurrent trim can be manipulating | 1233 | * locked while doing it because a concurrent trim can be manipulating |
1174 | * or freeing the bitmap. | 1234 | * or freeing the bitmap. |
1175 | */ | 1235 | */ |
1176 | ret = write_bitmap_entries(&io_ctl, &bitmap_list); | 1236 | ret = write_bitmap_entries(io_ctl, &bitmap_list); |
1177 | mutex_unlock(&ctl->cache_writeout_mutex); | 1237 | mutex_unlock(&ctl->cache_writeout_mutex); |
1178 | if (ret) | 1238 | if (ret) |
1179 | goto out_nospc; | 1239 | goto out_nospc; |
1180 | 1240 | ||
1181 | /* Zero out the rest of the pages just to make sure */ | 1241 | /* Zero out the rest of the pages just to make sure */ |
1182 | io_ctl_zero_remaining_pages(&io_ctl); | 1242 | io_ctl_zero_remaining_pages(io_ctl); |
1183 | 1243 | ||
1184 | /* Everything is written out, now we dirty the pages in the file. */ | 1244 | /* Everything is written out, now we dirty the pages in the file. */ |
1185 | ret = btrfs_dirty_pages(root, inode, io_ctl.pages, io_ctl.num_pages, | 1245 | ret = btrfs_dirty_pages(root, inode, io_ctl->pages, io_ctl->num_pages, |
1186 | 0, i_size_read(inode), &cached_state); | 1246 | 0, i_size_read(inode), &cached_state); |
1187 | if (ret) | 1247 | if (ret) |
1188 | goto out_nospc; | 1248 | goto out_nospc; |
@@ -1193,30 +1253,39 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, | |||
1193 | * Release the pages and unlock the extent, we will flush | 1253 | * Release the pages and unlock the extent, we will flush |
1194 | * them out later | 1254 | * them out later |
1195 | */ | 1255 | */ |
1196 | io_ctl_drop_pages(&io_ctl); | 1256 | io_ctl_drop_pages(io_ctl); |
1197 | 1257 | ||
1198 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, | 1258 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, |
1199 | i_size_read(inode) - 1, &cached_state, GFP_NOFS); | 1259 | i_size_read(inode) - 1, &cached_state, GFP_NOFS); |
1200 | 1260 | ||
1201 | /* Flush the dirty pages in the cache file. */ | 1261 | /* |
1202 | ret = flush_dirty_cache(inode); | 1262 | * at this point the pages are under IO and we're happy, |
1263 | * The caller is responsible for waiting on them and updating the | ||
1264 | * the cache and the inode | ||
1265 | */ | ||
1266 | io_ctl->entries = entries; | ||
1267 | io_ctl->bitmaps = bitmaps; | ||
1268 | |||
1269 | ret = btrfs_fdatawrite_range(inode, 0, (u64)-1); | ||
1203 | if (ret) | 1270 | if (ret) |
1204 | goto out; | 1271 | goto out; |
1205 | 1272 | ||
1206 | /* Update the cache item to tell everyone this cache file is valid. */ | 1273 | return 0; |
1207 | ret = update_cache_item(trans, root, inode, path, offset, | 1274 | |
1208 | entries, bitmaps); | ||
1209 | out: | 1275 | out: |
1210 | io_ctl_free(&io_ctl); | 1276 | io_ctl->inode = NULL; |
1277 | io_ctl_free(io_ctl); | ||
1211 | if (ret) { | 1278 | if (ret) { |
1212 | invalidate_inode_pages2(inode->i_mapping); | 1279 | invalidate_inode_pages2(inode->i_mapping); |
1213 | BTRFS_I(inode)->generation = 0; | 1280 | BTRFS_I(inode)->generation = 0; |
1214 | } | 1281 | } |
1215 | btrfs_update_inode(trans, root, inode); | 1282 | btrfs_update_inode(trans, root, inode); |
1283 | if (must_iput) | ||
1284 | iput(inode); | ||
1216 | return ret; | 1285 | return ret; |
1217 | 1286 | ||
1218 | out_nospc: | 1287 | out_nospc: |
1219 | cleanup_write_cache_enospc(inode, &io_ctl, &cached_state, &bitmap_list); | 1288 | cleanup_write_cache_enospc(inode, io_ctl, &cached_state, &bitmap_list); |
1220 | 1289 | ||
1221 | if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) | 1290 | if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) |
1222 | up_write(&block_group->data_rwsem); | 1291 | up_write(&block_group->data_rwsem); |
@@ -1232,7 +1301,6 @@ int btrfs_write_out_cache(struct btrfs_root *root, | |||
1232 | struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; | 1301 | struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; |
1233 | struct inode *inode; | 1302 | struct inode *inode; |
1234 | int ret = 0; | 1303 | int ret = 0; |
1235 | enum btrfs_disk_cache_state dcs = BTRFS_DC_WRITTEN; | ||
1236 | 1304 | ||
1237 | root = root->fs_info->tree_root; | 1305 | root = root->fs_info->tree_root; |
1238 | 1306 | ||
@@ -1253,22 +1321,28 @@ int btrfs_write_out_cache(struct btrfs_root *root, | |||
1253 | if (IS_ERR(inode)) | 1321 | if (IS_ERR(inode)) |
1254 | return 0; | 1322 | return 0; |
1255 | 1323 | ||
1256 | ret = __btrfs_write_out_cache(root, inode, ctl, block_group, trans, | 1324 | ret = __btrfs_write_out_cache(root, inode, ctl, block_group, |
1325 | &block_group->io_ctl, trans, | ||
1257 | path, block_group->key.objectid); | 1326 | path, block_group->key.objectid); |
1258 | if (ret) { | 1327 | if (ret) { |
1259 | dcs = BTRFS_DC_ERROR; | ||
1260 | ret = 0; | ||
1261 | #ifdef DEBUG | 1328 | #ifdef DEBUG |
1262 | btrfs_err(root->fs_info, | 1329 | btrfs_err(root->fs_info, |
1263 | "failed to write free space cache for block group %llu", | 1330 | "failed to write free space cache for block group %llu", |
1264 | block_group->key.objectid); | 1331 | block_group->key.objectid); |
1265 | #endif | 1332 | #endif |
1333 | spin_lock(&block_group->lock); | ||
1334 | block_group->disk_cache_state = BTRFS_DC_ERROR; | ||
1335 | spin_unlock(&block_group->lock); | ||
1336 | |||
1337 | block_group->io_ctl.inode = NULL; | ||
1338 | iput(inode); | ||
1266 | } | 1339 | } |
1267 | 1340 | ||
1268 | spin_lock(&block_group->lock); | 1341 | /* |
1269 | block_group->disk_cache_state = dcs; | 1342 | * if ret == 0 the caller is expected to call btrfs_wait_cache_io |
1270 | spin_unlock(&block_group->lock); | 1343 | * to wait for IO and put the inode |
1271 | iput(inode); | 1344 | */ |
1345 | |||
1272 | return ret; | 1346 | return ret; |
1273 | } | 1347 | } |
1274 | 1348 | ||
@@ -3331,11 +3405,14 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root, | |||
3331 | { | 3405 | { |
3332 | struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; | 3406 | struct btrfs_free_space_ctl *ctl = root->free_ino_ctl; |
3333 | int ret; | 3407 | int ret; |
3408 | struct btrfs_io_ctl io_ctl; | ||
3334 | 3409 | ||
3335 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) | 3410 | if (!btrfs_test_opt(root, INODE_MAP_CACHE)) |
3336 | return 0; | 3411 | return 0; |
3337 | 3412 | ||
3338 | ret = __btrfs_write_out_cache(root, inode, ctl, NULL, trans, path, 0); | 3413 | ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl, |
3414 | trans, path, 0) || | ||
3415 | btrfs_wait_cache_io(root, trans, NULL, &io_ctl, path, 0); | ||
3339 | if (ret) { | 3416 | if (ret) { |
3340 | btrfs_delalloc_release_metadata(inode, inode->i_size); | 3417 | btrfs_delalloc_release_metadata(inode, inode->i_size); |
3341 | #ifdef DEBUG | 3418 | #ifdef DEBUG |
diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h index 88b2238a0aed..c4339863af05 100644 --- a/fs/btrfs/free-space-cache.h +++ b/fs/btrfs/free-space-cache.h | |||
@@ -48,6 +48,8 @@ struct btrfs_free_space_op { | |||
48 | struct btrfs_free_space *info); | 48 | struct btrfs_free_space *info); |
49 | }; | 49 | }; |
50 | 50 | ||
51 | struct btrfs_io_ctl; | ||
52 | |||
51 | struct inode *lookup_free_space_inode(struct btrfs_root *root, | 53 | struct inode *lookup_free_space_inode(struct btrfs_root *root, |
52 | struct btrfs_block_group_cache | 54 | struct btrfs_block_group_cache |
53 | *block_group, struct btrfs_path *path); | 55 | *block_group, struct btrfs_path *path); |
@@ -63,11 +65,15 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root, | |||
63 | struct inode *inode); | 65 | struct inode *inode); |
64 | int load_free_space_cache(struct btrfs_fs_info *fs_info, | 66 | int load_free_space_cache(struct btrfs_fs_info *fs_info, |
65 | struct btrfs_block_group_cache *block_group); | 67 | struct btrfs_block_group_cache *block_group); |
68 | int btrfs_wait_cache_io(struct btrfs_root *root, | ||
69 | struct btrfs_trans_handle *trans, | ||
70 | struct btrfs_block_group_cache *block_group, | ||
71 | struct btrfs_io_ctl *io_ctl, | ||
72 | struct btrfs_path *path, u64 offset); | ||
66 | int btrfs_write_out_cache(struct btrfs_root *root, | 73 | int btrfs_write_out_cache(struct btrfs_root *root, |
67 | struct btrfs_trans_handle *trans, | 74 | struct btrfs_trans_handle *trans, |
68 | struct btrfs_block_group_cache *block_group, | 75 | struct btrfs_block_group_cache *block_group, |
69 | struct btrfs_path *path); | 76 | struct btrfs_path *path); |
70 | |||
71 | struct inode *lookup_free_ino_inode(struct btrfs_root *root, | 77 | struct inode *lookup_free_ino_inode(struct btrfs_root *root, |
72 | struct btrfs_path *path); | 78 | struct btrfs_path *path); |
73 | int create_free_ino_inode(struct btrfs_root *root, | 79 | int create_free_ino_inode(struct btrfs_root *root, |