From nobody Sun Feb 8 00:12:24 2026 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCF0A224B0D for ; Thu, 22 Jan 2026 14:36:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769092611; cv=none; b=fPGhkbDfqxxFSJH53Sz8MEKXMA5uBHe01r3hIba2rjxhta/SDv1Nc3QcziLOVKVZoOuikoqNhVDNyf6OKTaTG3bVGTa2xo4GPhRLMHC9mVXBQIdobQPLOWT09/nmFt1YTsaMgSjO+LEX24WBHOiElTQFw8zJDkMOwhT1prTkOpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769092611; c=relaxed/simple; bh=uHlzLrFVlqeMkM5Cu3ftGkQfXyY3OdMGc1rKtH+T9mA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=lOwAvVgpMIXS+34I4sfCuDRk8uFEr46ph8NobcMreEfHXzLUC8N85wUqs+H322uv7B6PPqrXBM2w5gmVuVfy9lh8uyvHm+FopEu3i71wOE2yrPAgkn++fes2IcHjpeXpvGY2Mc2nGl4fAdaN0/nhlqU5vWNAAHzsS6IlbRYWB+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=GvfE6KaK; arc=none smtp.client-ip=115.124.30.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="GvfE6KaK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1769092599; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=z8/Ug4crrEJ5u3wYxXOEMJIqkV8lK0cW12U+RkRRi0w=; b=GvfE6KaKHnpNDlqnvNCInGTG5jql8VXNiYHyJyLdF9XLCYLEko2Pl+eSqqYgX7yxV6lj5I9/snHMWO6AdfN62mj8hC02YzZRtOyCx5o0Z40rXAYmdG6e1zJL4rBy9n8Ix4XCfmcQXnJBg+OLreTlCowiNcPxH7qIqU8W0uV5TJY= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0Wxcc2mv_1769092594 cluster:ay36) by smtp.aliyun-inc.com; Thu, 22 Jan 2026 22:36:39 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , oliver.yang@linux.alibaba.com, Gao Xiang Subject: [PATCH] erofs: tidy up erofs_init_inode_xattrs() Date: Thu, 22 Jan 2026 22:36:33 +0800 Message-ID: <20260122143633.466466-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 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 Content-Type: text/plain; charset="utf-8" Mainly get rid of the use of `struct erofs_xattr_iter`, as it is no longer needed now that meta buffers are used. This also simplifies the code and uses an early return when there are no xattrs. Signed-off-by: Gao Xiang --- fs/erofs/xattr.c | 62 +++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index dad076ce0108..512b998bdfff 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -29,13 +29,18 @@ static const char *erofs_xattr_prefix(unsigned int idx,= struct dentry *dentry); =20 static int erofs_init_inode_xattrs(struct inode *inode) { - struct erofs_inode *const vi =3D EROFS_I(inode); - struct erofs_xattr_iter it; - unsigned int i; - struct erofs_xattr_ibody_header *ih; + struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; + struct erofs_inode *vi =3D EROFS_I(inode); struct super_block *sb =3D inode->i_sb; + const struct erofs_xattr_ibody_header *ih; + __le32 *xattr_id; + erofs_off_t pos; + unsigned int i; int ret =3D 0; =20 + if (!vi->xattr_isize) + return -ENODATA; + /* the most case is that xattrs of this inode are initialized. */ if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags)) { /* @@ -45,7 +50,6 @@ static int erofs_init_inode_xattrs(struct inode *inode) smp_mb(); return 0; } - if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_XATTR_BIT, TASK_KILLABLE)) return -ERESTARTSYS; =20 @@ -62,66 +66,50 @@ static int erofs_init_inode_xattrs(struct inode *inode) * undefined right now (maybe use later with some new sb feature). */ if (vi->xattr_isize =3D=3D sizeof(struct erofs_xattr_ibody_header)) { - erofs_err(sb, - "xattr_isize %d of nid %llu is not supported yet", + erofs_err(sb, "xattr_isize %d of nid %llu is not supported yet", vi->xattr_isize, vi->nid); ret =3D -EOPNOTSUPP; goto out_unlock; } else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) { - if (vi->xattr_isize) { - erofs_err(sb, "bogus xattr ibody @ nid %llu", vi->nid); - DBG_BUGON(1); - ret =3D -EFSCORRUPTED; - goto out_unlock; /* xattr ondisk layout error */ - } - ret =3D -ENODATA; + erofs_err(sb, "bogus xattr ibody @ nid %llu", vi->nid); + DBG_BUGON(1); + ret =3D -EFSCORRUPTED; goto out_unlock; } =20 - it.buf =3D __EROFS_BUF_INITIALIZER; - ret =3D erofs_init_metabuf(&it.buf, sb, erofs_inode_in_metabox(inode)); - if (ret) - goto out_unlock; - it.pos =3D erofs_iloc(inode) + vi->inode_isize; - - /* read in shared xattr array (non-atomic, see kmalloc below) */ - it.kaddr =3D erofs_bread(&it.buf, it.pos, true); - if (IS_ERR(it.kaddr)) { - ret =3D PTR_ERR(it.kaddr); + pos =3D erofs_iloc(inode) + vi->inode_isize; + ih =3D erofs_read_metabuf(&buf, sb, pos, erofs_inode_in_metabox(inode)); + if (IS_ERR(ih)) { + ret =3D PTR_ERR(ih); goto out_unlock; } - - ih =3D it.kaddr; vi->xattr_name_filter =3D le32_to_cpu(ih->h_name_filter); vi->xattr_shared_count =3D ih->h_shared_count; vi->xattr_shared_xattrs =3D kmalloc_array(vi->xattr_shared_count, sizeof(uint), GFP_KERNEL); if (!vi->xattr_shared_xattrs) { - erofs_put_metabuf(&it.buf); + erofs_put_metabuf(&buf); ret =3D -ENOMEM; goto out_unlock; } =20 - /* let's skip ibody header */ - it.pos +=3D sizeof(struct erofs_xattr_ibody_header); - + /* skip the ibody header and read the shared xattr array */ + pos +=3D sizeof(struct erofs_xattr_ibody_header); for (i =3D 0; i < vi->xattr_shared_count; ++i) { - it.kaddr =3D erofs_bread(&it.buf, it.pos, true); - if (IS_ERR(it.kaddr)) { + xattr_id =3D erofs_bread(&buf, pos + i * sizeof(__le32), true); + if (IS_ERR(xattr_id)) { kfree(vi->xattr_shared_xattrs); vi->xattr_shared_xattrs =3D NULL; - ret =3D PTR_ERR(it.kaddr); + ret =3D PTR_ERR(xattr_id); goto out_unlock; } - vi->xattr_shared_xattrs[i] =3D le32_to_cpu(*(__le32 *)it.kaddr); - it.pos +=3D sizeof(__le32); + vi->xattr_shared_xattrs[i] =3D le32_to_cpu(*xattr_id); } - erofs_put_metabuf(&it.buf); + erofs_put_metabuf(&buf); =20 /* paired with smp_mb() at the beginning of the function. */ smp_mb(); set_bit(EROFS_I_EA_INITED_BIT, &vi->flags); - out_unlock: clear_and_wake_up_bit(EROFS_I_BL_XATTR_BIT, &vi->flags); return ret; --=20 2.43.5