hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/batman-adv/debugfs.c
....@@ -1,32 +1,21 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-/* Copyright (C) 2010-2018 B.A.T.M.A.N. contributors:
2
+/* Copyright (C) 2010-2020 B.A.T.M.A.N. contributors:
33 *
44 * Marek Lindner
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of version 2 of the GNU General Public
8
- * License as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful, but
11
- * WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
175 */
186
197 #include "debugfs.h"
208 #include "main.h"
219
10
+#include <asm/current.h>
2211 #include <linux/dcache.h>
2312 #include <linux/debugfs.h>
24
-#include <linux/err.h>
2513 #include <linux/errno.h>
2614 #include <linux/export.h>
2715 #include <linux/fs.h>
2816 #include <linux/netdevice.h>
2917 #include <linux/printk.h>
18
+#include <linux/sched.h>
3019 #include <linux/seq_file.h>
3120 #include <linux/stat.h>
3221 #include <linux/stddef.h>
....@@ -47,8 +36,24 @@
4736
4837 static struct dentry *batadv_debugfs;
4938
39
+/**
40
+ * batadv_debugfs_deprecated() - Log use of deprecated batadv debugfs access
41
+ * @file: file which was accessed
42
+ * @alt: explanation what can be used as alternative
43
+ */
44
+void batadv_debugfs_deprecated(struct file *file, const char *alt)
45
+{
46
+ struct dentry *dentry = file_dentry(file);
47
+ const char *name = dentry->d_name.name;
48
+
49
+ pr_warn_ratelimited(DEPRECATED "%s (pid %d) Use of debugfs file \"%s\".\n%s",
50
+ current->comm, task_pid_nr(current), name, alt);
51
+}
52
+
5053 static int batadv_algorithms_open(struct inode *inode, struct file *file)
5154 {
55
+ batadv_debugfs_deprecated(file,
56
+ "Use genl command BATADV_CMD_GET_ROUTING_ALGOS instead\n");
5257 return single_open(file, batadv_algo_seq_print_text, NULL);
5358 }
5459
....@@ -56,6 +61,8 @@
5661 {
5762 struct net_device *net_dev = (struct net_device *)inode->i_private;
5863
64
+ batadv_debugfs_deprecated(file,
65
+ "Use genl command BATADV_CMD_GET_NEIGHBORS instead\n");
5966 return single_open(file, batadv_hardif_neigh_seq_print_text, net_dev);
6067 }
6168
....@@ -63,6 +70,8 @@
6370 {
6471 struct net_device *net_dev = (struct net_device *)inode->i_private;
6572
73
+ batadv_debugfs_deprecated(file,
74
+ "Use genl command BATADV_CMD_GET_ORIGINATORS instead\n");
6675 return single_open(file, batadv_orig_seq_print_text, net_dev);
6776 }
6877
....@@ -79,6 +88,8 @@
7988 {
8089 struct net_device *net_dev = (struct net_device *)inode->i_private;
8190
91
+ batadv_debugfs_deprecated(file,
92
+ "Use genl command BATADV_CMD_GET_HARDIFS instead\n");
8293 return single_open(file, batadv_orig_hardif_seq_print_text, net_dev);
8394 }
8495
....@@ -86,6 +97,8 @@
8697 {
8798 struct net_device *net_dev = (struct net_device *)inode->i_private;
8899
100
+ batadv_debugfs_deprecated(file,
101
+ "Use genl command BATADV_CMD_GET_GATEWAYS instead\n");
89102 return single_open(file, batadv_gw_client_seq_print_text, net_dev);
90103 }
91104
....@@ -93,6 +106,8 @@
93106 {
94107 struct net_device *net_dev = (struct net_device *)inode->i_private;
95108
109
+ batadv_debugfs_deprecated(file,
110
+ "Use genl command BATADV_CMD_GET_TRANSTABLE_GLOBAL instead\n");
96111 return single_open(file, batadv_tt_global_seq_print_text, net_dev);
97112 }
98113
....@@ -101,6 +116,8 @@
101116 {
102117 struct net_device *net_dev = (struct net_device *)inode->i_private;
103118
119
+ batadv_debugfs_deprecated(file,
120
+ "Use genl command BATADV_CMD_GET_BLA_CLAIM instead\n");
104121 return single_open(file, batadv_bla_claim_table_seq_print_text,
105122 net_dev);
106123 }
....@@ -110,6 +127,8 @@
110127 {
111128 struct net_device *net_dev = (struct net_device *)inode->i_private;
112129
130
+ batadv_debugfs_deprecated(file,
131
+ "Use genl command BATADV_CMD_GET_BLA_BACKBONE instead\n");
113132 return single_open(file, batadv_bla_backbone_table_seq_print_text,
114133 net_dev);
115134 }
....@@ -128,6 +147,8 @@
128147 {
129148 struct net_device *net_dev = (struct net_device *)inode->i_private;
130149
150
+ batadv_debugfs_deprecated(file,
151
+ "Use genl command BATADV_CMD_GET_DAT_CACHE instead\n");
131152 return single_open(file, batadv_dat_cache_seq_print_text, net_dev);
132153 }
133154 #endif
....@@ -136,6 +157,8 @@
136157 {
137158 struct net_device *net_dev = (struct net_device *)inode->i_private;
138159
160
+ batadv_debugfs_deprecated(file,
161
+ "Use genl command BATADV_CMD_GET_TRANSTABLE_LOCAL instead\n");
139162 return single_open(file, batadv_tt_local_seq_print_text, net_dev);
140163 }
141164
....@@ -149,6 +172,7 @@
149172 {
150173 struct net_device *net_dev = (struct net_device *)inode->i_private;
151174
175
+ batadv_debugfs_deprecated(file, "");
152176 return single_open(file, batadv_nc_nodes_seq_print_text, net_dev);
153177 }
154178 #endif
....@@ -165,6 +189,8 @@
165189 {
166190 struct net_device *net_dev = (struct net_device *)inode->i_private;
167191
192
+ batadv_debugfs_deprecated(file,
193
+ "Use genl command BATADV_CMD_GET_MCAST_FLAGS instead\n");
168194 return single_open(file, batadv_mcast_flags_seq_print_text, net_dev);
169195 }
170196 #endif
....@@ -266,31 +292,13 @@
266292 void batadv_debugfs_init(void)
267293 {
268294 struct batadv_debuginfo **bat_debug;
269
- struct dentry *file;
270295
271296 batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
272
- if (batadv_debugfs == ERR_PTR(-ENODEV))
273
- batadv_debugfs = NULL;
274297
275
- if (!batadv_debugfs)
276
- goto err;
277
-
278
- for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) {
279
- file = debugfs_create_file(((*bat_debug)->attr).name,
280
- S_IFREG | ((*bat_debug)->attr).mode,
281
- batadv_debugfs, NULL,
282
- &(*bat_debug)->fops);
283
- if (!file) {
284
- pr_err("Can't add general debugfs file: %s\n",
285
- ((*bat_debug)->attr).name);
286
- goto err;
287
- }
288
- }
289
-
290
- return;
291
-err:
292
- debugfs_remove_recursive(batadv_debugfs);
293
- batadv_debugfs = NULL;
298
+ for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug)
299
+ debugfs_create_file(((*bat_debug)->attr).name,
300
+ S_IFREG | ((*bat_debug)->attr).mode,
301
+ batadv_debugfs, NULL, &(*bat_debug)->fops);
294302 }
295303
296304 /**
....@@ -306,42 +314,23 @@
306314 * batadv_debugfs_add_hardif() - creates the base directory for a hard interface
307315 * in debugfs.
308316 * @hard_iface: hard interface which should be added.
309
- *
310
- * Return: 0 on success or negative error number in case of failure
311317 */
312
-int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
318
+void batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
313319 {
314320 struct net *net = dev_net(hard_iface->net_dev);
315321 struct batadv_debuginfo **bat_debug;
316
- struct dentry *file;
317
-
318
- if (!batadv_debugfs)
319
- goto out;
320322
321323 if (net != &init_net)
322
- return 0;
324
+ return;
323325
324326 hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name,
325327 batadv_debugfs);
326
- if (!hard_iface->debug_dir)
327
- goto out;
328328
329
- for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug) {
330
- file = debugfs_create_file(((*bat_debug)->attr).name,
331
- S_IFREG | ((*bat_debug)->attr).mode,
332
- hard_iface->debug_dir,
333
- hard_iface->net_dev,
334
- &(*bat_debug)->fops);
335
- if (!file)
336
- goto rem_attr;
337
- }
338
-
339
- return 0;
340
-rem_attr:
341
- debugfs_remove_recursive(hard_iface->debug_dir);
342
- hard_iface->debug_dir = NULL;
343
-out:
344
- return -ENOMEM;
329
+ for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug)
330
+ debugfs_create_file(((*bat_debug)->attr).name,
331
+ S_IFREG | ((*bat_debug)->attr).mode,
332
+ hard_iface->debug_dir, hard_iface->net_dev,
333
+ &(*bat_debug)->fops);
345334 }
346335
347336 /**
....@@ -352,15 +341,12 @@
352341 {
353342 const char *name = hard_iface->net_dev->name;
354343 struct dentry *dir;
355
- struct dentry *d;
356344
357345 dir = hard_iface->debug_dir;
358346 if (!dir)
359347 return;
360348
361
- d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
362
- if (!d)
363
- pr_err("Can't rename debugfs dir to %s\n", name);
349
+ debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
364350 }
365351
366352 /**
....@@ -392,44 +378,29 @@
392378 struct batadv_priv *bat_priv = netdev_priv(dev);
393379 struct batadv_debuginfo **bat_debug;
394380 struct net *net = dev_net(dev);
395
- struct dentry *file;
396
-
397
- if (!batadv_debugfs)
398
- goto out;
399381
400382 if (net != &init_net)
401383 return 0;
402384
403385 bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
404
- if (!bat_priv->debug_dir)
405
- goto out;
406386
407
- if (batadv_socket_setup(bat_priv) < 0)
408
- goto rem_attr;
387
+ batadv_socket_setup(bat_priv);
409388
410389 if (batadv_debug_log_setup(bat_priv) < 0)
411390 goto rem_attr;
412391
413
- for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) {
414
- file = debugfs_create_file(((*bat_debug)->attr).name,
415
- S_IFREG | ((*bat_debug)->attr).mode,
416
- bat_priv->debug_dir,
417
- dev, &(*bat_debug)->fops);
418
- if (!file) {
419
- batadv_err(dev, "Can't add debugfs file: %s/%s\n",
420
- dev->name, ((*bat_debug)->attr).name);
421
- goto rem_attr;
422
- }
423
- }
392
+ for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug)
393
+ debugfs_create_file(((*bat_debug)->attr).name,
394
+ S_IFREG | ((*bat_debug)->attr).mode,
395
+ bat_priv->debug_dir, dev,
396
+ &(*bat_debug)->fops);
424397
425
- if (batadv_nc_init_debugfs(bat_priv) < 0)
426
- goto rem_attr;
398
+ batadv_nc_init_debugfs(bat_priv);
427399
428400 return 0;
429401 rem_attr:
430402 debugfs_remove_recursive(bat_priv->debug_dir);
431403 bat_priv->debug_dir = NULL;
432
-out:
433404 return -ENOMEM;
434405 }
435406
....@@ -442,15 +413,12 @@
442413 struct batadv_priv *bat_priv = netdev_priv(dev);
443414 const char *name = dev->name;
444415 struct dentry *dir;
445
- struct dentry *d;
446416
447417 dir = bat_priv->debug_dir;
448418 if (!dir)
449419 return;
450420
451
- d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
452
- if (!d)
453
- pr_err("Can't rename debugfs dir to %s\n", name);
421
+ debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
454422 }
455423
456424 /**