[RFC][PATCH v2 08/11] sysfs: introduce new interfacesysfs_get_kobject

From: Lin Ming
Date: Tue May 18 2010 - 13:48:53 EST


Need this interface in the later sysfs pmu lookup.

struct kobject *sysfs_get_kobject(struct file *file);
Return the relative kobject of the sysfs file.

Signed-off-by: Lin Ming <ming.m.lin@xxxxxxxxx>
---
fs/sysfs/file.c | 15 +++++++++++++++
include/linux/sysfs.h | 2 ++
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index e222b25..0c5d6fe 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -748,6 +748,21 @@ int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
}
EXPORT_SYMBOL_GPL(sysfs_schedule_callback);

+struct kobject *sysfs_get_kobject(struct file *file)
+{
+ struct sysfs_dirent *attr_sd;
+ struct kobject *kobj;
+
+ if (!file)
+ return NULL;
+ if (file->f_op != &sysfs_file_operations)
+ return NULL;
+
+ attr_sd = file->f_path.dentry->d_fsdata;
+ kobj = attr_sd->s_parent->s_dir.kobj;
+
+ return kobj;
+}

EXPORT_SYMBOL_GPL(sysfs_create_file);
EXPORT_SYMBOL_GPL(sysfs_remove_file);
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index f0496b3..5954234 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -121,6 +121,8 @@ struct sysfs_dirent;

#ifdef CONFIG_SYSFS

+struct kobject *sysfs_get_kobject(struct file *file);
+
int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
void *data, struct module *owner);





--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/