Commit c6c4ccd7 authored by Taehee Yoo's avatar Taehee Yoo Committed by David S. Miller

hsr: add hsr root debugfs directory

In current hsr code, when hsr interface is created, it creates debugfs
directory /sys/kernel/debug/<interface name>.
If there is same directory or file name in there, it fails.
In order to reduce possibility of failure of creation of debugfs,
this patch adds root directory.

Test commands:
    ip link add dummy0 type dummy
    ip link add dummy1 type dummy
    ip link add hsr0 type hsr slave1 dummy0 slave2 dummy1

Before this patch:
    /sys/kernel/debug/hsr0/node_table

After this patch:
    /sys/kernel/debug/hsr/hsr0/node_table
Signed-off-by: default avatarTaehee Yoo <ap420073@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1d19e2d5
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "hsr_main.h" #include "hsr_main.h"
#include "hsr_framereg.h" #include "hsr_framereg.h"
static struct dentry *hsr_debugfs_root_dir;
static void print_mac_address(struct seq_file *sfp, unsigned char *mac) static void print_mac_address(struct seq_file *sfp, unsigned char *mac)
{ {
seq_printf(sfp, "%02x:%02x:%02x:%02x:%02x:%02x:", seq_printf(sfp, "%02x:%02x:%02x:%02x:%02x:%02x:",
...@@ -81,9 +83,9 @@ void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev) ...@@ -81,9 +83,9 @@ void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
{ {
struct dentry *de = NULL; struct dentry *de = NULL;
de = debugfs_create_dir(hsr_dev->name, NULL); de = debugfs_create_dir(hsr_dev->name, hsr_debugfs_root_dir);
if (IS_ERR(de)) { if (IS_ERR(de)) {
pr_err("Cannot create hsr debugfs root\n"); pr_err("Cannot create hsr debugfs directory\n");
return; return;
} }
...@@ -93,7 +95,7 @@ void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev) ...@@ -93,7 +95,7 @@ void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev)
priv->node_tbl_root, priv, priv->node_tbl_root, priv,
&hsr_fops); &hsr_fops);
if (IS_ERR(de)) { if (IS_ERR(de)) {
pr_err("Cannot create hsr node_table directory\n"); pr_err("Cannot create hsr node_table file\n");
debugfs_remove(priv->node_tbl_root); debugfs_remove(priv->node_tbl_root);
priv->node_tbl_root = NULL; priv->node_tbl_root = NULL;
return; return;
...@@ -115,3 +117,18 @@ hsr_debugfs_term(struct hsr_priv *priv) ...@@ -115,3 +117,18 @@ hsr_debugfs_term(struct hsr_priv *priv)
debugfs_remove(priv->node_tbl_root); debugfs_remove(priv->node_tbl_root);
priv->node_tbl_root = NULL; priv->node_tbl_root = NULL;
} }
void hsr_debugfs_create_root(void)
{
hsr_debugfs_root_dir = debugfs_create_dir("hsr", NULL);
if (IS_ERR(hsr_debugfs_root_dir)) {
pr_err("Cannot create hsr debugfs root directory\n");
hsr_debugfs_root_dir = NULL;
}
}
void hsr_debugfs_remove_root(void)
{
/* debugfs_remove() internally checks NULL and ERROR */
debugfs_remove(hsr_debugfs_root_dir);
}
...@@ -123,6 +123,7 @@ static void __exit hsr_exit(void) ...@@ -123,6 +123,7 @@ static void __exit hsr_exit(void)
{ {
unregister_netdevice_notifier(&hsr_nb); unregister_netdevice_notifier(&hsr_nb);
hsr_netlink_exit(); hsr_netlink_exit();
hsr_debugfs_remove_root();
} }
module_init(hsr_init); module_init(hsr_init);
......
...@@ -186,12 +186,18 @@ static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb) ...@@ -186,12 +186,18 @@ static inline u16 hsr_get_skb_sequence_nr(struct sk_buff *skb)
#if IS_ENABLED(CONFIG_DEBUG_FS) #if IS_ENABLED(CONFIG_DEBUG_FS)
void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev); void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev);
void hsr_debugfs_term(struct hsr_priv *priv); void hsr_debugfs_term(struct hsr_priv *priv);
void hsr_debugfs_create_root(void);
void hsr_debugfs_remove_root(void);
#else #else
static inline void hsr_debugfs_init(struct hsr_priv *priv, static inline void hsr_debugfs_init(struct hsr_priv *priv,
struct net_device *hsr_dev) struct net_device *hsr_dev)
{} {}
static inline void hsr_debugfs_term(struct hsr_priv *priv) static inline void hsr_debugfs_term(struct hsr_priv *priv)
{} {}
static inline void hsr_debugfs_create_root(void)
{}
static inline void hsr_debugfs_remove_root(void)
{}
#endif #endif
#endif /* __HSR_PRIVATE_H */ #endif /* __HSR_PRIVATE_H */
...@@ -476,6 +476,7 @@ int __init hsr_netlink_init(void) ...@@ -476,6 +476,7 @@ int __init hsr_netlink_init(void)
if (rc) if (rc)
goto fail_genl_register_family; goto fail_genl_register_family;
hsr_debugfs_create_root();
return 0; return 0;
fail_genl_register_family: fail_genl_register_family:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment