Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1130496rdg; Fri, 13 Oct 2023 11:04:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjl6Ho0NqzY0s4BqG9XLyjFgRCWWnFTCwp6OiOueXs6j2l2vHE8Q+SHyjKv+Hfcvcnky/g X-Received: by 2002:a05:6a00:3995:b0:68c:57c7:1eb0 with SMTP id fi21-20020a056a00399500b0068c57c71eb0mr33122742pfb.11.1697220265598; Fri, 13 Oct 2023 11:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697220265; cv=none; d=google.com; s=arc-20160816; b=LEKDP2UIYW/v1Sni5iDWOyGG1rRcAiOEsphOzuPVBIqvhIPfXMflQ+jtBO02bKng+7 s5u93jimU9TERsNDv/bOzotH1fMZcdvFMppPDl0VUfC0HxGYNuXX+yBaV2Uyn9dikj9K 1AGcOQpIMaNNTb1huP+mmuX6guV89vD1K/3/+G3IlBnR23/Ik0fI3TN/BJXD2SyR5Ozw s0r0b2jUIcbSFsvSrMSIqnhotYwxWEYJsqOMuQwhPzMHfLQd12dvwkFxZZYRDP1wQpp4 X8eLVIZ5q4xEUmmIylXaFxsALnsdFUx2rPNLhWNK1QvdKxMWJmVG40iQJnXkA3o5dmfz oTjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:subject:cc:to:from:message-id:date :dkim-signature; bh=sfjXdT7cAyc2iDE1Sn8k9xOdZrrZkWk2OCvv9E04Z4I=; fh=5jKeZeyH1Lr6BVSieo+kWmkikjCVG7DrV6F+qJQtP6w=; b=s1FlOvbjfxYogoVWgobF0EgMPmq34JyICEyUCXPKVQi0HfrEyqp0nRUVjtAr/DlafY ncT4GkpnPrTsctMvgxgZOMXt9b1JO3lhndXc8AnBA3M3iRLbJm1K+dbYVD81SeWuk/tc qAVNQUe5xEu6VPqnJU4BUA1sU2J/7z+d/UQSXDBZ6uzPmDERPE4md/L5sTIlf7Pmt4QM EPT2TtVw+Uabk0i+oqw/KUhIcG2y2VndtYQEi0l3Xx3HtmmNc3FuUKkW8XOfyyIcmqkk Cwz57UV16oE6E2Ea99t5XhI2hsi7xMF8o3SS8AAhyDnlsoLvQ+9Wldzxf3M7Af1x84ds tL+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="QdaF/6Qw"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id z18-20020aa79e52000000b00690ffbb46e6si208635pfq.261.2023.10.13.11.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 11:04:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="QdaF/6Qw"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 3EB3983A47B4; Fri, 13 Oct 2023 11:04:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229697AbjJMSEG (ORCPT + 99 others); Fri, 13 Oct 2023 14:04:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbjJMSEF (ORCPT ); Fri, 13 Oct 2023 14:04:05 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47056C0; Fri, 13 Oct 2023 11:04:02 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c8a1541232so20947615ad.0; Fri, 13 Oct 2023 11:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697220241; x=1697825041; darn=vger.kernel.org; h=in-reply-to:subject:cc:to:from:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=sfjXdT7cAyc2iDE1Sn8k9xOdZrrZkWk2OCvv9E04Z4I=; b=QdaF/6QwyBMIGP6nyfhSjJc3kMeaVFN71Yq65vWsCx69+5GFfPe0j+j8nqEhKj5LMS oFBoRQkQAdhnWw3xHoNHke8hRmEpAlUgcjUoaQarCuQ9L4oX6rl9OttBroqNhAbKaXc4 aBdVeNobDhliH2L3DxR87Zlwz3n5SMmPmgEpNywKbV5gWzXYfDSdAppsLX8eZYOju3/B QLotmfJwt0okb+xrDInJVE+TXSu2N7BVxgySqsKafnZit/81tbJLEBj3fU0yJVbsiRSV BVulcVusii0Svg+ogT1fvSxx8TKXoHEOzUybIAzMbNi/hCBijfh8BBFpMjS1XkLycLal B4WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697220241; x=1697825041; h=in-reply-to:subject:cc:to:from:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=sfjXdT7cAyc2iDE1Sn8k9xOdZrrZkWk2OCvv9E04Z4I=; b=neuizUH+b+KRCbadZlRMZ1xDOkPBz/hxPRnU5G7NXzgkcr374L6qWJEoAFS/NBq8Ww kf4aJoVWSIlfrSI/zzVYyteMScLoma2Yg0X9VQlRUkeKcQs143SPPHiqsHDVxYr7wpqZ BnOMePmdBYonEOY+NIDL2By6J2oRzsU5tDReGFHfyc0yU3L1UOi14FfjmhGBxHW3/964 182hSSrPnDYRPlWGOSmnD9rIrkfdjkGjtNwXEu+JdM28skV3hv9yrvLdMyPNsm54mFze MgKbMge2gB0E8zngylMIXRwKdgvp0qsxEV5NGY8HIKFgnu8NdOl/6BI3ryVecvvk+6Yx nV8Q== X-Gm-Message-State: AOJu0Yz6lnng1SSkuFVHQbPE8dYhk3Ya0kjU3jl4GboPFNf1eiw0SGsE jhH4LeeNPlM8z6xDL/B4R9XxKwV5IjY= X-Received: by 2002:a17:902:f688:b0:1c9:e830:160d with SMTP id l8-20020a170902f68800b001c9e830160dmr4544137plg.22.1697220241158; Fri, 13 Oct 2023 11:04:01 -0700 (PDT) Received: from dw-tp ([2401:4900:1cc4:c403:d76d:9a77:e4fd:36be]) by smtp.gmail.com with ESMTPSA id p4-20020a170902eac400b001b9da8b4eb7sm4170044pld.35.2023.10.13.11.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 11:04:00 -0700 (PDT) Date: Fri, 13 Oct 2023 23:33:56 +0530 Message-Id: <87edhyielv.fsf@doe.com> From: Ritesh Harjani (IBM) To: Jan Kara , Ted Tso Cc: linux-ext4@vger.kernel.org, Gao Xiang , Dave Chinner , Jan Kara , stable@vger.kernel.org Subject: Re: [PATCH v3] ext4: Properly sync file size update after O_SYNC direct IO In-Reply-To: <20231013121350.26872-1-jack@suse.cz> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 13 Oct 2023 11:04:07 -0700 (PDT) Jan Kara writes: > Gao Xiang has reported that on ext4 O_SYNC direct IO does not properly > sync file size update and thus if we crash at unfortunate moment, the > file can have smaller size although O_SYNC IO has reported successful > completion. The problem happens because update of on-disk inode size is > handled in ext4_dio_write_iter() *after* iomap_dio_rw() (and thus > dio_complete() in particular) has returned and generic_file_sync() gets > called by dio_complete(). Fix the problem by handling on-disk inode size > update directly in our ->end_io completion handler. > > References: https://lore.kernel.org/all/02d18236-26ef-09b0-90ad-030c4fe3ee20@linux.alibaba.com > Reported-by: Gao Xiang > CC: stable@vger.kernel.org > Fixes: 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure") > Signed-off-by: Jan Kara > --- > fs/ext4/file.c | 153 +++++++++++++++++++++---------------------------- > 1 file changed, 65 insertions(+), 88 deletions(-) > > Changes since v2: > * Added more comments explaining the code flow > * Added WARN_ON_ONCE to verify extending IO is handled synchronously > > Changes since v1: > * Rebased on top of Linus' tree (instead of a tree with iomap cleanup) > * Made ext4_dio_write_end_io() always return number of written bytes on > success for consistency Thanks for addressing it. It's always better to have a consistent return value wherever possible. > * Added Fixes tag Looks good to me. Please feel free to add - Reviewed-by: Ritesh Harjani (IBM)