From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795021419; b=qdvqcisP+48swqc5OGIhu4V09W7eN4oab8nj4qJD6Fvz3xcxJ99H8ehQOd2tsKMvC9pO 0eUsgCGLp5LKVqd4S/hcEzfwEYtnFH8YfjtfXtFvMKnHwp6GPpFUOK9m5xhYal1Xsfn9r mvdeNVABrnx+jvoe7vwkYv9kuh33eEfT+SBSI+EKNxaCeuk7pGI/aMfYD+7ZffpW8pxoP Sd9fGsQxS1IwSfz27TZ9eqQ5ykHQbGPAXRsIzGHJZrfEf4HE4rjUEpqwInguSGCBaUeZJ dLUnKHRKScZuvdgY31SRQKBV6S1ZvdACyuapeE9P283jojKNgNfllw737R33uwoXO5Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795021419; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=KnJXhu7ciaLsv/KZ4iy+rRBGb4F5cufxaccB/yywOfw=; b=JY0/DUTQVRe6UzX54jLXkyiGoABYfmAZjMvpcAZXNrHtlUfbLxmE1S2CetE/BqNWe4mz AmIHovPUIVzWbyxoAFQUwLPOYs/53qdl6QnaOqsrBks0hsvd9GHgPgkL+CDJW7LM8d2ot 2w8acxvEWP12kMKiPq7G5kDocjuRCkR7hFEbzOOjYvXFt2XGipUih21s5LO2jSLVzS7M9 2IjlkslzGAJg2EZbVhHWmkUeytURZoieKR6gvl2eibh7p7AZeTYek041EBcy/vNsovE1L pb40S1Un7fssIt4wSdeaswJn+nmAg1cqYxSQgT6dtvl+8vS1Kt274amFUXcfB/9jJnQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=toxicpanda.com; spf=pass smtp.mailfrom=toxicpanda.com; dkim=pass header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=idTO+BcP; arc=none smtp.remote-ip=209.85.219.47 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D2CE606A32A for ; Wed, 18 Nov 2026 17:03:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9D2CE606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=idTO+BcP Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-92110499585so11089366d6.0 for ; Wed, 18 Nov 2026 09:03:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda.com; s=google; t=1795021416; x=1795626216; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KnJXhu7ciaLsv/KZ4iy+rRBGb4F5cufxaccB/yywOfw=; b=idTO+BcPm37oc2zlimiLmAKY2YCQQiK6H+DKIttNpQuUNUleX5fIhJkRRg0FHDFLb9 JmuDiQnRuX51PKsKe860irNAWTy+SFjFJY9fxFMIWhs8SKvkuAQLx9EkfUA3+Ie3SLPl IpZWKk3iwOgTy/cwrdYLmLIfWtD+0LlHCTS7FD8NQNYlX5UjHm3GDN0JagcTfRPF8CX5 J9065mvk9LV/qiCGc4E+xAW3qimP9IXurOq1jivHvxRFdK42obeAoMl6SYFzfW5xU2F6 aVzV1TdvkTgP90eMxe0PcjymvED7Ou8j15C13v/pekZQozUnWGiJZa3Gj8wJxBwYwJi4 zZaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795021416; x=1795626216; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=KnJXhu7ciaLsv/KZ4iy+rRBGb4F5cufxaccB/yywOfw=; b=PNPjjgl1GKHxCLbV2CmsA85VtZsPthEEjWHckFgP2pwA2eN3Rhrq4gX6Ii5SxIZdBJ a8HRbuAWkQ0fKBAAIqe+rJUcZA8VX8Gh8py/vay7jTY/fVYzJ3w5ofQ0uZDbwbZvaSHN 8O0tzpT2bDQANvh1ItUS3x3AS2HO/48s1RKN44+QMXpdd4DlpJR7wiWmaU28JE2zzsCl ndaIqa1cHHvqJnRvut1/eq/1Ul55Yyuh3Ti/0y7bnyE2N2ZNJ1ASZu+KLoXNc83y8/Ru qTgX2AKCofYaZn2Iwd57l+wGjgqX2OdQEX1ZepzUBE9C34ytGyG1iRN0bpnI/ZDjAzHo N7Iw== X-Forwarded-Encrypted: i=1; AL+hErFiQYZyqD769ASrH5WKcoWteMZI6iv3LhrDfAqv/16+U7zjazAx5ViceScnvC2jKT7SE+giWRb0RY3uC68=@vger.kernel.org X-Gm-Message-State: APuU4Z9KqJookFvrW8Ld8c8U2j8lcTuEEzo3KgSoA/4ph78+CWK5kbP2 O78GQMo/rnOV1vARG34o4GeR+26Pxg+i8uCy0i6rvuJJ3LLPTgaIksZPPpksBQ/gbSl8ArACvv7 dKPw6ong= X-Gm-Gg: AZFdTZcVqKo0ep1aFj5rlAYRc1xatEOISNYEo1mAIIZJUDQup4D5F1xDZdwZ+6zNocJ ccDflZogrBfGhf+EhPcabma+DDRih99MZkCgHp+BvWaNqmP7I4EVMCzCCe4HrL3JyRZgGEgBFeH Dqen+AIEyXveXT3aV+eJTYXsDGJO/0NNk3y9jFvYmhDQorPIp7JEzgbT3YJj2iFC8buQFg5b1GH TjJW7/FIxwffkJUO23jjZOfIpgMglOek9EsFteKPFAHLaEQxg2C4+8r8l+npnMBNAT6jWiOZVfd ie65uRlH8V0Zm2U16xx3kV9zE6XK+fraOJyJOVE5EgiqJ0Xi0f/Gb4CatVoaFCyTBRoUptCpZ00 7VUerPplRp+tfr3L9XoiVNXhcD5WGta6TQ9J8Z6X5emk3006GXuVtx4yeFJeBNmTl9nQzuNZu+B Y1hbzMw3IegHpYITj+quuZ3UieoD93J8HCjY9mD2J7qcDbI2rOQgV+N+QY4uzEEe+aCp3nQdLvf dcEZiqtbRe8jHgP9qpqUZWztHqhYn773Kt1TGvGlL0xPUZdvsmRga5XFCPpm0mNujmTetrVI41h Nue/xc1CNveH+s5Chy3v3LVtIyuDjsRPpXmw4wOHKahhpg== X-Received: by 2002:a05:6214:2342:b0:91e:854c:4b56 with SMTP id 6a1803df08f44-92114f74aabmr47606106d6.45.1795021416193; Wed, 18 Nov 2026 09:03:36 -0800 (PST) Received: from toxicpanda.com ([153.61.196.241]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-92114d2ddf9sm26002426d6.18.2026.11.18.09.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 09:03:35 -0800 (PST) From: Josef Bacik Date: Wed, 18 Nov 2026 17:03:24 +0000 Subject: [PATCH v7 1/7] ovl: expand fsync mount options X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-b4-ovl-containerized-sync-v7-1-54f45743fe55@toxicpanda.com> References: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> In-Reply-To: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> To: Miklos Szeredi , Amir Goldstein , Christian Brauner Cc: Alexander Viro , Jan Kara , Christoph Hellwig , Chris Mason , Chengguang Xu , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Josef Bacik X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openssh-sha256; t=1795021413; l=12726; i=josef@toxicpanda.com; h=from:subject:message-id; bh=OlE+Yo4HPow1hWz7Ht9Z85c4EaLJMX0EegR5CuU7+i0=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUBr36M/n0nWN0DNbnxwzIiCZez6MG JiruuNaSCI/zXsAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QHOwzX6abx9oOKviUvaBxsdKv8J2udomv8/Pa0zDv9bq9Sn9ekDo/D//WPfSOBUTjGa7j+wF1oV MqzueUxD+kAs= X-Developer-Key: i=josef@toxicpanda.com; a=openssh; fpr=SHA256:C8kOX2QUJCMqnCX+KEeoqRAjLo9L+ELOSH2NSAJHqGA From: Amir Goldstein The fsync mount option currently accepts three values: "volatile", "strict" and "auto". All other "enum" mount options have "on" and "off" values and this is used by the generic _check_overlay_feature helper in fstests to probe for support for enabling overlayfs features. This commit adds support for values "on", "off" and "relaxed" and makes the value of "auto" depend on a kconfig/module option fsync_auto. The value of "off" behaves almost the same as "volatile", not persisting changes to upper layer, but it does not create the directory "$workdir/work/incompat/volatile", which prevents a mount cycle of a volatile overlayfs. Some users requested to opt-out of this guard rail. With upperdir on tmpfs, overlayfs now falls back to "fsync=3Doff", because the other fsync modes are futile on tmpfs. The new value "relaxed" is a preparation for not syncing the entire upper fs on syncfs(2) and unmount and instead tracking and syncing only the upper inodes modified by this overlayfs. The value of "on" is the traditional overlayfs behavior and it behaves the same as the current value "auto", releasing the value of "auto" to differ by the kconfig/module option fsync_auto. By default, with kconfig/module option fsync_auto=3DY, the meaning of the value "auto" is that filesystems that support RENAME_WHITEOUT default to "relaxed" and filesystems that do not support RENAME_WHITEOUT default to the traditional "fsync=3Don". Signed-off-by: Amir Goldstein Signed-off-by: Josef Bacik --- Documentation/filesystems/overlayfs.rst | 36 ++++++++++++++++++++++++++++-= ---- fs/overlayfs/Kconfig | 21 +++++++++++++++++++ fs/overlayfs/overlayfs.h | 24 +++++++++++++++++++--- fs/overlayfs/params.c | 18 +++++++++++++---- fs/overlayfs/params.h | 2 ++ fs/overlayfs/super.c | 22 ++++++++++++++++++-- 6 files changed, 109 insertions(+), 14 deletions(-) diff --git a/Documentation/filesystems/overlayfs.rst b/Documentation/filesy= stems/overlayfs.rst index 16c35b491dad..1a59500834a1 100644 --- a/Documentation/filesystems/overlayfs.rst +++ b/Documentation/filesystems/overlayfs.rst @@ -826,27 +826,53 @@ The fsync during copy up only guarantees that if a co= py up is observed after a crash, the observed data is not zeroes or intermediate values from the copy up staging area. =20 +Traditionally, syncfs(2) and unmount of an overlay sync the entire upper +filesystem, including the dirty data of other overlays that share it. +Overlayfs can be told to only write back the files that were modified +through the overlay, and then ask the upper filesystem to commit its +metadata. + On traditional local filesystems with a single journal (e.g. ext4, xfs), fsync on a file also persists the parent directory changes, because they are usually modified in the same transaction, so metadata durability during -data copy up effectively comes for free. Overlayfs further limits risk by -disallowing network filesystems as upper layer. +data copy up and the persistence of other upper changes such as whiteouts +effectively come for free. Other filesystems (e.g. ubifs) require an expl= icit +fsync(2) on the copied up files and directories to persist their metadata. =20 Overlayfs can be tuned to prefer performance or durability when storing to the underlying upper layer. This is controlled by the "fsync" mount option, which supports these values: =20 -- "auto": (default) +- "volatile": [*] + Prefer performance over durability (see `Volatile mount`_) +- "off": + Same as "volatile", but does not prevent mounting the overlay again + after unmount (see `Volatile mount`_) +- "relaxed": Call fsync(2) on upper file before completion of data copy up. No explicit fsync(2) on directory or metadata-only copy up. + syncfs(2) and unmount only write back the files that were modified + through the overlay. +- "auto": (default) + "relaxed" if the upper filesystem supports RENAME_WHITEOUT, + otherwise "on". +- "on": + syncfs(2) syncs the entire upper filesystem. + Copy up behaves like "relaxed". - "strict": + syncfs(2) syncs the entire upper filesystem. Call fsync(2) on upper file and directories before completion of any copy up. -- "volatile": [*] - Prefer performance over durability (see `Volatile mount`_) =20 [*] The mount option "volatile" is an alias to "fsync=3Dvolatile". =20 +The default is "fsync=3Don" instead of "fsync=3Dauto" with the module opti= on +"fsync_auto=3DN" or with the kernel config option +CONFIG_OVERLAY_FS_FSYNC_AUTO=3Dn. + +If the upper filesystem has no writeback (e.g. tmpfs), a non-default mode +falls back to "fsync=3Doff". + =20 Volatile mount -------------- diff --git a/fs/overlayfs/Kconfig b/fs/overlayfs/Kconfig index 2ac67e04a6fb..f1b2f3784c76 100644 --- a/fs/overlayfs/Kconfig +++ b/fs/overlayfs/Kconfig @@ -108,6 +108,27 @@ config OVERLAY_FS_XINO_AUTO =20 If unsure, say N. =20 +config OVERLAY_FS_FSYNC_AUTO + bool "Overlayfs: auto select the fsync mode by default" + default y + depends on OVERLAY_FS + help + If this config option is enabled then overlay filesystems will use + "fsync=3Dauto" by default, which selects "fsync=3Drelaxed" if the upper + filesystem supports RENAME_WHITEOUT and "fsync=3Don" otherwise. + With "fsync=3Drelaxed", syncfs(2) and unmount of an overlay only write + back the files that were modified through the overlay, instead of + syncing the entire upper filesystem. + + If this config option is disabled then overlay filesystems will use + "fsync=3Don" by default. It is still possible to change the default + with the "fsync_auto" module option or on a filesystem instance + basis with the "fsync" mount option. + + For more information, see Documentation/filesystems/overlayfs.rst + + If unsure, say Y. + config OVERLAY_FS_METACOPY bool "Overlayfs: turn on metadata only copy up feature by default" depends on OVERLAY_FS diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 901335026a20..13fbe016ed75 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -102,8 +102,11 @@ enum { }; =20 enum { + OVL_FSYNC_OFF, OVL_FSYNC_VOLATILE, + OVL_FSYNC_RELAXED, OVL_FSYNC_AUTO, + OVL_FSYNC_ON, OVL_FSYNC_STRICT, }; =20 @@ -666,7 +669,8 @@ static inline bool ovl_xino_warn(struct ovl_fs *ofs) =20 static inline bool ovl_should_sync(struct ovl_fs *ofs) { - return ofs->config.fsync_mode !=3D OVL_FSYNC_VOLATILE; + return ofs->config.fsync_mode !=3D OVL_FSYNC_OFF && + ofs->config.fsync_mode !=3D OVL_FSYNC_VOLATILE; } =20 static inline bool ovl_should_sync_metadata(struct ovl_fs *ofs) @@ -674,9 +678,23 @@ static inline bool ovl_should_sync_metadata(struct ovl= _fs *ofs) return ofs->config.fsync_mode =3D=3D OVL_FSYNC_STRICT; } =20 -static inline bool ovl_is_volatile(struct ovl_config *config) +/* + * With fsync=3Drelaxed, track the files that were modified through the ov= erlay, + * so that syncfs(2) and unmount only write back those. + */ +static inline bool ovl_tracks_dirty(struct ovl_fs *ofs) +{ + return ofs->config.fsync_mode =3D=3D OVL_FSYNC_RELAXED; +} + +/* + * With fsync=3Drelaxed, syncfs(2) and unmount only write back the files t= hat were + * modified through the overlay. Otherwise they sync the entire upper + * filesystem. + */ +static inline bool ovl_should_sync_upper_fs(struct ovl_fs *ofs) { - return config->fsync_mode =3D=3D OVL_FSYNC_VOLATILE; + return ovl_should_sync(ofs) && !ovl_tracks_dirty(ofs); } =20 /* diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c index 5a15e5478a6b..549fc1e83ac9 100644 --- a/fs/overlayfs/params.c +++ b/fs/overlayfs/params.c @@ -28,6 +28,11 @@ module_param_named(xino_auto, ovl_xino_auto_def, bool, 0= 644); MODULE_PARM_DESC(xino_auto, "Auto enable xino feature"); =20 +static bool ovl_fsync_auto_def =3D IS_ENABLED(CONFIG_OVERLAY_FS_FSYNC_AUTO= ); +module_param_named(fsync_auto, ovl_fsync_auto_def, bool, 0644); +MODULE_PARM_DESC(fsync_auto, + "Default to fsync=3Dauto instead of fsync=3Don"); + static bool ovl_index_def =3D IS_ENABLED(CONFIG_OVERLAY_FS_INDEX); module_param_named(index, ovl_index_def, bool, 0644); MODULE_PARM_DESC(index, @@ -142,8 +147,11 @@ static int ovl_verity_mode_def(void) } =20 static const struct constant_table ovl_parameter_fsync[] =3D { + { "off", OVL_FSYNC_OFF }, { "volatile", OVL_FSYNC_VOLATILE }, + { "relaxed", OVL_FSYNC_RELAXED }, { "auto", OVL_FSYNC_AUTO }, + { "on", OVL_FSYNC_ON }, { "strict", OVL_FSYNC_STRICT }, {} }; @@ -153,9 +161,9 @@ static const char *ovl_fsync_mode(struct ovl_config *co= nfig) return ovl_parameter_fsync[config->fsync_mode].name; } =20 -static int ovl_fsync_mode_def(void) +int ovl_fsync_mode_def(void) { - return OVL_FSYNC_AUTO; + return ovl_fsync_auto_def ? OVL_FSYNC_AUTO : OVL_FSYNC_ON; } =20 const struct fs_parameter_spec ovl_parameter_spec[] =3D { @@ -689,9 +697,11 @@ static int ovl_parse_param(struct fs_context *fc, stru= ct fs_parameter *param) break; case Opt_fsync: config->fsync_mode =3D result.uint_32; + ctx->set.fsync =3D true; break; case Opt_volatile: config->fsync_mode =3D OVL_FSYNC_VOLATILE; + ctx->set.fsync =3D true; break; case Opt_userxattr: config->userxattr =3D true; @@ -896,8 +906,8 @@ int ovl_fs_params_verify(const struct ovl_fs_context *c= tx, config->index =3D false; } =20 - if (!config->upperdir && ovl_is_volatile(config)) { - pr_info("option \"volatile\" is meaningless in a non-upper mount, ignori= ng it.\n"); + if (!config->upperdir && set.fsync) { + pr_info("options \"fsync\" and \"volatile\" are meaningless in a non-upp= er mount, ignoring them.\n"); config->fsync_mode =3D ovl_fsync_mode_def(); } =20 diff --git a/fs/overlayfs/params.h b/fs/overlayfs/params.h index ffd53cdd8482..5f3572b270f3 100644 --- a/fs/overlayfs/params.h +++ b/fs/overlayfs/params.h @@ -15,6 +15,7 @@ struct ovl_opt_set { bool redirect; bool nfs_export; bool index; + bool fsync; }; =20 #define OVL_MAX_STACK 500 @@ -42,3 +43,4 @@ int ovl_fs_params_verify(const struct ovl_fs_context *ctx, struct ovl_config *config); int ovl_show_options(struct seq_file *m, struct dentry *dentry); const char *ovl_xino_mode(struct ovl_config *config); +int ovl_fsync_mode_def(void); diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 08695a99f4f9..5960974c5af2 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -762,6 +763,11 @@ static int ovl_make_workdir(struct super_block *sb, st= ruct ovl_fs *ofs, if (!rename_whiteout) pr_warn("upper fs does not support RENAME_WHITEOUT.\n"); =20 + /* fsync=3Dauto that is not resolved to fsync=3Drelaxed means fsync=3Don = */ + if (ofs->config.fsync_mode =3D=3D OVL_FSYNC_AUTO && rename_whiteout && + mnt->mnt_sb->s_bdi !=3D &noop_backing_dev_info) + ofs->config.fsync_mode =3D OVL_FSYNC_RELAXED; + /* * Check if upper/work fs supports (trusted|user).overlay.* xattr */ @@ -814,9 +820,9 @@ static int ovl_make_workdir(struct super_block *sb, str= uct ovl_fs *ofs, =20 /* * For volatile mount, create a incompat/volatile/dirty file to keep - * track of it. + * track of it. fsync=3Doff allows mounting the overlay again. */ - if (ovl_is_volatile(&ofs->config)) { + if (ofs->config.fsync_mode =3D=3D OVL_FSYNC_VOLATILE) { err =3D ovl_create_volatile_dirty(ofs); if (err < 0) { pr_err("Failed to create volatile/dirty file.\n"); @@ -1481,6 +1487,18 @@ static int ovl_fill_super_creds(struct fs_context *f= c, struct super_block *sb) return err; =20 upper_sb =3D ovl_upper_mnt(ofs)->mnt_sb; + /* + * An upper fs without writeback has nothing to sync and nothing + * to lose, so every fsync mode behaves like fsync=3Doff. Keep the + * default mode, which is not shown in mountinfo. + */ + if (upper_sb->s_bdi =3D=3D &noop_backing_dev_info && + ofs->config.fsync_mode !=3D ovl_fsync_mode_def() && + ofs->config.fsync_mode !=3D OVL_FSYNC_OFF) { + pr_warn("upper fs does not support writeback, falling back to fsync=3Do= ff.\n"); + ofs->config.fsync_mode =3D OVL_FSYNC_OFF; + } + if (!ovl_should_sync(ofs)) { ofs->errseq =3D errseq_sample(&upper_sb->s_wb_err); if (errseq_check(&upper_sb->s_wb_err, ofs->errseq)) { --=20 2.55.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795021419; b=lM9MxU7gt3qQg3pVhSOCLeG+693uVq1+5GMdFXk5QCWJdo65EuVS2Ezz0lKYkrCIjbSo 0QrJcPNJlErVvgks5xYzXUuheLeRi8Ab5G55FxUAocjEzAO4L+nqD+Nj9IC5u5V8597TV tDPipkvcgBH4ImgX/zgZl2dt3+xgk6Do1zN+OMxKvT8M0QOF9UAgkt0MjWLx7/f5m9lTz WeqKxL01lG+vRf4YDoVAO9bcVYWWgvzIgTYY99RfVTDlRw7Gk/6z6dLybr1e/nh+I7oLP CL89xR7tEimQnY5YGzfdYO7KYFPTzwQ2g7j0hDwFPLpnuj3n1KjAtvTVCB00tBO52LQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795021419; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=Nz+IbEOviOWTqeWPFaSKYQFDDLKcLrIMVLmfi5/eTq8=; b=EvHWpTQbFOafjbcX2Ayd+9yqL9eN/SzAAOLInfJgwcNz9/1MOhJIWy8YtyWXy7ob0PD1 OKGK/5q3qQeQ0ZJ3O2cIaMwVUrdcjfWyTvrjXktYAN94bmEK94/fUAzHxuufgrSqPtkQe vIKgQ89gbu0nrPrdSKc2DqjMs6IxbCTbaRhIZ0d2ZnyCqUpe/1Zx47UdA6WCWXTm0huCQ VNMMb1wQT2o1M+v0JESNeHOy19bGRKuVHQ93X36T8XyjkC9CGM16PPLlQpoAH2whEroix Dcpdy5MBkmJ8Lb4KmiIw536kUbBWHuHN6Sxdo2D/hI3CAi/99CB94I9sfTcZHra1eVw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=toxicpanda.com; spf=pass smtp.mailfrom=toxicpanda.com; dkim=pass header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=RYYnDKjb; arc=none smtp.remote-ip=209.85.219.47 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58F7A606A339 for ; Wed, 18 Nov 2026 17:03:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 58F7A606A339 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=RYYnDKjb Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-91eb46044c4so14452896d6.1 for ; Wed, 18 Nov 2026 09:03:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda.com; s=google; t=1795021417; x=1795626217; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Nz+IbEOviOWTqeWPFaSKYQFDDLKcLrIMVLmfi5/eTq8=; b=RYYnDKjbnXwVVfMkR5rVpzsoay5v4fYowEr/xrIsozOndFgoJNMKNlazBBG6+xaKuo f2M20sHVniTYaHovrJM/58OydmMRkDa5lRJn4+UqyZ/FIrvrTfHG+Fe0gOgRK5b7NqjK T+kLa1Tf0qgl3MefkW6gWFQPwTQLJyi7Qp8g6OAHCM1eUelx04VXcqkcxfG872OxIQO6 oUt5pQm7OyO/2VIJ5ioD4kuvOL1AjQnr0sQy/D3oyoUGu/VfUPJkdJGdXcU0io9hTTi0 8BvVpkSBN9qM/z3grPj+rrMzAtQSZsjnwBwUoyWmhL63qjG8oCQaEaoy0ApGCGQmgXAN kpCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795021417; x=1795626217; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Nz+IbEOviOWTqeWPFaSKYQFDDLKcLrIMVLmfi5/eTq8=; b=jl/PEVo99kpWvApjTNu5prqUwGxQy7b5keqjmPYpqjmtYsUtmLL9BXZQkbOj9UM6Vb Ef+AWg9J6juMiyg7p++8vpi+D1YLisZ/ydu9rhQ5SRnJx0Cz4I9fr4ajKsuGARlU45e0 cVQP2Hdj5zB74I/FfDMmhWz/bOTjLRy1yO8n+i5bbwe02nFBWsBviJt+tNzfRCEkYVXv ArjUmXGVuzsfGK2Lm5mcW7UpqdvgmpB6JiF8bAsfm00NZrzXO+LsAH8rgdqOd6mJh0dL KjWX3VAeW2+zbhCbTrVocH8XH2OgSzLr8LaYtyrsP0nOmPXGNrSQLRHWDuxuWDj5JW8P 6Maw== X-Forwarded-Encrypted: i=1; AL+hErGKCoqQZeyx4Rn2l8EF2NLXbxPO4Lwnu3STF4RuEcplUCBAyvAsKUJLgvF7UYqFsuyana7fgTDey4Co7qE=@vger.kernel.org X-Gm-Message-State: APuU4Z9xlQFgrzx+giiKXhX1fiGagcfQrJZ9K8PeWPvJedreRp5Ygqwq MczqCdcfgiBByX7Ue+AmhCW6RRyW1r+ybwZj2SaVyyk8uclroPbxj37mumSy3F7Or/o= X-Gm-Gg: AZFdTZfKzvIqLWwFL5LJsh+pdE1iCDNC3mmNmnwKza4GHz02J28d2sQcgZioqr3r8yK MpvRFAuNMogI3vSceU1cBtA2cvV9lVjddbQOSwQ3ZPFpzXUdPm/j4vIkhNLcc9my+oWZ6AqzQg/ 73c9UAqISk3f5im/6AXNmxAA9yC1NczNvaS7jWeesiEVWxVpvV1+9JVsIJJO42lWeqZD5I6y7s4 3YMJkqs/gCbaTmksIbU/+yQNMRTOn9S3TEsd64ssL8MkJT6/tiG/d8N3Quq5ZLwW+l7khatne6n ujZwaoNLIvlOYV4Okp04WROw1RrUq4ICMnGqf2bSGzZHng+qDnbLa4zkCOzXY0Hxirta1xnkBOD rpfARy8Y3kCudbl2p0iWydMjq4RcKyCaNXSLM9tGa0i/GRznGeF+uVgE+rCjedog2luGRCXCzxG FGiQ8ZiSECZKR1yVKnHUdusZksLaHEY4/LLrVR67GBmyeWRUuUsiwSC2Ii/jclDV3lT527rt1OX a6PotqsO+R1sUCP902ynn4tm6KrBgpRufHUvI5tRs/rbgz4K4+tSpP5YYU7Be9lKJ2nZNzQ+DlR 4qr9O6y730oas2iwSLUSt6qlHwJw6KkJaslSQ4jC4v3ACUw= X-Received: by 2002:ad4:5f0d:0:b0:91e:dde3:f213 with SMTP id 6a1803df08f44-92114f6e1a2mr51313906d6.40.1795021417403; Wed, 18 Nov 2026 09:03:37 -0800 (PST) Received: from toxicpanda.com ([153.61.196.240]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-92114d16bafsm26217506d6.7.2026.11.18.09.03.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 09:03:36 -0800 (PST) From: Josef Bacik Date: Wed, 18 Nov 2026 17:03:25 +0000 Subject: [PATCH v7 2/7] ovl: no fsync=relaxed without data integrity X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-b4-ovl-containerized-sync-v7-2-54f45743fe55@toxicpanda.com> References: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> In-Reply-To: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> To: Miklos Szeredi , Amir Goldstein , Christian Brauner Cc: Alexander Viro , Jan Kara , Christoph Hellwig , Chris Mason , Chengguang Xu , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Josef Bacik X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openssh-sha256; t=1795021413; l=2797; i=josef@toxicpanda.com; h=from:subject:message-id; bh=m/J0LFSWS2GOFbjFlPJg5ev3Pv5YOtwv52o2fbrDkrM=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUBr36M/n0nWN0DNbnxwzIiCZez6MG JiruuNaSCI/zXsAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QJaASzyDcz8eRSVN5bIxFtETYxlSP6hrDkAbw4w7+PorJtI2UWASNywIzy1ye/L726ylFajsmAi bP6pwRVuy1ww= X-Developer-Key: i=josef@toxicpanda.com; a=openssh; fpr=SHA256:C8kOX2QUJCMqnCX+KEeoqRAjLo9L+ELOSH2NSAJHqGA A sync does not wait for a filesystem with SB_I_NO_DATA_INTEGRITY, which is fuse, so that a server that does not answer cannot block it. With fsync=3Drelaxed, syncfs() and unmount of the overlay are going to write the upper inodes one by one and wait for each. fuse_write_inode() waits for the server whatever the sync mode is, so they would wait for the server once for every inode. Do not resolve fsync=3Dauto to fsync=3Drelaxed on such an upper filesystem,= and fall back to fsync=3Don if fsync=3Drelaxed was asked for. Signed-off-by: Josef Bacik Reviewed-by: Amir Goldstein --- Documentation/filesystems/overlayfs.rst | 4 ++++ fs/overlayfs/super.c | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/overlayfs.rst b/Documentation/filesy= stems/overlayfs.rst index 1a59500834a1..8a007fbc5257 100644 --- a/Documentation/filesystems/overlayfs.rst +++ b/Documentation/filesystems/overlayfs.rst @@ -870,6 +870,10 @@ The default is "fsync=3Don" instead of "fsync=3Dauto" = with the module option "fsync_auto=3DN" or with the kernel config option CONFIG_OVERLAY_FS_FSYNC_AUTO=3Dn. =20 +An upper filesystem that cannot guarantee data persistence on sync (fuse) +does not get "fsync=3Drelaxed". "fsync=3Dauto" means "fsync=3Don" there, = and +"fsync=3Drelaxed" falls back to it. + If the upper filesystem has no writeback (e.g. tmpfs), a non-default mode falls back to "fsync=3Doff". =20 diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 5960974c5af2..31a58e28968c 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -765,7 +765,8 @@ static int ovl_make_workdir(struct super_block *sb, str= uct ovl_fs *ofs, =20 /* fsync=3Dauto that is not resolved to fsync=3Drelaxed means fsync=3Don = */ if (ofs->config.fsync_mode =3D=3D OVL_FSYNC_AUTO && rename_whiteout && - mnt->mnt_sb->s_bdi !=3D &noop_backing_dev_info) + mnt->mnt_sb->s_bdi !=3D &noop_backing_dev_info && + !(mnt->mnt_sb->s_iflags & SB_I_NO_DATA_INTEGRITY)) ofs->config.fsync_mode =3D OVL_FSYNC_RELAXED; =20 /* @@ -1499,6 +1500,16 @@ static int ovl_fill_super_creds(struct fs_context *f= c, struct super_block *sb) ofs->config.fsync_mode =3D OVL_FSYNC_OFF; } =20 + /* + * A sync does not wait for such an upper fs, whose server may + * not answer. A relaxed overlay waits for each upper inode. + */ + if ((upper_sb->s_iflags & SB_I_NO_DATA_INTEGRITY) && + ofs->config.fsync_mode =3D=3D OVL_FSYNC_RELAXED) { + pr_warn("upper fs does not guarantee data integrity, falling back to fs= ync=3Don.\n"); + ofs->config.fsync_mode =3D OVL_FSYNC_ON; + } + if (!ovl_should_sync(ofs)) { ofs->errseq =3D errseq_sample(&upper_sb->s_wb_err); if (errseq_check(&upper_sb->s_wb_err, ofs->errseq)) { --=20 2.55.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795021420; b=rCkQOlePtsD6oCou6jTElsVktMiTcdflaprhPfY5wxl45BHSS5Mle2Dckujz6xPxIdVW 1h/5zrrW6xV3JLUsFgxk7OHMFkbd0KZF4FnPNnFHMFgweV5VfzaYBHvhSdGhhL42AOV/C 2bqhE7n0f8D43mILenOp4aNFaVmta8v3G7aBpy3ASbkXfm9GOFU13vPYS1BaIyWEMvfY2 jWco0fb8uiXqImw17bW5uBl1YWDy+ye8Hq4T355uZK5QWNEqoJa1gBhF+R5EVhcbr7DpQ +AhFna8mDRLXVlrks9JhljXEfpdvdoWGOOU2JOzRXc+jSX8pGGpGneiw+hlY181ICEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795021420; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=M6gwJXb2gxib6r9BoJFITNoCXtYKADtb0yPwtxpwaOo=; b=1bmDDXmjCWdAhNSRuFmPxS/UIkEl5XFBGurgRMw7EtSP5uppE86iUr1/CZe2esWyA9ka gJ5ZIKNy1U8c98/ZboSgZPj9L98gTbcGiKz7EUIkYOYzXiMMlHvYDnqDnqaeelH2PSOQ5 IBfNzsMm0IqK8nvf0+qey+wGXUiIC+lxhtdr46RsJjNdOSVGwKwjuvYfBACM9x7l/BOt9 Dpk5j4wuY9p/4dj5/Tm1yLP/+oMzjRvXGVnxRSOM/QdZ172w6zFb5wH1R5mWD851KD8Sl fG9E27ZjSRBTQWh8VmyxQO85GRXbrNgwwylgj0uQZF9HH/+lZHBz98kG24myxBKXQyw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=toxicpanda.com; spf=pass smtp.mailfrom=toxicpanda.com; dkim=pass header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=h5wwtyx9; arc=none smtp.remote-ip=209.85.219.44 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADBC860A2624 for ; Wed, 18 Nov 2026 17:03:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ADBC860A2624 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=h5wwtyx9 Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-92123588d53so243116d6.1 for ; Wed, 18 Nov 2026 09:03:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda.com; s=google; t=1795021419; x=1795626219; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=M6gwJXb2gxib6r9BoJFITNoCXtYKADtb0yPwtxpwaOo=; b=h5wwtyx983KqxvtzYtyCP4Jlk50BvZnUZzdAgv9BdQ6nie5VPNi/h09I+8TpOGvzNs qOYJ51QcwElFNZvVu3Wt2ycNChH3o+eCxP1MrgLSVruh0VKLQe+P0SFFuND1fLCrTeRk E6L3QyDghF2m9Fl68ZdU+N2pdvgmEdTtJ6xs8pq+Eyz0wtezENllQGj9cI+yslFmtUzW Jj1rCmmY8+GO0LECNn0WhrruaAiWUyabvTb/UX5k3wVhFRSBtF3l87vA1WCyvX4THSui j1kFei1I1g2Ri1BR+iUtmoAZFfttYZEQSmk0bEzDMmy3Yb5o/PXBS/Q+DMEut2by/f9q npqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795021419; x=1795626219; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=M6gwJXb2gxib6r9BoJFITNoCXtYKADtb0yPwtxpwaOo=; b=CCKxNOCi1eyTFGzxrlK7DbBQoui58dC4lvMkqbkPFgdLZFviW/gD7m0dqH7QDqYPbU 0kpl+iZ6X68tGGpBlksMqYhCYoJkcGOPa/9e7+8K/tN4x/fLNK9cPA1XtHk1PyTilzD+ djqS7Au1mrh72m/kGlamv3eoVxPhrpTNVMmp0dVHKDGPbcDMdO/AO9pwelxSDt1Y7qsA KdRKNbSRCUvKh5gPfL8YD2FUp3yF8KbNfFAgjAuYmPU2ZGXrDvfo3coibl+vAxXhcaEA asGzM0umVwF0SzUMfE7tnz4brwLeX5P5tm20XMkfgGwIIIi7mdaauJJ7IpnAdwZ2bBGn w65Q== X-Forwarded-Encrypted: i=1; AL+hErE7EHV4HTfJMWbYyToH5YlREnmVc4XMLt7FlGUecgsVMkWCo+h4XPQdOMKS0lyX+P2HKnTwEi5oLGuR5Q4=@vger.kernel.org X-Gm-Message-State: APuU4Z89rtfxHxzO/DK6aH2UzJLlZx5ER01Rsk2UyH2rkUUP+DWoWeFJ 2sLGW3sbQyD6rozZ4eAp76Yb/ir0DtNc74idgftt9q2mZZRmSY7wwSARN08g5gI3bUE= X-Gm-Gg: AZFdTZe8KUrk+OvFVdfVrSN8yId9BjTfefif73p9qzsk8GYSlwXPqAgI6rGoskOznEZ xCp8QP9ZP9nvJHZjZZDubkNbiRP1Jdwr0T/JRibwr19/186RUVcBGCLjF4WjDQtEFevPcc4Dnty +pnU9EYy/k79ZoO/5Agl9qipRMSIM3X3TUcxkPe1QjvdrbUUHAvncu3RxsOSMlnFvGV6kC7LQhB MfP4jcKEL0TAnBj7bG6XaCC4XegyBlIuPw0FuYijQE+SywohqooI3Mrm6Ln943NDo/6UiqtrbbX 4EfV0oocXZURmiVtqH3oHj6oLFpkCMfEB6oSP2doZBxsbTUHikAu/usd/lnjLuIqwMN+Snu2FYK +Sh3da7cBg2/mSBKHFIvEfZ9aHH/+wRowyibXbNE2/TRYruKEAWQKZyVa/Hk+n1e11cskqo1svh DYDDSpVggY9JfriXAeR+KB3pz3Go55dh4VCr/+gy6fcI0+K/FPQY2xm/P2rONVI2tOmPqo+R1VR 4pPBWLS6Y//Tx5rkH2I++mrze4SdnvBPKTYNb+XThqnJgEnJG8GyYJIi8+inrrTCAoJ1v8kzZQ3 vLED2uJyA0bWwqIhYASuVMv5SLR1GK7hbLIl6W/X1UgPfeU= X-Received: by 2002:a05:6214:3283:b0:91e:f506:5dd6 with SMTP id 6a1803df08f44-9212431c63cmr1633126d6.25.1795021418473; Wed, 18 Nov 2026 09:03:38 -0800 (PST) Received: from toxicpanda.com ([153.61.196.240]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-92114d5558bsm26530406d6.23.2026.11.18.09.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 09:03:37 -0800 (PST) From: Josef Bacik Date: Wed, 18 Nov 2026 17:03:26 +0000 Subject: [PATCH v7 3/7] fs: add sync_fs_and_bdev() X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-b4-ovl-containerized-sync-v7-3-54f45743fe55@toxicpanda.com> References: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> In-Reply-To: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> To: Miklos Szeredi , Amir Goldstein , Christian Brauner Cc: Alexander Viro , Jan Kara , Christoph Hellwig , Chris Mason , Chengguang Xu , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Josef Bacik X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openssh-sha256; t=1795021413; l=3528; i=josef@toxicpanda.com; h=from:subject:message-id; bh=VgFAjK6/pmygZeLoXZRAr4NOxj7vW3wdwgCAbaJfu4g=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUBr36M/n0nWN0DNbnxwzIiCZez6MG JiruuNaSCI/zXsAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QIKPEs2/oj58xMvoTPppV9N6Jkq6vIHs5zmNVB7xMWWJ0Q7qr1VkLk2vBWBFUueDe5HlROQC77L cZ6B/xDA7oAk= X-Developer-Key: i=josef@toxicpanda.com; a=openssh; fpr=SHA256:C8kOX2QUJCMqnCX+KEeoqRAjLo9L+ELOSH2NSAJHqGA sync_filesystem() writes the inodes, calls ->sync_fs() and writes the block device, first without waiting and then with. overlayfs is about to write the inodes of its upper filesystem by itself, only those that were modified through the overlay, and needs the other two steps as they are. Move them to a helper so that overlayfs does not have to know what they are. sync_filesystem() calls the inner helper, so it still tests for a read-only filesystem and for s_umount once. The exported function does both tests for its callers. Nothing calls the exported function yet, no functional change intended. Suggested-by: Christian Brauner Signed-off-by: Josef Bacik Reviewed-by: Jan Kara --- fs/sync.c | 52 +++++++++++++++++++++++++++++++++++++++-----------= -- include/linux/fs.h | 1 + 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/fs/sync.c b/fs/sync.c index 4a84dd837b86..9adc7076c24d 100644 --- a/fs/sync.c +++ b/fs/sync.c @@ -22,6 +22,42 @@ #define VALID_FLAGS (SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE| \ SYNC_FILE_RANGE_WAIT_AFTER) =20 +static int __sync_fs_and_bdev(struct super_block *sb, bool wait) +{ + int ret; + + if (sb->s_op->sync_fs) { + ret =3D sb->s_op->sync_fs(sb, wait); + if (ret) + return ret; + } + if (!wait) + return sync_blockdev_nowait(sb->s_bdev); + return sync_blockdev(sb->s_bdev); +} + +/** + * sync_fs_and_bdev - finish a sync whose inodes the caller has written + * @sb: the superblock, the caller holds s_umount + * @wait: wait for the I/O to complete + * + * These are the steps of sync_filesystem() that follow the writing of the + * inodes. This is for a caller that has already written the inodes it ca= res + * about. Like sync_filesystem() it does nothing on a read-only filesyste= m. + * + * Return: 0 on success, a negative error code otherwise. + */ +int sync_fs_and_bdev(struct super_block *sb, bool wait) +{ + WARN_ON(!rwsem_is_locked(&sb->s_umount)); + + if (sb_rdonly(sb)) + return 0; + + return __sync_fs_and_bdev(sb, wait); +} +EXPORT_SYMBOL_GPL(sync_fs_and_bdev); + /* * Write out and wait upon all dirty data associated with this * superblock. Filesystem data as well as the underlying block @@ -29,7 +65,7 @@ */ int sync_filesystem(struct super_block *sb) { - int ret =3D 0; + int ret; =20 /* * We need to be protected against the filesystem going from @@ -52,22 +88,12 @@ int sync_filesystem(struct super_block *sb) * at a time. */ writeback_inodes_sb(sb, WB_REASON_SYNC); - if (sb->s_op->sync_fs) { - ret =3D sb->s_op->sync_fs(sb, 0); - if (ret) - return ret; - } - ret =3D sync_blockdev_nowait(sb->s_bdev); + ret =3D __sync_fs_and_bdev(sb, false); if (ret) return ret; =20 sync_inodes_sb(sb); - if (sb->s_op->sync_fs) { - ret =3D sb->s_op->sync_fs(sb, 1); - if (ret) - return ret; - } - return sync_blockdev(sb->s_bdev); + return __sync_fs_and_bdev(sb, true); } EXPORT_SYMBOL(sync_filesystem); =20 diff --git a/include/linux/fs.h b/include/linux/fs.h index 99caef43ff3c..2b016d9dfb88 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2619,6 +2619,7 @@ extern void __init vfs_caches_init(void); =20 void emergency_thaw_all(void); extern int sync_filesystem(struct super_block *); +int sync_fs_and_bdev(struct super_block *sb, bool wait); extern const struct file_operations def_blk_fops; extern const struct file_operations def_chr_fops; =20 --=20 2.55.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795021422; b=Nu89Tij6KdtUz01LNp8UUtM2sjXWyi60cD2ZLE21b2p+HxXdZYP/ou7nQ54mQIkqJMkp rTRhEj55Aojk8C4CPUqEO2egdJLKJJPVkezWtOvuEhp6+0CF7z2SzeiPWxvgHqm3nhDHQ 2VUa1atKUb6zw81Ohz++7gy+YIedrS8QB4Z/diYArXj8Em5CeO9KXlKTbS3kiMHP2cBNu GGDKZONo3fA+UyVUarLFZ6HlPwvmYbVTqDNFIxfmxCkrdgv4dQXu9ImcwiwVOIeG4+ZI2 /pl/Ai8XVjvFXRbJ1t2tt4aMsbtLZf3GfiMCufBxrVgzmBui594msMBFnsTkUvi68Gw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795021422; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=GLHuqACsTi6DOH91EEx2HMnXciRG7zk2OqldyJV4r9U=; b=y8U0NEes0HnwlHM43DsKEbMFoTFspsyTVlxAL9kOhbpIzkF+S/gxMKxuMMnZ5683A6qf 9RANADHDnspD1bX4zcu+cjxKeWDCCJTi1omrN3zgjPmtL6tSACcJtwbb6PzkHpS3WXIKs jgQ0wqIU/M53HYcnrOwuhufkSJ/79zj4Udvn2Tlrcv/rUY11wrIHvD8cW8sqJnAdQsFFP dCbfAmJit1BW9i/Kx4FNLLqRf6KZ/5qcHhw+Ry0iWXEu65Oy8heHwaC7Bmi38jKA5b7Pd ZVQaZch9QW7ykhCEK8zirg3hYWUd72fQWMptNtPq4nCWrL9BbzHOEeKbRVbMjF5npyw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=toxicpanda.com; spf=pass smtp.mailfrom=toxicpanda.com; dkim=pass header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=AkgNh3ey; arc=none smtp.remote-ip=209.85.128.176 Received: from mail-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3683D60A263E for ; Wed, 18 Nov 2026 17:03:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3683D60A263E Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=AkgNh3ey Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-8b4e2ec4b42so8041217b3.0 for ; Wed, 18 Nov 2026 09:03:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda.com; s=google; t=1795021420; x=1795626220; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GLHuqACsTi6DOH91EEx2HMnXciRG7zk2OqldyJV4r9U=; b=AkgNh3ey6Ev+lN7gotDHPUOV5RYD+TnT7qOwD5SaiKaH/vnC/VO8ghxeJvFSsJzwSJ 3uDiXEZgeH+SHqH05FgLXOuFoUFD5Dj6tLrUjqutO+0+I8gynDymizv5b6uD1QFlgzQo xmPESuIK/GssqngbAJFlMVJROaQ8GIt1OtggTgYiMz0phUq47Z+4GjVhhTazzr5ETAGn 7+uzgjCCb24Da8w/pFnYH7wsg7WyXbuwZY0eBdm5eISnT2XYUxqb21zHSOYhrvsvoIGs FrIwCPSqpgzSTp+2wdYc+xxgGr0nLdGL5kzVrFbYwl14O+v2XvfRMMlLq/gHLKsa8DMB hifQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795021420; x=1795626220; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GLHuqACsTi6DOH91EEx2HMnXciRG7zk2OqldyJV4r9U=; b=lNi5SrPZ95shprRqsDD/7APu5MFUq/PZoSVldwy2owIMX/gQsjw67wTEli/RiT9ygs S0gS0XuPNInyjbk/UoYqJYyKOsrBmlnGESFLWWWF0FrxJq8+JB3NVhgvHyQ+1Q6YIdYL 9+i1LCjtA59oZuKFgmZNoJL+0JJmisjAzLBqy+KNo3iffGZvepZuI12nt3cIvNjqNbpD c0OVhQwY3DqHglkdiulLb0GGxonSOiYeM97zu4EWwH/7ifJsjGSwEoWI99QmiLTvWesf ccBAhsV2BCuIZhZXeYL1Vi6LqSKPrymPtcyaBGT/iHoHZl2n/TiqMnrioXpLqweL4YnQ Mklg== X-Forwarded-Encrypted: i=1; AL+hErG2dbk4O3R0bG/v3ED84K62H9YkLBxtCsxxtxvF5PgYMduB4hKLTptnfvPlQOZrmL7tBS5Eyt+RVm0SHsY=@vger.kernel.org X-Gm-Message-State: APuU4Z9Znu1+fDOQGyxofKuYXXWn1g3dlms9TGT8vUtAPq8TPsOtDKvh bHgZIFyP1YezOeH4Z1MnlfqEczuJ+WDv+S0EikBtgenHE1R2GXkTmAli/+IKXyc0J7E= X-Gm-Gg: AZFdTZel3NoyztdgvqcHYrS7qmle7QtGIoDm94Rmnc/V1U41v79t8UlpMgR3DOYNnxV e2Y6+6u8oiSSktET8sNAgf4db7D4hwU8LdrIqhx6MIfxWslx6Ep9z1gKVpIOUHt2ohi6umgoTRP AzgXl2NrKhDSWkE5Hjc60HxuHnEITDCi4ExRCLxNAQGvXqQhjrFchUlFEZ7N8RIpUfWgOQ2lV1Q 3F2+T6GSs5Ucr/m6ok8E920tiiTMR8k8iQgv7OogACC6M2nwQ4aEhChrIE/S1T3TraZQAh7u1wm 1sYTjXkYAfrD6ivWWx/5eUxzOjRpOFZM7gb1xM1ffqvL1b0/WHRxks2riwOcPb7/uOImBHHQjuL xCXm0eijHFXlFKxtlsJopN8Beq4R+6YllL6MgYlbJcKG3ipRG+5ywyFuKE8fYbuZ5RQkFTOVWb3 C1e9UiZUsJU8VeivqKeW4wHU2RQP15k+heQmkcC0oE/S7cQEIYPRpEdSYvdMw6XMms/bktKkrz9 8vPDOVyw8PUlCGcvFoP/2zBfwxDdC3q2YweuEp9cX19LJnitsHbvqxGjRbsfhRPcZ78NudLDq4A ZMinEekXelYLcu29eYhtVgOrZzXeMmxs+NrgW8y+FGcNVQ== X-Received: by 2002:a05:690c:3507:b0:8b2:bb94:8cb2 with SMTP id 00721157ae682-8b4fed735damr13715107b3.35.1795021419607; Wed, 18 Nov 2026 09:03:39 -0800 (PST) Received: from toxicpanda.com ([153.61.196.248]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9499b721861sm224672485a.11.2026.11.18.09.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 09:03:39 -0800 (PST) From: Josef Bacik Date: Wed, 18 Nov 2026 17:03:27 +0000 Subject: [PATCH v7 4/7] fs: add write_inode_for_sync() X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-b4-ovl-containerized-sync-v7-4-54f45743fe55@toxicpanda.com> References: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> In-Reply-To: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> To: Miklos Szeredi , Amir Goldstein , Christian Brauner Cc: Alexander Viro , Jan Kara , Christoph Hellwig , Chris Mason , Chengguang Xu , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Josef Bacik X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openssh-sha256; t=1795021413; l=3205; i=josef@toxicpanda.com; h=from:subject:message-id; bh=p0YhEkTdw0npTy+LdFTgBjMgbpJBL9rcoMEF9LbcE8g=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUBr36M/n0nWN0DNbnxwzIiCZez6MG JiruuNaSCI/zXsAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QNW37LsNkBnQAFJvjEqEnn2YU8K4cQtYudIaa6RXFHOIT4DwIBxZFAEYqnEqCYymrGX2bhK02K8 bR1zva27ngQ0= X-Developer-Key: i=josef@toxicpanda.com; a=openssh; fpr=SHA256:C8kOX2QUJCMqnCX+KEeoqRAjLo9L+ELOSH2NSAJHqGA sync_inodes_sb() has the flusher write every dirty inode of a superblock with WB_SYNC_ALL and for_sync set. That writes the pages without waiting for them, hands over the timestamps that lazytime has deferred while it holds I_SYNC, and calls ->write_inode() in a way that tells the filesystem that ->sync_fs() follows, so ext4 does not commit a transaction for every inode. overlayfs is about to sync some of the inodes of its upper filesystem, and none of the exported functions does that for one inode. write_inode_now() and sync_inode_metadata() either do not wait for somebody else who is writing the inode and leave deferred timestamps alone, or they wait for the pages, clear the error flags of the mapping and make ext4 commit. Add a function that writes one inode the way a sync does. Nothing calls it yet. Signed-off-by: Josef Bacik Reviewed-by: Jan Kara --- fs/fs-writeback.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/pagemap.h | 1 + 2 files changed, 37 insertions(+) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 15260cf2a29b..d265466f12a8 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -3103,6 +3103,42 @@ int write_inode_now(struct inode *inode, int sync) } EXPORT_SYMBOL(write_inode_now); =20 +/** + * write_inode_for_sync - write an inode like a sync of its filesystem does + * @inode: inode to write to disk + * + * This does for one inode what sync_inodes_sb() has the flusher do for ev= ery + * dirty inode of a superblock. It writes all dirty pages, the timestamps= that + * lazytime has deferred and the inode. It waits for somebody else who is + * writing the inode, but not for the pages it writes, and it does not ask= the + * filesystem to commit anything. + * + * This is for a caller that syncs some of the inodes of a filesystem. It= has + * to wait for the pages with filemap_fdatawait_keep_errors(), like + * wait_sb_inodes() does, and to call sync_fs_and_bdev() in the end. + * + * The caller must have a ref on the inode. + * + * Return: 0 on success, a negative error code otherwise. + */ +int write_inode_for_sync(struct inode *inode) +{ + struct writeback_control wbc =3D { + .nr_to_write =3D LONG_MAX, + .sync_mode =3D WB_SYNC_ALL, + .range_start =3D 0, + .range_end =3D LLONG_MAX, + .for_sync =3D 1, + }; + + if (!mapping_can_writeback(inode->i_mapping)) + wbc.nr_to_write =3D 0; + + might_sleep(); + return writeback_single_inode(inode, &wbc); +} +EXPORT_SYMBOL_GPL(write_inode_for_sync); + /** * sync_inode_metadata - write an inode to disk * @inode: the inode to sync diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 73af18a37367..172c0fe0453f 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -35,6 +35,7 @@ int filemap_invalidate_pages(struct address_space *mappin= g, loff_t pos, loff_t end, bool nowait); =20 int write_inode_now(struct inode *, int sync); +int write_inode_for_sync(struct inode *inode); int filemap_fdatawrite(struct address_space *); int filemap_flush(struct address_space *); int filemap_flush_nr(struct address_space *mapping, long *nr_to_write); --=20 2.55.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795021422; b=nJvinN5geDcKDr6tCm0E6zPV3Kifg8BSMCK1tpRG6v/GhEp0S4uf16Z3RbJWS4hJo2fd 6vdSbNtF/a9kAowYhbStGyG4CICKDUwyT67sNMgMK20b2zQs0csIqCHlfvQqs2ib+p/M8 ARQVsq4J3eFE/Il6fEXEMvACCqk7RHG7MojGQ7mhtPTf0qwB93MfESxbtePZ2UsewgEFI vgr/HcCOitRWKc+3oVriuPaumIW+TE/i9bhWKqD1moKPbV5732bRdKla4gQRX3+6BC9n3 svoNgNn9eDds86N/rUq9twEQoyH8TQQSeyISIEW88h3huYueV0HbTxDRAOrm9KvmVUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795021422; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=Y70yXZAvOr66TxVQEPkIiAIDxuUPqlw54kS33Yt/9Yg=; b=HE5WhLquJeyRcKZsXKJNsC2DRBk4IJG5MIrxAWrkrZFuzQXsEJgX6l6Dq/ormgsZw3hO MvqB/e8Y/iGlLhh8HVB+IHaV3b+LpdIwK1FYAxd/obD8SeGScStm8T+iwR14KmHY+TgOJ SKZBCqSA5lrwonZTZ5FqaOqc2sAKRKK9z8YINN1Id2Vj64T6iH7KD+8gk8BxJpfgdlnGb yxy58scZ5MZ/uBb23nsMSD1OSxACptO0n22z2dxrlFtGof/Dz/UwLoqFQ2im9YePB0z/C 6TyGBvW3AnpP7RnBiul0gU78WKnuQ2PlHKwBm/FOsTFY67MArjdUMkuxGe5EShv4dGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=toxicpanda.com; spf=pass smtp.mailfrom=toxicpanda.com; dkim=pass header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=VvxeAFXj; arc=none smtp.remote-ip=209.85.128.171 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4278060A3818 for ; Wed, 18 Nov 2026 17:03:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4278060A3818 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=VvxeAFXj Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-8b4d26094beso12936357b3.1 for ; Wed, 18 Nov 2026 09:03:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda.com; s=google; t=1795021421; x=1795626221; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Y70yXZAvOr66TxVQEPkIiAIDxuUPqlw54kS33Yt/9Yg=; b=VvxeAFXjuopI0I2Mu1pmoG80zb9nFW9MNifuU2a++NMuSoxb8LNb9Lvv/nHUcOxGGv a6sJyMl9I/E+/mA9w3nkDaQAK5wDp7O4uMLi5+ypwPkDAFrsZNY4dxnk5jGRtsVWFrMN ERscCbz1TquRbEoaoCS/ss+u5qbMHwiiFhXxiz7hRGgGHl/iJY1tNpWNep7yE/5FHgzH Z7GqyBVuGIkGGp0i2u0s0gpfHXgpIw/ZA2ypd/HTWfZlw1AZu+8Tf/mfXJj+pVX9JTtU uA/FnqQoSloTlPWoQj90YnlZdVWtVcFqQIa+9nwH8tKMVgnRUXSeG1+0y/c7yAJt9Z+y ZSEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795021421; x=1795626221; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Y70yXZAvOr66TxVQEPkIiAIDxuUPqlw54kS33Yt/9Yg=; b=f1QCPSuc/SIbjHdAIBdH2IH9chnY2PW7k2ghFIsYjkJwXBYwkP/h978gsaVDShNiWs HljV/l2bRtjolBQZUABztmjEYr6vKkABghFQHCdIbvf76tJSGwyaFCah+oLOzrVC5ytC HuTvU+b3jOTRWhzkp+osHDfrHdm7EY9lX5gwF6HSMOW8zrDJhxx9mSGhUpHP1MVBqorG XvciPolRqVHJxbgiz4OoCTo+foVrjCoWMZuNe/+9a+ZPT7kOlGdK0Tq4IscCEpBBHdR1 BjazLcTsLhqhOpSEWStjM5BE94FfJ5dPRhdMikmbKwpMwyYfIKgnL2vk0Ld9Mvwk5Qsj 4weQ== X-Forwarded-Encrypted: i=1; AL+hErFy0Mc96eVrDleu4JkHWwtMR429prPuoiVKfajAW/Bli0nqBqGHxRMj+bmjiyLJ/PccYGQoTP4P/03QV0g=@vger.kernel.org X-Gm-Message-State: APuU4Z/jw505ePjJuluHsUQSVjEwUaOZ2ASBv0DcPZDVpbkBmWnjedkE q6nHH/52dzeA8OJTrNvjOt5Dy++BsCOWZiuqpCjX9Yum/9sb6KwptqyWa6pYCYl1W2s= X-Gm-Gg: AZFdTZeqA5YWL23x3pJHWspeXaNBzm+7Kjh9WcdSw17W9Dot1fFlaYilQbQJEaA7KdR jtldTndd0SVm7nLQnYUwr1e3QEsVFGutaa86m9heItkeQaSRcLwKoNNhY1Mt03uLbUHEb0KXN6Q SeXYSFsJC4rrxP5BaJRQowiaym1GkQTMOFXel807BoUKlYuxziQj3ddmi4VIsauQAxQx48r+z0s DGnDGVyAa4I4u+7AqXdJLEtFlYIHTxcch/Mughnt4kxPd9VqqiTXhbPHR1Hk02uvoxynqfqoeHQ /ecn7+xpF+GB2DkG2x/EwnevnwkpcJSVjEqvM1/2K3InzxDgELHbRcgHH0lG1D4rd9T+wgJcrUN Fg0vjBYeW5DUWmBB6LFIlOjtJvkiE7rID4Caxv7lXMzOjk6foiWDqP6tECzeYCpmA9ZLP0BOSIP ytHrUw90JYN+Ra4yQPxbQcGVSPfkbsiAdZW+wkGCqpf/47rSJjrlIPBuLkCA779U2NeaSycy/qO nuAKFLFigQvPu1g6SkSxCKH0uSy3VAItR1ImhkDcAF18KxQLnIPNjCvz+XrjOwKyzYYKqYiKr4y BWPvCtTmv2lOIatyHZ+XFqoE5NPwqo57JuysyYPBDVoFrQ== X-Received: by 2002:a05:690c:a417:20b0:8b5:6e9:217a with SMTP id 00721157ae682-8b506e927ebmr6451737b3.31.1795021420862; Wed, 18 Nov 2026 09:03:40 -0800 (PST) Received: from toxicpanda.com ([153.61.196.248]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9499b7ccf2fsm224499785a.36.2026.11.18.09.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 09:03:40 -0800 (PST) From: Josef Bacik Date: Wed, 18 Nov 2026 17:03:28 +0000 Subject: [PATCH v7 5/7] ovl: add a set of the inodes that a sync has to write X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-b4-ovl-containerized-sync-v7-5-54f45743fe55@toxicpanda.com> References: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> In-Reply-To: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> To: Miklos Szeredi , Amir Goldstein , Christian Brauner Cc: Alexander Viro , Jan Kara , Christoph Hellwig , Chris Mason , Chengguang Xu , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Josef Bacik X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openssh-sha256; t=1795021413; l=20402; i=josef@toxicpanda.com; h=from:subject:message-id; bh=firYUPSqbzQV1rQ8cQeHwp95pCeKXnKisRaN+Gl6t8o=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUBr36M/n0nWN0DNbnxwzIiCZez6MG JiruuNaSCI/zXsAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QEljXLHtzHBpk8vxccH/PMMI9TEAjtx8LAvS3h7xdPgPJpL3boy0e962JJt5UDTlAaBTV/pjA8c Zn1OCOKHeHgs= X-Developer-Key: i=josef@toxicpanda.com; a=openssh; fpr=SHA256:C8kOX2QUJCMqnCX+KEeoqRAjLo9L+ELOSH2NSAJHqGA To sync only what was written through an overlay, overlayfs has to know which upper inodes were modified through it. An overlay inode has no pages and no metadata of its own. What is dirty, under writeback or deferred by lazytime is the state of the upper inode, in another superblock, and nothing tells overlayfs when it changes. So do not mirror that state. Only remember the overlay inodes that were modified, in an xarray of the overlay, and let a sync ask the upper inode of each. The xarray has the marks of the page cache, dirty, towrite and writeback. This patch only uses the first, the others come with the sync. The set holds a reference to an inode that has a mark. The overlay inode holds the upper dentry, so the upper inode is one pointer away, whatever the upper filesystem is. An inode gets its slot in the xarray when it is allocated, and tracking it only sets a mark, so that cannot fail. The index is the address of the inode. i_ino is not unique in an overlay, and xa_alloc() needs one of the three marks for itself. So with fsync=3Drelaxed, which the default resolves to on most upper filesystems, every inode of the overlay, also one that is never modified, costs a slot and takes the lock of the xarray when it is allocated and when it is freed. All overlays allocate from one slab cache, so where their inodes are mixed a slot can cost a node of the xarray or more. With 64 overlays of 2000 files on a guest with KASAN and lockdep it is 21 bytes an inode if they are walked one after the other, 89 if all at once, and 489 if they take turns entry by entry. The tree is tall, about 6K for every overlay. An inode leaves the set in a sync, when it is unlinked, or when memory is needed and its upper inode has become clean. For the last one use the hooks of the superblock's own shrinker. Reclaim in a memory cgroup only runs shrinkers that have objects on a list_lru of that cgroup, which one of our own would not have. The hook only queues a work item. The reference that is dropped may be the last one to an upper inode that was unlinked, and filesystems allocate memory under locks that deleting a file needs. An inode only leaves the set for being clean if its upper inode is seen clean under the i_lock of the overlay inode, which tracking takes as well. A modification that came before is visible, and one that comes later puts the inode back. So whoever walks the set needs no lock against anybody else who does. With lazytime the upper inode holds timestamps back for up to a day. The last iput() would write them, but that cannot come while the inode is in the set. So the work item hands them to the upper filesystem. When an inode enters the set, remember where the wb_err of the upper mapping is. Writeback that fails from there on, whoever does it, is for a sync of the overlay to report, and until then the inode is not clean. Nothing is put into the set yet, and syncfs() still syncs the upper filesystem. Signed-off-by: Josef Bacik --- fs/overlayfs/Makefile | 2 +- fs/overlayfs/overlayfs.h | 13 ++ fs/overlayfs/ovl_entry.h | 9 ++ fs/overlayfs/params.c | 2 + fs/overlayfs/super.c | 11 +- fs/overlayfs/sync.c | 374 +++++++++++++++++++++++++++++++++++++++++++= ++++ 6 files changed, 409 insertions(+), 2 deletions(-) diff --git a/fs/overlayfs/Makefile b/fs/overlayfs/Makefile index 5648954f8588..080fb902bafd 100644 --- a/fs/overlayfs/Makefile +++ b/fs/overlayfs/Makefile @@ -6,4 +6,4 @@ obj-$(CONFIG_OVERLAY_FS) +=3D overlay.o =20 overlay-objs :=3D super.o namei.o util.o inode.o file.o dir.o readdir.o \ - copy_up.o export.o params.o xattrs.o + copy_up.o export.o params.o xattrs.o sync.o diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 13fbe016ed75..fad8ab77ac19 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -65,6 +65,8 @@ enum ovl_inode_flag { OVL_CONST_INO, OVL_HAS_DIGEST, OVL_VERIFIED_DIGEST, + /* Modified since a sync has started to write it, under i_lock */ + OVL_TRACKED, }; =20 enum ovl_entry_flag { @@ -886,6 +888,17 @@ struct inode *ovl_get_inode(struct super_block *sb, struct ovl_inode_params *oip); void ovl_copyattr(struct inode *to); =20 +/* sync.c */ +void ovl_track_init(struct ovl_fs *ofs); +void ovl_track_exit(struct ovl_fs *ofs); +int ovl_track_alloc(struct super_block *sb, struct inode *inode); +void ovl_track_inode(struct inode *inode); +void ovl_untrack_inode(struct inode *inode); +void ovl_forget_inode(struct inode *inode); +void ovl_drop_tracked(struct ovl_fs *ofs); +long ovl_nr_cached_objects(struct super_block *sb, struct shrink_control *= sc); +long ovl_free_cached_objects(struct super_block *sb, struct shrink_control= *sc); + /* vfs fileattr flags read from overlay.protattr xattr to ovl inode */ #define OVL_PROT_I_FLAGS_MASK (S_APPEND | S_IMMUTABLE) /* vfs fileattr flags copied from real to ovl inode */ diff --git a/fs/overlayfs/ovl_entry.h b/fs/overlayfs/ovl_entry.h index ac07e8769f9b..44e22b2860d2 100644 --- a/fs/overlayfs/ovl_entry.h +++ b/fs/overlayfs/ovl_entry.h @@ -92,6 +92,13 @@ struct ovl_fs { /* r/o snapshot of upperdir sb's only taken on volatile mounts */ errseq_t errseq; bool casefold; + /* The inodes that syncfs() and unmount have to write, see sync.c */ + struct xarray tracked; + atomic_long_t nr_tracked; + /* Reclaim has this drop what is clean: how many, and where it goes on */ + struct work_struct release_work; + atomic_long_t release_nr; + unsigned long release_id[2]; }; =20 /* Number of lower layers, not including data-only layers */ @@ -164,6 +171,8 @@ struct ovl_inode { const char *redirect; u64 version; unsigned long flags; + /* wb_err of the upper mapping up to where a sync has reported it */ + errseq_t wb_err; struct inode vfs_inode; struct dentry *__upperdentry; struct ovl_entry *oe; diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c index 549fc1e83ac9..370dd6341392 100644 --- a/fs/overlayfs/params.c +++ b/fs/overlayfs/params.c @@ -842,6 +842,7 @@ int ovl_init_fs_context(struct fs_context *fc) fc->ops =3D &ovl_context_ops; =20 mutex_init(&ofs->whiteout_lock); + ovl_track_init(ofs); return 0; =20 out_err: @@ -883,6 +884,7 @@ void ovl_free_fs(struct ovl_fs *ofs) kfree(ofs->config.workdir); if (ofs->creator_cred) put_cred(ofs->creator_cred); + ovl_track_exit(ofs); kfree(ofs); } =20 diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 31a58e28968c..5eb510bf1b9a 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -221,6 +221,10 @@ static struct inode *ovl_alloc_inode(struct super_bloc= k *sb) oi->__upperdentry =3D NULL; oi->lowerdata_redirect =3D NULL; oi->oe =3D NULL; + if (ovl_track_alloc(sb, &oi->vfs_inode)) { + kmem_cache_free(ovl_inode_cachep, oi); + return NULL; + } mutex_init(&oi->lock); =20 return &oi->vfs_inode; @@ -240,6 +244,7 @@ static void ovl_destroy_inode(struct inode *inode) { struct ovl_inode *oi =3D OVL_I(inode); =20 + ovl_forget_inode(inode); dput(oi->__upperdentry); ovl_stack_put(ovl_lowerstack(oi->oe), ovl_numlower(oi->oe)); if (S_ISDIR(inode->i_mode)) @@ -252,8 +257,10 @@ static void ovl_put_super(struct super_block *sb) { struct ovl_fs *ofs =3D OVL_FS(sb); =20 - if (ofs) + if (ofs) { + ovl_drop_tracked(ofs); ovl_free_fs(ofs); + } } =20 /* Sync real dirty inodes in upper filesystem (if it exists) */ @@ -327,6 +334,8 @@ static const struct super_operations ovl_super_operatio= ns =3D { .drop_inode =3D inode_just_drop, .put_super =3D ovl_put_super, .sync_fs =3D ovl_sync_fs, + .nr_cached_objects =3D ovl_nr_cached_objects, + .free_cached_objects =3D ovl_free_cached_objects, .statfs =3D ovl_statfs, .show_options =3D ovl_show_options, }; diff --git a/fs/overlayfs/sync.c b/fs/overlayfs/sync.c new file mode 100644 index 000000000000..03dfd903bf08 --- /dev/null +++ b/fs/overlayfs/sync.c @@ -0,0 +1,374 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * The inodes that syncfs() and unmount have to write with fsync=3Drelaxed. + * + * An overlay inode has no pages and no metadata of its own. What is dirt= y, + * under writeback or deferred by lazytime is the state of the upper inode= , and + * nothing tells overlayfs when it changes. So overlayfs does not mirror = that + * state. It only remembers which overlay inodes were modified, and a sync + * asks the upper inode of each of them. + * + * The set is an xarray with the marks of the page cache: + * + * OVL_X_DIRTY the upper inode was modified + * OVL_X_TOWRITE a sync that has begun is going to write it + * OVL_X_WRITEBACK a sync has started to write it + * + * The set holds one reference to an inode that has any of them. They cha= nge + * under the i_lock of the inode, except that OVL_X_TOWRITE is added to + * OVL_X_DIRTY under the lock of the xarray alone. + * + * There is one difference to the page cache. No completion clears + * OVL_X_WRITEBACK, whoever has waited does. Another sync may have starte= d the + * inode again meanwhile, so the mark only goes when the upper inode is se= en + * clean. That way whoever walks the set needs no lock against anybody el= se who + * does. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "overlayfs.h" + +#define OVL_X_DIRTY XA_MARK_0 +#define OVL_X_TOWRITE XA_MARK_1 +#define OVL_X_WRITEBACK XA_MARK_2 + +/* + * Index by address. Inodes are at least their size apart and the shift r= ounds + * down, so it stays unique, and neighbours in a slab share an xarray node. + */ +static unsigned long ovl_slot(struct inode *inode) +{ + return (unsigned long)OVL_I(inode) >> ilog2(sizeof(struct ovl_inode)); +} + +/* + * Give a new inode its slot in the set, so that tracking it later cannot = fail. + * An entry without a mark is never looked at. + */ +int ovl_track_alloc(struct super_block *sb, struct inode *inode) +{ + struct ovl_fs *ofs =3D OVL_FS(sb); + + if (!ovl_tracks_dirty(ofs)) + return 0; + + return xa_insert(&ofs->tracked, ovl_slot(inode), inode, GFP_KERNEL); +} + +/* + * @inode is about to be freed. It is not tracked, or it had a reference. + * + * Mount settles on the fsync mode after it has allocated the first trap i= nodes, + * so the mode does not tell if @inode has a slot. + */ +void ovl_forget_inode(struct inode *inode) +{ + struct ovl_fs *ofs =3D OVL_FS(inode->i_sb); + + WARN_ON_ONCE(ovl_test_flag(OVL_TRACKED, inode)); + if (!xa_empty(&ofs->tracked)) + xa_erase(&ofs->tracked, ovl_slot(inode)); +} + +static bool ovl_marked(struct ovl_fs *ofs, unsigned long id) +{ + return xa_get_mark(&ofs->tracked, id, OVL_X_DIRTY) || + xa_get_mark(&ofs->tracked, id, OVL_X_TOWRITE) || + xa_get_mark(&ofs->tracked, id, OVL_X_WRITEBACK); +} + +/* OVL_TRACKED is OVL_X_DIRTY without a walk down the tree */ +static void ovl_set_dirty(struct ovl_fs *ofs, struct inode *inode) +{ + unsigned long id =3D ovl_slot(inode); + + lockdep_assert_held(&inode->i_lock); + + if (ovl_test_flag(OVL_TRACKED, inode)) + return; + if (!ovl_marked(ofs, id)) { + struct inode *upper =3D ovl_inode_upper(inode); + + __iget(inode); + atomic_long_inc(&ofs->nr_tracked); + /* A sync reports what fails now, or what nobody has seen */ + OVL_I(inode)->wb_err =3D filemap_sample_wb_err(upper->i_mapping); + } + ovl_set_flag(OVL_TRACKED, inode); + xa_set_mark(&ofs->tracked, id, OVL_X_DIRTY); +} + +/* OVL_X_DIRTY goes first, nobody adds OVL_X_TOWRITE after that */ +static void ovl_clear_dirty(struct ovl_fs *ofs, struct inode *inode) +{ + unsigned long id =3D ovl_slot(inode); + + lockdep_assert_held(&inode->i_lock); + + ovl_clear_flag(OVL_TRACKED, inode); + xa_clear_mark(&ofs->tracked, id, OVL_X_DIRTY); + xa_clear_mark(&ofs->tracked, id, OVL_X_TOWRITE); +} + +/* + * The upper inode was modified through this overlay, remember the overlay + * inode for syncfs() and unmount. The caller holds a reference to @inode. + * + * Do not look at the upper inode here. Its dirty flags are cleared when = its + * writeback starts, not when it completes. + * + * Nobody needs an unlinked file to be durable, and the reference would ke= ep its + * space. An O_TMPFILE that can still get a name is not such a file. + * + * This takes i_lock even if @inode is tracked already, see ovl_untrack(). + */ +void ovl_track_inode(struct inode *inode) +{ + if (!ovl_tracks_dirty(OVL_FS(inode->i_sb)) || !ovl_inode_upper(inode)) + return; + + spin_lock(&inode->i_lock); + if (inode->i_nlink || (inode_state_read(inode) & I_LINKABLE)) + ovl_set_dirty(OVL_FS(inode->i_sb), inode); + spin_unlock(&inode->i_lock); +} + +/* + * Is there nothing that a sync would have to do for the upper inode? The + * caller holds i_lock. + * + * Stores through a shared mapping dirty the pages without a call into + * overlayfs, so the inode has to stay tracked while there may be one. The + * mapping holds the real file open for writing. Read i_writecount first:= the + * page cache tag is set before the last fput(). + * + * That does not cover pages that are pinned through such a mapping. A di= rect + * read into it that completes after the last munmap() and close() dirties= them + * with nobody looking. + * + * An error that was not reported yet is something to do as well. + */ +static bool ovl_upper_clean(struct inode *inode) +{ + struct inode *upper =3D ovl_inode_upper(inode); + struct address_space *mapping =3D upper->i_mapping; + + if (atomic_read_acquire(&upper->i_writecount) > 0) + return false; + + return !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) && + !mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK) && + !(inode_state_read_once(upper) & (I_DIRTY_ALL | I_SYNC)) && + !filemap_check_wb_err(mapping, OVL_I(inode)->wb_err); +} + +enum ovl_untrack { + OVL_UNTRACK_ALWAYS, + OVL_UNTRACK_CLEAN, /* if the upper inode is clean */ + OVL_UNTRACK_UNLINKED, /* if it has no link and cannot get one */ +}; + +/* + * Take @inode out of the set. The caller holds a reference to @inode of = its + * own. + * + * The condition is looked at under i_lock as well. A task that has called + * ovl_track_inode() before is ordered by i_lock, so what it did to the up= per + * inode, or to the link count, is visible. One that calls it later tracks + * @inode again. + */ +static bool ovl_untrack(struct inode *inode, enum ovl_untrack when) +{ + struct ovl_fs *ofs =3D OVL_FS(inode->i_sb); + unsigned long id =3D ovl_slot(inode); + bool done; + + spin_lock(&inode->i_lock); + done =3D ovl_marked(ofs, id); + if (done && when =3D=3D OVL_UNTRACK_CLEAN) + done =3D ovl_upper_clean(inode); + else if (done && when =3D=3D OVL_UNTRACK_UNLINKED) + done =3D !inode->i_nlink && + (!(inode_state_read(inode) & I_LINKABLE) || + hlist_empty(&inode->i_dentry)); + if (done) { + ovl_clear_dirty(ofs, inode); + xa_clear_mark(&ofs->tracked, id, OVL_X_WRITEBACK); + atomic_long_dec(&ofs->nr_tracked); + } + spin_unlock(&inode->i_lock); + + if (done) + iput(inode); + return done; +} + +/* + * A link to @inode was removed, or a dentry of it has gone and it may be = an + * O_TMPFILE that never got a name. The caller holds a reference to @inod= e. + */ +void ovl_untrack_inode(struct inode *inode) +{ + if (ovl_tracks_dirty(OVL_FS(inode->i_sb)) && !inode->i_nlink) + ovl_untrack(inode, OVL_UNTRACK_UNLINKED); +} + +/* + * Get a reference to the first inode with @mark from *@id on. A mark is + * cleared before the reference of the set is dropped, so under the lock o= f the + * xarray an inode that has one is alive. + */ +static struct inode *ovl_next_marked(struct ovl_fs *ofs, unsigned long *id, + xa_mark_t mark) +{ + struct inode *inode; + + xa_lock(&ofs->tracked); + inode =3D xa_find(&ofs->tracked, id, ULONG_MAX, mark); + if (inode) + ihold(inode); + xa_unlock(&ofs->tracked); + + return inode; +} + +/* Does only lazytime keep @upper from being clean? */ +static bool ovl_only_lazytime(struct inode *upper) +{ + return (inode_state_read_once(upper) & I_DIRTY_ALL) =3D=3D I_DIRTY_TIME && + atomic_read(&upper->i_writecount) <=3D 0; +} + +/* + * Drop @inode if its upper inode is clean. + * + * lazytime holds timestamps back for up to a day. The last iput() would = write + * them, but that cannot come while the overlay inode is tracked. So hand= them + * to the upper filesystem. Nobody has asked for them to be on disk, so t= here + * is nothing to wait for. + */ +static void ovl_release_inode(struct vfsmount *mnt, struct inode *inode) +{ + struct inode *upper =3D ovl_inode_upper(inode); + int err; + + if (ovl_untrack(inode, OVL_UNTRACK_CLEAN) || + !ovl_only_lazytime(upper) || mnt_get_write_access(mnt)) + return; + + err =3D write_inode_for_sync(upper); + mnt_put_write_access(mnt); + if (err) + errseq_set(&inode->i_sb->s_wb_err, err); + + ovl_untrack(inode, OVL_UNTRACK_CLEAN); +} + +/* + * Look at up to *@nr inodes with @mark. Dropping one writes nothing, so = that + * also works on an upper filesystem that has become read-only. It keeps a + * freeze out, because on a frozen filesystem dropping the last reference = to an + * inode that was unlinked sleeps until the thaw. + */ +static void ovl_scan_marked(struct ovl_fs *ofs, xa_mark_t mark, + unsigned long *id, unsigned long *nr) +{ + struct vfsmount *mnt =3D ovl_upper_mnt(ofs); + struct inode *inode; + + while (*nr && sb_start_write_trylock(mnt->mnt_sb)) { + --*nr; + inode =3D ovl_next_marked(ofs, id, mark); + if (inode) { + ovl_release_inode(mnt, inode); + iput(inode); + } + sb_end_write(mnt->mnt_sb); + + if (!inode) { + *id =3D 0; + break; + } + ++*id; + cond_resched(); + } +} + +/* + * An inode may be left with OVL_X_WRITEBACK alone, if a sync did not get = to + * wait for it. + */ +static void ovl_release_work(struct work_struct *work) +{ + struct ovl_fs *ofs =3D container_of(work, struct ovl_fs, release_work); + unsigned long nr =3D atomic_long_xchg(&ofs->release_nr, 0); + + ovl_scan_marked(ofs, OVL_X_DIRTY, &ofs->release_id[0], &nr); + ovl_scan_marked(ofs, OVL_X_WRITEBACK, &ofs->release_id[1], &nr); +} + +void ovl_track_init(struct ovl_fs *ofs) +{ + xa_init_flags(&ofs->tracked, XA_FLAGS_ACCOUNT); + INIT_WORK(&ofs->release_work, ovl_release_work); +} + +void ovl_track_exit(struct ovl_fs *ofs) +{ + unsigned long id =3D 0; + + /* Not xa_empty(), an insert that has failed can leave nodes behind */ + WARN_ON(xa_find(&ofs->tracked, &id, ULONG_MAX, XA_PRESENT)); + xa_destroy(&ofs->tracked); +} + +/* + * Unmount. The sync of generic_shutdown_super() has written what it coul= d, if + * the overlay is not read-only. evict_inodes() has left alone what is st= ill + * in the set. Trap inodes can be in the xarray as well, without a mark. + */ +void ovl_drop_tracked(struct ovl_fs *ofs) +{ + struct inode *inode; + unsigned long id; + + cancel_work_sync(&ofs->release_work); + + xa_for_each(&ofs->tracked, id, inode) { + ihold(inode); + ovl_untrack(inode, OVL_UNTRACK_ALWAYS); + iput(inode); + cond_resched(); + } +} + +long ovl_nr_cached_objects(struct super_block *sb, struct shrink_control *= sc) +{ + return atomic_long_read(&OVL_FS(sb)->nr_tracked); +} + +/* + * A tracked inode, its upper inode and the dentry of that cannot be recla= imed. + * While the upper inode is dirty that is as with any filesystem. Afterwa= rds + * nothing tells overlayfs, so look when memory is needed. + * + * Not from reclaim itself. The reference that is dropped may be the last= one + * to an upper inode that was unlinked, and handing over timestamps takes = locks + * of an upper inode that is in use. Filesystems allocate memory under the + * locks that both need. + */ +long ovl_free_cached_objects(struct super_block *sb, struct shrink_control= *sc) +{ + struct ovl_fs *ofs =3D OVL_FS(sb); + + atomic_long_add(sc->nr_to_scan, &ofs->release_nr); + queue_work(system_dfl_wq, &ofs->release_work); + + return 0; +} --=20 2.55.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795021423; b=JVeCbYFXogu9GkKHbF1WbppipA2CkCb9R3LOd+NikSvb/F7Tefvy5TcQDsvqofs/AtXk x9Z/Wkoa+1jmJjFoQ819q/iP5dcrSUpiyf535fVCLGIXH2PDTttB+oekkIWpm2C+1xb0o 4s91qfZ9iBQtaiI65XZELn0ih1x+9OnoTq5gs8fL83x1Q8PqdLQi+MaL5IOR8PIxRv/O2 0IBWgA2aBBSGSAfka/o8rzAO5jc68aursEZRMAhRzGXGvFf0gSKrDeLUm6RoVSK7rRxIL Xx991tlSgkOD9tjVBfnLCnoJQXbB1+5aJd3gHJNSkG2w1HNAhMQ8yo+0VGyrd3bXXIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795021423; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=fvH4Ub8pP4SdrCX5S0hlW5fTiXrWyYJiu9ya5yzf294=; b=QH4gTWq9AuLBBRGxSRPtewf9d6h5fYYam7LXNKQV1IhkpO31Z/17rJsLGiqA0KEPvAN7 Dxz7OCsACB4ncgvUnfREUIOwlhMRJOh4RLp13lOLuy3jgc3OYAkS8pCV9T7mxuC9BYmmi c52JAGpFGgy+qwIOFv9Ja8y7jY/ND2Ux7u4TmfJrui4u2G/f12xsX/OeMeGGsAUGbNP38 IEJJpjZiMmjyGqYLArP7YCOzVXrVRO8mBcGp3s7bsrbyOk7A9v9V1dRYg1J3oTsKQ3anV 5qtkxb/0X5uAIjvLo5bDACOcVViqtp92QiEGU+jia3NR2wf1uHIkcFgax+1ItAaBlUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=toxicpanda.com; spf=pass smtp.mailfrom=toxicpanda.com; dkim=pass header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=jtytjb57; arc=none smtp.remote-ip=209.85.160.173 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2990460A3822 for ; Wed, 18 Nov 2026 17:03:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2990460A3822 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=jtytjb57 Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-5569551d19dso381591cf.0 for ; Wed, 18 Nov 2026 09:03:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda.com; s=google; t=1795021422; x=1795626222; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=fvH4Ub8pP4SdrCX5S0hlW5fTiXrWyYJiu9ya5yzf294=; b=jtytjb57xWTV0T3LCUy3gueJ9ET8VJS5Lif7NquguELphfY9Sg8SADYdnucpgE+9tL JHjO1HaK5LNCd/fjguE4v+bDOqrwOYMyYEPI/5pj/ZirfgyCOcCNi9fXrn9mppI7tPPl 7j3W3u41eDM+UkvQIibSESXmVld4g397bUZv0DuoIdJbQEIUCzApfpTLDeiNDxY0J9vJ j8xtiH68EYMsfPK+yPvWhNMWz6pgihO4e8NknbslH9IWCNKGP982enbdFUdF9pyWrVZT ENEqzHPpFpsiNCQBugGdhHM28hyOY+vthdpwFP229gzP4ubaQhcGEOCqZIsru4WbZlG1 Qpnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795021422; x=1795626222; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fvH4Ub8pP4SdrCX5S0hlW5fTiXrWyYJiu9ya5yzf294=; b=GGWqIbmkoJhLVtY4QHyMvtgtOIyh7HgvVfzrrQrz83gsE8PqdY9PgbnUri7Xfy+8ef kwd85gwntfXi0zzHmoKgTz/CTZeJSl1iOQlDL9+sGytSCPJqIO7J/Wh42f+gnCn53TdY 51mFKvlvs6XvyxMAp+mhHmEWH6wa7SpFYRNS83+Bc0AdcRxDGfim0A7DRDgNANPNFhEd EAvDsKR2wYSqYUPf7T9Sh8msvsfwNuruesJz2zU5Pt2B7/yx7DDFAD9epFH149Y8My9p KUyGg5Hsu/mJyk7zuf8ie1JVX+pKZ3F2Ykbp1DfkqQvtsyh+cbvnbejGOM33SgeNVXWJ gCnA== X-Forwarded-Encrypted: i=1; AL+hErH3Kak0A0F1phBlkPQQsugSk3ozrRrtu0YjaZ6JmwrMC1f3LPyw6Wr7SzK6lcqIyBhXQ3rgwtO9XPnpqpo=@vger.kernel.org X-Gm-Message-State: APuU4Z+iVTZp2pMvThanIjmrlyliaE1MXxdYljMpfYhOAozB+rT4bQER ooN7oDlOObpS3dxLtCSVKfgbe6xbGL1tyY5AFMBBCUpj6gcGpjoledMkP+Db83qUBSw= X-Gm-Gg: AYBFou2I/UT6dXKNm531R9ixdOxKuLWvSh/Wtlz3kRKM1JnximfdKgLgKEQYHrkVXNy fEQLB8SjpyjX0VUbCRbn5u3T5b+PEvf11F3mdW5+1dFhA8b/Iu0SD5vgqQ06ySrhMPP4NakT7zB qH9aK5w2tDJz+iMKqEDOYoDgeaE7ZYGpLO2iR5CROB8SR6WYrqdxzdx7RkvctfJ81Ws6xBguepd RqZjLhL60NAmSI5qD5uhy8jG9NLlOJcK7fFkBZ9rBkCb3+kaLOCl8Nzkc7qSisZqfa3qGJXRsl4 MKor9UmV8RBOXwhHItquc3QstWZx0f/7p35+B6ZVvQ0gWrWVLAEbTsMMqlVcKHARAtOWd30W1oi WwfMbbZiUmHT7nD6UYj3iL6uzHt4E2A0tNErgi2iplq2Lre2sDm7BzTZk2EmMleP/TpLtVLy2Px cgV0EWd8sJKgGu95KBUPHv1jpvjdkgOPP9gPYhvtnbe+s4uCYYSw9493IizoO6rCqcbmss61Oh+ BogJqflEIKevc4OiQv3sze/NbRSN1PMb6jlejuWwqzm2mLf21ZzSCaZVy19ZxrPz7GmvFOaaLGc 6jTRdYlWABzA/QF2ecYTtoHl4V6uLRrDZmOsmzdk6jFhyg== X-Received: by 2002:a05:622a:888a:b0:531:2eb:be76 with SMTP id d75a77b69052e-55d685dca55mr1340681cf.22.1795021421979; Wed, 18 Nov 2026 09:03:41 -0800 (PST) Received: from toxicpanda.com ([153.61.196.248]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-55d66b75823sm3947741cf.13.2026.11.18.09.03.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 09:03:41 -0800 (PST) From: Josef Bacik Date: Wed, 18 Nov 2026 17:03:29 +0000 Subject: [PATCH v7 6/7] ovl: track an inode when it is modified X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-b4-ovl-containerized-sync-v7-6-54f45743fe55@toxicpanda.com> References: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> In-Reply-To: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> To: Miklos Szeredi , Amir Goldstein , Christian Brauner Cc: Alexander Viro , Jan Kara , Christoph Hellwig , Chris Mason , Chengguang Xu , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Josef Bacik X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openssh-sha256; t=1795021413; l=13673; i=josef@toxicpanda.com; h=from:subject:message-id; bh=sPqSka9KhAUm2vDOMU5sUKmAVVG3y6JkxmGpRbiINKM=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUBr36M/n0nWN0DNbnxwzIiCZez6MG JiruuNaSCI/zXsAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QGnsSjcuEKTtgEft92GUU32bXEuHRW8HnFTNhiaCJW68t6KKT4UsoRahoD+H6+lZqin6Mi/UD1S zS0NalCrLBQ4= X-Developer-Key: i=josef@toxicpanda.com; a=openssh; fpr=SHA256:C8kOX2QUJCMqnCX+KEeoqRAjLo9L+ELOSH2NSAJHqGA Put an overlay inode into the set of inodes to sync when its upper inode is modified through the overlay. Nearly every modification ends in ovl_copyattr(), so do it there. These do not, so they track the inode themselves: - copy up, for the inode and for its parent - ovl_instantiate(), for a new inode and for a new hard link - atime updates, if the atime of the upper inode has changed - the root, because the mount may have set xattrs on the upper root - shared writable mappings - the removal of a stale "impure" xattr in readdir - the "origin" xattr that lookup sets on a merge directory - the helpers that set the "impure", "redirect", "opaque" and "nlink" xattrs, and ovl_clear_empty() for the parent. The operation that calls them may still fail, and then it does not get to ovl_copyattr(). - a setattr that fails, it may have truncated some of the file Take an inode out of the set when its last link is removed. Nobody needs a deleted file to be durable, and the reference of the set would keep its space. An O_TMPFILE that can still get a name is tracked like any other file, and leaves the set when its dentry goes without one. syncfs() does not look at the set yet. Until the next patch an inode only leaves it when it is unlinked, at unmount, or when memory is needed. Based on work by Chengguang Xu. Link: https://lore.kernel.org/r/20211122030038.1938875-1-cgxu519@mykernel.n= et Suggested-by: Amir Goldstein Suggested-by: Miklos Szeredi Signed-off-by: Josef Bacik --- fs/overlayfs/copy_up.c | 9 +++++++++ fs/overlayfs/dir.c | 11 +++++++++++ fs/overlayfs/file.c | 7 ++++++- fs/overlayfs/inode.c | 27 +++++++++++++++++++++------ fs/overlayfs/namei.c | 9 +++++++-- fs/overlayfs/overlayfs.h | 1 + fs/overlayfs/readdir.c | 1 + fs/overlayfs/super.c | 11 +++++++++++ fs/overlayfs/util.c | 16 ++++++++++++++-- 9 files changed, 81 insertions(+), 11 deletions(-) diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c index c147ad155b79..f5c89af79e15 100644 --- a/fs/overlayfs/copy_up.c +++ b/fs/overlayfs/copy_up.c @@ -1223,6 +1223,15 @@ static int ovl_copy_up_one(struct dentry *parent, st= ruct dentry *dentry, err =3D ovl_link_up(&ctx); if (!err && ovl_dentry_needs_data_copy_up_locked(dentry, flags)) err =3D ovl_copy_up_meta_inode_data(&ctx); + /* + * All three write to the upper inode, and there may be no later + * write that would track the overlay inode. The first two + * also add an entry to the upper inode of the parent, set its + * "impure" xattr and restore its timestamps. + */ + ovl_track_inode(d_inode(dentry)); + if (parent) + ovl_track_inode(d_inode(parent)); ovl_copy_up_end(dentry); } do_delayed_call(&done); diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 1792e4114621..3d50e0e7183f 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -276,6 +276,9 @@ static int ovl_set_opaque_xerr(struct dentry *dentry, s= truct dentry *upper, err =3D ovl_check_setxattr(ofs, upper, OVL_XATTR_OPAQUE, "y", 1, xerr); if (!err) ovl_dentry_set_opaque(dentry); + /* A new directory has no inode yet, ovl_instantiate() tracks it */ + if (d_inode(dentry)) + ovl_track_inode(d_inode(dentry)); =20 return err; } @@ -330,6 +333,9 @@ static int ovl_instantiate(struct dentry *dentry, struc= t inode *inode, inc_nlink(inode); } =20 + /* The upper inode was just created, or has got a new link */ + ovl_track_inode(inode); + if (tmpfile) d_mark_tmpfile(tmpfile, inode); =20 @@ -457,6 +463,8 @@ static struct dentry *ovl_clear_empty(struct dentry *de= ntry, =20 err =3D ovl_do_rename_rd(&rd); end_renaming(&rd); + /* The caller tracks the parent, unless it fails after this */ + ovl_track_inode(d_inode(dentry->d_parent)); if (err) goto out_cleanup_unlocked; =20 @@ -971,6 +979,7 @@ static int ovl_do_remove(struct dentry *dentry, bool is= _dir) clear_nlink(dentry->d_inode); else ovl_drop_nlink(dentry); + ovl_untrack_inode(dentry->d_inode); } ovl_nlink_end(dentry); =20 @@ -1127,6 +1136,7 @@ static int ovl_set_redirect(struct dentry *dentry, bo= ol samedir) err =3D ovl_check_setxattr(ofs, ovl_dentry_upper(dentry), OVL_XATTR_REDIRECT, redirect, strlen(redirect), -EXDEV); + ovl_track_inode(d_inode(dentry)); if (!err) { spin_lock(&dentry->d_lock); ovl_dentry_set_redirect(dentry, redirect); @@ -1339,6 +1349,7 @@ static int ovl_rename_upper(struct ovl_renamedata *ov= lrd, struct list_head *list clear_nlink(d_inode(new)); else ovl_drop_nlink(new); + ovl_untrack_inode(d_inode(new)); } =20 ovl_dir_modified(old->d_parent, ovl_type_origin(old) || diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 7433220d4ad6..95dc34f2690b 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -472,8 +472,13 @@ static int ovl_mmap(struct file *file, struct vm_area_= struct *vma) .cred =3D ovl_creds(file_inode(file)->i_sb), .accessed =3D ovl_file_accessed, }; + int err; =20 - return backing_file_mmap(of->realfile, vma, &ctx); + err =3D backing_file_mmap(of->realfile, vma, &ctx); + /* Stores through the mapping go straight to the upper inode */ + if (!err && vma_is_shared_maywrite(vma)) + ovl_track_inode(file_inode(file)); + return err; } =20 static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff= _t len) diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index a11564e90751..08de2e9fdffa 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -84,11 +84,17 @@ int ovl_setattr(const struct mnt_idmap *idmap, struct d= entry *dentry, if (err) goto out_put_write; =20 + /* Before a truncate dirties a page, for errors of writeback */ + if (winode) + ovl_track_inode(dentry->d_inode); + inode_lock(upperdentry->d_inode); with_ovl_creds(dentry->d_sb) err =3D ovl_do_notify_change(ofs, upperdentry, attr); if (!err) ovl_copyattr(dentry->d_inode); + else + ovl_track_inode(dentry->d_inode); inode_unlock(upperdentry->d_inode); ovl_drop_write(dentry); =20 @@ -582,11 +588,17 @@ int ovl_update_time(struct inode *inode, enum fs_upda= te_time type, }; =20 if (upperpath.dentry) { + struct inode *upper =3D d_inode(upperpath.dentry); + struct timespec64 old =3D inode_get_atime(upper), new; + if (flags & IOCB_NOWAIT) return -EAGAIN; touch_atime(&upperpath); - inode_set_atime_to_ts(inode, - inode_get_atime(d_inode(upperpath.dentry))); + new =3D inode_get_atime(upper); + inode_set_atime_to_ts(inode, new); + /* touch_atime() may have had nothing to do */ + if (!timespec64_equal(&old, &new)) + ovl_track_inode(inode); } } return 0; @@ -898,7 +910,8 @@ void ovl_inode_init(struct inode *inode, struct ovl_ino= de_params *oip, oi->lowerdata_redirect =3D oip->lowerdata_redirect; =20 realinode =3D ovl_inode_real(inode); - ovl_copyattr(inode); + /* Nothing was changed, the inode is only being looked up */ + __ovl_copyattr(inode); ovl_copyflags(realinode, inode); ovl_map_ino(inode, ino, fsid); } @@ -975,7 +988,7 @@ static int ovl_set_nlink_common(struct dentry *dentry, struct inode *inode =3D d_inode(dentry); struct inode *realinode =3D d_inode(realdentry); char buf[13]; - int len; + int len, err; =20 len =3D snprintf(buf, sizeof(buf), format, (int) (inode->i_nlink - realinode->i_nlink)); @@ -983,8 +996,10 @@ static int ovl_set_nlink_common(struct dentry *dentry, if (WARN_ON(len >=3D sizeof(buf))) return -EIO; =20 - return ovl_setxattr(OVL_FS(inode->i_sb), ovl_dentry_upper(dentry), - OVL_XATTR_NLINK, buf, len); + err =3D ovl_setxattr(OVL_FS(inode->i_sb), ovl_dentry_upper(dentry), + OVL_XATTR_NLINK, buf, len); + ovl_track_inode(inode); + return err; } =20 int ovl_set_nlink_upper(struct dentry *dentry) diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index c6127edb9be9..353392dbbde4 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c @@ -951,7 +951,8 @@ static int ovl_fix_origin(struct ovl_fs *ofs, struct de= ntry *dentry, ovl_drop_write(dentry); out: kfree(fh); - return err; + /* Tell the caller that @upper was modified, it has no inode yet */ + return err ? err : 1; } =20 static int ovl_maybe_validate_verity(struct dentry *dentry) @@ -1102,6 +1103,7 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *c= tx, struct ovl_lookup_data struct dentry *origin =3D NULL; bool upperopaque =3D false; bool uppermetacopy =3D false; + bool origin_fixed =3D false; int metacopy_size =3D 0; unsigned int i; int err; @@ -1181,10 +1183,11 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx = *ctx, struct ovl_lookup_data */ if (ctx->upperdentry && !ctx->ctr && !ofs->noxattr && d->is_dir) { err =3D ovl_fix_origin(ofs, dentry, this, ctx->upperdentry); - if (err) { + if (err < 0) { dput(this); return err; } + origin_fixed =3D err; } =20 /* @@ -1370,6 +1373,8 @@ static int ovl_lookup_layers(struct ovl_lookup_ctx *c= tx, struct ovl_lookup_data return PTR_ERR(inode); =20 ctx->inode =3D inode; + if (origin_fixed) + ovl_track_inode(inode); if (ctx->upperdentry && !uppermetacopy) ovl_set_flag(OVL_UPPERDATA, ctx->inode); =20 diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index fad8ab77ac19..f4770b4c0222 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -886,6 +886,7 @@ bool ovl_lookup_trap_inode(struct super_block *sb, stru= ct dentry *dir); struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *di= r); struct inode *ovl_get_inode(struct super_block *sb, struct ovl_inode_params *oip); +void __ovl_copyattr(struct inode *to); void ovl_copyattr(struct inode *to); =20 /* sync.c */ diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c index 2018e3114655..599e76e1294a 100644 --- a/fs/overlayfs/readdir.c +++ b/fs/overlayfs/readdir.c @@ -745,6 +745,7 @@ static struct ovl_dir_cache *ovl_cache_get_impure(const= struct path *path) if (!ovl_want_write(dentry)) { ovl_removexattr(ofs, ovl_dentry_upper(dentry), OVL_XATTR_IMPURE); + ovl_track_inode(inode); ovl_drop_write(dentry); } ovl_clear_flag(OVL_IMPURE, inode); diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 5eb510bf1b9a..7f7d3993bc7a 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -187,8 +187,16 @@ static int ovl_dentry_init(struct dentry *dentry) #define ovl_dentry_init NULL #endif =20 +/* An O_TMPFILE that has not got a name cannot get one without a dentry */ +static void ovl_d_iput(struct dentry *dentry, struct inode *inode) +{ + ovl_untrack_inode(inode); + iput(inode); +} + static const struct dentry_operations ovl_dentry_operations =3D { .d_real =3D ovl_d_real, + .d_iput =3D ovl_d_iput, .d_revalidate =3D ovl_dentry_revalidate, .d_weak_revalidate =3D ovl_dentry_weak_revalidate, .d_init =3D ovl_dentry_init, @@ -197,6 +205,7 @@ static const struct dentry_operations ovl_dentry_operat= ions =3D { #if IS_ENABLED(CONFIG_UNICODE) static const struct dentry_operations ovl_dentry_ci_operations =3D { .d_real =3D ovl_d_real, + .d_iput =3D ovl_d_iput, .d_revalidate =3D ovl_dentry_revalidate, .d_weak_revalidate =3D ovl_dentry_weak_revalidate, .d_hash =3D generic_ci_d_hash, @@ -1407,6 +1416,8 @@ static struct dentry *ovl_get_root(struct super_block= *sb, ovl_dentry_set_flag(OVL_E_CONNECTED, root); ovl_set_upperdata(d_inode(root)); ovl_inode_init(d_inode(root), &oip, ino, fsid); + /* The mount may have set xattrs on the upper root */ + ovl_track_inode(d_inode(root)); WARN_ON(!!IS_CASEFOLDED(d_inode(root)) !=3D ofs->casefold); ovl_dentry_init_flags(root, upperdentry, oe, DCACHE_OP_WEAK_REVALIDATE); /* root keeps a reference of upperdentry */ diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c index 521717209b2e..2effec540dac 100644 --- a/fs/overlayfs/util.c +++ b/fs/overlayfs/util.c @@ -921,6 +921,8 @@ int ovl_set_impure(struct dentry *dentry, struct dentry= *upperdentry) err =3D ovl_check_setxattr(ofs, upperdentry, OVL_XATTR_IMPURE, "y", 1, 0); if (!err) ovl_set_flag(OVL_IMPURE, d_inode(dentry)); + /* Here, because the operation that needs this may still fail */ + ovl_track_inode(d_inode(dentry)); =20 return err; } @@ -1482,7 +1484,7 @@ int ovl_sync_status(struct ovl_fs *ofs) } =20 /* - * ovl_copyattr() - copy inode attributes from layer to ovl inode + * __ovl_copyattr() - copy inode attributes from layer to ovl inode * * When overlay copies inode information from an upper or lower layer to t= he * relevant overlay inode it will apply the idmapping of the upper or lower @@ -1492,7 +1494,7 @@ int ovl_sync_status(struct ovl_fs *ofs) * map any lower or upper inode owned by id 1001 to id 1000. These mapping * helpers are nops when the relevant layer isn't idmapped. */ -void ovl_copyattr(struct inode *inode) +void __ovl_copyattr(struct inode *inode) { struct path realpath; struct inode *realinode; @@ -1516,3 +1518,13 @@ void ovl_copyattr(struct inode *inode) i_size_write(inode, i_size_read(realinode)); spin_unlock(&inode->i_lock); } + +/* + * The attributes are copied because the real inode was modified through t= he + * overlay, so this is also where the overlay inode is tracked for a sync. + */ +void ovl_copyattr(struct inode *inode) +{ + __ovl_copyattr(inode); + ovl_track_inode(inode); +} --=20 2.55.0 From nobody Tue Nov 24 04:37:10 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795021425; b=sAtAlTOKBvOlox04DVMlgvr/g4WKoBdGcZbKBvHcVFgRJcS412rRb+JNiuu8aEXaNQGd Isw9qE25581DAixUtRBqcUIOnksjPDJTxx1+4tCXGnuT84CU/skqyTyJ5G3CyBQsdH3Jz e0dxhpJbxL80Nj/ZwBUUaWjEkW/4BD/bTOG9+ybLWGKPoKuumxPEfE5GHdEHTXF+R1Itq HOtWuzD7oE118IvlRaraFAcU8hUdF3gzD4YsUtDgwR5AFusGamCR2RVvU6S4+q7Zw2S8G aBQ4v+2DQ1Fe2r2DKi4GreumpEVoaF20PX2CevWIX2N8JQPC1n4bGHPG/o7FFHp7yfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795021425; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key; bh=GDaftTZG2qoD8d5JNs4QEnlOuUEcrK2xcraqbRaCDJg=; b=LipWpsayxYOTme0XLGYW3hiqRP7oYz2JfIFcEldWzUnPkeL7D1781xdZx0n/GGr+OpGr 6a/VtYgUhVTmS38xlZ4f85xSrS1FkjJsLiWwxHkFCVjU8KsqQeC7ncWSfuxqe7D70bzf+ t2/Ob5A+VDF8mKhjr4RUIoVuLmhHhbpBohaSv9+7udx8wr8Qrrtn9Nlge1NKH63wkntNd 49r7E0gFqeshMgsKxhbWAsTW2t/6Y4C1s/YS5C8QKW+n/rqNqGMjR67HZNIpr+sgJBXL4 QGEO6M3l3/oNHc/q16/WuiHJNUEzsp/LMZtEuip2shnFKLyCJ8Ze2DWqIAUgodI7Ong== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=toxicpanda.com; spf=pass smtp.mailfrom=toxicpanda.com; dkim=pass header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=kpkGONn7; arc=none smtp.remote-ip=209.85.128.178 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA86760A5BFD for ; Wed, 18 Nov 2026 17:03:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BA86760A5BFD Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda.com header.i=@toxicpanda.com header.a=rsa-sha256 header.s=google header.b=kpkGONn7 Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-8b0ca1ebc8bso12362377b3.2 for ; Wed, 18 Nov 2026 09:03:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda.com; s=google; t=1795021424; x=1795626224; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GDaftTZG2qoD8d5JNs4QEnlOuUEcrK2xcraqbRaCDJg=; b=kpkGONn7RLILDNmnhNLGBgd/HmKU4U2G+A+nbt6T7shuqZDw83TkR8kcQ+o09mCHHr a9hjwoRxj2eRp8Pvp7EmSl2aTkosi8JfqlgLSNoAhlDh9ONWKpCSbjEHfQ6ThvVLz2aq rVSjt6TMDpCrMgn6n7kje5j+MvklKhCjV8PCWiKN43iNC/AFfBZnBD/Vng7Gm9vhZHFU UlEPyIDjPCqWpgZNJfqqTs/McVOfiJQG1r2D3QewxQ9r0ph+R/8oiNrgSUyLbT0nKDlb Zv4q9f8muhQ+zoubIBW/qLqwNHLReNsk1nmdo5oHPww8rLFgk9V2TEkY8GXrEa1g5C6P QD+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795021424; x=1795626224; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GDaftTZG2qoD8d5JNs4QEnlOuUEcrK2xcraqbRaCDJg=; b=B9rfMiTISVQH89g+kfrM/AU222yFHcABdY9TJwYTsKh40ESu2LBDGmIjiXyELG5bEq Vg66NNAvklDvWFq+9gWZRWq+bTyDLHOCT/hQ1GnSL/PqpskGA/lpLXfw+FO0SaCg3LGd dUHSH0QxA17QNyezQGWUatkHSaQsIKS0X/Iqy8mukl7iLHLVRQEuNJ+ZYj7qpwAubdSM ZfCQT2QItoYdWYRZ2OyTgU5JuiIZJDMzQp4iNr4fITZhn1yyJg89iwZr9pklzdFpoP5C 81w3oUMQIzK/pYaD7tlSzWnpbRNkneGNHLQxBBS59eC3oyc5IAPvbScOXKf8KE3LlP/i CRuQ== X-Forwarded-Encrypted: i=1; AL+hErGAEuLEQADdRePSIYc4DMp1k4edShDLeYLsXvXZZjr9DJ5rBb9T6hs7r8XjTOdzxzQH8Y/i8/ZPU4ZAKTY=@vger.kernel.org X-Gm-Message-State: APuU4Z9atN+fp3mNkm2r2ip4Yt7bvNiU1GGAOBJ3s+dUa1ZjWwmZpkbc /M/WjKV3Q4iD+3v9kjLC+N/LaSS9PyNK0gLe0MStnoJBtQ4F3e3D7sHJoAO5/88Ulns= X-Gm-Gg: AZFdTZfA9jh4nlSjKfLbEsk9/fPyNj99g+3Vwfb8LH0H8xvxInH/CMvtDL1I0vWJYm7 3ERdapi8u/exkeI9U2ir1EpQXPYwOxGzoPce+qJjh5FHFtFxFjzusju+KvEywV2CXK3QFLltH2Z 6adP/vnmQhsKdf2zBQGnM7lGSRWXieapXZVn7SguGOb02oCVQxp3V6B1jRZZiu4FY9NRZTcbNCm zG83I/epwyd6094fFlP4+8Jag26BAKYqlwdu68Jct2TIwreumbQOSkIlMCxACwRHpDGA4McA+3y VjMNnRlBiDsWwhuUM8m1hNAPhCeVKAQ8/Zu4ThSA39Up9YZzIZ3kKo05GGmmLkhyEnRbSay302l vGSj/WtxECrTibt4fVMvxqep9+GN6BFSQXeAtxAFw8sYz2Opt1EwMwMahiG/gLk2GIRxa/F0ZbE daoUkO3/fvTuKFT1tvUVYJiIIBBCLHTSZ6As6AJ8DSpy9/J5nn7gROe5hvXFN2QY70fXhxYgwEd +riDaPmJqQjFeLMU3ZsPDPi/y2ll4367ZD0fs9ouu9xNqiCaXKfyW7DoKqWn/RrAaYu9qY++wj/ taZDIPsZYDPZQ53HHBwmnVfMaepJcmR5HovSVsTyK703qA== X-Received: by 2002:a05:690c:6987:b0:8b0:a8c1:b203 with SMTP id 00721157ae682-8b4fed186bamr13298507b3.29.1795021423355; Wed, 18 Nov 2026 09:03:43 -0800 (PST) Received: from toxicpanda.com ([153.61.196.246]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-55d66bb7125sm3914951cf.16.2026.11.18.09.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 09:03:42 -0800 (PST) From: Josef Bacik Date: Wed, 18 Nov 2026 17:03:30 +0000 Subject: [PATCH v7 7/7] ovl: implement containerized syncfs for overlayfs X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261118-b4-ovl-containerized-sync-v7-7-54f45743fe55@toxicpanda.com> References: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> In-Reply-To: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com> To: Miklos Szeredi , Amir Goldstein , Christian Brauner Cc: Alexander Viro , Jan Kara , Christoph Hellwig , Chris Mason , Chengguang Xu , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chengguang Xu , Josef Bacik X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openssh-sha256; t=1795021413; l=13738; i=josef@toxicpanda.com; h=from:subject:message-id; bh=xwQopqxAspN2Y7uS8EZ8sE3hY8fEG+A084bV3fjgQR8=; b=U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgUBr36M/n0nWN0DNbnxwzIiCZez6MG JiruuNaSCI/zXsAAAAGcGF0YXR0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5AAAA QEPNbGuvH/0gkRcepth3B5DQwgGs5rbVfSl/WtuZu45diccdoGHBVxsXqqEIp3d4s8EgXMXEPBA PYLYCVr5bfgU= X-Developer-Key: i=josef@toxicpanda.com; a=openssh; fpr=SHA256:C8kOX2QUJCMqnCX+KEeoqRAjLo9L+ELOSH2NSAJHqGA From: Chengguang Xu Now overlayfs can only sync own dirty inodes during syncfs, so remove unnecessary sync_filesystem() on upper file system. Do that with fsync=3Drelaxed only, which is what the default, fsync=3Dauto, selects on most filesystems. fsync=3Don brings the old behaviour back. Take the steps of sync_filesystem() for the upper filesystem, but only for the tracked inodes, and go about it like the page cache does. Without wait, ->sync_fs() gives every inode that is marked dirty the towrite mark. That is what this sync has to write. Then it starts writeback of the upper inode of each of them, and replaces dirty and towrite by the writeback mark. With wait, for every inode with the writeback mark, it calls write_inode_for_sync(), which also hands over the timestamps that lazytime has deferred, and waits for the data, whoever has started to write it. Both end with sync_fs_and_bdev(), which is what sync_filesystem() does after the inodes. Do the same for unmount and for a read-only remount. A sync tags once, so tasks that modify files do not keep it going. The marks are shared by all syncs that are running, so it also writes and waits for what another one tags ahead of it. A walk only goes up, so it ends. In the page cache the completion of the I/O clears the writeback mark. Here whoever has waited does, and another sync may have started the inode again meanwhile. So the mark only goes if the upper inode is seen clean. Until then every sync sees the inode and waits for it as well, so they do not have to wait for each other. Otherwise the inode is marked dirty again, which also covers an upper inode that is open for writing: stores through a shared mapping do not call into overlayfs. That does not cover pages that are pinned through such a mapping. A direct read into it that completes after the last munmap() and close() dirties them when the inode may have left the set, and the next syncfs() does not write them. syncfs() now also returns the error of writeback that the flusher of the upper filesystem has done before, which it did not do so far. It compares the wb_err of the upper mapping with what it was when the inode entered the set. Unlike the error flags of the mapping, nobody can take that away, an fsync() for one. The error is recorded in the superblock of the overlay under the lock that protects the cursor, so another syncfs() that runs at the same time gets it as well. A read-only remount of the overlay syncs it the same way, so it now fails with such an error, once. Keep a freeze and a read-only remount of the upper filesystem out while an inode is handed over. If one has already begun when ->sync_fs() is to wait, sync the whole upper filesystem, like before. If one kept it from starting an inode and has gone away since, start that inode then. Upper inodes that have no overlay inode, like whiteouts and the work directories, are not tracked. It is up to ->sync_fs() and the block device to get them to disk. ext4, xfs and btrfs log all metadata, and ext4 without a journal keeps it in the buffers of the block device. With many containers on one upper filesystem, stopping one of them no longer writes out the dirty data of all the others. Signed-off-by: Chengguang Xu [josef: everything after the first paragraph] Signed-off-by: Josef Bacik --- Documentation/filesystems/overlayfs.rst | 7 +- fs/overlayfs/overlayfs.h | 1 + fs/overlayfs/params.c | 14 +-- fs/overlayfs/super.c | 3 + fs/overlayfs/sync.c | 217 ++++++++++++++++++++++++++++= ++++ 5 files changed, 230 insertions(+), 12 deletions(-) diff --git a/Documentation/filesystems/overlayfs.rst b/Documentation/filesy= stems/overlayfs.rst index 8a007fbc5257..00e2cba65e2c 100644 --- a/Documentation/filesystems/overlayfs.rst +++ b/Documentation/filesystems/overlayfs.rst @@ -830,7 +830,12 @@ Traditionally, syncfs(2) and unmount of an overlay syn= c the entire upper filesystem, including the dirty data of other overlays that share it. Overlayfs can be told to only write back the files that were modified through the overlay, and then ask the upper filesystem to commit its -metadata. +metadata and write its block device. + +In that mode syncfs(2) also returns the error of writeback of such a file +that has failed earlier, like fsync(2) on the file does. As after fsync(2= ), +a file that is opened on the upper filesystem later does not get that error +any more. A read-only remount of the overlay fails with such an error onc= e. =20 On traditional local filesystems with a single journal (e.g. ext4, xfs), fsync on a file also persists the parent directory changes, because they diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index f4770b4c0222..63200551a7d0 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -899,6 +899,7 @@ void ovl_forget_inode(struct inode *inode); void ovl_drop_tracked(struct ovl_fs *ofs); long ovl_nr_cached_objects(struct super_block *sb, struct shrink_control *= sc); long ovl_free_cached_objects(struct super_block *sb, struct shrink_control= *sc); +int ovl_sync_tracked(struct super_block *sb, int wait); =20 /* vfs fileattr flags read from overlay.protattr xattr to ovl inode */ #define OVL_PROT_I_FLAGS_MASK (S_APPEND | S_IMMUTABLE) diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c index 370dd6341392..90111c480440 100644 --- a/fs/overlayfs/params.c +++ b/fs/overlayfs/params.c @@ -774,22 +774,14 @@ static int ovl_reconfigure(struct fs_context *fc) { struct super_block *sb =3D fc->root->d_sb; struct ovl_fs *ofs =3D OVL_FS(sb); - struct super_block *upper_sb; - int ret =3D 0; =20 if (!(fc->sb_flags & SB_RDONLY) && ovl_force_readonly(ofs)) return -EROFS; =20 - if (fc->sb_flags & SB_RDONLY && !sb_rdonly(sb)) { - upper_sb =3D ovl_upper_mnt(ofs)->mnt_sb; - if (ovl_should_sync(ofs)) { - down_read(&upper_sb->s_umount); - ret =3D sync_filesystem(upper_sb); - up_read(&upper_sb->s_umount); - } - } + if (fc->sb_flags & SB_RDONLY && !sb_rdonly(sb) && ovl_should_sync(ofs)) + return sync_filesystem(sb); =20 - return ret; + return 0; } =20 static const struct fs_context_operations ovl_context_ops =3D { diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 7f7d3993bc7a..a2d527f62d75 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -287,6 +287,9 @@ static int ovl_sync_fs(struct super_block *sb, int wait) if (!ret) return ret; =20 + if (!ovl_should_sync_upper_fs(ofs)) + return ovl_sync_tracked(sb, wait); + /* * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC). * All the super blocks will be iterated, including upper_sb. diff --git a/fs/overlayfs/sync.c b/fs/overlayfs/sync.c index 03dfd903bf08..55d40cde8984 100644 --- a/fs/overlayfs/sync.c +++ b/fs/overlayfs/sync.c @@ -372,3 +372,220 @@ long ovl_free_cached_objects(struct super_block *sb, = struct shrink_control *sc) =20 return 0; } + +/* + * Keep a freeze and a read-only remount of the upper filesystem out. Do = not + * wait for either. + */ +static bool ovl_upper_start_write(struct ovl_fs *ofs) +{ + struct vfsmount *mnt =3D ovl_upper_mnt(ofs); + + if (!sb_start_write_trylock(mnt->mnt_sb)) + return false; + if (mnt_get_write_access(mnt)) { + sb_end_write(mnt->mnt_sb); + return false; + } + return true; +} + +/* + * Like tag_pages_for_writeback(): what is dirty now is what this sync has= to + * write. + */ +static void ovl_tag_for_writeback(struct ovl_fs *ofs) +{ + XA_STATE(xas, &ofs->tracked, 0); + unsigned int tagged =3D 0; + struct inode *inode; + + xas_lock(&xas); + xas_for_each_marked(&xas, inode, ULONG_MAX, OVL_X_DIRTY) { + xas_set_mark(&xas, OVL_X_TOWRITE); + if (++tagged % XA_CHECK_SCHED) + continue; + + xas_pause(&xas); + xas_unlock(&xas); + cond_resched(); + xas_lock(&xas); + } + xas_unlock(&xas); +} + +/* + * Start to write the data of the upper inode. OVL_X_WRITEBACK is set bef= ore + * OVL_X_DIRTY is cleared, so that a sync always finds one of them, and + * OVL_X_DIRTY is cleared before the write, so that a modification that co= mes + * later sets it again. + */ +static void ovl_start_inode(struct super_block *sb, struct inode *inode) +{ + struct ovl_fs *ofs =3D OVL_FS(sb); + unsigned long id =3D ovl_slot(inode); + bool start; + int err; + + spin_lock(&inode->i_lock); + /* It may have been unlinked, or another sync was here first */ + start =3D xa_get_mark(&ofs->tracked, id, OVL_X_TOWRITE); + if (start) { + xa_set_mark(&ofs->tracked, id, OVL_X_WRITEBACK); + ovl_clear_dirty(ofs, inode); + } + spin_unlock(&inode->i_lock); + + if (!start) + return; + + /* Tags the pages first, so it does not follow an appender */ + err =3D filemap_fdatawrite(ovl_inode_upper(inode)->i_mapping); + /* If ->sync_fs() returned it the VFS would not call again to wait */ + if (err) + errseq_set(&sb->s_wb_err, err); +} + +/* + * Write the upper inode and wait for its data, whoever has started to wri= te it. + * + * After that OVL_X_WRITEBACK goes if the upper inode is clean. If it is = not, + * another sync may have started it again and relies on the mark, or it is= open + * for writing and the next sync has to write it again. + * + * Writeback of the upper inode that has failed since @inode has entered t= he + * set, whoever has done it, shows in the wb_err of the mapping. Nobody t= akes + * that away, unlike the error flags. It is recorded in the superblock of= the + * overlay under the lock that protects the cursor. So another syncfs() t= hat is + * here at the same time finds the one or the other. + * + * btrfs records an error after it has ended writeback. If that is too la= te for + * the look here, the error is reported once the inode is modified again. + */ +static int ovl_wait_inode(struct super_block *sb, struct inode *inode) +{ + struct ovl_fs *ofs =3D OVL_FS(sb); + struct inode *upper =3D ovl_inode_upper(inode); + struct address_space *mapping =3D upper->i_mapping; + unsigned long id =3D ovl_slot(inode); + bool drop =3D false; + int err, err2 =3D 0; + + err =3D write_inode_for_sync(upper); + if (err) + errseq_set(&sb->s_wb_err, err); + filemap_fdatawait_keep_errors(mapping); + + spin_lock(&inode->i_lock); + if (xa_get_mark(&ofs->tracked, id, OVL_X_WRITEBACK)) { + err2 =3D errseq_check_and_advance(&mapping->wb_err, + &OVL_I(inode)->wb_err); + if (err2) + errseq_set(&sb->s_wb_err, err2); + + if (ovl_upper_clean(inode)) { + xa_clear_mark(&ofs->tracked, id, OVL_X_WRITEBACK); + drop =3D !ovl_marked(ofs, id); + if (drop) + atomic_long_dec(&ofs->nr_tracked); + } else { + ovl_set_dirty(ofs, inode); + } + } + spin_unlock(&inode->i_lock); + + if (drop) + iput(inode); + return err ? err : err2; +} + +/* + * Start every inode that has OVL_X_TOWRITE, or finish every inode that has + * OVL_X_WRITEBACK. + * + * Do not write to an upper filesystem that is frozen or read-only, or on = its + * way there. Keep a freeze and a read-only remount out meanwhile, inode = by + * inode, because writers wait behind a freeze that waits for us. + * + * Returns false if one of the two has begun. + */ +static bool ovl_walk_marked(struct super_block *sb, xa_mark_t mark, int *e= rror) +{ + struct ovl_fs *ofs =3D OVL_FS(sb); + struct inode *inode; + unsigned long id =3D 0; + int err; + + for (;;) { + if (!ovl_upper_start_write(ofs)) + return false; + + inode =3D ovl_next_marked(ofs, &id, mark); + if (inode && mark =3D=3D OVL_X_TOWRITE) { + ovl_start_inode(sb, inode); + } else if (inode) { + err =3D ovl_wait_inode(sb, inode); + if (err && !*error) + *error =3D err; + } + iput(inode); + mnt_drop_write(ovl_upper_mnt(ofs)); + + if (!inode) + return true; + id++; + cond_resched(); + } +} + +/* + * This tags once, so tasks that modify files do not keep it going. The m= arks + * are shared with every other sync that is running, and what those tag ah= ead of + * a walk is written and waited for as well. But a walk only goes up, so = it + * comes to an end. + */ +static bool ovl_sync_inodes(struct super_block *sb, int wait, int *error) +{ + if (!wait) + ovl_tag_for_writeback(OVL_FS(sb)); + + /* + * With @wait this is for what the call before could not start, because + * of a freeze or a remount that has gone away again. + */ + if (!ovl_walk_marked(sb, OVL_X_TOWRITE, error)) + return false; + + return !wait || ovl_walk_marked(sb, OVL_X_WRITEBACK, error); +} + +/* + * syncfs(), unmount or a read-only remount of an overlay with fsync=3Drel= axed. + * sync_filesystem() calls this without @wait first and then with. The st= eps + * are those that it takes itself for the upper filesystem, except that on= ly the + * tracked inodes are written. + */ +int ovl_sync_tracked(struct super_block *sb, int wait) +{ + struct super_block *upper_sb =3D ovl_upper_mnt(OVL_FS(sb))->mnt_sb; + int ret, err =3D 0; + bool done; + + done =3D ovl_sync_inodes(sb, wait, &err); + + down_read(&upper_sb->s_umount); + /* + * If the upper filesystem is frozen or read-only, or on its way there, + * sync all of it when asked to wait, like without fsync=3Drelaxed. + * + * Otherwise this has to take care of the upper inodes that have no + * overlay inode, like whiteouts and the work directories. + */ + if (wait && !done) + ret =3D sync_filesystem(upper_sb); + else + ret =3D sync_fs_and_bdev(upper_sb, wait); + up_read(&upper_sb->s_umount); + + return err ? err : ret; +} --=20 2.55.0