Skip to content

Commit 6c43f41

Browse files
committed
nilfs2: keep zero value in i_cno except for gc-inodes
On-memory inode structures of nilfs have a member "i_cno" which stores a checkpoint number related to the inode. For gc-inodes, this field indicates version of data each gc-inode caches for GC. Log writer temporarily uses "i_cno" to transfer the latest checkpoint number. This stops the latter use and lets only gc-inodes use it. The purpose of this patch is to allow the successive change use "i_cno" for inode lookup. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
1 parent 7d6cd92 commit 6c43f41

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

‎fs/nilfs2/segment.c‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ static int nilfs_segctor_reset_segment_buffer(struct nilfs_sc_info *sci)
366366

367367
if (nilfs_doing_gc())
368368
flags = NILFS_SS_GC;
369-
err = nilfs_segbuf_reset(segbuf, flags, sci->sc_seg_ctime,
370-
sci->sc_sbi->s_nilfs->ns_cno);
369+
err = nilfs_segbuf_reset(segbuf, flags, sci->sc_seg_ctime, sci->sc_cno);
371370
if (unlikely(err))
372371
return err;
373372

@@ -440,17 +439,26 @@ static void nilfs_segctor_end_finfo(struct nilfs_sc_info *sci,
440439
struct nilfs_finfo *finfo;
441440
struct nilfs_inode_info *ii;
442441
struct nilfs_segment_buffer *segbuf;
442+
__u64 cno;
443443

444444
if (sci->sc_blk_cnt == 0)
445445
return;
446446

447447
ii = NILFS_I(inode);
448+
449+
if (test_bit(NILFS_I_GCINODE, &ii->i_state))
450+
cno = ii->i_cno;
451+
else if (NILFS_ROOT_METADATA_FILE(inode->i_ino))
452+
cno = 0;
453+
else
454+
cno = sci->sc_cno;
455+
448456
finfo = nilfs_segctor_map_segsum_entry(sci, &sci->sc_finfo_ptr,
449457
sizeof(*finfo));
450458
finfo->fi_ino = cpu_to_le64(inode->i_ino);
451459
finfo->fi_nblocks = cpu_to_le32(sci->sc_blk_cnt);
452460
finfo->fi_ndatablk = cpu_to_le32(sci->sc_datablk_cnt);
453-
finfo->fi_cno = cpu_to_le64(ii->i_cno);
461+
finfo->fi_cno = cpu_to_le64(cno);
454462

455463
segbuf = sci->sc_curseg;
456464
segbuf->sb_sum.sumbytes = sci->sc_binfo_ptr.offset +
@@ -1976,7 +1984,6 @@ static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci,
19761984
struct nilfs_sb_info *sbi)
19771985
{
19781986
struct nilfs_inode_info *ii, *n;
1979-
__u64 cno = sbi->s_nilfs->ns_cno;
19801987

19811988
spin_lock(&sbi->s_inode_lock);
19821989
retry:
@@ -2002,7 +2009,6 @@ static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci,
20022009
brelse(ibh);
20032010
goto retry;
20042011
}
2005-
ii->i_cno = cno;
20062012

20072013
clear_bit(NILFS_I_QUEUED, &ii->i_state);
20082014
set_bit(NILFS_I_BUSY, &ii->i_state);
@@ -2011,8 +2017,6 @@ static int nilfs_segctor_check_in_files(struct nilfs_sc_info *sci,
20112017
}
20122018
spin_unlock(&sbi->s_inode_lock);
20132019

2014-
NILFS_I(sbi->s_ifile)->i_cno = cno;
2015-
20162020
return 0;
20172021
}
20182022

@@ -2021,19 +2025,13 @@ static void nilfs_segctor_check_out_files(struct nilfs_sc_info *sci,
20212025
{
20222026
struct nilfs_transaction_info *ti = current->journal_info;
20232027
struct nilfs_inode_info *ii, *n;
2024-
__u64 cno = sbi->s_nilfs->ns_cno;
20252028

20262029
spin_lock(&sbi->s_inode_lock);
20272030
list_for_each_entry_safe(ii, n, &sci->sc_dirty_files, i_dirty) {
20282031
if (!test_and_clear_bit(NILFS_I_UPDATED, &ii->i_state) ||
2029-
test_bit(NILFS_I_DIRTY, &ii->i_state)) {
2030-
/* The current checkpoint number (=nilfs->ns_cno) is
2031-
changed between check-in and check-out only if the
2032-
super root is written out. So, we can update i_cno
2033-
for the inodes that remain in the dirty list. */
2034-
ii->i_cno = cno;
2032+
test_bit(NILFS_I_DIRTY, &ii->i_state))
20352033
continue;
2036-
}
2034+
20372035
clear_bit(NILFS_I_BUSY, &ii->i_state);
20382036
brelse(ii->i_bh);
20392037
ii->i_bh = NULL;
@@ -2054,6 +2052,7 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
20542052
int err;
20552053

20562054
sci->sc_stage.scnt = NILFS_ST_INIT;
2055+
sci->sc_cno = nilfs->ns_cno;
20572056

20582057
err = nilfs_segctor_check_in_files(sci, sbi);
20592058
if (unlikely(err))

‎fs/nilfs2/segment.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct nilfs_segsum_pointer {
107107
* @sc_datablk_cnt: Data block count of a file
108108
* @sc_nblk_this_inc: Number of blocks included in the current logical segment
109109
* @sc_seg_ctime: Creation time
110+
* @sc_cno: checkpoint number of current log
110111
* @sc_flags: Internal flags
111112
* @sc_state_lock: spinlock for sc_state and so on
112113
* @sc_state: Segctord state flags
@@ -156,7 +157,7 @@ struct nilfs_sc_info {
156157
unsigned long sc_datablk_cnt;
157158
unsigned long sc_nblk_this_inc;
158159
time_t sc_seg_ctime;
159-
160+
__u64 sc_cno;
160161
unsigned long sc_flags;
161162

162163
spinlock_t sc_state_lock;

‎include/linux/nilfs2_fs.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,14 @@ struct nilfs_super_block {
270270
#define NILFS_MIN_NRSVSEGS 8 /* Minimum number of reserved
271271
segments */
272272

273+
/*
274+
* We call DAT, cpfile, and sufile root metadata files. Inodes of
275+
* these files are written in super root block instead of ifile, and
276+
* garbage collector doesn't keep any past versions of these files.
277+
*/
278+
#define NILFS_ROOT_METADATA_FILE(ino) \
279+
((ino) >= NILFS_DAT_INO && (ino) <= NILFS_SUFILE_INO)
280+
273281
/*
274282
* bytes offset of secondary super block
275283
*/

0 commit comments

Comments
 (0)