kernfs: s/sysfs/kernfs/ in constants
[platform/adaptation/renesas_rcar/renesas_kernel.git] / fs / kernfs / file.c
index 1bf07de..abe93e1 100644 (file)
 #include "kernfs-internal.h"
 
 /*
- * There's one sysfs_open_file for each open file and one sysfs_open_dirent
+ * There's one kernfs_open_file for each open file and one kernfs_open_node
  * for each kernfs_node with one or more open files.
  *
- * kernfs_node->s_attr.open points to sysfs_open_dirent.  s_attr.open is
- * protected by sysfs_open_dirent_lock.
+ * kernfs_node->attr.open points to kernfs_open_node.  attr.open is
+ * protected by kernfs_open_node_lock.
  *
  * filp->private_data points to seq_file whose ->private points to
- * sysfs_open_file.  sysfs_open_files are chained at
- * sysfs_open_dirent->files, which is protected by sysfs_open_file_mutex.
+ * kernfs_open_file.  kernfs_open_files are chained at
+ * kernfs_open_node->files, which is protected by kernfs_open_file_mutex.
  */
-static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
-static DEFINE_MUTEX(sysfs_open_file_mutex);
+static DEFINE_SPINLOCK(kernfs_open_node_lock);
+static DEFINE_MUTEX(kernfs_open_file_mutex);
 
-struct sysfs_open_dirent {
+struct kernfs_open_node {
        atomic_t                refcnt;
        atomic_t                event;
        wait_queue_head_t       poll;
-       struct list_head        files; /* goes through sysfs_open_file.list */
+       struct list_head        files; /* goes through kernfs_open_file.list */
 };
 
-static struct sysfs_open_file *sysfs_of(struct file *file)
+static struct kernfs_open_file *kernfs_of(struct file *file)
 {
        return ((struct seq_file *)file->private_data)->private;
 }
@@ -49,14 +49,14 @@ static struct sysfs_open_file *sysfs_of(struct file *file)
  */
 static const struct kernfs_ops *kernfs_ops(struct kernfs_node *kn)
 {
-       if (kn->s_flags & SYSFS_FLAG_LOCKDEP)
+       if (kn->flags & KERNFS_LOCKDEP)
                lockdep_assert_held(kn);
-       return kn->s_attr.ops;
+       return kn->attr.ops;
 }
 
 static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
 {
-       struct sysfs_open_file *of = sf->private;
+       struct kernfs_open_file *of = sf->private;
        const struct kernfs_ops *ops;
 
        /*
@@ -81,7 +81,7 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
 
 static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
 {
-       struct sysfs_open_file *of = sf->private;
+       struct kernfs_open_file *of = sf->private;
        const struct kernfs_ops *ops = kernfs_ops(of->kn);
 
        if (ops->seq_next) {
@@ -98,7 +98,7 @@ static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
 
 static void kernfs_seq_stop(struct seq_file *sf, void *v)
 {
-       struct sysfs_open_file *of = sf->private;
+       struct kernfs_open_file *of = sf->private;
        const struct kernfs_ops *ops = kernfs_ops(of->kn);
 
        if (ops->seq_stop)
@@ -110,11 +110,11 @@ static void kernfs_seq_stop(struct seq_file *sf, void *v)
 
 static int kernfs_seq_show(struct seq_file *sf, void *v)
 {
-       struct sysfs_open_file *of = sf->private;
+       struct kernfs_open_file *of = sf->private;
 
-       of->event = atomic_read(&of->kn->s_attr.open->event);
+       of->event = atomic_read(&of->kn->attr.open->event);
 
-       return of->kn->s_attr.ops->seq_show(sf, v);
+       return of->kn->attr.ops->seq_show(sf, v);
 }
 
 static const struct seq_operations kernfs_seq_ops = {
@@ -130,7 +130,7 @@ static const struct seq_operations kernfs_seq_ops = {
  * it difficult to use seq_file.  Implement simplistic custom buffering for
  * bin files.
  */
-static ssize_t kernfs_file_direct_read(struct sysfs_open_file *of,
+static ssize_t kernfs_file_direct_read(struct kernfs_open_file *of,
                                       char __user *user_buf, size_t count,
                                       loff_t *ppos)
 {
@@ -187,9 +187,9 @@ static ssize_t kernfs_file_direct_read(struct sysfs_open_file *of,
 static ssize_t kernfs_file_read(struct file *file, char __user *user_buf,
                                size_t count, loff_t *ppos)
 {
-       struct sysfs_open_file *of = sysfs_of(file);
+       struct kernfs_open_file *of = kernfs_of(file);
 
-       if (of->kn->s_flags & SYSFS_FLAG_HAS_SEQ_SHOW)
+       if (of->kn->flags & KERNFS_HAS_SEQ_SHOW)
                return seq_read(file, user_buf, count, ppos);
        else
                return kernfs_file_direct_read(of, user_buf, count, ppos);
@@ -214,7 +214,7 @@ static ssize_t kernfs_file_read(struct file *file, char __user *user_buf,
 static ssize_t kernfs_file_write(struct file *file, const char __user *user_buf,
                                 size_t count, loff_t *ppos)
 {
-       struct sysfs_open_file *of = sysfs_of(file);
+       struct kernfs_open_file *of = kernfs_of(file);
        ssize_t len = min_t(size_t, count, PAGE_SIZE);
        const struct kernfs_ops *ops;
        char *buf;
@@ -259,7 +259,7 @@ out_free:
 static void kernfs_vma_open(struct vm_area_struct *vma)
 {
        struct file *file = vma->vm_file;
-       struct sysfs_open_file *of = sysfs_of(file);
+       struct kernfs_open_file *of = kernfs_of(file);
 
        if (!of->vm_ops)
                return;
@@ -276,7 +276,7 @@ static void kernfs_vma_open(struct vm_area_struct *vma)
 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);
+       struct kernfs_open_file *of = kernfs_of(file);
        int ret;
 
        if (!of->vm_ops)
@@ -297,7 +297,7 @@ 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);
+       struct kernfs_open_file *of = kernfs_of(file);
        int ret;
 
        if (!of->vm_ops)
@@ -320,7 +320,7 @@ 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);
+       struct kernfs_open_file *of = kernfs_of(file);
        int ret;
 
        if (!of->vm_ops)
@@ -342,7 +342,7 @@ 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);
+       struct kernfs_open_file *of = kernfs_of(file);
        int ret;
 
        if (!of->vm_ops)
@@ -363,7 +363,7 @@ 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);
+       struct kernfs_open_file *of = kernfs_of(file);
        struct mempolicy *pol;
 
        if (!of->vm_ops)
@@ -385,7 +385,7 @@ static int kernfs_vma_migrate(struct vm_area_struct *vma,
                              unsigned long flags)
 {
        struct file *file = vma->vm_file;
-       struct sysfs_open_file *of = sysfs_of(file);
+       struct kernfs_open_file *of = kernfs_of(file);
        int ret;
 
        if (!of->vm_ops)
@@ -417,7 +417,7 @@ static const struct vm_operations_struct kernfs_vm_ops = {
 
 static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
 {
-       struct sysfs_open_file *of = sysfs_of(file);
+       struct kernfs_open_file *of = kernfs_of(file);
        const struct kernfs_ops *ops;
        int rc;
 
@@ -428,7 +428,7 @@ static int kernfs_file_mmap(struct file *file, struct vm_area_struct *vma)
         * without grabbing @of->mutex by testing HAS_MMAP flag.  See the
         * comment in kernfs_file_open() for more details.
         */
-       if (!(of->kn->s_flags & SYSFS_FLAG_HAS_MMAP))
+       if (!(of->kn->flags & KERNFS_HAS_MMAP))
                return -ENODEV;
 
        mutex_lock(&of->mutex);
@@ -473,12 +473,12 @@ out_unlock:
 }
 
 /**
- *     sysfs_get_open_dirent - get or create sysfs_open_dirent
+ *     sysfs_get_open_dirent - get or create kernfs_open_node
  *     @kn: target kernfs_node
- *     @of: sysfs_open_file for this instance of open
+ *     @of: kernfs_open_file for this instance of open
  *
- *     If @kn->s_attr.open exists, increment its reference count;
- *     otherwise, create one.  @of is chained to the files list.
+ *     If @kn->attr.open exists, increment its reference count; otherwise,
+ *     create one.  @of is chained to the files list.
  *
  *     LOCKING:
  *     Kernel thread context (may sleep).
@@ -487,84 +487,84 @@ out_unlock:
  *     0 on success, -errno on failure.
  */
 static int sysfs_get_open_dirent(struct kernfs_node *kn,
-                                struct sysfs_open_file *of)
+                                struct kernfs_open_file *of)
 {
-       struct sysfs_open_dirent *od, *new_od = NULL;
+       struct kernfs_open_node *on, *new_on = NULL;
 
  retry:
-       mutex_lock(&sysfs_open_file_mutex);
-       spin_lock_irq(&sysfs_open_dirent_lock);
+       mutex_lock(&kernfs_open_file_mutex);
+       spin_lock_irq(&kernfs_open_node_lock);
 
-       if (!kn->s_attr.open && new_od) {
-               kn->s_attr.open = new_od;
-               new_od = NULL;
+       if (!kn->attr.open && new_on) {
+               kn->attr.open = new_on;
+               new_on = NULL;
        }
 
-       od = kn->s_attr.open;
-       if (od) {
-               atomic_inc(&od->refcnt);
-               list_add_tail(&of->list, &od->files);
+       on = kn->attr.open;
+       if (on) {
+               atomic_inc(&on->refcnt);
+               list_add_tail(&of->list, &on->files);
        }
 
-       spin_unlock_irq(&sysfs_open_dirent_lock);
-       mutex_unlock(&sysfs_open_file_mutex);
+       spin_unlock_irq(&kernfs_open_node_lock);
+       mutex_unlock(&kernfs_open_file_mutex);
 
-       if (od) {
-               kfree(new_od);
+       if (on) {
+               kfree(new_on);
                return 0;
        }
 
        /* not there, initialize a new one and retry */
-       new_od = kmalloc(sizeof(*new_od), GFP_KERNEL);
-       if (!new_od)
+       new_on = kmalloc(sizeof(*new_on), GFP_KERNEL);
+       if (!new_on)
                return -ENOMEM;
 
-       atomic_set(&new_od->refcnt, 0);
-       atomic_set(&new_od->event, 1);
-       init_waitqueue_head(&new_od->poll);
-       INIT_LIST_HEAD(&new_od->files);
+       atomic_set(&new_on->refcnt, 0);
+       atomic_set(&new_on->event, 1);
+       init_waitqueue_head(&new_on->poll);
+       INIT_LIST_HEAD(&new_on->files);
        goto retry;
 }
 
 /**
- *     sysfs_put_open_dirent - put sysfs_open_dirent
+ *     sysfs_put_open_dirent - put kernfs_open_node
  *     @kn: target kernfs_nodet
- *     @of: associated sysfs_open_file
+ *     @of: associated kernfs_open_file
  *
- *     Put @kn->s_attr.open and unlink @of from the files list.  If
+ *     Put @kn->attr.open and unlink @of from the files list.  If
  *     reference count reaches zero, disassociate and free it.
  *
  *     LOCKING:
  *     None.
  */
 static void sysfs_put_open_dirent(struct kernfs_node *kn,
-                                 struct sysfs_open_file *of)
+                                 struct kernfs_open_file *of)
 {
-       struct sysfs_open_dirent *od = kn->s_attr.open;
+       struct kernfs_open_node *on = kn->attr.open;
        unsigned long flags;
 
-       mutex_lock(&sysfs_open_file_mutex);
-       spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
+       mutex_lock(&kernfs_open_file_mutex);
+       spin_lock_irqsave(&kernfs_open_node_lock, flags);
 
        if (of)
                list_del(&of->list);
 
-       if (atomic_dec_and_test(&od->refcnt))
-               kn->s_attr.open = NULL;
+       if (atomic_dec_and_test(&on->refcnt))
+               kn->attr.open = NULL;
        else
-               od = NULL;
+               on = NULL;
 
-       spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
-       mutex_unlock(&sysfs_open_file_mutex);
+       spin_unlock_irqrestore(&kernfs_open_node_lock, flags);
+       mutex_unlock(&kernfs_open_file_mutex);
 
-       kfree(od);
+       kfree(on);
 }
 
 static int kernfs_file_open(struct inode *inode, struct file *file)
 {
        struct kernfs_node *kn = file->f_path.dentry->d_fsdata;
        const struct kernfs_ops *ops;
-       struct sysfs_open_file *of;
+       struct kernfs_open_file *of;
        bool has_read, has_write, has_mmap;
        int error = -EACCES;
 
@@ -586,9 +586,9 @@ static int kernfs_file_open(struct inode *inode, struct file *file)
            (!(inode->i_mode & S_IRUGO) || !has_read))
                goto err_out;
 
-       /* allocate a sysfs_open_file for the file */
+       /* allocate a kernfs_open_file for the file */
        error = -ENOMEM;
-       of = kzalloc(sizeof(struct sysfs_open_file), GFP_KERNEL);
+       of = kzalloc(sizeof(struct kernfs_open_file), GFP_KERNEL);
        if (!of)
                goto err_out;
 
@@ -654,7 +654,7 @@ err_out:
 static int kernfs_file_release(struct inode *inode, struct file *filp)
 {
        struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
-       struct sysfs_open_file *of = sysfs_of(filp);
+       struct kernfs_open_file *of = kernfs_of(filp);
 
        sysfs_put_open_dirent(kn, of);
        seq_release(inode, filp);
@@ -665,26 +665,26 @@ static int kernfs_file_release(struct inode *inode, struct file *filp)
 
 void sysfs_unmap_bin_file(struct kernfs_node *kn)
 {
-       struct sysfs_open_dirent *od;
-       struct sysfs_open_file *of;
+       struct kernfs_open_node *on;
+       struct kernfs_open_file *of;
 
-       if (!(kn->s_flags & SYSFS_FLAG_HAS_MMAP))
+       if (!(kn->flags & KERNFS_HAS_MMAP))
                return;
 
-       spin_lock_irq(&sysfs_open_dirent_lock);
-       od = kn->s_attr.open;
-       if (od)
-               atomic_inc(&od->refcnt);
-       spin_unlock_irq(&sysfs_open_dirent_lock);
-       if (!od)
+       spin_lock_irq(&kernfs_open_node_lock);
+       on = kn->attr.open;
+       if (on)
+               atomic_inc(&on->refcnt);
+       spin_unlock_irq(&kernfs_open_node_lock);
+       if (!on)
                return;
 
-       mutex_lock(&sysfs_open_file_mutex);
-       list_for_each_entry(of, &od->files, list) {
+       mutex_lock(&kernfs_open_file_mutex);
+       list_for_each_entry(of, &on->files, list) {
                struct inode *inode = file_inode(of->file);
                unmap_mapping_range(inode->i_mapping, 0, 0, 1);
        }
-       mutex_unlock(&sysfs_open_file_mutex);
+       mutex_unlock(&kernfs_open_file_mutex);
 
        sysfs_put_open_dirent(kn, NULL);
 }
@@ -704,19 +704,19 @@ void sysfs_unmap_bin_file(struct kernfs_node *kn)
  */
 static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait)
 {
-       struct sysfs_open_file *of = sysfs_of(filp);
+       struct kernfs_open_file *of = kernfs_of(filp);
        struct kernfs_node *kn = filp->f_path.dentry->d_fsdata;
-       struct sysfs_open_dirent *od = kn->s_attr.open;
+       struct kernfs_open_node *on = kn->attr.open;
 
        /* need parent for the kobj, grab both */
        if (!sysfs_get_active(kn))
                goto trigger;
 
-       poll_wait(filp, &od->poll, wait);
+       poll_wait(filp, &on->poll, wait);
 
        sysfs_put_active(kn);
 
-       if (of->event != atomic_read(&od->event))
+       if (of->event != atomic_read(&on->event))
                goto trigger;
 
        return DEFAULT_POLLMASK;
@@ -733,20 +733,20 @@ static unsigned int kernfs_file_poll(struct file *filp, poll_table *wait)
  */
 void kernfs_notify(struct kernfs_node *kn)
 {
-       struct sysfs_open_dirent *od;
+       struct kernfs_open_node *on;
        unsigned long flags;
 
-       spin_lock_irqsave(&sysfs_open_dirent_lock, flags);
+       spin_lock_irqsave(&kernfs_open_node_lock, flags);
 
-       if (!WARN_ON(sysfs_type(kn) != SYSFS_KOBJ_ATTR)) {
-               od = kn->s_attr.open;
-               if (od) {
-                       atomic_inc(&od->event);
-                       wake_up_interruptible(&od->poll);
+       if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
+               on = kn->attr.open;
+               if (on) {
+                       atomic_inc(&on->event);
+                       wake_up_interruptible(&on->poll);
                }
        }
 
-       spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags);
+       spin_unlock_irqrestore(&kernfs_open_node_lock, flags);
 }
 EXPORT_SYMBOL_GPL(kernfs_notify);
 
@@ -780,36 +780,36 @@ struct kernfs_node *kernfs_create_file_ns_key(struct kernfs_node *parent,
                                              void *priv, const void *ns,
                                              struct lock_class_key *key)
 {
-       struct sysfs_addrm_cxt acxt;
+       struct kernfs_addrm_cxt acxt;
        struct kernfs_node *kn;
        int rc;
 
        kn = sysfs_new_dirent(kernfs_root(parent), name,
-                             (mode & S_IALLUGO) | S_IFREG, SYSFS_KOBJ_ATTR);
+                             (mode & S_IALLUGO) | S_IFREG, KERNFS_FILE);
        if (!kn)
                return ERR_PTR(-ENOMEM);
 
-       kn->s_attr.ops = ops;
-       kn->s_attr.size = size;
-       kn->s_ns = ns;
+       kn->attr.ops = ops;
+       kn->attr.size = size;
+       kn->ns = ns;
        kn->priv = priv;
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
        if (key) {
                lockdep_init_map(&kn->dep_map, "s_active", key, 0);
-               kn->s_flags |= SYSFS_FLAG_LOCKDEP;
+               kn->flags |= KERNFS_LOCKDEP;
        }
 #endif
 
        /*
-        * kn->s_attr.ops is accesible only while holding active ref.  We
+        * kn->attr.ops is accesible only while holding active ref.  We
         * need to know whether some ops are implemented outside active
         * ref.  Cache their existence in flags.
         */
        if (ops->seq_show)
-               kn->s_flags |= SYSFS_FLAG_HAS_SEQ_SHOW;
+               kn->flags |= KERNFS_HAS_SEQ_SHOW;
        if (ops->mmap)
-               kn->s_flags |= SYSFS_FLAG_HAS_MMAP;
+               kn->flags |= KERNFS_HAS_MMAP;
 
        sysfs_addrm_start(&acxt);
        rc = sysfs_add_one(&acxt, kn, parent);