From 2dde7297910a2e647fc7028645f824c87e502dc9 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Fri, 23 Aug 2019 14:44:23 -0700 Subject: [PATCH] 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 --- kmod/src/sysfs.c | 11 ++++++----- kmod/src/sysfs.h | 11 ++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/kmod/src/sysfs.c b/kmod/src/sysfs.c index bea667d0..5f2f024c 100644 --- a/kmod/src/sysfs.c +++ b/kmod/src/sysfs.c @@ -131,9 +131,10 @@ void scoutfs_sysfs_init_attrs(struct super_block *sb, * If this returns success then the file will be visible and show can * be called until unmount. */ -int scoutfs_sysfs_create_attrs(struct super_block *sb, - struct scoutfs_sysfs_attrs *ssa, - struct attribute **attrs, char *fmt, ...) +int scoutfs_sysfs_create_attrs_parent(struct super_block *sb, + struct kobject *parent, + struct scoutfs_sysfs_attrs *ssa, + struct attribute **attrs, char *fmt, ...) { va_list args; size_t name_len; @@ -174,8 +175,8 @@ int scoutfs_sysfs_create_attrs(struct super_block *sb, goto out; } - ret = kobject_init_and_add(&ssa->kobj, &ssa->ktype, - scoutfs_sysfs_sb_dir(sb), "%s", ssa->name); + ret = kobject_init_and_add(&ssa->kobj, &ssa->ktype, parent, + "%s", ssa->name); out: if (ret) { kfree(ssa->name); diff --git a/kmod/src/sysfs.h b/kmod/src/sysfs.h index 861258df..2d218bba 100644 --- a/kmod/src/sysfs.h +++ b/kmod/src/sysfs.h @@ -36,9 +36,14 @@ struct scoutfs_sysfs_attrs { void scoutfs_sysfs_init_attrs(struct super_block *sb, struct scoutfs_sysfs_attrs *ssa); -int scoutfs_sysfs_create_attrs(struct super_block *sb, - struct scoutfs_sysfs_attrs *ssa, - struct attribute **attrs, char *fmt, ...); +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);