From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796044956; b=MvGsqk+ANcDeeLYPeDnjt/9k2LIKk17ysGoeD/5l6vZZ67hsD7Bek5gHF4mMwoZHyPls gNnkxdIzKHgAFyjERjMehhcWGtCpIRTV4E2ZNAmG8fCdLQpNGaj4n0oAcwltz3prJLXul v6UL5r3joBSGF2PFXlc+ZidzPPdYI0kI8Pj0CVFK59EyKTWiUBFAmw8I99cB/uLHF770Z HQ+o/aLKyYuwIDyI36Bi9DIguF7zz17zKfXL5rRfzdgL+2ZnEYupGwwQMwfAiwG5gg4t7 hU/xbHc/V9kfnA2p3xKnwuKwIFqro+bWrTDf/93GccgIQVlBc4GJeIS5KeqZPBknHkA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796044956; h=Received:DKIM-Signature:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key; bh=oXEyLbc8M7gmio+gvGip3buD25VfJ4KphAoOcxFEq9w=; b=pbnWIcLo0LCjamq+RHYqZ9hATLUuX50aOknqauEqS2VQMUFHj6yBpb3crolCxkiXfRCk hhhcVMjcXHQMYlLayzaHAXQfq3lbYhUTaWMM78BBrL8NE7ovafgun+Xw2Xd0NxkvihGZi G4tpI5a//Kv/hGtqofm2iIJYbjClQoevIt0mYjsPyAndW6MEBTIQZfpKPgR7EC4CcVzMI B21opfYcTBB9zKFb2ALxjulcsiImrsz/+Owa/sSKm0mGKm3gJS9cfn74T803r7PYWvume RCCduImUrpIb0dhmcB7STWXc2bikWWGgnejx9dOsoGNeeXPydGgj8h7EjfsxlD8Tqnw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=imdzfnY7; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8863F606A31C; Mon, 30 Nov 2026 13:22:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=imdzfnY7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A67F1F00897; Mon, 30 Nov 2026 13:22:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796044956; bh=oXEyLbc8M7gmio+gvGip3buD25VfJ4KphAoOcxFEq9w=; h=From:Subject:Date:To:Cc; b=imdzfnY7i+HWeHXD74nePt3wPzMGoBg5dFrA/OTLlghqDmFNkzMk028kAdJUB19N5 RzVKBa7h9Gg6YnYs/FaucS56yNd/1wxRr/tVEkl3Cz0Dx5Cxwu4VS2JtKhhO3pLnqs CcAUVfkIKueG6T26fv83/4sHmk4z8ZAIF7ZWbGAQeHQs+GBVqhzudDTANuBRN5nheb akbjaq/FSAkGZJ0Y8G5qALFz7lPMHtIUpt1XLJ92Xo/csoq85jhn1sSFeOf5sZhb1c FqWCS4uyicWUqB42KElCuLZLxxkzHBWZGf7uG7nz2I4LC0sggQDivUzJ96avPxyNhU 412rODTFcMFzQ== From: Christian Brauner Subject: [PATCH 0/4] ext4: don't fail FS_IOC_{SETFLAGS,FSSETXATTR} after applying them aka things that fell out of my uapi16 library work Date: Mon, 30 Nov 2026 14:22:12 +0100 Message-Id: <20261130-work-ext4-setflags_migrate-v1-0-80f1875cfadc@kernel.org> X-Mailing-List: linux-ext4@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: 7bit X-B4-Tracking: v=1; b=H4sIAAAAAAAC/13MywrCMBCF4Vcps3ZKU0NBX0VEkjhJ4yWVmaiF0 nc30Z3L/3D4FhDiSAL7ZgGmV5Q4pRJq04AbTQqE8Vwa+q4flNp2+J74ijRnjULZ30yQ0z0GNpl QK1I7rwevSUEBHkw+zl/8cPy1PO2FXK5ifVgjhJZNcmOdqt1Wu/232/qEdf0Akvmvf7AAAAA= X-Change-ID: 20261130-work-ext4-setflags_migrate-41e19f46f4e1 To: Theodore Ts'o , Jan Kara , linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, "Christian Brauner (Amutable)" X-Mailer: b4 0.17-dev-04696 X-Developer-Signature: v=1; a=openpgp-sha256; l=4004; i=brauner@kernel.org; h=from:subject:message-id; bh=ZKA9WCPQA7SZ2JwmPZy1ncjHQOPHXLDnKwnNq7qb4w4=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWTzVkw2CmaNuxtix/65XnLnhS38NRHfPScu+brB8oKN3 zpLG9njHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABNp12BkmGX4PqTs4km3/TPE Lh9VPjOrJzJSa53SnfREbnvXy+L7DjEy3HkQK/A9J/fQCeXEvfGp5199vmk8U2yqr/LzjfZFLsJ HOAE= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 I'm working on a uapi16 shared library and tool that generates filesystem manifests according to https://uapi-group.org/specifications/specs/file_manifest It's a Rust crate + C shared library + Rust binary. It has extensive testing and as part of that some ext4 misbehavior was detected. So here's my attempt at fixing it: ext4 fails FS_IOC_SETFLAGS and FS_IOC_FSSETXATTR after it has already written part of the request. The flags and the ctime are written first and only then is the block mapping converted, the journaling mode switched or the project ID changed. If one of those is refused the call fails but the flags stick. We hit this with a test that passed FS_NODUMP_FL | FS_NOATIME_FL to FS_IOC_SETFLAGS without reading the flags first. It got EOPNOTSUPP back with both flags set. xfs and btrfs check everything before they write anything and then do the whole change in a single transaction. This gets ext4 there for everything that can share a handle. Converting to block mapping and changing the project ID now happen in the same handle as the flags. The first patch fixes ext4_ext_migrate(). Since v5.5 it returns the result of its last credit check instead of its own, so a conversion to extents that fails with ENOSPC is reported as success and a restarted handle comes back as 1. Once the conversion runs before the flags that 1 would silently drop the rest of the call. The one real question is what to do about a cleared extent flag that ext4 can't honor. Callers that don't start from FS_IOC_GETFLAGS leave the flag out. Today that silently converts small files to block mapping and fails for everything else. I'm treating it like the other visible but unsettable flags. If anything else was asked for the rest is applied and the call succeeds. If clearing the extent flag is all that was asked for it still fails and nothing changes. btrfs silently leaves NOCOW alone on a non-empty file too. Failing and changing nothing would be stricter but it would break restore tools that only work today because the flags stick. BorgBackup before 1.4.2 builds its flags from scratch and ignores EOPNOTSUPP for example. Borg switched to FS_IOC_GETFLAGS in 1.4.2 after running into exactly this (cf. [1]) but the older releases are still around. The downside is that repeating such a call fails the second time because then only the extent flag differs. That's the same request as chattr -e though so I don't see a way to tell them apart. A refused attempt to set the extent flag, i.e., no extents feature or inline data, still fails but doesn't apply the rest anymore. I didn't give it the same treatment as the cleared flag. If you'd rather have that it's a small change. Setting the extent flag and switching the journaling mode still use their own handles. ext4_ext_migrate() builds the new tree in a temporary inode across several handles and the mode switch flushes the journal. Their refusals happen before anything is written now but an I/O error between them and the flags handle can still leave part of the change behind. Tested in VMs on 4k and 1k blocks with bigalloc, ext3, inline data, buffered_iomap, dioread_lock, DAX and project quota, and with two new fstests cases that I'll send separately. [1]: https://github.com/borgbackup/borg/issues/9039 Signed-off-by: Christian Brauner (Amutable) --- Christian Brauner (4): ext4: don't lose the result of ext4_ext_migrate() ext4: don't fail FS_IOC_SETFLAGS after applying it ext4: split the flag checks out of ext4_ioctl_setflags() ext4: don't fail FS_IOC_FSSETXATTR after applying it fs/ext4/ext4.h | 3 +- fs/ext4/ioctl.c | 333 ++++++++++++++++++++++++++++++------------------------ fs/ext4/migrate.c | 69 ++++++----- 3 files changed, 218 insertions(+), 187 deletions(-) --- base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f change-id: 20261130-work-ext4-setflags_migrate-41e19f46f4e1