Skip to contentSkip to conversation

exfat: add sysfs interface

PATCH In review Yangtao Li 2 participants 3 messages Apr 5, 2023 – Apr 25, 2023

Subsystems (2)
lore
Share & tools
lore

Yangtao Li

author
#0 lore raw

PATCH 1/1 exfat: add sysfs interface

Add sysfs interface to configure exfat related parameters.

---
 fs/exfat/Makefile   |   2 +-
 fs/exfat/dir.c      |   4 +-
 fs/exfat/exfat_fs.h |  13 +++++
 fs/exfat/super.c    |  23 +++++++-
 fs/exfat/sysfs.c    | 138 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 174 insertions(+), 6 deletions(-)
 create mode 100644 fs/exfat/sysfs.c
fs/exfat/Makefile +1 -1
index ed51926a4971..96bda5e5cca2 100644
@@ -5,4 +5,4 @@
 obj-$(CONFIG_EXFAT_FS) += exfat.o
 
 exfat-y	:= inode.o namei.o dir.o super.o fatent.o cache.o nls.o misc.o \
-	   file.o balloc.o
+	   file.o balloc.o sysfs.o
fs/exfat/dir.c +1 -3
index 957574180a5e..efd2bd6e0567 100644
@@ -711,15 +711,13 @@ static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir
 	return 0;
 }
 
-#define EXFAT_MAX_RA_SIZE     (128*1024)
 static int exfat_dir_readahead(struct super_block *sb, sector_t sec)
 {
 	struct exfat_sb_info *sbi = EXFAT_SB(sb);
 	struct buffer_head *bh;
-	unsigned int max_ra_count = EXFAT_MAX_RA_SIZE >> sb->s_blocksize_bits;
 	unsigned int page_ra_count = PAGE_SIZE >> sb->s_blocksize_bits;
 	unsigned int adj_ra_count = max(sbi->sect_per_clus, page_ra_count);
-	unsigned int ra_count = min(adj_ra_count, max_ra_count);
+	unsigned int ra_count = min(adj_ra_count, sbi->max_dir_ra_count);
 
 	/* Read-ahead is not required */
 	if (sbi->sect_per_clus == 1)
fs/exfat/exfat_fs.h +13 -0
index 729ada9e26e8..20638334e1ec 100644
@@ -236,10 +236,13 @@ struct exfat_mount_options {
 	int time_offset; /* Offset of timestamps from UTC (in minutes) */
 };
 
+#define EXFAT_MAX_RA_SIZE     (128*1024)
+
 /*
  * EXFAT file system superblock in-memory data
  */
 struct exfat_sb_info {
+	struct super_block *sb; /* pointer to VFS super block */
 	unsigned long long num_sectors; /* num of sectors in volume */
 	unsigned int num_clusters; /* num of clusters in volume */
 	unsigned int cluster_size; /* cluster size in bytes */
@@ -275,6 +278,10 @@ struct exfat_sb_info {
 	struct hlist_head inode_hashtable[EXFAT_HASH_SIZE];
 
 	struct rcu_head rcu;
+
+	unsigned int max_dir_ra_count;
+	struct kobject s_kobj;
+	struct completion s_kobj_unregister;
 };
 
 #define EXFAT_CACHE_VALID	0
@@ -516,6 +523,12 @@ int exfat_write_inode(struct inode *inode, struct writeback_control *wbc);
 void exfat_evict_inode(struct inode *inode);
 int exfat_block_truncate_page(struct inode *inode, loff_t from);
 
+/* In sysfs.c */
+int exfat_sysfs_register(struct super_block *sb);
+void exfat_sysfs_unregister(struct super_block *sb);
+int __init exfat_sysfs_init(void);
+void exfat_sysfs_exit(void);
+
 /* exfat/nls.c */
 unsigned short exfat_toupper(struct super_block *sb, unsigned short a);
 int exfat_uniname_ncmp(struct super_block *sb, unsigned short *a,
fs/exfat/super.c +21 -2
index 8c32460e031e..a29ce9561cc1 100644
@@ -501,6 +501,7 @@ static int exfat_read_boot_sector(struct super_block *sb)
 	sbi->vol_flags_persistent = sbi->vol_flags & (VOLUME_DIRTY | MEDIA_FAILURE);
 	sbi->clu_srch_ptr = EXFAT_FIRST_CLUSTER;
 	sbi->used_clusters = EXFAT_CLUSTERS_UNTRACKED;
+	sbi->max_dir_ra_count = EXFAT_MAX_RA_SIZE >> sb->s_blocksize_bits;
 
 	/* check consistencies */
 	if ((u64)sbi->num_FAT_sectors << p_boot->sect_size_bits <
@@ -638,6 +639,7 @@ static int exfat_fill_super(struct super_block *sb, struct fs_context *fc)
 		opts->discard = 0;
 	}
 
+	sbi->sb = sb;
 	sb->s_flags |= SB_NODIRATIME;
 	sb->s_magic = EXFAT_SUPER_MAGIC;
 	sb->s_op = &exfat_sops;
@@ -697,6 +699,10 @@ static int exfat_fill_super(struct super_block *sb, struct fs_context *fc)
 		goto free_table;
 	}
 
+	err = exfat_sysfs_register(sb);
+	if (err)
+		goto put_inode;
+
 	return 0;
 
 put_inode:
@@ -773,12 +779,18 @@ static int exfat_init_fs_context(struct fs_context *fc)
 	return 0;
 }
 
+static void exfat_kill_super(struct super_block *sb)
+{
+	kill_block_super(sb);
+	exfat_sysfs_unregister(sb);
+}
+
 static struct file_system_type exfat_fs_type = {
 	.owner			= THIS_MODULE,
 	.name			= "exfat",
 	.init_fs_context	= exfat_init_fs_context,
 	.parameters		= exfat_parameters,
-	.kill_sb		= kill_block_super,
+	.kill_sb		= exfat_kill_super,
 	.fs_flags		= FS_REQUIRES_DEV,
 };
 
@@ -811,12 +823,18 @@ static int __init init_exfat_fs(void)
 		goto shutdown_cache;
 	}
 
-	err = register_filesystem(&exfat_fs_type);
+	err = exfat_sysfs_init();
 	if (err)
 		goto destroy_cache;
 
+	err = register_filesystem(&exfat_fs_type);
+	if (err)
+		goto sysfs_exit;
+
 	return 0;
 
+sysfs_exit:
+	exfat_sysfs_exit();
 destroy_cache:
 	kmem_cache_destroy(exfat_inode_cachep);
 shutdown_cache:
@@ -833,6 +851,7 @@ static void __exit exit_exfat_fs(void)
 	rcu_barrier();
 	kmem_cache_destroy(exfat_inode_cachep);
 	unregister_filesystem(&exfat_fs_type);
+	exfat_sysfs_exit();
 	exfat_cache_shutdown();
 }
 
fs/exfat/sysfs.c new file +138 -0

138 lines not on this page · raw message

Signature · 1 line
2.35.1
maintainer
#2 lore raw

2023-04-26 4:32 GMT+09:00, Yangtao Li <[email protected]>:

Quoted 1 line

ping.....

There is no explanation as to why this parameter is needed.

Quoted 4 lines

Thx,
Yangtao