Skip to content

Commit e581595

Browse files
gregkhtorvalds
authored andcommitted
ocfs: no need to check return value of debugfs_create functions
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this. Also, because there is no need to save the file dentry, remove all of the variables that were being saved, and just recursively delete the whole directory when shutting down, saving a lot of logic and local variables. [[email protected]: v2] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Joseph Qi <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Joseph Qi <[email protected]> Cc: Jia Guo <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Gang He <[email protected]> Cc: Jun Piao <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5da844a commit e581595

File tree

13 files changed

+73
-261
lines changed

13 files changed

+73
-261
lines changed

fs/ocfs2/blockcheck.c

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -242,57 +242,29 @@ static struct dentry *blockcheck_debugfs_create(const char *name,
242242
static void ocfs2_blockcheck_debug_remove(struct ocfs2_blockcheck_stats *stats)
243243
{
244244
if (stats) {
245-
debugfs_remove(stats->b_debug_check);
246-
stats->b_debug_check = NULL;
247-
debugfs_remove(stats->b_debug_failure);
248-
stats->b_debug_failure = NULL;
249-
debugfs_remove(stats->b_debug_recover);
250-
stats->b_debug_recover = NULL;
251-
debugfs_remove(stats->b_debug_dir);
245+
debugfs_remove_recursive(stats->b_debug_dir);
252246
stats->b_debug_dir = NULL;
253247
}
254248
}
255249

256-
static int ocfs2_blockcheck_debug_install(struct ocfs2_blockcheck_stats *stats,
257-
struct dentry *parent)
250+
static void ocfs2_blockcheck_debug_install(struct ocfs2_blockcheck_stats *stats,
251+
struct dentry *parent)
258252
{
259-
int rc = -EINVAL;
260-
261-
if (!stats)
262-
goto out;
263-
264253
stats->b_debug_dir = debugfs_create_dir("blockcheck", parent);
265-
if (!stats->b_debug_dir)
266-
goto out;
267254

268-
stats->b_debug_check =
269-
blockcheck_debugfs_create("blocks_checked",
270-
stats->b_debug_dir,
271-
&stats->b_check_count);
255+
blockcheck_debugfs_create("blocks_checked", stats->b_debug_dir,
256+
&stats->b_check_count);
272257

273-
stats->b_debug_failure =
274-
blockcheck_debugfs_create("checksums_failed",
275-
stats->b_debug_dir,
276-
&stats->b_failure_count);
258+
blockcheck_debugfs_create("checksums_failed", stats->b_debug_dir,
259+
&stats->b_failure_count);
277260

278-
stats->b_debug_recover =
279-
blockcheck_debugfs_create("ecc_recoveries",
280-
stats->b_debug_dir,
281-
&stats->b_recover_count);
282-
if (stats->b_debug_check && stats->b_debug_failure &&
283-
stats->b_debug_recover)
284-
rc = 0;
285-
286-
out:
287-
if (rc)
288-
ocfs2_blockcheck_debug_remove(stats);
289-
return rc;
261+
blockcheck_debugfs_create("ecc_recoveries", stats->b_debug_dir,
262+
&stats->b_recover_count);
290263
}
291264
#else
292-
static inline int ocfs2_blockcheck_debug_install(struct ocfs2_blockcheck_stats *stats,
293-
struct dentry *parent)
265+
static inline void ocfs2_blockcheck_debug_install(struct ocfs2_blockcheck_stats *stats,
266+
struct dentry *parent)
294267
{
295-
return 0;
296268
}
297269

298270
static inline void ocfs2_blockcheck_debug_remove(struct ocfs2_blockcheck_stats *stats)
@@ -301,10 +273,10 @@ static inline void ocfs2_blockcheck_debug_remove(struct ocfs2_blockcheck_stats *
301273
#endif /* CONFIG_DEBUG_FS */
302274

303275
/* Always-called wrappers for starting and stopping the debugfs files */
304-
int ocfs2_blockcheck_stats_debugfs_install(struct ocfs2_blockcheck_stats *stats,
305-
struct dentry *parent)
276+
void ocfs2_blockcheck_stats_debugfs_install(struct ocfs2_blockcheck_stats *stats,
277+
struct dentry *parent)
306278
{
307-
return ocfs2_blockcheck_debug_install(stats, parent);
279+
ocfs2_blockcheck_debug_install(stats, parent);
308280
}
309281

310282
void ocfs2_blockcheck_stats_debugfs_remove(struct ocfs2_blockcheck_stats *stats)

fs/ocfs2/blockcheck.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ struct ocfs2_blockcheck_stats {
2525
* ocfs2_blockcheck_stats_debugfs_install()
2626
*/
2727
struct dentry *b_debug_dir; /* Parent of the debugfs files */
28-
struct dentry *b_debug_check; /* Exposes b_check_count */
29-
struct dentry *b_debug_failure; /* Exposes b_failure_count */
30-
struct dentry *b_debug_recover; /* Exposes b_recover_count */
3128
};
3229

3330

@@ -56,8 +53,8 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
5653
struct ocfs2_blockcheck_stats *stats);
5754

5855
/* Debug Initialization */
59-
int ocfs2_blockcheck_stats_debugfs_install(struct ocfs2_blockcheck_stats *stats,
60-
struct dentry *parent);
56+
void ocfs2_blockcheck_stats_debugfs_install(struct ocfs2_blockcheck_stats *stats,
57+
struct dentry *parent);
6158
void ocfs2_blockcheck_stats_debugfs_remove(struct ocfs2_blockcheck_stats *stats);
6259

6360
/*

fs/ocfs2/cluster/heartbeat.c

Lines changed: 25 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ static struct o2hb_debug_buf *o2hb_db_failedregions;
9292
#define O2HB_DEBUG_REGION_PINNED "pinned"
9393

9494
static struct dentry *o2hb_debug_dir;
95-
static struct dentry *o2hb_debug_livenodes;
96-
static struct dentry *o2hb_debug_liveregions;
97-
static struct dentry *o2hb_debug_quorumregions;
98-
static struct dentry *o2hb_debug_failedregions;
9995

10096
static LIST_HEAD(o2hb_all_regions);
10197

@@ -1391,11 +1387,7 @@ static const struct file_operations o2hb_debug_fops = {
13911387

13921388
void o2hb_exit(void)
13931389
{
1394-
debugfs_remove(o2hb_debug_failedregions);
1395-
debugfs_remove(o2hb_debug_quorumregions);
1396-
debugfs_remove(o2hb_debug_liveregions);
1397-
debugfs_remove(o2hb_debug_livenodes);
1398-
debugfs_remove(o2hb_debug_dir);
1390+
debugfs_remove_recursive(o2hb_debug_dir);
13991391
kfree(o2hb_db_livenodes);
14001392
kfree(o2hb_db_liveregions);
14011393
kfree(o2hb_db_quorumregions);
@@ -1419,79 +1411,37 @@ static struct dentry *o2hb_debug_create(const char *name, struct dentry *dir,
14191411
&o2hb_debug_fops);
14201412
}
14211413

1422-
static int o2hb_debug_init(void)
1414+
static void o2hb_debug_init(void)
14231415
{
1424-
int ret = -ENOMEM;
1425-
14261416
o2hb_debug_dir = debugfs_create_dir(O2HB_DEBUG_DIR, NULL);
1427-
if (!o2hb_debug_dir) {
1428-
mlog_errno(ret);
1429-
goto bail;
1430-
}
14311417

1432-
o2hb_debug_livenodes = o2hb_debug_create(O2HB_DEBUG_LIVENODES,
1433-
o2hb_debug_dir,
1434-
&o2hb_db_livenodes,
1435-
sizeof(*o2hb_db_livenodes),
1436-
O2HB_DB_TYPE_LIVENODES,
1437-
sizeof(o2hb_live_node_bitmap),
1438-
O2NM_MAX_NODES,
1439-
o2hb_live_node_bitmap);
1440-
if (!o2hb_debug_livenodes) {
1441-
mlog_errno(ret);
1442-
goto bail;
1443-
}
1418+
o2hb_debug_create(O2HB_DEBUG_LIVENODES, o2hb_debug_dir,
1419+
&o2hb_db_livenodes, sizeof(*o2hb_db_livenodes),
1420+
O2HB_DB_TYPE_LIVENODES, sizeof(o2hb_live_node_bitmap),
1421+
O2NM_MAX_NODES, o2hb_live_node_bitmap);
14441422

1445-
o2hb_debug_liveregions = o2hb_debug_create(O2HB_DEBUG_LIVEREGIONS,
1446-
o2hb_debug_dir,
1447-
&o2hb_db_liveregions,
1448-
sizeof(*o2hb_db_liveregions),
1449-
O2HB_DB_TYPE_LIVEREGIONS,
1450-
sizeof(o2hb_live_region_bitmap),
1451-
O2NM_MAX_REGIONS,
1452-
o2hb_live_region_bitmap);
1453-
if (!o2hb_debug_liveregions) {
1454-
mlog_errno(ret);
1455-
goto bail;
1456-
}
1423+
o2hb_debug_create(O2HB_DEBUG_LIVEREGIONS, o2hb_debug_dir,
1424+
&o2hb_db_liveregions, sizeof(*o2hb_db_liveregions),
1425+
O2HB_DB_TYPE_LIVEREGIONS,
1426+
sizeof(o2hb_live_region_bitmap), O2NM_MAX_REGIONS,
1427+
o2hb_live_region_bitmap);
14571428

1458-
o2hb_debug_quorumregions =
1459-
o2hb_debug_create(O2HB_DEBUG_QUORUMREGIONS,
1460-
o2hb_debug_dir,
1461-
&o2hb_db_quorumregions,
1462-
sizeof(*o2hb_db_quorumregions),
1463-
O2HB_DB_TYPE_QUORUMREGIONS,
1464-
sizeof(o2hb_quorum_region_bitmap),
1465-
O2NM_MAX_REGIONS,
1466-
o2hb_quorum_region_bitmap);
1467-
if (!o2hb_debug_quorumregions) {
1468-
mlog_errno(ret);
1469-
goto bail;
1470-
}
1471-
1472-
o2hb_debug_failedregions =
1473-
o2hb_debug_create(O2HB_DEBUG_FAILEDREGIONS,
1474-
o2hb_debug_dir,
1475-
&o2hb_db_failedregions,
1476-
sizeof(*o2hb_db_failedregions),
1477-
O2HB_DB_TYPE_FAILEDREGIONS,
1478-
sizeof(o2hb_failed_region_bitmap),
1479-
O2NM_MAX_REGIONS,
1480-
o2hb_failed_region_bitmap);
1481-
if (!o2hb_debug_failedregions) {
1482-
mlog_errno(ret);
1483-
goto bail;
1484-
}
1429+
o2hb_debug_create(O2HB_DEBUG_QUORUMREGIONS, o2hb_debug_dir,
1430+
&o2hb_db_quorumregions,
1431+
sizeof(*o2hb_db_quorumregions),
1432+
O2HB_DB_TYPE_QUORUMREGIONS,
1433+
sizeof(o2hb_quorum_region_bitmap), O2NM_MAX_REGIONS,
1434+
o2hb_quorum_region_bitmap);
14851435

1486-
ret = 0;
1487-
bail:
1488-
if (ret)
1489-
o2hb_exit();
1490-
1491-
return ret;
1436+
o2hb_debug_create(O2HB_DEBUG_FAILEDREGIONS, o2hb_debug_dir,
1437+
&o2hb_db_failedregions,
1438+
sizeof(*o2hb_db_failedregions),
1439+
O2HB_DB_TYPE_FAILEDREGIONS,
1440+
sizeof(o2hb_failed_region_bitmap), O2NM_MAX_REGIONS,
1441+
o2hb_failed_region_bitmap);
14921442
}
14931443

1494-
int o2hb_init(void)
1444+
void o2hb_init(void)
14951445
{
14961446
int i;
14971447

@@ -1511,7 +1461,7 @@ int o2hb_init(void)
15111461

15121462
o2hb_dependent_users = 0;
15131463

1514-
return o2hb_debug_init();
1464+
o2hb_debug_init();
15151465
}
15161466

15171467
/* if we're already in a callback then we're already serialized by the sem */

fs/ocfs2/cluster/heartbeat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void o2hb_unregister_callback(const char *region_uuid,
6363
void o2hb_fill_node_map(unsigned long *map,
6464
unsigned bytes);
6565
void o2hb_exit(void);
66-
int o2hb_init(void);
66+
void o2hb_init(void);
6767
int o2hb_check_node_heartbeating_no_sem(u8 node_num);
6868
int o2hb_check_node_heartbeating_from_callback(u8 node_num);
6969
void o2hb_stop_all_regions(void);

fs/ocfs2/cluster/netdebug.c

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
#define SHOW_SOCK_STATS 1
3939

4040
static struct dentry *o2net_dentry;
41-
static struct dentry *sc_dentry;
42-
static struct dentry *nst_dentry;
43-
static struct dentry *stats_dentry;
44-
static struct dentry *nodes_dentry;
4541

4642
static DEFINE_SPINLOCK(o2net_debug_lock);
4743

@@ -490,36 +486,23 @@ static const struct file_operations nodes_fops = {
490486

491487
void o2net_debugfs_exit(void)
492488
{
493-
debugfs_remove(nodes_dentry);
494-
debugfs_remove(stats_dentry);
495-
debugfs_remove(sc_dentry);
496-
debugfs_remove(nst_dentry);
497-
debugfs_remove(o2net_dentry);
489+
debugfs_remove_recursive(o2net_dentry);
498490
}
499491

500-
int o2net_debugfs_init(void)
492+
void o2net_debugfs_init(void)
501493
{
502494
umode_t mode = S_IFREG|S_IRUSR;
503495

504496
o2net_dentry = debugfs_create_dir(O2NET_DEBUG_DIR, NULL);
505-
if (o2net_dentry)
506-
nst_dentry = debugfs_create_file(NST_DEBUG_NAME, mode,
507-
o2net_dentry, NULL, &nst_seq_fops);
508-
if (nst_dentry)
509-
sc_dentry = debugfs_create_file(SC_DEBUG_NAME, mode,
510-
o2net_dentry, NULL, &sc_seq_fops);
511-
if (sc_dentry)
512-
stats_dentry = debugfs_create_file(STATS_DEBUG_NAME, mode,
513-
o2net_dentry, NULL, &stats_seq_fops);
514-
if (stats_dentry)
515-
nodes_dentry = debugfs_create_file(NODES_DEBUG_NAME, mode,
516-
o2net_dentry, NULL, &nodes_fops);
517-
if (nodes_dentry)
518-
return 0;
519-
520-
o2net_debugfs_exit();
521-
mlog_errno(-ENOMEM);
522-
return -ENOMEM;
497+
498+
debugfs_create_file(NST_DEBUG_NAME, mode, o2net_dentry, NULL,
499+
&nst_seq_fops);
500+
debugfs_create_file(SC_DEBUG_NAME, mode, o2net_dentry, NULL,
501+
&sc_seq_fops);
502+
debugfs_create_file(STATS_DEBUG_NAME, mode, o2net_dentry, NULL,
503+
&stats_seq_fops);
504+
debugfs_create_file(NODES_DEBUG_NAME, mode, o2net_dentry, NULL,
505+
&nodes_fops);
523506
}
524507

525508
#endif /* CONFIG_DEBUG_FS */

fs/ocfs2/cluster/nodemanager.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,7 @@ static int __init init_o2nm(void)
828828
{
829829
int ret = -1;
830830

831-
ret = o2hb_init();
832-
if (ret)
833-
goto out;
831+
o2hb_init();
834832

835833
ret = o2net_init();
836834
if (ret)

fs/ocfs2/cluster/tcp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,8 +2129,7 @@ int o2net_init(void)
21292129

21302130
o2quo_init();
21312131

2132-
if (o2net_debugfs_init())
2133-
goto out;
2132+
o2net_debugfs_init();
21342133

21352134
o2net_hand = kzalloc(sizeof(struct o2net_handshake), GFP_KERNEL);
21362135
o2net_keep_req = kzalloc(sizeof(struct o2net_msg), GFP_KERNEL);

fs/ocfs2/cluster/tcp.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,15 @@ struct o2net_send_tracking;
109109
struct o2net_sock_container;
110110

111111
#ifdef CONFIG_DEBUG_FS
112-
int o2net_debugfs_init(void);
112+
void o2net_debugfs_init(void);
113113
void o2net_debugfs_exit(void);
114114
void o2net_debug_add_nst(struct o2net_send_tracking *nst);
115115
void o2net_debug_del_nst(struct o2net_send_tracking *nst);
116116
void o2net_debug_add_sc(struct o2net_sock_container *sc);
117117
void o2net_debug_del_sc(struct o2net_sock_container *sc);
118118
#else
119-
static inline int o2net_debugfs_init(void)
119+
static inline void o2net_debugfs_init(void)
120120
{
121-
return 0;
122121
}
123122
static inline void o2net_debugfs_exit(void)
124123
{

0 commit comments

Comments
 (0)