From: cheng wei <tomwei7g@xxxxxxxxx> Zonefs has no way to easily modify file permissions. though we can run mkzonefs again to reset file permissions but it also change uuid that case a lot of problam. To solve this problem add permissions mount option may a good way, we can specify permissions when mount and without zonefs userland tools. Signed-off-by: cheng wei <tomwei7g@xxxxxxxxx> --- fs/zonefs/super.c | 42 ++++++++++++++++++++++++++++++++++++++++-- fs/zonefs/zonefs.h | 3 +++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index 0fe76f376dee..188a2e7bdda7 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -1136,7 +1136,7 @@ static int zonefs_statfs(struct dentry *dentry, struct kstatfs *buf) enum { Opt_errors_ro, Opt_errors_zro, Opt_errors_zol, Opt_errors_repair, - Opt_explicit_open, Opt_err, + Opt_explicit_open, Opt_uid, Opt_gid, Opt_perm, Opt_err, }; static const match_table_t tokens = { @@ -1145,7 +1145,10 @@ static const match_table_t tokens = { { Opt_errors_zol, "errors=zone-offline"}, { Opt_errors_repair, "errors=repair"}, { Opt_explicit_open, "explicit-open" }, - { Opt_err, NULL} + { Opt_uid, "uid=%d" }, + { Opt_gid, "gid=%d" }, + { Opt_perm, "perm=%d" }, + { Opt_err, NULL} }; static int zonefs_parse_options(struct super_block *sb, char *options) @@ -1159,10 +1162,13 @@ static int zonefs_parse_options(struct super_block *sb, char *options) while ((p = strsep(&options, ",")) != NULL) { int token; + int arg; if (!*p) continue; + args[0].to = args[0].from = NULL; + token = match_token(p, tokens, args); switch (token) { case Opt_errors_ro: @@ -1184,6 +1190,32 @@ static int zonefs_parse_options(struct super_block *sb, char *options) case Opt_explicit_open: sbi->s_mount_opts |= ZONEFS_MNTOPT_EXPLICIT_OPEN; break; + case Opt_uid: + sbi->s_mount_opts |= ZONEFS_MNTOPT_UID; + if(args->from && match_int(args, &arg)) + return -EINVAL; + sbi->s_uid = make_kuid(current_user_ns(), arg); + if (!uid_valid(sbi->s_uid)) { + zonefs_err(sb, "Invalid uid value %d\n", arg); + return -EINVAL; + } + break; + case Opt_gid: + sbi->s_mount_opts |= ZONEFS_MNTOPT_GID; + if(args->from && match_int(args, &arg)) + return -EINVAL; + sbi->s_gid = make_kgid(current_user_ns(), arg); + if (!gid_valid(sbi->s_gid)) { + zonefs_err(sb, "Invalid gid value %d\n", arg); + return -EINVAL; + } + break; + case Opt_perm: + sbi->s_mount_opts |= ZONEFS_MNTOPT_PERM; + if(args->from && match_int(args, &arg)) + return -EINVAL; + sbi->s_perm = arg; + break; default: return -EINVAL; } @@ -1204,6 +1236,12 @@ static int zonefs_show_options(struct seq_file *seq, struct dentry *root) seq_puts(seq, ",errors=zone-offline"); if (sbi->s_mount_opts & ZONEFS_MNTOPT_ERRORS_REPAIR) seq_puts(seq, ",errors=repair"); + if (sbi->s_mount_opts & ZONEFS_MNTOPT_UID) + seq_printf(seq, ",uid=%u", from_kuid(&init_user_ns, sbi->s_uid)); + if (sbi->s_mount_opts & ZONEFS_MNTOPT_GID) + seq_printf(seq, ",gid=%u", from_kgid(&init_user_ns, sbi->s_gid)); + if (sbi->s_mount_opts & ZONEFS_MNTOPT_PERM) + seq_printf(seq, ",perm=0%o", sbi->s_perm); return 0; } diff --git a/fs/zonefs/zonefs.h b/fs/zonefs/zonefs.h index 51141907097c..234b203b7436 100644 --- a/fs/zonefs/zonefs.h +++ b/fs/zonefs/zonefs.h @@ -161,6 +161,9 @@ enum zonefs_features { (ZONEFS_MNTOPT_ERRORS_RO | ZONEFS_MNTOPT_ERRORS_ZRO | \ ZONEFS_MNTOPT_ERRORS_ZOL | ZONEFS_MNTOPT_ERRORS_REPAIR) #define ZONEFS_MNTOPT_EXPLICIT_OPEN (1 << 4) /* Explicit open/close of zones on open/close */ +#define ZONEFS_MNTOPT_UID (1 << 5) /* Specify file uid */ +#define ZONEFS_MNTOPT_GID (1 << 6) /* Specify file gid */ +#define ZONEFS_MNTOPT_PERM (1 << 7) /* Specify file perm */ /* * In-memory Super block information. base-commit: 1e28eed17697bcf343c6743f0028cc3b5dd88bf0 -- 2.31.1