Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Aug 2023 18:56:16 GMT
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: da5a6738d589 - main - linux(4): Allow in fd to be a socket in sendfile
Message-ID:  <202308191856.37JIuGjm084174@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=da5a6738d589d748ddf93678767d1565558bddd9

commit da5a6738d589d748ddf93678767d1565558bddd9
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-08-19 18:55:23 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-08-19 18:55:23 +0000

    linux(4): Allow in fd to be a socket in sendfile
    
    In this case sendfile fallback is used.
    
    MFC after:              1 month
---
 sys/compat/linux/linux_socket.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index 6c7cf12cf42e..67736ecc69f6 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -2381,16 +2381,24 @@ out:
  * with FreeBSD sendfile.
  */
 static bool
-is_stream_socket(struct file *fp)
+is_sendfile(struct file *fp, struct file *ofp)
 {
 	struct socket *so;
 
+	/*
+	 * FreeBSD sendfile() system call sends a regular file or
+	 * shared memory object out a stream socket.
+	 */
+	if ((fp->f_type != DTYPE_SHM && fp->f_type != DTYPE_VNODE) ||
+	    (fp->f_type == DTYPE_VNODE &&
+	    (fp->f_vnode == NULL || fp->f_vnode->v_type != VREG)))
+		return (false);
 	/*
 	 * The socket must be a stream socket and connected.
 	 */
-	if (fp->f_type != DTYPE_SOCKET)
+	if (ofp->f_type != DTYPE_SOCKET)
 		return (false);
-	so = fp->f_data;
+	so = ofp->f_data;
 	if (so->so_type != SOCK_STREAM)
 		return (false);
 	/*
@@ -2556,7 +2564,7 @@ linux_sendfile_common(struct thread *td, l_int out, l_int in,
 		    0);
 	} else {
 		sbytes = 0;
-		if (is_stream_socket(ofp))
+		if (is_sendfile(fp, ofp))
 			error = sendfile_sendfile(td, fp, out, offset, count,
 			    &sbytes);
 		else



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202308191856.37JIuGjm084174>