Commit 09655373 authored by Chris Mason's avatar Chris Mason

Merge branch 'ino-alloc' of git://repo.or.cz/linux-btrfs-devel into inode_numbers

Conflicts:
	fs/btrfs/free-space-cache.c
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parents 61c4f2c8 82d5902d
...@@ -166,6 +166,15 @@ static inline struct btrfs_inode *BTRFS_I(struct inode *inode) ...@@ -166,6 +166,15 @@ static inline struct btrfs_inode *BTRFS_I(struct inode *inode)
return container_of(inode, struct btrfs_inode, vfs_inode); return container_of(inode, struct btrfs_inode, vfs_inode);
} }
static inline u64 btrfs_ino(struct inode *inode)
{
u64 ino = BTRFS_I(inode)->location.objectid;
if (ino <= BTRFS_FIRST_FREE_OBJECTID)
ino = inode->i_ino;
return ino;
}
static inline void btrfs_i_size_write(struct inode *inode, u64 size) static inline void btrfs_i_size_write(struct inode *inode, u64 size)
{ {
i_size_write(inode, size); i_size_write(inode, size);
......
...@@ -125,9 +125,10 @@ static int check_compressed_csum(struct inode *inode, ...@@ -125,9 +125,10 @@ static int check_compressed_csum(struct inode *inode,
kunmap_atomic(kaddr, KM_USER0); kunmap_atomic(kaddr, KM_USER0);
if (csum != *cb_sum) { if (csum != *cb_sum) {
printk(KERN_INFO "btrfs csum failed ino %lu " printk(KERN_INFO "btrfs csum failed ino %llu "
"extent %llu csum %u " "extent %llu csum %u "
"wanted %u mirror %d\n", inode->i_ino, "wanted %u mirror %d\n",
(unsigned long long)btrfs_ino(inode),
(unsigned long long)disk_start, (unsigned long long)disk_start,
csum, *cb_sum, cb->mirror_num); csum, *cb_sum, cb->mirror_num);
ret = -EIO; ret = -EIO;
......
...@@ -105,6 +105,12 @@ struct btrfs_ordered_sum; ...@@ -105,6 +105,12 @@ struct btrfs_ordered_sum;
/* For storing free space cache */ /* For storing free space cache */
#define BTRFS_FREE_SPACE_OBJECTID -11ULL #define BTRFS_FREE_SPACE_OBJECTID -11ULL
/*
* The inode number assigned to the special inode for sotring
* free ino cache
*/
#define BTRFS_FREE_INO_OBJECTID -12ULL
/* dummy objectid represents multiple objectids */ /* dummy objectid represents multiple objectids */
#define BTRFS_MULTIPLE_OBJECTIDS -255ULL #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
...@@ -830,9 +836,6 @@ struct btrfs_block_group_cache { ...@@ -830,9 +836,6 @@ struct btrfs_block_group_cache {
u64 bytes_super; u64 bytes_super;
u64 flags; u64 flags;
u64 sectorsize; u64 sectorsize;
int extents_thresh;
int free_extents;
int total_bitmaps;
unsigned int ro:1; unsigned int ro:1;
unsigned int dirty:1; unsigned int dirty:1;
unsigned int iref:1; unsigned int iref:1;
...@@ -847,9 +850,7 @@ struct btrfs_block_group_cache { ...@@ -847,9 +850,7 @@ struct btrfs_block_group_cache {
struct btrfs_space_info *space_info; struct btrfs_space_info *space_info;
/* free space cache stuff */ /* free space cache stuff */
spinlock_t tree_lock; struct btrfs_free_space_ctl *free_space_ctl;
struct rb_root free_space_offset;
u64 free_space;
/* block group cache stuff */ /* block group cache stuff */
struct rb_node cache_node; struct rb_node cache_node;
...@@ -1107,6 +1108,16 @@ struct btrfs_root { ...@@ -1107,6 +1108,16 @@ struct btrfs_root {
spinlock_t accounting_lock; spinlock_t accounting_lock;
struct btrfs_block_rsv *block_rsv; struct btrfs_block_rsv *block_rsv;
/* free ino cache stuff */
struct mutex fs_commit_mutex;
struct btrfs_free_space_ctl *free_ino_ctl;
enum btrfs_caching_type cached;
spinlock_t cache_lock;
wait_queue_head_t cache_wait;
struct btrfs_free_space_ctl *free_ino_pinned;
u64 cache_progress;
struct inode *cache_inode;
struct mutex log_mutex; struct mutex log_mutex;
wait_queue_head_t log_writer_wait; wait_queue_head_t log_writer_wait;
wait_queue_head_t log_commit_wait[2]; wait_queue_head_t log_commit_wait[2];
...@@ -2413,12 +2424,6 @@ int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, ...@@ -2413,12 +2424,6 @@ int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 offset); struct btrfs_root *root, u64 offset);
int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset); int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset);
/* inode-map.c */
int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
struct btrfs_root *fs_root,
u64 dirid, u64 *objectid);
int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
/* inode-item.c */ /* inode-item.c */
int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "locking.h" #include "locking.h"
#include "tree-log.h" #include "tree-log.h"
#include "free-space-cache.h" #include "free-space-cache.h"
#include "inode-map.h"
static struct extent_io_ops btree_extent_io_ops; static struct extent_io_ops btree_extent_io_ops;
static void end_workqueue_fn(struct btrfs_work *work); static void end_workqueue_fn(struct btrfs_work *work);
...@@ -1326,6 +1327,19 @@ struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info, ...@@ -1326,6 +1327,19 @@ struct btrfs_root *btrfs_read_fs_root_no_name(struct btrfs_fs_info *fs_info,
if (IS_ERR(root)) if (IS_ERR(root))
return root; return root;
root->free_ino_ctl = kzalloc(sizeof(*root->free_ino_ctl), GFP_NOFS);
if (!root->free_ino_ctl)
goto fail;
root->free_ino_pinned = kzalloc(sizeof(*root->free_ino_pinned),
GFP_NOFS);
if (!root->free_ino_pinned)
goto fail;
btrfs_init_free_ino_ctl(root);
mutex_init(&root->fs_commit_mutex);
spin_lock_init(&root->cache_lock);
init_waitqueue_head(&root->cache_wait);
set_anon_super(&root->anon_super, NULL); set_anon_super(&root->anon_super, NULL);
if (btrfs_root_refs(&root->root_item) == 0) { if (btrfs_root_refs(&root->root_item) == 0) {
...@@ -2404,12 +2418,15 @@ int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root) ...@@ -2404,12 +2418,15 @@ int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
if (btrfs_root_refs(&root->root_item) == 0) if (btrfs_root_refs(&root->root_item) == 0)
synchronize_srcu(&fs_info->subvol_srcu); synchronize_srcu(&fs_info->subvol_srcu);
__btrfs_remove_free_space_cache(root->free_ino_pinned);
__btrfs_remove_free_space_cache(root->free_ino_ctl);
free_fs_root(root); free_fs_root(root);
return 0; return 0;
} }
static void free_fs_root(struct btrfs_root *root) static void free_fs_root(struct btrfs_root *root)
{ {
iput(root->cache_inode);
WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree)); WARN_ON(!RB_EMPTY_ROOT(&root->inode_tree));
if (root->anon_super.s_dev) { if (root->anon_super.s_dev) {
down_write(&root->anon_super.s_umount); down_write(&root->anon_super.s_umount);
...@@ -2417,6 +2434,8 @@ static void free_fs_root(struct btrfs_root *root) ...@@ -2417,6 +2434,8 @@ static void free_fs_root(struct btrfs_root *root)
} }
free_extent_buffer(root->node); free_extent_buffer(root->node);
free_extent_buffer(root->commit_root); free_extent_buffer(root->commit_root);
kfree(root->free_ino_ctl);
kfree(root->free_ino_pinned);
kfree(root->name); kfree(root->name);
kfree(root); kfree(root);
} }
......
...@@ -32,7 +32,7 @@ static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len, ...@@ -32,7 +32,7 @@ static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
len = BTRFS_FID_SIZE_NON_CONNECTABLE; len = BTRFS_FID_SIZE_NON_CONNECTABLE;
type = FILEID_BTRFS_WITHOUT_PARENT; type = FILEID_BTRFS_WITHOUT_PARENT;
fid->objectid = inode->i_ino; fid->objectid = btrfs_ino(inode);
fid->root_objectid = BTRFS_I(inode)->root->objectid; fid->root_objectid = BTRFS_I(inode)->root->objectid;
fid->gen = inode->i_generation; fid->gen = inode->i_generation;
...@@ -178,13 +178,13 @@ static struct dentry *btrfs_get_parent(struct dentry *child) ...@@ -178,13 +178,13 @@ static struct dentry *btrfs_get_parent(struct dentry *child)
if (!path) if (!path)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (dir->i_ino == BTRFS_FIRST_FREE_OBJECTID) { if (btrfs_ino(dir) == BTRFS_FIRST_FREE_OBJECTID) {
key.objectid = root->root_key.objectid; key.objectid = root->root_key.objectid;
key.type = BTRFS_ROOT_BACKREF_KEY; key.type = BTRFS_ROOT_BACKREF_KEY;
key.offset = (u64)-1; key.offset = (u64)-1;
root = root->fs_info->tree_root; root = root->fs_info->tree_root;
} else { } else {
key.objectid = dir->i_ino; key.objectid = btrfs_ino(dir);
key.type = BTRFS_INODE_REF_KEY; key.type = BTRFS_INODE_REF_KEY;
key.offset = (u64)-1; key.offset = (u64)-1;
} }
...@@ -244,6 +244,7 @@ static int btrfs_get_name(struct dentry *parent, char *name, ...@@ -244,6 +244,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
struct btrfs_key key; struct btrfs_key key;
int name_len; int name_len;
int ret; int ret;
u64 ino;
if (!dir || !inode) if (!dir || !inode)
return -EINVAL; return -EINVAL;
...@@ -251,19 +252,21 @@ static int btrfs_get_name(struct dentry *parent, char *name, ...@@ -251,19 +252,21 @@ static int btrfs_get_name(struct dentry *parent, char *name,
if (!S_ISDIR(dir->i_mode)) if (!S_ISDIR(dir->i_mode))
return -EINVAL; return -EINVAL;
ino = btrfs_ino(inode);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
path->leave_spinning = 1; path->leave_spinning = 1;
if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) { if (ino == BTRFS_FIRST_FREE_OBJECTID) {
key.objectid = BTRFS_I(inode)->root->root_key.objectid; key.objectid = BTRFS_I(inode)->root->root_key.objectid;
key.type = BTRFS_ROOT_BACKREF_KEY; key.type = BTRFS_ROOT_BACKREF_KEY;
key.offset = (u64)-1; key.offset = (u64)-1;
root = root->fs_info->tree_root; root = root->fs_info->tree_root;
} else { } else {
key.objectid = inode->i_ino; key.objectid = ino;
key.offset = dir->i_ino; key.offset = btrfs_ino(dir);
key.type = BTRFS_INODE_REF_KEY; key.type = BTRFS_INODE_REF_KEY;
} }
...@@ -272,7 +275,7 @@ static int btrfs_get_name(struct dentry *parent, char *name, ...@@ -272,7 +275,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
btrfs_free_path(path); btrfs_free_path(path);
return ret; return ret;
} else if (ret > 0) { } else if (ret > 0) {
if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) { if (ino == BTRFS_FIRST_FREE_OBJECTID) {
path->slots[0]--; path->slots[0]--;
} else { } else {
btrfs_free_path(path); btrfs_free_path(path);
...@@ -281,7 +284,7 @@ static int btrfs_get_name(struct dentry *parent, char *name, ...@@ -281,7 +284,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
} }
leaf = path->nodes[0]; leaf = path->nodes[0];
if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) { if (ino == BTRFS_FIRST_FREE_OBJECTID) {
rref = btrfs_item_ptr(leaf, path->slots[0], rref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_root_ref); struct btrfs_root_ref);
name_ptr = (unsigned long)(rref + 1); name_ptr = (unsigned long)(rref + 1);
......
...@@ -105,6 +105,7 @@ void btrfs_put_block_group(struct btrfs_block_group_cache *cache) ...@@ -105,6 +105,7 @@ void btrfs_put_block_group(struct btrfs_block_group_cache *cache)
WARN_ON(cache->pinned > 0); WARN_ON(cache->pinned > 0);
WARN_ON(cache->reserved > 0); WARN_ON(cache->reserved > 0);
WARN_ON(cache->reserved_pinned > 0); WARN_ON(cache->reserved_pinned > 0);
kfree(cache->free_space_ctl);
kfree(cache); kfree(cache);
} }
} }
...@@ -3144,7 +3145,8 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes) ...@@ -3144,7 +3145,8 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes)
/* make sure bytes are sectorsize aligned */ /* make sure bytes are sectorsize aligned */
bytes = (bytes + root->sectorsize - 1) & ~((u64)root->sectorsize - 1); bytes = (bytes + root->sectorsize - 1) & ~((u64)root->sectorsize - 1);
if (root == root->fs_info->tree_root) { if (root == root->fs_info->tree_root ||
BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) {
alloc_chunk = 0; alloc_chunk = 0;
committed = 1; committed = 1;
} }
...@@ -4893,7 +4895,7 @@ wait_block_group_cache_progress(struct btrfs_block_group_cache *cache, ...@@ -4893,7 +4895,7 @@ wait_block_group_cache_progress(struct btrfs_block_group_cache *cache,
return 0; return 0;
wait_event(caching_ctl->wait, block_group_cache_done(cache) || wait_event(caching_ctl->wait, block_group_cache_done(cache) ||
(cache->free_space >= num_bytes)); (cache->free_space_ctl->free_space >= num_bytes));
put_caching_control(caching_ctl); put_caching_control(caching_ctl);
return 0; return 0;
...@@ -7008,8 +7010,8 @@ static noinline int get_new_locations(struct inode *reloc_inode, ...@@ -7008,8 +7010,8 @@ static noinline int get_new_locations(struct inode *reloc_inode,
cur_pos = extent_key->objectid - offset; cur_pos = extent_key->objectid - offset;
last_byte = extent_key->objectid + extent_key->offset; last_byte = extent_key->objectid + extent_key->offset;
ret = btrfs_lookup_file_extent(NULL, root, path, reloc_inode->i_ino, ret = btrfs_lookup_file_extent(NULL, root, path,
cur_pos, 0); btrfs_ino(reloc_inode), cur_pos, 0);
if (ret < 0) if (ret < 0)
goto out; goto out;
if (ret > 0) { if (ret > 0) {
...@@ -7032,7 +7034,7 @@ static noinline int get_new_locations(struct inode *reloc_inode, ...@@ -7032,7 +7034,7 @@ static noinline int get_new_locations(struct inode *reloc_inode,
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
if (found_key.offset != cur_pos || if (found_key.offset != cur_pos ||
found_key.type != BTRFS_EXTENT_DATA_KEY || found_key.type != BTRFS_EXTENT_DATA_KEY ||
found_key.objectid != reloc_inode->i_ino) found_key.objectid != btrfs_ino(reloc_inode))
break; break;
fi = btrfs_item_ptr(leaf, path->slots[0], fi = btrfs_item_ptr(leaf, path->slots[0],
...@@ -7178,7 +7180,7 @@ static noinline int replace_one_extent(struct btrfs_trans_handle *trans, ...@@ -7178,7 +7180,7 @@ static noinline int replace_one_extent(struct btrfs_trans_handle *trans,
break; break;
} }
if (inode && key.objectid != inode->i_ino) { if (inode && key.objectid != btrfs_ino(inode)) {
BUG_ON(extent_locked); BUG_ON(extent_locked);
btrfs_release_path(root, path); btrfs_release_path(root, path);
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
...@@ -7487,7 +7489,7 @@ static noinline int invalidate_extent_cache(struct btrfs_root *root, ...@@ -7487,7 +7489,7 @@ static noinline int invalidate_extent_cache(struct btrfs_root *root,
continue; continue;
if (btrfs_file_extent_disk_bytenr(leaf, fi) == 0) if (btrfs_file_extent_disk_bytenr(leaf, fi) == 0)
continue; continue;
if (!inode || inode->i_ino != key.objectid) { if (!inode || btrfs_ino(inode) != key.objectid) {
iput(inode); iput(inode);
inode = btrfs_ilookup(target_root->fs_info->sb, inode = btrfs_ilookup(target_root->fs_info->sb,
key.objectid, target_root, 1); key.objectid, target_root, 1);
...@@ -8555,10 +8557,16 @@ int btrfs_read_block_groups(struct btrfs_root *root) ...@@ -8555,10 +8557,16 @@ int btrfs_read_block_groups(struct btrfs_root *root)
ret = -ENOMEM; ret = -ENOMEM;
goto error; goto error;
} }
cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl),
GFP_NOFS);
if (!cache->free_space_ctl) {
kfree(cache);
ret = -ENOMEM;
goto error;
}
atomic_set(&cache->count, 1); atomic_set(&cache->count, 1);
spin_lock_init(&cache->lock); spin_lock_init(&cache->lock);
spin_lock_init(&cache->tree_lock);
cache->fs_info = info; cache->fs_info = info;
INIT_LIST_HEAD(&cache->list); INIT_LIST_HEAD(&cache->list);
INIT_LIST_HEAD(&cache->cluster_list); INIT_LIST_HEAD(&cache->cluster_list);
...@@ -8566,14 +8574,6 @@ int btrfs_read_block_groups(struct btrfs_root *root) ...@@ -8566,14 +8574,6 @@ int btrfs_read_block_groups(struct btrfs_root *root)
if (need_clear) if (need_clear)
cache->disk_cache_state = BTRFS_DC_CLEAR; cache->disk_cache_state = BTRFS_DC_CLEAR;
/*
* we only want to have 32k of ram per block group for keeping
* track of free space, and if we pass 1/2 of that we want to
* start converting things over to using bitmaps
*/
cache->extents_thresh = ((1024 * 32) / 2) /
sizeof(struct btrfs_free_space);
read_extent_buffer(leaf, &cache->item, read_extent_buffer(leaf, &cache->item,
btrfs_item_ptr_offset(leaf, path->slots[0]), btrfs_item_ptr_offset(leaf, path->slots[0]),
sizeof(cache->item)); sizeof(cache->item));
...@@ -8584,6 +8584,8 @@ int btrfs_read_block_groups(struct btrfs_root *root) ...@@ -8584,6 +8584,8 @@ int btrfs_read_block_groups(struct btrfs_root *root)
cache->flags = btrfs_block_group_flags(&cache->item); cache->flags = btrfs_block_group_flags(&cache->item);
cache->sectorsize = root->sectorsize; cache->sectorsize = root->sectorsize;
btrfs_init_free_space_ctl(cache);
/* /*
* We need to exclude the super stripes now so that the space * We need to exclude the super stripes now so that the space
* info has super bytes accounted for, otherwise we'll think * info has super bytes accounted for, otherwise we'll think
...@@ -8670,6 +8672,12 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, ...@@ -8670,6 +8672,12 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
cache = kzalloc(sizeof(*cache), GFP_NOFS); cache = kzalloc(sizeof(*cache), GFP_NOFS);
if (!cache) if (!cache)
return -ENOMEM; return -ENOMEM;
cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl),
GFP_NOFS);
if (!cache->free_space_ctl) {
kfree(cache);
return -ENOMEM;
}
cache->key.objectid = chunk_offset; cache->key.objectid = chunk_offset;
cache->key.offset = size; cache->key.offset = size;
...@@ -8677,19 +8685,13 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, ...@@ -8677,19 +8685,13 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
cache->sectorsize = root->sectorsize; cache->sectorsize = root->sectorsize;
cache->fs_info = root->fs_info; cache->fs_info = root->fs_info;
/*
* we only want to have 32k of ram per block group for keeping track
* of free space, and if we pass 1/2 of that we want to start
* converting things over to using bitmaps
*/
cache->extents_thresh = ((1024 * 32) / 2) /
sizeof(struct btrfs_free_space);
atomic_set(&cache->count, 1); atomic_set(&cache->count, 1);
spin_lock_init(&cache->lock); spin_lock_init(&cache->lock);
spin_lock_init(&cache->tree_lock);
INIT_LIST_HEAD(&cache->list); INIT_LIST_HEAD(&cache->list);
INIT_LIST_HEAD(&cache->cluster_list); INIT_LIST_HEAD(&cache->cluster_list);
btrfs_init_free_space_ctl(cache);
btrfs_set_block_group_used(&cache->item, bytes_used); btrfs_set_block_group_used(&cache->item, bytes_used);
btrfs_set_block_group_chunk_objectid(&cache->item, chunk_objectid); btrfs_set_block_group_chunk_objectid(&cache->item, chunk_objectid);
cache->flags = type; cache->flags = type;
......
...@@ -3030,7 +3030,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, ...@@ -3030,7 +3030,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
* because there might be preallocation past i_size * because there might be preallocation past i_size
*/ */
ret = btrfs_lookup_file_extent(NULL, BTRFS_I(inode)->root, ret = btrfs_lookup_file_extent(NULL, BTRFS_I(inode)->root,
path, inode->i_ino, -1, 0); path, btrfs_ino(inode), -1, 0);
if (ret < 0) { if (ret < 0) {
btrfs_free_path(path); btrfs_free_path(path);
return ret; return ret;
...@@ -3043,7 +3043,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, ...@@ -3043,7 +3043,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
found_type = btrfs_key_type(&found_key); found_type = btrfs_key_type(&found_key);
/* No extents, but there might be delalloc bits */ /* No extents, but there might be delalloc bits */
if (found_key.objectid != inode->i_ino || if (found_key.objectid != btrfs_ino(inode) ||
found_type != BTRFS_EXTENT_DATA_KEY) { found_type != BTRFS_EXTENT_DATA_KEY) {
/* have to trust i_size as the end */ /* have to trust i_size as the end */
last = (u64)-1; last = (u64)-1;
......
...@@ -208,8 +208,9 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, ...@@ -208,8 +208,9 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
EXTENT_NODATASUM, GFP_NOFS); EXTENT_NODATASUM, GFP_NOFS);
} else { } else {
printk(KERN_INFO "btrfs no csum found " printk(KERN_INFO "btrfs no csum found "
"for inode %lu start %llu\n", "for inode %llu start %llu\n",
inode->i_ino, (unsigned long long)
btrfs_ino(inode),
(unsigned long long)offset); (unsigned long long)offset);
} }
item = NULL; item = NULL;
......
...@@ -298,6 +298,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -298,6 +298,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_key key; struct btrfs_key key;
struct btrfs_key new_key; struct btrfs_key new_key;
u64 ino = btrfs_ino(inode);
u64 search_start = start; u64 search_start = start;
u64 disk_bytenr = 0; u64 disk_bytenr = 0;
u64 num_bytes = 0; u64 num_bytes = 0;
...@@ -318,14 +319,14 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -318,14 +319,14 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
while (1) { while (1) {
recow = 0; recow = 0;
ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino, ret = btrfs_lookup_file_extent(trans, root, path, ino,
search_start, -1); search_start, -1);
if (ret < 0) if (ret < 0)
break; break;
if (ret > 0 && path->slots[0] > 0 && search_start == start) { if (ret > 0 && path->slots[0] > 0 && search_start == start) {
leaf = path->nodes[0]; leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &key, path->slots[0] - 1); btrfs_item_key_to_cpu(leaf, &key, path->slots[0] - 1);
if (key.objectid == inode->i_ino && if (key.objectid == ino &&
key.type == BTRFS_EXTENT_DATA_KEY) key.type == BTRFS_EXTENT_DATA_KEY)
path->slots[0]--; path->slots[0]--;
} }
...@@ -346,7 +347,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -346,7 +347,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
} }
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
if (key.objectid > inode->i_ino || if (key.objectid > ino ||
key.type > BTRFS_EXTENT_DATA_KEY || key.offset >= end) key.type > BTRFS_EXTENT_DATA_KEY || key.offset >= end)
break; break;
...@@ -592,6 +593,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -592,6 +593,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
int del_slot = 0; int del_slot = 0;
int recow; int recow;
int ret; int ret;
u64 ino = btrfs_ino(inode);
btrfs_drop_extent_cache(inode, start, end - 1, 0); btrfs_drop_extent_cache(inode, start, end - 1, 0);
...@@ -600,7 +602,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -600,7 +602,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
again: again:
recow = 0; recow = 0;
split = start; split = start;
key.objectid = inode->i_ino; key.objectid = ino;
key.type = BTRFS_EXTENT_DATA_KEY; key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = split; key.offset = split;
...@@ -612,8 +614,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -612,8 +614,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
leaf = path->nodes[0]; leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
BUG_ON(key.objectid != inode->i_ino || BUG_ON(key.objectid != ino || key.type != BTRFS_EXTENT_DATA_KEY);
key.type != BTRFS_EXTENT_DATA_KEY);
fi = btrfs_item_ptr(leaf, path->slots[0], fi = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item); struct btrfs_file_extent_item);
BUG_ON(btrfs_file_extent_type(leaf, fi) != BUG_ON(btrfs_file_extent_type(leaf, fi) !=
...@@ -630,7 +631,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -630,7 +631,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
other_start = 0; other_start = 0;
other_end = start; other_end = start;
if (extent_mergeable(leaf, path->slots[0] - 1, if (extent_mergeable(leaf, path->slots[0] - 1,
inode->i_ino, bytenr, orig_offset, ino, bytenr, orig_offset,
&other_start, &other_end)) { &other_start, &other_end)) {
new_key.offset = end; new_key.offset = end;
btrfs_set_item_key_safe(trans, root, path, &new_key); btrfs_set_item_key_safe(trans, root, path, &new_key);
...@@ -653,7 +654,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -653,7 +654,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
other_start = end; other_start = end;
other_end = 0; other_end = 0;
if (extent_mergeable(leaf, path->slots[0] + 1, if (extent_mergeable(leaf, path->slots[0] + 1,
inode->i_ino, bytenr, orig_offset, ino, bytenr, orig_offset,
&other_start, &other_end)) { &other_start, &other_end)) {
fi = btrfs_item_ptr(leaf, path->slots[0], fi = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item); struct btrfs_file_extent_item);
...@@ -702,7 +703,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -702,7 +703,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0, ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0,
root->root_key.objectid, root->root_key.objectid,
inode->i_ino, orig_offset); ino, orig_offset);
BUG_ON(ret); BUG_ON(ret);
if (split == start) { if (split == start) {
...@@ -718,7 +719,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -718,7 +719,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
other_start = end; other_start = end;
other_end = 0; other_end = 0;
if (extent_mergeable(leaf, path->slots[0] + 1, if (extent_mergeable(leaf, path->slots[0] + 1,
inode->i_ino, bytenr, orig_offset, ino, bytenr, orig_offset,
&other_start, &other_end)) { &other_start, &other_end)) {
if (recow) { if (recow) {
btrfs_release_path(root, path); btrfs_release_path(root, path);
...@@ -729,13 +730,13 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -729,13 +730,13 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
del_nr++; del_nr++;
ret = btrfs_free_extent(trans, root, bytenr, num_bytes, ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
0, root->root_key.objectid, 0, root->root_key.objectid,
inode->i_ino, orig_offset); ino, orig_offset);
BUG_ON(ret); BUG_ON(ret);
} }
other_start = 0; other_start = 0;
other_end = start; other_end = start;
if (extent_mergeable(leaf, path->slots[0] - 1, if (extent_mergeable(leaf, path->slots[0] - 1,
inode->i_ino, bytenr, orig_offset, ino, bytenr, orig_offset,
&other_start, &other_end)) { &other_start, &other_end)) {
if (recow) { if (recow) {
btrfs_release_path(root, path); btrfs_release_path(root, path);
...@@ -746,7 +747,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -746,7 +747,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
del_nr++; del_nr++;
ret = btrfs_free_extent(trans, root, bytenr, num_bytes, ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
0, root->root_key.objectid, 0, root->root_key.objectid,
inode->i_ino, orig_offset); ino, orig_offset);
BUG_ON(ret); BUG_ON(ret);
} }
if (del_nr == 0) { if (del_nr == 0) {
......
This diff is collapsed.
...@@ -27,6 +27,25 @@ struct btrfs_free_space { ...@@ -27,6 +27,25 @@ struct btrfs_free_space {
struct list_head list; struct list_head list;
}; };
struct btrfs_free_space_ctl {
spinlock_t tree_lock;
struct rb_root free_space_offset;
u64 free_space;
int extents_thresh;
int free_extents;
int total_bitmaps;
int unit;
u64 start;
struct btrfs_free_space_op *op;
void *private;
};
struct btrfs_free_space_op {
void (*recalc_thresholds)(struct btrfs_free_space_ctl *ctl);
bool (*use_bitmap)(struct btrfs_free_space_ctl *ctl,
struct btrfs_free_space *info);
};
struct inode *lookup_free_space_inode(struct btrfs_root *root, struct inode *lookup_free_space_inode(struct btrfs_root *root,
struct btrfs_block_group_cache struct btrfs_block_group_cache
*block_group, struct btrfs_path *path); *block_group, struct btrfs_path *path);
...@@ -45,17 +64,38 @@ int btrfs_write_out_cache(struct btrfs_root *root, ...@@ -45,17 +64,38 @@ int btrfs_write_out_cache(struct btrfs_root *root,
struct btrfs_trans_handle *trans, struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path); struct btrfs_path *path);
int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
struct inode *lookup_free_ino_inode(struct btrfs_root *root,
struct btrfs_path *path);
int create_free_ino_inode(struct btrfs_root *root,
struct btrfs_trans_handle *trans,
struct btrfs_path *path);
int load_free_ino_cache(struct btrfs_fs_info *fs_info,
struct btrfs_root *root);
int btrfs_write_out_ino_cache(struct btrfs_root *root,
struct btrfs_trans_handle *trans,
struct btrfs_path *path);
void btrfs_init_free_space_ctl(struct btrfs_block_group_cache *block_group);
int __btrfs_add_free_space(struct btrfs_free_space_ctl *ctl,
u64 bytenr, u64 size); u64 bytenr, u64 size);
static inline int
btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
u64 bytenr, u64 size)
{
return __btrfs_add_free_space(block_group->free_space_ctl,
bytenr, size);
}
int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group, int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
u64 bytenr, u64 size); u64 bytenr, u64 size);
void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl);
void btrfs_remove_free_space_cache(struct btrfs_block_group_cache void btrfs_remove_free_space_cache(struct btrfs_block_group_cache
*block_group); *block_group);
u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group, u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group,
u64 offset, u64 bytes, u64 empty_size); u64 offset, u64 bytes, u64 empty_size);
u64 btrfs_find_ino_for_alloc(struct btrfs_root *fs_root);
void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group, void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
u64 bytes); u64 bytes);
u64 btrfs_block_group_free_space(struct btrfs_block_group_cache *block_group);
int btrfs_find_space_cluster(struct btrfs_trans_handle *trans, int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
......
This diff is collapsed.
#ifndef __BTRFS_INODE_MAP
#define __BTRFS_INODE_MAP
void btrfs_init_free_ino_ctl(struct btrfs_root *root);
void btrfs_unpin_free_ino(struct btrfs_root *root);
void btrfs_return_ino(struct btrfs_root *root, u64 objectid);
int btrfs_find_free_ino(struct btrfs_root *root, u64 *objectid);
int btrfs_save_ino_cache(struct btrfs_root *root,
struct btrfs_trans_handle *trans);
int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid);
#endif
This diff is collapsed.
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "print-tree.h" #include "print-tree.h"
#include "volumes.h" #include "volumes.h"
#include "locking.h" #include "locking.h"
#include "inode-map.h"
/* Mask out flags that are inappropriate for the given type of inode. */ /* Mask out flags that are inappropriate for the given type of inode. */
static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags) static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags)
...@@ -329,8 +330,7 @@ static noinline int create_subvol(struct btrfs_root *root, ...@@ -329,8 +330,7 @@ static noinline int create_subvol(struct btrfs_root *root,
u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID; u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID;
u64 index = 0; u64 index = 0;
ret = btrfs_find_free_objectid(NULL, root->fs_info->tree_root, ret = btrfs_find_free_objectid(root->fs_info->tree_root, &objectid);
0, &objectid);
if (ret) { if (ret) {
dput(parent); dput(parent);
return ret; return ret;
...@@ -422,7 +422,7 @@ static noinline int create_subvol(struct btrfs_root *root, ...@@ -422,7 +422,7 @@ static noinline int create_subvol(struct btrfs_root *root,
BUG_ON(ret); BUG_ON(ret);
ret = btrfs_insert_dir_item(trans, root, ret = btrfs_insert_dir_item(trans, root,
name, namelen, dir->i_ino, &key, name, namelen, btrfs_ino(dir), &key,
BTRFS_FT_DIR, index); BTRFS_FT_DIR, index);
if (ret) if (ret)
goto fail; goto fail;
...@@ -433,7 +433,7 @@ static noinline int create_subvol(struct btrfs_root *root, ...@@ -433,7 +433,7 @@ static noinline int create_subvol(struct btrfs_root *root,
ret = btrfs_add_root_ref(trans, root->fs_info->tree_root, ret = btrfs_add_root_ref(trans, root->fs_info->tree_root,
objectid, root->root_key.objectid, objectid, root->root_key.objectid,
dir->i_ino, index, name, namelen); btrfs_ino(dir), index, name, namelen);
BUG_ON(ret); BUG_ON(ret);
...@@ -1129,7 +1129,7 @@ static noinline int btrfs_ioctl_subvol_getflags(struct file *file, ...@@ -1129,7 +1129,7 @@ static noinline int btrfs_ioctl_subvol_getflags(struct file *file,
int ret = 0; int ret = 0;
u64 flags = 0; u64 flags = 0;
if (inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID)
return -EINVAL; return -EINVAL;
down_read(&root->fs_info->subvol_sem); down_read(&root->fs_info->subvol_sem);
...@@ -1156,7 +1156,7 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file, ...@@ -1156,7 +1156,7 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
if (root->fs_info->sb->s_flags & MS_RDONLY) if (root->fs_info->sb->s_flags & MS_RDONLY)
return -EROFS; return -EROFS;
if (inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID)
return -EINVAL; return -EINVAL;
if (copy_from_user(&flags, arg, sizeof(flags))) if (copy_from_user(&flags, arg, sizeof(flags)))
...@@ -1639,7 +1639,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, ...@@ -1639,7 +1639,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
goto out_dput; goto out_dput;
} }
if (inode->i_ino != BTRFS_FIRST_FREE_OBJECTID) { if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID) {
err = -EINVAL; err = -EINVAL;
goto out_dput; goto out_dput;
} }
...@@ -1925,7 +1925,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, ...@@ -1925,7 +1925,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
} }
/* clone data */ /* clone data */
key.objectid = src->i_ino; key.objectid = btrfs_ino(src);
key.type = BTRFS_EXTENT_DATA_KEY; key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = 0; key.offset = 0;
...@@ -1952,7 +1952,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, ...@@ -1952,7 +1952,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
btrfs_item_key_to_cpu(leaf, &key, slot); btrfs_item_key_to_cpu(leaf, &key, slot);
if (btrfs_key_type(&key) > BTRFS_EXTENT_DATA_KEY || if (btrfs_key_type(&key) > BTRFS_EXTENT_DATA_KEY ||
key.objectid != src->i_ino) key.objectid != btrfs_ino(src))
break; break;
if (btrfs_key_type(&key) == BTRFS_EXTENT_DATA_KEY) { if (btrfs_key_type(&key) == BTRFS_EXTENT_DATA_KEY) {
...@@ -1995,7 +1995,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, ...@@ -1995,7 +1995,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
goto next; goto next;
memcpy(&new_key, &key, sizeof(new_key)); memcpy(&new_key, &key, sizeof(new_key));
new_key.objectid = inode->i_ino; new_key.objectid = btrfs_ino(inode);
if (off <= key.offset) if (off <= key.offset)
new_key.offset = key.offset + destoff - off; new_key.offset = key.offset + destoff - off;
else else
...@@ -2049,7 +2049,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, ...@@ -2049,7 +2049,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
ret = btrfs_inc_extent_ref(trans, root, ret = btrfs_inc_extent_ref(trans, root,
disko, diskl, 0, disko, diskl, 0,
root->root_key.objectid, root->root_key.objectid,
inode->i_ino, btrfs_ino(inode),
new_key.offset - datao); new_key.offset - datao);
BUG_ON(ret); BUG_ON(ret);
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "btrfs_inode.h" #include "btrfs_inode.h"
#include "async-thread.h" #include "async-thread.h"
#include "free-space-cache.h" #include "free-space-cache.h"
#include "inode-map.h"
/* /*
* backref_node, mapping_node and tree_block start with this * backref_node, mapping_node and tree_block start with this
...@@ -1409,9 +1410,9 @@ static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid) ...@@ -1409,9 +1410,9 @@ static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid)
prev = node; prev = node;
entry = rb_entry(node, struct btrfs_inode, rb_node); entry = rb_entry(node, struct btrfs_inode, rb_node);
if (objectid < entry->vfs_inode.i_ino) if (objectid < btrfs_ino(&entry->vfs_inode))
node = node->rb_left; node = node->rb_left;
else if (objectid > entry->vfs_inode.i_ino) else if (objectid > btrfs_ino(&entry->vfs_inode))
node = node->rb_right; node = node->rb_right;
else else
break; break;
...@@ -1419,7 +1420,7 @@ static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid) ...@@ -1419,7 +1420,7 @@ static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid)
if (!node) { if (!node) {
while (prev) { while (prev) {
entry = rb_entry(prev, struct btrfs_inode, rb_node); entry = rb_entry(prev, struct btrfs_inode, rb_node);
if (objectid <= entry->vfs_inode.i_ino) { if (objectid <= btrfs_ino(&entry->vfs_inode)) {
node = prev; node = prev;
break; break;
} }
...@@ -1434,7 +1435,7 @@ static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid) ...@@ -1434,7 +1435,7 @@ static struct inode *find_next_inode(struct btrfs_root *root, u64 objectid)
return inode; return inode;
} }
objectid = entry->vfs_inode.i_ino + 1; objectid = btrfs_ino(&entry->vfs_inode) + 1;
if (cond_resched_lock(&root->inode_lock)) if (cond_resched_lock(&root->inode_lock))
goto again; goto again;
...@@ -1470,7 +1471,7 @@ static int get_new_location(struct inode *reloc_inode, u64 *new_bytenr, ...@@ -1470,7 +1471,7 @@ static int get_new_location(struct inode *reloc_inode, u64 *new_bytenr,
return -ENOMEM; return -ENOMEM;
bytenr -= BTRFS_I(reloc_inode)->index_cnt; bytenr -= BTRFS_I(reloc_inode)->index_cnt;
ret = btrfs_lookup_file_extent(NULL, root, path, reloc_inode->i_ino, ret = btrfs_lookup_file_extent(NULL, root, path, btrfs_ino(reloc_inode),
bytenr, 0); bytenr, 0);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -1558,11 +1559,11 @@ int replace_file_extents(struct btrfs_trans_handle *trans, ...@@ -1558,11 +1559,11 @@ int replace_file_extents(struct btrfs_trans_handle *trans,
if (first) { if (first) {
inode = find_next_inode(root, key.objectid); inode = find_next_inode(root, key.objectid);
first = 0; first = 0;
} else if (inode && inode->i_ino < key.objectid) { } else if (inode && btrfs_ino(inode) < key.objectid) {
btrfs_add_delayed_iput(inode); btrfs_add_delayed_iput(inode);
inode = find_next_inode(root, key.objectid); inode = find_next_inode(root, key.objectid);
} }
if (inode && inode->i_ino == key.objectid) { if (inode && btrfs_ino(inode) == key.objectid) {
end = key.offset + end = key.offset +
btrfs_file_extent_num_bytes(leaf, fi); btrfs_file_extent_num_bytes(leaf, fi);
WARN_ON(!IS_ALIGNED(key.offset, WARN_ON(!IS_ALIGNED(key.offset,
...@@ -1893,6 +1894,7 @@ static int invalidate_extent_cache(struct btrfs_root *root, ...@@ -1893,6 +1894,7 @@ static int invalidate_extent_cache(struct btrfs_root *root,
struct inode *inode = NULL; struct inode *inode = NULL;
u64 objectid; u64 objectid;
u64 start, end; u64 start, end;
u64 ino;
objectid = min_key->objectid; objectid = min_key->objectid;
while (1) { while (1) {
...@@ -1905,17 +1907,18 @@ static int invalidate_extent_cache(struct btrfs_root *root, ...@@ -1905,17 +1907,18 @@ static int invalidate_extent_cache(struct btrfs_root *root,
inode = find_next_inode(root, objectid); inode = find_next_inode(root, objectid);
if (!inode) if (!inode)
break; break;
ino = btrfs_ino(inode);
if (inode->i_ino > max_key->objectid) { if (ino > max_key->objectid) {
iput(inode); iput(inode);
break; break;
} }
objectid = inode->i_ino + 1; objectid = ino + 1;
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
continue; continue;
if (unlikely(min_key->objectid == inode->i_ino)) { if (unlikely(min_key->objectid == ino)) {
if (min_key->type > BTRFS_EXTENT_DATA_KEY) if (min_key->type > BTRFS_EXTENT_DATA_KEY)
continue; continue;
if (min_key->type < BTRFS_EXTENT_DATA_KEY) if (min_key->type < BTRFS_EXTENT_DATA_KEY)
...@@ -1928,7 +1931,7 @@ static int invalidate_extent_cache(struct btrfs_root *root, ...@@ -1928,7 +1931,7 @@ static int invalidate_extent_cache(struct btrfs_root *root,
start = 0; start = 0;
} }
if (unlikely(max_key->objectid == inode->i_ino)) { if (unlikely(max_key->objectid == ino)) {
if (max_key->type < BTRFS_EXTENT_DATA_KEY) if (max_key->type < BTRFS_EXTENT_DATA_KEY)
continue; continue;
if (max_key->type > BTRFS_EXTENT_DATA_KEY) { if (max_key->type > BTRFS_EXTENT_DATA_KEY) {
...@@ -3897,7 +3900,7 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info, ...@@ -3897,7 +3900,7 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info,
if (IS_ERR(trans)) if (IS_ERR(trans))
return ERR_CAST(trans); return ERR_CAST(trans);
err = btrfs_find_free_objectid(trans, root, objectid, &objectid); err = btrfs_find_free_objectid(root, &objectid);
if (err) if (err)
goto out; goto out;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "transaction.h" #include "transaction.h"
#include "locking.h" #include "locking.h"
#include "tree-log.h" #include "tree-log.h"
#include "inode-map.h"
#define BTRFS_ROOT_TRANS_TAG 0 #define BTRFS_ROOT_TRANS_TAG 0
...@@ -760,8 +761,14 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans, ...@@ -760,8 +761,14 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans,
btrfs_update_reloc_root(trans, root); btrfs_update_reloc_root(trans, root);
btrfs_orphan_commit_root(trans, root); btrfs_orphan_commit_root(trans, root);
btrfs_save_ino_cache(root, trans);
if (root->commit_root != root->node) { if (root->commit_root != root->node) {
mutex_lock(&root->fs_commit_mutex);
switch_commit_root(root); switch_commit_root(root);
btrfs_unpin_free_ino(root);
mutex_unlock(&root->fs_commit_mutex);
btrfs_set_root_node(&root->root_item, btrfs_set_root_node(&root->root_item,
root->node); root->node);
} }
...@@ -930,7 +937,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -930,7 +937,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
goto fail; goto fail;
} }
ret = btrfs_find_free_objectid(trans, tree_root, 0, &objectid); ret = btrfs_find_free_objectid(tree_root, &objectid);
if (ret) { if (ret) {
pending->error = ret; pending->error = ret;
goto fail; goto fail;
...@@ -967,7 +974,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -967,7 +974,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
BUG_ON(ret); BUG_ON(ret);
ret = btrfs_insert_dir_item(trans, parent_root, ret = btrfs_insert_dir_item(trans, parent_root,
dentry->d_name.name, dentry->d_name.len, dentry->d_name.name, dentry->d_name.len,
parent_inode->i_ino, &key, btrfs_ino(parent_inode), &key,
BTRFS_FT_DIR, index); BTRFS_FT_DIR, index);
BUG_ON(ret); BUG_ON(ret);
...@@ -1009,7 +1016,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1009,7 +1016,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
*/ */
ret = btrfs_add_root_ref(trans, tree_root, objectid, ret = btrfs_add_root_ref(trans, tree_root, objectid,
parent_root->root_key.objectid, parent_root->root_key.objectid,
parent_inode->i_ino, index, btrfs_ino(parent_inode), index,
dentry->d_name.name, dentry->d_name.len); dentry->d_name.name, dentry->d_name.len);
BUG_ON(ret); BUG_ON(ret);
dput(parent); dput(parent);
......
...@@ -519,7 +519,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, ...@@ -519,7 +519,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
* file. This must be done before the btrfs_drop_extents run * file. This must be done before the btrfs_drop_extents run
* so we don't try to drop this extent. * so we don't try to drop this extent.
*/ */
ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino, ret = btrfs_lookup_file_extent(trans, root, path, btrfs_ino(inode),
start, 0); start, 0);
if (ret == 0 && if (ret == 0 &&
...@@ -832,7 +832,7 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans, ...@@ -832,7 +832,7 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
read_extent_buffer(eb, name, (unsigned long)(ref + 1), namelen); read_extent_buffer(eb, name, (unsigned long)(ref + 1), namelen);
/* if we already have a perfect match, we're done */ /* if we already have a perfect match, we're done */
if (inode_in_dir(root, path, dir->i_ino, inode->i_ino, if (inode_in_dir(root, path, btrfs_ino(dir), btrfs_ino(inode),
btrfs_inode_ref_index(eb, ref), btrfs_inode_ref_index(eb, ref),
name, namelen)) { name, namelen)) {
goto out; goto out;
...@@ -960,8 +960,9 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans, ...@@ -960,8 +960,9 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans,
unsigned long ptr; unsigned long ptr;
unsigned long ptr_end; unsigned long ptr_end;
int name_len; int name_len;
u64 ino = btrfs_ino(inode);
key.objectid = inode->i_ino; key.objectid = ino;
key.type = BTRFS_INODE_REF_KEY; key.type = BTRFS_INODE_REF_KEY;
key.offset = (u64)-1; key.offset = (u64)-1;
...@@ -980,7 +981,7 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans, ...@@ -980,7 +981,7 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans,
} }
btrfs_item_key_to_cpu(path->nodes[0], &key, btrfs_item_key_to_cpu(path->nodes[0], &key,
path->slots[0]); path->slots[0]);
if (key.objectid != inode->i_ino || if (key.objectid != ino ||
key.type != BTRFS_INODE_REF_KEY) key.type != BTRFS_INODE_REF_KEY)
break; break;
ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]); ptr = btrfs_item_ptr_offset(path->nodes[0], path->slots[0]);
...@@ -1011,10 +1012,10 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans, ...@@ -1011,10 +1012,10 @@ static noinline int fixup_inode_link_count(struct btrfs_trans_handle *trans,
if (inode->i_nlink == 0) { if (inode->i_nlink == 0) {
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
ret = replay_dir_deletes(trans, root, NULL, path, ret = replay_dir_deletes(trans, root, NULL, path,
inode->i_ino, 1); ino, 1);
BUG_ON(ret); BUG_ON(ret);
} }
ret = insert_orphan_item(trans, root, inode->i_ino); ret = insert_orphan_item(trans, root, ino);
BUG_ON(ret); BUG_ON(ret);
} }
btrfs_free_path(path); btrfs_free_path(path);
...@@ -2197,6 +2198,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, ...@@ -2197,6 +2198,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
int ret; int ret;
int err = 0; int err = 0;
int bytes_del = 0; int bytes_del = 0;
u64 dir_ino = btrfs_ino(dir);
if (BTRFS_I(dir)->logged_trans < trans->transid) if (BTRFS_I(dir)->logged_trans < trans->transid)
return 0; return 0;
...@@ -2214,7 +2216,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, ...@@ -2214,7 +2216,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
goto out_unlock; goto out_unlock;
} }
di = btrfs_lookup_dir_item(trans, log, path, dir->i_ino, di = btrfs_lookup_dir_item(trans, log, path, dir_ino,
name, name_len, -1); name, name_len, -1);
if (IS_ERR(di)) { if (IS_ERR(di)) {
err = PTR_ERR(di); err = PTR_ERR(di);
...@@ -2226,7 +2228,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, ...@@ -2226,7 +2228,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
BUG_ON(ret); BUG_ON(ret);
} }
btrfs_release_path(log, path); btrfs_release_path(log, path);
di = btrfs_lookup_dir_index_item(trans, log, path, dir->i_ino, di = btrfs_lookup_dir_index_item(trans, log, path, dir_ino,
index, name, name_len, -1); index, name, name_len, -1);
if (IS_ERR(di)) { if (IS_ERR(di)) {
err = PTR_ERR(di); err = PTR_ERR(di);
...@@ -2244,7 +2246,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, ...@@ -2244,7 +2246,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
if (bytes_del) { if (bytes_del) {
struct btrfs_key key; struct btrfs_key key;
key.objectid = dir->i_ino; key.objectid = dir_ino;
key.offset = 0; key.offset = 0;
key.type = BTRFS_INODE_ITEM_KEY; key.type = BTRFS_INODE_ITEM_KEY;
btrfs_release_path(log, path); btrfs_release_path(log, path);
...@@ -2303,7 +2305,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, ...@@ -2303,7 +2305,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
log = root->log_root; log = root->log_root;
mutex_lock(&BTRFS_I(inode)->log_mutex); mutex_lock(&BTRFS_I(inode)->log_mutex);
ret = btrfs_del_inode_ref(trans, log, name, name_len, inode->i_ino, ret = btrfs_del_inode_ref(trans, log, name, name_len, btrfs_ino(inode),
dirid, &index); dirid, &index);
mutex_unlock(&BTRFS_I(inode)->log_mutex); mutex_unlock(&BTRFS_I(inode)->log_mutex);
if (ret == -ENOSPC) { if (ret == -ENOSPC) {
...@@ -2369,13 +2371,14 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -2369,13 +2371,14 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
int nritems; int nritems;
u64 first_offset = min_offset; u64 first_offset = min_offset;
u64 last_offset = (u64)-1; u64 last_offset = (u64)-1;
u64 ino = btrfs_ino(inode);
log = root->log_root; log = root->log_root;
max_key.objectid = inode->i_ino; max_key.objectid = ino;
max_key.offset = (u64)-1; max_key.offset = (u64)-1;
max_key.type = key_type; max_key.type = key_type;
min_key.objectid = inode->i_ino; min_key.objectid = ino;
min_key.type = key_type; min_key.type = key_type;
min_key.offset = min_offset; min_key.offset = min_offset;
...@@ -2388,9 +2391,8 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -2388,9 +2391,8 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
* we didn't find anything from this transaction, see if there * we didn't find anything from this transaction, see if there
* is anything at all * is anything at all
*/ */
if (ret != 0 || min_key.objectid != inode->i_ino || if (ret != 0 || min_key.objectid != ino || min_key.type != key_type) {
min_key.type != key_type) { min_key.objectid = ino;
min_key.objectid = inode->i_ino;
min_key.type = key_type; min_key.type = key_type;
min_key.offset = (u64)-1; min_key.offset = (u64)-1;
btrfs_release_path(root, path); btrfs_release_path(root, path);
...@@ -2399,7 +2401,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -2399,7 +2401,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
btrfs_release_path(root, path); btrfs_release_path(root, path);
return ret; return ret;
} }
ret = btrfs_previous_item(root, path, inode->i_ino, key_type); ret = btrfs_previous_item(root, path, ino, key_type);
/* if ret == 0 there are items for this type, /* if ret == 0 there are items for this type,
* create a range to tell us the last key of this type. * create a range to tell us the last key of this type.
...@@ -2417,7 +2419,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -2417,7 +2419,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
} }
/* go backward to find any previous key */ /* go backward to find any previous key */
ret = btrfs_previous_item(root, path, inode->i_ino, key_type); ret = btrfs_previous_item(root, path, ino, key_type);
if (ret == 0) { if (ret == 0) {
struct btrfs_key tmp; struct btrfs_key tmp;
btrfs_item_key_to_cpu(path->nodes[0], &tmp, path->slots[0]); btrfs_item_key_to_cpu(path->nodes[0], &tmp, path->slots[0]);
...@@ -2452,8 +2454,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -2452,8 +2454,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
for (i = path->slots[0]; i < nritems; i++) { for (i = path->slots[0]; i < nritems; i++) {
btrfs_item_key_to_cpu(src, &min_key, i); btrfs_item_key_to_cpu(src, &min_key, i);
if (min_key.objectid != inode->i_ino || if (min_key.objectid != ino || min_key.type != key_type)
min_key.type != key_type)
goto done; goto done;
ret = overwrite_item(trans, log, dst_path, src, i, ret = overwrite_item(trans, log, dst_path, src, i,
&min_key); &min_key);
...@@ -2474,7 +2475,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -2474,7 +2475,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
goto done; goto done;
} }
btrfs_item_key_to_cpu(path->nodes[0], &tmp, path->slots[0]); btrfs_item_key_to_cpu(path->nodes[0], &tmp, path->slots[0]);
if (tmp.objectid != inode->i_ino || tmp.type != key_type) { if (tmp.objectid != ino || tmp.type != key_type) {
last_offset = (u64)-1; last_offset = (u64)-1;
goto done; goto done;
} }
...@@ -2500,8 +2501,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -2500,8 +2501,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
* is valid * is valid
*/ */
ret = insert_dir_log_key(trans, log, path, key_type, ret = insert_dir_log_key(trans, log, path, key_type,
inode->i_ino, first_offset, ino, first_offset, last_offset);
last_offset);
if (ret) if (ret)
err = ret; err = ret;
} }
...@@ -2745,6 +2745,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -2745,6 +2745,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
int nritems; int nritems;
int ins_start_slot = 0; int ins_start_slot = 0;
int ins_nr; int ins_nr;
u64 ino = btrfs_ino(inode);
log = root->log_root; log = root->log_root;
...@@ -2757,11 +2758,11 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -2757,11 +2758,11 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
return -ENOMEM; return -ENOMEM;
} }
min_key.objectid = inode->i_ino; min_key.objectid = ino;
min_key.type = BTRFS_INODE_ITEM_KEY; min_key.type = BTRFS_INODE_ITEM_KEY;
min_key.offset = 0; min_key.offset = 0;
max_key.objectid = inode->i_ino; max_key.objectid = ino;
/* today the code can only do partial logging of directories */ /* today the code can only do partial logging of directories */
if (!S_ISDIR(inode->i_mode)) if (!S_ISDIR(inode->i_mode))
...@@ -2784,8 +2785,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -2784,8 +2785,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
if (inode_only == LOG_INODE_EXISTS) if (inode_only == LOG_INODE_EXISTS)
max_key_type = BTRFS_XATTR_ITEM_KEY; max_key_type = BTRFS_XATTR_ITEM_KEY;
ret = drop_objectid_items(trans, log, path, ret = drop_objectid_items(trans, log, path, ino, max_key_type);
inode->i_ino, max_key_type);
} else { } else {
ret = btrfs_truncate_inode_items(trans, log, inode, 0, 0); ret = btrfs_truncate_inode_items(trans, log, inode, 0, 0);
} }
...@@ -2803,7 +2803,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -2803,7 +2803,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
break; break;
again: again:
/* note, ins_nr might be > 0 here, cleanup outside the loop */ /* note, ins_nr might be > 0 here, cleanup outside the loop */
if (min_key.objectid != inode->i_ino) if (min_key.objectid != ino)
break; break;
if (min_key.type > max_key.type) if (min_key.type > max_key.type)
break; break;
......
...@@ -44,7 +44,7 @@ ssize_t __btrfs_getxattr(struct inode *inode, const char *name, ...@@ -44,7 +44,7 @@ ssize_t __btrfs_getxattr(struct inode *inode, const char *name,
return -ENOMEM; return -ENOMEM;
/* lookup the xattr by name */ /* lookup the xattr by name */
di = btrfs_lookup_xattr(NULL, root, path, inode->i_ino, name, di = btrfs_lookup_xattr(NULL, root, path, btrfs_ino(inode), name,
strlen(name), 0); strlen(name), 0);
if (!di) { if (!di) {
ret = -ENODATA; ret = -ENODATA;
...@@ -103,7 +103,7 @@ static int do_setxattr(struct btrfs_trans_handle *trans, ...@@ -103,7 +103,7 @@ static int do_setxattr(struct btrfs_trans_handle *trans,
return -ENOMEM; return -ENOMEM;
/* first lets see if we already have this xattr */ /* first lets see if we already have this xattr */
di = btrfs_lookup_xattr(trans, root, path, inode->i_ino, name, di = btrfs_lookup_xattr(trans, root, path, btrfs_ino(inode), name,
strlen(name), -1); strlen(name), -1);
if (IS_ERR(di)) { if (IS_ERR(di)) {
ret = PTR_ERR(di); ret = PTR_ERR(di);
...@@ -136,7 +136,7 @@ static int do_setxattr(struct btrfs_trans_handle *trans, ...@@ -136,7 +136,7 @@ static int do_setxattr(struct btrfs_trans_handle *trans,
} }
/* ok we have to create a completely new xattr */ /* ok we have to create a completely new xattr */
ret = btrfs_insert_xattr_item(trans, root, path, inode->i_ino, ret = btrfs_insert_xattr_item(trans, root, path, btrfs_ino(inode),
name, name_len, value, size); name, name_len, value, size);
BUG_ON(ret); BUG_ON(ret);
out: out:
...@@ -190,7 +190,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) ...@@ -190,7 +190,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
* NOTE: we set key.offset = 0; because we want to start with the * NOTE: we set key.offset = 0; because we want to start with the
* first xattr that we find and walk forward * first xattr that we find and walk forward
*/ */
key.objectid = inode->i_ino; key.objectid = btrfs_ino(inode);
btrfs_set_key_type(&key, BTRFS_XATTR_ITEM_KEY); btrfs_set_key_type(&key, BTRFS_XATTR_ITEM_KEY);
key.offset = 0; key.offset = 0;
......
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