Skip to content

Commit 33345d0

Browse files
author
Li Zefan
committed
Btrfs: Always use 64bit inode number
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 <[email protected]>
1 parent 0414efa commit 33345d0

File tree

13 files changed

+208
-182
lines changed

13 files changed

+208
-182
lines changed

fs/btrfs/btrfs_inode.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ static inline struct btrfs_inode *BTRFS_I(struct inode *inode)
166166
return container_of(inode, struct btrfs_inode, vfs_inode);
167167
}
168168

169+
static inline u64 btrfs_ino(struct inode *inode)
170+
{
171+
u64 ino = BTRFS_I(inode)->location.objectid;
172+
173+
if (ino <= BTRFS_FIRST_FREE_OBJECTID)
174+
ino = inode->i_ino;
175+
return ino;
176+
}
177+
169178
static inline void btrfs_i_size_write(struct inode *inode, u64 size)
170179
{
171180
i_size_write(inode, size);

fs/btrfs/compression.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ static int check_compressed_csum(struct inode *inode,
125125
kunmap_atomic(kaddr, KM_USER0);
126126

127127
if (csum != *cb_sum) {
128-
printk(KERN_INFO "btrfs csum failed ino %lu "
128+
printk(KERN_INFO "btrfs csum failed ino %llu "
129129
"extent %llu csum %u "
130-
"wanted %u mirror %d\n", inode->i_ino,
130+
"wanted %u mirror %d\n",
131+
(unsigned long long)btrfs_ino(inode),
131132
(unsigned long long)disk_start,
132133
csum, *cb_sum, cb->mirror_num);
133134
ret = -EIO;

fs/btrfs/export.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
2828
len = BTRFS_FID_SIZE_NON_CONNECTABLE;
2929
type = FILEID_BTRFS_WITHOUT_PARENT;
3030

31-
fid->objectid = inode->i_ino;
31+
fid->objectid = btrfs_ino(inode);
3232
fid->root_objectid = BTRFS_I(inode)->root->objectid;
3333
fid->gen = inode->i_generation;
3434

@@ -174,13 +174,13 @@ static struct dentry *btrfs_get_parent(struct dentry *child)
174174
if (!path)
175175
return ERR_PTR(-ENOMEM);
176176

177-
if (dir->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
177+
if (btrfs_ino(dir) == BTRFS_FIRST_FREE_OBJECTID) {
178178
key.objectid = root->root_key.objectid;
179179
key.type = BTRFS_ROOT_BACKREF_KEY;
180180
key.offset = (u64)-1;
181181
root = root->fs_info->tree_root;
182182
} else {
183-
key.objectid = dir->i_ino;
183+
key.objectid = btrfs_ino(dir);
184184
key.type = BTRFS_INODE_REF_KEY;
185185
key.offset = (u64)-1;
186186
}
@@ -240,26 +240,29 @@ static int btrfs_get_name(struct dentry *parent, char *name,
240240
struct btrfs_key key;
241241
int name_len;
242242
int ret;
243+
u64 ino;
243244

244245
if (!dir || !inode)
245246
return -EINVAL;
246247

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

251+
ino = btrfs_ino(inode);
252+
250253
path = btrfs_alloc_path();
251254
if (!path)
252255
return -ENOMEM;
253256
path->leave_spinning = 1;
254257

255-
if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
258+
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
256259
key.objectid = BTRFS_I(inode)->root->root_key.objectid;
257260
key.type = BTRFS_ROOT_BACKREF_KEY;
258261
key.offset = (u64)-1;
259262
root = root->fs_info->tree_root;
260263
} else {
261-
key.objectid = inode->i_ino;
262-
key.offset = dir->i_ino;
264+
key.objectid = ino;
265+
key.offset = btrfs_ino(dir);
263266
key.type = BTRFS_INODE_REF_KEY;
264267
}
265268

@@ -268,7 +271,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
268271
btrfs_free_path(path);
269272
return ret;
270273
} else if (ret > 0) {
271-
if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
274+
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
272275
path->slots[0]--;
273276
} else {
274277
btrfs_free_path(path);
@@ -277,11 +280,11 @@ static int btrfs_get_name(struct dentry *parent, char *name,
277280
}
278281
leaf = path->nodes[0];
279282

280-
if (inode->i_ino == BTRFS_FIRST_FREE_OBJECTID) {
281-
rref = btrfs_item_ptr(leaf, path->slots[0],
283+
if (ino == BTRFS_FIRST_FREE_OBJECTID) {
284+
rref = btrfs_item_ptr(leaf, path->slots[0],
282285
struct btrfs_root_ref);
283-
name_ptr = (unsigned long)(rref + 1);
284-
name_len = btrfs_root_ref_name_len(leaf, rref);
286+
name_ptr = (unsigned long)(rref + 1);
287+
name_len = btrfs_root_ref_name_len(leaf, rref);
285288
} else {
286289
iref = btrfs_item_ptr(leaf, path->slots[0],
287290
struct btrfs_inode_ref);

fs/btrfs/extent-tree.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7009,8 +7009,8 @@ static noinline int get_new_locations(struct inode *reloc_inode,
70097009

70107010
cur_pos = extent_key->objectid - offset;
70117011
last_byte = extent_key->objectid + extent_key->offset;
7012-
ret = btrfs_lookup_file_extent(NULL, root, path, reloc_inode->i_ino,
7013-
cur_pos, 0);
7012+
ret = btrfs_lookup_file_extent(NULL, root, path,
7013+
btrfs_ino(reloc_inode), cur_pos, 0);
70147014
if (ret < 0)
70157015
goto out;
70167016
if (ret > 0) {
@@ -7033,7 +7033,7 @@ static noinline int get_new_locations(struct inode *reloc_inode,
70337033
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
70347034
if (found_key.offset != cur_pos ||
70357035
found_key.type != BTRFS_EXTENT_DATA_KEY ||
7036-
found_key.objectid != reloc_inode->i_ino)
7036+
found_key.objectid != btrfs_ino(reloc_inode))
70377037
break;
70387038

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

7182-
if (inode && key.objectid != inode->i_ino) {
7182+
if (inode && key.objectid != btrfs_ino(inode)) {
71837183
BUG_ON(extent_locked);
71847184
btrfs_release_path(root, path);
71857185
mutex_unlock(&inode->i_mutex);
@@ -7488,7 +7488,7 @@ static noinline int invalidate_extent_cache(struct btrfs_root *root,
74887488
continue;
74897489
if (btrfs_file_extent_disk_bytenr(leaf, fi) == 0)
74907490
continue;
7491-
if (!inode || inode->i_ino != key.objectid) {
7491+
if (!inode || btrfs_ino(inode) != key.objectid) {
74927492
iput(inode);
74937493
inode = btrfs_ilookup(target_root->fs_info->sb,
74947494
key.objectid, target_root, 1);

fs/btrfs/extent_io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
30303030
* because there might be preallocation past i_size
30313031
*/
30323032
ret = btrfs_lookup_file_extent(NULL, BTRFS_I(inode)->root,
3033-
path, inode->i_ino, -1, 0);
3033+
path, btrfs_ino(inode), -1, 0);
30343034
if (ret < 0) {
30353035
btrfs_free_path(path);
30363036
return ret;
@@ -3043,7 +3043,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
30433043
found_type = btrfs_key_type(&found_key);
30443044

30453045
/* No extents, but there might be delalloc bits */
3046-
if (found_key.objectid != inode->i_ino ||
3046+
if (found_key.objectid != btrfs_ino(inode) ||
30473047
found_type != BTRFS_EXTENT_DATA_KEY) {
30483048
/* have to trust i_size as the end */
30493049
last = (u64)-1;

fs/btrfs/file-item.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
208208
EXTENT_NODATASUM, GFP_NOFS);
209209
} else {
210210
printk(KERN_INFO "btrfs no csum found "
211-
"for inode %lu start %llu\n",
212-
inode->i_ino,
211+
"for inode %llu start %llu\n",
212+
(unsigned long long)
213+
btrfs_ino(inode),
213214
(unsigned long long)offset);
214215
}
215216
item = NULL;

fs/btrfs/file.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
298298
struct btrfs_path *path;
299299
struct btrfs_key key;
300300
struct btrfs_key new_key;
301+
u64 ino = btrfs_ino(inode);
301302
u64 search_start = start;
302303
u64 disk_bytenr = 0;
303304
u64 num_bytes = 0;
@@ -318,14 +319,14 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
318319

319320
while (1) {
320321
recow = 0;
321-
ret = btrfs_lookup_file_extent(trans, root, path, inode->i_ino,
322+
ret = btrfs_lookup_file_extent(trans, root, path, ino,
322323
search_start, -1);
323324
if (ret < 0)
324325
break;
325326
if (ret > 0 && path->slots[0] > 0 && search_start == start) {
326327
leaf = path->nodes[0];
327328
btrfs_item_key_to_cpu(leaf, &key, path->slots[0] - 1);
328-
if (key.objectid == inode->i_ino &&
329+
if (key.objectid == ino &&
329330
key.type == BTRFS_EXTENT_DATA_KEY)
330331
path->slots[0]--;
331332
}
@@ -346,7 +347,7 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
346347
}
347348

348349
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
349-
if (key.objectid > inode->i_ino ||
350+
if (key.objectid > ino ||
350351
key.type > BTRFS_EXTENT_DATA_KEY || key.offset >= end)
351352
break;
352353

@@ -592,6 +593,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
592593
int del_slot = 0;
593594
int recow;
594595
int ret;
596+
u64 ino = btrfs_ino(inode);
595597

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

@@ -600,7 +602,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
600602
again:
601603
recow = 0;
602604
split = start;
603-
key.objectid = inode->i_ino;
605+
key.objectid = ino;
604606
key.type = BTRFS_EXTENT_DATA_KEY;
605607
key.offset = split;
606608

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

613615
leaf = path->nodes[0];
614616
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
615-
BUG_ON(key.objectid != inode->i_ino ||
616-
key.type != BTRFS_EXTENT_DATA_KEY);
617+
BUG_ON(key.objectid != ino || key.type != BTRFS_EXTENT_DATA_KEY);
617618
fi = btrfs_item_ptr(leaf, path->slots[0],
618619
struct btrfs_file_extent_item);
619620
BUG_ON(btrfs_file_extent_type(leaf, fi) !=
@@ -630,7 +631,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
630631
other_start = 0;
631632
other_end = start;
632633
if (extent_mergeable(leaf, path->slots[0] - 1,
633-
inode->i_ino, bytenr, orig_offset,
634+
ino, bytenr, orig_offset,
634635
&other_start, &other_end)) {
635636
new_key.offset = end;
636637
btrfs_set_item_key_safe(trans, root, path, &new_key);
@@ -653,7 +654,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
653654
other_start = end;
654655
other_end = 0;
655656
if (extent_mergeable(leaf, path->slots[0] + 1,
656-
inode->i_ino, bytenr, orig_offset,
657+
ino, bytenr, orig_offset,
657658
&other_start, &other_end)) {
658659
fi = btrfs_item_ptr(leaf, path->slots[0],
659660
struct btrfs_file_extent_item);
@@ -702,7 +703,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
702703

703704
ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, 0,
704705
root->root_key.objectid,
705-
inode->i_ino, orig_offset);
706+
ino, orig_offset);
706707
BUG_ON(ret);
707708

708709
if (split == start) {
@@ -718,7 +719,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
718719
other_start = end;
719720
other_end = 0;
720721
if (extent_mergeable(leaf, path->slots[0] + 1,
721-
inode->i_ino, bytenr, orig_offset,
722+
ino, bytenr, orig_offset,
722723
&other_start, &other_end)) {
723724
if (recow) {
724725
btrfs_release_path(root, path);
@@ -729,13 +730,13 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
729730
del_nr++;
730731
ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
731732
0, root->root_key.objectid,
732-
inode->i_ino, orig_offset);
733+
ino, orig_offset);
733734
BUG_ON(ret);
734735
}
735736
other_start = 0;
736737
other_end = start;
737738
if (extent_mergeable(leaf, path->slots[0] - 1,
738-
inode->i_ino, bytenr, orig_offset,
739+
ino, bytenr, orig_offset,
739740
&other_start, &other_end)) {
740741
if (recow) {
741742
btrfs_release_path(root, path);
@@ -746,7 +747,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
746747
del_nr++;
747748
ret = btrfs_free_extent(trans, root, bytenr, num_bytes,
748749
0, root->root_key.objectid,
749-
inode->i_ino, orig_offset);
750+
ino, orig_offset);
750751
BUG_ON(ret);
751752
}
752753
if (del_nr == 0) {

0 commit comments

Comments
 (0)