Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp487986imn; Thu, 28 Jul 2022 06:54:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tKTKBClMxEzvx1QtiIqiei0gMq/wxcUp0GWUDUiT+AFkA3L2j3v1BY27iN2yw6pntL5ZHu X-Received: by 2002:a17:90b:4b10:b0:1f2:d4a9:6b6d with SMTP id lx16-20020a17090b4b1000b001f2d4a96b6dmr10126416pjb.12.1659016483245; Thu, 28 Jul 2022 06:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659016483; cv=none; d=google.com; s=arc-20160816; b=U5D19QEf7OK0/1KdZwbFyECbcZOf2bYQdr4YfFGKAcko7N+oLw3ZhSnFxKwc9aJaVT CpPPrg2tZnslal+LXy9+TYx1gn3c+FXY+OaM6kqKK7/BjW+pSXEKnAxUZWVcZ1pe/ha9 VK2qqpyMu5hj6oiHWoJd+668CYYWBM+x+HexPZ40WWXq5UW11XN860bIUconajydllMD 7ceP5QcFPScZHMTWw3Y2w1AqQPPdTMnfBfuErMXcXJ9hOyM4rO8YD8xYNO6t8Kvg4Li5 VRFMrc8K/ixXn5rZZ7JkPgdBIgnjMZEN58sXiJ+DTHQTli5jD60vZAhZXIremmjEUUOm 0Y8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MEG7fIKaCcVg64l3rHOgljVHfKFni+uklyxHNrGsN2k=; b=hp+uNwc2UcWoP+CLDjklXBfXpAspkZ6GSAZG6g4J/Rlq1VSs77+VHtxqxnQuOH4T0Q +JwhlHjDlVN3I0qlv1UA3tnXEVg6uV6Jehk9o0XOJuz1/os+87Va/W4MLvqDtT6TtAY0 ROgXHmmSiPkmkOHbJqUXoqsuXzkPHMMmKo/35dGpppOlfL1Ju5tdFzkJyN4qAMtP8/YP kpbv5/XgdE+hdEnvz3lQFY68fUlOeKrY1kYVIGdTAipJSH+1wGxKh5SCHmLviFiT01uI QBlLKMshyQxwpkWZXI0DWMxYeCEiQ6irbIrZ/cj0m8blls10mBoSzN/C7F+r9cKEYH1G uAhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FveV0GdX; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020a056a0008c600b0052ace23bfd2si887902pfu.70.2022.07.28.06.54.17; Thu, 28 Jul 2022 06:54:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FveV0GdX; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229751AbiG1Nj0 (ORCPT + 99 others); Thu, 28 Jul 2022 09:39:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230130AbiG1NjZ (ORCPT ); Thu, 28 Jul 2022 09:39:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 78078564DD for ; Thu, 28 Jul 2022 06:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659015563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MEG7fIKaCcVg64l3rHOgljVHfKFni+uklyxHNrGsN2k=; b=FveV0GdXLG+xbqAI/ED1WfIY2m5Ae8qCyg24Sq+QgX9m/Xp41MSwi21qrXQfnq8a8zAbvT u7wGgnr29hJzZuOk55f91xx/oVn4VacN1pEov+jCc9dxwkO+qqOqgfxRzM3HxS1OkHW3Y6 3z/HXujOGc1q8Fuyk3bqiDo9M97pSAQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-217-rfB9pIH9OC6rTapXqGE2Bw-1; Thu, 28 Jul 2022 09:39:17 -0400 X-MC-Unique: rfB9pIH9OC6rTapXqGE2Bw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 218B1803520; Thu, 28 Jul 2022 13:39:17 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.193.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 068142026D64; Thu, 28 Jul 2022 13:39:15 +0000 (UTC) From: Lukas Czerner To: linux-ext4@vger.kernel.org Cc: jlayton@kernel.org, tytso@mit.edu, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/2] fs: record I_DIRTY_TIME even if inode already has I_DIRTY_INODE Date: Thu, 28 Jul 2022 15:39:14 +0200 Message-Id: <20220728133914.49890-2-lczerner@redhat.com> In-Reply-To: <20220728133914.49890-1-lczerner@redhat.com> References: <20220728133914.49890-1-lczerner@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Currently the I_DIRTY_TIME will never get set if the inode already has I_DIRTY_INODE with assumption that it supersedes I_DIRTY_TIME. That's true, however ext4 will only update the on-disk inode in ->dirty_inode(), not on actual writeback. As a result if the inode already has I_DIRTY_INODE state by the time we get to __mark_inode_dirty() only with I_DIRTY_TIME, the time was already filled into on-disk inode and will not get updated until the next I_DIRTY_INODE update, which might never come if we crash or get a power failure. The problem can be reproduced on ext4 by running xfstest generic/622 with -o iversion mount option. Fix it by setting I_DIRTY_TIME even if the inode already has I_DIRTY_INODE. Also clear the I_DIRTY_TIME after ->dirty_inode() otherwise it may never get cleared. Signed-off-by: Lukas Czerner --- fs/fs-writeback.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 05221366a16d..174f01e6b912 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -2383,6 +2383,11 @@ void __mark_inode_dirty(struct inode *inode, int flags) /* I_DIRTY_INODE supersedes I_DIRTY_TIME. */ flags &= ~I_DIRTY_TIME; + if (inode->i_state & I_DIRTY_TIME) { + spin_lock(&inode->i_lock); + inode->i_state &= ~I_DIRTY_TIME; + spin_unlock(&inode->i_lock); + } } else { /* * Else it's either I_DIRTY_PAGES, I_DIRTY_TIME, or nothing. @@ -2399,13 +2404,20 @@ void __mark_inode_dirty(struct inode *inode, int flags) */ smp_mb(); - if (((inode->i_state & flags) == flags) || - (dirtytime && (inode->i_state & I_DIRTY_INODE))) + if ((inode->i_state & flags) == flags) return; spin_lock(&inode->i_lock); - if (dirtytime && (inode->i_state & I_DIRTY_INODE)) + if (dirtytime && (inode->i_state & I_DIRTY_INODE)) { + /* + * We've got a new lazytime update. Make sure it's recorded in + * i_state, because the time might have already got updated in + * ->dirty_inode() and will not get updated until next + * I_DIRTY_INODE update. + */ + inode->i_state |= I_DIRTY_TIME; goto out_unlock_inode; + } if ((inode->i_state & flags) != flags) { const int was_dirty = inode->i_state & I_DIRTY; -- 2.35.3