]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
Btrfs: tweak the inode-map and free extent search starts on cold mount
authorChris Mason <chris.mason@oracle.com>
Wed, 4 Apr 2007 19:27:52 +0000 (15:27 -0400)
committerDavid Woodhouse <dwmw2@hera.kernel.org>
Wed, 4 Apr 2007 19:27:52 +0000 (15:27 -0400)
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/TODO
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/inode-map.c

index e9371385ccc01ac6b9c5e02181039c49352a7313..db986c46a554c2e80fa5a9313749008be095031e 100644 (file)
@@ -1,9 +1,7 @@
 * cleanup, add more error checking, get rid of BUG_ONs
 * Fix ENOSPC handling
-* Do checksumming
 * Add block mapping tree (simple dm layer)
 * Make allocator smarter
-* make level a field in header
 * add a block group to struct inode
 * Make directory hashing work on 32 bit
 * Make sure nobh stuff is working properly for cows
index d8e03bd797ff6338d09c36a643581ee4156bec78..41cc013ef08de6c1e971d7883a34efb08ea71591 100644 (file)
@@ -238,7 +238,6 @@ struct btrfs_fs_info {
        struct radix_tree_root pending_del_radix;
        struct radix_tree_root pinned_radix;
        u64 last_inode_alloc;
-       u64 last_inode_alloc_dirid;
        u64 generation;
        struct btrfs_transaction *running_transaction;
        struct btrfs_super_block *disk_super;
index 055cd45e802e0c794960d0ba3d72a826fdeb83b4..de9ee3aa0aad53d0437b0dae4df193429e20faf1 100644 (file)
@@ -311,7 +311,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
        fs_info->extent_root = extent_root;
        fs_info->inode_root = inode_root;
        fs_info->last_inode_alloc = 0;
-       fs_info->last_inode_alloc_dirid = 0;
        fs_info->sb = sb;
        fs_info->btree_inode = new_inode(sb);
        fs_info->btree_inode->i_ino = 1;
index cd40a08dd8a666af9b0a77bb7e2cf17e16101544..688aa861a9281c09ed807d8845e18f773b7bc759 100644 (file)
@@ -339,13 +339,30 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
        int total_needed = num_blocks;
        int level;
 
+       path = btrfs_alloc_path();
+       ins->flags = 0;
+       btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY);
+
        level = btrfs_header_level(btrfs_buffer_header(root->node));
        total_needed += (level + 1) * 3;
+       if (root->fs_info->last_insert.objectid == 0 && search_end == (u64)-1) {
+               struct btrfs_disk_key *last_key;
+               btrfs_init_path(path);
+               ins->objectid = (u64)-1;
+               ins->offset = (u64)-1;
+               ret = btrfs_search_slot(trans, root, ins, path, 0, 0);
+               if (ret < 0)
+                       goto error;
+               BUG_ON(ret == 0);
+               if (path->slots[0] > 0)
+                       path->slots[0]--;
+               l = btrfs_buffer_leaf(path->nodes[0]);
+               last_key = &l->items[path->slots[0]].key;
+               search_start = btrfs_disk_key_objectid(last_key);
+       }
        if (root->fs_info->last_insert.objectid > search_start)
                search_start = root->fs_info->last_insert.objectid;
 
-       ins->flags = 0;
-       btrfs_set_key_type(ins, BTRFS_EXTENT_ITEM_KEY);
        path = btrfs_alloc_path();
 
 check_failed:
index b3de823eb628d31735eae51f5a418aae36d54cad..329edb42897ef3dff064278f7bd13e804c8f03ae 100644 (file)
@@ -22,17 +22,31 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
        struct btrfs_key search_key;
        u64 search_start = dirid;
 
-       if (fs_root->fs_info->last_inode_alloc_dirid == dirid)
-               search_start = fs_root->fs_info->last_inode_alloc;
+       path = btrfs_alloc_path();
+       BUG_ON(!path);
+       search_key.flags = 0;
+       btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY);
 
+       search_start = fs_root->fs_info->last_inode_alloc;
+       if (search_start == 0) {
+               struct btrfs_disk_key *last_key;
+               btrfs_init_path(path);
+               search_key.objectid = (u64)-1;
+               search_key.offset = (u64)-1;
+               ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0);
+               if (ret < 0)
+                       goto error;
+               BUG_ON(ret == 0);
+               if (path->slots[0] > 0)
+                       path->slots[0]--;
+               l = btrfs_buffer_leaf(path->nodes[0]);
+               last_key = &l->items[path->slots[0]].key;
+               search_start = btrfs_disk_key_objectid(last_key);
+       }
        search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID);
        search_key.objectid = search_start;
-       search_key.flags = 0;
-       btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY);
        search_key.offset = 0;
 
-       path = btrfs_alloc_path();
-       BUG_ON(!path);
        btrfs_init_path(path);
        start_found = 0;
        ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0);
@@ -79,7 +93,6 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
        // FIXME -ENOSPC
 found:
        root->fs_info->last_inode_alloc = *objectid;
-       root->fs_info->last_inode_alloc_dirid = dirid;
        btrfs_release_path(root, path);
        btrfs_free_path(path);
        BUG_ON(*objectid < search_start);