Files
scoutfs/kmod/src/sysfs.h
Zach Brown 2dde729791 Add sysfs create attr w/ parent
Add sysfs attribute creation that can provide the parent dir kobject
instead of always creating the sysfs object dir off of the main
per-mount dir.

Signed-off-by: Zach Brown <zab@versity.com>
2021-05-26 14:18:19 -07:00

59 lines
1.7 KiB
C

#ifndef _SCOUTFS_SYSFS_H_
#define _SCOUTFS_SYSFS_H_
#include <linux/kobject.h>
/*
* We have some light wrappers around sysfs attributes to make it safe
* to tear down the attributes before freeing the data they describe.
*/
#define SCOUTFS_ATTR_RO(_name) \
static struct kobj_attribute scoutfs_attr_##_name = __ATTR_RO(_name)
#define SCOUTFS_ATTR_RW(_name) \
static struct kobj_attribute scoutfs_attr_##_name = __ATTR_RW(_name)
#define SCOUTFS_ATTR_PTR(_name) \
&scoutfs_attr_##_name.attr
struct scoutfs_sysfs_attrs {
struct super_block *sb;
char *name;
struct completion comp;
struct kobject kobj;
struct kobj_type ktype;
};
#define SCOUTFS_SYSFS_ATTRS(kobj) \
container_of(kobj, struct scoutfs_sysfs_attrs, kobj)
#define SCOUTFS_SYSFS_ATTRS_SB(kobj) \
(SCOUTFS_SYSFS_ATTRS(kobj)->sb)
#define DECLARE_SCOUTFS_SYSFS_ATTRS(name, kobj) \
struct scoutfs_sysfs_attrs *ssa = SCOUTFS_SYSFS_ATTRS(kobj)
void scoutfs_sysfs_init_attrs(struct super_block *sb,
struct scoutfs_sysfs_attrs *ssa);
int scoutfs_sysfs_create_attrs_parent(struct super_block *sb,
struct kobject *parent,
struct scoutfs_sysfs_attrs *ssa,
struct attribute **attrs, char *fmt, ...);
#define scoutfs_sysfs_create_attrs(sb, ssa, attrs, fmt, args...) \
scoutfs_sysfs_create_attrs_parent(sb, scoutfs_sysfs_sb_dir(sb), \
ssa, attrs, fmt, ##args)
void scoutfs_sysfs_destroy_attrs(struct super_block *sb,
struct scoutfs_sysfs_attrs *ssa);
struct kobject *scoutfs_sysfs_sb_dir(struct super_block *sb);
int scoutfs_setup_sysfs(struct super_block *sb);
void scoutfs_destroy_sysfs(struct super_block *sb);
int __init scoutfs_sysfs_init(void);
void __exit scoutfs_sysfs_exit(void);
#endif