[v2,7/8] batman-adv: add debugfs structure for information per interface
Commit Message
From: Simon Wunderlich <simon@open-mesh.com>
To show information per interface, add a debugfs hardif structure
similar to the system in sysfs. A folder "$debugfs/batman_adv/hardif"
will be created and will contain all hard interfaces. Files are not
yet added.
Signed-off-by: Simon Wunderlich <simon@open-mesh.com>
---
debugfs.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
debugfs.h | 3 +++
hard-interface.c | 9 ++++++++
types.h | 2 ++
4 files changed, 80 insertions(+)
@@ -34,6 +34,7 @@
#include "network-coding.h"
static struct dentry *batadv_debugfs;
+static struct dentry *batadv_hardif_debugfs;
#ifdef CONFIG_BATMAN_ADV_DEBUG
#define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1)
@@ -371,6 +372,10 @@ static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
NULL,
};
+static struct batadv_debuginfo *batadv_hardif_debuginfos[] = {
+ NULL,
+};
+
void batadv_debugfs_init(void)
{
struct batadv_debuginfo **bat_debug;
@@ -383,6 +388,11 @@ void batadv_debugfs_init(void)
if (!batadv_debugfs)
goto err;
+ batadv_hardif_debugfs = debugfs_create_dir(BATADV_DEBUGFS_HARDIF_SUBDIR,
+ batadv_debugfs);
+ if (batadv_hardif_debugfs == ERR_PTR(-ENODEV))
+ goto err;
+
for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) {
file = debugfs_create_file(((*bat_debug)->attr).name,
S_IFREG | ((*bat_debug)->attr).mode,
@@ -398,12 +408,68 @@ void batadv_debugfs_init(void)
return;
err:
debugfs_remove_recursive(batadv_debugfs);
+ batadv_debugfs = NULL;
+ batadv_hardif_debugfs = NULL;
}
void batadv_debugfs_destroy(void)
{
debugfs_remove_recursive(batadv_debugfs);
batadv_debugfs = NULL;
+ batadv_hardif_debugfs = NULL;
+}
+
+/**
+ * batadv_debugfs_add_hardif - creates the base directory for a hard interface
+ * in debugfs.
+ * @hard_iface: hard interface which should be added.
+ */
+int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
+{
+ struct batadv_debuginfo **bat_debug;
+ struct dentry *file;
+
+ if (!batadv_debugfs)
+ goto out;
+
+ hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name,
+ batadv_hardif_debugfs);
+ if (!hard_iface->debug_dir)
+ goto out;
+
+ for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug) {
+ file = debugfs_create_file(((*bat_debug)->attr).name,
+ S_IFREG | ((*bat_debug)->attr).mode,
+ hard_iface->debug_dir,
+ hard_iface->net_dev,
+ &(*bat_debug)->fops);
+ if (!file)
+ goto rem_attr;
+ }
+
+ return 0;
+rem_attr:
+ debugfs_remove_recursive(hard_iface->debug_dir);
+ hard_iface->debug_dir = NULL;
+out:
+#ifdef CONFIG_DEBUG_FS
+ return -ENOMEM;
+#else
+ return 0;
+#endif /* CONFIG_DEBUG_FS */
+}
+
+/**
+ * batadv_debugfs_del_hardif - delete the base directory for a hard interface
+ * in debugfs.
+ * @hard_iface: hard interface which is deleted.
+ */
+void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface)
+{
+ if (batadv_hardif_debugfs) {
+ debugfs_remove_recursive(hard_iface->debug_dir);
+ hard_iface->debug_dir = NULL;
+ }
}
int batadv_debugfs_add_meshif(struct net_device *dev)
@@ -21,10 +21,13 @@
#define _NET_BATMAN_ADV_DEBUGFS_H_
#define BATADV_DEBUGFS_SUBDIR "batman_adv"
+#define BATADV_DEBUGFS_HARDIF_SUBDIR "hardif"
void batadv_debugfs_init(void);
void batadv_debugfs_destroy(void);
int batadv_debugfs_add_meshif(struct net_device *dev);
void batadv_debugfs_del_meshif(struct net_device *dev);
+int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface);
+void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface);
#endif /* _NET_BATMAN_ADV_DEBUGFS_H_ */
@@ -25,6 +25,7 @@
#include "translation-table.h"
#include "routing.h"
#include "sysfs.h"
+#include "debugfs.h"
#include "originator.h"
#include "hash.h"
#include "bridge_loop_avoidance.h"
@@ -541,6 +542,7 @@ static void batadv_hardif_remove_interface_finish(struct work_struct *work)
hard_iface = container_of(work, struct batadv_hard_iface,
cleanup_work);
+ batadv_debugfs_del_hardif(hard_iface);
batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
batadv_hardif_free_ref(hard_iface);
}
@@ -571,6 +573,11 @@ batadv_hardif_add_interface(struct net_device *net_dev)
hard_iface->net_dev = net_dev;
hard_iface->soft_iface = NULL;
hard_iface->if_status = BATADV_IF_NOT_IN_USE;
+
+ ret = batadv_debugfs_add_hardif(hard_iface);
+ if (ret)
+ goto free_sysfs;
+
INIT_LIST_HEAD(&hard_iface->list);
INIT_WORK(&hard_iface->cleanup_work,
batadv_hardif_remove_interface_finish);
@@ -587,6 +594,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
return hard_iface;
+free_sysfs:
+ batadv_sysfs_del_hardif(&hard_iface->hardif_obj);
free_if:
kfree(hard_iface);
release_dev:
@@ -74,6 +74,7 @@ struct batadv_hard_iface_bat_iv {
* @rcu: struct used for freeing in an RCU-safe manner
* @bat_iv: BATMAN IV specific per hard interface data
* @cleanup_work: work queue callback item for hard interface deinit
+ * @debug_dir: dentry for nc subdir in batman-adv directory in debugfs
*/
struct batadv_hard_iface {
struct list_head list;
@@ -88,6 +89,7 @@ struct batadv_hard_iface {
struct rcu_head rcu;
struct batadv_hard_iface_bat_iv bat_iv;
struct work_struct cleanup_work;
+ struct dentry *debug_dir;
};
/* struct batadv_orig_ifinfo - originator info per outgoing interface