diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2013-10-02 22:35:11 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-11-09 00:16:27 -0500 |
commit | 6987843ff7e836ea65b554905aec34d2fad05c94 (patch) | |
tree | b6a66c9d11b96ee6d03eef374e016ed855b25738 /fs/libfs.c | |
parent | 22a8cb8248ba5d340307ba72432253b1dbdb5cf7 (diff) | |
download | linux-6987843ff7e836ea65b554905aec34d2fad05c94.tar.gz linux-6987843ff7e836ea65b554905aec34d2fad05c94.tar.bz2 linux-6987843ff7e836ea65b554905aec34d2fad05c94.zip |
take anon inode allocation to libfs.c
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/libfs.c')
-rw-r--r-- | fs/libfs.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/fs/libfs.c b/fs/libfs.c index 8c5018493154..5de06947ba5e 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1002,3 +1002,46 @@ void kfree_put_link(struct dentry *dentry, struct nameidata *nd, kfree(s); } EXPORT_SYMBOL(kfree_put_link); + +/* + * 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; +}; + +/* + * A single inode exists for all anon_inode files. Contrary to pipes, + * anon_inode inodes have no associated per-instance data, so we need + * only allocate one of them. + */ +struct inode *alloc_anon_inode(struct super_block *s) +{ + static const struct address_space_operations anon_aops = { + .set_page_dirty = anon_set_page_dirty, + }; + struct inode *inode = new_inode_pseudo(s); + + if (!inode) + return ERR_PTR(-ENOMEM); + + inode->i_ino = get_next_ino(); + 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 + * list because mark_inode_dirty() will think + * that it already _is_ on the dirty list. + */ + inode->i_state = I_DIRTY; + inode->i_mode = S_IRUSR | S_IWUSR; + inode->i_uid = current_fsuid(); + inode->i_gid = current_fsgid(); + inode->i_flags |= S_PRIVATE; + inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; + return inode; +} +EXPORT_SYMBOL(alloc_anon_inode); |