Skip to contentSkip to conversation

gfs2: Fix usage of bio->bi_status in gfs2_end_log_write

PATCH Applied Andrew Price 2 participants 2 messages Apr 23, 2025 GFS2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gfs2: Fix usage of bio->bi_status in gfs2_end_log_write

bio->bi_status is an index into the blk_errors array, not an errno. Its __bitwise tag is cast away here, resulting in a sparse warning:

fs/gfs2/lops.c:207:22: warning: cast from restricted blk_status_t

We could either add __force to the cast and continue logging bi_status in the error message, or we could look up the errno in the array and log that. As sdp->sd_log_error is used as an errno in all other cases, look up the errno here for consistency.

---
 fs/gfs2/lops.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/gfs2/lops.c +4 -2
index 0fd3b5ec7d8cc..a1022635abc98 100644
@@ -204,9 +204,11 @@ static void gfs2_end_log_write(struct bio *bio)
 	struct bvec_iter_all iter_all;
 
 	if (bio->bi_status) {
-		if (!cmpxchg(&sdp->sd_log_error, 0, (int)bio->bi_status))
+		int err = blk_status_to_errno(bio->bi_status);
+
+		if (!cmpxchg(&sdp->sd_log_error, 0, err))
 			fs_err(sdp, "Error %d writing to journal, jid=%u\n",
-			       bio->bi_status, sdp->sd_jdesc->jd_jid);
+			       err, sdp->sd_jdesc->jd_jid);
 		gfs2_withdraw_delayed(sdp);
 		/* prevent more writes to the journal */
 		clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
Signature · 1 line
2.49.0
maintainer Applied
#1 lore raw
Quoted 34 lines · Andrew Price

bio->bi_status is an index into the blk_errors array, not an errno. Its __bitwise tag is cast away here, resulting in a sparse warning:

fs/gfs2/lops.c:207:22: warning: cast from restricted blk_status_t

We could either add __force to the cast and continue logging bi_status in the error message, or we could look up the errno in the array and log that. As sdp->sd_log_error is used as an errno in all other cases, look up the errno here for consistency.

---
 fs/gfs2/lops.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/gfs2/lops.c +4 -3
index 0fd3b5ec7d8cc..a1022635abc98 100644
@@ -204,9 +204,11 @@ static void gfs2_end_log_write(struct bio *bio)
        struct bvec_iter_all iter_all;
 
        if (bio->bi_status) {
-               if (!cmpxchg(&sdp->sd_log_error, 0, (int)bio->bi_status))
+               int err = blk_status_to_errno(bio->bi_status);
+
+               if (!cmpxchg(&sdp->sd_log_error, 0, err))
                        fs_err(sdp, "Error %d writing to journal, jid=%u\n",
-                              bio->bi_status, sdp->sd_jdesc->jd_jid);
+                              err, sdp->sd_jdesc->jd_jid);
                gfs2_withdraw_delayed(sdp);
                /* prevent more writes to the journal */
                clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
--
Quoted 1 line

2.49.0

Applied, thanks.

Andreas