Merge branch 'for-linus' of git://git.alsa-project.org/alsa-kernel
[pandora-kernel.git] / arch / s390 / hypfs / inode.c
index 8e1ea1c..7383781 100644 (file)
@@ -17,6 +17,8 @@
 #include <linux/parser.h>
 #include <linux/sysfs.h>
 #include <linux/module.h>
+#include <linux/seq_file.h>
+#include <linux/mount.h>
 #include <asm/ebcdic.h>
 #include "hypfs.h"
 
@@ -58,17 +60,28 @@ static void hypfs_add_dentry(struct dentry *dentry)
        hypfs_last_dentry = dentry;
 }
 
+static inline int hypfs_positive(struct dentry *dentry)
+{
+       return dentry->d_inode && !d_unhashed(dentry);
+}
+
 static void hypfs_remove(struct dentry *dentry)
 {
        struct dentry *parent;
 
        parent = dentry->d_parent;
-       if (S_ISDIR(dentry->d_inode->i_mode))
-               simple_rmdir(parent->d_inode, dentry);
-       else
-               simple_unlink(parent->d_inode, dentry);
+       if (!parent || !parent->d_inode)
+               return;
+       mutex_lock(&parent->d_inode->i_mutex);
+       if (hypfs_positive(dentry)) {
+               if (S_ISDIR(dentry->d_inode->i_mode))
+                       simple_rmdir(parent->d_inode, dentry);
+               else
+                       simple_unlink(parent->d_inode, dentry);
+       }
        d_delete(dentry);
        dput(dentry);
+       mutex_unlock(&parent->d_inode->i_mutex);
 }
 
 static void hypfs_delete_tree(struct dentry *root)
@@ -137,33 +150,24 @@ static ssize_t hypfs_aio_read(struct kiocb *iocb, const struct iovec *iov,
                              unsigned long nr_segs, loff_t offset)
 {
        char *data;
-       size_t len;
+       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) {
-               count = -EINVAL;
-               goto out;
-       }
+       if (nr_segs != 1)
+               return -EINVAL;
 
        data = filp->private_data;
-       len = strlen(data);
-       if (offset > len) {
-               count = 0;
-               goto out;
-       }
-       if (count > len - offset)
-               count = len - offset;
-       if (copy_to_user(buf, data + offset, count)) {
-               count = -EFAULT;
-               goto out;
-       }
-       iocb->ki_pos += count;
+       ret = simple_read_from_buffer(buf, count, &offset, data, strlen(data));
+       if (ret <= 0)
+               return ret;
+
+       iocb->ki_pos += ret;
        file_accessed(filp);
-out:
-       return count;
+
+       return ret;
 }
 static ssize_t hypfs_aio_write(struct kiocb *iocb, const struct iovec *iov,
                              unsigned long nr_segs, loff_t offset)
@@ -256,6 +260,15 @@ static int hypfs_parse_options(char *options, struct super_block *sb)
        return 0;
 }
 
+static int hypfs_show_options(struct seq_file *s, struct vfsmount *mnt)
+{
+       struct hypfs_sb_info *hypfs_info = mnt->mnt_sb->s_fs_info;
+
+       seq_printf(s, ",uid=%u", hypfs_info->uid);
+       seq_printf(s, ",gid=%u", hypfs_info->gid);
+       return 0;
+}
+
 static int hypfs_fill_super(struct super_block *sb, void *data, int silent)
 {
        struct inode *root_inode;
@@ -304,6 +317,7 @@ static int hypfs_fill_super(struct super_block *sb, void *data, int silent)
        }
        hypfs_update_update(sb);
        sb->s_root = root_dentry;
+       printk(KERN_INFO "hypfs: Hypervisor filesystem mounted\n");
        return 0;
 
 err_tree:
@@ -345,13 +359,17 @@ static struct dentry *hypfs_create_file(struct super_block *sb,
        qname.name = name;
        qname.len = strlen(name);
        qname.hash = full_name_hash(name, qname.len);
+       mutex_lock(&parent->d_inode->i_mutex);
        dentry = lookup_one_len(name, parent, strlen(name));
-       if (IS_ERR(dentry))
-               return ERR_PTR(-ENOMEM);
+       if (IS_ERR(dentry)) {
+               dentry = ERR_PTR(-ENOMEM);
+               goto fail;
+       }
        inode = hypfs_make_inode(sb, mode);
        if (!inode) {
                dput(dentry);
-               return ERR_PTR(-ENOMEM);
+               dentry = ERR_PTR(-ENOMEM);
+               goto fail;
        }
        if (mode & S_IFREG) {
                inode->i_fop = &hypfs_file_ops;
@@ -368,6 +386,8 @@ static struct dentry *hypfs_create_file(struct super_block *sb,
        inode->i_private = data;
        d_instantiate(dentry, inode);
        dget(dentry);
+fail:
+       mutex_unlock(&parent->d_inode->i_mutex);
        return dentry;
 }
 
@@ -380,7 +400,6 @@ struct dentry *hypfs_mkdir(struct super_block *sb, struct dentry *parent,
        if (IS_ERR(dentry))
                return dentry;
        hypfs_add_dentry(dentry);
-       parent->d_inode->i_nlink++;
        return dentry;
 }
 
@@ -459,9 +478,10 @@ static struct file_system_type hypfs_type = {
 static struct super_operations hypfs_s_ops = {
        .statfs         = simple_statfs,
        .drop_inode     = hypfs_drop_inode,
+       .show_options   = hypfs_show_options,
 };
 
-static decl_subsys(s390, NULL, NULL);
+static struct kobject *s390_kobj;
 
 static int __init hypfs_init(void)
 {
@@ -477,17 +497,18 @@ static int __init hypfs_init(void)
                        goto fail_diag;
                }
        }
-       kobj_set_kset_s(&s390_subsys, hypervisor_subsys);
-       rc = subsystem_register(&s390_subsys);
-       if (rc)
+       s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
+       if (!s390_kobj) {
+               rc = -ENOMEM;;
                goto fail_sysfs;
+       }
        rc = register_filesystem(&hypfs_type);
        if (rc)
                goto fail_filesystem;
        return 0;
 
 fail_filesystem:
-       subsystem_unregister(&s390_subsys);
+       kobject_put(s390_kobj);
 fail_sysfs:
        if (!MACHINE_IS_VM)
                hypfs_diag_exit();
@@ -501,7 +522,7 @@ static void __exit hypfs_exit(void)
        if (!MACHINE_IS_VM)
                hypfs_diag_exit();
        unregister_filesystem(&hypfs_type);
-       subsystem_unregister(&s390_subsys);
+       kobject_put(s390_kobj);
 }
 
 module_init(hypfs_init)