[PATCH] erofs-utils: add I/O control for tarerofs stream via `erofs_vfile`
Gao Xiang
hsiangkao at linux.alibaba.com
Wed Jun 12 12:23:22 AEST 2024
On 2024/6/11 19:19, Hongzhen Luo wrote:
> This adds I/O control for tarerofs stream.
>
> Signed-off-by: Hongzhen Luo <hongzhen at linux.alibaba.com>
> ---
> v3: Make the code cleaner.
> v2: https://lore.kernel.org/all/20240611095359.294925-1-hongzhen@linux.alibaba.com/
> v1: https://lore.kernel.org/all/20240611075445.178659-1-hongzhen@linux.alibaba.com/
> ---
> include/erofs/io.h | 4 ++++
> include/erofs/tar.h | 2 +-
> lib/io.c | 35 +++++++++++++++++++++++++++++++++++
> lib/tar.c | 34 +++++-----------------------------
> 4 files changed, 45 insertions(+), 30 deletions(-)
>
> diff --git a/include/erofs/io.h b/include/erofs/io.h
> index c82dfdf..2c91314 100644
> --- a/include/erofs/io.h
> +++ b/include/erofs/io.h
> @@ -30,6 +30,8 @@ struct erofs_vfops {
> int (*fsync)(struct erofs_vfile *vf);
> int (*fallocate)(struct erofs_vfile *vf, u64 offset, size_t len, bool pad);
> int (*ftruncate)(struct erofs_vfile *vf, u64 length);
> + int (*read)(struct erofs_vfile *vf, void *buf, size_t len);
it can overflow, I think it's much better to use `ssize_t` instead.
> + off_t (*lseek)(struct erofs_vfile *vf, u64 offset, int whence);
> };
>
> struct erofs_vfile {
> @@ -43,6 +45,8 @@ int erofs_io_fsync(struct erofs_vfile *vf);
> int erofs_io_fallocate(struct erofs_vfile *vf, u64 offset, size_t len, bool pad);
> int erofs_io_ftruncate(struct erofs_vfile *vf, u64 length);
> int erofs_io_pread(struct erofs_vfile *vf, void *buf, u64 offset, size_t len);
> +int erofs_io_read(struct erofs_vfile *vf, void *buf, size_t len);
> +off_t erofs_io_lseek(struct erofs_vfile *vf, u64 offset, int whence);
>
> ssize_t erofs_copy_file_range(int fd_in, u64 *off_in, int fd_out, u64 *off_out,
> size_t length);
> 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/io.c b/lib/io.c
> index 2db384c..8e01948 100644
> --- a/lib/io.c
> +++ b/lib/io.c
> @@ -420,3 +420,38 @@ out:
> #endif
> return __erofs_copy_file_range(fd_in, off_in, fd_out, off_out, length);
> }
> +
> +int erofs_io_read(struct erofs_vfile *vf, void *buf, size_t bytes)
> +{
> + s64 i = 0;
ssize_t i = 0;
> +
> + if (vf->ops)
> + return vf->ops->read(vf, buf, bytes);
> +
> + while (bytes) {
> + int len = bytes > INT_MAX ? INT_MAX : bytes;
> + int ret;
> +
> + ret = read(vf->fd, buf + i, len);
> + if (ret < 1) {
> + if (ret == 0) {
> + break;
> + } else if (errno != EINTR) {
> + erofs_err("failed to read : %s\n",
erofs_err("failed to read: %s",
Otherwise it looks good to me,
Thanks,
Gao Xiang
More information about the Linux-erofs
mailing list