mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-27 09:02:06 +00:00
new wrapper: alloc_file_pseudo()
takes inode, vfsmount, name, O_... flags and file_operations and either returns a new struct file (in which case inode reference we held is consumed) or returns ERR_PTR(), in which case no refcounts are altered. converted aio_private_file() and sock_alloc_file() to it Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
dbae8f2ca2
commit
d93aa9d82a
4 changed files with 39 additions and 39 deletions
28
net/socket.c
28
net/socket.c
|
@ -391,33 +391,15 @@ static struct file_system_type sock_fs_type = {
|
|||
|
||||
struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname)
|
||||
{
|
||||
struct qstr name = { .name = "" };
|
||||
struct path path;
|
||||
struct file *file;
|
||||
|
||||
if (dname) {
|
||||
name.name = dname;
|
||||
name.len = strlen(name.name);
|
||||
} else if (sock->sk) {
|
||||
name.name = sock->sk->sk_prot_creator->name;
|
||||
name.len = strlen(name.name);
|
||||
}
|
||||
path.dentry = d_alloc_pseudo(sock_mnt->mnt_sb, &name);
|
||||
if (unlikely(!path.dentry)) {
|
||||
sock_release(sock);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
path.mnt = mntget(sock_mnt);
|
||||
if (!dname)
|
||||
dname = sock->sk ? sock->sk->sk_prot_creator->name : "";
|
||||
|
||||
d_instantiate(path.dentry, SOCK_INODE(sock));
|
||||
|
||||
file = alloc_file(&path, O_RDWR | (flags & O_NONBLOCK),
|
||||
&socket_file_ops);
|
||||
file = alloc_file_pseudo(SOCK_INODE(sock), sock_mnt, dname,
|
||||
O_RDWR | (flags & O_NONBLOCK),
|
||||
&socket_file_ops);
|
||||
if (IS_ERR(file)) {
|
||||
/* drop dentry, keep inode for a bit */
|
||||
ihold(d_inode(path.dentry));
|
||||
path_put(&path);
|
||||
/* ... and now kill it properly */
|
||||
sock_release(sock);
|
||||
return file;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue