struct bch_inode_unpacked *bi,
unsigned fields)
{
- set_nlink(&inode->v, bi->bi_flags & BCH_INODE_UNLINKED
- ? 0
- : bi->bi_nlink + nlink_bias(inode->v.i_mode));
+ set_nlink(&inode->v, bch2_inode_nlink_get(bi));
i_uid_write(&inode->v, bi->bi_uid);
i_gid_write(&inode->v, bi->bi_gid);
inode->v.i_mode = bi->bi_mode;
struct bch_fs *c = inode->v.i_sb->s_fs_info;
bi->bi_ctime = bch2_current_time(c);
-
- if (bi->bi_flags & BCH_INODE_UNLINKED)
- bi->bi_flags &= ~BCH_INODE_UNLINKED;
- else
- bi->bi_nlink++;
-
+ bch2_inode_nlink_inc(bi);
return 0;
}
struct bch_fs *c = inode->v.i_sb->s_fs_info;
bi->bi_ctime = bch2_current_time(c);
- if (bi->bi_nlink)
- bi->bi_nlink--;
- else
- bi->bi_flags |= BCH_INODE_UNLINKED;
-
+ bch2_inode_nlink_dec(bi);
return 0;
}
BUG_ON(bi->bi_nlink &&
S_ISDIR(info->dst_inode->v.i_mode));
- if (bi->bi_nlink)
- bi->bi_nlink--;
- else
- bi->bi_flags |= BCH_INODE_UNLINKED;
+ bch2_inode_nlink_dec(bi);
}
if (inode == info->src_dir ||
return (mode >> 12) & 15;
}
-static inline unsigned nlink_bias(umode_t mode)
-{
- return S_ISDIR(mode) ? 2 : 1;
-}
-
static inline bool inode_attr_changing(struct bch_inode_info *dir,
struct bch_inode_info *inode,
enum inode_opt_id id)
struct nlink *link,
bool *do_update)
{
- u32 i_nlink = u->bi_flags & BCH_INODE_UNLINKED
- ? 0
- : u->bi_nlink + nlink_bias(u->bi_mode);
+ u32 i_nlink = bch2_inode_nlink_get(u);
u32 real_i_nlink =
link->count * nlink_bias(u->bi_mode) +
link->dir_count;
u->bi_inum, i_nlink, real_i_nlink);
set_i_nlink:
if (i_nlink != real_i_nlink) {
- if (real_i_nlink) {
- u->bi_nlink = real_i_nlink - nlink_bias(u->bi_mode);
- u->bi_flags &= ~BCH_INODE_UNLINKED;
- } else {
- u->bi_nlink = 0;
- u->bi_flags |= BCH_INODE_UNLINKED;
- }
-
+ bch2_inode_nlink_set(u, real_i_nlink);
*do_update = true;
}
fsck_err:
}
}
+/* i_nlink: */
+
+static inline unsigned nlink_bias(umode_t mode)
+{
+ return S_ISDIR(mode) ? 2 : 1;
+}
+
+static inline void bch2_inode_nlink_inc(struct bch_inode_unpacked *bi)
+{
+ if (bi->bi_flags & BCH_INODE_UNLINKED)
+ bi->bi_flags &= ~BCH_INODE_UNLINKED;
+ else
+ bi->bi_nlink++;
+}
+
+static inline void bch2_inode_nlink_dec(struct bch_inode_unpacked *bi)
+{
+ BUG_ON(bi->bi_flags & BCH_INODE_UNLINKED);
+ if (bi->bi_nlink)
+ bi->bi_nlink--;
+ else
+ bi->bi_flags |= BCH_INODE_UNLINKED;
+}
+
+static inline unsigned bch2_inode_nlink_get(struct bch_inode_unpacked *bi)
+{
+ return bi->bi_flags & BCH_INODE_UNLINKED
+ ? 0
+ : bi->bi_nlink + nlink_bias(bi->bi_mode);
+}
+
+static inline void bch2_inode_nlink_set(struct bch_inode_unpacked *bi,
+ unsigned nlink)
+{
+ if (nlink) {
+ bi->bi_nlink = nlink - nlink_bias(bi->bi_mode);
+ bi->bi_flags &= ~BCH_INODE_UNLINKED;
+ } else {
+ bi->bi_nlink = 0;
+ bi->bi_flags |= BCH_INODE_UNLINKED;
+ }
+}
+
#ifdef CONFIG_BCACHEFS_DEBUG
void bch2_inode_pack_test(void);
#else