Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1008697rwb; Sat, 17 Sep 2022 21:36:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5IPCYumiMzF2zDE1SW97FfCKD0F4z119p1gHY6IKI/SXtLd1Vh4mYewQ18nen6AAqVSqLD X-Received: by 2002:a63:2207:0:b0:439:b319:2549 with SMTP id i7-20020a632207000000b00439b3192549mr10271041pgi.329.1663475803348; Sat, 17 Sep 2022 21:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663475803; cv=none; d=google.com; s=arc-20160816; b=LZAhKNIaOrydd43WQD2EpwEhxLTkMjj+KjgJp6qajx/RF1P+cVjxfduVEuAKwlXxfU uXYyo9k4+8fhLgfuEhR+8E8DuykXPmUQkETtHpDltnv67D7IewjLGIMn4efv/DbqaBt8 d94rywjbYtqojTRtPdgiZsPVIUoQeiaQuwCAOGaTDfjyMyKNGz2Ah0k++r+kybaVh8V/ uP9csTLwpluoIOfyk+V2gs3qoZYuw3il44xV8qcumbQpKcGtQd0sigWgFPxrgcKq6M9y Y2FpLboG2k5bYouQ6KDNmlyywUVpVZlFQlnVEPgBoT9GNtd8cu9eKuyQ4SH7BVTmXqF5 VBGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A/aoDsk49ETFUaGu6ntYPDp5Xpa3glyWzoYuA85stpo=; b=p2ceaDWvxspmZWlhS3c+T7bBkwzuK77sKYNMI9ou9wtteiDm5aTJVN4S1sM4/RqABM yhIwXyYxFmfoq9QdV2m0yAkzD44a7bHgrqdJ6koe76imG5jFE/NSnewDhv3k6wFINqMX eJz2o7jfEeoofh+4yM9D/VeKISiPzf+vVqPXNbWUI574lxgdE1CN5vZrPvIVN79cDWSX JRM1Xvr/wKS1EPLwfYqe4UCBs5c8U89ggzyfg9wXcLRhRkVOb/6wp2YkEr5C08ycG7qq qIzuIaTcA9ySNnsYHWhAJbwm/eUHbMIb7eOLA00wltKYmG95O2MQeqN58I3+IBGY7S2U 2ANA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=61PHmhzx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b126-20020a636784000000b00429e52c1de8si12288491pgc.816.2022.09.17.21.36.32; Sat, 17 Sep 2022 21:36:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=61PHmhzx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229542AbiIREfR (ORCPT + 99 others); Sun, 18 Sep 2022 00:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbiIREfK (ORCPT ); Sun, 18 Sep 2022 00:35:10 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A1315A39 for ; Sat, 17 Sep 2022 21:35:08 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id t3so25084254ply.2 for ; Sat, 17 Sep 2022 21:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=A/aoDsk49ETFUaGu6ntYPDp5Xpa3glyWzoYuA85stpo=; b=61PHmhzxDjMs06OEy3Cb1sztffy0FZOHZCqFyM6w2PJ/XFUpo97cM+5wNAwiN6TtBO fzy1o7cenhEgpWgMVxov1vtcB70zgPt0gHAG2/qeb7Nefh+ezr4gLsqsK2b1tlsoGKyT 5/qfa44PhkZm000renBu0LIAsqj3ZsJkysOWwzdJqPKfXb0mjoXGw3nqfCGvn80B95ha UWUdu6g+vtwG2PtxJIkSspk3MT9DfLXHDV/OAe4cc6hVmzQ6WcI6/xLN59NLuL6X1eFD rIsM5fkH8sliEY1Cmk/aCjjVXgoAql1yduupzTFihK1RUipimMY4m3sXSAGf2SRazNr+ tBaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=A/aoDsk49ETFUaGu6ntYPDp5Xpa3glyWzoYuA85stpo=; b=1CYYr5a/mO62lKYL7RGvRHjcw71jhl47tNh96edjvdnxucC3fQwI1pIxyZJU+6iw1F 8n/GeuW7Lyvhisv236mEE8fpNYfkKiVFxl/GXGU1siERnhCH+isdmtce1FUMevkr1u0q LQ4CVdApAg2bZGQCtuSTnHkx+4UkR2L5UnmbZrrgz4CAz/2jcXjMdxfIuyCH9mtR0lk+ LnPSRbUxwTADRUvjQK5gG6FFj4kq3qjacN5zHkM6DoMGK+6hdKp4npys8pJod0yFKZdP dvCH+9G1M+UspQNRUqXsX2Ty0o03VUfxxWNep6BIyGd6Jl6bocg/D0dIxRSiEd0LMxKU wF7A== X-Gm-Message-State: ACrzQf3Y2JYf8vMHd953IS2b2uaLrmQhOcESMvfwfmXVQxW+815aP+TT SEisBcwIYEd6C+yOAsgN3tg7Mg== X-Received: by 2002:a17:902:d4cf:b0:178:1e39:31ff with SMTP id o15-20020a170902d4cf00b001781e3931ffmr6996051plg.137.1663475708271; Sat, 17 Sep 2022 21:35:08 -0700 (PDT) Received: from localhost.localdomain ([111.201.134.95]) by smtp.gmail.com with ESMTPSA id l63-20020a622542000000b0054b5239f7fesm3955248pfl.210.2022.09.17.21.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 21:35:07 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V6 2/6] erofs: code clean up for fscache Date: Sun, 18 Sep 2022 12:34:52 +0800 Message-Id: <20220918043456.147-3-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220918043456.147-1-zhujia.zj@bytedance.com> References: <20220918043456.147-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some cleanups. No logic changes. Suggested-by: Jingbo Xu Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/erofs/fscache.c | 39 +++++++++++++++++++-------------------- fs/erofs/internal.h | 19 +++++++++---------- fs/erofs/super.c | 21 ++++++++------------- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 8e01d89c3319..d3a90103abb7 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -417,9 +417,8 @@ const struct address_space_operations erofs_fscache_access_aops = { .readahead = erofs_fscache_readahead, }; -int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, - char *name, bool need_inode) +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, + char *name, bool need_inode) { struct fscache_volume *volume = EROFS_SB(sb)->volume; struct erofs_fscache *ctx; @@ -428,7 +427,7 @@ int erofs_fscache_register_cookie(struct super_block *sb, ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) - return -ENOMEM; + return ERR_PTR(-ENOMEM); cookie = fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE, name, strlen(name), NULL, 0, 0); @@ -458,42 +457,33 @@ int erofs_fscache_register_cookie(struct super_block *sb, ctx->inode = inode; } - *fscache = ctx; - return 0; + return ctx; err_cookie: fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); - ctx->cookie = NULL; err: kfree(ctx); - return ret; + return ERR_PTR(ret); } -void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) +void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) { - struct erofs_fscache *ctx = *fscache; - if (!ctx) return; fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_relinquish_cookie(ctx->cookie, false); - ctx->cookie = NULL; - iput(ctx->inode); - ctx->inode = NULL; - kfree(ctx); - *fscache = NULL; } int erofs_fscache_register_fs(struct super_block *sb) { struct erofs_sb_info *sbi = EROFS_SB(sb); struct fscache_volume *volume; + struct erofs_fscache *fscache; char *name; - int ret = 0; name = kasprintf(GFP_KERNEL, "erofs,%s", sbi->opt.fsid); if (!name) @@ -502,19 +492,28 @@ int erofs_fscache_register_fs(struct super_block *sb) volume = fscache_acquire_volume(name, NULL, NULL, 0); if (IS_ERR_OR_NULL(volume)) { erofs_err(sb, "failed to register volume for %s", name); - ret = volume ? PTR_ERR(volume) : -EOPNOTSUPP; - volume = NULL; + kfree(name); + return volume ? PTR_ERR(volume) : -EOPNOTSUPP; } sbi->volume = volume; kfree(name); - return ret; + + fscache = erofs_fscache_register_cookie(sb, sbi->opt.fsid, true); + /* acquired volume will be relinquished in kill_sb() */ + if (IS_ERR(fscache)) + return PTR_ERR(fscache); + + sbi->s_fscache = fscache; + return 0; } void erofs_fscache_unregister_fs(struct super_block *sb) { struct erofs_sb_info *sbi = EROFS_SB(sb); + erofs_fscache_unregister_cookie(sbi->s_fscache); fscache_relinquish_volume(sbi->volume, NULL, false); + sbi->s_fscache = NULL; sbi->volume = NULL; } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index cfee49d33b95..b36850dd7813 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -610,27 +610,26 @@ static inline int z_erofs_load_lzma_config(struct super_block *sb, int erofs_fscache_register_fs(struct super_block *sb); void erofs_fscache_unregister_fs(struct super_block *sb); -int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, - char *name, bool need_inode); -void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache); +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, + char *name, bool need_inode); +void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); extern const struct address_space_operations erofs_fscache_access_aops; #else static inline int erofs_fscache_register_fs(struct super_block *sb) { - return 0; + return -EOPNOTSUPP; } static inline void erofs_fscache_unregister_fs(struct super_block *sb) {} -static inline int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, - char *name, bool need_inode) +static inline +struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, + char *name, bool need_inode) { - return -EOPNOTSUPP; + return ERR_PTR(-EOPNOTSUPP); } -static inline void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) +static inline void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache) { } #endif diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 9716d355a63e..884e7ed3d760 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -224,10 +224,10 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, struct erofs_device_info *dif, erofs_off_t *pos) { struct erofs_sb_info *sbi = EROFS_SB(sb); + struct erofs_fscache *fscache; struct erofs_deviceslot *dis; struct block_device *bdev; void *ptr; - int ret; ptr = erofs_read_metabuf(buf, sb, erofs_blknr(*pos), EROFS_KMAP); if (IS_ERR(ptr)) @@ -245,10 +245,10 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, } if (erofs_is_fscache_mode(sb)) { - ret = erofs_fscache_register_cookie(sb, &dif->fscache, - dif->path, false); - if (ret) - return ret; + fscache = erofs_fscache_register_cookie(sb, dif->path, false); + if (IS_ERR(fscache)) + return PTR_ERR(fscache); + dif->fscache = fscache; } else { bdev = blkdev_get_by_path(dif->path, FMODE_READ | FMODE_EXCL, sb->s_type); @@ -706,11 +706,6 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) if (err) return err; - err = erofs_fscache_register_cookie(sb, &sbi->s_fscache, - sbi->opt.fsid, true); - if (err) - return err; - err = super_setup_bdi(sb); if (err) return err; @@ -817,7 +812,8 @@ static int erofs_release_device_info(int id, void *ptr, void *data) fs_put_dax(dif->dax_dev, NULL); if (dif->bdev) blkdev_put(dif->bdev, FMODE_READ | FMODE_EXCL); - erofs_fscache_unregister_cookie(&dif->fscache); + erofs_fscache_unregister_cookie(dif->fscache); + dif->fscache = NULL; kfree(dif->path); kfree(dif); return 0; @@ -889,7 +885,6 @@ static void erofs_kill_sb(struct super_block *sb) erofs_free_dev_context(sbi->devs); fs_put_dax(sbi->dax_dev, NULL); - erofs_fscache_unregister_cookie(&sbi->s_fscache); erofs_fscache_unregister_fs(sb); kfree(sbi->opt.fsid); kfree(sbi); @@ -909,7 +904,7 @@ static void erofs_put_super(struct super_block *sb) iput(sbi->managed_cache); sbi->managed_cache = NULL; #endif - erofs_fscache_unregister_cookie(&sbi->s_fscache); + erofs_fscache_unregister_fs(sb); } static struct file_system_type erofs_fs_type = { -- 2.20.1