diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2018-06-09 09:40:05 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-07-12 10:04:23 -0400 |
commit | d93aa9d82aea80b80f225dbf9c7986df444d8106 (patch) | |
tree | 887b5626f375e6745e034e227eb0c583fbefad99 /net/socket.c | |
parent | dbae8f2ca2f0586f4b80201c78ff0aed2a012ab5 (diff) |
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>
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/net/socket.c b/net/socket.c index 2cdbe8f71b7f..4cf3568caf9f 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -391,33 +391,15 @@ static struct file_system_type sock_fs_type = { | |||
391 | 391 | ||
392 | struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname) | 392 | struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname) |
393 | { | 393 | { |
394 | struct qstr name = { .name = "" }; | ||
395 | struct path path; | ||
396 | struct file *file; | 394 | struct file *file; |
397 | 395 | ||
398 | if (dname) { | 396 | if (!dname) |
399 | name.name = dname; | 397 | dname = sock->sk ? sock->sk->sk_prot_creator->name : ""; |
400 | name.len = strlen(name.name); | ||
401 | } else if (sock->sk) { | ||
402 | name.name = sock->sk->sk_prot_creator->name; | ||
403 | name.len = strlen(name.name); | ||
404 | } | ||
405 | path.dentry = d_alloc_pseudo(sock_mnt->mnt_sb, &name); | ||
406 | if (unlikely(!path.dentry)) { | ||
407 | sock_release(sock); | ||
408 | return ERR_PTR(-ENOMEM); | ||
409 | } | ||
410 | path.mnt = mntget(sock_mnt); | ||
411 | |||
412 | d_instantiate(path.dentry, SOCK_INODE(sock)); | ||
413 | 398 | ||
414 | file = alloc_file(&path, O_RDWR | (flags & O_NONBLOCK), | 399 | file = alloc_file_pseudo(SOCK_INODE(sock), sock_mnt, dname, |
415 | &socket_file_ops); | 400 | O_RDWR | (flags & O_NONBLOCK), |
401 | &socket_file_ops); | ||
416 | if (IS_ERR(file)) { | 402 | if (IS_ERR(file)) { |
417 | /* drop dentry, keep inode for a bit */ | ||
418 | ihold(d_inode(path.dentry)); | ||
419 | path_put(&path); | ||
420 | /* ... and now kill it properly */ | ||
421 | sock_release(sock); | 403 | sock_release(sock); |
422 | return file; | 404 | return file; |
423 | } | 405 | } |