From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E818BB0FD for ; Thu, 29 Jun 2023 13:35:17 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CFC173F582 for ; Thu, 29 Jun 2023 13:35:17 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 29 Jun 2023 13:35:17 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C90EC42178 for ; Thu, 29 Jun 2023 13:35:16 +0200 (CEST) Date: Thu, 29 Jun 2023 13:35:09 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Dominik Csapak , Proxmox Backup Server development discussion References: <20230629103213.1041236-1-f.gruenbichler@proxmox.com> <08228309-cc0a-2e76-1038-215eee1217d6@proxmox.com> In-Reply-To: <08228309-cc0a-2e76-1038-215eee1217d6@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1688038237.3xn9d6donm.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.071 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pbs-devel] [PATCH proxmox-backup] mapped loop device: use read loop instead of read_exact X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Jun 2023 11:35:17 -0000 On June 29, 2023 1:03 pm, Dominik Csapak wrote: > On 6/29/23 12:32, Fabian Gr=C3=BCnbichler wrote: >> since read_exact does not support short reads, which can easily happen i= f the >> mapped image's EOF is not aligned with the request size. >>=20 >> Signed-off-by: Fabian Gr=C3=BCnbichler >> --- >>=20 >> Notes: >> reported on the forum: >> =20 >> https://forum.proxmox.com/threads/problem-backing-up-using-backup-c= lient.129347 >> =20 >> did a quick test reading from a mapped image full of random data, o= bserved >> no performance difference.. >>=20 >> pbs-fuse-loop/src/fuse_loop.rs | 19 +++++++++++++------ >> 1 file changed, 13 insertions(+), 6 deletions(-) >>=20 >> diff --git a/pbs-fuse-loop/src/fuse_loop.rs b/pbs-fuse-loop/src/fuse_loo= p.rs >> index 3d0ef123..7e780799 100644 >> --- a/pbs-fuse-loop/src/fuse_loop.rs >> +++ b/pbs-fuse-loop/src/fuse_loop.rs >> @@ -188,13 +188,20 @@ impl FuseLoopSes= sion { >> match self.reader.seek(SeekFrom::Start(req= .offset)).await { >> Ok(_) =3D> { >> let mut buf =3D vec![0u8; req.size= ]; >> - match self.reader.read_exact(&mut b= uf).await { >> - Ok(_) =3D> { >> - req.reply(&buf) >> - }, >> - Err(e) =3D> { >> - req.io_fail(e) >> + let mut read =3D 0; >> + let mut res =3D Ok(()); >> + while read < req.size && res.is_ok(= ) { >> + match self.reader.read(&mut buf= ).await { >> + Ok(0) =3D> { break; }, >> + Ok(n) =3D> { read +=3D n; }= , >> + Err(e) =3D> { res =3D Err(e= ); }, >> } >=20 > according to https://doc.rust-lang.org/std/io/trait.Read.html the error > with errorkind 'Interrupted' should be retried so imho we should do that = here? this is tokio's AsyncRead(Ext), which doesn't have that remark (and AFAICT, we don't handle that error when using it anywhere).. if it were std::io::Read I'd have used our ReadExt's read_exact_or_eof :) >=20 >> + }; >> + if let Err(e) =3D res { >> + req.io_fail(e) >> + } else { >> + buf.truncate(read); >> + req.reply(&buf) >> } >> }, >> Err(e) =3D> { >=20 >=20 >=20