Skip to content

Commit d7cee0b

Browse files
konisakpm00
authored andcommitted
nilfs2: separate inode type information from i_state field
In nilfs_iget_locked() and nilfs_ilookup(), which are used to find or obtain nilfs2 inodes, the nilfs_iget_args structure used to identify inodes has type information divided into multiple booleans, making type determination complicated. Simplify inode type determination by consolidating inode type information into an unsigned integer represented by a comibination of flags and by separating the type identification information for on-memory inodes from the i_state member in the nilfs_inode_info structure. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ryusuke Konishi <[email protected]> Cc: Huang Xiaojia <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 21176c0 commit d7cee0b

File tree

4 files changed

+28
-46
lines changed

4 files changed

+28
-46
lines changed

fs/nilfs2/inode.c

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,13 @@
2828
* @ino: inode number
2929
* @cno: checkpoint number
3030
* @root: pointer on NILFS root object (mounted checkpoint)
31-
* @for_gc: inode for GC flag
32-
* @for_btnc: inode for B-tree node cache flag
33-
* @for_shadow: inode for shadowed page cache flag
31+
* @type: inode type
3432
*/
3533
struct nilfs_iget_args {
3634
u64 ino;
3735
__u64 cno;
3836
struct nilfs_root *root;
39-
bool for_gc;
40-
bool for_btnc;
41-
bool for_shadow;
37+
unsigned int type;
4238
};
4339

4440
static int nilfs_iget_test(struct inode *inode, void *opaque);
@@ -315,8 +311,7 @@ static int nilfs_insert_inode_locked(struct inode *inode,
315311
unsigned long ino)
316312
{
317313
struct nilfs_iget_args args = {
318-
.ino = ino, .root = root, .cno = 0, .for_gc = false,
319-
.for_btnc = false, .for_shadow = false
314+
.ino = ino, .root = root, .cno = 0, .type = NILFS_I_TYPE_NORMAL
320315
};
321316

322317
return insert_inode_locked4(inode, ino, nilfs_iget_test, &args);
@@ -343,6 +338,7 @@ struct inode *nilfs_new_inode(struct inode *dir, umode_t mode)
343338
root = NILFS_I(dir)->i_root;
344339
ii = NILFS_I(inode);
345340
ii->i_state = BIT(NILFS_I_NEW);
341+
ii->i_type = NILFS_I_TYPE_NORMAL;
346342
ii->i_root = root;
347343

348344
err = nilfs_ifile_create_inode(root->ifile, &ino, &bh);
@@ -546,23 +542,10 @@ static int nilfs_iget_test(struct inode *inode, void *opaque)
546542
return 0;
547543

548544
ii = NILFS_I(inode);
549-
if (test_bit(NILFS_I_BTNC, &ii->i_state)) {
550-
if (!args->for_btnc)
551-
return 0;
552-
} else if (args->for_btnc) {
545+
if (ii->i_type != args->type)
553546
return 0;
554-
}
555-
if (test_bit(NILFS_I_SHADOW, &ii->i_state)) {
556-
if (!args->for_shadow)
557-
return 0;
558-
} else if (args->for_shadow) {
559-
return 0;
560-
}
561547

562-
if (!test_bit(NILFS_I_GCINODE, &ii->i_state))
563-
return !args->for_gc;
564-
565-
return args->for_gc && args->cno == ii->i_cno;
548+
return !(args->type & NILFS_I_TYPE_GC) || args->cno == ii->i_cno;
566549
}
567550

568551
static int nilfs_iget_set(struct inode *inode, void *opaque)
@@ -572,24 +555,17 @@ static int nilfs_iget_set(struct inode *inode, void *opaque)
572555
inode->i_ino = args->ino;
573556
NILFS_I(inode)->i_cno = args->cno;
574557
NILFS_I(inode)->i_root = args->root;
558+
NILFS_I(inode)->i_type = args->type;
575559
if (args->root && args->ino == NILFS_ROOT_INO)
576560
nilfs_get_root(args->root);
577-
578-
if (args->for_gc)
579-
NILFS_I(inode)->i_state = BIT(NILFS_I_GCINODE);
580-
if (args->for_btnc)
581-
NILFS_I(inode)->i_state |= BIT(NILFS_I_BTNC);
582-
if (args->for_shadow)
583-
NILFS_I(inode)->i_state |= BIT(NILFS_I_SHADOW);
584561
return 0;
585562
}
586563

587564
struct inode *nilfs_ilookup(struct super_block *sb, struct nilfs_root *root,
588565
unsigned long ino)
589566
{
590567
struct nilfs_iget_args args = {
591-
.ino = ino, .root = root, .cno = 0, .for_gc = false,
592-
.for_btnc = false, .for_shadow = false
568+
.ino = ino, .root = root, .cno = 0, .type = NILFS_I_TYPE_NORMAL
593569
};
594570

595571
return ilookup5(sb, ino, nilfs_iget_test, &args);
@@ -599,8 +575,7 @@ struct inode *nilfs_iget_locked(struct super_block *sb, struct nilfs_root *root,
599575
unsigned long ino)
600576
{
601577
struct nilfs_iget_args args = {
602-
.ino = ino, .root = root, .cno = 0, .for_gc = false,
603-
.for_btnc = false, .for_shadow = false
578+
.ino = ino, .root = root, .cno = 0, .type = NILFS_I_TYPE_NORMAL
604579
};
605580

606581
return iget5_locked(sb, ino, nilfs_iget_test, nilfs_iget_set, &args);
@@ -631,8 +606,7 @@ struct inode *nilfs_iget_for_gc(struct super_block *sb, unsigned long ino,
631606
__u64 cno)
632607
{
633608
struct nilfs_iget_args args = {
634-
.ino = ino, .root = NULL, .cno = cno, .for_gc = true,
635-
.for_btnc = false, .for_shadow = false
609+
.ino = ino, .root = NULL, .cno = cno, .type = NILFS_I_TYPE_GC
636610
};
637611
struct inode *inode;
638612
int err;
@@ -677,9 +651,7 @@ int nilfs_attach_btree_node_cache(struct inode *inode)
677651
args.ino = inode->i_ino;
678652
args.root = ii->i_root;
679653
args.cno = ii->i_cno;
680-
args.for_gc = test_bit(NILFS_I_GCINODE, &ii->i_state) != 0;
681-
args.for_btnc = true;
682-
args.for_shadow = test_bit(NILFS_I_SHADOW, &ii->i_state) != 0;
654+
args.type = ii->i_type | NILFS_I_TYPE_BTNC;
683655

684656
btnc_inode = iget5_locked(inode->i_sb, inode->i_ino, nilfs_iget_test,
685657
nilfs_iget_set, &args);
@@ -733,8 +705,8 @@ void nilfs_detach_btree_node_cache(struct inode *inode)
733705
struct inode *nilfs_iget_for_shadow(struct inode *inode)
734706
{
735707
struct nilfs_iget_args args = {
736-
.ino = inode->i_ino, .root = NULL, .cno = 0, .for_gc = false,
737-
.for_btnc = false, .for_shadow = true
708+
.ino = inode->i_ino, .root = NULL, .cno = 0,
709+
.type = NILFS_I_TYPE_SHADOW
738710
};
739711
struct inode *s_inode;
740712
int err;
@@ -900,7 +872,7 @@ static void nilfs_clear_inode(struct inode *inode)
900872
if (test_bit(NILFS_I_BMAP, &ii->i_state))
901873
nilfs_bmap_clear(ii->i_bmap);
902874

903-
if (!test_bit(NILFS_I_BTNC, &ii->i_state))
875+
if (!(ii->i_type & NILFS_I_TYPE_BTNC))
904876
nilfs_detach_btree_node_cache(inode);
905877

906878
if (ii->i_root && inode->i_ino == NILFS_ROOT_INO)

fs/nilfs2/nilfs.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/**
2323
* struct nilfs_inode_info - nilfs inode data in memory
2424
* @i_flags: inode flags
25+
* @i_type: inode type (combination of flags that inidicate usage)
2526
* @i_state: dynamic state flags
2627
* @i_bmap: pointer on i_bmap_data
2728
* @i_bmap_data: raw block mapping
@@ -37,6 +38,7 @@
3738
*/
3839
struct nilfs_inode_info {
3940
__u32 i_flags;
41+
unsigned int i_type;
4042
unsigned long i_state; /* Dynamic state flags */
4143
struct nilfs_bmap *i_bmap;
4244
struct nilfs_bmap i_bmap_data;
@@ -90,9 +92,16 @@ enum {
9092
NILFS_I_UPDATED, /* The file has been written back */
9193
NILFS_I_INODE_SYNC, /* dsync is not allowed for inode */
9294
NILFS_I_BMAP, /* has bmap and btnode_cache */
93-
NILFS_I_GCINODE, /* inode for GC, on memory only */
94-
NILFS_I_BTNC, /* inode for btree node cache */
95-
NILFS_I_SHADOW, /* inode for shadowed page cache */
95+
};
96+
97+
/*
98+
* Flags to identify the usage of on-memory inodes (i_type)
99+
*/
100+
enum {
101+
NILFS_I_TYPE_NORMAL = 0,
102+
NILFS_I_TYPE_GC = 0x0001, /* For data caching during GC */
103+
NILFS_I_TYPE_BTNC = 0x0002, /* For btree node cache */
104+
NILFS_I_TYPE_SHADOW = 0x0004, /* For shadowed page cache */
96105
};
97106

98107
/*

fs/nilfs2/segment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static void nilfs_segctor_end_finfo(struct nilfs_sc_info *sci,
519519

520520
ii = NILFS_I(inode);
521521

522-
if (test_bit(NILFS_I_GCINODE, &ii->i_state))
522+
if (ii->i_type & NILFS_I_TYPE_GC)
523523
cno = ii->i_cno;
524524
else if (NILFS_ROOT_METADATA_FILE(inode->i_ino))
525525
cno = 0;

fs/nilfs2/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ struct inode *nilfs_alloc_inode(struct super_block *sb)
160160
return NULL;
161161
ii->i_bh = NULL;
162162
ii->i_state = 0;
163+
ii->i_type = 0;
163164
ii->i_cno = 0;
164165
ii->i_assoc_inode = NULL;
165166
ii->i_bmap = &ii->i_bmap_data;

0 commit comments

Comments
 (0)