From nobody Fri Dec 19 11:30:57 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 C86962EB873 for ; Mon, 8 Dec 2025 12:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765195846; cv=none; b=oPlUnbVBfHG0WaqupNmw5qefrgOblkNqFuGVT78j4Wwn0RVYoiu0smK+Wd+Bsj0SdwzPt8OcvDYi7VIICwMM1DvBv1IsR9dFfPvwHZYLYAaA/zyTsJBjrs95f1y4UP5e4HKz2YtlNKzrbAG2dC9eZIyXomAVJT8rWOPpxt9T3iI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765195846; c=relaxed/simple; bh=CqnLgM9bxGlrVxyPzoFh+1bkpkx8bpzOqL+eTMygvt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BOjARUu+2DtyQfClwCRqn/P8ZWZLlWVLfHTUjkedZKYYfjSyKBUE50N5akXrjf+12yocB8u11M66RVoKoheKoIYaLFWroY8y++vjv+n0/Bjeiq0RJ9czaJzEQzqxpbl2uoST/bT7DVR0NV7OCZue5yhY3O1zAzoVZzH8fx2jw0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JxYutkVP; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JxYutkVP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765195843; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H4kcdoSw7LDS9+yf8C2Tt+DzBl7/RT2q80T0a13WnlE=; b=JxYutkVPyOPP5opqr+aMfdfZNKJHp2pEXoxiAvMl4m41p6OBM1LmWNxBy/S/TpxqUb6URP PfZKeQVSMYVA935SUN+rQvMkdJDNiIq21C+jllza6XW4bB/qLx5TUTANOLB8YXPeWFoF4h AXOi+smClTdLPFssP5m+go+FcVkJzds= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-NPV6KeqjMjW1Oqy3pjOVkA-1; Mon, 08 Dec 2025 07:10:40 -0500 X-MC-Unique: NPV6KeqjMjW1Oqy3pjOVkA-1 X-Mimecast-MFC-AGG-ID: NPV6KeqjMjW1Oqy3pjOVkA_1765195839 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 21E1B18001D7; Mon, 8 Dec 2025 12:10:39 +0000 (UTC) Received: from pasta.fast.eng.rdu2.dc.redhat.com (unknown [10.44.34.3]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC7F41956095; Mon, 8 Dec 2025 12:10:35 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , Jens Axboe , Chris Mason , David Sterba Cc: Andreas Gruenbacher , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-raid@vger.kernel.org, dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [RFC 03/12] bio: add bio_set_errno Date: Mon, 8 Dec 2025 12:10:10 +0000 Message-ID: <20251208121020.1780402-4-agruenba@redhat.com> In-Reply-To: <20251208121020.1780402-1-agruenba@redhat.com> References: <20251208121020.1780402-1-agruenba@redhat.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-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" Add a bio_set_errno(bio, errno) helper that sets bio->bi_status to errno_to_blk_status(errno) if errno !=3D 0. Replace instances of this pattern in the code with a call to the new helper. The WRITE_ONCE() in bio_set_errno() ensures that the compiler won't reorder things in a weird way, but it isn't needed to prevent tearing because a single-byte field like bi_status cannot tear. Created with Coccinelle using the following semantic patch: @@ struct bio *bio; expression errno; @@ - if (errno) - bio->bi_status =3D errno_to_blk_status(errno); + bio_set_errno(bio, errno); @@ struct bio *bio; expression errno; @@ - if (unlikely(errno)) - bio->bi_status =3D errno_to_blk_status(errno); + bio_set_errno(bio, errno); Signed-off-by: Andreas Gruenbacher --- drivers/block/drbd/drbd_req.c | 3 +-- drivers/nvdimm/pmem.c | 3 +-- include/linux/bio.h | 8 ++++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c index d15826f6ee81..bd4bc882cc5a 100644 --- a/drivers/block/drbd/drbd_req.c +++ b/drivers/block/drbd/drbd_req.c @@ -176,8 +176,7 @@ void start_new_tl_epoch(struct drbd_connection *connect= ion) void complete_master_bio(struct drbd_device *device, struct bio_and_error *m) { - if (unlikely(m->error)) - m->bio->bi_status =3D errno_to_blk_status(m->error); + bio_set_errno(m->bio, m->error); bio_endio(m->bio); dec_ap_bio(device); } diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 05785ff21a8b..a2f8b5a85326 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -232,8 +232,7 @@ static void pmem_submit_bio(struct bio *bio) if (bio->bi_opf & REQ_FUA) ret =3D nvdimm_flush(nd_region, bio); =20 - if (ret) - bio->bi_status =3D errno_to_blk_status(ret); + bio_set_errno(bio, ret); =20 bio_endio(bio); } diff --git a/include/linux/bio.h b/include/linux/bio.h index 16c1c85613b7..38ebf03036cb 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -389,6 +389,14 @@ static inline void bio_wouldblock_error(struct bio *bi= o) bio_endio(bio); } =20 +blk_status_t errno_to_blk_status(int errno); + +static inline void bio_set_errno(struct bio *bio, int errno) +{ + if (errno) + WRITE_ONCE(bio->bi_status, errno_to_blk_status(errno)); +} + /* * Calculate number of bvec segments that should be allocated to fit data * pointed by @iter. If @iter is backed by bvec it's going to be reused --=20 2.51.0