ext4: Fix potential reclaim deadlock when truncating partial block
[safe/jmp/linux-2.6] / fs / anon_inodes.c
index c16d9be..47d4a01 100644 (file)
@@ -48,10 +48,23 @@ static struct file_system_type anon_inode_fs_type = {
        .get_sb         = anon_inodefs_get_sb,
        .kill_sb        = kill_anon_super,
 };
-static struct dentry_operations anon_inodefs_dentry_operations = {
+static const struct dentry_operations anon_inodefs_dentry_operations = {
        .d_delete       = anon_inodefs_delete_dentry,
 };
 
+/*
+ * nop .set_page_dirty method so that people can use .page_mkwrite on
+ * anon inodes.
+ */
+static int anon_set_page_dirty(struct page *page)
+{
+       return 0;
+};
+
+static const struct address_space_operations anon_aops = {
+       .set_page_dirty = anon_set_page_dirty,
+};
+
 /**
  * anon_inode_getfd - creates a new file instance by hooking it up to an
  *                    anonymous inode, and a dentry that describe the "class"
@@ -79,9 +92,12 @@ int anon_inode_getfd(const char *name, const struct file_operations *fops,
        if (IS_ERR(anon_inode_inode))
                return -ENODEV;
 
+       if (fops->owner && !try_module_get(fops->owner))
+               return -ENOENT;
+
        error = get_unused_fd_flags(flags);
        if (error < 0)
-               return error;
+               goto err_module;
        fd = error;
 
        /*
@@ -128,6 +144,8 @@ err_dput:
        dput(dentry);
 err_put_unused_fd:
        put_unused_fd(fd);
+err_module:
+       module_put(fops->owner);
        return error;
 }
 EXPORT_SYMBOL_GPL(anon_inode_getfd);
@@ -146,6 +164,8 @@ static struct inode *anon_inode_mkinode(void)
 
        inode->i_fop = &anon_inode_fops;
 
+       inode->i_mapping->a_ops = &anon_aops;
+
        /*
         * Mark the inode dirty from the very beginning,
         * that way it will never be moved to the dirty