Skip to contentSkip to conversation

erofs-utils: add I/O control for tarerofs stream via `erofs_vfile`

PATCH Superseded Hongzhen Luo 2 participants 3 messages Jun 11, 2024 Library code

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: add I/O control for tarerofs stream via `erofs_vfile`

This adds I/O control for tarerofs stream.

---
 include/erofs/io.h  |  1 +
 include/erofs/tar.h |  2 +-
 lib/tar.c           | 16 ++++++++++------
 3 files changed, 12 insertions(+), 7 deletions(-)
include/erofs/io.h +1 -0
index c82dfdf..a501685 100644
@@ -26,6 +26,7 @@ struct erofs_vfile;
 
 struct erofs_vfops {
 	int (*pread)(struct erofs_vfile *vf, void *buf, u64 offset, size_t len);
+	int (*read)(struct erofs_vfile *vf, void *buf, size_t len);
 	int (*pwrite)(struct erofs_vfile *vf, const void *buf, u64 offset, size_t len);
 	int (*fsync)(struct erofs_vfile *vf);
 	int (*fallocate)(struct erofs_vfile *vf, u64 offset, size_t len, bool pad);
include/erofs/tar.h +1 -1
index b5c966b..e1de0df 100644
@@ -39,7 +39,7 @@ struct erofs_iostream_liblzma {
 
 struct erofs_iostream {
 	union {
-		int fd;			/* original fd */
+		struct erofs_vfile vf;
 		void *handler;
 #ifdef HAVE_LIBLZMA
 		struct erofs_iostream_liblzma *lzma;
lib/tar.c +10 -6
index 3514381..77e09ae 100644
@@ -79,7 +79,7 @@ void erofs_iostream_close(struct erofs_iostream *ios)
 #endif
 		return;
 	}
-	close(ios->fd);
+	close(ios->vf.fd);
 }
 
 int erofs_iostream_open(struct erofs_iostream *ios, int fd, int decoder)
@@ -119,7 +119,7 @@ int erofs_iostream_open(struct erofs_iostream *ios, int fd, int decoder)
 		return -EOPNOTSUPP;
 #endif
 	} else {
-		ios->fd = fd;
+		ios->vf.fd = fd;
 		fsz = lseek(fd, 0, SEEK_END);
 		if (fsz <= 0) {
 			ios->feof = !fsz;
@@ -218,8 +218,12 @@ int erofs_iostream_read(struct erofs_iostream *ios, void **buf, u64 bytes)
 			return -EOPNOTSUPP;
 #endif
 		} else {
-			ret = erofs_read_from_fd(ios->fd, ios->buffer + rabytes,
-						 ios->bufsize - rabytes);
+			if (ios->vf.ops)
+				ret = ios->vf.ops->read(&ios->vf, ios->buffer + rabytes,
+							 ios->bufsize - rabytes);
+			else
+				ret = erofs_read_from_fd(ios->vf.fd, ios->buffer + rabytes,
+							 ios->bufsize - rabytes);
 			if (ret < 0)
 				return ret;
 			ios->tail += ret;
@@ -270,8 +274,8 @@ int erofs_iostream_lskip(struct erofs_iostream *ios, u64 sz)
 	if (ios->feof)
 		return sz;
 
-	if (ios->sz && likely(ios->dumpfd < 0)) {
-		s64 cur = lseek(ios->fd, sz, SEEK_CUR);
+	if (ios->sz && likely(ios->dumpfd < 0) && !ios->vf.ops) {
+		s64 cur = lseek(ios->vf.fd, sz, SEEK_CUR);
 
 		if (cur > ios->sz)
 			return cur - ios->sz;
Signature · 1 line
2.39.3
#1 lore raw

Hi,

Quoted 14 lines · Hongzhen Luo

This adds I/O control for tarerofs stream.

---
  include/erofs/io.h  |  1 +
  include/erofs/tar.h |  2 +-
  lib/tar.c           | 16 ++++++++++------
  3 files changed, 12 insertions(+), 7 deletions(-)
include/erofs/io.h +0 -0
index c82dfdf..a501685 100644

include/erofs/io.h struct erofs_vfile; · line 29

Quoted 4 lines
include/erofs/io.h +1 -0
@@ -26,6 +26,7 @@ struct erofs_vfile;
 
  struct erofs_vfops {
  	int (*pread)(struct erofs_vfile *vf, void *buf, u64 offset, size_t len);
+	int (*read)(struct erofs_vfile *vf, void *buf, size_t len);

I think you need to add both read and lseek.

Quoted 40 lines
include/erofs/io.h +0 -0
  	int (*pwrite)(struct erofs_vfile *vf, const void *buf, u64 offset, size_t len);
  	int (*fsync)(struct erofs_vfile *vf);
  	int (*fallocate)(struct erofs_vfile *vf, u64 offset, size_t len, bool pad);
include/erofs/tar.h +1 -1
index b5c966b..e1de0df 100644
@@ -39,7 +39,7 @@ struct erofs_iostream_liblzma {
 
  struct erofs_iostream {
  	union {
-		int fd;			/* original fd */
+		struct erofs_vfile vf;
  		void *handler;
  #ifdef HAVE_LIBLZMA
  		struct erofs_iostream_liblzma *lzma;
lib/tar.c +2 -2
index 3514381..77e09ae 100644
@@ -79,7 +79,7 @@ void erofs_iostream_close(struct erofs_iostream *ios)
  #endif
  		return;
  	}
-	close(ios->fd);
+	close(ios->vf.fd);
  }
 
  int erofs_iostream_open(struct erofs_iostream *ios, int fd, int decoder)
@@ -119,7 +119,7 @@ int erofs_iostream_open(struct erofs_iostream *ios, int fd, int decoder)
  		return -EOPNOTSUPP;
  #endif
  	} else {
-		ios->fd = fd;
+		ios->vf.fd = fd;
  		fsz = lseek(fd, 0, SEEK_END);
  		if (fsz <= 0) {
  			ios->feof = !fsz;
@@ -218,8 +218,12 @@ int erofs_iostream_read(struct erofs_iostream *ios, void **buf, u64 bytes)
  			return -EOPNOTSUPP;

lib/tar.c int erofs_iostream_read(struct erofs_iostream *ios, void **buf, u64 bytes) · line 226

Quoted 10 lines
lib/tar.c +6 -2
  #endif
  		} else {
-			ret = erofs_read_from_fd(ios->fd, ios->buffer + rabytes,
-						 ios->bufsize - rabytes);
+			if (ios->vf.ops)
+				ret = ios->vf.ops->read(&ios->vf, ios->buffer + rabytes,
+							 ios->bufsize - rabytes);
+			else
+				ret = erofs_read_from_fd(ios->vf.fd, ios->buffer + rabytes,
+							 ios->bufsize - rabytes);

I guess this could be moved into lib/io.c? and call erofs_io_read() here.

lib/tar.c int erofs_iostream_lskip(struct erofs_iostream *ios, u64 sz) · line 278

Quoted 11 lines
lib/tar.c +2 -2
  			if (ret < 0)
  				return ret;
  			ios->tail += ret;
@@ -270,8 +274,8 @@ int erofs_iostream_lskip(struct erofs_iostream *ios, u64 sz)
  	if (ios->feof)
  		return sz;
 
-	if (ios->sz && likely(ios->dumpfd < 0)) {
-		s64 cur = lseek(ios->fd, sz, SEEK_CUR);
+	if (ios->sz && likely(ios->dumpfd < 0) && !ios->vf.ops) {
+		s64 cur = lseek(ios->vf.fd, sz, SEEK_CUR);

Same here, erofs_io_lseek is needed.

Thanks,
Gao Xiang

#2 lore raw
Quoted 93 lines · Gao Xiang

Hi,

Quoted 14 lines · Hongzhen Luo

This adds I/O control for tarerofs stream.

---
  include/erofs/io.h  |  1 +
  include/erofs/tar.h |  2 +-
  lib/tar.c           | 16 ++++++++++------

  3 files changed, 12 insertions(+), 7 deletions(-)
include/erofs/io.h +0 -0
index c82dfdf..a501685 100644

include/erofs/io.h struct erofs_vfile; · line 28

Quoted 3 lines
include/erofs/io.h +1 -0
@@ -26,6 +26,7 @@ struct erofs_vfile;
     struct erofs_vfops {
       int (*pread)(struct erofs_vfile *vf, void *buf, u64 offset, size_t len);
+    int (*read)(struct erofs_vfile *vf, void *buf, size_t len);

I think you need to add both read and lseek.

Quoted 42 lines
include/erofs/io.h +0 -0
       int (*pwrite)(struct erofs_vfile *vf, const void *buf, u64 offset, size_t len);
       int (*fsync)(struct erofs_vfile *vf);
       int (*fallocate)(struct erofs_vfile *vf, u64 offset, size_t len, bool pad);
include/erofs/tar.h +1 -1
index b5c966b..e1de0df 100644
@@ -39,7 +39,7 @@ struct erofs_iostream_liblzma {
     struct erofs_iostream {
       union {
-        int fd;            /* original fd */
+        struct erofs_vfile vf;
           void *handler;
   #ifdef HAVE_LIBLZMA
           struct erofs_iostream_liblzma *lzma;
lib/tar.c +2 -2
index 3514381..77e09ae 100644
@@ -79,7 +79,7 @@ void erofs_iostream_close(struct erofs_iostream *ios)
   #endif
           return;
       }
-    close(ios->fd);
+    close(ios->vf.fd);
   }
     int erofs_iostream_open(struct erofs_iostream *ios, int fd, int decoder)
@@ -119,7 +119,7 @@ int erofs_iostream_open(struct erofs_iostream 
 *ios, int fd, int decoder)
           return -EOPNOTSUPP;
   #endif
       } else {
-        ios->fd = fd;
+        ios->vf.fd = fd;
           fsz = lseek(fd, 0, SEEK_END);
           if (fsz <= 0) {

              ios->feof = !fsz;

lib/tar.c +0 -0
@@ -218,8 +218,12 @@ int erofs_iostream_read(struct erofs_iostream 
 *ios, void **buf, u64 bytes)
               return -EOPNOTSUPP;
   #endif
           } else {

lib/tar.c int erofs_iostream_read(struct erofs_iostream · line 229

Quoted 10 lines
lib/tar.c +6 -2
-            ret = erofs_read_from_fd(ios->fd, ios->buffer + rabytes,
-                         ios->bufsize - rabytes);
+            if (ios->vf.ops)
+                ret = ios->vf.ops->read(&ios->vf, ios->buffer + 
 rabytes,
+                             ios->bufsize - rabytes);
+            else
+                ret = erofs_read_from_fd(ios->vf.fd, ios->buffer + 
 rabytes,
+                             ios->bufsize - rabytes);

I guess this could be moved into lib/io.c? and call erofs_io_read() here.

lib/tar.c int erofs_iostream_lskip(struct erofs_iostream · line 279

Quoted 11 lines

              if (ret < 0)
                  return ret;
              ios->tail += ret;

lib/tar.c +2 -1
@@ -270,8 +274,8 @@ int erofs_iostream_lskip(struct erofs_iostream 
 *ios, u64 sz)
       if (ios->feof)
           return sz;
   -    if (ios->sz && likely(ios->dumpfd < 0)) {
-        s64 cur = lseek(ios->fd, sz, SEEK_CUR);
+    if (ios->sz && likely(ios->dumpfd < 0) && !ios->vf.ops) {
+        s64 cur = lseek(ios->vf.fd, sz, SEEK_CUR);

Same here, erofs_io_lseek is needed.

Quoted 2 lines

Thanks,
Gao Xiang

Ok, I will send a new version later.

---

Thanks,

Hongzhen Luo