From nobody Thu Nov 28 15:59:30 2024 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.8]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A07321C174D for ; Tue, 1 Oct 2024 11:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727783737; cv=none; b=u/doX98zKmXuEKtPwDHtmKx+g4psYEwSWZSInT3h4dSr/dpLiO6lImfXMbuJ0T2CkJlldw4WhYKeUCgAOOyVaU75cgPjmjKA/aJK3sCndUU+j0fuQnv8e1ydpIvl/fTvDm7MsAPNPJpDPOias5UTqhKg+bAJyM/cnTFRzfoAEnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727783737; c=relaxed/simple; bh=NHhzJ2SQKIsYU97cZ7PLEOwNUqwlBTJes82AlBdji2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pNa4kSsKFR6NGGIsKsQkV9YSzPTCKq0M/iEfFii4LrJ3CcYbt2xArqJdQXS4cRyFIOlWUpGQrrkqWk5Lzb9WrtAPaLF8BEkW/qubdseXBb+I6HVewwbHvz/K2RtVpl0VSZmOP+mjAX+uDCgiWSzxtcvqcbOIfhFroc4cxpqpsAQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b=RWyN7ll6; arc=none smtp.client-ip=117.135.210.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b="RWyN7ll6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=4pE4q PshJZkFvr0EH/7wYyzDZOjRN4ISAjH97wAZP5M=; b=RWyN7ll6Upv6UoHVbXn2c IZFPGot6MmS4MdjNPPJ9phGoPAnTLue/hiKg4r8PO9UTtIIstqy+7Dc8cBrufcWL xpq4CMxVFPvMYW2mrSRot2nzUciyFBw0whutsQrIMyNLIAyDA4exbHsIQ+0aPHS3 X2NoqWi1KKktyanAzAqHvA= Received: from localhost.localdomain (unknown [39.162.142.163]) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wD33yf24vtm4rdrAA--.18425S3; Tue, 01 Oct 2024 19:54:31 +0800 (CST) From: Zhao Mengmeng To: jack@suse.com, zhaomengmeng@kylinos.cn Cc: linux-kernel@vger.kernel.org Subject: [PATCH v3 1/3] udf: refactor udf_current_aext() to handle error Date: Tue, 1 Oct 2024 19:54:23 +0800 Message-ID: <20241001115425.266556-2-zhaomzhao@126.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241001115425.266556-1-zhaomzhao@126.com> References: <20241001115425.266556-1-zhaomzhao@126.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD33yf24vtm4rdrAA--.18425S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxtF1fKFy8JrykArW3Cr1rJFb_yoW7KF4kpF W2kasxAw45XrWxur4IqF4DZF1aqa97Gr47Gry2q34rtF4j9r1rtF1Utr4I9Fy5Krs5Ww4S qFs5tryq9w4Iy3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U8gAwUUUUU= X-CM-SenderInfo: 52kd0zp2kd0qqrswhudrp/1tbimgZrd2b74GcXdQAAs4 Content-Type: text/plain; charset="utf-8" From: Zhao Mengmeng As Jan suggested in links below, refactor udf_current_aext() to differentiate between error, hit EOF and success, it now takes pointer to etype to store the extent type, return 1 when getting etype success, return 0 when hitting EOF and return -errno when err. Link: https://lore.kernel.org/all/20240912111235.6nr3wuqvktecy3vh@quack3/ Link: https://lore.kernel.org/all/20240927115509.a6ie4b75c65gjvfu@quack3/ Signed-off-by: Zhao Mengmeng Suggested-by: Jan Kara --- fs/udf/inode.c | 40 ++++++++++++++++++++++++++-------------- fs/udf/truncate.c | 10 ++++++++-- fs/udf/udfdecl.h | 5 +++-- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 4726a4d014b6..70a27d2bfd29 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -1955,6 +1955,7 @@ int udf_setup_indirect_aext(struct inode *inode, udf_= pblk_t block, struct extent_position nepos; struct kernel_lb_addr neloc; int ver, adsize; + int err =3D 0; =20 if (UDF_I(inode)->i_alloc_type =3D=3D ICBTAG_FLAG_AD_SHORT) adsize =3D sizeof(struct short_ad); @@ -1999,10 +2000,12 @@ int udf_setup_indirect_aext(struct inode *inode, ud= f_pblk_t block, if (epos->offset + adsize > sb->s_blocksize) { struct kernel_lb_addr cp_loc; uint32_t cp_len; - int cp_type; + int8_t cp_type; =20 epos->offset -=3D adsize; - cp_type =3D udf_current_aext(inode, epos, &cp_loc, &cp_len, 0); + err =3D udf_current_aext(inode, epos, &cp_loc, &cp_len, &cp_type, 0); + if (err !=3D 1) + goto err_out; cp_len |=3D ((uint32_t)cp_type) << 30; =20 __udf_add_aext(inode, &nepos, &cp_loc, cp_len, 1); @@ -2017,6 +2020,9 @@ int udf_setup_indirect_aext(struct inode *inode, udf_= pblk_t block, *epos =3D nepos; =20 return 0; +err_out: + brelse(bh); + return err; } =20 /* @@ -2167,9 +2173,12 @@ int8_t udf_next_aext(struct inode *inode, struct ext= ent_position *epos, { int8_t etype; unsigned int indirections =3D 0; + int err =3D 0; =20 - while ((etype =3D udf_current_aext(inode, epos, eloc, elen, inc)) =3D=3D - (EXT_NEXT_EXTENT_ALLOCDESCS >> 30)) { + while ((err =3D udf_current_aext(inode, epos, eloc, elen, + &etype, inc)) =3D=3D 1) { + if (etype !=3D (EXT_NEXT_EXTENT_ALLOCDESCS >> 30)) + break; udf_pblk_t block; =20 if (++indirections > UDF_MAX_INDIR_EXTS) { @@ -2190,14 +2199,17 @@ int8_t udf_next_aext(struct inode *inode, struct ex= tent_position *epos, } } =20 - return etype; + return err =3D=3D 1 ? etype : -1; } =20 -int8_t udf_current_aext(struct inode *inode, struct extent_position *epos, - struct kernel_lb_addr *eloc, uint32_t *elen, int inc) +/* + * Returns 1 on success, -errno on error, 0 on hit EOF. + */ +int udf_current_aext(struct inode *inode, struct extent_position *epos, + struct kernel_lb_addr *eloc, uint32_t *elen, int8_t *etype, + int inc) { int alen; - int8_t etype; uint8_t *ptr; struct short_ad *sad; struct long_ad *lad; @@ -2224,8 +2236,8 @@ int8_t udf_current_aext(struct inode *inode, struct e= xtent_position *epos, case ICBTAG_FLAG_AD_SHORT: sad =3D udf_get_fileshortad(ptr, alen, &epos->offset, inc); if (!sad) - return -1; - etype =3D le32_to_cpu(sad->extLength) >> 30; + return 0; + *etype =3D le32_to_cpu(sad->extLength) >> 30; eloc->logicalBlockNum =3D le32_to_cpu(sad->extPosition); eloc->partitionReferenceNum =3D iinfo->i_location.partitionReferenceNum; @@ -2234,17 +2246,17 @@ int8_t udf_current_aext(struct inode *inode, struct= extent_position *epos, case ICBTAG_FLAG_AD_LONG: lad =3D udf_get_filelongad(ptr, alen, &epos->offset, inc); if (!lad) - return -1; - etype =3D le32_to_cpu(lad->extLength) >> 30; + return 0; + *etype =3D le32_to_cpu(lad->extLength) >> 30; *eloc =3D lelb_to_cpu(lad->extLocation); *elen =3D le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK; break; default: udf_debug("alloc_type =3D %u unsupported\n", iinfo->i_alloc_type); - return -1; + return -EINVAL; } =20 - return etype; + return 1; } =20 static int udf_insert_aext(struct inode *inode, struct extent_position epo= s, diff --git a/fs/udf/truncate.c b/fs/udf/truncate.c index a686c10fd709..76186b211efe 100644 --- a/fs/udf/truncate.c +++ b/fs/udf/truncate.c @@ -188,6 +188,7 @@ int udf_truncate_extents(struct inode *inode) loff_t byte_offset; int adsize; struct udf_inode_info *iinfo =3D UDF_I(inode); + int err =3D 0; =20 if (iinfo->i_alloc_type =3D=3D ICBTAG_FLAG_AD_SHORT) adsize =3D sizeof(struct short_ad); @@ -217,8 +218,8 @@ int udf_truncate_extents(struct inode *inode) else lenalloc -=3D sizeof(struct allocExtDesc); =20 - while ((etype =3D udf_current_aext(inode, &epos, &eloc, - &elen, 0)) !=3D -1) { + while ((err =3D udf_current_aext(inode, &epos, &eloc, + &elen, &etype, 0)) =3D=3D 1) { if (etype =3D=3D (EXT_NEXT_EXTENT_ALLOCDESCS >> 30)) { udf_write_aext(inode, &epos, &neloc, nelen, 0); if (indirect_ext_len) { @@ -253,6 +254,11 @@ int udf_truncate_extents(struct inode *inode) } } =20 + if (err < 0) { + brelse(epos.bh); + return err; + } + if (indirect_ext_len) { BUG_ON(!epos.bh); udf_free_blocks(sb, NULL, &epos.block, 0, indirect_ext_len); diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index 88692512a466..d893db95ac70 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h @@ -171,8 +171,9 @@ extern void udf_write_aext(struct inode *, struct exten= t_position *, extern int8_t udf_delete_aext(struct inode *, struct extent_position); extern int8_t udf_next_aext(struct inode *, struct extent_position *, struct kernel_lb_addr *, uint32_t *, int); -extern int8_t udf_current_aext(struct inode *, struct extent_position *, - struct kernel_lb_addr *, uint32_t *, int); +extern int udf_current_aext(struct inode *inode, struct extent_position *e= pos, + struct kernel_lb_addr *eloc, uint32_t *elen, + int8_t *etype, int inc); extern void udf_update_extra_perms(struct inode *inode, umode_t mode); =20 /* misc.c */ --=20 2.43.0