| .. | .. |
|---|
| 1 | 1 | // 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: |
|---|
| 3 | 3 | * |
|---|
| 4 | 4 | * 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/>. |
|---|
| 17 | 5 | */ |
|---|
| 18 | 6 | |
|---|
| 19 | 7 | #include "debugfs.h" |
|---|
| 20 | 8 | #include "main.h" |
|---|
| 21 | 9 | |
|---|
| 10 | +#include <asm/current.h> |
|---|
| 22 | 11 | #include <linux/dcache.h> |
|---|
| 23 | 12 | #include <linux/debugfs.h> |
|---|
| 24 | | -#include <linux/err.h> |
|---|
| 25 | 13 | #include <linux/errno.h> |
|---|
| 26 | 14 | #include <linux/export.h> |
|---|
| 27 | 15 | #include <linux/fs.h> |
|---|
| 28 | 16 | #include <linux/netdevice.h> |
|---|
| 29 | 17 | #include <linux/printk.h> |
|---|
| 18 | +#include <linux/sched.h> |
|---|
| 30 | 19 | #include <linux/seq_file.h> |
|---|
| 31 | 20 | #include <linux/stat.h> |
|---|
| 32 | 21 | #include <linux/stddef.h> |
|---|
| .. | .. |
|---|
| 47 | 36 | |
|---|
| 48 | 37 | static struct dentry *batadv_debugfs; |
|---|
| 49 | 38 | |
|---|
| 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 | + |
|---|
| 50 | 53 | static int batadv_algorithms_open(struct inode *inode, struct file *file) |
|---|
| 51 | 54 | { |
|---|
| 55 | + batadv_debugfs_deprecated(file, |
|---|
| 56 | + "Use genl command BATADV_CMD_GET_ROUTING_ALGOS instead\n"); |
|---|
| 52 | 57 | return single_open(file, batadv_algo_seq_print_text, NULL); |
|---|
| 53 | 58 | } |
|---|
| 54 | 59 | |
|---|
| .. | .. |
|---|
| 56 | 61 | { |
|---|
| 57 | 62 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 58 | 63 | |
|---|
| 64 | + batadv_debugfs_deprecated(file, |
|---|
| 65 | + "Use genl command BATADV_CMD_GET_NEIGHBORS instead\n"); |
|---|
| 59 | 66 | return single_open(file, batadv_hardif_neigh_seq_print_text, net_dev); |
|---|
| 60 | 67 | } |
|---|
| 61 | 68 | |
|---|
| .. | .. |
|---|
| 63 | 70 | { |
|---|
| 64 | 71 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 65 | 72 | |
|---|
| 73 | + batadv_debugfs_deprecated(file, |
|---|
| 74 | + "Use genl command BATADV_CMD_GET_ORIGINATORS instead\n"); |
|---|
| 66 | 75 | return single_open(file, batadv_orig_seq_print_text, net_dev); |
|---|
| 67 | 76 | } |
|---|
| 68 | 77 | |
|---|
| .. | .. |
|---|
| 79 | 88 | { |
|---|
| 80 | 89 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 81 | 90 | |
|---|
| 91 | + batadv_debugfs_deprecated(file, |
|---|
| 92 | + "Use genl command BATADV_CMD_GET_HARDIFS instead\n"); |
|---|
| 82 | 93 | return single_open(file, batadv_orig_hardif_seq_print_text, net_dev); |
|---|
| 83 | 94 | } |
|---|
| 84 | 95 | |
|---|
| .. | .. |
|---|
| 86 | 97 | { |
|---|
| 87 | 98 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 88 | 99 | |
|---|
| 100 | + batadv_debugfs_deprecated(file, |
|---|
| 101 | + "Use genl command BATADV_CMD_GET_GATEWAYS instead\n"); |
|---|
| 89 | 102 | return single_open(file, batadv_gw_client_seq_print_text, net_dev); |
|---|
| 90 | 103 | } |
|---|
| 91 | 104 | |
|---|
| .. | .. |
|---|
| 93 | 106 | { |
|---|
| 94 | 107 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 95 | 108 | |
|---|
| 109 | + batadv_debugfs_deprecated(file, |
|---|
| 110 | + "Use genl command BATADV_CMD_GET_TRANSTABLE_GLOBAL instead\n"); |
|---|
| 96 | 111 | return single_open(file, batadv_tt_global_seq_print_text, net_dev); |
|---|
| 97 | 112 | } |
|---|
| 98 | 113 | |
|---|
| .. | .. |
|---|
| 101 | 116 | { |
|---|
| 102 | 117 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 103 | 118 | |
|---|
| 119 | + batadv_debugfs_deprecated(file, |
|---|
| 120 | + "Use genl command BATADV_CMD_GET_BLA_CLAIM instead\n"); |
|---|
| 104 | 121 | return single_open(file, batadv_bla_claim_table_seq_print_text, |
|---|
| 105 | 122 | net_dev); |
|---|
| 106 | 123 | } |
|---|
| .. | .. |
|---|
| 110 | 127 | { |
|---|
| 111 | 128 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 112 | 129 | |
|---|
| 130 | + batadv_debugfs_deprecated(file, |
|---|
| 131 | + "Use genl command BATADV_CMD_GET_BLA_BACKBONE instead\n"); |
|---|
| 113 | 132 | return single_open(file, batadv_bla_backbone_table_seq_print_text, |
|---|
| 114 | 133 | net_dev); |
|---|
| 115 | 134 | } |
|---|
| .. | .. |
|---|
| 128 | 147 | { |
|---|
| 129 | 148 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 130 | 149 | |
|---|
| 150 | + batadv_debugfs_deprecated(file, |
|---|
| 151 | + "Use genl command BATADV_CMD_GET_DAT_CACHE instead\n"); |
|---|
| 131 | 152 | return single_open(file, batadv_dat_cache_seq_print_text, net_dev); |
|---|
| 132 | 153 | } |
|---|
| 133 | 154 | #endif |
|---|
| .. | .. |
|---|
| 136 | 157 | { |
|---|
| 137 | 158 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 138 | 159 | |
|---|
| 160 | + batadv_debugfs_deprecated(file, |
|---|
| 161 | + "Use genl command BATADV_CMD_GET_TRANSTABLE_LOCAL instead\n"); |
|---|
| 139 | 162 | return single_open(file, batadv_tt_local_seq_print_text, net_dev); |
|---|
| 140 | 163 | } |
|---|
| 141 | 164 | |
|---|
| .. | .. |
|---|
| 149 | 172 | { |
|---|
| 150 | 173 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 151 | 174 | |
|---|
| 175 | + batadv_debugfs_deprecated(file, ""); |
|---|
| 152 | 176 | return single_open(file, batadv_nc_nodes_seq_print_text, net_dev); |
|---|
| 153 | 177 | } |
|---|
| 154 | 178 | #endif |
|---|
| .. | .. |
|---|
| 165 | 189 | { |
|---|
| 166 | 190 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
|---|
| 167 | 191 | |
|---|
| 192 | + batadv_debugfs_deprecated(file, |
|---|
| 193 | + "Use genl command BATADV_CMD_GET_MCAST_FLAGS instead\n"); |
|---|
| 168 | 194 | return single_open(file, batadv_mcast_flags_seq_print_text, net_dev); |
|---|
| 169 | 195 | } |
|---|
| 170 | 196 | #endif |
|---|
| .. | .. |
|---|
| 266 | 292 | void batadv_debugfs_init(void) |
|---|
| 267 | 293 | { |
|---|
| 268 | 294 | struct batadv_debuginfo **bat_debug; |
|---|
| 269 | | - struct dentry *file; |
|---|
| 270 | 295 | |
|---|
| 271 | 296 | batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL); |
|---|
| 272 | | - if (batadv_debugfs == ERR_PTR(-ENODEV)) |
|---|
| 273 | | - batadv_debugfs = NULL; |
|---|
| 274 | 297 | |
|---|
| 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); |
|---|
| 294 | 302 | } |
|---|
| 295 | 303 | |
|---|
| 296 | 304 | /** |
|---|
| .. | .. |
|---|
| 306 | 314 | * batadv_debugfs_add_hardif() - creates the base directory for a hard interface |
|---|
| 307 | 315 | * in debugfs. |
|---|
| 308 | 316 | * @hard_iface: hard interface which should be added. |
|---|
| 309 | | - * |
|---|
| 310 | | - * Return: 0 on success or negative error number in case of failure |
|---|
| 311 | 317 | */ |
|---|
| 312 | | -int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) |
|---|
| 318 | +void batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) |
|---|
| 313 | 319 | { |
|---|
| 314 | 320 | struct net *net = dev_net(hard_iface->net_dev); |
|---|
| 315 | 321 | struct batadv_debuginfo **bat_debug; |
|---|
| 316 | | - struct dentry *file; |
|---|
| 317 | | - |
|---|
| 318 | | - if (!batadv_debugfs) |
|---|
| 319 | | - goto out; |
|---|
| 320 | 322 | |
|---|
| 321 | 323 | if (net != &init_net) |
|---|
| 322 | | - return 0; |
|---|
| 324 | + return; |
|---|
| 323 | 325 | |
|---|
| 324 | 326 | hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, |
|---|
| 325 | 327 | batadv_debugfs); |
|---|
| 326 | | - if (!hard_iface->debug_dir) |
|---|
| 327 | | - goto out; |
|---|
| 328 | 328 | |
|---|
| 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); |
|---|
| 345 | 334 | } |
|---|
| 346 | 335 | |
|---|
| 347 | 336 | /** |
|---|
| .. | .. |
|---|
| 352 | 341 | { |
|---|
| 353 | 342 | const char *name = hard_iface->net_dev->name; |
|---|
| 354 | 343 | struct dentry *dir; |
|---|
| 355 | | - struct dentry *d; |
|---|
| 356 | 344 | |
|---|
| 357 | 345 | dir = hard_iface->debug_dir; |
|---|
| 358 | 346 | if (!dir) |
|---|
| 359 | 347 | return; |
|---|
| 360 | 348 | |
|---|
| 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); |
|---|
| 364 | 350 | } |
|---|
| 365 | 351 | |
|---|
| 366 | 352 | /** |
|---|
| .. | .. |
|---|
| 392 | 378 | struct batadv_priv *bat_priv = netdev_priv(dev); |
|---|
| 393 | 379 | struct batadv_debuginfo **bat_debug; |
|---|
| 394 | 380 | struct net *net = dev_net(dev); |
|---|
| 395 | | - struct dentry *file; |
|---|
| 396 | | - |
|---|
| 397 | | - if (!batadv_debugfs) |
|---|
| 398 | | - goto out; |
|---|
| 399 | 381 | |
|---|
| 400 | 382 | if (net != &init_net) |
|---|
| 401 | 383 | return 0; |
|---|
| 402 | 384 | |
|---|
| 403 | 385 | bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); |
|---|
| 404 | | - if (!bat_priv->debug_dir) |
|---|
| 405 | | - goto out; |
|---|
| 406 | 386 | |
|---|
| 407 | | - if (batadv_socket_setup(bat_priv) < 0) |
|---|
| 408 | | - goto rem_attr; |
|---|
| 387 | + batadv_socket_setup(bat_priv); |
|---|
| 409 | 388 | |
|---|
| 410 | 389 | if (batadv_debug_log_setup(bat_priv) < 0) |
|---|
| 411 | 390 | goto rem_attr; |
|---|
| 412 | 391 | |
|---|
| 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); |
|---|
| 424 | 397 | |
|---|
| 425 | | - if (batadv_nc_init_debugfs(bat_priv) < 0) |
|---|
| 426 | | - goto rem_attr; |
|---|
| 398 | + batadv_nc_init_debugfs(bat_priv); |
|---|
| 427 | 399 | |
|---|
| 428 | 400 | return 0; |
|---|
| 429 | 401 | rem_attr: |
|---|
| 430 | 402 | debugfs_remove_recursive(bat_priv->debug_dir); |
|---|
| 431 | 403 | bat_priv->debug_dir = NULL; |
|---|
| 432 | | -out: |
|---|
| 433 | 404 | return -ENOMEM; |
|---|
| 434 | 405 | } |
|---|
| 435 | 406 | |
|---|
| .. | .. |
|---|
| 442 | 413 | struct batadv_priv *bat_priv = netdev_priv(dev); |
|---|
| 443 | 414 | const char *name = dev->name; |
|---|
| 444 | 415 | struct dentry *dir; |
|---|
| 445 | | - struct dentry *d; |
|---|
| 446 | 416 | |
|---|
| 447 | 417 | dir = bat_priv->debug_dir; |
|---|
| 448 | 418 | if (!dir) |
|---|
| 449 | 419 | return; |
|---|
| 450 | 420 | |
|---|
| 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); |
|---|
| 454 | 422 | } |
|---|
| 455 | 423 | |
|---|
| 456 | 424 | /** |
|---|