mm/backing-dev: Check return value of the debugfs_create_dir()
Subsystems (2)
PATCH 1/1 mm/backing-dev: Check return value of the debugfs_create_dir()
The debugfs_create_dir() function may fail and return error. If the root directory not created, we can't create anything inside it. This patch adds check for this case.
--- mm/backing-dev.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
mm/backing-dev.c +11 -5
@@ -117,15 +117,21 @@ 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) { -debugfs_remove (bdi->debug_stats); -debugfs_remove (bdi->debug_dir); +if (bdi_debug_root) { +debugfs_remove (bdi->debug_stats); +debugfs_remove (bdi->debug_dir); + } }#else static inline void bdi_debug_init (void )
Signature · 7 lines
2.5.0 -- 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>
Quoted 5 lines · Alexander Kuleshov
The
debugfs_create_dir()function may fail and return error. If the root directory not created, we can't create anything inside it. This patch adds check for this case.Signed-off-by Alexander Kuleshov <[email protected]>
The patch looks good to me. You can add:
Honza
Quoted 38 lines
--- mm/backing-dev.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)mm/backing-dev.c +11
-5@@ -117,15 +117,21 @@ 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) { -debugfs_remove (bdi->debug_stats); -debugfs_remove (bdi->debug_dir); +if (bdi_debug_root) { +debugfs_remove (bdi->debug_stats); +debugfs_remove (bdi->debug_dir); + } }#else static inline void bdi_debug_init (void )Signature · 1 line
2.5.0
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>
Andrew Morton
maintainerQuoted 12 lines · On Tue, 25 Aug 2015 13:54:23 +0600 Alexander Kuleshov <[email protected]>…
The
debugfs_create_dir()function may fail and return error. If the root directory not created, we can't create anything inside it. This patch adds check for this case....
mm/backing-dev.c +0
-0@@ -117,15 +117,21 @@ static const struct file_operations bdi_debug_stats_fops = {static void bdi_debug_register (struct backing_dev_info *bdi,const char *name) {
mm/backing-dev.c static const struct file_operations bdi_debug_stats_fops = { · line 126
Quoted 10 lines
mm/backing-dev.c +7
-3- 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); + }
If debugfs_create_dir() fails, debugfs_create_file() will go ahead and attempt to create the debugfs file in the debugfs root directory:
: static struct dentry *start_creating(const char *name, struct dentry *parent) : {
: ...
: /* If the parent is not specified, we create it in the root.
: * We need the root dentry to do this, which is in the super
: * block. A pointer to that is in the struct vfsmount that we
: * have around.
: */
: if (!parent)
: parent = debugfs_mount->mnt_root;
I'm not sure that this is very useful behaviour, and putting the files in the wrong place is a very obscure way of informing the user that debugfs_create_dir() failed :(
I don't think it's worth making little changes such as this - handling debugfs failures needs a deeper rethink.
--
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>
Quoted 39 lines · Andrew Morton
Quoted 12 lines · On Tue, 25 Aug 2015 13:54:23 +0600 Alexander Kuleshov <[email protected]>…
The
debugfs_create_dir()function may fail and return error. If the root directory not created, we can't create anything inside it. This patch adds check for this case....
mm/backing-dev.c +0
-0@@ -117,15 +117,21 @@ static const struct file_operations bdi_debug_stats_fops = {static void bdi_debug_register (struct backing_dev_info *bdi,const char *name) {mm/backing-dev.c static const struct file_operations bdi_debug_stats_fops = { · line 126
Quoted 10 lines
mm/backing-dev.c +7
-3- 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); + }If
debugfs_create_dir()fails,debugfs_create_file()will go ahead and attempt to create the debugfs file in the debugfs root directory:: static struct dentry *start_creating(const char *name, struct dentry *parent) : {
: ...
: /* If the parent is not specified, we create it in the root.
: * We need the root dentry to do this, which is in the super
: * block. A pointer to that is in the struct vfsmount that we
: * have around.
: */
: if (!parent)
: parent =debugfs_mount->mnt_root;
Quoted 3 lines
I'm not sure that this is very useful behaviour, and putting the files in the wrong place is a very obscure way of informing the user that
debugfs_create_dir()failed :(
But this patch actually makes sure that we don't call debugfs_create_dir() and debugfs_create_file() with parent == NULL so this patch avoids creation of entries in debugfs root. So IMHO it really improves the situation. And I agree with you that falling back to debugfs root is just broken...
Quoted 2 lines
I don't think it's worth making little changes such as this - handling debugfs failures needs a deeper rethink.
Well, handling debugfs failures like in this patch is the right way to go, isn't it? Or what else would you imagine than checking for errors and bailing out instead of trying to create entries in non-existent dirs?
Honza
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>
Hello Jan,
2015-08-26 15:23 GMT+06:00 Jan Kara <[email protected]>:
Quoted 3 lines
Well, handling debugfs failures like in this patch is the right way to go, isn't it? Or what else would you imagine than checking for errors and bailing out instead of trying to create entries in non-existent dirs?
I think Andrew talks about this thread https://lkml.org/lkml/2015/8/14/555
--
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>