[PATCH 2/2] erofs-utils: get rid of `{erofsmount_tarindex,ocierofs_io}_sendfile()`

Gao Xiang hsiangkao at linux.alibaba.com
Fri Oct 10 14:49:22 AEDT 2025


Use the default fallback approach directly.

Cc: Chengyu Zhu <hudsonzhu at tencent.com>
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 lib/io.c          |  9 +++++----
 lib/remotes/oci.c | 43 -------------------------------------------
 mount/main.c      | 37 -------------------------------------
 3 files changed, 5 insertions(+), 84 deletions(-)

diff --git a/lib/io.c b/lib/io.c
index d4cfbef..2aa81de 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -583,12 +583,13 @@ ssize_t erofs_io_sendfile(struct erofs_vfile *vout, struct erofs_vfile *vin,
 	ssize_t read, written;
 
 	if (vin->ops || vout->ops) {
-		if (vin->ops)
+		if (vin->ops && vin->ops->sendfile)
 			return vin->ops->sendfile(vout, vin, pos, count);
-		return vout->ops->sendfile(vout, vin, pos, count);
+		if (vout->ops && vout->ops->sendfile)
+			return vout->ops->sendfile(vout, vin, pos, count);
 	}
 #if defined(HAVE_SYS_SENDFILE_H) && defined(HAVE_SENDFILE)
-	do {
+	else do {
 		written = sendfile(vout->fd, vin->fd, pos, count);
 		if (written <= 0) {
 			if (written < 0) {
@@ -602,7 +603,7 @@ ssize_t erofs_io_sendfile(struct erofs_vfile *vout, struct erofs_vfile *vin,
 	} while (written);
 #endif
 	while (count) {
-		char buf[EROFS_MAX_BLOCK_SIZE];
+		char buf[max(EROFS_MAX_BLOCK_SIZE, 32768)];
 
 		read = min_t(u64, count, sizeof(buf));
 		if (pos)
diff --git a/lib/remotes/oci.c b/lib/remotes/oci.c
index 25f991d..1524251 100644
--- a/lib/remotes/oci.c
+++ b/lib/remotes/oci.c
@@ -1458,48 +1458,6 @@ static ssize_t ocierofs_io_read(struct erofs_vfile *vf, void *buf, size_t len)
 	return ret;
 }
 
-static ssize_t ocierofs_io_sendfile(struct erofs_vfile *vout, struct erofs_vfile *vin,
-				    off_t *pos, size_t count)
-{
-	struct ocierofs_iostream *oci_iostream = *(struct ocierofs_iostream **)vin->payload;
-	static char buf[OCIEROFS_IO_CHUNK_SIZE];
-	ssize_t total_written = 0;
-	ssize_t ret = 0;
-
-	while (count > 0) {
-		size_t to_read = min_t(size_t, count, OCIEROFS_IO_CHUNK_SIZE);
-		u64 read_offset = pos ? *pos : oci_iostream->offset;
-
-		ret = ocierofs_io_pread(vin, buf, to_read, read_offset);
-		if (ret <= 0) {
-			if (ret < 0 && total_written == 0)
-				return ret;
-			break;
-		}
-		ssize_t written = __erofs_io_write(vout->fd, buf, ret);
-
-		if (written < 0) {
-			erofs_err("OCI I/O sendfile: failed to write to output: %s",
-				  strerror(errno));
-			ret = -errno;
-			break;
-		}
-
-		if (written != ret) {
-			erofs_err("OCI I/O sendfile: partial write: %zd != %zd", written, ret);
-			ret = written;
-		}
-
-		total_written += ret;
-		count -= ret;
-		if (pos)
-			*pos += ret;
-		else
-			oci_iostream->offset += ret;
-	}
-	return count;
-}
-
 static void ocierofs_io_close(struct erofs_vfile *vfile)
 {
 	struct ocierofs_iostream *oci_iostream = *(struct ocierofs_iostream **)vfile->payload;
@@ -1513,7 +1471,6 @@ static void ocierofs_io_close(struct erofs_vfile *vfile)
 static struct erofs_vfops ocierofs_io_vfops = {
 	.pread = ocierofs_io_pread,
 	.read = ocierofs_io_read,
-	.sendfile = ocierofs_io_sendfile,
 	.close = ocierofs_io_close,
 };
 
diff --git a/mount/main.c b/mount/main.c
index fa4c322..d98e1e9 100644
--- a/mount/main.c
+++ b/mount/main.c
@@ -409,45 +409,8 @@ static void erofsmount_tarindex_close(struct erofs_vfile *vf)
 	free(tp);
 }
 
-static ssize_t erofsmount_tarindex_sendfile(struct erofs_vfile *vout,
-					    struct erofs_vfile *vin,
-					    off_t *pos, size_t count)
-{
-	static char buf[32768];
-	ssize_t total_written = 0, ret = 0, written;
-	size_t to_read;
-	u64 read_offset;
-
-	while (count > 0) {
-		to_read = min_t(size_t, count, sizeof(buf));
-		read_offset = pos ? *pos : 0;
-
-		ret = erofsmount_tarindex_pread(vin, buf, to_read, read_offset);
-		if (ret <= 0) {
-			if (ret < 0 && total_written == 0)
-				return ret;
-			break;
-		}
-
-		written = __erofs_io_write(vout->fd, buf, ret);
-		if (written < 0) {
-			ret = -errno;
-			break;
-		}
-		if (written != ret)
-			ret = written;
-
-		total_written += ret;
-		count -= ret;
-		if (pos)
-			*pos += ret;
-	}
-	return count;
-}
-
 static struct erofs_vfops tarindex_vfile_ops = {
 	.pread = erofsmount_tarindex_pread,
-	.sendfile = erofsmount_tarindex_sendfile,
 	.close = erofsmount_tarindex_close,
 };
 
-- 
2.43.5



More information about the Linux-erofs mailing list