Commit 9e579fc1 authored by Gao Xiang's avatar Gao Xiang

erofs: clean up collection handling routines

 - change return value to int since collection is
   already returned within the collector.
 - better function naming.

Link: https://lore.kernel.org/r/20191008125616.183715-1-gaoxiang25@huawei.comReviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarGao Xiang <gaoxiang25@huawei.com>
parent 4f5cafb5
...@@ -337,9 +337,9 @@ try_to_claim_pcluster(struct z_erofs_pcluster *pcl, ...@@ -337,9 +337,9 @@ try_to_claim_pcluster(struct z_erofs_pcluster *pcl,
return COLLECT_PRIMARY; /* :( better luck next time */ return COLLECT_PRIMARY; /* :( better luck next time */
} }
static struct z_erofs_collection *cllookup(struct z_erofs_collector *clt, static int z_erofs_lookup_collection(struct z_erofs_collector *clt,
struct inode *inode, struct inode *inode,
struct erofs_map_blocks *map) struct erofs_map_blocks *map)
{ {
struct erofs_workgroup *grp; struct erofs_workgroup *grp;
struct z_erofs_pcluster *pcl; struct z_erofs_pcluster *pcl;
...@@ -349,20 +349,20 @@ static struct z_erofs_collection *cllookup(struct z_erofs_collector *clt, ...@@ -349,20 +349,20 @@ static struct z_erofs_collection *cllookup(struct z_erofs_collector *clt,
grp = erofs_find_workgroup(inode->i_sb, map->m_pa >> PAGE_SHIFT, &tag); grp = erofs_find_workgroup(inode->i_sb, map->m_pa >> PAGE_SHIFT, &tag);
if (!grp) if (!grp)
return NULL; return -ENOENT;
pcl = container_of(grp, struct z_erofs_pcluster, obj); pcl = container_of(grp, struct z_erofs_pcluster, obj);
if (clt->owned_head == &pcl->next || pcl == clt->tailpcl) { if (clt->owned_head == &pcl->next || pcl == clt->tailpcl) {
DBG_BUGON(1); DBG_BUGON(1);
erofs_workgroup_put(grp); erofs_workgroup_put(grp);
return ERR_PTR(-EFSCORRUPTED); return -EFSCORRUPTED;
} }
cl = z_erofs_primarycollection(pcl); cl = z_erofs_primarycollection(pcl);
if (cl->pageofs != (map->m_la & ~PAGE_MASK)) { if (cl->pageofs != (map->m_la & ~PAGE_MASK)) {
DBG_BUGON(1); DBG_BUGON(1);
erofs_workgroup_put(grp); erofs_workgroup_put(grp);
return ERR_PTR(-EFSCORRUPTED); return -EFSCORRUPTED;
} }
length = READ_ONCE(pcl->length); length = READ_ONCE(pcl->length);
...@@ -370,7 +370,7 @@ static struct z_erofs_collection *cllookup(struct z_erofs_collector *clt, ...@@ -370,7 +370,7 @@ static struct z_erofs_collection *cllookup(struct z_erofs_collector *clt,
if ((map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) > length) { if ((map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) > length) {
DBG_BUGON(1); DBG_BUGON(1);
erofs_workgroup_put(grp); erofs_workgroup_put(grp);
return ERR_PTR(-EFSCORRUPTED); return -EFSCORRUPTED;
} }
} else { } else {
unsigned int llen = map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT; unsigned int llen = map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT;
...@@ -394,12 +394,12 @@ static struct z_erofs_collection *cllookup(struct z_erofs_collector *clt, ...@@ -394,12 +394,12 @@ static struct z_erofs_collection *cllookup(struct z_erofs_collector *clt,
clt->tailpcl = NULL; clt->tailpcl = NULL;
clt->pcl = pcl; clt->pcl = pcl;
clt->cl = cl; clt->cl = cl;
return cl; return 0;
} }
static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, static int z_erofs_register_collection(struct z_erofs_collector *clt,
struct inode *inode, struct inode *inode,
struct erofs_map_blocks *map) struct erofs_map_blocks *map)
{ {
struct z_erofs_pcluster *pcl; struct z_erofs_pcluster *pcl;
struct z_erofs_collection *cl; struct z_erofs_collection *cl;
...@@ -408,7 +408,7 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, ...@@ -408,7 +408,7 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt,
/* no available workgroup, let's allocate one */ /* no available workgroup, let's allocate one */
pcl = kmem_cache_alloc(pcluster_cachep, GFP_NOFS); pcl = kmem_cache_alloc(pcluster_cachep, GFP_NOFS);
if (!pcl) if (!pcl)
return ERR_PTR(-ENOMEM); return -ENOMEM;
z_erofs_pcluster_init_always(pcl); z_erofs_pcluster_init_always(pcl);
pcl->obj.index = map->m_pa >> PAGE_SHIFT; pcl->obj.index = map->m_pa >> PAGE_SHIFT;
...@@ -442,7 +442,7 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, ...@@ -442,7 +442,7 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt,
if (err) { if (err) {
mutex_unlock(&cl->lock); mutex_unlock(&cl->lock);
kmem_cache_free(pcluster_cachep, pcl); kmem_cache_free(pcluster_cachep, pcl);
return ERR_PTR(-EAGAIN); return -EAGAIN;
} }
/* used to check tail merging loop due to corrupted images */ /* used to check tail merging loop due to corrupted images */
if (clt->owned_head == Z_EROFS_PCLUSTER_TAIL) if (clt->owned_head == Z_EROFS_PCLUSTER_TAIL)
...@@ -450,14 +450,14 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, ...@@ -450,14 +450,14 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt,
clt->owned_head = &pcl->next; clt->owned_head = &pcl->next;
clt->pcl = pcl; clt->pcl = pcl;
clt->cl = cl; clt->cl = cl;
return cl; return 0;
} }
static int z_erofs_collector_begin(struct z_erofs_collector *clt, static int z_erofs_collector_begin(struct z_erofs_collector *clt,
struct inode *inode, struct inode *inode,
struct erofs_map_blocks *map) struct erofs_map_blocks *map)
{ {
struct z_erofs_collection *cl; int ret;
DBG_BUGON(clt->cl); DBG_BUGON(clt->cl);
...@@ -471,19 +471,22 @@ static int z_erofs_collector_begin(struct z_erofs_collector *clt, ...@@ -471,19 +471,22 @@ static int z_erofs_collector_begin(struct z_erofs_collector *clt,
} }
repeat: repeat:
cl = cllookup(clt, inode, map); ret = z_erofs_lookup_collection(clt, inode, map);
if (!cl) { if (ret == -ENOENT) {
cl = clregister(clt, inode, map); ret = z_erofs_register_collection(clt, inode, map);
if (cl == ERR_PTR(-EAGAIN)) /* someone registered at the same time, give another try */
if (ret == -EAGAIN) {
cond_resched();
goto repeat; goto repeat;
}
} }
if (IS_ERR(cl)) if (ret)
return PTR_ERR(cl); return ret;
z_erofs_pagevec_ctor_init(&clt->vector, Z_EROFS_NR_INLINE_PAGEVECS, z_erofs_pagevec_ctor_init(&clt->vector, Z_EROFS_NR_INLINE_PAGEVECS,
cl->pagevec, cl->vcnt); clt->cl->pagevec, clt->cl->vcnt);
clt->compressedpages = clt->pcl->compressed_pages; clt->compressedpages = clt->pcl->compressed_pages;
if (clt->mode <= COLLECT_PRIMARY) /* cannot do in-place I/O */ if (clt->mode <= COLLECT_PRIMARY) /* cannot do in-place I/O */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment