mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-14 10:09:48 +00:00
Use getsock() and fput() instead of fgetsock() and fputsock() in
sendfile(). This causes sendfile() to use the file descriptor reference to the socket instead of bumping the socket reference count, which avoids an additional refcount operation, as well as a potential expensive socket refcount drop, which can lead to contention on the accept mutex. This change also has the side effect of further reducing the number of cases where an in-progress I/O operation can occur on a socket after close, as using the file descriptor refcount prevents the socket from closing while in use. MFC after: 3 months
This commit is contained in:
parent
8a3dce3376
commit
20bdac8a4f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=158914
@ -1802,6 +1802,7 @@ int
|
||||
kern_sendfile(struct thread *td, struct sendfile_args *uap,
|
||||
struct uio *hdr_uio, struct uio *trl_uio, int compat)
|
||||
{
|
||||
struct file *sock_fp;
|
||||
struct vnode *vp;
|
||||
struct vm_object *obj = NULL;
|
||||
struct socket *so = NULL;
|
||||
@ -1845,8 +1846,9 @@ kern_sendfile(struct thread *td, struct sendfile_args *uap,
|
||||
error = EINVAL;
|
||||
goto done;
|
||||
}
|
||||
if ((error = fgetsock(td, uap->s, &so, NULL)) != 0)
|
||||
if ((error = getsock(td->td_proc->p_fd, uap->s, &sock_fp, NULL)) != 0)
|
||||
goto done;
|
||||
so = sock_fp->f_data;
|
||||
if (so->so_type != SOCK_STREAM) {
|
||||
error = EINVAL;
|
||||
goto done;
|
||||
@ -2196,7 +2198,7 @@ kern_sendfile(struct thread *td, struct sendfile_args *uap,
|
||||
VFS_UNLOCK_GIANT(vfslocked);
|
||||
}
|
||||
if (so)
|
||||
fputsock(so);
|
||||
fdrop(sock_fp, td);
|
||||
if (m_header)
|
||||
m_freem(m_header);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user