@@ -137,25 +137,22 @@ static int lookup_first_inode(struct btree_trans *trans, u64 inode_nr,
137
137
return ret ;
138
138
}
139
139
140
- static int lookup_inode (struct btree_trans * trans , u64 inode_nr ,
141
- struct bch_inode_unpacked * inode ,
142
- u32 * snapshot )
140
+ static int lookup_inode (struct btree_trans * trans , u64 inode_nr , u32 snapshot ,
141
+ struct bch_inode_unpacked * inode )
143
142
{
144
143
struct btree_iter iter ;
145
144
struct bkey_s_c k ;
146
145
int ret ;
147
146
148
147
k = bch2_bkey_get_iter (trans , & iter , BTREE_ID_inodes ,
149
- SPOS (0 , inode_nr , * snapshot ), 0 );
148
+ SPOS (0 , inode_nr , snapshot ), 0 );
150
149
ret = bkey_err (k );
151
150
if (ret )
152
151
goto err ;
153
152
154
153
ret = bkey_is_inode (k .k )
155
154
? bch2_inode_unpack (k , inode )
156
155
: - BCH_ERR_ENOENT_inode ;
157
- if (!ret )
158
- * snapshot = iter .pos .snapshot ;
159
156
err :
160
157
bch2_trans_iter_exit (trans , & iter );
161
158
return ret ;
@@ -250,8 +247,7 @@ static int lookup_lostfound(struct btree_trans *trans, u32 snapshot,
250
247
251
248
struct bch_inode_unpacked root_inode ;
252
249
struct bch_hash_info root_hash_info ;
253
- u32 root_inode_snapshot = snapshot ;
254
- ret = lookup_inode (trans , root_inum .inum , & root_inode , & root_inode_snapshot );
250
+ ret = lookup_inode (trans , root_inum .inum , snapshot , & root_inode );
255
251
bch_err_msg (c , ret , "looking up root inode %llu for subvol %u" ,
256
252
root_inum .inum , le32_to_cpu (st .master_subvol ));
257
253
if (ret )
@@ -277,7 +273,7 @@ static int lookup_lostfound(struct btree_trans *trans, u32 snapshot,
277
273
* The bch2_check_dirents pass has already run, dangling dirents
278
274
* shouldn't exist here:
279
275
*/
280
- ret = lookup_inode (trans , inum , lostfound , & snapshot );
276
+ ret = lookup_inode (trans , inum , snapshot , lostfound );
281
277
bch_err_msg (c , ret , "looking up lost+found %llu:%u in (root inode %llu, snapshot root %u)" ,
282
278
inum , snapshot , root_inum .inum , bch2_snapshot_root (c , snapshot ));
283
279
return ret ;
@@ -302,6 +298,7 @@ static int lookup_lostfound(struct btree_trans *trans, u32 snapshot,
302
298
bch2_inode_init_early (c , lostfound );
303
299
bch2_inode_init_late (lostfound , now , 0 , 0 , S_IFDIR |0700 , 0 , & root_inode );
304
300
lostfound -> bi_dir = root_inode .bi_inum ;
301
+ lostfound -> bi_snapshot = le32_to_cpu (st .root_snapshot );
305
302
306
303
root_inode .bi_nlink ++ ;
307
304
@@ -329,17 +326,15 @@ static int lookup_lostfound(struct btree_trans *trans, u32 snapshot,
329
326
return ret ;
330
327
}
331
328
332
- static int reattach_inode (struct btree_trans * trans ,
333
- struct bch_inode_unpacked * inode ,
334
- u32 inode_snapshot )
329
+ static int reattach_inode (struct btree_trans * trans , struct bch_inode_unpacked * inode )
335
330
{
336
331
struct bch_fs * c = trans -> c ;
337
332
struct bch_hash_info dir_hash ;
338
333
struct bch_inode_unpacked lostfound ;
339
334
char name_buf [20 ];
340
335
struct qstr name ;
341
336
u64 dir_offset = 0 ;
342
- u32 dirent_snapshot = inode_snapshot ;
337
+ u32 dirent_snapshot = inode -> bi_snapshot ;
343
338
int ret ;
344
339
345
340
if (inode -> bi_subvol ) {
@@ -363,7 +358,12 @@ static int reattach_inode(struct btree_trans *trans,
363
358
lostfound .bi_nlink += S_ISDIR (inode -> bi_mode );
364
359
365
360
/* ensure lost+found inode is also present in inode snapshot */
366
- ret = __bch2_fsck_write_inode (trans , & lostfound , inode_snapshot );
361
+ if (!inode -> bi_subvol ) {
362
+ BUG_ON (!bch2_snapshot_is_ancestor (c , inode -> bi_snapshot , lostfound .bi_snapshot ));
363
+ lostfound .bi_snapshot = inode -> bi_snapshot ;
364
+ }
365
+
366
+ ret = __bch2_fsck_write_inode (trans , & lostfound );
367
367
if (ret )
368
368
return ret ;
369
369
@@ -388,7 +388,7 @@ static int reattach_inode(struct btree_trans *trans,
388
388
inode -> bi_dir = lostfound .bi_inum ;
389
389
inode -> bi_dir_offset = dir_offset ;
390
390
391
- return __bch2_fsck_write_inode (trans , inode , inode_snapshot );
391
+ return __bch2_fsck_write_inode (trans , inode );
392
392
}
393
393
394
394
static int remove_backpointer (struct btree_trans * trans ,
@@ -427,7 +427,7 @@ static int reattach_subvol(struct btree_trans *trans, struct bkey_s_c_subvolume
427
427
if (ret )
428
428
return ret ;
429
429
430
- ret = reattach_inode (trans , & inode , le32_to_cpu ( s . v -> snapshot ) );
430
+ ret = reattach_inode (trans , & inode );
431
431
bch_err_msg (c , ret , "reattaching inode %llu" , inode .bi_inum );
432
432
return ret ;
433
433
}
@@ -545,8 +545,9 @@ static int reconstruct_inode(struct btree_trans *trans, enum btree_id btree, u32
545
545
bch2_inode_init_late (& new_inode , bch2_current_time (c ), 0 , 0 , i_mode |0600 , 0 , NULL );
546
546
new_inode .bi_size = i_size ;
547
547
new_inode .bi_inum = inum ;
548
+ new_inode .bi_snapshot = snapshot ;
548
549
549
- return __bch2_fsck_write_inode (trans , & new_inode , snapshot );
550
+ return __bch2_fsck_write_inode (trans , & new_inode );
550
551
}
551
552
552
553
struct snapshots_seen {
@@ -1110,7 +1111,7 @@ static int check_inode(struct btree_trans *trans,
1110
1111
1111
1112
u .bi_flags &= ~BCH_INODE_i_size_dirty |BCH_INODE_unlinked ;
1112
1113
1113
- ret = __bch2_fsck_write_inode (trans , & u , iter -> pos . snapshot );
1114
+ ret = __bch2_fsck_write_inode (trans , & u );
1114
1115
1115
1116
bch_err_msg (c , ret , "in fsck updating inode" );
1116
1117
if (ret )
@@ -1258,7 +1259,7 @@ static int check_inode(struct btree_trans *trans,
1258
1259
}
1259
1260
do_update :
1260
1261
if (do_update ) {
1261
- ret = __bch2_fsck_write_inode (trans , & u , iter -> pos . snapshot );
1262
+ ret = __bch2_fsck_write_inode (trans , & u );
1262
1263
bch_err_msg (c , ret , "in fsck updating inode" );
1263
1264
if (ret )
1264
1265
goto err_noprint ;
@@ -1383,7 +1384,7 @@ static int check_i_sectors_notnested(struct btree_trans *trans, struct inode_wal
1383
1384
w -> last_pos .inode , i -> snapshot ,
1384
1385
i -> inode .bi_sectors , i -> count )) {
1385
1386
i -> inode .bi_sectors = i -> count ;
1386
- ret = bch2_fsck_write_inode (trans , & i -> inode , i -> snapshot );
1387
+ ret = bch2_fsck_write_inode (trans , & i -> inode );
1387
1388
if (ret )
1388
1389
break ;
1389
1390
}
@@ -1825,7 +1826,7 @@ static int check_subdir_count_notnested(struct btree_trans *trans, struct inode_
1825
1826
"directory %llu:%u with wrong i_nlink: got %u, should be %llu" ,
1826
1827
w -> last_pos .inode , i -> snapshot , i -> inode .bi_nlink , i -> count )) {
1827
1828
i -> inode .bi_nlink = i -> count ;
1828
- ret = bch2_fsck_write_inode (trans , & i -> inode , i -> snapshot );
1829
+ ret = bch2_fsck_write_inode (trans , & i -> inode );
1829
1830
if (ret )
1830
1831
break ;
1831
1832
}
@@ -1846,8 +1847,7 @@ noinline_for_stack
1846
1847
static int check_dirent_inode_dirent (struct btree_trans * trans ,
1847
1848
struct btree_iter * iter ,
1848
1849
struct bkey_s_c_dirent d ,
1849
- struct bch_inode_unpacked * target ,
1850
- u32 target_snapshot )
1850
+ struct bch_inode_unpacked * target )
1851
1851
{
1852
1852
struct bch_fs * c = trans -> c ;
1853
1853
struct printbuf buf = PRINTBUF ;
@@ -1880,7 +1880,7 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
1880
1880
target -> bi_flags &= ~BCH_INODE_unlinked ;
1881
1881
target -> bi_dir = d .k -> p .inode ;
1882
1882
target -> bi_dir_offset = d .k -> p .offset ;
1883
- return __bch2_fsck_write_inode (trans , target , target_snapshot );
1883
+ return __bch2_fsck_write_inode (trans , target );
1884
1884
}
1885
1885
1886
1886
if (bch2_inode_should_have_bp (target ) &&
@@ -1893,7 +1893,7 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
1893
1893
goto err ;
1894
1894
1895
1895
struct bkey_s_c_dirent bp_dirent = dirent_get_by_pos (trans , & bp_iter ,
1896
- SPOS (target -> bi_dir , target -> bi_dir_offset , target_snapshot ));
1896
+ SPOS (target -> bi_dir , target -> bi_dir_offset , target -> bi_snapshot ));
1897
1897
ret = bkey_err (bp_dirent );
1898
1898
if (ret && !bch2_err_matches (ret , ENOENT ))
1899
1899
goto err ;
@@ -1906,14 +1906,14 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
1906
1906
"inode %llu:%u has wrong backpointer:\n"
1907
1907
"got %llu:%llu\n"
1908
1908
"should be %llu:%llu" ,
1909
- target -> bi_inum , target_snapshot ,
1909
+ target -> bi_inum , target -> bi_snapshot ,
1910
1910
target -> bi_dir ,
1911
1911
target -> bi_dir_offset ,
1912
1912
d .k -> p .inode ,
1913
1913
d .k -> p .offset )) {
1914
1914
target -> bi_dir = d .k -> p .inode ;
1915
1915
target -> bi_dir_offset = d .k -> p .offset ;
1916
- ret = __bch2_fsck_write_inode (trans , target , target_snapshot );
1916
+ ret = __bch2_fsck_write_inode (trans , target );
1917
1917
goto out ;
1918
1918
}
1919
1919
@@ -1928,7 +1928,7 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
1928
1928
trans , inode_dir_multiple_links ,
1929
1929
"%s %llu:%u with multiple links\n%s" ,
1930
1930
S_ISDIR (target -> bi_mode ) ? "directory" : "subvolume" ,
1931
- target -> bi_inum , target_snapshot , buf .buf )) {
1931
+ target -> bi_inum , target -> bi_snapshot , buf .buf )) {
1932
1932
ret = __remove_dirent (trans , d .k -> p );
1933
1933
goto out ;
1934
1934
}
@@ -1941,10 +1941,10 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
1941
1941
if (fsck_err_on (backpointer_exists && !target -> bi_nlink ,
1942
1942
trans , inode_multiple_links_but_nlink_0 ,
1943
1943
"inode %llu:%u type %s has multiple links but i_nlink 0\n%s" ,
1944
- target -> bi_inum , target_snapshot , bch2_d_types [d .v -> d_type ], buf .buf )) {
1944
+ target -> bi_inum , target -> bi_snapshot , bch2_d_types [d .v -> d_type ], buf .buf )) {
1945
1945
target -> bi_nlink ++ ;
1946
1946
target -> bi_flags &= ~BCH_INODE_unlinked ;
1947
- ret = __bch2_fsck_write_inode (trans , target , target_snapshot );
1947
+ ret = __bch2_fsck_write_inode (trans , target );
1948
1948
if (ret )
1949
1949
goto err ;
1950
1950
}
@@ -1961,15 +1961,14 @@ noinline_for_stack
1961
1961
static int check_dirent_target (struct btree_trans * trans ,
1962
1962
struct btree_iter * iter ,
1963
1963
struct bkey_s_c_dirent d ,
1964
- struct bch_inode_unpacked * target ,
1965
- u32 target_snapshot )
1964
+ struct bch_inode_unpacked * target )
1966
1965
{
1967
1966
struct bch_fs * c = trans -> c ;
1968
1967
struct bkey_i_dirent * n ;
1969
1968
struct printbuf buf = PRINTBUF ;
1970
1969
int ret = 0 ;
1971
1970
1972
- ret = check_dirent_inode_dirent (trans , iter , d , target , target_snapshot );
1971
+ ret = check_dirent_inode_dirent (trans , iter , d , target );
1973
1972
if (ret )
1974
1973
goto err ;
1975
1974
@@ -2128,7 +2127,7 @@ static int check_dirent_to_subvol(struct btree_trans *trans, struct btree_iter *
2128
2127
u64 target_inum = le64_to_cpu (s .v -> inode );
2129
2128
u32 target_snapshot = le32_to_cpu (s .v -> snapshot );
2130
2129
2131
- ret = lookup_inode (trans , target_inum , & subvol_root , & target_snapshot );
2130
+ ret = lookup_inode (trans , target_inum , target_snapshot , & subvol_root );
2132
2131
if (ret && !bch2_err_matches (ret , ENOENT ))
2133
2132
goto err ;
2134
2133
@@ -2144,13 +2143,13 @@ static int check_dirent_to_subvol(struct btree_trans *trans, struct btree_iter *
2144
2143
target_inum ,
2145
2144
subvol_root .bi_parent_subvol , parent_subvol )) {
2146
2145
subvol_root .bi_parent_subvol = parent_subvol ;
2147
- ret = __bch2_fsck_write_inode (trans , & subvol_root , target_snapshot );
2146
+ subvol_root .bi_snapshot = le32_to_cpu (s .v -> snapshot );
2147
+ ret = __bch2_fsck_write_inode (trans , & subvol_root );
2148
2148
if (ret )
2149
2149
goto err ;
2150
2150
}
2151
2151
2152
- ret = check_dirent_target (trans , iter , d , & subvol_root ,
2153
- target_snapshot );
2152
+ ret = check_dirent_target (trans , iter , d , & subvol_root );
2154
2153
if (ret )
2155
2154
goto err ;
2156
2155
out :
@@ -2243,8 +2242,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
2243
2242
}
2244
2243
2245
2244
darray_for_each (target -> inodes , i ) {
2246
- ret = check_dirent_target (trans , iter , d ,
2247
- & i -> inode , i -> snapshot );
2245
+ ret = check_dirent_target (trans , iter , d , & i -> inode );
2248
2246
if (ret )
2249
2247
goto err ;
2250
2248
}
@@ -2385,7 +2383,7 @@ static int check_root_trans(struct btree_trans *trans)
2385
2383
goto err ;
2386
2384
}
2387
2385
2388
- ret = lookup_inode (trans , BCACHEFS_ROOT_INO , & root_inode , & snapshot );
2386
+ ret = lookup_inode (trans , BCACHEFS_ROOT_INO , snapshot , & root_inode );
2389
2387
if (ret && !bch2_err_matches (ret , ENOENT ))
2390
2388
return ret ;
2391
2389
@@ -2398,8 +2396,9 @@ static int check_root_trans(struct btree_trans *trans)
2398
2396
bch2_inode_init (c , & root_inode , 0 , 0 , S_IFDIR |0755 ,
2399
2397
0 , NULL );
2400
2398
root_inode .bi_inum = inum ;
2399
+ root_inode .bi_snapshot = snapshot ;
2401
2400
2402
- ret = __bch2_fsck_write_inode (trans , & root_inode , snapshot );
2401
+ ret = __bch2_fsck_write_inode (trans , & root_inode );
2403
2402
bch_err_msg (c , ret , "writing root inode" );
2404
2403
}
2405
2404
err :
@@ -2566,7 +2565,7 @@ static int check_path(struct btree_trans *trans, pathbuf *p, struct bkey_s_c ino
2566
2565
(printbuf_reset (& buf ),
2567
2566
bch2_bkey_val_to_text (& buf , c , inode_k ),
2568
2567
buf .buf )))
2569
- ret = reattach_inode (trans , & inode , snapshot );
2568
+ ret = reattach_inode (trans , & inode );
2570
2569
goto out ;
2571
2570
}
2572
2571
@@ -2612,7 +2611,7 @@ static int check_path(struct btree_trans *trans, pathbuf *p, struct bkey_s_c ino
2612
2611
if (ret )
2613
2612
break ;
2614
2613
2615
- ret = reattach_inode (trans , & inode , snapshot );
2614
+ ret = reattach_inode (trans , & inode );
2616
2615
bch_err_msg (c , ret , "reattaching inode %llu" , inode .bi_inum );
2617
2616
}
2618
2617
break ;
@@ -2842,7 +2841,7 @@ static int check_nlinks_update_inode(struct btree_trans *trans, struct btree_ite
2842
2841
u .bi_inum , bch2_d_types [mode_to_type (u .bi_mode )],
2843
2842
bch2_inode_nlink_get (& u ), link -> count )) {
2844
2843
bch2_inode_nlink_set (& u , link -> count );
2845
- ret = __bch2_fsck_write_inode (trans , & u , k . k -> p . snapshot );
2844
+ ret = __bch2_fsck_write_inode (trans , & u );
2846
2845
}
2847
2846
fsck_err :
2848
2847
return ret ;
0 commit comments