Skip to content

Commit 103ffe9

Browse files
author
Kent Overstreet
committed
bcachefs: x-macro-ify inode flags enum
This lets us use bch2_prt_bitflags to print them out. Signed-off-by: Kent Overstreet <[email protected]>
1 parent d4c8bb6 commit 103ffe9

File tree

9 files changed

+89
-83
lines changed

9 files changed

+89
-83
lines changed

fs/bcachefs/bcachefs_format.h

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -824,34 +824,30 @@ enum inode_opt_id {
824824
Inode_opt_nr,
825825
};
826826

827-
enum {
828-
/*
829-
* User flags (get/settable with FS_IOC_*FLAGS, correspond to FS_*_FL
830-
* flags)
831-
*/
832-
__BCH_INODE_SYNC = 0,
833-
__BCH_INODE_IMMUTABLE = 1,
834-
__BCH_INODE_APPEND = 2,
835-
__BCH_INODE_NODUMP = 3,
836-
__BCH_INODE_NOATIME = 4,
837-
838-
__BCH_INODE_I_SIZE_DIRTY = 5, /* obsolete */
839-
__BCH_INODE_I_SECTORS_DIRTY = 6, /* obsolete */
840-
__BCH_INODE_UNLINKED = 7,
841-
__BCH_INODE_BACKPTR_UNTRUSTED = 8,
842-
843-
/* bits 20+ reserved for packed fields below: */
844-
};
845-
846-
#define BCH_INODE_SYNC (1 << __BCH_INODE_SYNC)
847-
#define BCH_INODE_IMMUTABLE (1 << __BCH_INODE_IMMUTABLE)
848-
#define BCH_INODE_APPEND (1 << __BCH_INODE_APPEND)
849-
#define BCH_INODE_NODUMP (1 << __BCH_INODE_NODUMP)
850-
#define BCH_INODE_NOATIME (1 << __BCH_INODE_NOATIME)
851-
#define BCH_INODE_I_SIZE_DIRTY (1 << __BCH_INODE_I_SIZE_DIRTY)
852-
#define BCH_INODE_I_SECTORS_DIRTY (1 << __BCH_INODE_I_SECTORS_DIRTY)
853-
#define BCH_INODE_UNLINKED (1 << __BCH_INODE_UNLINKED)
854-
#define BCH_INODE_BACKPTR_UNTRUSTED (1 << __BCH_INODE_BACKPTR_UNTRUSTED)
827+
#define BCH_INODE_FLAGS() \
828+
x(sync, 0) \
829+
x(immutable, 1) \
830+
x(append, 2) \
831+
x(nodump, 3) \
832+
x(noatime, 4) \
833+
x(i_size_dirty, 5) \
834+
x(i_sectors_dirty, 6) \
835+
x(unlinked, 7) \
836+
x(backptr_untrusted, 8)
837+
838+
/* bits 20+ reserved for packed fields below: */
839+
840+
enum bch_inode_flags {
841+
#define x(t, n) BCH_INODE_##t = 1U << n,
842+
BCH_INODE_FLAGS()
843+
#undef x
844+
};
845+
846+
enum __bch_inode_flags {
847+
#define x(t, n) __BCH_INODE_##t = n,
848+
BCH_INODE_FLAGS()
849+
#undef x
850+
};
855851

856852
LE32_BITMASK(INODE_STR_HASH, struct bch_inode, bi_flags, 20, 24);
857853
LE32_BITMASK(INODE_NR_FIELDS, struct bch_inode, bi_flags, 24, 31);

fs/bcachefs/fs-common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int bch2_create_trans(struct btree_trans *trans,
5151
bch2_inode_init_late(new_inode, now, uid, gid, mode, rdev, dir_u);
5252

5353
if (flags & BCH_CREATE_TMPFILE)
54-
new_inode->bi_flags |= BCH_INODE_UNLINKED;
54+
new_inode->bi_flags |= BCH_INODE_unlinked;
5555

5656
ret = bch2_inode_create(trans, &inode_iter, new_inode, snapshot, cpu);
5757
if (ret)

fs/bcachefs/fs-ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ static int bch2_inode_flags_set(struct btree_trans *trans,
4545
unsigned newflags = s->flags;
4646
unsigned oldflags = bi->bi_flags & s->mask;
4747

48-
if (((newflags ^ oldflags) & (BCH_INODE_APPEND|BCH_INODE_IMMUTABLE)) &&
48+
if (((newflags ^ oldflags) & (BCH_INODE_append|BCH_INODE_immutable)) &&
4949
!capable(CAP_LINUX_IMMUTABLE))
5050
return -EPERM;
5151

5252
if (!S_ISREG(bi->bi_mode) &&
5353
!S_ISDIR(bi->bi_mode) &&
54-
(newflags & (BCH_INODE_NODUMP|BCH_INODE_NOATIME)) != newflags)
54+
(newflags & (BCH_INODE_nodump|BCH_INODE_noatime)) != newflags)
5555
return -EINVAL;
5656

5757
if (s->set_projinherit) {

fs/bcachefs/fs-ioctl.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@
66

77
/* bcachefs inode flags -> vfs inode flags: */
88
static const __maybe_unused unsigned bch_flags_to_vfs[] = {
9-
[__BCH_INODE_SYNC] = S_SYNC,
10-
[__BCH_INODE_IMMUTABLE] = S_IMMUTABLE,
11-
[__BCH_INODE_APPEND] = S_APPEND,
12-
[__BCH_INODE_NOATIME] = S_NOATIME,
9+
[__BCH_INODE_sync] = S_SYNC,
10+
[__BCH_INODE_immutable] = S_IMMUTABLE,
11+
[__BCH_INODE_append] = S_APPEND,
12+
[__BCH_INODE_noatime] = S_NOATIME,
1313
};
1414

1515
/* bcachefs inode flags -> FS_IOC_GETFLAGS: */
1616
static const __maybe_unused unsigned bch_flags_to_uflags[] = {
17-
[__BCH_INODE_SYNC] = FS_SYNC_FL,
18-
[__BCH_INODE_IMMUTABLE] = FS_IMMUTABLE_FL,
19-
[__BCH_INODE_APPEND] = FS_APPEND_FL,
20-
[__BCH_INODE_NODUMP] = FS_NODUMP_FL,
21-
[__BCH_INODE_NOATIME] = FS_NOATIME_FL,
17+
[__BCH_INODE_sync] = FS_SYNC_FL,
18+
[__BCH_INODE_immutable] = FS_IMMUTABLE_FL,
19+
[__BCH_INODE_append] = FS_APPEND_FL,
20+
[__BCH_INODE_nodump] = FS_NODUMP_FL,
21+
[__BCH_INODE_noatime] = FS_NOATIME_FL,
2222
};
2323

2424
/* bcachefs inode flags -> FS_IOC_FSGETXATTR: */
2525
static const __maybe_unused unsigned bch_flags_to_xflags[] = {
26-
[__BCH_INODE_SYNC] = FS_XFLAG_SYNC,
27-
[__BCH_INODE_IMMUTABLE] = FS_XFLAG_IMMUTABLE,
28-
[__BCH_INODE_APPEND] = FS_XFLAG_APPEND,
29-
[__BCH_INODE_NODUMP] = FS_XFLAG_NODUMP,
30-
[__BCH_INODE_NOATIME] = FS_XFLAG_NOATIME,
26+
[__BCH_INODE_sync] = FS_XFLAG_SYNC,
27+
[__BCH_INODE_immutable] = FS_XFLAG_IMMUTABLE,
28+
[__BCH_INODE_append] = FS_XFLAG_APPEND,
29+
[__BCH_INODE_nodump] = FS_XFLAG_NODUMP,
30+
[__BCH_INODE_noatime] = FS_XFLAG_NOATIME,
3131
//[__BCH_INODE_PROJINHERIT] = FS_XFLAG_PROJINHERIT;
3232
};
3333

fs/bcachefs/fs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,15 +764,15 @@ static int bch2_getattr(struct mnt_idmap *idmap,
764764
stat->btime = bch2_time_to_timespec(c, inode->ei_inode.bi_otime);
765765
}
766766

767-
if (inode->ei_inode.bi_flags & BCH_INODE_IMMUTABLE)
767+
if (inode->ei_inode.bi_flags & BCH_INODE_immutable)
768768
stat->attributes |= STATX_ATTR_IMMUTABLE;
769769
stat->attributes_mask |= STATX_ATTR_IMMUTABLE;
770770

771-
if (inode->ei_inode.bi_flags & BCH_INODE_APPEND)
771+
if (inode->ei_inode.bi_flags & BCH_INODE_append)
772772
stat->attributes |= STATX_ATTR_APPEND;
773773
stat->attributes_mask |= STATX_ATTR_APPEND;
774774

775-
if (inode->ei_inode.bi_flags & BCH_INODE_NODUMP)
775+
if (inode->ei_inode.bi_flags & BCH_INODE_nodump)
776776
stat->attributes |= STATX_ATTR_NODUMP;
777777
stat->attributes_mask |= STATX_ATTR_NODUMP;
778778

fs/bcachefs/fsck.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,9 @@ static int check_inode(struct btree_trans *trans,
854854
BUG_ON(bch2_inode_unpack(k, &u));
855855

856856
if (!full &&
857-
!(u.bi_flags & (BCH_INODE_I_SIZE_DIRTY|
858-
BCH_INODE_I_SECTORS_DIRTY|
859-
BCH_INODE_UNLINKED)))
857+
!(u.bi_flags & (BCH_INODE_i_size_dirty|
858+
BCH_INODE_i_sectors_dirty|
859+
BCH_INODE_unlinked)))
860860
return 0;
861861

862862
if (prev->bi_inum != u.bi_inum)
@@ -870,15 +870,15 @@ static int check_inode(struct btree_trans *trans,
870870
return -EINVAL;
871871
}
872872

873-
if ((u.bi_flags & (BCH_INODE_I_SIZE_DIRTY|BCH_INODE_UNLINKED)) &&
873+
if ((u.bi_flags & (BCH_INODE_i_size_dirty|BCH_INODE_unlinked)) &&
874874
bch2_key_has_snapshot_overwrites(trans, BTREE_ID_inodes, k.k->p)) {
875875
struct bpos new_min_pos;
876876

877877
ret = bch2_propagate_key_to_snapshot_leaves(trans, iter->btree_id, k, &new_min_pos);
878878
if (ret)
879879
goto err;
880880

881-
u.bi_flags &= ~BCH_INODE_I_SIZE_DIRTY|BCH_INODE_UNLINKED;
881+
u.bi_flags &= ~BCH_INODE_i_size_dirty|BCH_INODE_unlinked;
882882

883883
ret = __write_inode(trans, &u, iter->pos.snapshot);
884884
bch_err_msg(c, ret, "in fsck updating inode");
@@ -890,7 +890,7 @@ static int check_inode(struct btree_trans *trans,
890890
return 0;
891891
}
892892

893-
if (u.bi_flags & BCH_INODE_UNLINKED &&
893+
if (u.bi_flags & BCH_INODE_unlinked &&
894894
(!c->sb.clean ||
895895
fsck_err(c, inode_unlinked_but_clean,
896896
"filesystem marked clean, but inode %llu unlinked",
@@ -903,7 +903,7 @@ static int check_inode(struct btree_trans *trans,
903903
return ret;
904904
}
905905

906-
if (u.bi_flags & BCH_INODE_I_SIZE_DIRTY &&
906+
if (u.bi_flags & BCH_INODE_i_size_dirty &&
907907
(!c->sb.clean ||
908908
fsck_err(c, inode_i_size_dirty_but_clean,
909909
"filesystem marked clean, but inode %llu has i_size dirty",
@@ -930,13 +930,13 @@ static int check_inode(struct btree_trans *trans,
930930
* We truncated without our normal sector accounting hook, just
931931
* make sure we recalculate it:
932932
*/
933-
u.bi_flags |= BCH_INODE_I_SECTORS_DIRTY;
933+
u.bi_flags |= BCH_INODE_i_sectors_dirty;
934934

935-
u.bi_flags &= ~BCH_INODE_I_SIZE_DIRTY;
935+
u.bi_flags &= ~BCH_INODE_i_size_dirty;
936936
do_update = true;
937937
}
938938

939-
if (u.bi_flags & BCH_INODE_I_SECTORS_DIRTY &&
939+
if (u.bi_flags & BCH_INODE_i_sectors_dirty &&
940940
(!c->sb.clean ||
941941
fsck_err(c, inode_i_sectors_dirty_but_clean,
942942
"filesystem marked clean, but inode %llu has i_sectors dirty",
@@ -953,14 +953,14 @@ static int check_inode(struct btree_trans *trans,
953953
}
954954

955955
u.bi_sectors = sectors;
956-
u.bi_flags &= ~BCH_INODE_I_SECTORS_DIRTY;
956+
u.bi_flags &= ~BCH_INODE_i_sectors_dirty;
957957
do_update = true;
958958
}
959959

960-
if (u.bi_flags & BCH_INODE_BACKPTR_UNTRUSTED) {
960+
if (u.bi_flags & BCH_INODE_backptr_untrusted) {
961961
u.bi_dir = 0;
962962
u.bi_dir_offset = 0;
963-
u.bi_flags &= ~BCH_INODE_BACKPTR_UNTRUSTED;
963+
u.bi_flags &= ~BCH_INODE_backptr_untrusted;
964964
do_update = true;
965965
}
966966

@@ -1065,7 +1065,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w)
10651065
return -BCH_ERR_internal_fsck_err;
10661066
}
10671067

1068-
if (fsck_err_on(!(i->inode.bi_flags & BCH_INODE_I_SECTORS_DIRTY),
1068+
if (fsck_err_on(!(i->inode.bi_flags & BCH_INODE_i_sectors_dirty),
10691069
c, inode_i_sectors_wrong,
10701070
"inode %llu:%u has incorrect i_sectors: got %llu, should be %llu",
10711071
w->last_pos.inode, i->snapshot,
@@ -1405,7 +1405,7 @@ static int check_extent(struct btree_trans *trans, struct btree_iter *iter,
14051405
continue;
14061406

14071407
if (k.k->type != KEY_TYPE_whiteout) {
1408-
if (fsck_err_on(!(i->inode.bi_flags & BCH_INODE_I_SIZE_DIRTY) &&
1408+
if (fsck_err_on(!(i->inode.bi_flags & BCH_INODE_i_size_dirty) &&
14091409
k.k->p.offset > round_up(i->inode.bi_size, block_bytes(c)) >> 9 &&
14101410
!bkey_extent_is_reservation(k),
14111411
c, extent_past_end_of_inode,
@@ -1588,7 +1588,7 @@ static int check_dirent_target(struct btree_trans *trans,
15881588
"inode %llu type %s has multiple links but i_nlink 0",
15891589
target->bi_inum, bch2_d_types[d.v->d_type])) {
15901590
target->bi_nlink++;
1591-
target->bi_flags &= ~BCH_INODE_UNLINKED;
1591+
target->bi_flags &= ~BCH_INODE_unlinked;
15921592

15931593
ret = __write_inode(trans, target, target_snapshot);
15941594
if (ret)
@@ -2160,7 +2160,7 @@ int bch2_check_directory_structure(struct bch_fs *c)
21602160
break;
21612161
}
21622162

2163-
if (u.bi_flags & BCH_INODE_UNLINKED)
2163+
if (u.bi_flags & BCH_INODE_unlinked)
21642164
continue;
21652165

21662166
ret = check_path(trans, &path, &u, iter.pos.snapshot);

fs/bcachefs/inode.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020

2121
#include <asm/unaligned.h>
2222

23-
const char * const bch2_inode_opts[] = {
2423
#define x(name, ...) #name,
24+
const char * const bch2_inode_opts[] = {
2525
BCH_INODE_OPTS()
26-
#undef x
2726
NULL,
2827
};
2928

29+
static const char * const bch2_inode_flag_strs[] = {
30+
BCH_INODE_FLAGS()
31+
NULL
32+
};
33+
#undef x
34+
3035
static const u8 byte_table[8] = { 1, 2, 3, 4, 6, 8, 10, 13 };
3136

3237
static int inode_decode_field(const u8 *in, const u8 *end,
@@ -426,7 +431,7 @@ static int __bch2_inode_invalid(struct bch_fs *c, struct bkey_s_c k, struct prin
426431
inode_compression_type_invalid,
427432
"invalid compression opt %u", unpacked.bi_compression - 1);
428433

429-
bkey_fsck_err_on((unpacked.bi_flags & BCH_INODE_UNLINKED) &&
434+
bkey_fsck_err_on((unpacked.bi_flags & BCH_INODE_unlinked) &&
430435
unpacked.bi_nlink != 0, c, err,
431436
inode_unlinked_but_nlink_nonzero,
432437
"flagged as unlinked but bi_nlink != 0");
@@ -500,15 +505,20 @@ int bch2_inode_v3_invalid(struct bch_fs *c, struct bkey_s_c k,
500505
static void __bch2_inode_unpacked_to_text(struct printbuf *out,
501506
struct bch_inode_unpacked *inode)
502507
{
503-
prt_printf(out, "mode %o flags %x journal_seq %llu bi_size %llu bi_sectors %llu bi_version %llu",
504-
inode->bi_mode, inode->bi_flags,
508+
prt_printf(out, "mode=%o ", inode->bi_mode);
509+
510+
prt_str(out, "flags=");
511+
prt_bitflags(out, bch2_inode_flag_strs, inode->bi_flags & ((1U << 20) - 1));
512+
prt_printf(out, " (%x)", inode->bi_flags);
513+
514+
prt_printf(out, " journal_seq=%llu bi_size=%llu bi_sectors=%llu bi_version=%llu",
505515
inode->bi_journal_seq,
506516
inode->bi_size,
507517
inode->bi_sectors,
508518
inode->bi_version);
509519

510520
#define x(_name, _bits) \
511-
prt_printf(out, " "#_name " %llu", (u64) inode->_name);
521+
prt_printf(out, " "#_name "=%llu", (u64) inode->_name);
512522
BCH_INODE_FIELDS_v3()
513523
#undef x
514524
}
@@ -547,7 +557,7 @@ static inline u64 bkey_inode_flags(struct bkey_s_c k)
547557

548558
static inline bool bkey_is_deleted_inode(struct bkey_s_c k)
549559
{
550-
return bkey_inode_flags(k) & BCH_INODE_UNLINKED;
560+
return bkey_inode_flags(k) & BCH_INODE_unlinked;
551561
}
552562

553563
int bch2_trans_mark_inode(struct btree_trans *trans,
@@ -928,8 +938,8 @@ int bch2_inode_find_by_inum(struct bch_fs *c, subvol_inum inum,
928938

929939
int bch2_inode_nlink_inc(struct bch_inode_unpacked *bi)
930940
{
931-
if (bi->bi_flags & BCH_INODE_UNLINKED)
932-
bi->bi_flags &= ~BCH_INODE_UNLINKED;
941+
if (bi->bi_flags & BCH_INODE_unlinked)
942+
bi->bi_flags &= ~BCH_INODE_unlinked;
933943
else {
934944
if (bi->bi_nlink == U32_MAX)
935945
return -EINVAL;
@@ -942,21 +952,21 @@ int bch2_inode_nlink_inc(struct bch_inode_unpacked *bi)
942952

943953
void bch2_inode_nlink_dec(struct btree_trans *trans, struct bch_inode_unpacked *bi)
944954
{
945-
if (bi->bi_nlink && (bi->bi_flags & BCH_INODE_UNLINKED)) {
955+
if (bi->bi_nlink && (bi->bi_flags & BCH_INODE_unlinked)) {
946956
bch2_trans_inconsistent(trans, "inode %llu unlinked but link count nonzero",
947957
bi->bi_inum);
948958
return;
949959
}
950960

951-
if (bi->bi_flags & BCH_INODE_UNLINKED) {
961+
if (bi->bi_flags & BCH_INODE_unlinked) {
952962
bch2_trans_inconsistent(trans, "inode %llu link count underflow", bi->bi_inum);
953963
return;
954964
}
955965

956966
if (bi->bi_nlink)
957967
bi->bi_nlink--;
958968
else
959-
bi->bi_flags |= BCH_INODE_UNLINKED;
969+
bi->bi_flags |= BCH_INODE_unlinked;
960970
}
961971

962972
struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *inode)
@@ -1089,7 +1099,7 @@ static int may_delete_deleted_inode(struct btree_trans *trans,
10891099
pos.offset, pos.snapshot))
10901100
goto delete;
10911101

1092-
if (fsck_err_on(!(inode.bi_flags & BCH_INODE_UNLINKED), c,
1102+
if (fsck_err_on(!(inode.bi_flags & BCH_INODE_unlinked), c,
10931103
deleted_inode_not_unlinked,
10941104
"non-deleted inode %llu:%u in deleted_inodes btree",
10951105
pos.offset, pos.snapshot))
@@ -1111,7 +1121,7 @@ static int may_delete_deleted_inode(struct btree_trans *trans,
11111121
if (ret)
11121122
goto out;
11131123

1114-
inode.bi_flags &= ~BCH_INODE_UNLINKED;
1124+
inode.bi_flags &= ~BCH_INODE_unlinked;
11151125

11161126
ret = bch2_inode_write_flags(trans, &inode_iter, &inode,
11171127
BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE);

0 commit comments

Comments
 (0)