From nobody Sun Oct 5 03:36:57 2025 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 98480246795; Sun, 10 Aug 2025 10:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754820962; cv=none; b=B7zpEWZBK8beXwbNoZgQbMeV/Rr70b8MX+awxA0xRzPyQ8JmwgwXVs2UIsIZHHucs0PUF/xldxAMJe6mCo77614S0n4dTte6J6tIP+YKwjYSh46HcFubXwj8qsHcnDJC3z/TFa5cr5haA+v8nIKKl9/GiNPtmRbmLpCsVEPziPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754820962; c=relaxed/simple; bh=cB6DVaTT+s01L6C+876Rd99+8HN+C74X/wlCK0guPnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mXBRb+D95FENRkiciJqwKu5DWNcEIwSkswxFszpJcOcKShxJ4PhFBMUmRUJfURMr1UKJpoKmPPMmXS6pOIDxQDKA53X/nssNv4cMoeDhPzKgbCX+BBTU2860kX3KDFVP96JdK1LDUXjgBZxrdXoEr9PfVY02aqwN5Taz+2vgH5E= 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=EDyIV9Bq; arc=none smtp.client-ip=209.85.215.173 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="EDyIV9Bq" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-b429abd429aso1733894a12.1; Sun, 10 Aug 2025 03:16:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754820960; x=1755425760; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QqyEjaGkOre4w9EHd3uKzVy/NASFwfYu/ST40fxNR2A=; b=EDyIV9Bqg5q0jDjUtm1U4v/JrWL9jEqgXemjNPXVqH7P76GxtSYC+eod0+0bXKYFnz 2kgkxSmd2NmjX+yzAQ5SEZC84Yiy/hT3CjsCMnqnc9lBeOM8/uq/SKd5IIUfEbugeYMW eqjS6sUgMktseV8pRGV6SpFb27o2zhzc9/bGFQofxJxnm9jI4fYvO1eW0qP2/IgP6Gp+ vhjdPqtOI13fu4Q5kk4ov4eDC2C+thadc7bY6iDRgsNKVzHBtHwhrwmlJtgdHRK8hX5a ITaceYEbaFekx3DHtpZl8vk6MNO4WJvfxAtiHd4TGOJqOxnQe5cLohG4XCfPtYe1cp5z nayQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754820960; x=1755425760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QqyEjaGkOre4w9EHd3uKzVy/NASFwfYu/ST40fxNR2A=; b=XJVQUkC6GM/xhWQ5+ws2Z5AuPu9p5ATOnwIfVJu+V3hF61jqLJfZM7Km94x1wFEoLX Sa1Zi3y0WyIoWaMXovny+lSvBCJS24rd1bdtZtMhoMJ04JyW6UVPCSH/w8pZUF0P4kE5 DYe0uljTR11ktFjMBzgkYgIHNyALv5zDm4030LldP6KvtUgsSiXNwAbEtwNfQwXlY2gz mstd2h2OnwQPwkE0Zq3y0JGacfYeBuz5Z/aXJXyFVSj5FnltHDdKAdXYXUVv8fbnU4Yl yL1fMzEynBuPINEbLjbSDja0ga//SW+McRrr3cK32RYoxMkMoVpygIdChlCitRd/kwt1 cBXA== X-Forwarded-Encrypted: i=1; AJvYcCWA75475q2gTQ3o4WYrsN9PMT+Pfpgxud2r64JgUJAnyBY5ix4GoyFHIYwo6grCdjHrqkHLNll8M+De0/Cp@vger.kernel.org, AJvYcCXXcbvEipwgh60ay1w4VMPBQMkY1foqiqnPBojiWWBEKCyxelNiS4jQ6hKiAuLcLcPkB680Ws+cnpuEaZzg@vger.kernel.org X-Gm-Message-State: AOJu0YwJJnLjErYbZA/zhVFuRNOnsthvD4FDGf6SBmQLlN6up+DNXO8n /8I54M4UvomdvIrntZsaoyfj8UJ0binU0t6j7wj6aB+hnBqbKhO9s5Av X-Gm-Gg: ASbGncuFxvRNqP3/OqtRNuox0QDJ9DUHOfQbunX8+I/K1VUF/n+pmgIBmwzKXr7pXkR E2OCbxa1CB/N5Ijrg2573z3IYODNqpSEOfmlenxAs31Yd94mXvlA75l9wGcQIM3HhN/shKZCVv6 f9oVBFpiUeELD202bhkVlB+qvU4QA+szEiSAXITrhjE4SlhROwU82nGYCLMsaEG6+FrWyTqDB9E mt9XvH85fWbUhTcJI5bC6+6vG1a6JHkT4DTOO/l6cs164gXVEi9bTxK9dkqW7DyLU9m9eiL+kPv NDKNEejlSyX1SUVgwH1SaqVm0yL6wyxvjhHvKt08pNAZtNace79hL5iGkbTA+jkOuFWoBaE7zCh PEyJiw/S1f7pFrepIBvc2so/zK6gYxL6II9g= X-Google-Smtp-Source: AGHT+IGGAYloXbgajoQ/MCYTDAiP+di0jEwd1KkKWrn28Oe8VknTP82jlNHQBOyggGg3giV0hMQ1ug== X-Received: by 2002:a17:90b:4c07:b0:31f:10e:2c01 with SMTP id 98e67ed59e1d1-321839e313emr13194991a91.8.1754820959798; Sun, 10 Aug 2025 03:15:59 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32161259329sm11923432a91.17.2025.08.10.03.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Aug 2025 03:15:59 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jinliang Zheng Subject: [PATCH v2 1/4] iomap: make sure iomap_adjust_read_range() are aligned with block_size Date: Sun, 10 Aug 2025 18:15:51 +0800 Message-ID: <20250810101554.257060-2-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250810101554.257060-1-alexjlzheng@tencent.com> References: <20250810101554.257060-1-alexjlzheng@tencent.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 Content-Type: text/plain; charset="utf-8" From: Jinliang Zheng iomap_folio_state marks the uptodate state in units of block_size, so it is better to check that pos and length are aligned with block_size. Signed-off-by: Jinliang Zheng --- fs/iomap/buffered-io.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index fd827398afd2..934458850ddb 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -234,6 +234,9 @@ static void iomap_adjust_read_range(struct inode *inode= , struct folio *folio, unsigned first =3D poff >> block_bits; unsigned last =3D (poff + plen - 1) >> block_bits; =20 + BUG_ON(*pos & (block_size - 1)); + BUG_ON(length & (block_size - 1)); + /* * If the block size is smaller than the page size, we need to check the * per-block uptodate status and adjust the offset and length if needed --=20 2.49.0 From nobody Sun Oct 5 03:36:57 2025 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 848D0248F4B; Sun, 10 Aug 2025 10:16:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754820963; cv=none; b=OKeZUqSc1vBkEjHavgbDWJp1zuePyaBq89tPZ4pPd+wLwwNGMMK3EjMF3A7/Fuu9aTaH1BQ3EYmMit4pkype6Qr51vbrsCodf1oA+UqvDB/8Zcu741PYyrBtUkpbiOTz1GVYtMPKQBzQGIGSPQ9t2jeJOlpQdz2umy+AULer5dU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754820963; c=relaxed/simple; bh=wb+bp7KgUnZ8vSUBcRKx3kcq2artvUGLOXWnk7mvfjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hek2Hu8KoFe7StfYfJFS8i2tXpCp+/IEJ2HXChjifSF6kGWtJy41T25uRQcTokbA6a8F/zyVLLyc8dSMyB4ZqtCPgaTq8+qDjqMtqIY5irbbwBRwlGLz8y/QX+oHIi9F4LSs9rU3Qy6nLPbhrRVnRf4MmNxjz2sUcWoiw3r147E= 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=YbqLftXl; arc=none smtp.client-ip=209.85.216.44 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="YbqLftXl" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-31ecd40352fso3007968a91.2; Sun, 10 Aug 2025 03:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754820962; x=1755425762; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o5cRw3nes6F1//c4vHntcd1HcPwQ6bE8lShJAHSAbo8=; b=YbqLftXlFVsQPh7BsA4so/TfRKLTUtRblji/LkLvFmu5WVc1+9A1rpU/NDv74f4Vir t6XstLw6wIHUjl13dn6MCfqpSZFaepcFrm1glARdex8xKbWFH9ghDOGo7ZvynMxm99mu 3sJGlK2ZCp90kQ78W5CshpB3jQRE4DA4+3n3jj72EBcnuGN+FAWzaSGxtmA0oc/I7JS4 4BAhdmK64E7w8b8ytOJcrPlQuz/fx7Jjeyo8yOwKz+BbXzCjiSfOStZtEH8DOz/GpYYJ nOnmezhlMW6yWxVVqbUL0+oU/s7/Lob/6WRxdCkm/z2rZdoB7W/Q9w3c8FthpAtnRxrI bBiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754820962; x=1755425762; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o5cRw3nes6F1//c4vHntcd1HcPwQ6bE8lShJAHSAbo8=; b=wmwGngJs7zuRTtnfhhhcTLjqBj5OHdiY7gS5GTF9R4bMvYXZy+Aaje4MPNigNW4Nkg Y7whbOMrMjcUTQ7ata4lVYhfCo2wsNuKs0SLQ/sYktDynEEskeTRYe8qKuwqankhhwi/ J4BdhSDOwM+PWHJnbSoyIXMnxM5ruTtXM5IyaW0Id8AkXFGOr/PtAZkuNkIeJg+SLRKS wpOHXA1jQ+SEovOICBd5WRdw65nX8HeNsdMiZpYjqs9R/E3vSlkClFa3MJ1CmtoY+55i xUZo+InIVtprpxUy9Pv8c0OMHb/wem/Ro2VWBenOMOahrqtqATPW93kkzNTT4kki44Ks wa+A== X-Forwarded-Encrypted: i=1; AJvYcCVIlfft7HPbt33KssGH74m7QXIM/bD9GMZidiOgpTF62eeE15SuhgQp0GnElpHsc1UloMUp3HfGimrLCeot@vger.kernel.org, AJvYcCViaH5V8G8srWpFuvptypu/nynbRDhliP4qXZIfRmBoICxu+jcgZO/Oj1YO8HXhM6dAwLir1DB81IBehys0@vger.kernel.org X-Gm-Message-State: AOJu0Yz1xEKARthV+a/AT37EZDiq/h9sx/oU8wo1eLCeBwlRBv6Z6yQB xAK0ZJb76yFoSfMO5A4A6FWFaREYoEvAOLbJ/LPNt/JPJ3o/whJxITCSjUeuxx5m X-Gm-Gg: ASbGnctbVxF3VLH5rvWw1ppO8xYWogvK25b+h3+biJzWhIit3vkfI6qbKJ9zQ4nGYO/ d9u/GGSbnwFHG+DLFclodYIdq43KCVGBz3WL9qTAspi+Ovtgv0XqP2qcuJROoCg6NXNAxgi4yPI Qb6lw2TlcMTKvtnwxeKBRFRFcet54d4kS0cVMVoXgkj0QDv37Q1mBrwQewLsDU6G70XG0Z9jC8i asZR9DQHloD5Qwo7pRFEzEihmOaXZivh8x52aC6eCft+XGhQsxvVsT+yTqhxtLXZM/weNB8iOdI jdbagbmBHUM/pn0pFXGCHWxw9KA0xRL62APob99zCV7NqwtMoAf510rRY7/22ymNP68vIjs4pAL 92+1zq2/m9BMSNW1Vyi90fDAc9VLDzAc5uwA= X-Google-Smtp-Source: AGHT+IFeEfO31R0TMLg4Yws2ieVAGTbmuCabmHxLHcKYeWQwwtzv4fcUw1w2ovhqNdrRsUTxPNU51A== X-Received: by 2002:a17:90b:1c08:b0:31a:bc78:7fe1 with SMTP id 98e67ed59e1d1-32183b3f11fmr15915269a91.18.1754820961697; Sun, 10 Aug 2025 03:16:01 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32161259329sm11923432a91.17.2025.08.10.03.16.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Aug 2025 03:16:01 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jinliang Zheng Subject: [PATCH v2 2/4] iomap: move iter revert case out of the unwritten branch Date: Sun, 10 Aug 2025 18:15:52 +0800 Message-ID: <20250810101554.257060-3-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250810101554.257060-1-alexjlzheng@tencent.com> References: <20250810101554.257060-1-alexjlzheng@tencent.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 Content-Type: text/plain; charset="utf-8" From: Jinliang Zheng This reverts commit e1f453d4336d ("iomap: do some small logical cleanup in buffered write"), for preparetion for the next patches which allow iomap_write_end() return a partial write length. Signed-off-by: Jinliang Zheng --- fs/iomap/buffered-io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 934458850ddb..641034f621c1 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1019,6 +1019,11 @@ static int iomap_write_iter(struct iomap_iter *iter,= struct iov_iter *i, =20 if (old_size < pos) pagecache_isize_extended(iter->inode, old_size, pos); + if (written < bytes) + iomap_write_failed(iter->inode, pos + written, + bytes - written); + if (unlikely(copied !=3D written)) + iov_iter_revert(i, copied - written); =20 cond_resched(); if (unlikely(written =3D=3D 0)) { @@ -1028,9 +1033,6 @@ static int iomap_write_iter(struct iomap_iter *iter, = struct iov_iter *i, * halfway through, might be a race with munmap, * might be severe memory pressure. */ - iomap_write_failed(iter->inode, pos, bytes); - iov_iter_revert(i, copied); - if (chunk > PAGE_SIZE) chunk /=3D 2; if (copied) { --=20 2.49.0 From nobody Sun Oct 5 03:36:57 2025 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 AC271248F5F; Sun, 10 Aug 2025 10:16:04 +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=1754820966; cv=none; b=KOLH/ijx7hezK1K6OZPaix4Ba41aOKHErK79WbGerlY8hh1x+Oi2N5R4U3G1TQ/GdlAOHkNYaMAruUob6ipj2sZHQzHb0FUKcmdxEPA5uKBzLSJN2zIqIW7TjlPUokh9LmkPYrboaHwibwvXV8z3vTfWHH3P4mGJpZgyYfsG50s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754820966; c=relaxed/simple; bh=pM70ONMWkVFOgrxrh7xrXySYMx9EuPeAq6ng5Zyjn7c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lA65RWm6A/tz7Ipa+XIOznDCmzYWUi+UYLTlz6Dn0W+L8iMTnQko3RoQp2XzSYyTRlzQb6SnZMeggXWE/fS+z79t+zqUJWo7h/Wz6gUTG2kX5p1Y01EIWhQpMxisHTxv5jVQp/o0Li2NWEjI4AriM5fsNaA97hlzv0qNrcnUr8A= 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=Zjs3oJDl; 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="Zjs3oJDl" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-31f325c1bc1so3091397a91.1; Sun, 10 Aug 2025 03:16:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754820964; x=1755425764; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3JpF+zMohgtWkSabMp3xpC3OoiSf5ZyK7hwqHgyEfgs=; b=Zjs3oJDlyKg0hRJTYW3s7ZxwSQq3sLUs6aEMnEVJZjy4955TCOGqfNq55KAKyUk+6m V8X6IFEI1W5oeiTApWOcFsoB0GI1BsrYCp8qlbFRy2DENQG+2awQu9BrW1C1cPjZOfLa 8LnyxJuWi39cLOjwCP023FM6/ZUwrvJibViRCUX3XezJa43BXUTmj7g2LqA79ij5XxWs pfIYqDwP8K0yIg9x3RJPPsDKT8TALXXRLgjNzmMF0Wg4pu2kkNmR109g67F68L9kdHk9 VrxaLuoL7gp0QyRW1FAPfN6hM0R+T+MzVyp2XmxRg/69EvBC6xG12r5bxJqg7v/iuyia 25AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754820964; x=1755425764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3JpF+zMohgtWkSabMp3xpC3OoiSf5ZyK7hwqHgyEfgs=; b=YRAByXFulG/017Hj2blFPKSp9lagl3LSVNBTBJd1Trx0pWqp0moSQJxbwY7PdupkMn 2AnVeTGRJQiy6wefVMg0k9w1J3SOAvu0sjMVqCBwnlOQE8aYiIkgkkmHjGxlHnRgAMgi GWpYA/xurJ/CmNqqnCVLZI7N30cKpi//tD/AaeYEp8KqBjljpuad0E4Ph/G8pCmuGc6Z UPVQx16Iv6ICGoh0pabRYrH+Y7kFzuUqjWxSdLfQ8iZQwtLqtexV/3tcDScJwbPzSpzv t8tfR7E+YXeqMZUCpuK/Nc44of259B6QwfQ/WcrwRGQhTAQYW5cvzaY6Epalx1UwgeQM kd/w== X-Forwarded-Encrypted: i=1; AJvYcCVh78ANxk/Lx9Hl5JiTNA/4Ip5N/Lp6PvL37/kAZQVRJACXyru3CM/5RYXnWNhuYvp8MCFyDe9caYaYy9B7@vger.kernel.org, AJvYcCXCITELRFeSjhDlTwTrjqGGMYQPtsIWk1MnUt5sHKPYbQxgZ0Omg/QW3Bgght8A+joedik1GxiuyHESLpfj@vger.kernel.org X-Gm-Message-State: AOJu0YyXPb833EG40KEUujPeC4nsYS8DL7Uo3y/seUjD7TkYDQ027jRD ldcfk0taUIaAmhiFXBmc/HR63GDe1271Nn6f2MGF3RwNu08EGDpt+7aP X-Gm-Gg: ASbGncthlRBXx1dGIugpRRiWrkAdGzim9GmNcaq9F573SU+19nb1//+yIahKR587QVz hwoLJRZQffpYowpEnpSM2aQWazv2j+3+UYo5fXm49AtasUfq38BsQbSxL25mumZiZkK5qzpq12q TqQKxFO3FPBaes1X4wWNqv74+66lahtYTBBbtPj9cgszNJZZ4KJQnE8uLHZnm2PMsYCBR2P6RSu gbxNFLB/3bujPzBC0lsE+ArCorAEGgJpP10bdmpklYheJDrtAuWRtcdpa9e5NFkAsF9Rr3vB2jr cI1JzO8aUITNwq+t1u460yXJY9NqdLM5yYYldk4p9FFA5sANeUVC/+ERsGl+8l45CrhfPgx4Gou dk/5yvFBl/JKU7ZKEAjvhphLhbX91s4HuwHc= X-Google-Smtp-Source: AGHT+IFoyTnVPeVwt4GwqWXdRJFvf0VOIWLsKNY0q91al0tJ6xoRHw9fxfYy3W9/HvDj2sLsiKYGTw== X-Received: by 2002:a17:90b:2e49:b0:31f:d0:95bc with SMTP id 98e67ed59e1d1-32183c4585dmr11018044a91.25.1754820963756; Sun, 10 Aug 2025 03:16:03 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32161259329sm11923432a91.17.2025.08.10.03.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Aug 2025 03:16:03 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jinliang Zheng Subject: [PATCH v2 3/4] iomap: make iomap_write_end() return the number of written length again Date: Sun, 10 Aug 2025 18:15:53 +0800 Message-ID: <20250810101554.257060-4-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250810101554.257060-1-alexjlzheng@tencent.com> References: <20250810101554.257060-1-alexjlzheng@tencent.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 Content-Type: text/plain; charset="utf-8" From: Jinliang Zheng In the next patch, we allow iomap_write_end() to conditionally accept partial writes, so this patch makes iomap_write_end() return the number of accepted write bytes in preparation for the next patch. Signed-off-by: Jinliang Zheng --- fs/iomap/buffered-io.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 641034f621c1..f80386a57d37 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -873,7 +873,7 @@ static int iomap_write_begin(struct iomap_iter *iter, return status; } =20 -static bool __iomap_write_end(struct inode *inode, loff_t pos, size_t len, +static int __iomap_write_end(struct inode *inode, loff_t pos, size_t len, size_t copied, struct folio *folio) { flush_dcache_folio(folio); @@ -890,11 +890,11 @@ static bool __iomap_write_end(struct inode *inode, lo= ff_t pos, size_t len, * redo the whole thing. */ if (unlikely(copied < len && !folio_test_uptodate(folio))) - return false; + return 0; iomap_set_range_uptodate(folio, offset_in_folio(folio, pos), len); iomap_set_range_dirty(folio, offset_in_folio(folio, pos), copied); filemap_dirty_folio(inode->i_mapping, folio); - return true; + return copied; } =20 static void iomap_write_end_inline(const struct iomap_iter *iter, @@ -915,10 +915,10 @@ static void iomap_write_end_inline(const struct iomap= _iter *iter, } =20 /* - * Returns true if all copied bytes have been written to the pagecache, - * otherwise return false. + * Returns number of copied bytes have been written to the pagecache, + * zero if block is partial update. */ -static bool iomap_write_end(struct iomap_iter *iter, size_t len, size_t co= pied, +static int iomap_write_end(struct iomap_iter *iter, size_t len, size_t cop= ied, struct folio *folio) { const struct iomap *srcmap =3D iomap_iter_srcmap(iter); @@ -926,7 +926,7 @@ static bool iomap_write_end(struct iomap_iter *iter, si= ze_t len, size_t copied, =20 if (srcmap->type =3D=3D IOMAP_INLINE) { iomap_write_end_inline(iter, folio, pos, copied); - return true; + return copied; } =20 if (srcmap->flags & IOMAP_F_BUFFER_HEAD) { @@ -934,7 +934,7 @@ static bool iomap_write_end(struct iomap_iter *iter, si= ze_t len, size_t copied, =20 bh_written =3D block_write_end(pos, len, copied, folio); WARN_ON_ONCE(bh_written !=3D copied && bh_written !=3D 0); - return bh_written =3D=3D copied; + return bh_written; } =20 return __iomap_write_end(iter->inode, pos, len, copied, folio); @@ -1000,8 +1000,7 @@ static int iomap_write_iter(struct iomap_iter *iter, = struct iov_iter *i, flush_dcache_folio(folio); =20 copied =3D copy_folio_from_iter_atomic(folio, offset, bytes, i); - written =3D iomap_write_end(iter, bytes, copied, folio) ? - copied : 0; + written =3D iomap_write_end(iter, bytes, copied, folio); =20 /* * Update the in-memory inode size after copying the data into @@ -1315,7 +1314,7 @@ static int iomap_unshare_iter(struct iomap_iter *iter, do { struct folio *folio; size_t offset; - bool ret; + int ret; =20 bytes =3D min_t(u64, SIZE_MAX, bytes); status =3D iomap_write_begin(iter, write_ops, &folio, &offset, @@ -1327,7 +1326,7 @@ static int iomap_unshare_iter(struct iomap_iter *iter, =20 ret =3D iomap_write_end(iter, bytes, bytes, folio); __iomap_put_folio(iter, write_ops, bytes, folio); - if (WARN_ON_ONCE(!ret)) + if (WARN_ON_ONCE(ret !=3D bytes)) return -EIO; =20 cond_resched(); @@ -1388,7 +1387,7 @@ static int iomap_zero_iter(struct iomap_iter *iter, b= ool *did_zero, do { struct folio *folio; size_t offset; - bool ret; + int ret; =20 bytes =3D min_t(u64, SIZE_MAX, bytes); status =3D iomap_write_begin(iter, write_ops, &folio, &offset, @@ -1406,7 +1405,7 @@ static int iomap_zero_iter(struct iomap_iter *iter, b= ool *did_zero, =20 ret =3D iomap_write_end(iter, bytes, bytes, folio); __iomap_put_folio(iter, write_ops, bytes, folio); - if (WARN_ON_ONCE(!ret)) + if (WARN_ON_ONCE(ret !=3D bytes)) return -EIO; =20 status =3D iomap_iter_advance(iter, &bytes); --=20 2.49.0 From nobody Sun Oct 5 03:36:57 2025 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (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 6581223FC42; Sun, 10 Aug 2025 10:16:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754820968; cv=none; b=OA0MIuIQD6QBaxcl3RvlCnvQCMRZtka9AxN0AEqBYuRLEr6uL9p1KADcs300r0XF6CQJ6I1oHVQpqVXe2ykAaX0E4jM8D+8JXEhcgD46rlVDCsVZmdxYLVBQtZF06R0gQcGonDPhEk4K6slX2Mrfy0iqZvoa16GrgvhRYrc6HwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754820968; c=relaxed/simple; bh=rDQIx1s6A6hGmi9HbZcEjXtoTdyxpU+DpS5cyiDpCqs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DDe/fbt9pB5rHEhzhk5lpxR/RHoj/jqZNP0DwqDCCgQZvhGwTaI3r8AAUbqOvegCEJJLSEVzujjKNUuRCKvhOd3UfkygbxC+YVGXeTebvJAcTnDkDSW9fII1o6PfiLz9M6jb2YPkvb7wmG8kv9sXkrQwDWGv34hIzRKfpLHHQxE= 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=mFbw6hvG; arc=none smtp.client-ip=209.85.215.175 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="mFbw6hvG" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-b34a8f69862so2490250a12.2; Sun, 10 Aug 2025 03:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754820967; x=1755425767; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y2OT5F7bZ/arjZTso2AUwwEE0thLjDqJvHVad93pKuM=; b=mFbw6hvGLvoMahE0p51EHAvIUB3WPzywNgIvWj8QsbqTaq+/pMM9y8Gdi/hXytJqep 1pru4AksJ9UddzlisCFr0aEjZTR2Bbja7tJb3ws38trz54NCBZu/MA9G9Wt2meCKQlfv +zxDKifr9/SWtJ+QaP9T48drAZ9WzG4+gBAVDPxqVPH7F5ql4NGSC8iVMleBBnwGlBC3 iTraatSIQ4b3Htuuu3G32Zw6APLScJo8S4aa/YByMn4f4SDJo99XIayvPQ4yYuKJYdKQ uwQ38oB3WSh2boQolLrmicWKr2Kmo9nCPMAP7B8BohAYJD3Lrr1FyQ5ydv9kk4OGleiv IiMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754820967; x=1755425767; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y2OT5F7bZ/arjZTso2AUwwEE0thLjDqJvHVad93pKuM=; b=w3LLOQxDrJY2Mfeba7CitJANmCaTVDu159IEHed6qDcwISS+9lgMjyklrCILjbaPtV mFiEAXFwRBZ/UQeTVj5env44XC3JPm8D1COFJM6lLDVDfLlAJLXvwNwnJTBOAvZDkvrV 9qLzejUgmJXc1QEfjET3IVg/gWoXON/4mpuCVpl+Sr3zN+UpAXektU3vyh0E38cmSMMa TVxebOgXNy3JQnXgD3/9Cinn2KvBJpcfmIiHpUw8e3Tckr87AdVBKVrZYTgNz6O6pTJ/ pyiPALipThCH3B1pMvDoHOvsx9eYjzSUGuZjUJVQI0X/3Q8vsP7NJUbxyZZyfxCCZFJ2 iFoA== X-Forwarded-Encrypted: i=1; AJvYcCWJy+L+DYt1sFEwR/9e/dTbvpf3plkZFncRHHv7bAOn8juyDkGaVvMBfKBN0Hsdx6YPm2M4Jz54kd7pcDID@vger.kernel.org, AJvYcCXQM74ixIaCknYoLjRkw3XFdGoMPRXsHU2gqxdxAg21uRKScB1uI/tnp4aQcswg1ZHNV38EfQVvUxF4sV5Y@vger.kernel.org X-Gm-Message-State: AOJu0Yyp1euaY+W1QPX3wfLxb/4zDEIT4vzOWx+r0NnWG5oBwZq23PRg +zaUs2IG1SMZa/FA9YLHJNDE0YYRrs+3mvbEr6mZ/HNLeHpH+KwceQjM X-Gm-Gg: ASbGncsLcPywx2W386SnOAGEkJokk8IfLnqGV91jTk1iRw+i1UUeLqPoEny5BxvXxc6 j4tA3CK3fvIxB9qgcuzjWBTNJK3nOPnt7CfDz4dp3f9CwAtGFWnBB/b49mQRtxG+XFinh5mQAx/ eW4JzM046p3/EuUpN1xnlBfmHOHQaHkRiKmpnt4rBfWa5LzmyLtZs/89tWzrCG6RmmkUXCpL+ft oVAjIIFoaxU49SVUyoMkUd2YxQdUHbSvsqRzV1ipv7fU4zOaUwNIc/nH0jxsXp1OfeZdM9K4xal HtT4gqmZWIfmmnG5JKMr8AhBEJ5YFhu1JTtqN5blqHo7dZlLBCHCrOyePwotCavI+he+vDF1vVB YY1Fij/aTBCNzoyW4g8N/D8qU2Py8pJPapjXwBmNIO4Rfcg== X-Google-Smtp-Source: AGHT+IEfzIB/bMwT0gz0dl/X1susnwXrNxFT85X7Tg/EAtUZIdu1PG7GaBu71SPqPgTGFInFXAWt6A== X-Received: by 2002:a17:90b:48c4:b0:31e:fe18:c6df with SMTP id 98e67ed59e1d1-32183e32f54mr15165340a91.16.1754820966597; Sun, 10 Aug 2025 03:16:06 -0700 (PDT) Received: from VM-16-24-fedora.. ([43.153.32.141]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32161259329sm11923432a91.17.2025.08.10.03.16.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Aug 2025 03:16:06 -0700 (PDT) From: alexjlzheng@gmail.com X-Google-Original-From: alexjlzheng@tencent.com To: brauner@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jinliang Zheng Subject: [PATCH v2 4/4] iomap: don't abandon the whole thing with iomap_folio_state Date: Sun, 10 Aug 2025 18:15:54 +0800 Message-ID: <20250810101554.257060-5-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250810101554.257060-1-alexjlzheng@tencent.com> References: <20250810101554.257060-1-alexjlzheng@tencent.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 Content-Type: text/plain; charset="utf-8" From: Jinliang Zheng With iomap_folio_state, we can identify uptodate states at the block level, and a read_folio reading can correctly handle partially uptodate folios. Therefore, when a partial write occurs, accept the block-aligned partial write instead of rejecting the entire write. Signed-off-by: Jinliang Zheng --- fs/iomap/buffered-io.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index f80386a57d37..19bf879f3333 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -873,6 +873,25 @@ static int iomap_write_begin(struct iomap_iter *iter, return status; } =20 +static int iomap_trim_tail_partial(struct inode *inode, loff_t pos, + size_t copied, struct folio *folio) +{ + struct iomap_folio_state *ifs =3D folio->private; + unsigned block_size, last_blk, last_blk_bytes; + + if (!ifs || !copied) + return 0; + + block_size =3D 1 << inode->i_blkbits; + last_blk =3D offset_in_folio(folio, pos + copied - 1) >> inode->i_blkbits; + last_blk_bytes =3D (pos + copied) & (block_size - 1); + + if (!ifs_block_is_uptodate(ifs, last_blk)) + copied -=3D min(copied, last_blk_bytes); + + return copied; +} + static int __iomap_write_end(struct inode *inode, loff_t pos, size_t len, size_t copied, struct folio *folio) { @@ -886,12 +905,15 @@ static int __iomap_write_end(struct inode *inode, lof= f_t pos, size_t len, * read_folio might come in and destroy our partial write. * * Do the simplest thing and just treat any short write to a - * non-uptodate page as a zero-length write, and force the caller to - * redo the whole thing. + * non-uptodate block as a zero-length write, and force the caller to + * redo the things begin from the block. */ - if (unlikely(copied < len && !folio_test_uptodate(folio))) - return 0; - iomap_set_range_uptodate(folio, offset_in_folio(folio, pos), len); + if (unlikely(copied < len && !folio_test_uptodate(folio))) { + copied =3D iomap_trim_tail_partial(inode, pos, copied, folio); + if (!copied) + return 0; + } + iomap_set_range_uptodate(folio, offset_in_folio(folio, pos), copied); iomap_set_range_dirty(folio, offset_in_folio(folio, pos), copied); filemap_dirty_folio(inode->i_mapping, folio); return copied; --=20 2.49.0