From: Daeho Jeong <daehoje...@google.com>

Added "volume_name" mount option. When the volume name in the on-disk
superblock doesn't exist, we can input the volume name as a mount
option and this is used to create a sysfs symbolic link pointing to
/sys/fs/f2fs/<disk>. The format of the symbolic directory link is like
/sys/fs/f2fs/<volume_name>_<num>, <volume_name> is the passed volume
name and <num> means the order of mounting with the same volume name.
When the on-disk volume name already exists, this mount option will be
ignored.

Signed-off-by: Daeho Jeong <daehoje...@google.com>
---
 Documentation/filesystems/f2fs.rst |  8 ++++++++
 fs/f2fs/super.c                    | 23 +++++++++++++++++++++++
 fs/f2fs/sysfs.c                    | 14 +++++++++++---
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/Documentation/filesystems/f2fs.rst 
b/Documentation/filesystems/f2fs.rst
index 8221f3af6042..07507bed4fc1 100644
--- a/Documentation/filesystems/f2fs.rst
+++ b/Documentation/filesystems/f2fs.rst
@@ -260,6 +260,14 @@ compress_extension=%s  Support adding specified extension, 
so that f2fs can enab
                        For other files, we can still enable compression via 
ioctl.
                        Note that, there is one reserved special extension '*', 
it
                        can be set to enable compression for all files.
+volume_name=%s         When the volume name in the on-disk superblock doesn't 
exist,
+                       we can input the volume name as a mount option and this 
is
+                       used to create a sysfs symbolic link pointing to
+                       /sys/fs/f2fs/<disk>. The format of the symbolic 
directory
+                       link is like /sys/fs/f2fs/<volume_name>_<num>, 
<volume_name>
+                       is the passed volume name and <num> means the order of 
mounting
+                       with the same volume name. When the on-disk volume name 
already
+                       exists, this mount option will be ignored.
 ====================== 
============================================================
 
 Debugfs Entries
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 7b002785417a..18d0a535697d 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -145,6 +145,7 @@ enum {
        Opt_compress_algorithm,
        Opt_compress_log_size,
        Opt_compress_extension,
+       Opt_volume_name,
        Opt_err,
 };
 
@@ -211,6 +212,7 @@ static match_table_t f2fs_tokens = {
        {Opt_compress_algorithm, "compress_algorithm=%s"},
        {Opt_compress_log_size, "compress_log_size=%u"},
        {Opt_compress_extension, "compress_extension=%s"},
+       {Opt_volume_name, "volume_name=%s"},
        {Opt_err, NULL},
 };
 
@@ -918,6 +920,21 @@ static int parse_options(struct super_block *sb, char 
*options, bool is_remount)
                        F2FS_OPTION(sbi).compress_ext_cnt++;
                        kfree(name);
                        break;
+               case Opt_volume_name:
+                       name = match_strdup(&args[0]);
+                       if (!name)
+                               return -ENOMEM;
+
+                       if (strlen(name) > MAX_VOLUME_NAME) {
+                               f2fs_err(sbi,
+                                       "Volume name is too long");
+                               kfree(name);
+                               return -EINVAL;
+                       }
+
+                       strncpy(sbi->syslink_name, name, MAX_VOLUME_NAME);
+                       kfree(name);
+                       break;
                default:
                        f2fs_err(sbi, "Unrecognized mount option \"%s\" or 
missing value",
                                 p);
@@ -1609,6 +1626,12 @@ static int f2fs_show_options(struct seq_file *seq, 
struct dentry *root)
                seq_printf(seq, ",fsync_mode=%s", "nobarrier");
 
        f2fs_show_compress_options(seq, sbi->sb);
+
+       mutex_lock(&sbi->syslink_mutex);
+       if (f2fs_has_syslink(sbi))
+               seq_printf(seq, ",volume_name=%s", sbi->syslink_name);
+       mutex_unlock(&sbi->syslink_mutex);
+
        return 0;
 }
 
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index e9818dd338c1..6d4a2f8aa0d7 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -907,7 +907,7 @@ static void f2fs_unload_syslink(struct f2fs_sb_info *sbi)
        memset(sbi->syslink_name, 0, MAX_SYSLINK_NAME);
 }
 
-static int f2fs_load_syslink(struct f2fs_sb_info *sbi)
+static int f2fs_load_syslink(struct f2fs_sb_info *sbi, bool mount)
 {
        int idx, count, ret;
 
@@ -918,6 +918,14 @@ static int f2fs_load_syslink(struct f2fs_sb_info *sbi)
                        MAX_VOLUME_NAME);
        up_read(&sbi->sb_lock);
 
+       if (mount) {
+               if (count)
+                       memset(sbi->syslink_name + count, 0,
+                                       MAX_SYSLINK_NAME - count);
+               else
+                       count = strlen(sbi->syslink_name);
+       }
+
        if (!count)
                return -ENOENT;
 
@@ -939,7 +947,7 @@ void f2fs_reload_syslink(struct f2fs_sb_info *sbi)
 {
        mutex_lock(&sbi->syslink_mutex);
        f2fs_unload_syslink(sbi);
-       f2fs_load_syslink(sbi);
+       f2fs_load_syslink(sbi, false);
        mutex_unlock(&sbi->syslink_mutex);
 }
 
@@ -1001,7 +1009,7 @@ int f2fs_register_sysfs(struct f2fs_sb_info *sbi)
                                victim_bits_seq_show, sb);
        }
 
-       f2fs_load_syslink(sbi);
+       f2fs_load_syslink(sbi, true);
 
        return 0;
 }
-- 
2.28.0.rc0.105.gf9edc3c819-goog

Reply via email to