Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C008CC25B76 for ; Tue, 11 Jun 2024 08:06:24 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=Gz4u6hD8; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Vz1TV5C99z3cF6 for ; Tue, 11 Jun 2024 18:06:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=Gz4u6hD8; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.99; helo=out30-99.freemail.mail.aliyun.com; envelope-from=hongzhen@linux.alibaba.com; receiver=lists.ozlabs.org) Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Vz1TM3cYLz2yN3 for ; Tue, 11 Jun 2024 18:06:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1718093171; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=kTeBDGuldcDl3+/5F3+KJnoDwXgX3lYvTIFGGKabjOs=; b=Gz4u6hD8AoYOF0nEjyZktXoGffbg3VgTcC5DlWcMgIiQd9I1Gmz/gJcpRq1qUL8kAFKg/AC94on77kipmaFPZZVgegxanHIL227exkkwXfPljgd1XTydp0qBvVhloLQyjEzQcZBEnnaCPvyDxnrjnX5Ea8/ORuNS5l4rLq9YYVM= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045075189;MF=hongzhen@linux.alibaba.com;NM=1;PH=DS;RN=2;SR=0;TI=SMTPD_---0W8FgJjQ_1718093169; Received: from 30.221.132.93(mailfrom:hongzhen@linux.alibaba.com fp:SMTPD_---0W8FgJjQ_1718093169) by smtp.aliyun-inc.com; Tue, 11 Jun 2024 16:06:09 +0800 Message-ID: Date: Tue, 11 Jun 2024 16:06:08 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] erofs-utils: add I/O control for tarerofs stream via `erofs_vfile` To: Gao Xiang , linux-erofs@lists.ozlabs.org References: <20240611075445.178659-1-hongzhen@linux.alibaba.com> <019d4a56-aa4a-48b0-accc-2586509b2e29@linux.alibaba.com> From: Hongzhen Luo In-Reply-To: <019d4a56-aa4a-48b0-accc-2586509b2e29@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" On 2024/6/11 16:00, Gao Xiang wrote: > Hi, > > On 2024/6/11 15:54, Hongzhen Luo wrote: >> This adds I/O control for tarerofs stream. >> >> Signed-off-by: Hongzhen Luo >> --- >>   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 Ok, I will send a new version later. --- Thanks, Hongzhen Luo