From nobody Sun May 24 19:35:20 2026 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 423FA285CBA for ; Fri, 22 May 2026 06:12:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779430334; cv=none; b=Urkij5MwF3tMahFshHlRaEJ1TuHEKVWo0spb2DUubcZXPIJ8cfsLMsCxeh8f8XiJ4Z0jkGJSCMbp8PsZWoU1KFbfYtClThSHgE+nK4R+Bu4480jEt7qx/65MEuKzXB5mnXJh1egfxyCSWet6WfAVEWYVYEUNpVD2HdgCmbUhm6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779430334; c=relaxed/simple; bh=nRlDh8vw1rX0PIHNv2/NQ+nbuL5Uxd3Kz6C6zaGHVzM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=g0GsLskI09eK+mGiwhYa8TgaPo1MRApx+Ok23RbrS2J+f0wZyUx+2NaiOW1o5h/yTyk0+uLPS/fsvqL/Ytl+tQR7thI25yZkMNIIex8z3snPRydWrXCerNkU0yYKY/WtiCZbkI05f+JTU17Ovg2GKHZEiplua1JMOUR/x+z6rnI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AAdV5S6i; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AAdV5S6i" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-367c2a39fcfso3229010a91.3 for ; Thu, 21 May 2026 23:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779430332; x=1780035132; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6CYsnbQpwdBss8UJyhFzNCVV7Ck7wGnXEx/PkWGq2/s=; b=AAdV5S6iBbImJ+i+xvEaQnsniH1m0asW8vcp2OEJgay4s5zBYQbGdwf3UD/61Vg3OS CzzjId0ZDb8quvZxGb6CBpjqIAnA6fvEI7cMy1xBF2y7DOcVI9UqZU5Dj8EVDoaaNV28 quY1wCO2bQYsjbVa52lXOYgcyK5burDtU4iYgIWmT/z4N2VXR6Ui3joFvuCKH/teGeMd QEYh/uzX0bOD1KaGCeX/QlnSXeeFZ3uRuWD7Iznc5Q8YUOiBX+r0eWPrikAU56lEKd9h YrH4R8hveL7vX/eDtxsBm6rSpM/ZhK1N3sobmFfVD7z/XDttAufu2HMtGkAXgvHfoZCf 1DLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779430332; x=1780035132; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6CYsnbQpwdBss8UJyhFzNCVV7Ck7wGnXEx/PkWGq2/s=; b=VtXTL7eC4rFIihuJ0QosCEjwKzOVX/VwNT3mfVfEy86SAgpT8QkIjc6WVkaEsAoZ9E 8dw3+FR4sqxx+KCD7VZPcDZYQx8iWuBtuTYpoFlkip/PdnLAlQeu2dCr50SikxK2TCu8 QQ7pyOu1ZNU3D+1QzOAvHS95OJpNOChqFqETUrcmFkfAY/nFIMrK5W/scsofuHMQZRga WOK7Z07KnkXWxuzLTpnZbvkFlsRfTUQ2PwyVtWptLr0eruAOAfUtcjw6b6z3cNQaFUBU kwrLdI3k4eN3p5Tx8BK+WURqgD+mD0xARjxnGQoJYJ4bS3bRfBsCx/mv5h7EAMIiQwpe xlng== X-Forwarded-Encrypted: i=1; AFNElJ/hwoYD2jX8tNBy25XK9k4kZ3YHmMlDiHAKKcHQeC6q+Bvu2IKJr5354Veog4WwitU0IJDdVsTqqG3Kxew=@vger.kernel.org X-Gm-Message-State: AOJu0Yzc+1B4mrp41dP8kVxO17BlRLBR3iOyHYe2K0s0jpkrGkCvTT6y hQq1uXqjSYCvs8MpLlwM/75EiDJTjlk/JR6XFx62YGhYrAcvz0XYy7zh X-Gm-Gg: Acq92OE73vs9QD9xI0jEFsZJfNQKa7KZIx6ROQVMuIEMOg+mKldsZ1nlSaSa2GsQv4a JIGqUC12AThO/6Ua/NIu1TUmrWdxuuyc8N098gE60cu28U2WB8FBXvKGgKtekys2jDg19iLEwg4 ptriceeJi9/iXcpqRSApslg1gtbEdEiTwS2zGax7TJ2n4sRgYZOa8oXyJP9u1brJ/62/o2n8NE0 4bJC9AzLL7lNgPUg1eZ7pGuHH5XZDiptb0XyhadzFK+hRcr6fY9015qmtACxJBxMpfmUIcU99wo xUCnp2gqrqdpUVsIpx7q8utMiwLI+L5sa0EKj/6MCmxkw5jMzn3WExjo2B5FZsPSZ2Zx0CWi9BH aJPoV58TktD/RDNJi4YEOob+dytzB2wtNh1TK2kd7dBEBboaoawTxx5XKRVxZPW1JCzNxPLDckp eDVvRMnq2XQLW9HF02na6RkwZKyPIIyDkR36kVSYaxQlWCZYpfjBOylDmttvrCRKzO10k+Bg== X-Received: by 2002:a17:90b:2812:b0:369:b1d3:fa48 with SMTP id 98e67ed59e1d1-36a6761ead9mr2052200a91.18.1779430332431; Thu, 21 May 2026 23:12:12 -0700 (PDT) Received: from qiwenjie-ThinkCentre-M760t.mioffice.cn ([43.224.245.241]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36a71dc0f5csm827473a91.7.2026.05.21.23.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2026 23:12:12 -0700 (PDT) From: Wenjie Qi X-Google-Original-From: Wenjie Qi To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com, qwjhust@gmail.com Subject: [PATCH] f2fs: honor per-I/O write streams for direct writes Date: Fri, 22 May 2026 14:12:06 +0800 Message-ID: <20260522061206.2405336-1-qiwenjie@xiaomi.com> X-Mailer: git-send-email 2.43.0 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" io_uring can pass a per-I/O write stream through kiocb->ki_write_stream, and block direct I/O propagates that value to bio->bi_write_stream. F2FS added FDP stream mapping for DATA writes, but its direct write submit hook always rewrites bio->bi_write_stream from the inode write hint and F2FS temperature. As a result, a direct write with an explicit io_uring write_stream is submitted to the F2FS-selected stream instead of the user-requested stream. Validate an explicit write stream before starting F2FS direct I/O, pass the kiocb through the iomap private pointer, and preserve the per-I/O stream in the direct write bio. When no per-I/O stream is supplied, keep using the existing F2FS temperature-to-stream mapping. Fixes: 42f7a7a50a33 ("f2fs: map data writes to FDP streams") Signed-off-by: Wenjie Qi --- fs/f2fs/file.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 71385ca4163d..20d6e7ab7416 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -5074,17 +5074,36 @@ static int f2fs_dio_write_end_io(struct kiocb *iocb= , ssize_t size, int error, return 0; } =20 +static bool f2fs_valid_write_stream(struct f2fs_sb_info *sbi, u8 write_str= eam) +{ + int i; + + if (!write_stream) + return true; + if (!f2fs_is_multi_device(sbi)) + return write_stream <=3D bdev_max_write_streams(sbi->sb->s_bdev); + + for (i =3D 0; i < sbi->s_ndevs; i++) + if (write_stream > bdev_max_write_streams(FDEV(i).bdev)) + return false; + return true; +} + static void f2fs_dio_write_submit_io(const struct iomap_iter *iter, struct bio *bio, loff_t file_offset) { struct inode *inode =3D iter->inode; struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + struct kiocb *iocb =3D iter->private; enum log_type type =3D f2fs_rw_hint_to_seg_type(sbi, inode->i_write_hint); enum temp_type temp =3D f2fs_get_segment_temp(sbi, type); =20 bio->bi_write_hint =3D f2fs_io_type_to_rw_hint(sbi, DATA, temp); - bio->bi_write_stream =3D - f2fs_io_type_to_write_stream(bio->bi_bdev, DATA, temp); + if (iocb->ki_write_stream) + bio->bi_write_stream =3D iocb->ki_write_stream; + else + bio->bi_write_stream =3D + f2fs_io_type_to_write_stream(bio->bi_bdev, DATA, temp); blk_crypto_submit_bio(bio); } =20 @@ -5122,6 +5141,11 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *ioc= b, struct iov_iter *from, =20 trace_f2fs_direct_IO_enter(inode, iocb, count, WRITE); =20 + if (!f2fs_valid_write_stream(sbi, iocb->ki_write_stream)) { + ret =3D -EINVAL; + goto out; + } + if (iocb->ki_flags & IOCB_NOWAIT) { /* f2fs_convert_inline_inode() and block allocation can block */ if (f2fs_has_inline_data(inode) || @@ -5159,7 +5183,7 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *iocb= , struct iov_iter *from, if (pos + count > inode->i_size) dio_flags |=3D IOMAP_DIO_FORCE_WAIT; dio =3D __iomap_dio_rw(iocb, from, &f2fs_iomap_ops, - &f2fs_iomap_dio_write_ops, dio_flags, NULL, 0); + &f2fs_iomap_dio_write_ops, dio_flags, iocb, 0); if (IS_ERR_OR_NULL(dio)) { ret =3D PTR_ERR_OR_ZERO(dio); if (ret =3D=3D -ENOTBLK) base-commit: 520760b9f9156bf9698de38dc44c614fad68a1f9 --=20 2.43.0