.. | .. |
---|
220 | 220 | crypto_shash_update(shash, kaddr + BTRFS_CSUM_SIZE, |
---|
221 | 221 | PAGE_SIZE - BTRFS_CSUM_SIZE); |
---|
222 | 222 | |
---|
223 | | - for (i = 1; i < num_pages; i++) { |
---|
| 223 | + for (i = 1; i < num_pages && INLINE_EXTENT_BUFFER_PAGES > 1; i++) { |
---|
224 | 224 | kaddr = page_address(buf->pages[i]); |
---|
225 | 225 | crypto_shash_update(shash, kaddr, PAGE_SIZE); |
---|
226 | 226 | } |
---|
.. | .. |
---|
2246 | 2246 | |
---|
2247 | 2247 | fs_info->csum_shash = csum_shash; |
---|
2248 | 2248 | |
---|
| 2249 | + /* |
---|
| 2250 | + * Check if the checksum implementation is a fast accelerated one. |
---|
| 2251 | + * As-is this is a bit of a hack and should be replaced once the csum |
---|
| 2252 | + * implementations provide that information themselves. |
---|
| 2253 | + */ |
---|
| 2254 | + switch (csum_type) { |
---|
| 2255 | + case BTRFS_CSUM_TYPE_CRC32: |
---|
| 2256 | + if (!strstr(crypto_shash_driver_name(csum_shash), "generic")) |
---|
| 2257 | + set_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags); |
---|
| 2258 | + break; |
---|
| 2259 | + case BTRFS_CSUM_TYPE_XXHASH: |
---|
| 2260 | + set_bit(BTRFS_FS_CSUM_IMPL_FAST, &fs_info->flags); |
---|
| 2261 | + break; |
---|
| 2262 | + default: |
---|
| 2263 | + break; |
---|
| 2264 | + } |
---|
| 2265 | + |
---|
| 2266 | + btrfs_info(fs_info, "using %s (%s) checksum algorithm", |
---|
| 2267 | + btrfs_super_csum_name(csum_type), |
---|
| 2268 | + crypto_shash_driver_name(csum_shash)); |
---|
2249 | 2269 | return 0; |
---|
2250 | 2270 | } |
---|
2251 | 2271 | |
---|
.. | .. |
---|
2476 | 2496 | ret = -EINVAL; |
---|
2477 | 2497 | } |
---|
2478 | 2498 | |
---|
2479 | | - if (memcmp(fs_info->fs_devices->fsid, fs_info->super_copy->fsid, |
---|
2480 | | - BTRFS_FSID_SIZE)) { |
---|
| 2499 | + if (memcmp(fs_info->fs_devices->fsid, sb->fsid, BTRFS_FSID_SIZE) != 0) { |
---|
2481 | 2500 | btrfs_err(fs_info, |
---|
2482 | 2501 | "superblock fsid doesn't match fsid of fs_devices: %pU != %pU", |
---|
2483 | | - fs_info->super_copy->fsid, fs_info->fs_devices->fsid); |
---|
| 2502 | + sb->fsid, fs_info->fs_devices->fsid); |
---|
2484 | 2503 | ret = -EINVAL; |
---|
2485 | 2504 | } |
---|
2486 | 2505 | |
---|
2487 | | - if (btrfs_fs_incompat(fs_info, METADATA_UUID) && |
---|
2488 | | - memcmp(fs_info->fs_devices->metadata_uuid, |
---|
2489 | | - fs_info->super_copy->metadata_uuid, BTRFS_FSID_SIZE)) { |
---|
| 2506 | + if (memcmp(fs_info->fs_devices->metadata_uuid, btrfs_sb_fsid_ptr(sb), |
---|
| 2507 | + BTRFS_FSID_SIZE) != 0) { |
---|
2490 | 2508 | btrfs_err(fs_info, |
---|
2491 | 2509 | "superblock metadata_uuid doesn't match metadata uuid of fs_devices: %pU != %pU", |
---|
2492 | | - fs_info->super_copy->metadata_uuid, |
---|
2493 | | - fs_info->fs_devices->metadata_uuid); |
---|
| 2510 | + btrfs_sb_fsid_ptr(sb), fs_info->fs_devices->metadata_uuid); |
---|
2494 | 2511 | ret = -EINVAL; |
---|
2495 | 2512 | } |
---|
2496 | 2513 | |
---|
.. | .. |
---|
4518 | 4535 | */ |
---|
4519 | 4536 | inode = igrab(&btrfs_inode->vfs_inode); |
---|
4520 | 4537 | if (inode) { |
---|
| 4538 | + unsigned int nofs_flag; |
---|
| 4539 | + |
---|
| 4540 | + nofs_flag = memalloc_nofs_save(); |
---|
4521 | 4541 | invalidate_inode_pages2(inode->i_mapping); |
---|
| 4542 | + memalloc_nofs_restore(nofs_flag); |
---|
4522 | 4543 | iput(inode); |
---|
4523 | 4544 | } |
---|
4524 | 4545 | spin_lock(&root->delalloc_lock); |
---|
.. | .. |
---|
4623 | 4644 | |
---|
4624 | 4645 | inode = cache->io_ctl.inode; |
---|
4625 | 4646 | if (inode) { |
---|
| 4647 | + unsigned int nofs_flag; |
---|
| 4648 | + |
---|
| 4649 | + nofs_flag = memalloc_nofs_save(); |
---|
4626 | 4650 | invalidate_inode_pages2(inode->i_mapping); |
---|
| 4651 | + memalloc_nofs_restore(nofs_flag); |
---|
| 4652 | + |
---|
4627 | 4653 | BTRFS_I(inode)->generation = 0; |
---|
4628 | 4654 | cache->io_ctl.inode = NULL; |
---|
4629 | 4655 | iput(inode); |
---|
.. | .. |
---|
4763 | 4789 | |
---|
4764 | 4790 | return 0; |
---|
4765 | 4791 | } |
---|
| 4792 | + |
---|
| 4793 | +int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid) |
---|
| 4794 | +{ |
---|
| 4795 | + struct btrfs_path *path; |
---|
| 4796 | + int ret; |
---|
| 4797 | + struct extent_buffer *l; |
---|
| 4798 | + struct btrfs_key search_key; |
---|
| 4799 | + struct btrfs_key found_key; |
---|
| 4800 | + int slot; |
---|
| 4801 | + |
---|
| 4802 | + path = btrfs_alloc_path(); |
---|
| 4803 | + if (!path) |
---|
| 4804 | + return -ENOMEM; |
---|
| 4805 | + |
---|
| 4806 | + search_key.objectid = BTRFS_LAST_FREE_OBJECTID; |
---|
| 4807 | + search_key.type = -1; |
---|
| 4808 | + search_key.offset = (u64)-1; |
---|
| 4809 | + ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); |
---|
| 4810 | + if (ret < 0) |
---|
| 4811 | + goto error; |
---|
| 4812 | + BUG_ON(ret == 0); /* Corruption */ |
---|
| 4813 | + if (path->slots[0] > 0) { |
---|
| 4814 | + slot = path->slots[0] - 1; |
---|
| 4815 | + l = path->nodes[0]; |
---|
| 4816 | + btrfs_item_key_to_cpu(l, &found_key, slot); |
---|
| 4817 | + *objectid = max_t(u64, found_key.objectid, |
---|
| 4818 | + BTRFS_FIRST_FREE_OBJECTID - 1); |
---|
| 4819 | + } else { |
---|
| 4820 | + *objectid = BTRFS_FIRST_FREE_OBJECTID - 1; |
---|
| 4821 | + } |
---|
| 4822 | + ret = 0; |
---|
| 4823 | +error: |
---|
| 4824 | + btrfs_free_path(path); |
---|
| 4825 | + return ret; |
---|
| 4826 | +} |
---|
| 4827 | + |
---|
| 4828 | +int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid) |
---|
| 4829 | +{ |
---|
| 4830 | + int ret; |
---|
| 4831 | + mutex_lock(&root->objectid_mutex); |
---|
| 4832 | + |
---|
| 4833 | + if (unlikely(root->highest_objectid >= BTRFS_LAST_FREE_OBJECTID)) { |
---|
| 4834 | + btrfs_warn(root->fs_info, |
---|
| 4835 | + "the objectid of root %llu reaches its highest value", |
---|
| 4836 | + root->root_key.objectid); |
---|
| 4837 | + ret = -ENOSPC; |
---|
| 4838 | + goto out; |
---|
| 4839 | + } |
---|
| 4840 | + |
---|
| 4841 | + *objectid = ++root->highest_objectid; |
---|
| 4842 | + ret = 0; |
---|
| 4843 | +out: |
---|
| 4844 | + mutex_unlock(&root->objectid_mutex); |
---|
| 4845 | + return ret; |
---|
| 4846 | +} |
---|