Skip to contentSkip to conversation

zonefs: add uid,gid,perm mount option

PATCH New [email protected] 2 participants 2 messages Apr 24, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zonefs: add uid,gid,perm mount option

From: cheng wei <[email protected]>

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.

---
 fs/zonefs/super.c  | 42 ++++++++++++++++++++++++++++++++++++++++--
 fs/zonefs/zonefs.h |  3 +++
 2 files changed, 43 insertions(+), 2 deletions(-)
fs/zonefs/super.c +40 -2
index 0fe76f376dee..188a2e7bdda7 100644
@@ -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;
 }
fs/zonefs/zonefs.h +3 -0
index 51141907097c..234b203b7436 100644
@@ -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

Signature · 1 line
2.31.1
#1 lore raw
Thank you for the patch! Perhaps something to improve:

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on 1e28eed17697bcf343c6743f0028cc3b5dd88bf0]

url:    https://github.com/0day-ci/linux/commits/tomwei7g-gmail-com/zonefs-add-uid-gid-perm-mount-option/20210424-221530
base:   1e28eed17697bcf343c6743f0028cc3b5dd88bf0
config: x86_64-randconfig-a004-20210424 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 8e9d17fd4243faa954ae35a4da94e5e922e458e5)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/219d3c453ff7baa144c61b429f1df96b0d2617a3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review tomwei7g-gmail-com/zonefs-add-uid-gid-perm-mount-option/20210424-221530 git checkout 219d3c453ff7baa144c61b429f1df96b0d2617a3
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

>> fs/zonefs/super.c:1195:7: warning: variable 'arg' is used uninitialized whenever '&&' condition is false [-Wsometimes-uninitialized]
                           if(args->from && match_int(args, &arg))
                              ^~~~~~~~~~
   fs/zonefs/super.c:1197:46: note: uninitialized use occurs here
                           sbi->s_uid = make_kuid(current_user_ns(), arg);
                                                                     ^~~
   fs/zonefs/super.c:1195:7: note: remove the '&&' if its condition is always true
                           if(args->from && match_int(args, &arg))
                              ^~~~~~~~~~~~~
   fs/zonefs/super.c:1165:10: note: initialize the variable 'arg' to silence this warning
                   int arg;
                          ^
                           = 0

1 warning generated.

vim +1195 fs/zonefs/super.c

1153
1154 static int zonefs_parse_options(struct super_block *sb, char *options)
1155 {
1156 struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
1157 substring_t args[MAX_OPT_ARGS];
1158 char *p;
1159
1160 if (!options)
1161 return 0;
1162
1163 while ((p = strsep(&options, ",")) != NULL) {
1164 int token;
1165 int arg;
1166
1167 if (!*p)
1168 continue;
1169
1170 args[0].to = args[0].from = NULL;
1171
1172 token = match_token(p, tokens, args);
1173 switch (token) {
1174 case Opt_errors_ro:
1175 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK;
1176 sbi->s_mount_opts |= ZONEFS_MNTOPT_ERRORS_RO;
1177 break;
1178 case Opt_errors_zro:
1179 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK;
1180 sbi->s_mount_opts |= ZONEFS_MNTOPT_ERRORS_ZRO;
1181 break;
1182 case Opt_errors_zol:
1183 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK;
1184 sbi->s_mount_opts |= ZONEFS_MNTOPT_ERRORS_ZOL;
1185 break;
1186 case Opt_errors_repair:
1187 sbi->s_mount_opts &= ~ZONEFS_MNTOPT_ERRORS_MASK;
1188 sbi->s_mount_opts |= ZONEFS_MNTOPT_ERRORS_REPAIR;
1189 break;
1190 case Opt_explicit_open:
1191 sbi->s_mount_opts |= ZONEFS_MNTOPT_EXPLICIT_OPEN;
1192 break;
1193 case Opt_uid:
1194 sbi->s_mount_opts |= ZONEFS_MNTOPT_UID;

> 1195				if(args->from && match_int(args, &arg))

1196 return -EINVAL;
1197 sbi->s_uid = make_kuid(current_user_ns(), arg);
1198 if (!uid_valid(sbi->s_uid)) {
1199 zonefs_err(sb, "Invalid uid value %d\n", arg);
1200 return -EINVAL;
1201 }
1202 break;
1203 case Opt_gid:
1204 sbi->s_mount_opts |= ZONEFS_MNTOPT_GID;
1205 if(args->from && match_int(args, &arg))
1206 return -EINVAL;
1207 sbi->s_gid = make_kgid(current_user_ns(), arg);
1208 if (!gid_valid(sbi->s_gid)) {
1209 zonefs_err(sb, "Invalid gid value %d\n", arg);
1210 return -EINVAL;
1211 }
1212 break;
1213 case Opt_perm:
1214 sbi->s_mount_opts |= ZONEFS_MNTOPT_PERM;
1215 if(args->from && match_int(args, &arg))
1216 return -EINVAL;
1217 sbi->s_perm = arg;
1218 break;
1219 default:
1220 return -EINVAL;
1221 }
1222 }
1223
1224 return 0;
1225 }
1226

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org