Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3746226pxu; Tue, 8 Dec 2020 22:30:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvHEjQTIymX0VXMuv4zKwjh2Hg4ccVeM4wJQM4UzDgqtE1sS/6AwLIXLTpA9zXsh6ol1ZA X-Received: by 2002:a17:906:660b:: with SMTP id b11mr808277ejp.190.1607495457678; Tue, 08 Dec 2020 22:30:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607495457; cv=none; d=google.com; s=arc-20160816; b=erHuVLVQkGez5GZF+Ru7704sLHIB9VuWijLooYr3RoexSmrS8bQ/T4OslyHBEcXXmo rMuEBMtSTY7i5cTQ6Us3Znhc+Pv0RqfQ1Y+1ksuhYrjHxGh8hUN0nVGtOJMubWkkynnF Nqn5F4IKwntaJeB0kEEG8j8g3CC05+umnCWFJBmcQyAlscGEkndhG25IoB95Ubi7pPey 6XkhGqXEz42+mvKv2CvBsjFlDcYVGWdlvDqC6Sk0bZrT5WviSiz4Imax7u51Ca9i1UO5 ymoaaGulpgeGLq1WUovP4pSU4n00qh2kounUrJDGx0d3uaVOQrmAtnYyPvT4zKwHO6Em hh1A== 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; bh=NKfE+PlqgAnyiUlc+jb21xEU3+yK65w3/Al2g9p4XWk=; b=aps3l8n5Yi85Ol2F1wVslUKxi+h3kjXeA8Z0VyNorTw9bkz2vIMSMWszjmo1+K/jT+ nXag+z01pk5NJqNQPrD2GXckLYvUx9rGR+E3ufR7ZgQv5QpaFt7LUC5Q8IrkyIZv7+bT 1KhGGlmJIdl2B1TSU9VucTnijsj/RrhXql/SzWPqjFCCJr0qvaKOfuuptW+Msz05bPR2 GPO7KJL4KUY7RcjonWlAHD5D52WQ/usgQJYkPHXtxzQILx/tfux5gcLY+G1NNWdsWudE tRjtpFyrD1DZL+lWGT8JklSbkoHpvrMYiujP8BoVzi51ySIIxJE1thDreKzGMTMUQTfV 9GAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e9si293532ejq.721.2020.12.08.22.30.35; Tue, 08 Dec 2020 22:30:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbgLIG0K (ORCPT + 99 others); Wed, 9 Dec 2020 01:26:10 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:9401 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727641AbgLIG0J (ORCPT ); Wed, 9 Dec 2020 01:26:09 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CrRq851fzz7Bjx; Wed, 9 Dec 2020 14:24:52 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Wed, 9 Dec 2020 14:25:16 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH RESEND 5/6] f2fs: introduce a new per-sb directory in sysfs Date: Wed, 9 Dec 2020 14:24:56 +0800 Message-ID: <20201209062457.111907-5-yuchao0@huawei.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201209062457.111907-1-yuchao0@huawei.com> References: <20201209062457.111907-1-yuchao0@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new directory 'stat' in path of /sys/fs/f2fs//, later we can add new readonly stat sysfs file into this directory, it will make directory less mess. Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 5 +++- fs/f2fs/sysfs.c | 69 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index fbaef39e51df..cb94f650ec3d 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1549,9 +1549,12 @@ struct f2fs_sb_info { unsigned int node_io_flag; /* For sysfs suppport */ - struct kobject s_kobj; + struct kobject s_kobj; /* /sys/fs/f2fs/ */ struct completion s_kobj_unregister; + struct kobject s_stat_kobj; /* /sys/fs/f2fs//stat */ + struct completion s_stat_kobj_unregister; + /* For shrinker support */ struct list_head s_list; int s_ndevs; /* number of devices */ diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 989a649cfa8b..ebca0b4961e8 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -711,6 +711,11 @@ static struct attribute *f2fs_feat_attrs[] = { }; ATTRIBUTE_GROUPS(f2fs_feat); +static struct attribute *f2fs_stat_attrs[] = { + NULL, +}; +ATTRIBUTE_GROUPS(f2fs_stat); + static const struct sysfs_ops f2fs_attr_ops = { .show = f2fs_attr_show, .store = f2fs_attr_store, @@ -739,6 +744,44 @@ static struct kobject f2fs_feat = { .kset = &f2fs_kset, }; +static ssize_t f2fs_stat_attr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, + s_stat_kobj); + struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); + + return a->show ? a->show(a, sbi, buf) : 0; +} + +static ssize_t f2fs_stat_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t len) +{ + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, + s_stat_kobj); + struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr); + + return a->store ? a->store(a, sbi, buf, len) : 0; +} + +static void f2fs_stat_kobj_release(struct kobject *kobj) +{ + struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info, + s_stat_kobj); + complete(&sbi->s_stat_kobj_unregister); +} + +static const struct sysfs_ops f2fs_stat_attr_ops = { + .show = f2fs_stat_attr_show, + .store = f2fs_stat_attr_store, +}; + +static struct kobj_type f2fs_stat_ktype = { + .default_groups = f2fs_stat_groups, + .sysfs_ops = &f2fs_stat_attr_ops, + .release = f2fs_stat_kobj_release, +}; + static int __maybe_unused segment_info_seq_show(struct seq_file *seq, void *offset) { @@ -945,11 +988,15 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) init_completion(&sbi->s_kobj_unregister); err = kobject_init_and_add(&sbi->s_kobj, &f2fs_sb_ktype, NULL, "%s", sb->s_id); - if (err) { - kobject_put(&sbi->s_kobj); - wait_for_completion(&sbi->s_kobj_unregister); - return err; - } + if (err) + goto put_sb_kobj; + + sbi->s_stat_kobj.kset = &f2fs_kset; + init_completion(&sbi->s_stat_kobj_unregister); + err = kobject_init_and_add(&sbi->s_stat_kobj, &f2fs_stat_ktype, + &sbi->s_kobj, "stat"); + if (err) + goto put_stat_kobj; if (f2fs_proc_root) sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); @@ -965,6 +1012,13 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) victim_bits_seq_show, sb); } return 0; +put_stat_kobj: + kobject_put(&sbi->s_stat_kobj); + wait_for_completion(&sbi->s_stat_kobj_unregister); +put_sb_kobj: + kobject_put(&sbi->s_kobj); + wait_for_completion(&sbi->s_kobj_unregister); + return err; } void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) @@ -976,6 +1030,11 @@ void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) remove_proc_entry("victim_bits", sbi->s_proc); remove_proc_entry(sbi->sb->s_id, f2fs_proc_root); } + + kobject_del(&sbi->s_stat_kobj); + kobject_put(&sbi->s_stat_kobj); + wait_for_completion(&sbi->s_stat_kobj_unregister); + kobject_del(&sbi->s_kobj); kobject_put(&sbi->s_kobj); wait_for_completion(&sbi->s_kobj_unregister); -- 2.29.2