Skip to contentSkip to conversation

f2fs: add symbolic link to kobject in sysfs

PATCH Superseded Daeho Jeong 2 participants 7 messages Jun 30, 2020 – Jul 3, 2020 F2FS file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: add symbolic link to kobject in sysfs

From: Daeho Jeong <[email protected]>

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.

---
 fs/f2fs/f2fs.h  |  4 ++++
 fs/f2fs/sysfs.c | 31 +++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +4 -0
index 4b28fd42fdbc..7d6c5f8ce16b 100644
@@ -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;
fs/f2fs/sysfs.c +27 -4
index ab40e1f89f23..64bbe0b3b830 100644
@@ -18,6 +18,7 @@
 #include <trace/events/f2fs.h>
 
 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);
 }
Signature · 1 line
2.27.0.212.ge8ba1cc988-goog
#1 lore raw

Hi Daeho,

Quoted 7 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

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,

Quoted 109 lines
---
 fs/f2fs/f2fs.h  |  4 ++++
 fs/f2fs/sysfs.c | 31 +++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +4 -0
index 4b28fd42fdbc..7d6c5f8ce16b 100644
@@ -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;
fs/f2fs/sysfs.c +27 -4
index ab40e1f89f23..64bbe0b3b830 100644
@@ -18,6 +18,7 @@
 #include <trace/events/f2fs.h>
 
 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);
 }
#2 lore raw

Actually, I want to keep the mount number remaining to the same number, even if it's re-mounted.
Or we need to keep track of the number being increased whenever it's remounted. :(

2020년 7월 1일 (수) 오후 3:36, Chao Yu <[email protected]>님이 작성:

Quoted 144 lines

Hi Daeho,

Quoted 7 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

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,

Quoted 109 lines
---
 fs/f2fs/f2fs.h  |  4 ++++
 fs/f2fs/sysfs.c | 31 +++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +4 -0
index 4b28fd42fdbc..7d6c5f8ce16b 100644
@@ -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;
fs/f2fs/sysfs.c +27 -4
index ab40e1f89f23..64bbe0b3b830 100644
@@ -18,6 +18,7 @@
 #include <trace/events/f2fs.h>
 
 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);
 }
#3 lore raw
Quoted 2 lines · Daeho Jeong

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...

Quoted 2 lines

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,

Quoted 148 lines

2020년 7월 1일 (수) 오후 3:36, Chao Yu <[email protected]>님이 작성:

Quoted 133 lines

Hi Daeho,

Quoted 7 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

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,

Quoted 98 lines
---
 fs/f2fs/f2fs.h  |  4 ++++
 fs/f2fs/sysfs.c | 31 +++++++++++++++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)
fs/f2fs/f2fs.h +4 -0
index 4b28fd42fdbc..7d6c5f8ce16b 100644
@@ -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;
fs/f2fs/sysfs.c +25 -4
index ab40e1f89f23..64bbe0b3b830 100644
@@ -18,6 +18,7 @@
 #include <trace/events/f2fs.h>
 
 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;
 }
 
Quoted 11 lines

fs/f2fs/sysfs.c void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi) · line 985

Quoted 11 lines
fs/f2fs/sysfs.c +2 -0
 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);
 }

.

#4 lore raw
Quoted 5 lines · Daeho Jeong
Quoted 2 lines

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...

Actually, we prepared this patch for a strictly controlled system like Android to easily access the sysfs node for a specific partition like userdata partition using a specific number.
In this system, we don't worry about another unexpected f2fs umounter interfering in between unmounting and mounting a partition.

When we are under the condition that we can keep track of how many times the userdata partition has been re-mounted, we might as well use the original partition name like "/sys/fs/f2fs/dm-9".
This is for when we couldn't do that.

#5 lore raw
Quoted 9 lines · Daeho Jeong
Quoted 5 lines · Daeho Jeong
Quoted 2 lines

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...

Actually, we prepared this patch for a strictly controlled system like Android to easily access the sysfs node for a specific partition like userdata partition using a specific number.

I'm not against Android defined interfaces, just be confused about the behavior that does not fully documented (at least, we should add this into f2fs doc, and specify this is android specified interface), something like once one mount point was umounted, that sequential number @x in 'mount_@x" could be reused by later newly mounted point, it breaks the
description: "in the order of mounting filesystem".

Quoted 9 lines

In this system, we don't worry about another unexpected f2fs umounter interfering in between unmounting and mounting a partition.

When we are under the condition that we can keep track of how many times the userdata partition has been re-mounted, we might as well use the original partition name like "/sys/fs/f2fs/dm-9".
This is for when we couldn't do that.
.

#6 lore raw

Got it.

Thanks~

2020년 7월 3일 (금) 오전 11:02, Chao Yu <[email protected]>님이 작성:

Quoted 28 lines · Daeho Jeong
Quoted 9 lines
Quoted 5 lines · Daeho Jeong
Quoted 2 lines

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...

Actually, we prepared this patch for a strictly controlled system like Android to easily access the sysfs node for a specific partition like userdata partition using a specific number.

I'm not against Android defined interfaces, just be confused about the behavior that does not fully documented (at least, we should add this into f2fs doc, and specify this is android specified interface), something like once one mount point was umounted, that sequential number @x in 'mount_@x" could be reused by later newly mounted point, it breaks the
description: "in the order of mounting filesystem".

Quoted 9 lines

In this system, we don't worry about another unexpected f2fs umounter interfering in between unmounting and mounting a partition.

When we are under the condition that we can keep track of how many times the userdata partition has been re-mounted, we might as well use the original partition name like "/sys/fs/f2fs/dm-9".
This is for when we couldn't do that.
.