Skip to content

Commit 8d5ac18

Browse files
author
Kent Overstreet
committed
bcachefs: Fix casefold opt via xattr interface
Changing the casefold option requires extra checks/work - factor out a helper from bch2_fileattr_set() for the xattr code to use. Signed-off-by: Kent Overstreet <[email protected]>
1 parent cbed828 commit 8d5ac18

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

fs/bcachefs/fs.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,33 +1664,9 @@ static int fssetxattr_inode_update_fn(struct btree_trans *trans,
16641664
return -EINVAL;
16651665

16661666
if (s->casefold != bch2_inode_casefold(c, bi)) {
1667-
#ifdef CONFIG_UNICODE
1668-
int ret = 0;
1669-
/* Not supported on individual files. */
1670-
if (!S_ISDIR(bi->bi_mode))
1671-
return -EOPNOTSUPP;
1672-
1673-
/*
1674-
* Make sure the dir is empty, as otherwise we'd need to
1675-
* rehash everything and update the dirent keys.
1676-
*/
1677-
ret = bch2_empty_dir_trans(trans, inode_inum(inode));
1678-
if (ret < 0)
1679-
return ret;
1680-
1681-
ret = bch2_request_incompat_feature(c, bcachefs_metadata_version_casefolding);
1667+
int ret = bch2_inode_set_casefold(trans, inode_inum(inode), bi, s->casefold);
16821668
if (ret)
16831669
return ret;
1684-
1685-
bch2_check_set_feature(c, BCH_FEATURE_casefolding);
1686-
1687-
bi->bi_casefold = s->casefold + 1;
1688-
bi->bi_fields_set |= BIT(Inode_opt_casefold);
1689-
1690-
#else
1691-
printk(KERN_ERR "Cannot use casefolding on a kernel without CONFIG_UNICODE\n");
1692-
return -EOPNOTSUPP;
1693-
#endif
16941670
}
16951671

16961672
if (s->set_project) {

fs/bcachefs/inode.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "extent_update.h"
1515
#include "fs.h"
1616
#include "inode.h"
17+
#include "namei.h"
1718
#include "opts.h"
1819
#include "str_hash.h"
1920
#include "snapshot.h"
@@ -1204,6 +1205,41 @@ int bch2_inum_opts_get(struct btree_trans *trans, subvol_inum inum, struct bch_i
12041205
return 0;
12051206
}
12061207

1208+
int bch2_inode_set_casefold(struct btree_trans *trans, subvol_inum inum,
1209+
struct bch_inode_unpacked *bi, unsigned v)
1210+
{
1211+
struct bch_fs *c = trans->c;
1212+
1213+
#ifdef CONFIG_UNICODE
1214+
int ret = 0;
1215+
/* Not supported on individual files. */
1216+
if (!S_ISDIR(bi->bi_mode))
1217+
return -EOPNOTSUPP;
1218+
1219+
/*
1220+
* Make sure the dir is empty, as otherwise we'd need to
1221+
* rehash everything and update the dirent keys.
1222+
*/
1223+
ret = bch2_empty_dir_trans(trans, inum);
1224+
if (ret < 0)
1225+
return ret;
1226+
1227+
ret = bch2_request_incompat_feature(c, bcachefs_metadata_version_casefolding);
1228+
if (ret)
1229+
return ret;
1230+
1231+
bch2_check_set_feature(c, BCH_FEATURE_casefolding);
1232+
1233+
bi->bi_casefold = v + 1;
1234+
bi->bi_fields_set |= BIT(Inode_opt_casefold);
1235+
1236+
return 0;
1237+
#else
1238+
bch_err(c, "Cannot use casefolding on a kernel without CONFIG_UNICODE");
1239+
return -EOPNOTSUPP;
1240+
#endif
1241+
}
1242+
12071243
static noinline int __bch2_inode_rm_snapshot(struct btree_trans *trans, u64 inum, u32 snapshot)
12081244
{
12091245
struct bch_fs *c = trans->c;

fs/bcachefs/inode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ static inline bool bch2_inode_should_have_single_bp(struct bch_inode_unpacked *i
292292
struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *);
293293
void bch2_inode_opts_get(struct bch_io_opts *, struct bch_fs *,
294294
struct bch_inode_unpacked *);
295-
int bch2_inum_opts_get(struct btree_trans*, subvol_inum, struct bch_io_opts *);
295+
int bch2_inum_opts_get(struct btree_trans *, subvol_inum, struct bch_io_opts *);
296+
int bch2_inode_set_casefold(struct btree_trans *, subvol_inum,
297+
struct bch_inode_unpacked *, unsigned);
296298

297299
#include "rebalance.h"
298300

fs/bcachefs/xattr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ static int inode_opt_set_fn(struct btree_trans *trans,
473473
{
474474
struct inode_opt_set *s = p;
475475

476+
if (s->id == Inode_opt_casefold) {
477+
int ret = bch2_inode_set_casefold(trans, inode_inum(inode), bi, s->v);
478+
if (ret)
479+
return ret;
480+
}
481+
476482
if (s->defined)
477483
bi->bi_fields_set |= 1U << s->id;
478484
else

0 commit comments

Comments
 (0)