blob: bd032bc4e262d19db92a8a359a092af2726af400 [file] [log] [blame]
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001/* Copyright (C) 2010-2012 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00002 *
3 * Marek Lindner
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000018 */
19
20#include "main.h"
21
22#include <linux/debugfs.h>
23
Sven Eckelmannb706b132012-06-10 23:58:51 +020024#include "debugfs.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000025#include "translation-table.h"
26#include "originator.h"
27#include "hard-interface.h"
28#include "gateway_common.h"
29#include "gateway_client.h"
30#include "soft-interface.h"
31#include "vis.h"
32#include "icmp_socket.h"
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +010033#include "bridge_loop_avoidance.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000034
Sven Eckelmann9e466252012-05-12 18:33:50 +020035static struct dentry *batadv_debugfs;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000036
37#ifdef CONFIG_BATMAN_ADV_DEBUG
Sven Eckelmann347c80f2012-06-03 22:19:07 +020038#define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000039
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020040static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN;
41
42static char *batadv_log_char_addr(struct batadv_debug_log *debug_log,
43 size_t idx)
44{
45 return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK];
46}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000047
Sven Eckelmann56303d32012-06-05 22:31:31 +020048static void batadv_emit_log_char(struct batadv_debug_log *debug_log, char c)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000049{
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020050 char *char_addr;
51
52 char_addr = batadv_log_char_addr(debug_log, debug_log->log_end);
53 *char_addr = c;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000054 debug_log->log_end++;
55
Sven Eckelmann9e466252012-05-12 18:33:50 +020056 if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len)
57 debug_log->log_start = debug_log->log_end - batadv_log_buff_len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000058}
59
Sven Eckelmannd3a547b2011-05-14 23:14:46 +020060__printf(2, 3)
Sven Eckelmann56303d32012-06-05 22:31:31 +020061static int batadv_fdebug_log(struct batadv_debug_log *debug_log,
62 const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000063{
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000064 va_list args;
65 static char debug_log_buf[256];
66 char *p;
67
68 if (!debug_log)
69 return 0;
70
71 spin_lock_bh(&debug_log->lock);
72 va_start(args, fmt);
Sven Eckelmann1299bda2011-01-27 13:48:54 +010073 vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000074 va_end(args);
75
76 for (p = debug_log_buf; *p != 0; p++)
Sven Eckelmann9e466252012-05-12 18:33:50 +020077 batadv_emit_log_char(debug_log, *p);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000078
79 spin_unlock_bh(&debug_log->lock);
80
81 wake_up(&debug_log->queue_wait);
82
83 return 0;
84}
85
Sven Eckelmann56303d32012-06-05 22:31:31 +020086int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000087{
88 va_list args;
89 char tmp_log_buf[256];
90
91 va_start(args, fmt);
92 vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
Sven Eckelmann9e466252012-05-12 18:33:50 +020093 batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s",
94 jiffies_to_msecs(jiffies), tmp_log_buf);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000095 va_end(args);
96
97 return 0;
98}
99
Sven Eckelmann9e466252012-05-12 18:33:50 +0200100static int batadv_log_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000101{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200102 if (!try_module_get(THIS_MODULE))
103 return -EBUSY;
104
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000105 nonseekable_open(inode, file);
106 file->private_data = inode->i_private;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000107 return 0;
108}
109
Sven Eckelmann9e466252012-05-12 18:33:50 +0200110static int batadv_log_release(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000111{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200112 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000113 return 0;
114}
115
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200116static int batadv_log_empty(struct batadv_debug_log *debug_log)
117{
118 return !(debug_log->log_start - debug_log->log_end);
119}
120
Sven Eckelmann9e466252012-05-12 18:33:50 +0200121static ssize_t batadv_log_read(struct file *file, char __user *buf,
122 size_t count, loff_t *ppos)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000123{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200124 struct batadv_priv *bat_priv = file->private_data;
125 struct batadv_debug_log *debug_log = bat_priv->debug_log;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000126 int error, i = 0;
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200127 char *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000128 char c;
129
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200130 if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000131 return -EAGAIN;
132
Sven Eckelmann16f14b42011-05-14 23:14:48 +0200133 if (!buf)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000134 return -EINVAL;
135
136 if (count == 0)
137 return 0;
138
139 if (!access_ok(VERIFY_WRITE, buf, count))
140 return -EFAULT;
141
142 error = wait_event_interruptible(debug_log->queue_wait,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200143 (!batadv_log_empty(debug_log)));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000144
145 if (error)
146 return error;
147
148 spin_lock_bh(&debug_log->lock);
149
150 while ((!error) && (i < count) &&
151 (debug_log->log_start != debug_log->log_end)) {
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200152 char_addr = batadv_log_char_addr(debug_log,
153 debug_log->log_start);
154 c = *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000155
156 debug_log->log_start++;
157
158 spin_unlock_bh(&debug_log->lock);
159
160 error = __put_user(c, buf);
161
162 spin_lock_bh(&debug_log->lock);
163
164 buf++;
165 i++;
166
167 }
168
169 spin_unlock_bh(&debug_log->lock);
170
171 if (!error)
172 return i;
173
174 return error;
175}
176
Sven Eckelmann9e466252012-05-12 18:33:50 +0200177static unsigned int batadv_log_poll(struct file *file, poll_table *wait)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000178{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200179 struct batadv_priv *bat_priv = file->private_data;
180 struct batadv_debug_log *debug_log = bat_priv->debug_log;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000181
182 poll_wait(file, &debug_log->queue_wait, wait);
183
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200184 if (!batadv_log_empty(debug_log))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000185 return POLLIN | POLLRDNORM;
186
187 return 0;
188}
189
Sven Eckelmann9e466252012-05-12 18:33:50 +0200190static const struct file_operations batadv_log_fops = {
191 .open = batadv_log_open,
192 .release = batadv_log_release,
193 .read = batadv_log_read,
194 .poll = batadv_log_poll,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000195 .llseek = no_llseek,
196};
197
Sven Eckelmann56303d32012-06-05 22:31:31 +0200198static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000199{
200 struct dentry *d;
201
202 if (!bat_priv->debug_dir)
203 goto err;
204
Sven Eckelmann704509b2011-05-14 23:14:54 +0200205 bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000206 if (!bat_priv->debug_log)
207 goto err;
208
209 spin_lock_init(&bat_priv->debug_log->lock);
210 init_waitqueue_head(&bat_priv->debug_log->queue_wait);
211
212 d = debugfs_create_file("log", S_IFREG | S_IRUSR,
Sven Eckelmann9e466252012-05-12 18:33:50 +0200213 bat_priv->debug_dir, bat_priv,
214 &batadv_log_fops);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200215 if (!d)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000216 goto err;
217
218 return 0;
219
220err:
Sven Eckelmann5346c352012-05-05 13:27:28 +0200221 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000222}
223
Sven Eckelmann56303d32012-06-05 22:31:31 +0200224static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000225{
226 kfree(bat_priv->debug_log);
227 bat_priv->debug_log = NULL;
228}
229#else /* CONFIG_BATMAN_ADV_DEBUG */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200230static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000231{
232 bat_priv->debug_log = NULL;
233 return 0;
234}
235
Sven Eckelmann56303d32012-06-05 22:31:31 +0200236static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000237{
238 return;
239}
240#endif
241
Sven Eckelmann9e466252012-05-12 18:33:50 +0200242static int batadv_algorithms_open(struct inode *inode, struct file *file)
Marek Lindner1c280472011-11-28 17:40:17 +0800243{
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200244 return single_open(file, batadv_algo_seq_print_text, NULL);
Marek Lindner1c280472011-11-28 17:40:17 +0800245}
246
Sven Eckelmann9e466252012-05-12 18:33:50 +0200247static int batadv_originators_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000248{
249 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200250 return single_open(file, batadv_orig_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000251}
252
Sven Eckelmann9e466252012-05-12 18:33:50 +0200253static int batadv_gateways_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000254{
255 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann7cf06bc2012-05-12 02:09:29 +0200256 return single_open(file, batadv_gw_client_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000257}
258
Sven Eckelmann9e466252012-05-12 18:33:50 +0200259static int batadv_transtable_global_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000260{
261 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200262 return single_open(file, batadv_tt_global_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000263}
264
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100265#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200266static int batadv_bla_claim_table_open(struct inode *inode, struct file *file)
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100267{
268 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08adf152012-05-12 13:38:47 +0200269 return single_open(file, batadv_bla_claim_table_seq_print_text,
270 net_dev);
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100271}
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200272
273static int batadv_bla_backbone_table_open(struct inode *inode,
274 struct file *file)
275{
276 struct net_device *net_dev = (struct net_device *)inode->i_private;
277 return single_open(file, batadv_bla_backbone_table_seq_print_text,
278 net_dev);
279}
280
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100281#endif
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100282
Sven Eckelmann9e466252012-05-12 18:33:50 +0200283static int batadv_transtable_local_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000284{
285 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200286 return single_open(file, batadv_tt_local_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000287}
288
Sven Eckelmann9e466252012-05-12 18:33:50 +0200289static int batadv_vis_data_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000290{
291 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmannd0f714f2012-05-12 02:09:41 +0200292 return single_open(file, batadv_vis_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000293}
294
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200295struct batadv_debuginfo {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000296 struct attribute attr;
297 const struct file_operations fops;
298};
299
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200300#define BATADV_DEBUGINFO(_name, _mode, _open) \
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200301struct batadv_debuginfo batadv_debuginfo_##_name = { \
Sven Eckelmann9e466252012-05-12 18:33:50 +0200302 .attr = { .name = __stringify(_name), \
303 .mode = _mode, }, \
304 .fops = { .owner = THIS_MODULE, \
305 .open = _open, \
306 .read = seq_read, \
307 .llseek = seq_lseek, \
308 .release = single_release, \
309 } \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000310};
311
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200312static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open);
313static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open);
314static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open);
315static BATADV_DEBUGINFO(transtable_global, S_IRUGO,
316 batadv_transtable_global_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100317#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200318static BATADV_DEBUGINFO(bla_claim_table, S_IRUGO, batadv_bla_claim_table_open);
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200319static BATADV_DEBUGINFO(bla_backbone_table, S_IRUGO,
320 batadv_bla_backbone_table_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100321#endif
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200322static BATADV_DEBUGINFO(transtable_local, S_IRUGO,
323 batadv_transtable_local_open);
324static BATADV_DEBUGINFO(vis_data, S_IRUGO, batadv_vis_data_open);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000325
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200326static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
Sven Eckelmann9e466252012-05-12 18:33:50 +0200327 &batadv_debuginfo_originators,
328 &batadv_debuginfo_gateways,
329 &batadv_debuginfo_transtable_global,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100330#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200331 &batadv_debuginfo_bla_claim_table,
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200332 &batadv_debuginfo_bla_backbone_table,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100333#endif
Sven Eckelmann9e466252012-05-12 18:33:50 +0200334 &batadv_debuginfo_transtable_local,
335 &batadv_debuginfo_vis_data,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000336 NULL,
337};
338
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200339void batadv_debugfs_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000340{
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200341 struct batadv_debuginfo *bat_debug;
Marek Lindner1c280472011-11-28 17:40:17 +0800342 struct dentry *file;
343
Sven Eckelmann54590e42012-06-03 22:19:08 +0200344 batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
Sven Eckelmann9e466252012-05-12 18:33:50 +0200345 if (batadv_debugfs == ERR_PTR(-ENODEV))
346 batadv_debugfs = NULL;
Marek Lindner1c280472011-11-28 17:40:17 +0800347
Sven Eckelmann9e466252012-05-12 18:33:50 +0200348 if (!batadv_debugfs)
Marek Lindner1c280472011-11-28 17:40:17 +0800349 goto out;
350
Sven Eckelmann9e466252012-05-12 18:33:50 +0200351 bat_debug = &batadv_debuginfo_routing_algos;
Marek Lindner1c280472011-11-28 17:40:17 +0800352 file = debugfs_create_file(bat_debug->attr.name,
353 S_IFREG | bat_debug->attr.mode,
Sven Eckelmann9e466252012-05-12 18:33:50 +0200354 batadv_debugfs, NULL, &bat_debug->fops);
Marek Lindner1c280472011-11-28 17:40:17 +0800355 if (!file)
356 pr_err("Can't add debugfs file: %s\n", bat_debug->attr.name);
357
358out:
359 return;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000360}
361
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200362void batadv_debugfs_destroy(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000363{
Sven Eckelmann9e466252012-05-12 18:33:50 +0200364 if (batadv_debugfs) {
365 debugfs_remove_recursive(batadv_debugfs);
366 batadv_debugfs = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000367 }
368}
369
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200370int batadv_debugfs_add_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000371{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200372 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200373 struct batadv_debuginfo **bat_debug;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000374 struct dentry *file;
375
Sven Eckelmann9e466252012-05-12 18:33:50 +0200376 if (!batadv_debugfs)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000377 goto out;
378
Sven Eckelmann9e466252012-05-12 18:33:50 +0200379 bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000380 if (!bat_priv->debug_dir)
381 goto out;
382
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200383 if (batadv_socket_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200384 goto rem_attr;
385
Sven Eckelmann9e466252012-05-12 18:33:50 +0200386 if (batadv_debug_log_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200387 goto rem_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000388
Sven Eckelmann9e466252012-05-12 18:33:50 +0200389 for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000390 file = debugfs_create_file(((*bat_debug)->attr).name,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200391 S_IFREG | ((*bat_debug)->attr).mode,
392 bat_priv->debug_dir,
393 dev, &(*bat_debug)->fops);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000394 if (!file) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200395 batadv_err(dev, "Can't add debugfs file: %s/%s\n",
396 dev->name, ((*bat_debug)->attr).name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000397 goto rem_attr;
398 }
399 }
400
401 return 0;
402rem_attr:
403 debugfs_remove_recursive(bat_priv->debug_dir);
404 bat_priv->debug_dir = NULL;
405out:
406#ifdef CONFIG_DEBUG_FS
407 return -ENOMEM;
408#else
409 return 0;
410#endif /* CONFIG_DEBUG_FS */
411}
412
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200413void batadv_debugfs_del_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000414{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200415 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000416
Sven Eckelmann9e466252012-05-12 18:33:50 +0200417 batadv_debug_log_cleanup(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000418
Sven Eckelmann9e466252012-05-12 18:33:50 +0200419 if (batadv_debugfs) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000420 debugfs_remove_recursive(bat_priv->debug_dir);
421 bat_priv->debug_dir = NULL;
422 }
423}