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

Gao Xiang hsiangkao at linux.alibaba.com
Tue Jun 11 18:00:49 AEST 2024


Hi,

On 2024/6/11 15:54, Hongzhen Luo wrote:
> This adds I/O control for tarerofs stream.
> 
> Signed-off-by: Hongzhen Luo <hongzhen at linux.alibaba.com>
> ---
>   include/erofs/io.h  |  1 +
>   include/erofs/tar.h |  2 +-
>   lib/tar.c           | 16 ++++++++++------
>   3 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/include/erofs/io.h b/include/erofs/io.h
> index c82dfdf..a501685 100644
> --- a/include/erofs/io.h
> +++ b/include/erofs/io.h
> @@ -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.


>   	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);
> diff --git a/include/erofs/tar.h b/include/erofs/tar.h
> index b5c966b..e1de0df 100644
> --- a/include/erofs/tar.h
> +++ b/include/erofs/tar.h
> @@ -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;
> diff --git a/lib/tar.c b/lib/tar.c
> index 3514381..77e09ae 100644
> --- a/lib/tar.c
> +++ b/lib/tar.c
> @@ -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);

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

>   			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


More information about the Linux-erofs mailing list