Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcachefs: x-macro-ify inode flags enum

This lets us use bch2_prt_bitflags to print them out.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

+85 -79
+20 -24
fs/bcachefs/bcachefs_format.h
··· 824 824 Inode_opt_nr, 825 825 }; 826 826 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, 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 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, 838 + /* bits 20+ reserved for packed fields below: */ 842 839 843 - /* bits 20+ reserved for packed fields below: */ 840 + enum bch_inode_flags { 841 + #define x(t, n) BCH_INODE_##t = 1U << n, 842 + BCH_INODE_FLAGS() 843 + #undef x 844 844 }; 845 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) 846 + enum __bch_inode_flags { 847 + #define x(t, n) __BCH_INODE_##t = n, 848 + BCH_INODE_FLAGS() 849 + #undef x 850 + }; 855 851 856 852 LE32_BITMASK(INODE_STR_HASH, struct bch_inode, bi_flags, 20, 24); 857 853 LE32_BITMASK(INODE_NR_FIELDS, struct bch_inode, bi_flags, 24, 31);
+1 -1
fs/bcachefs/fs-common.c
··· 51 51 bch2_inode_init_late(new_inode, now, uid, gid, mode, rdev, dir_u); 52 52 53 53 if (flags & BCH_CREATE_TMPFILE) 54 - new_inode->bi_flags |= BCH_INODE_UNLINKED; 54 + new_inode->bi_flags |= BCH_INODE_unlinked; 55 55 56 56 ret = bch2_inode_create(trans, &inode_iter, new_inode, snapshot, cpu); 57 57 if (ret)
+2 -2
fs/bcachefs/fs-ioctl.c
··· 45 45 unsigned newflags = s->flags; 46 46 unsigned oldflags = bi->bi_flags & s->mask; 47 47 48 - if (((newflags ^ oldflags) & (BCH_INODE_APPEND|BCH_INODE_IMMUTABLE)) && 48 + if (((newflags ^ oldflags) & (BCH_INODE_append|BCH_INODE_immutable)) && 49 49 !capable(CAP_LINUX_IMMUTABLE)) 50 50 return -EPERM; 51 51 52 52 if (!S_ISREG(bi->bi_mode) && 53 53 !S_ISDIR(bi->bi_mode) && 54 - (newflags & (BCH_INODE_NODUMP|BCH_INODE_NOATIME)) != newflags) 54 + (newflags & (BCH_INODE_nodump|BCH_INODE_noatime)) != newflags) 55 55 return -EINVAL; 56 56 57 57 if (s->set_projinherit) {
+14 -14
fs/bcachefs/fs-ioctl.h
··· 6 6 7 7 /* bcachefs inode flags -> vfs inode flags: */ 8 8 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, 13 13 }; 14 14 15 15 /* bcachefs inode flags -> FS_IOC_GETFLAGS: */ 16 16 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, 22 22 }; 23 23 24 24 /* bcachefs inode flags -> FS_IOC_FSGETXATTR: */ 25 25 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, 31 31 //[__BCH_INODE_PROJINHERIT] = FS_XFLAG_PROJINHERIT; 32 32 }; 33 33
+3 -3
fs/bcachefs/fs.c
··· 764 764 stat->btime = bch2_time_to_timespec(c, inode->ei_inode.bi_otime); 765 765 } 766 766 767 - if (inode->ei_inode.bi_flags & BCH_INODE_IMMUTABLE) 767 + if (inode->ei_inode.bi_flags & BCH_INODE_immutable) 768 768 stat->attributes |= STATX_ATTR_IMMUTABLE; 769 769 stat->attributes_mask |= STATX_ATTR_IMMUTABLE; 770 770 771 - if (inode->ei_inode.bi_flags & BCH_INODE_APPEND) 771 + if (inode->ei_inode.bi_flags & BCH_INODE_append) 772 772 stat->attributes |= STATX_ATTR_APPEND; 773 773 stat->attributes_mask |= STATX_ATTR_APPEND; 774 774 775 - if (inode->ei_inode.bi_flags & BCH_INODE_NODUMP) 775 + if (inode->ei_inode.bi_flags & BCH_INODE_nodump) 776 776 stat->attributes |= STATX_ATTR_NODUMP; 777 777 stat->attributes_mask |= STATX_ATTR_NODUMP; 778 778
+17 -17
fs/bcachefs/fsck.c
··· 854 854 BUG_ON(bch2_inode_unpack(k, &u)); 855 855 856 856 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))) 860 860 return 0; 861 861 862 862 if (prev->bi_inum != u.bi_inum) ··· 870 870 return -EINVAL; 871 871 } 872 872 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)) && 874 874 bch2_key_has_snapshot_overwrites(trans, BTREE_ID_inodes, k.k->p)) { 875 875 struct bpos new_min_pos; 876 876 ··· 878 878 if (ret) 879 879 goto err; 880 880 881 - u.bi_flags &= ~BCH_INODE_I_SIZE_DIRTY|BCH_INODE_UNLINKED; 881 + u.bi_flags &= ~BCH_INODE_i_size_dirty|BCH_INODE_unlinked; 882 882 883 883 ret = __write_inode(trans, &u, iter->pos.snapshot); 884 884 bch_err_msg(c, ret, "in fsck updating inode"); ··· 890 890 return 0; 891 891 } 892 892 893 - if (u.bi_flags & BCH_INODE_UNLINKED && 893 + if (u.bi_flags & BCH_INODE_unlinked && 894 894 (!c->sb.clean || 895 895 fsck_err(c, inode_unlinked_but_clean, 896 896 "filesystem marked clean, but inode %llu unlinked", ··· 903 903 return ret; 904 904 } 905 905 906 - if (u.bi_flags & BCH_INODE_I_SIZE_DIRTY && 906 + if (u.bi_flags & BCH_INODE_i_size_dirty && 907 907 (!c->sb.clean || 908 908 fsck_err(c, inode_i_size_dirty_but_clean, 909 909 "filesystem marked clean, but inode %llu has i_size dirty", ··· 930 930 * We truncated without our normal sector accounting hook, just 931 931 * make sure we recalculate it: 932 932 */ 933 - u.bi_flags |= BCH_INODE_I_SECTORS_DIRTY; 933 + u.bi_flags |= BCH_INODE_i_sectors_dirty; 934 934 935 - u.bi_flags &= ~BCH_INODE_I_SIZE_DIRTY; 935 + u.bi_flags &= ~BCH_INODE_i_size_dirty; 936 936 do_update = true; 937 937 } 938 938 939 - if (u.bi_flags & BCH_INODE_I_SECTORS_DIRTY && 939 + if (u.bi_flags & BCH_INODE_i_sectors_dirty && 940 940 (!c->sb.clean || 941 941 fsck_err(c, inode_i_sectors_dirty_but_clean, 942 942 "filesystem marked clean, but inode %llu has i_sectors dirty", ··· 953 953 } 954 954 955 955 u.bi_sectors = sectors; 956 - u.bi_flags &= ~BCH_INODE_I_SECTORS_DIRTY; 956 + u.bi_flags &= ~BCH_INODE_i_sectors_dirty; 957 957 do_update = true; 958 958 } 959 959 960 - if (u.bi_flags & BCH_INODE_BACKPTR_UNTRUSTED) { 960 + if (u.bi_flags & BCH_INODE_backptr_untrusted) { 961 961 u.bi_dir = 0; 962 962 u.bi_dir_offset = 0; 963 - u.bi_flags &= ~BCH_INODE_BACKPTR_UNTRUSTED; 963 + u.bi_flags &= ~BCH_INODE_backptr_untrusted; 964 964 do_update = true; 965 965 } 966 966 ··· 1065 1065 return -BCH_ERR_internal_fsck_err; 1066 1066 } 1067 1067 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), 1069 1069 c, inode_i_sectors_wrong, 1070 1070 "inode %llu:%u has incorrect i_sectors: got %llu, should be %llu", 1071 1071 w->last_pos.inode, i->snapshot, ··· 1405 1405 continue; 1406 1406 1407 1407 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) && 1409 1409 k.k->p.offset > round_up(i->inode.bi_size, block_bytes(c)) >> 9 && 1410 1410 !bkey_extent_is_reservation(k), 1411 1411 c, extent_past_end_of_inode, ··· 1588 1588 "inode %llu type %s has multiple links but i_nlink 0", 1589 1589 target->bi_inum, bch2_d_types[d.v->d_type])) { 1590 1590 target->bi_nlink++; 1591 - target->bi_flags &= ~BCH_INODE_UNLINKED; 1591 + target->bi_flags &= ~BCH_INODE_unlinked; 1592 1592 1593 1593 ret = __write_inode(trans, target, target_snapshot); 1594 1594 if (ret) ··· 2160 2160 break; 2161 2161 } 2162 2162 2163 - if (u.bi_flags & BCH_INODE_UNLINKED) 2163 + if (u.bi_flags & BCH_INODE_unlinked) 2164 2164 continue; 2165 2165 2166 2166 ret = check_path(trans, &path, &u, iter.pos.snapshot);
+24 -14
fs/bcachefs/inode.c
··· 20 20 21 21 #include <asm/unaligned.h> 22 22 23 - const char * const bch2_inode_opts[] = { 24 23 #define x(name, ...) #name, 24 + const char * const bch2_inode_opts[] = { 25 25 BCH_INODE_OPTS() 26 - #undef x 27 26 NULL, 28 27 }; 28 + 29 + static const char * const bch2_inode_flag_strs[] = { 30 + BCH_INODE_FLAGS() 31 + NULL 32 + }; 33 + #undef x 29 34 30 35 static const u8 byte_table[8] = { 1, 2, 3, 4, 6, 8, 10, 13 }; 31 36 ··· 431 426 inode_compression_type_invalid, 432 427 "invalid compression opt %u", unpacked.bi_compression - 1); 433 428 434 - bkey_fsck_err_on((unpacked.bi_flags & BCH_INODE_UNLINKED) && 429 + bkey_fsck_err_on((unpacked.bi_flags & BCH_INODE_unlinked) && 435 430 unpacked.bi_nlink != 0, c, err, 436 431 inode_unlinked_but_nlink_nonzero, 437 432 "flagged as unlinked but bi_nlink != 0"); ··· 505 500 static void __bch2_inode_unpacked_to_text(struct printbuf *out, 506 501 struct bch_inode_unpacked *inode) 507 502 { 508 - prt_printf(out, "mode %o flags %x journal_seq %llu bi_size %llu bi_sectors %llu bi_version %llu", 509 - inode->bi_mode, inode->bi_flags, 503 + prt_printf(out, "mode=%o ", inode->bi_mode); 504 + 505 + prt_str(out, "flags="); 506 + prt_bitflags(out, bch2_inode_flag_strs, inode->bi_flags & ((1U << 20) - 1)); 507 + prt_printf(out, " (%x)", inode->bi_flags); 508 + 509 + prt_printf(out, " journal_seq=%llu bi_size=%llu bi_sectors=%llu bi_version=%llu", 510 510 inode->bi_journal_seq, 511 511 inode->bi_size, 512 512 inode->bi_sectors, 513 513 inode->bi_version); 514 514 515 515 #define x(_name, _bits) \ 516 - prt_printf(out, " "#_name " %llu", (u64) inode->_name); 516 + prt_printf(out, " "#_name "=%llu", (u64) inode->_name); 517 517 BCH_INODE_FIELDS_v3() 518 518 #undef x 519 519 } ··· 557 547 558 548 static inline bool bkey_is_deleted_inode(struct bkey_s_c k) 559 549 { 560 - return bkey_inode_flags(k) & BCH_INODE_UNLINKED; 550 + return bkey_inode_flags(k) & BCH_INODE_unlinked; 561 551 } 562 552 563 553 int bch2_trans_mark_inode(struct btree_trans *trans, ··· 938 928 939 929 int bch2_inode_nlink_inc(struct bch_inode_unpacked *bi) 940 930 { 941 - if (bi->bi_flags & BCH_INODE_UNLINKED) 942 - bi->bi_flags &= ~BCH_INODE_UNLINKED; 931 + if (bi->bi_flags & BCH_INODE_unlinked) 932 + bi->bi_flags &= ~BCH_INODE_unlinked; 943 933 else { 944 934 if (bi->bi_nlink == U32_MAX) 945 935 return -EINVAL; ··· 952 942 953 943 void bch2_inode_nlink_dec(struct btree_trans *trans, struct bch_inode_unpacked *bi) 954 944 { 955 - if (bi->bi_nlink && (bi->bi_flags & BCH_INODE_UNLINKED)) { 945 + if (bi->bi_nlink && (bi->bi_flags & BCH_INODE_unlinked)) { 956 946 bch2_trans_inconsistent(trans, "inode %llu unlinked but link count nonzero", 957 947 bi->bi_inum); 958 948 return; 959 949 } 960 950 961 - if (bi->bi_flags & BCH_INODE_UNLINKED) { 951 + if (bi->bi_flags & BCH_INODE_unlinked) { 962 952 bch2_trans_inconsistent(trans, "inode %llu link count underflow", bi->bi_inum); 963 953 return; 964 954 } ··· 966 956 if (bi->bi_nlink) 967 957 bi->bi_nlink--; 968 958 else 969 - bi->bi_flags |= BCH_INODE_UNLINKED; 959 + bi->bi_flags |= BCH_INODE_unlinked; 970 960 } 971 961 972 962 struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *inode) ··· 1099 1089 pos.offset, pos.snapshot)) 1100 1090 goto delete; 1101 1091 1102 - if (fsck_err_on(!(inode.bi_flags & BCH_INODE_UNLINKED), c, 1092 + if (fsck_err_on(!(inode.bi_flags & BCH_INODE_unlinked), c, 1103 1093 deleted_inode_not_unlinked, 1104 1094 "non-deleted inode %llu:%u in deleted_inodes btree", 1105 1095 pos.offset, pos.snapshot)) ··· 1121 1111 if (ret) 1122 1112 goto out; 1123 1113 1124 - inode.bi_flags &= ~BCH_INODE_UNLINKED; 1114 + inode.bi_flags &= ~BCH_INODE_unlinked; 1125 1115 1126 1116 ret = bch2_inode_write_flags(trans, &inode_iter, &inode, 1127 1117 BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE);
+3 -3
fs/bcachefs/inode.h
··· 186 186 187 187 static inline unsigned bch2_inode_nlink_get(struct bch_inode_unpacked *bi) 188 188 { 189 - return bi->bi_flags & BCH_INODE_UNLINKED 189 + return bi->bi_flags & BCH_INODE_unlinked 190 190 ? 0 191 191 : bi->bi_nlink + nlink_bias(bi->bi_mode); 192 192 } ··· 196 196 { 197 197 if (nlink) { 198 198 bi->bi_nlink = nlink - nlink_bias(bi->bi_mode); 199 - bi->bi_flags &= ~BCH_INODE_UNLINKED; 199 + bi->bi_flags &= ~BCH_INODE_unlinked; 200 200 } else { 201 201 bi->bi_nlink = 0; 202 - bi->bi_flags |= BCH_INODE_UNLINKED; 202 + bi->bi_flags |= BCH_INODE_unlinked; 203 203 } 204 204 } 205 205
+1 -1
fs/bcachefs/io_write.c
··· 234 234 235 235 inode = bkey_i_to_inode_v3(k); 236 236 237 - if (!(le64_to_cpu(inode->v.bi_flags) & BCH_INODE_I_SIZE_DIRTY) && 237 + if (!(le64_to_cpu(inode->v.bi_flags) & BCH_INODE_i_size_dirty) && 238 238 new_i_size > le64_to_cpu(inode->v.bi_size)) { 239 239 inode->v.bi_size = cpu_to_le64(new_i_size); 240 240 inode_update_flags = 0;