Commit 23125104 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: make btrfs_root::free_objectid hold the next available objectid

Adjust the way free_objectid is being initialized, it now stores
BTRFS_FIRST_FREE_OBJECTID rather than the, somewhat arbitrary,
BTRFS_FIRST_FREE_OBJECTID - 1. This change also has the added benefit
that now it becomes unnecessary to explicitly initialize free_objectid
for a newly create fs root.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 6b8fad57
...@@ -4767,10 +4767,10 @@ int btrfs_init_root_free_objectid(struct btrfs_root *root) ...@@ -4767,10 +4767,10 @@ int btrfs_init_root_free_objectid(struct btrfs_root *root)
slot = path->slots[0] - 1; slot = path->slots[0] - 1;
l = path->nodes[0]; l = path->nodes[0];
btrfs_item_key_to_cpu(l, &found_key, slot); btrfs_item_key_to_cpu(l, &found_key, slot);
root->free_objectid = max_t(u64, found_key.objectid, root->free_objectid = max_t(u64, found_key.objectid + 1,
BTRFS_FIRST_FREE_OBJECTID - 1); BTRFS_FIRST_FREE_OBJECTID);
} else { } else {
root->free_objectid = BTRFS_FIRST_FREE_OBJECTID - 1; root->free_objectid = BTRFS_FIRST_FREE_OBJECTID;
} }
ret = 0; ret = 0;
error: error:
...@@ -4791,7 +4791,7 @@ int btrfs_get_free_objectid(struct btrfs_root *root, u64 *objectid) ...@@ -4791,7 +4791,7 @@ int btrfs_get_free_objectid(struct btrfs_root *root, u64 *objectid)
goto out; goto out;
} }
*objectid = ++root->free_objectid; *objectid = root->free_objectid++;
ret = 0; ret = 0;
out: out:
mutex_unlock(&root->objectid_mutex); mutex_unlock(&root->objectid_mutex);
......
...@@ -8598,9 +8598,13 @@ int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, ...@@ -8598,9 +8598,13 @@ int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
struct inode *inode; struct inode *inode;
int err; int err;
u64 index = 0; u64 index = 0;
u64 ino;
err = btrfs_get_free_objectid(new_root, &ino);
if (err < 0)
return err;
inode = btrfs_new_inode(trans, new_root, NULL, "..", 2, inode = btrfs_new_inode(trans, new_root, NULL, "..", 2, ino, ino,
new_dirid, new_dirid,
S_IFDIR | (~current_umask() & S_IRWXUGO), S_IFDIR | (~current_umask() & S_IRWXUGO),
&index); &index);
if (IS_ERR(inode)) if (IS_ERR(inode))
......
...@@ -724,10 +724,6 @@ static noinline int create_subvol(struct inode *dir, ...@@ -724,10 +724,6 @@ static noinline int create_subvol(struct inode *dir,
goto fail; goto fail;
} }
mutex_lock(&new_root->objectid_mutex);
new_root->free_objectid = new_dirid;
mutex_unlock(&new_root->objectid_mutex);
/* /*
* insert the directory item * insert the directory item
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment