[PATCH 3/6] Provide per-file private data for bin sysfs files

From: Thomas Schlichter
Date: Sat Oct 17 2009 - 06:39:11 EST


For binary sysfs files, provide a per-file private field in
struct bin_buffer. Therefore this modified struct is exported in the
<linux/sysfs.h> header file. Additionally add a release() callback
that can be used to free the private data on file release.

Signed-off-by: Thomas Schlichter <thomas.schlichter@xxxxxx>
---
fs/sysfs/bin.c | 18 ++++++++----------
include/linux/sysfs.h | 14 ++++++++++++++
2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index 60c702b..3647b7a 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -36,15 +36,6 @@
*/
static DEFINE_MUTEX(sysfs_bin_lock);

-struct bin_buffer {
- struct mutex mutex;
- void *buffer;
- int mmapped;
- const struct vm_operations_struct *vm_ops;
- struct file *file;
- struct hlist_node list;
-};
-
static int
fill_read(struct dentry *dentry, char *buffer, loff_t off, size_t count)
{
@@ -438,14 +429,21 @@ static int open(struct inode * inode, struct file * file)
static int release(struct inode * inode, struct file * file)
{
struct bin_buffer *bb = file->private_data;
+ struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
+ struct bin_attribute *attr = attr_sd->s_bin_attr.bin_attr;
+ struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
+ int rc = 0;

+ if (attr->release)
+ rc = attr->release(kobj, attr, file);
+
mutex_lock(&sysfs_bin_lock);
hlist_del(&bb->list);
mutex_unlock(&sysfs_bin_lock);

kfree(bb->buffer);
kfree(bb);
- return 0;
+ return rc;
}

const struct file_operations bin_fops = {
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 9d68fed..bcad8ad 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -15,6 +15,7 @@
#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/list.h>
+#include <linux/mutex.h>
#include <asm/atomic.h>

struct kobject;
@@ -60,8 +61,19 @@ struct attribute_group {

#define attr_name(_attr) (_attr).attr.name

+struct file;
struct vm_area_struct;

+struct bin_buffer {
+ struct mutex mutex;
+ void *buffer;
+ void *private;
+ int mmapped;
+ const struct vm_operations_struct *vm_ops;
+ struct file *file;
+ struct hlist_node list;
+};
+
struct bin_attribute {
struct attribute attr;
size_t size;
@@ -72,6 +84,8 @@ struct bin_attribute {
char *, loff_t, size_t);
int (*mmap)(struct kobject *, struct bin_attribute *attr,
struct vm_area_struct *vma);
+ int (*release)(struct kobject *, struct bin_attribute *attr,
+ struct file *file);
};

struct sysfs_ops {
--
1.6.5


--Boundary-00=_U+h2K2gddSw6RDO
Content-Type: text/x-patch;
charset="iso-8859-1";
name="0004-Use-MTRR-for-pci_mmap_resource_wc-if-PAT-is-not-avai.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="0004-Use-MTRR-for-pci_mmap_resource_wc-if-PAT-is-not-avai.patch"