Skip to content

Commit

Permalink
Btrfs: Always use 64bit inode number
Browse files Browse the repository at this point in the history
There's a potential problem in 32bit system when we exhaust 32bit inode
numbers and start to allocate big inode numbers, because btrfs uses
inode->i_ino in many places.

So here we always use BTRFS_I(inode)->location.objectid, which is an
u64 variable.

There are 2 exceptions that BTRFS_I(inode)->location.objectid !=
inode->i_ino: the btree inode (0 vs 1) and empty subvol dirs (256 vs 2),
and inode->i_ino will be used in those cases.

Another reason to make this change is I'm going to use a special inode
to save free ino cache, and the inode number must be > (u64)-256.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
  • Loading branch information
Li Zefan committed Apr 25, 2011
1 parent 0414efa commit 33345d0
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 182 deletions.
9 changes: 9 additions & 0 deletions fs/btrfs/btrfs_inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ static inline struct btrfs_inode *BTRFS_I(struct inode *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)
{
i_size_write(inode, size);
Expand Down
5 changes: 3 additions & 2 deletions fs/btrfs/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ static int check_compressed_csum(struct inode *inode,
kunmap_atomic(kaddr, KM_USER0);

if (csum != *cb_sum) {
printk(KERN_INFO "btrfs csum failed ino %lu "
printk(KERN_INFO "btrfs csum failed ino %llu "
"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,
csum, *cb_sum, cb->mirror_num);
ret = -EIO;
Expand Down
25 changes: 14 additions & 11 deletions fs/btrfs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
len = BTRFS_FID_SIZE_NON_CONNECTABLE;
type = FILEID_BTRFS_WITHOUT_PARENT;

fid->objectid = inode->i_ino;
fid->objectid = btrfs_ino(inode);
fid->root_objectid = BTRFS_I(inode)->root->objectid;
fid->gen = inode->i_generation;

Expand Down Expand Up @@ -174,13 +174,13 @@ static struct dentry *btrfs_get_parent(struct dentry *child)
if (!path)
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.type = BTRFS_ROOT_BACKREF_KEY;
key.offset = (u64)-1;
root = root->fs_info->tree_root;
} else {
key.objectid = dir->i_ino;
key.objectid = btrfs_ino(dir);
key.type = BTRFS_INODE_REF_KEY;
key.offset = (u64)-1;
}
Expand Down Expand Up @@ -240,26 +240,29 @@ static int btrfs_get_name(struct dentry *parent, char *name,
struct btrfs_key key;
int name_len;
int ret;
u64 ino;

if (!dir || !inode)
return -EINVAL;

if (!S_ISDIR(dir->i_mode))
return -EINVAL;

ino = btrfs_ino(inode);

path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
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.type = BTRFS_ROOT_BACKREF_KEY;
key.offset = (u64)-1;
root = root->fs_info->tree_root;
} else {
key.objectid = inode->i_ino;
key.offset = dir->i_ino;
key.objectid = ino;
key.offset = btrfs_ino(dir);
key.type = BTRFS_INODE_REF_KEY;
}

Expand All @@ -268,7 +271,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
btrfs_free_path(path);
return ret;
} else if (ret > 0) {
if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
path->slots[0]--;
} else {
btrfs_free_path(path);
Expand All @@ -277,11 +280,11 @@ static int btrfs_get_name(struct dentry *parent, char *name,
}
leaf = path->nodes[0];

if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
rref = btrfs_item_ptr(leaf, path->slots[0],
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
rref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_root_ref);
name_ptr = (unsigned long)(rref + 1);
name_len = btrfs_root_ref_name_len(leaf, rref);
name_ptr = (unsigned long)(rref + 1);
name_len = btrfs_root_ref_name_len(leaf, rref);
} else {
iref = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_inode_ref);
Expand Down
10 changes: 5 additions & 5 deletions fs/btrfs/extent-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -7009,8 +7009,8 @@ static noinline int get_new_locations(struct inode *reloc_inode,

cur_pos = extent_key->objectid - offset;
last_byte = extent_key->objectid + extent_key->offset;
ret = btrfs_lookup_file_extent(NULL, root, path, reloc_inode->i_ino,
cur_pos, 0);
ret = btrfs_lookup_file_extent(NULL, root, path,
btrfs_ino(reloc_inode), cur_pos, 0);
if (ret < 0)
goto out;
if (ret > 0) {
Expand All @@ -7033,7 +7033,7 @@ static noinline int get_new_locations(struct inode *reloc_inode,
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
if (found_key.offset != cur_pos ||
found_key.type != BTRFS_EXTENT_DATA_KEY ||
found_key.objectid != reloc_inode->i_ino)
found_key.objectid != btrfs_ino(reloc_inode))
break;

fi = btrfs_item_ptr(leaf, path->slots[0],
Expand Down Expand Up @@ -7179,7 +7179,7 @@ static noinline int replace_one_extent(struct btrfs_trans_handle *trans,
break;
}

if (inode && key.objectid != inode->i_ino) {
if (inode && key.objectid != btrfs_ino(inode)) {
BUG_ON(extent_locked);
btrfs_release_path(root, path);
mutex_unlock(&inode->i_mutex);
Expand Down Expand Up @@ -7488,7 +7488,7 @@ static noinline int invalidate_extent_cache(struct btrfs_root *root,
continue;
if (btrfs_file_extent_disk_bytenr(leaf, fi) == 0)
continue;
if (!inode || inode->i_ino != key.objectid) {
if (!inode || btrfs_ino(inode) != key.objectid) {
iput(inode);
inode = btrfs_ilookup(target_root->fs_info->sb,
key.objectid, target_root, 1);
Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -3030,7 +3030,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
* because there might be preallocation past i_size
*/
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) {
btrfs_free_path(path);
return ret;
Expand All @@ -3043,7 +3043,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
found_type = btrfs_key_type(&found_key);

/* 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) {
/* have to trust i_size as the end */
last = (u64)-1;
Expand Down
5 changes: 3 additions & 2 deletions fs/btrfs/file-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
EXTENT_NODATASUM, GFP_NOFS);
} else {
printk(KERN_INFO "btrfs no csum found "
"for inode %lu start %llu\n",
inode->i_ino,
"for inode %llu start %llu\n",
(unsigned long long)
btrfs_ino(inode),
(unsigned long long)offset);
}
item = NULL;
Expand Down
27 changes: 14 additions & 13 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
struct btrfs_path *path;
struct btrfs_key key;
struct btrfs_key new_key;
u64 ino = btrfs_ino(inode);
u64 search_start = start;
u64 disk_bytenr = 0;
u64 num_bytes = 0;
Expand All @@ -318,14 +319,14 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,

while (1) {
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);
if (ret < 0)
break;
if (ret > 0 && path->slots[0] > 0 && search_start == start) {
leaf = path->nodes[0];
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)
path->slots[0]--;
}
Expand All @@ -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]);
if (key.objectid > inode->i_ino ||
if (key.objectid > ino ||
key.type > BTRFS_EXTENT_DATA_KEY || key.offset >= end)
break;

Expand Down Expand Up @@ -592,6 +593,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
int del_slot = 0;
int recow;
int ret;
u64 ino = btrfs_ino(inode);

btrfs_drop_extent_cache(inode, start, end - 1, 0);

Expand All @@ -600,7 +602,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
again:
recow = 0;
split = start;
key.objectid = inode->i_ino;
key.objectid = ino;
key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = split;

Expand All @@ -612,8 +614,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,

leaf = path->nodes[0];
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
BUG_ON(key.objectid != inode->i_ino ||
key.type != BTRFS_EXTENT_DATA_KEY);
BUG_ON(key.objectid != ino || key.type != BTRFS_EXTENT_DATA_KEY);
fi = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item);
BUG_ON(btrfs_file_extent_type(leaf, fi) !=
Expand All @@ -630,7 +631,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
other_start = 0;
other_end = start;
if (extent_mergeable(leaf, path->slots[0] - 1,
inode->i_ino, bytenr, orig_offset,
ino, bytenr, orig_offset,
&other_start, &other_end)) {
new_key.offset = end;
btrfs_set_item_key_safe(trans, root, path, &new_key);
Expand All @@ -653,7 +654,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
other_start = end;
other_end = 0;
if (extent_mergeable(leaf, path->slots[0] + 1,
inode->i_ino, bytenr, orig_offset,
ino, bytenr, orig_offset,
&other_start, &other_end)) {
fi = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item);
Expand Down Expand Up @@ -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,
root->root_key.objectid,
inode->i_ino, orig_offset);
ino, orig_offset);
BUG_ON(ret);

if (split == start) {
Expand All @@ -718,7 +719,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
other_start = end;
other_end = 0;
if (extent_mergeable(leaf, path->slots[0] + 1,
inode->i_ino, bytenr, orig_offset,
ino, bytenr, orig_offset,
&other_start, &other_end)) {
if (recow) {
btrfs_release_path(root, path);
Expand All @@ -729,13 +730,13 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
del_nr++;
ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
0, root->root_key.objectid,
inode->i_ino, orig_offset);
ino, orig_offset);
BUG_ON(ret);
}
other_start = 0;
other_end = start;
if (extent_mergeable(leaf, path->slots[0] - 1,
inode->i_ino, bytenr, orig_offset,
ino, bytenr, orig_offset,
&other_start, &other_end)) {
if (recow) {
btrfs_release_path(root, path);
Expand All @@ -746,7 +747,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
del_nr++;
ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
0, root->root_key.objectid,
inode->i_ino, orig_offset);
ino, orig_offset);
BUG_ON(ret);
}
if (del_nr == 0) {
Expand Down
Loading

0 comments on commit 33345d0

Please sign in to comment.