Skip to content

Commit

Permalink
hugetlb_file_setup(): switch to alloc_file_pseudo()
Browse files Browse the repository at this point in the history
Acked-by: Linus Torvalds <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jul 12, 2018
1 parent 118f486 commit e68375c
Showing 1 changed file with 16 additions and 37 deletions.
53 changes: 16 additions & 37 deletions fs/hugetlbfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,10 +1308,6 @@ static int get_hstate_idx(int page_size_log)
return h - hstates;
}

static const struct dentry_operations anon_ops = {
.d_dname = simple_dname
};

/*
* Note that size should be aligned to proper hugepage size in caller side,
* otherwise hugetlb_reserve_pages reserves one less hugepages than intended.
Expand All @@ -1320,19 +1316,18 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
vm_flags_t acctflag, struct user_struct **user,
int creat_flags, int page_size_log)
{
struct file *file = ERR_PTR(-ENOMEM);
struct inode *inode;
struct path path;
struct super_block *sb;
struct qstr quick_string;
struct vfsmount *mnt;
int hstate_idx;
struct file *file;

hstate_idx = get_hstate_idx(page_size_log);
if (hstate_idx < 0)
return ERR_PTR(-ENODEV);

*user = NULL;
if (!hugetlbfs_vfsmount[hstate_idx])
mnt = hugetlbfs_vfsmount[hstate_idx];
if (!mnt)
return ERR_PTR(-ENOENT);

if (creat_flags == HUGETLB_SHMFS_INODE && !can_do_hugetlb_shm()) {
Expand All @@ -1348,44 +1343,28 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
}
}

sb = hugetlbfs_vfsmount[hstate_idx]->mnt_sb;
quick_string.name = name;
quick_string.len = strlen(quick_string.name);
quick_string.hash = 0;
path.dentry = d_alloc_pseudo(sb, &quick_string);
if (!path.dentry)
goto out_shm_unlock;

d_set_d_op(path.dentry, &anon_ops);
path.mnt = mntget(hugetlbfs_vfsmount[hstate_idx]);
file = ERR_PTR(-ENOSPC);
inode = hugetlbfs_get_inode(sb, NULL, S_IFREG | S_IRWXUGO, 0);
inode = hugetlbfs_get_inode(mnt->mnt_sb, NULL, S_IFREG | S_IRWXUGO, 0);
if (!inode)
goto out_dentry;
goto out;
if (creat_flags == HUGETLB_SHMFS_INODE)
inode->i_flags |= S_PRIVATE;

file = ERR_PTR(-ENOMEM);
if (hugetlb_reserve_pages(inode, 0,
size >> huge_page_shift(hstate_inode(inode)), NULL,
acctflag))
goto out_inode;

d_instantiate(path.dentry, inode);
inode->i_size = size;
clear_nlink(inode);

file = alloc_file(&path, O_RDWR, &hugetlbfs_file_operations);
if (IS_ERR(file))
goto out_dentry; /* inode is already attached */

return file;
if (hugetlb_reserve_pages(inode, 0,
size >> huge_page_shift(hstate_inode(inode)), NULL,
acctflag))
file = ERR_PTR(-ENOMEM);
else
file = alloc_file_pseudo(inode, mnt, name, O_RDWR,
&hugetlbfs_file_operations);
if (!IS_ERR(file))
return file;

out_inode:
iput(inode);
out_dentry:
path_put(&path);
out_shm_unlock:
out:
if (*user) {
user_shm_unlock(size, *user);
*user = NULL;
Expand Down

0 comments on commit e68375c

Please sign in to comment.