add error handle for bdi debugfs register
Subsystems (3)
cover add error handle for bdi debugfs register
this series add error handle for bdi debugfs register flow, the first three patches try to convert void function to int and do some cleanup if create dir or file fail.
the fourth patch only add a WARN_ON in device_add_disk, no function change.
weiping zhang (4):
bdi: add check for bdi_debug_root
bdi: convert bdi_debug_register to int
bdi: add error handle for bdi_debug_register
block: add WARN_ON if bdi register fail
block/genhd.c | 4 +++- mm/backing-dev.c | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 7 deletions(-)
Signature · 1 line
2.14.2
PATCH 1/4 bdi: add check for bdi_debug_root
this patch add a check for bdi_debug_root and do error handle for it. we should make sure it was created success, otherwise when add new block device's bdi folder(eg, 8:0) will be create a debugfs root directory.
--- mm/backing-dev.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
mm/backing-dev.c +14 -3
@@ -36,9 +36,12 @@ struct workqueue_struct *bdi_wq;static struct dentry *bdi_debug_root; -static void bdi_debug_init (void ) +static int bdi_debug_init (void ) { bdi_debug_root =debugfs_create_dir ("bdi" ,NULL ); +if (!bdi_debug_root) +return -ENOMEM ; +return 0 ; }static int bdi_debug_stats_show (struct seq_file *m,void *v)
@@ -126,8 +129,9 @@ static void bdi_debug_unregister(struct backing_dev_info *bdi) debugfs_remove(bdi->debug_dir); }#else -static inline void bdi_debug_init (void ) +static inline int bdi_debug_init (void ) { +return 0 ; }static inline void bdi_debug_register (struct backing_dev_info *bdi,const char *name)
@@ -229,12 +233,19 @@ ATTRIBUTE_GROUPS(bdi_dev);static __init int bdi_class_init (void ) { +int ret; + bdi_class =class_create (THIS_MODULE ,"bdi" );if (IS_ERR (bdi_class))return PTR_ERR (bdi_class); bdi_class->dev_groups = bdi_dev_groups; -bdi_debug_init (); + ret =bdi_debug_init (); +if (ret) { +class_destroy (bdi_class); + bdi_class =NULL ; +return ret; + }return 0 ; }
Signature · 1 line
2.14.2
Re: [PATCH 1/4] bdi: add check for bdi_debug_root
Quoted 8 lines · weiping zhang
this patch add a check for
bdi_debug_rootand do error handle for it. we should make sure it was created success, otherwise when add new block device's bdifolder(eg, 8:0)will be create a debugfs root directory.Signed-off-by weiping zhang <[email protected]>--- mm/backing-dev.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
These functions get called only on system boot - ENOMEM in those cases is generally considered fatal and oopsing is acceptable result. So I don't think this patch is needed.
Honza
Quoted 54 lines
mm/backing-dev.c +14
-3@@ -36,9 +36,12 @@ struct workqueue_struct *bdi_wq;static struct dentry *bdi_debug_root; -static void bdi_debug_init (void ) +static int bdi_debug_init (void ) { bdi_debug_root =debugfs_create_dir ("bdi" ,NULL ); +if (!bdi_debug_root) +return -ENOMEM ; +return 0 ; }static int bdi_debug_stats_show (struct seq_file *m,void *v)@@ -126,8 +129,9 @@ static void bdi_debug_unregister(struct backing_dev_info *bdi) debugfs_remove(bdi->debug_dir); }#else -static inline void bdi_debug_init (void ) +static inline int bdi_debug_init (void ) { +return 0 ; }static inline void bdi_debug_register (struct backing_dev_info *bdi,const char *name)@@ -229,12 +233,19 @@ ATTRIBUTE_GROUPS(bdi_dev);static __init int bdi_class_init (void ) { +int ret; + bdi_class =class_create (THIS_MODULE ,"bdi" );if (IS_ERR (bdi_class))return PTR_ERR (bdi_class); bdi_class->dev_groups = bdi_dev_groups; -bdi_debug_init (); + ret =bdi_debug_init (); +if (ret) { +class_destroy (bdi_class); + bdi_class =NULL ; +return ret; + }return 0 ; }Signature · 1 line
2.14.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 1/4] bdi: add check for bdi_debug_root
Quoted 5 lines · Jan Kara
Quoted 4 lines · weiping zhang
this patch add a check for
bdi_debug_rootand do error handle for it. we should make sure it was created success, otherwise when add new block device's bdifolder(eg, 8:0)will be create a debugfs root directory.
Quoted 9 lines
Quoted 4 lines
Signed-off-by weiping zhang <[email protected]>--- mm/backing-dev.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)These functions get called only on system boot - ENOMEM in those cases is generally considered fatal and oopsing is acceptable result. So I don't think this patch is needed.
OK, I drop this patch.
Thanks a ton.
PATCH 2/4 bdi: convert bdi_debug_register to int
In reply to weiping zhangConvert bdi_debug_register to int and then do error handle for it.
--- mm/backing-dev.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
mm/backing-dev.c +15 -2
@@ -116,11 +116,23 @@ static const struct file_operations bdi_debug_stats_fops = { .release = single_release, }; -static void bdi_debug_register (struct backing_dev_info *bdi,const char *name) +static int bdi_debug_register (struct backing_dev_info *bdi,const char *name) { +if (!bdi_debug_root) +return -ENOMEM ; + bdi->debug_dir =debugfs_create_dir (name, bdi_debug_root); +if (!bdi->debug_dir) +return -ENOMEM ; + bdi->debug_stats =debugfs_create_file ("stats" ,0444 , bdi->debug_dir, bdi, &bdi_debug_stats_fops); +if (!bdi->debug_stats) { +debugfs_remove (bdi->debug_dir); +return -ENOMEM ; + } + +return 0 ; }static void bdi_debug_unregister (struct backing_dev_info *bdi)
@@ -133,9 +145,10 @@ static inline int bdi_debug_init(void) {return 0 ; } -static inline void bdi_debug_register (struct backing_dev_info *bdi, +static inline int bdi_debug_register (struct backing_dev_info *bdi,const char *name) { +return 0 ; }static inline void bdi_debug_unregister (struct backing_dev_info *bdi) {
Signature · 1 line
2.14.2
Re: [PATCH 2/4] bdi: convert bdi_debug_register to int
Quoted 3 lines · weiping zhang
Convert
bdi_debug_registerto int and then do error handle for it.Signed-off-by weiping zhang <[email protected]>
This patch looks good to me. You can add:
Honza
Quoted 48 lines
--- mm/backing-dev.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)mm/backing-dev.c +15
-2@@ -116,11 +116,23 @@ static const struct file_operations bdi_debug_stats_fops = { .release = single_release, }; -static void bdi_debug_register (struct backing_dev_info *bdi,const char *name) +static int bdi_debug_register (struct backing_dev_info *bdi,const char *name) { +if (!bdi_debug_root) +return -ENOMEM ; + bdi->debug_dir =debugfs_create_dir (name, bdi_debug_root); +if (!bdi->debug_dir) +return -ENOMEM ; + bdi->debug_stats =debugfs_create_file ("stats" ,0444 , bdi->debug_dir, bdi, &bdi_debug_stats_fops); +if (!bdi->debug_stats) { +debugfs_remove (bdi->debug_dir); +return -ENOMEM ; + } + +return 0 ; }static void bdi_debug_unregister (struct backing_dev_info *bdi)@@ -133,9 +145,10 @@ static inline int bdi_debug_init(void) {return 0 ; } -static inline void bdi_debug_register (struct backing_dev_info *bdi, +static inline int bdi_debug_register (struct backing_dev_info *bdi,const char *name) { +return 0 ; }static inline void bdi_debug_unregister (struct backing_dev_info *bdi) {Signature · 1 line
2.14.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH 3/4 bdi: add error handle for bdi_debug_register
In reply to weiping zhangIn order to make error handle more cleaner we call bdi_debug_register before set state to WB_registered, that we can avoid call bdi_unregister in release_bdi().
--- mm/backing-dev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
mm/backing-dev.c +6 -1
@@ -893,10 +893,13 @@ int bdi_register_va(struct backing_dev_info *bdi, const char *fmt, va_list args)if (IS_ERR (dev))return PTR_ERR (dev); +if (bdi_debug_register (bdi,dev_name (dev))) { +device_destroy (bdi_class, dev->devt); +return -ENOMEM ; + }cgwb_bdi_register (bdi); bdi->dev = dev; -bdi_debug_register (bdi,dev_name (dev));set_bit (WB_registered, &bdi->wb.state);spin_lock_bh (&bdi_lock);
@@ -916,6 +919,8 @@ int bdi_register(struct backing_dev_info *bdi, const char *fmt, ...)va_start (args, fmt); ret =bdi_register_va (bdi, fmt, args);va_end (args); +if (ret) +bdi_put (bdi);return ret; }EXPORT_SYMBOL (bdi_register);
Signature · 1 line
2.14.2
Re: [PATCH 3/4] bdi: add error handle for bdi_debug_register
Quoted 29 lines · weiping zhang
In order to make error handle more cleaner we call
bdi_debug_registerbefore set state toWB_registered, that we can avoid callbdi_unregisterinrelease_bdi().Signed-off-by weiping zhang <[email protected]>--- mm/backing-dev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)mm/backing-dev.c +4
-1@@ -893,10 +893,13 @@ int bdi_register_va(struct backing_dev_info *bdi, const char *fmt, va_list args)if (IS_ERR (dev))return PTR_ERR (dev); +if (bdi_debug_register (bdi,dev_name (dev))) { +device_destroy (bdi_class, dev->devt); +return -ENOMEM ; + }cgwb_bdi_register (bdi); bdi->dev = dev; -bdi_debug_register (bdi,dev_name (dev));set_bit (WB_registered, &bdi->wb.state);spin_lock_bh (&bdi_lock);
mm/backing-dev.c int bdi_register(struct backing_dev_info *bdi, const char *fmt, ...) · line 923
Quoted 5 lines
mm/backing-dev.c +2
-0@@ -916,6 +919,8 @@ int bdi_register(struct backing_dev_info *bdi, const char *fmt, ...)va_start (args, fmt); ret =bdi_register_va (bdi, fmt, args);va_end (args); +if (ret) +bdi_put (bdi);
Why do you drop bdi reference here in case of error? We didn't do it previously if bdi_register_va() failed for other reasons...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 3/4] bdi: add error handle for bdi_debug_register
Quoted 28 lines · Jan Kara
Quoted 27 lines · weiping zhang
In order to make error handle more cleaner we call
bdi_debug_registerbefore set state toWB_registered, that we can avoid callbdi_unregisterinrelease_bdi().Signed-off-by weiping zhang <[email protected]>--- mm/backing-dev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)mm/backing-dev.c +4
-1@@ -893,10 +893,13 @@ int bdi_register_va(struct backing_dev_info *bdi, const char *fmt, va_list args)if (IS_ERR (dev))return PTR_ERR (dev); +if (bdi_debug_register (bdi,dev_name (dev))) { +device_destroy (bdi_class, dev->devt); +return -ENOMEM ; + }cgwb_bdi_register (bdi); bdi->dev = dev; -bdi_debug_register (bdi,dev_name (dev));set_bit (WB_registered, &bdi->wb.state);
Quoted 11 lines
mm/backing-dev.c int bdi_register(struct backing_dev_info *bdi, const char *fmt, ...) · line 923
Quoted 7 lines
mm/backing-dev.c +2
-0spin_lock_bh (&bdi_lock);@@ -916,6 +919,8 @@ int bdi_register(struct backing_dev_info *bdi, const char *fmt, ...)va_start (args, fmt); ret =bdi_register_va (bdi, fmt, args);va_end (args); +if (ret) +bdi_put (bdi);Why do you drop bdi reference here in case of error? We didn't do it previously if
bdi_register_va()failed for other reasons...
At first I want add cleanup, because device_add_disk->bdi_register_owner->bdi_register doen't do clanup. But I notice that mtd_bdi_init also call bdi_register and do cleanup, so this bdi_put() is wrong. I'll remove it at V2. Thanks a lot.
--
weiping
PATCH 4/4 block: add WARN_ON if bdi register fail
In reply to weiping zhangdevice_add_disk need do more safety error handle, so this patch just add WARN_ON.
--- block/genhd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/genhd.c +3 -1
@@ -660,7 +660,9 @@ void device_add_disk(struct device *parent, struct gendisk *disk)/* Register BDI before referencing it from bdev */ bdi = disk->queue->backing_dev_info; -bdi_register_owner (bdi,disk_to_dev (disk)); + retval =bdi_register_owner (bdi,disk_to_dev (disk)); +if (retval) +WARN_ON (1 );blk_register_region (disk_devt (disk), disk->minors,NULL , exact_match, exact_lock, disk);
Signature · 1 line
2.14.2
Re: [PATCH 4/4] block: add WARN_ON if bdi register fail
Quoted 13 lines · weiping zhang
device_add_diskneed do more safety error handle, so this patch just addWARN_ON.Signed-off-by weiping zhang <[email protected]>--- block/genhd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)block/genhd.c +0
-0
block/genhd.c void device_add_disk(struct device *parent, struct gendisk *disk) · line 665
Quoted 7 lines
block/genhd.c +3
-1@@ -660,7 +660,9 @@ void device_add_disk(struct device *parent, struct gendisk *disk)/* Register BDI before referencing it from bdev */ bdi = disk->queue->backing_dev_info; -bdi_register_owner (bdi,disk_to_dev (disk)); + retval =bdi_register_owner (bdi,disk_to_dev (disk)); +if (retval) +WARN_ON (1 );
Just a nit: You can do
WARN_ON(retval);
Otherwise you can add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 4/4] block: add WARN_ON if bdi register fail
Quoted 24 lines · Jan Kara
Quoted 13 lines · weiping zhang
device_add_diskneed do more safety error handle, so this patch just addWARN_ON.Signed-off-by weiping zhang <[email protected]>--- block/genhd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)block/genhd.c +0
-0block/genhd.c void device_add_disk(struct device *parent, struct gendisk *disk) · line 665
Quoted 7 lines
block/genhd.c +3
-1@@ -660,7 +660,9 @@ void device_add_disk(struct device *parent, struct gendisk *disk)/* Register BDI before referencing it from bdev */ bdi = disk->queue->backing_dev_info; -bdi_register_owner (bdi,disk_to_dev (disk)); + retval =bdi_register_owner (bdi,disk_to_dev (disk)); +if (retval) +WARN_ON (1 );Just a nit: You can do
Quoted 6 lines
WARN_ON(retval);Otherwise you can add:
Reviewed-by Jan Kara <[email protected]>
more claner, I'll apply at V2, Thanks
--
weiping