Skip to contentSkip to conversation

bdi: add check before create debugfs dir or files

PATCH In review weiping zhang 2 participants 3 messages Oct 25, 2017 – Oct 26, 2017

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

PATCH 1/1 bdi: add check before create debugfs dir or files

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

---
 mm/backing-dev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/backing-dev.c +5 -3
index 74b52dfd5852..81f4a86ebbed 100644
@@ -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)
Signature · 7 lines
2.14.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 4 lines · weiping zhang

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

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

Quoted 26 lines
---
 mm/backing-dev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/backing-dev.c +5 -3
index 74b52dfd5852..81f4a86ebbed 100644
@@ -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)
Signature · 1 line
2.14.2
Signature · 8 lines
Jan Kara <[email protected]>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 4 lines · Jan Kara
Quoted 3 lines · weiping zhang

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

Quoted 8 lines
Quoted 1 line

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 [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>