[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1382629780-10006-18-git-send-email-tj@kernel.org>
Date: Thu, 24 Oct 2013 11:49:23 -0400
From: Tejun Heo <tj@...nel.org>
To: gregkh@...uxfoundation.org
Cc: kay@...y.org, linux-kernel@...r.kernel.org, ebiederm@...ssion.com,
bhelgaas@...gle.com, Tejun Heo <tj@...nel.org>
Subject: [PATCH 17/34] sysfs, kernfs: prepare mmap path for kernfs
We're in the process of separating out core sysfs functionality into
kernfs which will deal with sysfs_dirents directly. This patch
rearranges mmap path so that the kernfs and sysfs parts are separate.
sysfs_kf_bin_mmap() which handles the interaction with bin_attribute
mmap method is factored out of sysfs_bin_mmap(), which is renamed to
kernfs_file_mmap(). All vma ops are renamed accordingly.
sysfs_bin_mmap() is updated such that it can be used for both file
types. This will eventually allow using the same file_operations for
both file types, which is necessary to separate out kernfs.
This patch doesn't introduce any behavior changes.
Signed-off-by: Tejun Heo <tj@...nel.org>
---
fs/sysfs/file.c | 70 ++++++++++++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 31 deletions(-)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 4f99da5..0fdc543 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -366,7 +366,19 @@ static loff_t kernfs_file_llseek(struct file *file, loff_t off, int whence)
return seq_lseek(file, off, whence);
}
-static void sysfs_bin_vma_open(struct vm_area_struct *vma)
+static int sysfs_kf_bin_mmap(struct sysfs_open_file *of,
+ struct vm_area_struct *vma)
+{
+ struct bin_attribute *battr = of->sd->priv;
+ struct kobject *kobj = of->sd->s_parent->priv;
+
+ if (!battr->mmap)
+ return -EINVAL; /* should be -ENODEV */
+
+ return battr->mmap(of->file, kobj, battr, vma);
+}
+
+static void kernfs_vma_open(struct vm_area_struct *vma)
{
struct file *file = vma->vm_file;
struct sysfs_open_file *of = sysfs_of(file);
@@ -383,7 +395,7 @@ static void sysfs_bin_vma_open(struct vm_area_struct *vma)
sysfs_put_active(of->sd);
}
-static int sysfs_bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+static int kernfs_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
{
struct file *file = vma->vm_file;
struct sysfs_open_file *of = sysfs_of(file);
@@ -403,8 +415,8 @@ static int sysfs_bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
return ret;
}
-static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
- struct vm_fault *vmf)
+static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
+ struct vm_fault *vmf)
{
struct file *file = vma->vm_file;
struct sysfs_open_file *of = sysfs_of(file);
@@ -426,8 +438,8 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
return ret;
}
-static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
- void *buf, int len, int write)
+static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
+ void *buf, int len, int write)
{
struct file *file = vma->vm_file;
struct sysfs_open_file *of = sysfs_of(file);
@@ -448,8 +460,8 @@ static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
}
#ifdef CONFIG_NUMA
-static int sysfs_bin_set_policy(struct vm_area_struct *vma,
- struct mempolicy *new)
+static int kernfs_vma_set_policy(struct vm_area_struct *vma,
+ struct mempolicy *new)
{
struct file *file = vma->vm_file;
struct sysfs_open_file *of = sysfs_of(file);
@@ -469,8 +481,8 @@ static int sysfs_bin_set_policy(struct vm_area_struct *vma,
return ret;
}
-static struct mempolicy *sysfs_bin_get_policy(struct vm_area_struct *vma,
- unsigned long addr)
+static struct mempolicy *kernfs_vma_get_policy(struct vm_area_struct *vma,
+ unsigned long addr)
{
struct file *file = vma->vm_file;
struct sysfs_open_file *of = sysfs_of(file);
@@ -490,8 +502,9 @@ static struct mempolicy *sysfs_bin_get_policy(struct vm_area_struct *vma,
return pol;
}
-static int sysfs_bin_migrate(struct vm_area_struct *vma, const nodemask_t *from,
- const nodemask_t *to, unsigned long flags)
+static int kernfs_vma_migrate(struct vm_area_struct *vma,
+ const nodemask_t *from, const nodemask_t *to,
+ unsigned long flags)
{
struct file *file = vma->vm_file;
struct sysfs_open_file *of = sysfs_of(file);
@@ -512,37 +525,31 @@ static int sysfs_bin_migrate(struct vm_area_struct *vma, const nodemask_t *from,
}
#endif
-static const struct vm_operations_struct sysfs_bin_vm_ops = {
- .open = sysfs_bin_vma_open,
- .fault = sysfs_bin_fault,
- .page_mkwrite = sysfs_bin_page_mkwrite,
- .access = sysfs_bin_access,
+static const struct vm_operations_struct kernfs_vm_ops = {
+ .open = kernfs_vma_open,
+ .fault = kernfs_vma_fault,
+ .page_mkwrite = kernfs_vma_page_mkwrite,
+ .access = kernfs_vma_access,
#ifdef CONFIG_NUMA
- .set_policy = sysfs_bin_set_policy,
- .get_policy = sysfs_bin_get_policy,
- .migrate = sysfs_bin_migrate,
+ .set_policy = kernfs_vma_set_policy,
+ .get_policy = kernfs_vma_get_policy,
+ .migrate = kernfs_vma_migrate,
#endif
};
-static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma)
+static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
{
struct sysfs_open_file *of = sysfs_of(file);
- struct bin_attribute *battr = of->sd->priv;
- struct kobject *kobj = of->sd->s_parent->priv;
int rc;
mutex_lock(&of->mutex);
- /* need of->sd for battr, its parent for kobj */
rc = -ENODEV;
if (!sysfs_get_active(of->sd))
goto out_unlock;
- rc = -EINVAL;
- if (!battr->mmap)
- goto out_put;
-
- rc = battr->mmap(file, kobj, battr, vma);
+ if (sysfs_is_bin(of->sd))
+ rc = sysfs_kf_bin_mmap(of, vma);
if (rc)
goto out_put;
@@ -569,7 +576,7 @@ static int sysfs_bin_mmap(struct file *file, struct vm_area_struct *vma)
rc = 0;
of->mmapped = 1;
of->vm_ops = vma->vm_ops;
- vma->vm_ops = &sysfs_bin_vm_ops;
+ vma->vm_ops = &kernfs_vm_ops;
out_put:
sysfs_put_active(of->sd);
out_unlock:
@@ -865,6 +872,7 @@ const struct file_operations sysfs_file_operations = {
.read = kernfs_file_read,
.write = kernfs_file_write,
.llseek = kernfs_file_llseek,
+ .mmap = kernfs_file_mmap,
.open = sysfs_open_file,
.release = sysfs_release,
.poll = sysfs_poll,
@@ -874,7 +882,7 @@ const struct file_operations sysfs_bin_operations = {
.read = kernfs_file_read,
.write = kernfs_file_write,
.llseek = kernfs_file_llseek,
- .mmap = sysfs_bin_mmap,
+ .mmap = kernfs_file_mmap,
.open = sysfs_open_file,
.release = sysfs_release,
.poll = sysfs_poll,
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists