Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp378133ybt; Wed, 1 Jul 2020 00:18:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl/0B0bVj+QH2Sc2z3i0d28U7aG2Kls5nXQ608HfUx8k7OgwMK4l7gKnZXCcEKAPVUEE0Z X-Received: by 2002:a17:907:9484:: with SMTP id dm4mr22822218ejc.56.1593587920534; Wed, 01 Jul 2020 00:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593587920; cv=none; d=google.com; s=arc-20160816; b=LZ/9nET2/OCGFoqoaKWUb1582tRc8vbq07JC5BbXeiZUKuhvcp8upb/2v9hgFlo34B wRzxSMRVFLbX8LHIvfFXJ4LtXD/A7F+dPK4dPGHC+kHNyhGVsvDsYiuBzRrjw+YsO8hP 6FN7kGKyqKIoQu1hF7qqFMoconqFrChVS+y/mAJ7SytmtIjtehv20cezG6cl//GyZBL9 DAPsW5v34ZGQ24rqy0FRv/QWFr4gBuMt8i3R48gVlL/RfXJsQ8DJeo/WaPwdf+5AGJjo PvIvsHyinborFQB4RdlHbdMpyQpfySQNW9EGV0fLzebmd4iV80Zr7/Oq+XGJsl5DeMoW KKSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=OtDncL7Pnc2bb95NrShvvPUz8EsGjmECZsV5x1roPas=; b=hGQiZYAaHoyBvaiipidXEnkNk6jUmTi80q413dtRUKNYiSZRsMCyd0P3+sxAjOBS+u g8CL88djj2nzACrDHj6sNQhEJWUouYCoc7K1u0YEshc4F0jDZnkPTM32r1UdvINHMoWD NeFII8XHEnHXW14/yc7e7QOMIJRiOOZtnUALbDVCQZ20c5mjPuCbVDesBv35/PjByM/z L0SPVTFWvk4nmBNwEUPI3EXPlrWk1hXWZRUn+7R0nvoJCNQGGlNuhjMGTwbvIe44y7DU VSOXrBNT4kWjc6L30yvNT01/GXDUgGWBQf5QHYeEzKaqxrwmnYMh40ZDgfW8kbx8gMk1 k63g== 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 bw19si3262829ejb.729.2020.07.01.00.18.17; Wed, 01 Jul 2020 00:18:40 -0700 (PDT) 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 S1728161AbgGAHP2 (ORCPT + 99 others); Wed, 1 Jul 2020 03:15:28 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:50350 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728068AbgGAHP2 (ORCPT ); Wed, 1 Jul 2020 03:15:28 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 1F30BD60DE3960F6D055; Wed, 1 Jul 2020 15:15:26 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.206) with Microsoft SMTP Server (TLS) id 14.3.487.0; Wed, 1 Jul 2020 15:15:20 +0800 Subject: Re: [f2fs-dev] [PATCH] f2fs: add symbolic link to kobject in sysfs To: Daeho Jeong CC: , , , Daeho Jeong References: <20200630005625.2405062-1-daeho43@gmail.com> <961072bb-4c8f-b01e-666d-1f5e35a8b76d@huawei.com> From: Chao Yu Message-ID: <9d1afacc-6033-2bae-d55d-909d50f1904b@huawei.com> Date: Wed, 1 Jul 2020 15:15:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/7/1 15:04, Daeho Jeong wrote: > Actually, I want to keep the mount number remaining to the same > number, even if it's re-mounted. Then once there is f2fs umounter, the order will be incorrect... > Or we need to keep track of the number being increased whenever it's > remounted. :( IMO, it needs to always keep the number being increased. Thanks, > > 2020년 7월 1일 (수) 오후 3:36, Chao Yu 님이 작성: >> >> Hi Daeho, >> >> On 2020/6/30 8:56, Daeho Jeong wrote: >>> From: Daeho Jeong >>> >>> Added a symbolic link to directory of sysfs. It will >>> create a symbolic link such as "mount_0" and "mount_1" to >>> each f2fs mount in the order of mounting filesystem. It will >>> provide easy access to sysfs node even if not knowing the >>> specific device node name like sda19 and dm-3. >> >> Just out of curiosity, if we mount/umount as below: >> >> mount /dev/zram0 /mnt/f2fs0 >> mount /dev/zram1 /mnt/f2fs1 >> umount /mnt/f2fs0 >> mount /dev/zram0 /mnt/f2fs0 >> >> Shouldn't sysfs structure be: >> mount_2 -> zram0 >> mount_1 -> zram1 >> zram0 >> zram1 >> >> Then we can know zram0 is mounted after zram1? >> >> However the result shows: >> mount_0 -> zram0 >> mount_1 -> zram1 >> zram0 >> zram1 >> >> Thanks, >> >>> >>> Signed-off-by: Daeho Jeong >>> --- >>> fs/f2fs/f2fs.h | 4 ++++ >>> fs/f2fs/sysfs.c | 31 +++++++++++++++++++++++++++---- >>> 2 files changed, 31 insertions(+), 4 deletions(-) >>> >>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >>> index 4b28fd42fdbc..7d6c5f8ce16b 100644 >>> --- a/fs/f2fs/f2fs.h >>> +++ b/fs/f2fs/f2fs.h >>> @@ -1419,6 +1419,8 @@ struct decompress_io_ctx { >>> #define MAX_COMPRESS_LOG_SIZE 8 >>> #define MAX_COMPRESS_WINDOW_SIZE ((PAGE_SIZE) << MAX_COMPRESS_LOG_SIZE) >>> >>> +#define MOUNT_NAME_SIZE 20 >>> + >>> struct f2fs_sb_info { >>> struct super_block *sb; /* pointer to VFS super block */ >>> struct proc_dir_entry *s_proc; /* proc entry */ >>> @@ -1599,6 +1601,8 @@ struct f2fs_sb_info { >>> /* For sysfs suppport */ >>> struct kobject s_kobj; >>> struct completion s_kobj_unregister; >>> + int s_mount_id; >>> + char s_mount_name[MOUNT_NAME_SIZE]; >>> >>> /* For shrinker support */ >>> struct list_head s_list; >>> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c >>> index ab40e1f89f23..64bbe0b3b830 100644 >>> --- a/fs/f2fs/sysfs.c >>> +++ b/fs/f2fs/sysfs.c >>> @@ -18,6 +18,7 @@ >>> #include >>> >>> static struct proc_dir_entry *f2fs_proc_root; >>> +static struct ida f2fs_mount_ida; >>> >>> /* Sysfs support for f2fs */ >>> enum { >>> @@ -906,6 +907,9 @@ int __init f2fs_init_sysfs(void) >>> } else { >>> f2fs_proc_root = proc_mkdir("fs/f2fs", NULL); >>> } >>> + >>> + ida_init(&f2fs_mount_ida); >>> + >>> return ret; >>> } >>> >>> @@ -915,6 +919,7 @@ void f2fs_exit_sysfs(void) >>> kset_unregister(&f2fs_kset); >>> remove_proc_entry("fs/f2fs", NULL); >>> f2fs_proc_root = NULL; >>> + ida_destroy(&f2fs_mount_ida); >>> } >>> >>> int f2fs_register_sysfs(struct f2fs_sb_info *sbi) >>> @@ -926,12 +931,22 @@ 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 err1; >>> + >>> + sbi->s_mount_id = ida_simple_get(&f2fs_mount_ida, 0, 0, GFP_KERNEL); >>> + if (sbi->s_mount_id < 0) { >>> + err = sbi->s_mount_id; >>> + goto err1; >>> } >>> >>> + snprintf(sbi->s_mount_name, MOUNT_NAME_SIZE, "mount_%d", >>> + sbi->s_mount_id); >>> + err = sysfs_create_link(&f2fs_kset.kobj, &sbi->s_kobj, >>> + sbi->s_mount_name); >>> + if (err) >>> + goto err2; >>> + >>> if (f2fs_proc_root) >>> sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root); >>> >>> @@ -946,6 +961,12 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi) >>> victim_bits_seq_show, sb); >>> } >>> return 0; >>> +err2: >>> + ida_simple_remove(&f2fs_mount_ida, sbi->s_mount_id); >>> +err1: >>> + kobject_put(&sbi->s_kobj); >>> + wait_for_completion(&sbi->s_kobj_unregister); >>> + return err; >>> } >>> >>> void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) >>> @@ -957,6 +978,8 @@ 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); >>> } >>> + sysfs_remove_link(&f2fs_kset.kobj, sbi->s_mount_name); >>> + ida_simple_remove(&f2fs_mount_ida, sbi->s_mount_id); >>> kobject_del(&sbi->s_kobj); >>> kobject_put(&sbi->s_kobj); >>> } >>> > . >