disk-io.c (fcb06702f023a0e7b1e6ebf9746f34b610ca0508) disk-io.c (533574c6bc30cf526cc1c41bde050c854a945efb)
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 393 unchanged lines hidden (view full) ---

402 mirror_num++;
403 if (mirror_num == failed_mirror)
404 mirror_num++;
405
406 if (mirror_num > num_copies)
407 break;
408 }
409
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 393 unchanged lines hidden (view full) ---

402 mirror_num++;
403 if (mirror_num == failed_mirror)
404 mirror_num++;
405
406 if (mirror_num > num_copies)
407 break;
408 }
409
410 if (failed && !ret)
410 if (failed && !ret && failed_mirror)
411 repair_eb_io_failure(root, eb, failed_mirror);
412
413 return ret;
414}
415
416/*
417 * checksum a dirty tree block before IO. This has extra checks to make sure
418 * we only fill in the checksum field in the first page of a multi-page block

--- 690 unchanged lines hidden (view full) ---

1109 if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)) {
1110 spin_lock(&root->fs_info->delalloc_lock);
1111 if (root->fs_info->dirty_metadata_bytes >= buf->len)
1112 root->fs_info->dirty_metadata_bytes -= buf->len;
1113 else {
1114 spin_unlock(&root->fs_info->delalloc_lock);
1115 btrfs_panic(root->fs_info, -EOVERFLOW,
1116 "Can't clear %lu bytes from "
411 repair_eb_io_failure(root, eb, failed_mirror);
412
413 return ret;
414}
415
416/*
417 * checksum a dirty tree block before IO. This has extra checks to make sure
418 * we only fill in the checksum field in the first page of a multi-page block

--- 690 unchanged lines hidden (view full) ---

1109 if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &buf->bflags)) {
1110 spin_lock(&root->fs_info->delalloc_lock);
1111 if (root->fs_info->dirty_metadata_bytes >= buf->len)
1112 root->fs_info->dirty_metadata_bytes -= buf->len;
1113 else {
1114 spin_unlock(&root->fs_info->delalloc_lock);
1115 btrfs_panic(root->fs_info, -EOVERFLOW,
1116 "Can't clear %lu bytes from "
1117 " dirty_mdatadata_bytes (%lu)",
1117 " dirty_mdatadata_bytes (%llu)",
1118 buf->len,
1119 root->fs_info->dirty_metadata_bytes);
1120 }
1121 spin_unlock(&root->fs_info->delalloc_lock);
1122 }
1123
1124 /* ugh, clear_extent_buffer_dirty needs to lock the page */
1125 btrfs_set_lock_blocking(buf);

--- 51 unchanged lines hidden (view full) ---

1177 memset(&root->root_item, 0, sizeof(root->root_item));
1178 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
1179 memset(&root->root_kobj, 0, sizeof(root->root_kobj));
1180 root->defrag_trans_start = fs_info->generation;
1181 init_completion(&root->kobj_unregister);
1182 root->defrag_running = 0;
1183 root->root_key.objectid = objectid;
1184 root->anon_dev = 0;
1118 buf->len,
1119 root->fs_info->dirty_metadata_bytes);
1120 }
1121 spin_unlock(&root->fs_info->delalloc_lock);
1122 }
1123
1124 /* ugh, clear_extent_buffer_dirty needs to lock the page */
1125 btrfs_set_lock_blocking(buf);

--- 51 unchanged lines hidden (view full) ---

1177 memset(&root->root_item, 0, sizeof(root->root_item));
1178 memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
1179 memset(&root->root_kobj, 0, sizeof(root->root_kobj));
1180 root->defrag_trans_start = fs_info->generation;
1181 init_completion(&root->kobj_unregister);
1182 root->defrag_running = 0;
1183 root->root_key.objectid = objectid;
1184 root->anon_dev = 0;
1185
1186 spin_lock_init(&root->root_times_lock);
1185}
1186
1187static int __must_check find_and_setup_root(struct btrfs_root *tree_root,
1188 struct btrfs_fs_info *fs_info,
1189 u64 objectid,
1190 struct btrfs_root *root)
1191{
1192 int ret;

--- 27 unchanged lines hidden (view full) ---

1220static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info)
1221{
1222 struct btrfs_root *root = kzalloc(sizeof(*root), GFP_NOFS);
1223 if (root)
1224 root->fs_info = fs_info;
1225 return root;
1226}
1227
1187}
1188
1189static int __must_check find_and_setup_root(struct btrfs_root *tree_root,
1190 struct btrfs_fs_info *fs_info,
1191 u64 objectid,
1192 struct btrfs_root *root)
1193{
1194 int ret;

--- 27 unchanged lines hidden (view full) ---

1222static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info)
1223{
1224 struct btrfs_root *root = kzalloc(sizeof(*root), GFP_NOFS);
1225 if (root)
1226 root->fs_info = fs_info;
1227 return root;
1228}
1229
1230struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
1231 struct btrfs_fs_info *fs_info,
1232 u64 objectid)
1233{
1234 struct extent_buffer *leaf;
1235 struct btrfs_root *tree_root = fs_info->tree_root;
1236 struct btrfs_root *root;
1237 struct btrfs_key key;
1238 int ret = 0;
1239 u64 bytenr;
1240
1241 root = btrfs_alloc_root(fs_info);
1242 if (!root)
1243 return ERR_PTR(-ENOMEM);
1244
1245 __setup_root(tree_root->nodesize, tree_root->leafsize,
1246 tree_root->sectorsize, tree_root->stripesize,
1247 root, fs_info, objectid);
1248 root->root_key.objectid = objectid;
1249 root->root_key.type = BTRFS_ROOT_ITEM_KEY;
1250 root->root_key.offset = 0;
1251
1252 leaf = btrfs_alloc_free_block(trans, root, root->leafsize,
1253 0, objectid, NULL, 0, 0, 0);
1254 if (IS_ERR(leaf)) {
1255 ret = PTR_ERR(leaf);
1256 goto fail;
1257 }
1258
1259 bytenr = leaf->start;
1260 memset_extent_buffer(leaf, 0, 0, sizeof(struct btrfs_header));
1261 btrfs_set_header_bytenr(leaf, leaf->start);
1262 btrfs_set_header_generation(leaf, trans->transid);
1263 btrfs_set_header_backref_rev(leaf, BTRFS_MIXED_BACKREF_REV);
1264 btrfs_set_header_owner(leaf, objectid);
1265 root->node = leaf;
1266
1267 write_extent_buffer(leaf, fs_info->fsid,
1268 (unsigned long)btrfs_header_fsid(leaf),
1269 BTRFS_FSID_SIZE);
1270 write_extent_buffer(leaf, fs_info->chunk_tree_uuid,
1271 (unsigned long)btrfs_header_chunk_tree_uuid(leaf),
1272 BTRFS_UUID_SIZE);
1273 btrfs_mark_buffer_dirty(leaf);
1274
1275 root->commit_root = btrfs_root_node(root);
1276 root->track_dirty = 1;
1277
1278
1279 root->root_item.flags = 0;
1280 root->root_item.byte_limit = 0;
1281 btrfs_set_root_bytenr(&root->root_item, leaf->start);
1282 btrfs_set_root_generation(&root->root_item, trans->transid);
1283 btrfs_set_root_level(&root->root_item, 0);
1284 btrfs_set_root_refs(&root->root_item, 1);
1285 btrfs_set_root_used(&root->root_item, leaf->len);
1286 btrfs_set_root_last_snapshot(&root->root_item, 0);
1287 btrfs_set_root_dirid(&root->root_item, 0);
1288 root->root_item.drop_level = 0;
1289
1290 key.objectid = objectid;
1291 key.type = BTRFS_ROOT_ITEM_KEY;
1292 key.offset = 0;
1293 ret = btrfs_insert_root(trans, tree_root, &key, &root->root_item);
1294 if (ret)
1295 goto fail;
1296
1297 btrfs_tree_unlock(leaf);
1298
1299fail:
1300 if (ret)
1301 return ERR_PTR(ret);
1302
1303 return root;
1304}
1305
1228static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1229 struct btrfs_fs_info *fs_info)
1230{
1231 struct btrfs_root *root;
1232 struct btrfs_root *tree_root = fs_info->tree_root;
1233 struct extent_buffer *leaf;
1234
1235 root = btrfs_alloc_root(fs_info);

--- 85 unchanged lines hidden (view full) ---

1321{
1322 struct btrfs_root *root;
1323 struct btrfs_fs_info *fs_info = tree_root->fs_info;
1324 struct btrfs_path *path;
1325 struct extent_buffer *l;
1326 u64 generation;
1327 u32 blocksize;
1328 int ret = 0;
1306static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
1307 struct btrfs_fs_info *fs_info)
1308{
1309 struct btrfs_root *root;
1310 struct btrfs_root *tree_root = fs_info->tree_root;
1311 struct extent_buffer *leaf;
1312
1313 root = btrfs_alloc_root(fs_info);

--- 85 unchanged lines hidden (view full) ---

1399{
1400 struct btrfs_root *root;
1401 struct btrfs_fs_info *fs_info = tree_root->fs_info;
1402 struct btrfs_path *path;
1403 struct extent_buffer *l;
1404 u64 generation;
1405 u32 blocksize;
1406 int ret = 0;
1407 int slot;
1329
1330 root = btrfs_alloc_root(fs_info);
1331 if (!root)
1332 return ERR_PTR(-ENOMEM);
1333 if (location->offset == (u64)-1) {
1334 ret = find_and_setup_root(tree_root, fs_info,
1335 location->objectid, root);
1336 if (ret) {

--- 10 unchanged lines hidden (view full) ---

1347 path = btrfs_alloc_path();
1348 if (!path) {
1349 kfree(root);
1350 return ERR_PTR(-ENOMEM);
1351 }
1352 ret = btrfs_search_slot(NULL, tree_root, location, path, 0, 0);
1353 if (ret == 0) {
1354 l = path->nodes[0];
1408
1409 root = btrfs_alloc_root(fs_info);
1410 if (!root)
1411 return ERR_PTR(-ENOMEM);
1412 if (location->offset == (u64)-1) {
1413 ret = find_and_setup_root(tree_root, fs_info,
1414 location->objectid, root);
1415 if (ret) {

--- 10 unchanged lines hidden (view full) ---

1426 path = btrfs_alloc_path();
1427 if (!path) {
1428 kfree(root);
1429 return ERR_PTR(-ENOMEM);
1430 }
1431 ret = btrfs_search_slot(NULL, tree_root, location, path, 0, 0);
1432 if (ret == 0) {
1433 l = path->nodes[0];
1355 read_extent_buffer(l, &root->root_item,
1356 btrfs_item_ptr_offset(l, path->slots[0]),
1357 sizeof(root->root_item));
1434 slot = path->slots[0];
1435 btrfs_read_root_item(tree_root, l, slot, &root->root_item);
1358 memcpy(&root->root_key, location, sizeof(*location));
1359 }
1360 btrfs_free_path(path);
1361 if (ret) {
1362 kfree(root);
1363 if (ret > 0)
1364 ret = -ENOENT;
1365 return ERR_PTR(ret);

--- 25 unchanged lines hidden (view full) ---

1391 if (location->objectid == BTRFS_EXTENT_TREE_OBJECTID)
1392 return fs_info->extent_root;
1393 if (location->objectid == BTRFS_CHUNK_TREE_OBJECTID)
1394 return fs_info->chunk_root;
1395 if (location->objectid == BTRFS_DEV_TREE_OBJECTID)
1396 return fs_info->dev_root;
1397 if (location->objectid == BTRFS_CSUM_TREE_OBJECTID)
1398 return fs_info->csum_root;
1436 memcpy(&root->root_key, location, sizeof(*location));
1437 }
1438 btrfs_free_path(path);
1439 if (ret) {
1440 kfree(root);
1441 if (ret > 0)
1442 ret = -ENOENT;
1443 return ERR_PTR(ret);

--- 25 unchanged lines hidden (view full) ---

1469 if (location->objectid == BTRFS_EXTENT_TREE_OBJECTID)
1470 return fs_info->extent_root;
1471 if (location->objectid == BTRFS_CHUNK_TREE_OBJECTID)
1472 return fs_info->chunk_root;
1473 if (location->objectid == BTRFS_DEV_TREE_OBJECTID)
1474 return fs_info->dev_root;
1475 if (location->objectid == BTRFS_CSUM_TREE_OBJECTID)
1476 return fs_info->csum_root;
1477 if (location->objectid == BTRFS_QUOTA_TREE_OBJECTID)
1478 return fs_info->quota_root ? fs_info->quota_root :
1479 ERR_PTR(-ENOENT);
1399again:
1400 spin_lock(&fs_info->fs_roots_radix_lock);
1401 root = radix_tree_lookup(&fs_info->fs_roots_radix,
1402 (unsigned long)location->objectid);
1403 spin_unlock(&fs_info->fs_roots_radix_lock);
1404 if (root)
1405 return root;
1406

--- 411 unchanged lines hidden (view full) ---

1818 free_extent_buffer(info->tree_root->node);
1819 free_extent_buffer(info->tree_root->commit_root);
1820 free_extent_buffer(info->dev_root->node);
1821 free_extent_buffer(info->dev_root->commit_root);
1822 free_extent_buffer(info->extent_root->node);
1823 free_extent_buffer(info->extent_root->commit_root);
1824 free_extent_buffer(info->csum_root->node);
1825 free_extent_buffer(info->csum_root->commit_root);
1480again:
1481 spin_lock(&fs_info->fs_roots_radix_lock);
1482 root = radix_tree_lookup(&fs_info->fs_roots_radix,
1483 (unsigned long)location->objectid);
1484 spin_unlock(&fs_info->fs_roots_radix_lock);
1485 if (root)
1486 return root;
1487

--- 411 unchanged lines hidden (view full) ---

1899 free_extent_buffer(info->tree_root->node);
1900 free_extent_buffer(info->tree_root->commit_root);
1901 free_extent_buffer(info->dev_root->node);
1902 free_extent_buffer(info->dev_root->commit_root);
1903 free_extent_buffer(info->extent_root->node);
1904 free_extent_buffer(info->extent_root->commit_root);
1905 free_extent_buffer(info->csum_root->node);
1906 free_extent_buffer(info->csum_root->commit_root);
1907 if (info->quota_root) {
1908 free_extent_buffer(info->quota_root->node);
1909 free_extent_buffer(info->quota_root->commit_root);
1910 }
1826
1827 info->tree_root->node = NULL;
1828 info->tree_root->commit_root = NULL;
1829 info->dev_root->node = NULL;
1830 info->dev_root->commit_root = NULL;
1831 info->extent_root->node = NULL;
1832 info->extent_root->commit_root = NULL;
1833 info->csum_root->node = NULL;
1834 info->csum_root->commit_root = NULL;
1911
1912 info->tree_root->node = NULL;
1913 info->tree_root->commit_root = NULL;
1914 info->dev_root->node = NULL;
1915 info->dev_root->commit_root = NULL;
1916 info->extent_root->node = NULL;
1917 info->extent_root->commit_root = NULL;
1918 info->csum_root->node = NULL;
1919 info->csum_root->commit_root = NULL;
1920 if (info->quota_root) {
1921 info->quota_root->node = NULL;
1922 info->quota_root->commit_root = NULL;
1923 }
1835
1836 if (chunk_root) {
1837 free_extent_buffer(info->chunk_root->node);
1838 free_extent_buffer(info->chunk_root->commit_root);
1839 info->chunk_root->node = NULL;
1840 info->chunk_root->commit_root = NULL;
1841 }
1842}

--- 14 unchanged lines hidden (view full) ---

1857 struct buffer_head *bh;
1858 struct btrfs_super_block *disk_super;
1859 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
1860 struct btrfs_root *tree_root;
1861 struct btrfs_root *extent_root;
1862 struct btrfs_root *csum_root;
1863 struct btrfs_root *chunk_root;
1864 struct btrfs_root *dev_root;
1924
1925 if (chunk_root) {
1926 free_extent_buffer(info->chunk_root->node);
1927 free_extent_buffer(info->chunk_root->commit_root);
1928 info->chunk_root->node = NULL;
1929 info->chunk_root->commit_root = NULL;
1930 }
1931}

--- 14 unchanged lines hidden (view full) ---

1946 struct buffer_head *bh;
1947 struct btrfs_super_block *disk_super;
1948 struct btrfs_fs_info *fs_info = btrfs_sb(sb);
1949 struct btrfs_root *tree_root;
1950 struct btrfs_root *extent_root;
1951 struct btrfs_root *csum_root;
1952 struct btrfs_root *chunk_root;
1953 struct btrfs_root *dev_root;
1954 struct btrfs_root *quota_root;
1865 struct btrfs_root *log_tree_root;
1866 int ret;
1867 int err = -EINVAL;
1868 int num_backups_tried = 0;
1869 int backup_index = 0;
1870
1871 tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info);
1872 extent_root = fs_info->extent_root = btrfs_alloc_root(fs_info);
1873 csum_root = fs_info->csum_root = btrfs_alloc_root(fs_info);
1874 chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info);
1875 dev_root = fs_info->dev_root = btrfs_alloc_root(fs_info);
1955 struct btrfs_root *log_tree_root;
1956 int ret;
1957 int err = -EINVAL;
1958 int num_backups_tried = 0;
1959 int backup_index = 0;
1960
1961 tree_root = fs_info->tree_root = btrfs_alloc_root(fs_info);
1962 extent_root = fs_info->extent_root = btrfs_alloc_root(fs_info);
1963 csum_root = fs_info->csum_root = btrfs_alloc_root(fs_info);
1964 chunk_root = fs_info->chunk_root = btrfs_alloc_root(fs_info);
1965 dev_root = fs_info->dev_root = btrfs_alloc_root(fs_info);
1966 quota_root = fs_info->quota_root = btrfs_alloc_root(fs_info);
1876
1877 if (!tree_root || !extent_root || !csum_root ||
1967
1968 if (!tree_root || !extent_root || !csum_root ||
1878 !chunk_root || !dev_root) {
1969 !chunk_root || !dev_root || !quota_root) {
1879 err = -ENOMEM;
1880 goto fail;
1881 }
1882
1883 ret = init_srcu_struct(&fs_info->subvol_srcu);
1884 if (ret) {
1885 err = ret;
1886 goto fail;

--- 52 unchanged lines hidden (view full) ---

1939 fs_info->sb = sb;
1940 fs_info->max_inline = 8192 * 1024;
1941 fs_info->metadata_ratio = 0;
1942 fs_info->defrag_inodes = RB_ROOT;
1943 fs_info->trans_no_join = 0;
1944 fs_info->free_chunk_space = 0;
1945 fs_info->tree_mod_log = RB_ROOT;
1946
1970 err = -ENOMEM;
1971 goto fail;
1972 }
1973
1974 ret = init_srcu_struct(&fs_info->subvol_srcu);
1975 if (ret) {
1976 err = ret;
1977 goto fail;

--- 52 unchanged lines hidden (view full) ---

2030 fs_info->sb = sb;
2031 fs_info->max_inline = 8192 * 1024;
2032 fs_info->metadata_ratio = 0;
2033 fs_info->defrag_inodes = RB_ROOT;
2034 fs_info->trans_no_join = 0;
2035 fs_info->free_chunk_space = 0;
2036 fs_info->tree_mod_log = RB_ROOT;
2037
2038 init_waitqueue_head(&fs_info->tree_mod_seq_wait);
2039
1947 /* readahead state */
1948 INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT);
1949 spin_lock_init(&fs_info->reada_lock);
1950
1951 fs_info->thread_pool_size = min_t(unsigned long,
1952 num_online_cpus() + 2, 8);
1953
1954 INIT_LIST_HEAD(&fs_info->ordered_extents);

--- 72 unchanged lines hidden (view full) ---

2027 mutex_init(&fs_info->chunk_mutex);
2028 mutex_init(&fs_info->transaction_kthread_mutex);
2029 mutex_init(&fs_info->cleaner_mutex);
2030 mutex_init(&fs_info->volume_mutex);
2031 init_rwsem(&fs_info->extent_commit_sem);
2032 init_rwsem(&fs_info->cleanup_work_sem);
2033 init_rwsem(&fs_info->subvol_sem);
2034
2040 /* readahead state */
2041 INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT);
2042 spin_lock_init(&fs_info->reada_lock);
2043
2044 fs_info->thread_pool_size = min_t(unsigned long,
2045 num_online_cpus() + 2, 8);
2046
2047 INIT_LIST_HEAD(&fs_info->ordered_extents);

--- 72 unchanged lines hidden (view full) ---

2120 mutex_init(&fs_info->chunk_mutex);
2121 mutex_init(&fs_info->transaction_kthread_mutex);
2122 mutex_init(&fs_info->cleaner_mutex);
2123 mutex_init(&fs_info->volume_mutex);
2124 init_rwsem(&fs_info->extent_commit_sem);
2125 init_rwsem(&fs_info->cleanup_work_sem);
2126 init_rwsem(&fs_info->subvol_sem);
2127
2128 spin_lock_init(&fs_info->qgroup_lock);
2129 fs_info->qgroup_tree = RB_ROOT;
2130 INIT_LIST_HEAD(&fs_info->dirty_qgroups);
2131 fs_info->qgroup_seq = 1;
2132 fs_info->quota_enabled = 0;
2133 fs_info->pending_quota_state = 0;
2134
2035 btrfs_init_free_cluster(&fs_info->meta_alloc_cluster);
2036 btrfs_init_free_cluster(&fs_info->data_alloc_cluster);
2037
2038 init_waitqueue_head(&fs_info->transaction_throttle);
2039 init_waitqueue_head(&fs_info->transaction_wait);
2040 init_waitqueue_head(&fs_info->transaction_blocked_wait);
2041 init_waitqueue_head(&fs_info->async_submit_wait);
2042

--- 196 unchanged lines hidden (view full) ---

2239 ret |= btrfs_start_workers(&fs_info->endio_meta_workers);
2240 ret |= btrfs_start_workers(&fs_info->endio_meta_write_workers);
2241 ret |= btrfs_start_workers(&fs_info->endio_write_workers);
2242 ret |= btrfs_start_workers(&fs_info->endio_freespace_worker);
2243 ret |= btrfs_start_workers(&fs_info->delayed_workers);
2244 ret |= btrfs_start_workers(&fs_info->caching_workers);
2245 ret |= btrfs_start_workers(&fs_info->readahead_workers);
2246 if (ret) {
2135 btrfs_init_free_cluster(&fs_info->meta_alloc_cluster);
2136 btrfs_init_free_cluster(&fs_info->data_alloc_cluster);
2137
2138 init_waitqueue_head(&fs_info->transaction_throttle);
2139 init_waitqueue_head(&fs_info->transaction_wait);
2140 init_waitqueue_head(&fs_info->transaction_blocked_wait);
2141 init_waitqueue_head(&fs_info->async_submit_wait);
2142

--- 196 unchanged lines hidden (view full) ---

2339 ret |= btrfs_start_workers(&fs_info->endio_meta_workers);
2340 ret |= btrfs_start_workers(&fs_info->endio_meta_write_workers);
2341 ret |= btrfs_start_workers(&fs_info->endio_write_workers);
2342 ret |= btrfs_start_workers(&fs_info->endio_freespace_worker);
2343 ret |= btrfs_start_workers(&fs_info->delayed_workers);
2344 ret |= btrfs_start_workers(&fs_info->caching_workers);
2345 ret |= btrfs_start_workers(&fs_info->readahead_workers);
2346 if (ret) {
2247 ret = -ENOMEM;
2347 err = -ENOMEM;
2248 goto fail_sb_buffer;
2249 }
2250
2251 fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super);
2252 fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages,
2253 4 * 1024 * 1024 / PAGE_CACHE_SIZE);
2254
2255 tree_root->nodesize = nodesize;

--- 95 unchanged lines hidden (view full) ---

2351 dev_root->track_dirty = 1;
2352
2353 ret = find_and_setup_root(tree_root, fs_info,
2354 BTRFS_CSUM_TREE_OBJECTID, csum_root);
2355 if (ret)
2356 goto recovery_tree_root;
2357 csum_root->track_dirty = 1;
2358
2348 goto fail_sb_buffer;
2349 }
2350
2351 fs_info->bdi.ra_pages *= btrfs_super_num_devices(disk_super);
2352 fs_info->bdi.ra_pages = max(fs_info->bdi.ra_pages,
2353 4 * 1024 * 1024 / PAGE_CACHE_SIZE);
2354
2355 tree_root->nodesize = nodesize;

--- 95 unchanged lines hidden (view full) ---

2451 dev_root->track_dirty = 1;
2452
2453 ret = find_and_setup_root(tree_root, fs_info,
2454 BTRFS_CSUM_TREE_OBJECTID, csum_root);
2455 if (ret)
2456 goto recovery_tree_root;
2457 csum_root->track_dirty = 1;
2458
2459 ret = find_and_setup_root(tree_root, fs_info,
2460 BTRFS_QUOTA_TREE_OBJECTID, quota_root);
2461 if (ret) {
2462 kfree(quota_root);
2463 quota_root = fs_info->quota_root = NULL;
2464 } else {
2465 quota_root->track_dirty = 1;
2466 fs_info->quota_enabled = 1;
2467 fs_info->pending_quota_state = 1;
2468 }
2469
2359 fs_info->generation = generation;
2360 fs_info->last_trans_committed = generation;
2361
2362 ret = btrfs_recover_balance(fs_info);
2363 if (ret) {
2364 printk(KERN_WARNING "btrfs: failed to recover balance\n");
2365 goto fail_block_groups;
2366 }

--- 43 unchanged lines hidden (view full) ---

2410 CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
2411 1 : 0,
2412 fs_info->check_integrity_print_mask);
2413 if (ret)
2414 printk(KERN_WARNING "btrfs: failed to initialize"
2415 " integrity check module %s\n", sb->s_id);
2416 }
2417#endif
2470 fs_info->generation = generation;
2471 fs_info->last_trans_committed = generation;
2472
2473 ret = btrfs_recover_balance(fs_info);
2474 if (ret) {
2475 printk(KERN_WARNING "btrfs: failed to recover balance\n");
2476 goto fail_block_groups;
2477 }

--- 43 unchanged lines hidden (view full) ---

2521 CHECK_INTEGRITY_INCLUDING_EXTENT_DATA) ?
2522 1 : 0,
2523 fs_info->check_integrity_print_mask);
2524 if (ret)
2525 printk(KERN_WARNING "btrfs: failed to initialize"
2526 " integrity check module %s\n", sb->s_id);
2527 }
2528#endif
2529 ret = btrfs_read_qgroup_config(fs_info);
2530 if (ret)
2531 goto fail_trans_kthread;
2418
2419 /* do not make disk changes in broken FS */
2420 if (btrfs_super_log_root(disk_super) != 0 &&
2421 !(fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR)) {
2422 u64 bytenr = btrfs_super_log_root(disk_super);
2423
2424 if (fs_devices->rw_devices == 0) {
2425 printk(KERN_WARNING "Btrfs log replay required "
2426 "on RO media\n");
2427 err = -EIO;
2532
2533 /* do not make disk changes in broken FS */
2534 if (btrfs_super_log_root(disk_super) != 0 &&
2535 !(fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR)) {
2536 u64 bytenr = btrfs_super_log_root(disk_super);
2537
2538 if (fs_devices->rw_devices == 0) {
2539 printk(KERN_WARNING "Btrfs log replay required "
2540 "on RO media\n");
2541 err = -EIO;
2428 goto fail_trans_kthread;
2542 goto fail_qgroup;
2429 }
2430 blocksize =
2431 btrfs_level_size(tree_root,
2432 btrfs_super_log_root_level(disk_super));
2433
2434 log_tree_root = btrfs_alloc_root(fs_info);
2435 if (!log_tree_root) {
2436 err = -ENOMEM;
2543 }
2544 blocksize =
2545 btrfs_level_size(tree_root,
2546 btrfs_super_log_root_level(disk_super));
2547
2548 log_tree_root = btrfs_alloc_root(fs_info);
2549 if (!log_tree_root) {
2550 err = -ENOMEM;
2437 goto fail_trans_kthread;
2551 goto fail_qgroup;
2438 }
2439
2440 __setup_root(nodesize, leafsize, sectorsize, stripesize,
2441 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
2442
2443 log_tree_root->node = read_tree_block(tree_root, bytenr,
2444 blocksize,
2445 generation + 1);

--- 15 unchanged lines hidden (view full) ---

2461 }
2462
2463 ret = btrfs_find_orphan_roots(tree_root);
2464 if (ret)
2465 goto fail_trans_kthread;
2466
2467 if (!(sb->s_flags & MS_RDONLY)) {
2468 ret = btrfs_cleanup_fs_roots(fs_info);
2552 }
2553
2554 __setup_root(nodesize, leafsize, sectorsize, stripesize,
2555 log_tree_root, fs_info, BTRFS_TREE_LOG_OBJECTID);
2556
2557 log_tree_root->node = read_tree_block(tree_root, bytenr,
2558 blocksize,
2559 generation + 1);

--- 15 unchanged lines hidden (view full) ---

2575 }
2576
2577 ret = btrfs_find_orphan_roots(tree_root);
2578 if (ret)
2579 goto fail_trans_kthread;
2580
2581 if (!(sb->s_flags & MS_RDONLY)) {
2582 ret = btrfs_cleanup_fs_roots(fs_info);
2469 if (ret) {
2470 }
2583 if (ret)
2584 goto fail_trans_kthread;
2471
2472 ret = btrfs_recover_relocation(tree_root);
2473 if (ret < 0) {
2474 printk(KERN_WARNING
2475 "btrfs: failed to recover relocation\n");
2476 err = -EINVAL;
2585
2586 ret = btrfs_recover_relocation(tree_root);
2587 if (ret < 0) {
2588 printk(KERN_WARNING
2589 "btrfs: failed to recover relocation\n");
2590 err = -EINVAL;
2477 goto fail_trans_kthread;
2591 goto fail_qgroup;
2478 }
2479 }
2480
2481 location.objectid = BTRFS_FS_TREE_OBJECTID;
2482 location.type = BTRFS_ROOT_ITEM_KEY;
2483 location.offset = (u64)-1;
2484
2485 fs_info->fs_root = btrfs_read_fs_root_no_name(fs_info, &location);
2486 if (!fs_info->fs_root)
2592 }
2593 }
2594
2595 location.objectid = BTRFS_FS_TREE_OBJECTID;
2596 location.type = BTRFS_ROOT_ITEM_KEY;
2597 location.offset = (u64)-1;
2598
2599 fs_info->fs_root = btrfs_read_fs_root_no_name(fs_info, &location);
2600 if (!fs_info->fs_root)
2487 goto fail_trans_kthread;
2601 goto fail_qgroup;
2488 if (IS_ERR(fs_info->fs_root)) {
2489 err = PTR_ERR(fs_info->fs_root);
2602 if (IS_ERR(fs_info->fs_root)) {
2603 err = PTR_ERR(fs_info->fs_root);
2490 goto fail_trans_kthread;
2604 goto fail_qgroup;
2491 }
2492
2493 if (sb->s_flags & MS_RDONLY)
2494 return 0;
2495
2496 down_read(&fs_info->cleanup_work_sem);
2497 if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) ||
2498 (ret = btrfs_orphan_cleanup(fs_info->tree_root))) {

--- 7 unchanged lines hidden (view full) ---

2506 if (ret) {
2507 printk(KERN_WARNING "btrfs: failed to resume balance\n");
2508 close_ctree(tree_root);
2509 return ret;
2510 }
2511
2512 return 0;
2513
2605 }
2606
2607 if (sb->s_flags & MS_RDONLY)
2608 return 0;
2609
2610 down_read(&fs_info->cleanup_work_sem);
2611 if ((ret = btrfs_orphan_cleanup(fs_info->fs_root)) ||
2612 (ret = btrfs_orphan_cleanup(fs_info->tree_root))) {

--- 7 unchanged lines hidden (view full) ---

2620 if (ret) {
2621 printk(KERN_WARNING "btrfs: failed to resume balance\n");
2622 close_ctree(tree_root);
2623 return ret;
2624 }
2625
2626 return 0;
2627
2628fail_qgroup:
2629 btrfs_free_qgroup_config(fs_info);
2514fail_trans_kthread:
2515 kthread_stop(fs_info->transaction_kthread);
2516fail_cleaner:
2517 kthread_stop(fs_info->cleaner_kthread);
2518
2519 /*
2520 * make sure we're done with the btree inode before we stop our
2521 * kthreads

--- 582 unchanged lines hidden (view full) ---

3104 btrfs_put_block_group_cache(fs_info);
3105
3106 kthread_stop(fs_info->transaction_kthread);
3107 kthread_stop(fs_info->cleaner_kthread);
3108
3109 fs_info->closing = 2;
3110 smp_mb();
3111
2630fail_trans_kthread:
2631 kthread_stop(fs_info->transaction_kthread);
2632fail_cleaner:
2633 kthread_stop(fs_info->cleaner_kthread);
2634
2635 /*
2636 * make sure we're done with the btree inode before we stop our
2637 * kthreads

--- 582 unchanged lines hidden (view full) ---

3220 btrfs_put_block_group_cache(fs_info);
3221
3222 kthread_stop(fs_info->transaction_kthread);
3223 kthread_stop(fs_info->cleaner_kthread);
3224
3225 fs_info->closing = 2;
3226 smp_mb();
3227
3228 btrfs_free_qgroup_config(root->fs_info);
3229
3112 if (fs_info->delalloc_bytes) {
3113 printk(KERN_INFO "btrfs: at unmount delalloc count %llu\n",
3114 (unsigned long long)fs_info->delalloc_bytes);
3115 }
3116 if (fs_info->total_ref_cache_size) {
3117 printk(KERN_INFO "btrfs: at umount reference cache size %llu\n",
3118 (unsigned long long)fs_info->total_ref_cache_size);
3119 }
3120
3121 free_extent_buffer(fs_info->extent_root->node);
3122 free_extent_buffer(fs_info->extent_root->commit_root);
3123 free_extent_buffer(fs_info->tree_root->node);
3124 free_extent_buffer(fs_info->tree_root->commit_root);
3125 free_extent_buffer(fs_info->chunk_root->node);
3126 free_extent_buffer(fs_info->chunk_root->commit_root);
3127 free_extent_buffer(fs_info->dev_root->node);
3128 free_extent_buffer(fs_info->dev_root->commit_root);
3129 free_extent_buffer(fs_info->csum_root->node);
3130 free_extent_buffer(fs_info->csum_root->commit_root);
3230 if (fs_info->delalloc_bytes) {
3231 printk(KERN_INFO "btrfs: at unmount delalloc count %llu\n",
3232 (unsigned long long)fs_info->delalloc_bytes);
3233 }
3234 if (fs_info->total_ref_cache_size) {
3235 printk(KERN_INFO "btrfs: at umount reference cache size %llu\n",
3236 (unsigned long long)fs_info->total_ref_cache_size);
3237 }
3238
3239 free_extent_buffer(fs_info->extent_root->node);
3240 free_extent_buffer(fs_info->extent_root->commit_root);
3241 free_extent_buffer(fs_info->tree_root->node);
3242 free_extent_buffer(fs_info->tree_root->commit_root);
3243 free_extent_buffer(fs_info->chunk_root->node);
3244 free_extent_buffer(fs_info->chunk_root->commit_root);
3245 free_extent_buffer(fs_info->dev_root->node);
3246 free_extent_buffer(fs_info->dev_root->commit_root);
3247 free_extent_buffer(fs_info->csum_root->node);
3248 free_extent_buffer(fs_info->csum_root->commit_root);
3249 if (fs_info->quota_root) {
3250 free_extent_buffer(fs_info->quota_root->node);
3251 free_extent_buffer(fs_info->quota_root->commit_root);
3252 }
3131
3132 btrfs_free_block_groups(fs_info);
3133
3134 del_fs_roots(fs_info);
3135
3136 iput(fs_info->btree_inode);
3137
3138 btrfs_stop_workers(&fs_info->generic_worker);

--- 114 unchanged lines hidden (view full) ---

3253}
3254
3255int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid)
3256{
3257 struct btrfs_root *root = BTRFS_I(buf->pages[0]->mapping->host)->root;
3258 return btree_read_extent_buffer_pages(root, buf, 0, parent_transid);
3259}
3260
3253
3254 btrfs_free_block_groups(fs_info);
3255
3256 del_fs_roots(fs_info);
3257
3258 iput(fs_info->btree_inode);
3259
3260 btrfs_stop_workers(&fs_info->generic_worker);

--- 114 unchanged lines hidden (view full) ---

3375}
3376
3377int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid)
3378{
3379 struct btrfs_root *root = BTRFS_I(buf->pages[0]->mapping->host)->root;
3380 return btree_read_extent_buffer_pages(root, buf, 0, parent_transid);
3381}
3382
3261static int btree_lock_page_hook(struct page *page, void *data,
3383int btree_lock_page_hook(struct page *page, void *data,
3262 void (*flush_fn)(void *))
3263{
3264 struct inode *inode = page->mapping->host;
3265 struct btrfs_root *root = BTRFS_I(inode)->root;
3266 struct extent_buffer *eb;
3267
3268 /*
3269 * We culled this eb but the page is still hanging out on the mapping,

--- 446 unchanged lines hidden ---
3384 void (*flush_fn)(void *))
3385{
3386 struct inode *inode = page->mapping->host;
3387 struct btrfs_root *root = BTRFS_I(inode)->root;
3388 struct extent_buffer *eb;
3389
3390 /*
3391 * We culled this eb but the page is still hanging out on the mapping,

--- 446 unchanged lines hidden ---