[PATCH] staging: erofs: set sb->s_root to NULL when failing from __getname()

2019-05-06 Thread Chengguang Xu
Set sb->s_root to NULL when failing from __getname(),
so that we can avoid double dput and unnecessary operations
in generic_shutdown_super().

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 15c784fba879..c8981662a49b 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -459,6 +459,7 @@ static int erofs_read_super(struct super_block *sb,
 */
 err_devname:
dput(sb->s_root);
+   sb->s_root = NULL;
 err_iget:
 #ifdef EROFS_FS_HAS_MANAGED_CACHE
iput(sbi->managed_cache);
-- 
2.20.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: erofs: remove redundant likely/unlikely annotation in namei.c

2019-02-11 Thread Chengguang Xu
unlikely has already included in IS_ERR(),
so just remove redundant likely/unlikely
annotation.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/namei.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/namei.c b/drivers/staging/erofs/namei.c
index 5596c52e246d..1acd742a41ed 100644
--- a/drivers/staging/erofs/namei.c
+++ b/drivers/staging/erofs/namei.c
@@ -144,7 +144,7 @@ static struct page *find_target_block_classic(
head = mid + 1;
startprfx = matched;
 
-   if (likely(!IS_ERR(candidate)))
+   if (!IS_ERR(candidate))
put_page(candidate);
candidate = page;
} else {
@@ -177,7 +177,7 @@ int erofs_namei(struct inode *dir,
diff = 1;
page = find_target_block_classic(dir, name, );
 
-   if (unlikely(IS_ERR(page)))
+   if (IS_ERR(page))
return PTR_ERR(page);
 
data = kmap_atomic(page);
@@ -187,7 +187,7 @@ int erofs_namei(struct inode *dir,
find_target_dirent(name, data, EROFS_BLKSIZ) :
(struct erofs_dirent *)data;
 
-   if (likely(!IS_ERR(de))) {
+   if (!IS_ERR(de)) {
*nid = le64_to_cpu(de->nid);
*d_type = de->file_type;
}
-- 
2.20.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/2] staging: erofs: remove redundant unlikely annotation in unzip_vle.c

2019-02-11 Thread Chengguang Xu
unlikely has already included in IS_ERR(),
so just remove it.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/unzip_vle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/erofs/unzip_vle.c 
b/drivers/staging/erofs/unzip_vle.c
index 4ac1099a39c6..7cd2d4d9c264 100644
--- a/drivers/staging/erofs/unzip_vle.c
+++ b/drivers/staging/erofs/unzip_vle.c
@@ -539,7 +539,7 @@ static int z_erofs_vle_work_iter_begin(struct 
z_erofs_vle_work_builder *builder,
if (unlikely(work == ERR_PTR(-EAGAIN)))
goto repeat;
 
-   if (unlikely(IS_ERR(work)))
+   if (IS_ERR(work))
return PTR_ERR(work);
 got_it:
z_erofs_pagevec_ctor_init(>vector,
-- 
2.20.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: erofs: fix potential double iput in erofs_read_super()

2019-01-22 Thread Chengguang Xu
Some error cases like failing from d_make_root() will
cause double iput because d_make_root() also does iput
in its error path.

Signed-off-by: Chengguang Xu 
---
Only compile tested.

 drivers/staging/erofs/super.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 1c2eb69682ef..bd97679aacfc 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -420,13 +420,14 @@ static int erofs_read_super(struct super_block *sb,
errln("rootino(nid %llu) is not a directory(i_mode %o)",
ROOT_NID(sbi), inode->i_mode);
err = -EINVAL;
-   goto err_isdir;
+   iput(inode);
+   goto err_iget;
}
 
sb->s_root = d_make_root(inode);
if (sb->s_root == NULL) {
err = -ENOMEM;
-   goto err_makeroot;
+   goto err_iget;
}
 
/* save the device name to sbi */
@@ -452,10 +453,6 @@ static int erofs_read_super(struct super_block *sb,
 */
 err_devname:
dput(sb->s_root);
-err_makeroot:
-err_isdir:
-   if (sb->s_root == NULL)
-   iput(inode);
 err_iget:
 #ifdef EROFS_FS_HAS_MANAGED_CACHE
iput(sbi->managed_cache);
-- 
2.20.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: erofs: change inode related info in erofs_statfs()

2018-09-24 Thread Chengguang Xu
As a read only filesystem, it's better to show available
inode num as 0 in statfs.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 51b076255988..6601a242071f 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -627,8 +627,8 @@ static int erofs_statfs(struct dentry *dentry, struct 
kstatfs *buf)
buf->f_blocks = sbi->blocks;
buf->f_bfree = buf->f_bavail = 0;
 
-   buf->f_files = ULLONG_MAX;
-   buf->f_ffree = ULLONG_MAX - sbi->inos;
+   buf->f_files = sbi->inos;
+   buf->f_ffree = 0;
 
buf->f_namelen = EROFS_NAME_LEN;
 
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 3/3] staging: erofs: option validation in remount

2018-09-19 Thread Chengguang Xu
Add option validation in remount. After this patch, remount
can change recognized options, and for unknown options remount
will fail and report error.

Signed-off-by: Chengguang Xu 
Reviewed-by: Chao Yu 
Reviewed-by: Gao Xiang 
---
 drivers/staging/erofs/super.c | 37 +--
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 720436d082f7..880d01f857ca 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -145,14 +145,10 @@ char *erofs_fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc",
 };
 
-static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
- substring_t *args)
+static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
+unsigned int rate)
 {
struct erofs_fault_info *ffi = >fault_info;
-   int rate = 0;
-
-   if (args->from && match_int(args, ))
-   return -EINVAL;
 
if (rate) {
atomic_set(>inject_ops, 0);
@@ -163,6 +159,17 @@ static int erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
}
 
set_opt(sbi, FAULT_INJECTION);
+}
+
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+ substring_t *args)
+{
+   int rate = 0;
+
+   if (args->from && match_int(args, ))
+   return -EINVAL;
+
+   __erofs_build_fault_attr(sbi, rate);
return 0;
 }
 
@@ -171,6 +178,11 @@ static unsigned int erofs_get_fault_rate(struct 
erofs_sb_info *sbi)
return sbi->fault_info.inject_rate;
 }
 #else
+static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
+unsigned int rate)
+{
+}
+
 static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
  substring_t *args)
 {
@@ -644,10 +656,23 @@ static int erofs_show_options(struct seq_file *seq, 
struct dentry *root)
 
 static int erofs_remount(struct super_block *sb, int *flags, char *data)
 {
+   struct erofs_sb_info *sbi = EROFS_SB(sb);
+   unsigned int org_mnt_opt = sbi->mount_opt;
+   unsigned int org_inject_rate = erofs_get_fault_rate(sbi);
+   int err;
+
BUG_ON(!sb_rdonly(sb));
+   err = parse_options(sb, data);
+   if (err)
+   goto out;
 
*flags |= SB_RDONLY;
return 0;
+out:
+   __erofs_build_fault_attr(sbi, org_inject_rate);
+   sbi->mount_opt = org_mnt_opt;
+
+   return err;
 }
 
 const struct super_operations erofs_sops = {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 2/3] staging: erofs: code cleanup for erofs_show_options()

2018-09-19 Thread Chengguang Xu
Add new helper erofs_get_fault_rate() to get fault rate instead of
directly getting it from sbi, so we can remove the macro check
surrounding it.

Signed-off-by: Chengguang Xu 
Reviewed-by: Chao Yu 
Reviewed-by: Gao Xiang 
---
 drivers/staging/erofs/super.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index d6c6ccc4936d..720436d082f7 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -165,6 +165,11 @@ static int erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
set_opt(sbi, FAULT_INJECTION);
return 0;
 }
+
+static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
+{
+   return sbi->fault_info.inject_rate;
+}
 #else
 static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
  substring_t *args)
@@ -172,6 +177,11 @@ static int erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
infoln("fault_injection options not supported");
return 0;
 }
+
+static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
+{
+   return 0;
+}
 #endif
 
 static void default_options(struct erofs_sb_info *sbi)
@@ -626,11 +636,9 @@ static int erofs_show_options(struct seq_file *seq, struct 
dentry *root)
else
seq_puts(seq, ",noacl");
 #endif
-#ifdef CONFIG_EROFS_FAULT_INJECTION
if (test_opt(sbi, FAULT_INJECTION))
seq_printf(seq, ",fault_injection=%u",
-   sbi->fault_info.inject_rate);
-#endif
+   erofs_get_fault_rate(sbi));
return 0;
 }
 
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 1/3] staging: erofs: code cleanup for option parsing of fault_injection

2018-09-19 Thread Chengguang Xu
Define a dummpy function of erofs_build_fault_attr() when macro
CONFIG_EROFS_FAULT_INJECTION is disabled, so that we don't have to
check the macro in calling place. Based on above adjustment,
do proper code cleanup for option parsing of fault_injection.

Signed-off-by: Chengguang Xu 
Reviewed-by: Chao Yu 
Reviewed-by: Gao Xiang 
---
 drivers/staging/erofs/super.c | 34 +-
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 802202ca7213..d6c6ccc4936d 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -145,10 +145,14 @@ char *erofs_fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc",
 };
 
-static void erofs_build_fault_attr(struct erofs_sb_info *sbi,
-   unsigned int rate)
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+ substring_t *args)
 {
struct erofs_fault_info *ffi = >fault_info;
+   int rate = 0;
+
+   if (args->from && match_int(args, ))
+   return -EINVAL;
 
if (rate) {
atomic_set(>inject_ops, 0);
@@ -157,6 +161,16 @@ static void erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
} else {
memset(ffi, 0, sizeof(struct erofs_fault_info));
}
+
+   set_opt(sbi, FAULT_INJECTION);
+   return 0;
+}
+#else
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+ substring_t *args)
+{
+   infoln("fault_injection options not supported");
+   return 0;
 }
 #endif
 
@@ -193,7 +207,7 @@ static int parse_options(struct super_block *sb, char 
*options)
 {
substring_t args[MAX_OPT_ARGS];
char *p;
-   int arg = 0;
+   int err;
 
if (!options)
return 0;
@@ -238,18 +252,12 @@ static int parse_options(struct super_block *sb, char 
*options)
infoln("noacl options not supported");
break;
 #endif
-#ifdef CONFIG_EROFS_FAULT_INJECTION
case Opt_fault_injection:
-   if (args->from && match_int(args, ))
-   return -EINVAL;
-   erofs_build_fault_attr(EROFS_SB(sb), arg);
-   set_opt(EROFS_SB(sb), FAULT_INJECTION);
+   err = erofs_build_fault_attr(EROFS_SB(sb), args);
+   if (err)
+   return err;
break;
-#else
-   case Opt_fault_injection:
-   infoln("fault_injection options not supported");
-   break;
-#endif
+
default:
errln("Unrecognized mount option \"%s\" "
"or missing value", p);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 0/3] staging: erofs: option validation for remount and some code cleanups

2018-09-19 Thread Chengguang Xu
Hi Greg, Xiang

I rebased code on latest erofs-master branch and that branch
has already merged the first patch in my previous patchset,
so this time I only post rest 3 patches.

Thanks,

--

This patch set mainly does option validation for remount and at
the same time does related code cleanups. Currently when we call
fault injection related code we have to surround it with macro
CONFIG_EROFS_FAULT_INJECTION in every calling place, after this
patch set we don't have to do that, so the code looks clean and
more understandable.

v3->v4:
- Rebase code on latest erofs-master branch in Chao's linux tree.
- Fix checkpatch complains.

v2->v3:
- Fold related patches to one patch.
- Fix building issue.

v1->v2:
Address Chao's comments:
- Allow to set fault_injection=0.
- Keep flag bit when setting fault_injection=0.
- Show injection info in original place.
- Rebase code on latest erofs branch in Chao's linux tree.
- Fix building issue.

Chengguang Xu (3):
  staging: erofs: code cleanup for option parsing of fault_injection
  staging: erofs: code cleanup for erofs_show_options()
  staging: erofs: option validation in remount

 drivers/staging/erofs/super.c | 73 +++
 1 file changed, 57 insertions(+), 16 deletions(-)

-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 3/4] staging: erofs: code cleanup for erofs_show_options()

2018-09-18 Thread Chengguang Xu
Add new helper erofs_get_fault_rate() to get fault rate instead of
directly getting it from sbi, so we can remove the macro check
surrounding it.

Signed-off-by: Chengguang Xu 
Reviewed-by: Chao Yu 
---
 drivers/staging/erofs/super.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index f496e0c1d04d..a091b93190e1 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -165,6 +165,11 @@ static int erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
set_opt(sbi, FAULT_INJECTION);
return 0;
 }
+
+static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
+{
+   return sbi->fault_info.inject_rate;
+}
 #else
 static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
substring_t *args)
@@ -172,6 +177,11 @@ static int erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
infoln("fault_injection options not supported");
return 0;
 }
+
+static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
+{
+   return 0;
+}
 #endif
 
 static void default_options(struct erofs_sb_info *sbi)
@@ -626,11 +636,9 @@ static int erofs_show_options(struct seq_file *seq, struct 
dentry *root)
else
seq_puts(seq, ",noacl");
 #endif
-#ifdef CONFIG_EROFS_FAULT_INJECTION
if (test_opt(sbi, FAULT_INJECTION))
seq_printf(seq, ",fault_injection=%u",
-   sbi->fault_info.inject_rate);
-#endif
+   erofs_get_fault_rate(sbi));
return 0;
 }
 
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 2/4] staging: erofs: code cleanup for option parsing of fault_injection

2018-09-18 Thread Chengguang Xu
Define a dummpy function of erofs_build_fault_attr() when macro
CONFIG_EROFS_FAULT_INJECTION is disabled, so that we don't have to
check the macro in calling place. Based on above adjustment,
do proper code cleanup for option parsing of fault_injection.

Signed-off-by: Chengguang Xu 
Reviewed-by: Chao Yu 
---
 drivers/staging/erofs/super.c | 34 +-
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 9e421536cbdf..f496e0c1d04d 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -145,10 +145,14 @@ char *erofs_fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc",
 };
 
-static void erofs_build_fault_attr(struct erofs_sb_info *sbi,
-   unsigned int rate)
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   substring_t *args)
 {
struct erofs_fault_info *ffi = >fault_info;
+   int rate = 0;
+
+   if (args->from && match_int(args, ))
+   return -EINVAL;
 
if (rate) {
atomic_set(>inject_ops, 0);
@@ -157,6 +161,16 @@ static void erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
} else {
memset(ffi, 0, sizeof(struct erofs_fault_info));
}
+
+   set_opt(sbi, FAULT_INJECTION);
+   return 0;
+}
+#else
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   substring_t *args)
+{
+   infoln("fault_injection options not supported");
+   return 0;
 }
 #endif
 
@@ -193,7 +207,7 @@ static int parse_options(struct super_block *sb, char 
*options)
 {
substring_t args[MAX_OPT_ARGS];
char *p;
-   int arg = 0;
+   int err;
 
if (!options)
return 0;
@@ -238,18 +252,12 @@ static int parse_options(struct super_block *sb, char 
*options)
infoln("noacl options not supported");
break;
 #endif
-#ifdef CONFIG_EROFS_FAULT_INJECTION
case Opt_fault_injection:
-   if (args->from && match_int(args, ))
-   return -EINVAL;
-   erofs_build_fault_attr(EROFS_SB(sb), arg);
-   set_opt(EROFS_SB(sb), FAULT_INJECTION);
+   err = erofs_build_fault_attr(EROFS_SB(sb), args);
+   if (err)
+   return err;
break;
-#else
-   case Opt_fault_injection:
-   infoln("fault_injection options not supported");
-   break;
-#endif
+
default:
errln("Unrecognized mount option \"%s\" "
"or missing value", p);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 0/4] staging: erofs: option validation for remount and some code cleanups

2018-09-18 Thread Chengguang Xu
This patch set mainly does option validation for remount and at
the same time does related code cleanups. Currently when we call
fault injection related code we have to surround it with macro
CONFIG_EROFS_FAULT_INJECTION in every calling place, after this
patch set we don't have to do that, so the code looks clean and
more understandable.

v2->v3:
- Fold related patches to one patch.
- Fix building issue.

v1->v2:
Address Chao's comments:
- Allow to set fault_injection=0.
- Keep flag bit when setting fault_injection=0.
- Show injection info in original place.
- Rebase code on latest erofs branch in Chao's linux tree.
- Fix building issue.

Hi Greg,

You may pick up rest 2-4 patches in this patch set if there
are no more comments from Chao and Xiang.

Thanks,

Chengguang Xu (4):
  staging: erofs: code cleanup for erofs_kmalloc()
  staging: erofs: code cleanup for option parsing of fault_injection
  staging: erofs: code cleanup for erofs_show_options()
  staging: erofs: option validation in remount

 drivers/staging/erofs/internal.h | 13 --
 drivers/staging/erofs/super.c| 73 +---
 2 files changed, 67 insertions(+), 19 deletions(-)

-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 4/4] staging: erofs: option validation in remount

2018-09-18 Thread Chengguang Xu
Add option validation in remount. After this patch, remount
can change recognized options, and for unknown options remount
will fail and report error.

Signed-off-by: Chengguang Xu 
Reviewed-by: Chao Yu 
---
 drivers/staging/erofs/super.c | 38 ---
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index a091b93190e1..30b6b44dc6c4 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -145,14 +145,10 @@ char *erofs_fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc",
 };
 
-static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
-   substring_t *args)
+static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   unsigned int rate)
 {
struct erofs_fault_info *ffi = >fault_info;
-   int rate = 0;
-
-   if (args->from && match_int(args, ))
-   return -EINVAL;
 
if (rate) {
atomic_set(>inject_ops, 0);
@@ -163,14 +159,29 @@ static int erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
}
 
set_opt(sbi, FAULT_INJECTION);
-   return 0;
 }
 
 static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
 {
return sbi->fault_info.inject_rate;
 }
+
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi, substring_t *args)
+{
+   int rate = 0;
+
+   if (args->from && match_int(args, ))
+   return -EINVAL;
+
+   __erofs_build_fault_attr(sbi, rate);
+   return 0;
+}
 #else
+static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   unsigned int rate)
+{
+}
+
 static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
substring_t *args)
 {
@@ -644,10 +655,23 @@ static int erofs_show_options(struct seq_file *seq, 
struct dentry *root)
 
 static int erofs_remount(struct super_block *sb, int *flags, char *data)
 {
+   struct erofs_sb_info *sbi = EROFS_SB(sb);
+   unsigned int org_mnt_opt = sbi->mount_opt;
+   unsigned int org_inject_rate = erofs_get_fault_rate(sbi);
+   int err;
+
BUG_ON(!sb_rdonly(sb));
+   err = parse_options(sb, data);
+   if (err)
+   goto out;
 
*flags |= MS_RDONLY;
return 0;
+out:
+   __erofs_build_fault_attr(sbi, org_inject_rate);
+   sbi->mount_opt = org_mnt_opt;
+
+   return err;
 }
 
 const struct super_operations erofs_sops = {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 1/4] staging: erofs: code cleanup for erofs_kmalloc()

2018-09-18 Thread Chengguang Xu
Define a dummy function of time_to_inject()/erofs_show_injection_info(),
so that we don't have to check macro CONFIG_EROFS_FAULT_INJECTION in
calling place.

Signed-off-by: Chengguang Xu 
Reviewed-by: Chao Yu 
Reviewed-by: Gao Xiang 
---
 drivers/staging/erofs/internal.h | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index f20c6e9b7471..0011b9d505fd 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -42,12 +42,12 @@
 #define DBG_BUGON(...)  ((void)0)
 #endif
 
-#ifdef CONFIG_EROFS_FAULT_INJECTION
 enum {
FAULT_KMALLOC,
FAULT_MAX,
 };
 
+#ifdef CONFIG_EROFS_FAULT_INJECTION
 extern char *erofs_fault_name[FAULT_MAX];
 #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
 
@@ -143,17 +143,24 @@ static inline bool time_to_inject(struct erofs_sb_info 
*sbi, int type)
}
return false;
 }
+#else
+static inline bool time_to_inject(struct erofs_sb_info *sbi, int type)
+{
+   return false;
+}
+
+static inline void erofs_show_injection_info(int type)
+{
+}
 #endif
 
 static inline void *erofs_kmalloc(struct erofs_sb_info *sbi,
size_t size, gfp_t flags)
 {
-#ifdef CONFIG_EROFS_FAULT_INJECTION
if (time_to_inject(sbi, FAULT_KMALLOC)) {
erofs_show_injection_info(FAULT_KMALLOC);
return NULL;
}
-#endif
return kmalloc(size, flags);
 }
 
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 6/6] staging: erofs: option validation in remount

2018-09-17 Thread Chengguang Xu
Add option validation in remount. After this patch, remount
can change recognized options, and for unknown options remount
will fail and report error.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index a6a4874d9c9e..2a952cc7e27d 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -656,10 +656,23 @@ static int erofs_show_options(struct seq_file *seq, 
struct dentry *root)
 
 static int erofs_remount(struct super_block *sb, int *flags, char *data)
 {
+   struct erofs_sb_info *sbi = EROFS_SB(sb);
+   unsigned int org_mnt_opt = sbi->mount_opt;
+   unsigned int org_inject_rate = erofs_get_fault_rate(sbi);
+   int err;
+
BUG_ON(!sb_rdonly(sb));
+   err = parse_options(sb, data);
+   if (err)
+   goto out;
 
*flags |= MS_RDONLY;
return 0;
+out:
+   __erofs_build_fault_attr(sbi, org_inject_rate);
+   sbi->mount_opt = org_mnt_opt;
+
+   return err;
 }
 
 const struct super_operations erofs_sops = {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 4/6] staging: erofs: introduce a new helper erofs_get_fault_rate()

2018-09-17 Thread Chengguang Xu
Introduce a new helper for getting fault rate, so that we
don't have to check macro in calling place.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 3f5ae64b9c60..24f3423ed804 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -145,6 +145,11 @@ char *erofs_fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc",
 };
 
+static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
+{
+   return sbi->fault_info.inject_rate;
+}
+
 static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
unsigned int rate)
 {
@@ -173,6 +178,11 @@ static int erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
return 0;
 }
 #else
+static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
+{
+   return 0;
+}
+
 static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
unsigned int rate)
 {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 5/6] staging: erofs: code cleanup for erofs_show_options()

2018-09-17 Thread Chengguang Xu
Call erofs_get_fault_rate() to get fault rate instead of
directly getting it from sbi, so we can remove the macro
check surrounding it.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 24f3423ed804..a6a4874d9c9e 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -648,11 +648,9 @@ static int erofs_show_options(struct seq_file *seq, struct 
dentry *root)
else
seq_puts(seq, ",noacl");
 #endif
-#ifdef CONFIG_EROFS_FAULT_INJECTION
if (test_opt(sbi, FAULT_INJECTION))
seq_printf(seq, ",fault_injection=%u",
-   sbi->fault_info.inject_rate);
-#endif
+   erofs_get_fault_rate(sbi));
return 0;
 }
 
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 3/6] staging: erofs: introduce a new helper __erofs_build_fault_attr()

2018-09-17 Thread Chengguang Xu
Introduce a new helper __erofs_build_fault_attr() to handle set/clear
erofs_fault_info, we need this funciton for internal use case.
for example, reset fault_injection option in remount.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 25 +++--
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 7ce2fd3d49f3..3f5ae64b9c60 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -145,14 +145,10 @@ char *erofs_fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc",
 };
 
-static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
-   substring_t *args)
+static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   unsigned int rate)
 {
struct erofs_fault_info *ffi = >fault_info;
-   int rate = 0;
-
-   if (args->from && match_int(args, ))
-   return -EINVAL;
 
if (rate) {
atomic_set(>inject_ops, 0);
@@ -164,7 +160,24 @@ static int erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
 
set_opt(sbi, FAILt_INJECTION);
 }
+
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   substring_t *args)
+{
+   int rate = 0;
+
+   if (args->from && match_int(args, ))
+   return -EINVAL;
+
+   __erofs_build_fault_attr(sbi, rate);
+   return 0;
+}
 #else
+static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   unsigned int rate)
+{
+}
+
 static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
substring_t *args)
 {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 2/6] staging: erofs: code cleanup for option parsing of fault_injection

2018-09-17 Thread Chengguang Xu
Define a dummpy function of erofs_build_fault_attr() when macro
CONFIG_EROFS_FAULT_INJECTION is disabled, so that we don't have to
check the macro in calling place. Based on above adjustment,
do proper code cleanup for option parsing of fault_injection.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 33 -
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 9e421536cbdf..7ce2fd3d49f3 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -145,10 +145,14 @@ char *erofs_fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc",
 };
 
-static void erofs_build_fault_attr(struct erofs_sb_info *sbi,
-   unsigned int rate)
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   substring_t *args)
 {
struct erofs_fault_info *ffi = >fault_info;
+   int rate = 0;
+
+   if (args->from && match_int(args, ))
+   return -EINVAL;
 
if (rate) {
atomic_set(>inject_ops, 0);
@@ -157,6 +161,15 @@ static void erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
} else {
memset(ffi, 0, sizeof(struct erofs_fault_info));
}
+
+   set_opt(sbi, FAILt_INJECTION);
+}
+#else
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   substring_t *args)
+{
+   infoln("fault_injection options not supported");
+   return 0;
 }
 #endif
 
@@ -193,7 +206,7 @@ static int parse_options(struct super_block *sb, char 
*options)
 {
substring_t args[MAX_OPT_ARGS];
char *p;
-   int arg = 0;
+   int err;
 
if (!options)
return 0;
@@ -238,18 +251,12 @@ static int parse_options(struct super_block *sb, char 
*options)
infoln("noacl options not supported");
break;
 #endif
-#ifdef CONFIG_EROFS_FAULT_INJECTION
-   case Opt_fault_injection:
-   if (args->from && match_int(args, ))
-   return -EINVAL;
-   erofs_build_fault_attr(EROFS_SB(sb), arg);
-   set_opt(EROFS_SB(sb), FAULT_INJECTION);
-   break;
-#else
case Opt_fault_injection:
-   infoln("fault_injection options not supported");
+   err = erofs_build_fault_attr(EROFS_SB(sb), args);
+   if (err)
+   return err;
break;
-#endif
+
default:
errln("Unrecognized mount option \"%s\" "
"or missing value", p);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/6] staging: erofs: code cleanup for erofs_kmalloc()

2018-09-17 Thread Chengguang Xu
Define a dummy function of time_to_inject()/erofs_show_injection_info(),
so that we don't have to check macro CONFIG_EROFS_FAULT_INJECTION in
calling place.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/internal.h | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index f20c6e9b7471..0011b9d505fd 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -42,12 +42,12 @@
 #define DBG_BUGON(...)  ((void)0)
 #endif
 
-#ifdef CONFIG_EROFS_FAULT_INJECTION
 enum {
FAULT_KMALLOC,
FAULT_MAX,
 };
 
+#ifdef CONFIG_EROFS_FAULT_INJECTION
 extern char *erofs_fault_name[FAULT_MAX];
 #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
 
@@ -143,17 +143,24 @@ static inline bool time_to_inject(struct erofs_sb_info 
*sbi, int type)
}
return false;
 }
+#else
+static inline bool time_to_inject(struct erofs_sb_info *sbi, int type)
+{
+   return false;
+}
+
+static inline void erofs_show_injection_info(int type)
+{
+}
 #endif
 
 static inline void *erofs_kmalloc(struct erofs_sb_info *sbi,
size_t size, gfp_t flags)
 {
-#ifdef CONFIG_EROFS_FAULT_INJECTION
if (time_to_inject(sbi, FAULT_KMALLOC)) {
erofs_show_injection_info(FAULT_KMALLOC);
return NULL;
}
-#endif
return kmalloc(size, flags);
 }
 
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 0/6] staging: erofs: option validation for remount and some code cleanups

2018-09-17 Thread Chengguang Xu
This patch set mainly does option validation for remount and at
the same time does related code cleanups. Currently when we call
fault injection related code we have to surround it with macro
CONFIG_EROFS_FAULT_INJECTION in every calling place, after this
patch set we don't have to do that, so the code looks clean and
more understandable.

v1->v2:
Address Chao's comments:
- Allow to set fault_injection=0.
- Keep flag bit when setting fault_injection=0.
- Show injection info in original place.
- Rebase code on latest erofs branch in Chao's linux tree.
- Fix building issue.


Chengguang Xu (6):
  staging: erofs: code cleanup for erofs_kmalloc()
  staging: erofs: code cleanup for option parsing of fault_injection
  staging: erofs: introduce a new helper __erofs_build_fault_attr()
  staging: erofs: introduce a new helper erofs_get_fault_rate()
  staging: erofs: code cleanup for erofs_show_options()
  staging: erofs: option validation in remount

 drivers/staging/erofs/internal.h | 13 --
 drivers/staging/erofs/super.c| 73 +---
 2 files changed, 67 insertions(+), 19 deletions(-)

-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 6/7] staging: erofs: code cleanup for erofs_show_options()

2018-09-11 Thread Chengguang Xu
Call erofs_get_fault_rate() to get fault rate instead of
directly getting it from sbi, so we can remove the macro
check surrounding it.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index a6ae60564c65..702098c80446 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -648,11 +648,9 @@ static int erofs_show_options(struct seq_file *seq, struct 
dentry *root)
else
seq_puts(seq, ",noacl");
 #endif
-#ifdef CONFIG_EROFS_FAULT_INJECTION
if (test_opt(sbi, FAULT_INJECTION))
seq_printf(seq, ",fault_injection=%u",
-   sbi->fault_info.inject_rate);
-#endif
+   erofs_get_fault_rate(sbi));
return 0;
 }
 
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 5/7] staging: erofs: introduce a new helper erofs_get_fault_rate()

2018-09-11 Thread Chengguang Xu
Introduce a new helper for getting fault rate, so that we
don't have to check macro in calling place.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 8df680aee55a..a6ae60564c65 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -144,6 +144,11 @@ char *erofs_fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc",
 };
 
+static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
+{
+   return sbi->fault_info.inject_rate;
+}
+
 static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
unsigned int rate)
 {
@@ -173,6 +178,11 @@ static int erofs_build_fault_attr(struct erofs_sb_info 
*sbi,
return 0;
 }
 #else
+static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi)
+{
+   return 0;
+}
+
 static void __erofs_build_fault_attr(struct erofs_sb_info *sbi,
unsigned int rate)
 {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 7/7] staging: erofs: option validation in remount

2018-09-11 Thread Chengguang Xu
Add option validation in remount. After this patch, remount
can change recognized options, and for unknown options remount
will fail and report error.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 702098c80446..953408fb82c8 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -656,10 +656,23 @@ static int erofs_show_options(struct seq_file *seq, 
struct dentry *root)
 
 static int erofs_remount(struct super_block *sb, int *flags, char *data)
 {
+   struct erofs_sb_info *sbi = EROFS_SB(sb);
+   unsigned int org_mnt_opt = sbi->mount_opt;
+   unsigned int org_inject_rate = erofs_get_fault_rate(sbi);
+   int err;
+
BUG_ON(!sb_rdonly(sb));
+   err = parse_options(sb, data);
+   if (err)
+   goto out;
 
*flags |= MS_RDONLY;
return 0;
+out:
+   __erofs_build_fault_attr(sbi, org_inject_rate);
+   sbi->mount_opt = org_mnt_opt;
+
+   return err;
 }
 
 const struct super_operations erofs_sops = {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/7] staging: erofs: code cleanup for option parsing of fault_injection

2018-09-11 Thread Chengguang Xu
Define a dummpy function of erofs_build_fault_attr() when macro
CONFIG_EROFS_FAULT_INJECTION is disabled, so that we don't have to
check the macro in calling place. Based on above adjustment,
do proper code cleanup for option parsing of fault_injection.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 33 ++---
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 1aec509c805f..14dbb6517b8d 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -144,18 +144,33 @@ char *erofs_fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc",
 };
 
-static void erofs_build_fault_attr(struct erofs_sb_info *sbi,
-   unsigned int rate)
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   substring_t *args)
 {
struct erofs_fault_info *ffi = >fault_info;
+   int rate = 0;
+
+   if (args->from && match_int(args, ))
+   return -EINVAL;
 
if (rate) {
atomic_set(>inject_ops, 0);
ffi->inject_rate = rate;
ffi->inject_type = (1 << FAULT_MAX) - 1;
+   set_opt(sbi, FAULT_INJECTION);
} else {
memset(ffi, 0, sizeof(struct erofs_fault_info));
+   clear_opt(sbi, FAULT_INJECTION);
}
+
+   return 0;
+}
+#else
+static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
+   substring_t *args)
+{
+   infoln("fault_injection options not supported");
+   return 0;
 }
 #endif
 
@@ -192,7 +207,7 @@ static int parse_options(struct super_block *sb, char 
*options)
 {
substring_t args[MAX_OPT_ARGS];
char *p;
-   int arg = 0;
+   int err;
 
if (!options)
return 0;
@@ -238,15 +253,11 @@ static int parse_options(struct super_block *sb, char 
*options)
break;
 #endif
case Opt_fault_injection:
-   if (args->from && match_int(args, ))
-   return -EINVAL;
-#ifdef CONFIG_EROFS_FAULT_INJECTION
-   erofs_build_fault_attr(EROFS_SB(sb), arg);
-   set_opt(EROFS_SB(sb), FAULT_INJECTION);
-#else
-   infoln("FAULT_INJECTION was not selected");
-#endif
+   err = erofs_build_fault_attr(EROFS_SB(sb), args);
+   if (err)
+   return err;
break;
+
default:
errln("Unrecognized mount option \"%s\" "
"or missing value", p);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/7] staging: erofs: return -EINVAL when specifying fault rate to 0

2018-09-11 Thread Chengguang Xu
Set fault rate to 0 is useless and confusable, so add check to
avoid it.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index d2dbc1fd3abb..8df680aee55a 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -166,6 +166,8 @@ static int erofs_build_fault_attr(struct erofs_sb_info *sbi,
 
if (args->from && match_int(args, ))
return -EINVAL;
+   if (!rate)
+   return -EINVAL;
 
__erofs_build_fault_attr(sbi, rate);
return 0;
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/7] staging: erofs: option validation for remount and some code cleanups

2018-09-11 Thread Chengguang Xu
This patch set mainly does option validation for remount and at
the same time does related code cleanups. Currently when we call
fault injection related code we have to surround it with macro
CONFIG_EROFS_FAULT_INJECTION in every calling place, after this
patch set we don't have to that, so the code looks clean and more
understandable.


Chengguang Xu (7):
  staging: erofs: code cleanup for erofs_kmalloc()
  staging: erofs: code cleanup for option parsing of fault_injection
  staging: erofs: introduce a new helper __erofs_build_fault_attr()
  staging: erofs: return -EINVAL when specifying fault rate to 0
  staging: erofs: introduce a new helper erofs_get_fault_rate()
  staging: erofs: code cleanup for erofs_show_options()
  staging: erofs: option validation in remount

 drivers/staging/erofs/internal.h | 16 ---
 drivers/staging/erofs/super.c| 74 +---
 2 files changed, 69 insertions(+), 21 deletions(-)

-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/7] staging: erofs: code cleanup for erofs_kmalloc()

2018-09-11 Thread Chengguang Xu
Define a dummy function of time_to_inject(), so that we don't
have to check macro CONFIG_EROFS_FAULT_INJECTION in calling place.
Base on above adjustment, do proper code cleanup for erofs_kmalloc().

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/internal.h | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 367b39fe46e5..1bb2e9e96143 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -42,12 +42,12 @@
 #define DBG_BUGON(...)  ((void)0)
 #endif
 
-#ifdef CONFIG_EROFS_FAULT_INJECTION
 enum {
FAULT_KMALLOC,
FAULT_MAX,
 };
 
+#ifdef CONFIG_EROFS_FAULT_INJECTION
 extern char *erofs_fault_name[FAULT_MAX];
 #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
 
@@ -139,21 +139,25 @@ static inline bool time_to_inject(struct erofs_sb_info 
*sbi, int type)
atomic_inc(>inject_ops);
if (atomic_read(>inject_ops) >= ffi->inject_rate) {
atomic_set(>inject_ops, 0);
+   erofs_show_injection_info(type);
return true;
}
return false;
 }
+
+#else
+static inline bool time_to_inject(struct erofs_sb_info *sbi, int type)
+{
+   return false;
+}
 #endif
 
 static inline void *erofs_kmalloc(struct erofs_sb_info *sbi,
size_t size, gfp_t flags)
 {
-#ifdef CONFIG_EROFS_FAULT_INJECTION
-   if (time_to_inject(sbi, FAULT_KMALLOC)) {
-   erofs_show_injection_info(FAULT_KMALLOC);
+   if (time_to_inject(sbi, FAULT_KMALLOC))
return NULL;
-   }
-#endif
+
return kmalloc(size, flags);
 }
 
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] erofs: option validation in remount

2018-09-11 Thread Chengguang Xu
Add option validation in remount. After this patch, remount
can change recognized options, and for unknown options remount
will fail and report error.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 1aec509c805f..8bab077381ad 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -625,10 +625,27 @@ static int erofs_show_options(struct seq_file *seq, 
struct dentry *root)
 
 static int erofs_remount(struct super_block *sb, int *flags, char *data)
 {
+   struct erofs_sb_info *sbi = EROFS_SB(sb);
+   struct erofs_fault_info *ffi = >fault_info;
+   unsigned int orig_mount_opt = sbi->mount_opt;
+   unsigned int orig_inject_rate = ffi->inject_rate;
+   int err;
+
BUG_ON(!sb_rdonly(sb));
 
+   err = parse_options(sb, data);
+   if (err)
+   goto out;
+
*flags |= MS_RDONLY;
return 0;
+
+out:
+   if (ffi->inject_rate != orig_inject_rate)
+   erofs_build_fault_attr(sbi, orig_inject_rate);
+   sbi->mount_opt = orig_mount_opt;
+
+   return err;
 }
 
 const struct super_operations erofs_sops = {
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2] erofs: surround fault_injection ralted option parsing using CONFIG_EROFS_FAULT_INJECTION

2018-09-10 Thread Chengguang Xu
It's a little bit strange when fault_injection related
option fail with -EINVAL which was already disabled
from config, so surround all fault_injection related option
parsing code using CONFIG_EROFS_FAULT_INJECTION. Meanwhile,
slightly change warning message to keep consistency with
option POSIX_ACL and FS_XATTR.

Signed-off-by: Chengguang Xu 
---
v1->v2:
- modify warning message.

 drivers/staging/erofs/super.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 1aec509c805f..4ad55dcb8e68 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -237,16 +237,18 @@ static int parse_options(struct super_block *sb, char 
*options)
infoln("noacl options not supported");
break;
 #endif
+#ifdef CONFIG_EROFS_FAULT_INJECTION
case Opt_fault_injection:
if (args->from && match_int(args, ))
return -EINVAL;
-#ifdef CONFIG_EROFS_FAULT_INJECTION
erofs_build_fault_attr(EROFS_SB(sb), arg);
set_opt(EROFS_SB(sb), FAULT_INJECTION);
+   break;
 #else
-   infoln("FAULT_INJECTION was not selected");
-#endif
+   case Opt_fault_injection:
+   infoln("fault_injection options not supported");
break;
+#endif
default:
errln("Unrecognized mount option \"%s\" "
"or missing value", p);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] erofs: surround fault_injection ralted option parsing using CONFIG_EROFS_FAULT_INJECTION

2018-09-10 Thread Chengguang Xu
It's a little bit strange when fault_injection related
option fail with -EINVAL which was already disabled
from config, so surround all fault_injection related option
parsing code using CONFIG_EROFS_FAULT_INJECTION. Meanwhile,
slightly change warning message to keep consistency with
option POSIX_ACL and FS_XATTR.

Signed-off-by: Chengguang Xu 
---
 drivers/staging/erofs/super.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index 1aec509c805f..4004a00d150d 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -237,16 +237,18 @@ static int parse_options(struct super_block *sb, char 
*options)
infoln("noacl options not supported");
break;
 #endif
+#ifdef CONFIG_EROFS_FAULT_INJECTION
case Opt_fault_injection:
if (args->from && match_int(args, ))
return -EINVAL;
-#ifdef CONFIG_EROFS_FAULT_INJECTION
erofs_build_fault_attr(EROFS_SB(sb), arg);
set_opt(EROFS_SB(sb), FAULT_INJECTION);
+   break;
 #else
-   infoln("FAULT_INJECTION was not selected");
-#endif
+   case Opt_fault_injection:
+   infoln("FAULT_INJECTION not supported");
break;
+#endif
default:
errln("Unrecognized mount option \"%s\" "
"or missing value", p);
-- 
2.17.1

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel