Skip to content

Commit b091e8e

Browse files
committed
erofs: get rid of erofs_{find,insert}_workgroup
Just fold them into the only two callers since they are simple enough. Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 83a8836 commit b091e8e

File tree

3 files changed

+30
-63
lines changed

3 files changed

+30
-63
lines changed

fs/erofs/internal.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,7 @@ void erofs_release_pages(struct page **pagepool);
457457

458458
#ifdef CONFIG_EROFS_FS_ZIP
459459
void erofs_workgroup_put(struct erofs_workgroup *grp);
460-
struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
461-
pgoff_t index);
462-
struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
463-
struct erofs_workgroup *grp);
460+
bool erofs_workgroup_get(struct erofs_workgroup *grp);
464461
void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
465462
void erofs_shrinker_register(struct super_block *sb);
466463
void erofs_shrinker_unregister(struct super_block *sb);

fs/erofs/zdata.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,10 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
714714
{
715715
struct erofs_map_blocks *map = &fe->map;
716716
struct super_block *sb = fe->inode->i_sb;
717+
struct erofs_sb_info *sbi = EROFS_SB(sb);
717718
bool ztailpacking = map->m_flags & EROFS_MAP_META;
718719
struct z_erofs_pcluster *pcl;
719-
struct erofs_workgroup *grp;
720+
struct erofs_workgroup *grp, *pre;
720721
int err;
721722

722723
if (!(map->m_flags & EROFS_MAP_ENCODED) ||
@@ -752,15 +753,23 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
752753
pcl->obj.index = 0; /* which indicates ztailpacking */
753754
} else {
754755
pcl->obj.index = erofs_blknr(sb, map->m_pa);
755-
756-
grp = erofs_insert_workgroup(fe->inode->i_sb, &pcl->obj);
757-
if (IS_ERR(grp)) {
758-
err = PTR_ERR(grp);
759-
goto err_out;
756+
while (1) {
757+
xa_lock(&sbi->managed_pslots);
758+
pre = __xa_cmpxchg(&sbi->managed_pslots, grp->index,
759+
NULL, grp, GFP_KERNEL);
760+
if (!pre || xa_is_err(pre) || erofs_workgroup_get(pre)) {
761+
xa_unlock(&sbi->managed_pslots);
762+
break;
763+
}
764+
/* try to legitimize the current in-tree one */
765+
xa_unlock(&sbi->managed_pslots);
766+
cond_resched();
760767
}
761-
762-
if (grp != &pcl->obj) {
763-
fe->pcl = container_of(grp,
768+
if (xa_is_err(pre)) {
769+
err = xa_err(pre);
770+
goto err_out;
771+
} else if (pre) {
772+
fe->pcl = container_of(pre,
764773
struct z_erofs_pcluster, obj);
765774
err = -EEXIST;
766775
goto err_out;
@@ -789,7 +798,16 @@ static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
789798
DBG_BUGON(fe->owned_head == Z_EROFS_PCLUSTER_NIL);
790799

791800
if (!(map->m_flags & EROFS_MAP_META)) {
792-
grp = erofs_find_workgroup(sb, blknr);
801+
while (1) {
802+
rcu_read_lock();
803+
grp = xa_load(&EROFS_SB(sb)->managed_pslots, blknr);
804+
if (!grp || erofs_workgroup_get(grp)) {
805+
DBG_BUGON(grp && blknr != grp->index);
806+
rcu_read_unlock();
807+
break;
808+
}
809+
rcu_read_unlock();
810+
}
793811
} else if ((map->m_pa & ~PAGE_MASK) + map->m_plen > PAGE_SIZE) {
794812
DBG_BUGON(1);
795813
return -EFSCORRUPTED;

fs/erofs/zutil.c

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void erofs_release_pages(struct page **pagepool)
214214
}
215215
}
216216

217-
static bool erofs_workgroup_get(struct erofs_workgroup *grp)
217+
bool erofs_workgroup_get(struct erofs_workgroup *grp)
218218
{
219219
if (lockref_get_not_zero(&grp->lockref))
220220
return true;
@@ -231,54 +231,6 @@ static bool erofs_workgroup_get(struct erofs_workgroup *grp)
231231
return true;
232232
}
233233

234-
struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
235-
pgoff_t index)
236-
{
237-
struct erofs_sb_info *sbi = EROFS_SB(sb);
238-
struct erofs_workgroup *grp;
239-
240-
repeat:
241-
rcu_read_lock();
242-
grp = xa_load(&sbi->managed_pslots, index);
243-
if (grp) {
244-
if (!erofs_workgroup_get(grp)) {
245-
/* prefer to relax rcu read side */
246-
rcu_read_unlock();
247-
goto repeat;
248-
}
249-
250-
DBG_BUGON(index != grp->index);
251-
}
252-
rcu_read_unlock();
253-
return grp;
254-
}
255-
256-
struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
257-
struct erofs_workgroup *grp)
258-
{
259-
struct erofs_sb_info *const sbi = EROFS_SB(sb);
260-
struct erofs_workgroup *pre;
261-
262-
DBG_BUGON(grp->lockref.count < 1);
263-
repeat:
264-
xa_lock(&sbi->managed_pslots);
265-
pre = __xa_cmpxchg(&sbi->managed_pslots, grp->index,
266-
NULL, grp, GFP_KERNEL);
267-
if (pre) {
268-
if (xa_is_err(pre)) {
269-
pre = ERR_PTR(xa_err(pre));
270-
} else if (!erofs_workgroup_get(pre)) {
271-
/* try to legitimize the current in-tree one */
272-
xa_unlock(&sbi->managed_pslots);
273-
cond_resched();
274-
goto repeat;
275-
}
276-
grp = pre;
277-
}
278-
xa_unlock(&sbi->managed_pslots);
279-
return grp;
280-
}
281-
282234
static void __erofs_workgroup_free(struct erofs_workgroup *grp)
283235
{
284236
atomic_long_dec(&erofs_global_shrink_cnt);

0 commit comments

Comments
 (0)