Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5618610ybp; Tue, 8 Oct 2019 05:57:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQ4oncc2ABJWRXgovwDRFaLfX0nD/Km6dwZ6NuYcjPWIXUBc0NWbNCQH1AnSnT1kpqUeSr X-Received: by 2002:a50:b6a8:: with SMTP id d37mr414619ede.63.1570539427528; Tue, 08 Oct 2019 05:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570539427; cv=none; d=google.com; s=arc-20160816; b=cT6Xk+Oay/wjv8U0nFDWnZmMNHEjNKAuio0LPxCWoa+jim6miHrUjrO6Zd2Nml+VkY LJVjfpjf2YX2545nqwAPiYPY4xTrx19Q63HrQ3haaw5mW2REIC2Cv0G7knkVWZA64nJt HBm7zOAmqGoWq3yVZvVxsupXQBor3iT7FslXEsyeAe/Bh5K+NX8tG37xPC2+09wHw4iR VN77QbC/TPV3DPbnB9wvjrYiutgEVaJQ/tqlAP1CHblp6b8G8RfAwRWYTnSK8k5LGTJr cw9AJx8ZtO/45lkgdoss4r1RS17G9/Swba7K5iPZkcrFQhJ2G+vRYUFL/dybYcjmrd09 VpMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=yspaonh285NuLKbzVYz7tCKjTca8y6hR7QsyV8jVE1o=; b=dB8qfIbO+jHOsV6yf+/iBpZEi+VKLOwnUqElq3EsTbw4hok1dY2ExHkRadISbkULwT thj5uTVmmCLmHAxmDmFf6jP7tqmdo+6qUs0kSxY9g2rJexE6RDeoYbLvWxTTLyq5OuYa 04F1hzoPW0zpae42+TtJ30tL9XSWUckTcCb+LIkrkqTHRJLQV7r8MyuExD952/MOpClc zH++rwkaR93t3+kPJhCKdUAKSBmW01L7cT/7xWkoi1nXrKT6rphznN8FeAxDnEDVW5zo Ne3vQaF6aUWDzgOT9qfJkWRuXMZwdxsYlA09lZc85yn79DVVE0crvt4fPEr7TK49hBo+ ti2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k16si8842130ejo.7.2019.10.08.05.56.43; Tue, 08 Oct 2019 05:57:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730797AbfJHMxW (ORCPT + 99 others); Tue, 8 Oct 2019 08:53:22 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:36934 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730541AbfJHMxW (ORCPT ); Tue, 8 Oct 2019 08:53:22 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id E8BFF7BAEF272BFF2464; Tue, 8 Oct 2019 20:53:20 +0800 (CST) Received: from architecture4.huawei.com (10.140.130.215) by smtp.huawei.com (10.3.19.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 8 Oct 2019 20:53:10 +0800 From: Gao Xiang To: Chao Yu , CC: LKML , Miao Xie , "Li Guifu" , Gao Xiang Subject: [PATCH for-next 1/5] erofs: clean up collection handling routines Date: Tue, 8 Oct 2019 20:56:12 +0800 Message-ID: <20191008125616.183715-1-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.140.130.215] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - change return value to int since collection is already returned within the collector. - better function naming. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index fad80c97d247..ef32757d1aac 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -337,9 +337,9 @@ try_to_claim_pcluster(struct z_erofs_pcluster *pcl, return COLLECT_PRIMARY; /* :( better luck next time */ } -static struct z_erofs_collection *cllookup(struct z_erofs_collector *clt, - struct inode *inode, - struct erofs_map_blocks *map) +static int z_erofs_lookup_collection(struct z_erofs_collector *clt, + struct inode *inode, + struct erofs_map_blocks *map) { struct erofs_workgroup *grp; struct z_erofs_pcluster *pcl; @@ -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); if (!grp) - return NULL; + return -ENOENT; pcl = container_of(grp, struct z_erofs_pcluster, obj); if (clt->owned_head == &pcl->next || pcl == clt->tailpcl) { DBG_BUGON(1); erofs_workgroup_put(grp); - return ERR_PTR(-EFSCORRUPTED); + return -EFSCORRUPTED; } cl = z_erofs_primarycollection(pcl); if (cl->pageofs != (map->m_la & ~PAGE_MASK)) { DBG_BUGON(1); erofs_workgroup_put(grp); - return ERR_PTR(-EFSCORRUPTED); + return -EFSCORRUPTED; } length = READ_ONCE(pcl->length); @@ -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) { DBG_BUGON(1); erofs_workgroup_put(grp); - return ERR_PTR(-EFSCORRUPTED); + return -EFSCORRUPTED; } } else { 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, clt->tailpcl = NULL; clt->pcl = pcl; clt->cl = cl; - return cl; + return 0; } -static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, - struct inode *inode, - struct erofs_map_blocks *map) +static int z_erofs_register_collection(struct z_erofs_collector *clt, + struct inode *inode, + struct erofs_map_blocks *map) { struct z_erofs_pcluster *pcl; struct z_erofs_collection *cl; @@ -408,7 +408,7 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, /* no available workgroup, let's allocate one */ pcl = kmem_cache_alloc(pcluster_cachep, GFP_NOFS); if (!pcl) - return ERR_PTR(-ENOMEM); + return -ENOMEM; z_erofs_pcluster_init_always(pcl); pcl->obj.index = map->m_pa >> PAGE_SHIFT; @@ -442,7 +442,7 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, if (err) { mutex_unlock(&cl->lock); kmem_cache_free(pcluster_cachep, pcl); - return ERR_PTR(-EAGAIN); + return -EAGAIN; } /* used to check tail merging loop due to corrupted images */ if (clt->owned_head == Z_EROFS_PCLUSTER_TAIL) @@ -450,14 +450,14 @@ static struct z_erofs_collection *clregister(struct z_erofs_collector *clt, clt->owned_head = &pcl->next; clt->pcl = pcl; clt->cl = cl; - return cl; + return 0; } static int z_erofs_collector_begin(struct z_erofs_collector *clt, struct inode *inode, struct erofs_map_blocks *map) { - struct z_erofs_collection *cl; + int ret; DBG_BUGON(clt->cl); @@ -471,19 +471,22 @@ static int z_erofs_collector_begin(struct z_erofs_collector *clt, } repeat: - cl = cllookup(clt, inode, map); - if (!cl) { - cl = clregister(clt, inode, map); + ret = z_erofs_lookup_collection(clt, inode, map); + if (ret == -ENOENT) { + 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; + } } - if (IS_ERR(cl)) - return PTR_ERR(cl); + if (ret) + return ret; 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; if (clt->mode <= COLLECT_PRIMARY) /* cannot do in-place I/O */ -- 2.17.1