mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-29 01:05:29 +00:00
8dc6d81c6b
As struct file_operations is really big, but (most) debugfs files only use simple_open, read, write and perhaps seek, and don't need anything else, this wastes a lot of space for NULL pointers. Add a struct debugfs_short_fops and some bookkeeping code in debugfs so that users can use that with debugfs_create_file() using _Generic to figure out which function to use. Converting mac80211 to use it where possible saves quite a bit of space: 1010127 205064 1220 1216411 128f9b net/mac80211/mac80211.ko (before) 981199 205064 1220 1187483 121e9b net/mac80211/mac80211.ko (after) ------- -28928 = ~28KiB With a marginal space cost in debugfs: 8701 550 16 9267 2433 fs/debugfs/inode.o (before) 25233 325 32 25590 63f6 fs/debugfs/file.o (before) 8914 558 16 9488 2510 fs/debugfs/inode.o (after) 25380 325 32 25737 6489 fs/debugfs/file.o (after) --------------- +360 +8 (All on x86-64) A simple spatch suggests there are more than 300 instances, not even counting the ones hidden in macros like in mac80211, that could be trivially converted, for additional savings of about 240 bytes for each. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://patch.msgid.link/20241022151838.26f9925fb959.Ia80b55e934bbfc45ce0df42a3233d34b35508046@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com>
64 lines
1.7 KiB
C
64 lines
1.7 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* internal.h - declarations internal to debugfs
|
|
*
|
|
* Copyright (C) 2016 Nicolai Stange <nicstange@gmail.com>
|
|
*/
|
|
|
|
#ifndef _DEBUGFS_INTERNAL_H_
|
|
#define _DEBUGFS_INTERNAL_H_
|
|
#include <linux/list.h>
|
|
|
|
struct file_operations;
|
|
|
|
/* declared over in file.c */
|
|
extern const struct file_operations debugfs_noop_file_operations;
|
|
extern const struct file_operations debugfs_open_proxy_file_operations;
|
|
extern const struct file_operations debugfs_full_proxy_file_operations;
|
|
|
|
struct debugfs_fsdata {
|
|
const struct file_operations *real_fops;
|
|
const struct debugfs_short_fops *short_fops;
|
|
union {
|
|
/* automount_fn is used when real_fops is NULL */
|
|
debugfs_automount_t automount;
|
|
struct {
|
|
refcount_t active_users;
|
|
struct completion active_users_drained;
|
|
|
|
/* protect cancellations */
|
|
struct mutex cancellations_mtx;
|
|
struct list_head cancellations;
|
|
};
|
|
};
|
|
};
|
|
|
|
/*
|
|
* A dentry's ->d_fsdata either points to the real fops or to a
|
|
* dynamically allocated debugfs_fsdata instance.
|
|
* In order to distinguish between these two cases, a real fops
|
|
* pointer gets its lowest bit set.
|
|
*/
|
|
#define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0)
|
|
/*
|
|
* A dentry's ->d_fsdata, when pointing to real fops, is with
|
|
* short fops instead of full fops.
|
|
*/
|
|
#define DEBUGFS_FSDATA_IS_SHORT_FOPS_BIT BIT(1)
|
|
|
|
/* Access BITS */
|
|
#define DEBUGFS_ALLOW_API BIT(0)
|
|
#define DEBUGFS_ALLOW_MOUNT BIT(1)
|
|
|
|
#ifdef CONFIG_DEBUG_FS_ALLOW_ALL
|
|
#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_MOUNT | DEBUGFS_ALLOW_API)
|
|
#endif
|
|
#ifdef CONFIG_DEBUG_FS_DISALLOW_MOUNT
|
|
#define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_API)
|
|
#endif
|
|
#ifdef CONFIG_DEBUG_FS_ALLOW_NONE
|
|
#define DEFAULT_DEBUGFS_ALLOW_BITS (0)
|
|
#endif
|
|
|
|
#endif /* _DEBUGFS_INTERNAL_H_ */
|