btrfs: move btrfs_find_highest_objectid/btrfs_find_free_objectid to disk-io.c
Those functions are going to be used even after inode cache is removed so moved them to a more appropriate place. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
1201b58b67
commit
ec7d6dfd73
|
@ -4735,3 +4735,58 @@ static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid)
|
||||||
|
{
|
||||||
|
struct btrfs_path *path;
|
||||||
|
int ret;
|
||||||
|
struct extent_buffer *l;
|
||||||
|
struct btrfs_key search_key;
|
||||||
|
struct btrfs_key found_key;
|
||||||
|
int slot;
|
||||||
|
|
||||||
|
path = btrfs_alloc_path();
|
||||||
|
if (!path)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
search_key.objectid = BTRFS_LAST_FREE_OBJECTID;
|
||||||
|
search_key.type = -1;
|
||||||
|
search_key.offset = (u64)-1;
|
||||||
|
ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
|
||||||
|
if (ret < 0)
|
||||||
|
goto error;
|
||||||
|
BUG_ON(ret == 0); /* Corruption */
|
||||||
|
if (path->slots[0] > 0) {
|
||||||
|
slot = path->slots[0] - 1;
|
||||||
|
l = path->nodes[0];
|
||||||
|
btrfs_item_key_to_cpu(l, &found_key, slot);
|
||||||
|
*objectid = max_t(u64, found_key.objectid,
|
||||||
|
BTRFS_FIRST_FREE_OBJECTID - 1);
|
||||||
|
} else {
|
||||||
|
*objectid = BTRFS_FIRST_FREE_OBJECTID - 1;
|
||||||
|
}
|
||||||
|
ret = 0;
|
||||||
|
error:
|
||||||
|
btrfs_free_path(path);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
mutex_lock(&root->objectid_mutex);
|
||||||
|
|
||||||
|
if (unlikely(root->highest_objectid >= BTRFS_LAST_FREE_OBJECTID)) {
|
||||||
|
btrfs_warn(root->fs_info,
|
||||||
|
"the objectid of root %llu reaches its highest value",
|
||||||
|
root->root_key.objectid);
|
||||||
|
ret = -ENOSPC;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
*objectid = ++root->highest_objectid;
|
||||||
|
ret = 0;
|
||||||
|
out:
|
||||||
|
mutex_unlock(&root->objectid_mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -131,6 +131,8 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
|
||||||
int btree_lock_page_hook(struct page *page, void *data,
|
int btree_lock_page_hook(struct page *page, void *data,
|
||||||
void (*flush_fn)(void *));
|
void (*flush_fn)(void *));
|
||||||
int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags);
|
int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags);
|
||||||
|
int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid);
|
||||||
|
int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid);
|
||||||
int __init btrfs_end_io_wq_init(void);
|
int __init btrfs_end_io_wq_init(void);
|
||||||
void __cold btrfs_end_io_wq_exit(void);
|
void __cold btrfs_end_io_wq_exit(void);
|
||||||
|
|
||||||
|
|
|
@ -525,58 +525,3 @@ out:
|
||||||
extent_changeset_free(data_reserved);
|
extent_changeset_free(data_reserved);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid)
|
|
||||||
{
|
|
||||||
struct btrfs_path *path;
|
|
||||||
int ret;
|
|
||||||
struct extent_buffer *l;
|
|
||||||
struct btrfs_key search_key;
|
|
||||||
struct btrfs_key found_key;
|
|
||||||
int slot;
|
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
|
||||||
if (!path)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
search_key.objectid = BTRFS_LAST_FREE_OBJECTID;
|
|
||||||
search_key.type = -1;
|
|
||||||
search_key.offset = (u64)-1;
|
|
||||||
ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
|
|
||||||
if (ret < 0)
|
|
||||||
goto error;
|
|
||||||
BUG_ON(ret == 0); /* Corruption */
|
|
||||||
if (path->slots[0] > 0) {
|
|
||||||
slot = path->slots[0] - 1;
|
|
||||||
l = path->nodes[0];
|
|
||||||
btrfs_item_key_to_cpu(l, &found_key, slot);
|
|
||||||
*objectid = max_t(u64, found_key.objectid,
|
|
||||||
BTRFS_FIRST_FREE_OBJECTID - 1);
|
|
||||||
} else {
|
|
||||||
*objectid = BTRFS_FIRST_FREE_OBJECTID - 1;
|
|
||||||
}
|
|
||||||
ret = 0;
|
|
||||||
error:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
mutex_lock(&root->objectid_mutex);
|
|
||||||
|
|
||||||
if (unlikely(root->highest_objectid >= BTRFS_LAST_FREE_OBJECTID)) {
|
|
||||||
btrfs_warn(root->fs_info,
|
|
||||||
"the objectid of root %llu reaches its highest value",
|
|
||||||
root->root_key.objectid);
|
|
||||||
ret = -ENOSPC;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
*objectid = ++root->highest_objectid;
|
|
||||||
ret = 0;
|
|
||||||
out:
|
|
||||||
mutex_unlock(&root->objectid_mutex);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,7 +10,4 @@ int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid);
|
||||||
int btrfs_save_ino_cache(struct btrfs_root *root,
|
int btrfs_save_ino_cache(struct btrfs_root *root,
|
||||||
struct btrfs_trans_handle *trans);
|
struct btrfs_trans_handle *trans);
|
||||||
|
|
||||||
int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid);
|
|
||||||
int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue