Skip to content

Commit b9e1f87

Browse files
author
Kent Overstreet
committed
bcachefs: Casefold is now a regular opts.h option
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 7a4a866 commit b9e1f87

File tree

7 files changed

+43
-22
lines changed

7 files changed

+43
-22
lines changed

fs/bcachefs/bcachefs_format.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ LE64_BITMASK(BCH_SB_VERSION_INCOMPAT_ALLOWED,
867867
LE64_BITMASK(BCH_SB_SHARD_INUMS_NBITS, struct bch_sb, flags[6], 0, 4);
868868
LE64_BITMASK(BCH_SB_WRITE_ERROR_TIMEOUT,struct bch_sb, flags[6], 4, 14);
869869
LE64_BITMASK(BCH_SB_CSUM_ERR_RETRY_NR, struct bch_sb, flags[6], 14, 20);
870+
LE64_BITMASK(BCH_SB_CASEFOLD, struct bch_sb, flags[6], 22, 23);
870871

871872
static inline __u64 BCH_SB_COMPRESSION_TYPE(const struct bch_sb *sb)
872873
{

fs/bcachefs/fs.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ static void bch2_vfs_inode_init(struct btree_trans *, subvol_inum,
5353
struct bch_subvolume *);
5454

5555
/* Set VFS inode flags from bcachefs inode: */
56-
static inline void bch2_inode_flags_to_vfs(struct bch_inode_info *inode)
56+
static inline void bch2_inode_flags_to_vfs(struct bch_fs *c, struct bch_inode_info *inode)
5757
{
5858
static const __maybe_unused unsigned bch_flags_to_vfs[] = {
5959
[__BCH_INODE_sync] = S_SYNC,
6060
[__BCH_INODE_immutable] = S_IMMUTABLE,
6161
[__BCH_INODE_append] = S_APPEND,
6262
[__BCH_INODE_noatime] = S_NOATIME,
63-
[__BCH_INODE_casefolded] = S_CASEFOLD,
6463
};
64+
6565
set_flags(bch_flags_to_vfs, inode->ei_inode.bi_flags, inode->v.i_flags);
66+
67+
if (bch2_inode_casefold(c, &inode->ei_inode))
68+
inode->v.i_flags |= S_CASEFOLD;
6669
}
6770

6871
void bch2_inode_update_after_write(struct btree_trans *trans,
@@ -93,7 +96,7 @@ void bch2_inode_update_after_write(struct btree_trans *trans,
9396

9497
inode->ei_inode = *bi;
9598

96-
bch2_inode_flags_to_vfs(inode);
99+
bch2_inode_flags_to_vfs(c, inode);
97100
}
98101

99102
int __must_check bch2_write_inode(struct bch_fs *c,
@@ -1470,7 +1473,6 @@ static const __maybe_unused unsigned bch_flags_to_uflags[] = {
14701473
[__BCH_INODE_append] = FS_APPEND_FL,
14711474
[__BCH_INODE_nodump] = FS_NODUMP_FL,
14721475
[__BCH_INODE_noatime] = FS_NOATIME_FL,
1473-
[__BCH_INODE_casefolded] = FS_CASEFOLD_FL,
14741476
};
14751477

14761478
/* bcachefs inode flags -> FS_IOC_FSGETXATTR: */
@@ -1486,13 +1488,14 @@ static int bch2_fileattr_get(struct dentry *dentry,
14861488
struct fileattr *fa)
14871489
{
14881490
struct bch_inode_info *inode = to_bch_ei(d_inode(dentry));
1491+
struct bch_fs *c = inode->v.i_sb->s_fs_info;
14891492

14901493
fileattr_fill_xflags(fa, map_flags(bch_flags_to_xflags, inode->ei_inode.bi_flags));
14911494

14921495
if (inode->ei_inode.bi_fields_set & (1 << Inode_opt_project))
14931496
fa->fsx_xflags |= FS_XFLAG_PROJINHERIT;
14941497

1495-
if (inode->ei_inode.bi_flags & BCH_INODE_casefolded)
1498+
if (bch2_inode_casefold(c, &inode->ei_inode))
14961499
fa->flags |= FS_CASEFOLD_FL;
14971500

14981501
fa->fsx_projid = inode->ei_qid.q[QTYP_PRJ];
@@ -1504,6 +1507,8 @@ struct flags_set {
15041507
unsigned flags;
15051508
unsigned projid;
15061509
bool set_project;
1510+
bool set_casefold;
1511+
bool casefold;
15071512
};
15081513

15091514
static int fssetxattr_inode_update_fn(struct btree_trans *trans,
@@ -1518,15 +1523,12 @@ static int fssetxattr_inode_update_fn(struct btree_trans *trans,
15181523
* We're relying on btree locking here for exclusion with other ioctl
15191524
* calls - use the flags in the btree (@bi), not inode->i_flags:
15201525
*/
1521-
unsigned newflags = s->flags;
1522-
unsigned oldflags = bi->bi_flags & s->mask;
1523-
15241526
if (!S_ISREG(bi->bi_mode) &&
15251527
!S_ISDIR(bi->bi_mode) &&
1526-
(newflags & (BCH_INODE_nodump|BCH_INODE_noatime)) != newflags)
1528+
(s->flags & (BCH_INODE_nodump|BCH_INODE_noatime)) != s->flags)
15271529
return -EINVAL;
15281530

1529-
if ((newflags ^ oldflags) & BCH_INODE_casefolded) {
1531+
if (s->casefold != bch2_inode_casefold(c, bi)) {
15301532
#ifdef CONFIG_UNICODE
15311533
int ret = 0;
15321534
/* Not supported on individual files. */
@@ -1546,6 +1548,10 @@ static int fssetxattr_inode_update_fn(struct btree_trans *trans,
15461548
return ret;
15471549

15481550
bch2_check_set_feature(c, BCH_FEATURE_casefolding);
1551+
1552+
bi->bi_casefold = s->casefold + 1;
1553+
bi->bi_fields_set |= BIT(Inode_opt_casefold);
1554+
15491555
#else
15501556
printk(KERN_ERR "Cannot use casefolding on a kernel without CONFIG_UNICODE\n");
15511557
return -EOPNOTSUPP;
@@ -1558,7 +1564,7 @@ static int fssetxattr_inode_update_fn(struct btree_trans *trans,
15581564
}
15591565

15601566
bi->bi_flags &= ~s->mask;
1561-
bi->bi_flags |= newflags;
1567+
bi->bi_flags |= s->flags;
15621568

15631569
bi->bi_ctime = timespec_to_bch2_time(c, current_time(&inode->v));
15641570
return 0;
@@ -1598,6 +1604,11 @@ static int bch2_fileattr_set(struct mnt_idmap *idmap,
15981604

15991605
if (fa->flags_valid) {
16001606
s.mask = map_defined(bch_flags_to_uflags);
1607+
1608+
s.set_casefold = true;
1609+
s.casefold = (fa->flags & FS_CASEFOLD_FL) != 0;
1610+
fa->flags &= ~FS_CASEFOLD_FL;
1611+
16011612
s.flags |= map_flags_rev(bch_flags_to_uflags, fa->flags);
16021613
if (fa->flags)
16031614
return -EOPNOTSUPP;

fs/bcachefs/inode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ static inline unsigned bkey_inode_mode(struct bkey_s_c k)
243243
}
244244
}
245245

246+
static inline bool bch2_inode_casefold(struct bch_fs *c, const struct bch_inode_unpacked *bi)
247+
{
248+
/* inode apts are stored with a +1 bias: 0 means "unset, use fs opt" */
249+
return bi->bi_casefold
250+
? bi->bi_casefold - 1
251+
: c->opts.casefold;
252+
}
253+
246254
/* i_nlink: */
247255

248256
static inline unsigned nlink_bias(umode_t mode)

fs/bcachefs/inode_format.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ struct bch_inode_generation {
103103
x(bi_parent_subvol, 32) \
104104
x(bi_nocow, 8) \
105105
x(bi_depth, 32) \
106-
x(bi_inodes_32bit, 8)
106+
x(bi_inodes_32bit, 8) \
107+
x(bi_casefold, 8)
107108

108109
/* subset of BCH_INODE_FIELDS */
109110
#define BCH_INODE_OPTS() \
@@ -117,7 +118,8 @@ struct bch_inode_generation {
117118
x(background_target, 16) \
118119
x(erasure_code, 16) \
119120
x(nocow, 8) \
120-
x(inodes_32bit, 8)
121+
x(inodes_32bit, 8) \
122+
x(casefold, 8)
121123

122124
enum inode_opt_id {
123125
#define x(name, ...) \
@@ -137,8 +139,7 @@ enum inode_opt_id {
137139
x(i_sectors_dirty, 6) \
138140
x(unlinked, 7) \
139141
x(backptr_untrusted, 8) \
140-
x(has_child_snapshot, 9) \
141-
x(casefolded, 10)
142+
x(has_child_snapshot, 9)
142143

143144
/* bits 20+ reserved for packed fields below: */
144145

fs/bcachefs/namei.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ int bch2_create_trans(struct btree_trans *trans,
4747
if (ret)
4848
goto err;
4949

50-
/* Inherit casefold state from parent. */
51-
if (S_ISDIR(mode))
52-
new_inode->bi_flags |= dir_u->bi_flags & BCH_INODE_casefolded;
53-
5450
if (!(flags & BCH_CREATE_SNAPSHOT)) {
5551
/* Normal create path - allocate a new inode: */
5652
bch2_inode_init_late(new_inode, now, uid, gid, mode, rdev, dir_u);

fs/bcachefs/opts.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ enum fsck_err_opts {
228228
OPT_BOOL(), \
229229
BCH_SB_ERASURE_CODE, false, \
230230
NULL, "Enable erasure coding (DO NOT USE YET)") \
231+
x(casefold, u8, \
232+
OPT_FS|OPT_INODE|OPT_FORMAT, \
233+
OPT_BOOL(), \
234+
BCH_SB_CASEFOLD, false, \
235+
NULL, "Dirent lookups are casefolded") \
231236
x(inodes_32bit, u8, \
232237
OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
233238
OPT_BOOL(), \

fs/bcachefs/str_hash.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bch2_str_hash_opt_to_type(struct bch_fs *c, enum bch_str_hash_opts opt)
3333

3434
struct bch_hash_info {
3535
u8 type;
36-
struct unicode_map *cf_encoding;
36+
struct unicode_map *cf_encoding;
3737
/*
3838
* For crc32 or crc64 string hashes the first key value of
3939
* the siphash_key (k0) is used as the key.
@@ -44,11 +44,10 @@ struct bch_hash_info {
4444
static inline struct bch_hash_info
4545
bch2_hash_info_init(struct bch_fs *c, const struct bch_inode_unpacked *bi)
4646
{
47-
/* XXX ick */
4847
struct bch_hash_info info = {
4948
.type = INODE_STR_HASH(bi),
5049
#ifdef CONFIG_UNICODE
51-
.cf_encoding = !!(bi->bi_flags & BCH_INODE_casefolded) ? c->cf_encoding : NULL,
50+
.cf_encoding = bch2_inode_casefold(c, bi) ? c->cf_encoding : NULL,
5251
#endif
5352
.siphash_key = { .k0 = bi->bi_hash_seed }
5453
};

0 commit comments

Comments
 (0)