OSDN Git Service

sysfs: Create mountpoints with sysfs_create_mount_point
[android-x86/kernel.git] / arch / s390 / hypfs / inode.c
index 4c8008d..a36ce4d 100644 (file)
@@ -74,7 +74,7 @@ static void hypfs_remove(struct dentry *dentry)
        parent = dentry->d_parent;
        mutex_lock(&parent->d_inode->i_mutex);
        if (hypfs_positive(dentry)) {
-               if (S_ISDIR(dentry->d_inode->i_mode))
+               if (d_is_dir(dentry))
                        simple_rmdir(parent->d_inode, dentry);
                else
                        simple_unlink(parent->d_inode, dentry);
@@ -144,36 +144,32 @@ static int hypfs_open(struct inode *inode, struct file *filp)
        return nonseekable_open(inode, filp);
 }
 
-static ssize_t hypfs_aio_read(struct kiocb *iocb, const struct iovec *iov,
-                             unsigned long nr_segs, loff_t offset)
+static ssize_t hypfs_read_iter(struct kiocb *iocb, struct iov_iter *to)
 {
-       char *data;
-       ssize_t ret;
-       struct file *filp = iocb->ki_filp;
-       /* XXX: temporary */
-       char __user *buf = iov[0].iov_base;
-       size_t count = iov[0].iov_len;
-
-       if (nr_segs != 1)
-               return -EINVAL;
-
-       data = filp->private_data;
-       ret = simple_read_from_buffer(buf, count, &offset, data, strlen(data));
-       if (ret <= 0)
-               return ret;
-
-       iocb->ki_pos += ret;
-       file_accessed(filp);
+       struct file *file = iocb->ki_filp;
+       char *data = file->private_data;
+       size_t available = strlen(data);
+       loff_t pos = iocb->ki_pos;
+       size_t count;
 
-       return ret;
+       if (pos < 0)
+               return -EINVAL;
+       if (pos >= available || !iov_iter_count(to))
+               return 0;
+       count = copy_to_iter(data + pos, available - pos, to);
+       if (!count)
+               return -EFAULT;
+       iocb->ki_pos = pos + count;
+       file_accessed(file);
+       return count;
 }
-static ssize_t hypfs_aio_write(struct kiocb *iocb, const struct iovec *iov,
-                             unsigned long nr_segs, loff_t offset)
+
+static ssize_t hypfs_write_iter(struct kiocb *iocb, struct iov_iter *from)
 {
        int rc;
        struct super_block *sb = file_inode(iocb->ki_filp)->i_sb;
        struct hypfs_sb_info *fs_info = sb->s_fs_info;
-       size_t count = iov_length(iov, nr_segs);
+       size_t count = iov_iter_count(from);
 
        /*
         * Currently we only allow one update per second for two reasons:
@@ -202,6 +198,7 @@ static ssize_t hypfs_aio_write(struct kiocb *iocb, const struct iovec *iov,
        }
        hypfs_update_update(sb);
        rc = count;
+       iov_iter_advance(from, count);
 out:
        mutex_unlock(&fs_info->lock);
        return rc;
@@ -440,10 +437,10 @@ struct dentry *hypfs_create_str(struct dentry *dir,
 static const struct file_operations hypfs_file_ops = {
        .open           = hypfs_open,
        .release        = hypfs_release,
-       .read           = do_sync_read,
-       .write          = do_sync_write,
-       .aio_read       = hypfs_aio_read,
-       .aio_write      = hypfs_aio_write,
+       .read           = new_sync_read,
+       .write          = new_sync_write,
+       .read_iter      = hypfs_read_iter,
+       .write_iter     = hypfs_write_iter,
        .llseek         = no_llseek,
 };
 
@@ -461,8 +458,6 @@ static const struct super_operations hypfs_s_ops = {
        .show_options   = hypfs_show_options,
 };
 
-static struct kobject *s390_kobj;
-
 static int __init hypfs_init(void)
 {
        int rc;
@@ -486,18 +481,16 @@ static int __init hypfs_init(void)
                rc = -ENODATA;
                goto fail_hypfs_sprp_exit;
        }
-       s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
-       if (!s390_kobj) {
-               rc = -ENOMEM;
+       rc = sysfs_create_mount_point(hypervisor_kobj, "s390");
+       if (rc)
                goto fail_hypfs_diag0c_exit;
-       }
        rc = register_filesystem(&hypfs_type);
        if (rc)
                goto fail_filesystem;
        return 0;
 
 fail_filesystem:
-       kobject_put(s390_kobj);
+       sysfs_remove_mount_point(hypervisor_kobj, "s390");
 fail_hypfs_diag0c_exit:
        hypfs_diag0c_exit();
 fail_hypfs_sprp_exit:
@@ -515,7 +508,7 @@ fail_dbfs_exit:
 static void __exit hypfs_exit(void)
 {
        unregister_filesystem(&hypfs_type);
-       kobject_put(s390_kobj);
+       sysfs_remove_mount_point(hypervisor_kobj, "s390");
        hypfs_diag0c_exit();
        hypfs_sprp_exit();
        hypfs_vm_exit();