linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bdi: add check before create debugfs dir or files
@ 2017-10-25 15:23 weiping zhang
  2017-10-26 13:54 ` Jan Kara
  0 siblings, 1 reply; 3+ messages in thread
From: weiping zhang @ 2017-10-25 15:23 UTC (permalink / raw)
  To: axboe, jack; +Cc: linux-mm

we should make sure parents directory exist, and then create dir or
files under that.

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 mm/backing-dev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index 74b52dfd5852..81f4a86ebbed 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -115,9 +115,11 @@ static const struct file_operations bdi_debug_stats_fops = {
 
 static void bdi_debug_register(struct backing_dev_info *bdi, const char *name)
 {
-	bdi->debug_dir = debugfs_create_dir(name, bdi_debug_root);
-	bdi->debug_stats = debugfs_create_file("stats", 0444, bdi->debug_dir,
-					       bdi, &bdi_debug_stats_fops);
+	if (bdi_debug_root)
+		bdi->debug_dir = debugfs_create_dir(name, bdi_debug_root);
+	if (bdi->debug_dir)
+		bdi->debug_stats = debugfs_create_file("stats", 0444,
+				bdi->debug_dir, bdi, &bdi_debug_stats_fops);
 }
 
 static void bdi_debug_unregister(struct backing_dev_info *bdi)
-- 
2.14.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bdi: add check before create debugfs dir or files
  2017-10-25 15:23 [PATCH] bdi: add check before create debugfs dir or files weiping zhang
@ 2017-10-26 13:54 ` Jan Kara
  2017-10-26 14:33   ` weiping zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2017-10-26 13:54 UTC (permalink / raw)
  To: weiping zhang; +Cc: axboe, jack, linux-mm

On Wed 25-10-17 23:23:18, weiping zhang wrote:
> we should make sure parents directory exist, and then create dir or
> files under that.
> 
> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>

OK, this looks reasonable to me but instead of instead of just leaving
debugfs in half-initialized state, we should rather properly tear it down,
return error from bdi_debug_register() and handle it in
bdi_register_va()...

								hONZA

> ---
>  mm/backing-dev.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/backing-dev.c b/mm/backing-dev.c
> index 74b52dfd5852..81f4a86ebbed 100644
> --- a/mm/backing-dev.c
> +++ b/mm/backing-dev.c
> @@ -115,9 +115,11 @@ static const struct file_operations bdi_debug_stats_fops = {
>  
>  static void bdi_debug_register(struct backing_dev_info *bdi, const char *name)
>  {
> -	bdi->debug_dir = debugfs_create_dir(name, bdi_debug_root);
> -	bdi->debug_stats = debugfs_create_file("stats", 0444, bdi->debug_dir,
> -					       bdi, &bdi_debug_stats_fops);
> +	if (bdi_debug_root)
> +		bdi->debug_dir = debugfs_create_dir(name, bdi_debug_root);
> +	if (bdi->debug_dir)
> +		bdi->debug_stats = debugfs_create_file("stats", 0444,
> +				bdi->debug_dir, bdi, &bdi_debug_stats_fops);
>  }
>  
>  static void bdi_debug_unregister(struct backing_dev_info *bdi)
> -- 
> 2.14.2
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bdi: add check before create debugfs dir or files
  2017-10-26 13:54 ` Jan Kara
@ 2017-10-26 14:33   ` weiping zhang
  0 siblings, 0 replies; 3+ messages in thread
From: weiping zhang @ 2017-10-26 14:33 UTC (permalink / raw)
  To: Jan Kara; +Cc: axboe, linux-mm

On Thu, Oct 26, 2017 at 03:54:05PM +0200, Jan Kara wrote:
> On Wed 25-10-17 23:23:18, weiping zhang wrote:
> > we should make sure parents directory exist, and then create dir or
> > files under that.
> > 
> > Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> 
> OK, this looks reasonable to me but instead of instead of just leaving
> debugfs in half-initialized state, we should rather properly tear it down,
> return error from bdi_debug_register() and handle it in
> bdi_register_va()...
> 
> 
At beginning I try to return error code to caller, then I find
bdi_register_owner's return value was not checked in device_add_disk,
so I think there may have some stories. But now, I found we must check
bdi_register_owner in device_add_disk, otherwise bdi may lead some
undefined behavior. blk_mq_debugfs_register also has same issue.

I will send new patch series to fix these issues.


--
weiping

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-26 14:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-25 15:23 [PATCH] bdi: add check before create debugfs dir or files weiping zhang
2017-10-26 13:54 ` Jan Kara
2017-10-26 14:33   ` weiping zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox