Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796293167; b=m12DKrCN9i7bwELxFNRYrqKmLQZkLW25NX0CeZOLvDAkkVg8wgaAcxNZcLXCod/wqVr1 DnSyqzx6g7jOcQDuytZXRmtpPvffsQ/vGmzOkzq4JhoGw4JNSJP5RHtYn4Wtqln/VgK2R Fv9cyouYCBLxmZsQrBjSwpODvEByO8eSPl+fDSnVYIEIyTZ50UKJgA6G9/4RSkw1jrsJq Er77QMKzE6T39yqQr/LBZECzDvLzgX3Q1NOy5e2EMViRsASJ45peKqSgYY7JEt4Mr961d p8/y82wDLtxkbTaxc3/HunV7WNwcWKXQPr3LeQRDAreaHFrQDRwNvym3jquD0x+h3IQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796293167; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=3JHvyCGv2J3UpD7OgArEWVY10BzVs+9MgsTlTIe4z/Y=; b=lRWEHr7odZDlGie6OatqKEKtHWTagICr3/UalF7FpPE3JAjk1KT28LTV5BJQIDW1pgsh SoqobruPZmjllAd/W2dINgsOidp6JRRc6xJx9GIq297xryq71MS6fbPfjgRwCjlsSn8sd slMkfgpoWgjCZfG0K9pQLEBFgxKQyXsUrMD/3h27jz6MThvPay3ZFfhkbzzIMQrOwW37p 9jU/PriuVnRdGnEc0z6LmjesBsgPJenH0gLNt+YWPKmEcELtC2Gy+FQeIorBovVHKsxPk xfJ1bETmkg2IVxzFPjwwS8OwlqEhoGPipByyiuwjiywntsvuDP8QzJNQwlHDZV93RXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="JCJq63/4"; arc=none smtp.remote-ip=209.85.128.43 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 674A8606A33C for ; Thu, 3 Dec 2026 10:19:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 674A8606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JCJq63/4 Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4bba5e17728so74012975e9.2 for ; Thu, 03 Dec 2026 02:19:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796293166; x=1796897966; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3JHvyCGv2J3UpD7OgArEWVY10BzVs+9MgsTlTIe4z/Y=; b=JCJq63/4L4zV26/i9INl+Xo/K1UoHbpGWXCXQQ6HiKKpcn50S1imkeRcOvw3OGcOAO JyagDWkRd7tGnques1yC+xV8td9VtTUsQAepMUc+2sk2trViA5EmnqRSYtoOAWjWWfAB TuFR06pforP8tfEq3TUyfBmFZdpuXfok7USsBm0UBBYz2DAj7xYXgxRtHjHRCCgntn7a QP71wfw0y52TqlKj5dVti7a+tW3pWbgqYlK+6oNFK3ftgCVw6RBVavJbHNjTsf7098z3 sz0HIsMHfecL8FytHf4Uzui05J4ksMZx0CzViQRgLSgnXd/Bv7gcepxtyqzX0hg9iNlE nYWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796293166; x=1796897966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=3JHvyCGv2J3UpD7OgArEWVY10BzVs+9MgsTlTIe4z/Y=; b=dEG1XKSy3onSRZyITyCxxCzmTfbDl4RhL3aiTu+FgWAYU5tcyTrs0dmqJAu0uP+eGV rbvh14LEkdjQWVwwfz84m4Ckztm2wk0wNcA8M9d8mOSkR1ZpPo0hf8K7nZ12TSM7i2Yn mo2+McXLzQs+N8q6wRP7KaLHtYTqOzf9iBJu/mJSQ6Lme6/+4aGM7UH7kpoKfeWktxgq UGoxmRIqNJ3z4BiU+RtFq65Dp84SVmXE3LAUr8rOkSyhnlf/ehG899HadwrdA9hltgcY d6RamX6eOKRJxebIZ757bttvsgj9AmBB8YrMlHdLpXKUGYLriF6Dl32cRH+FF34K+93f kzZQ== X-Forwarded-Encrypted: i=1; AL+hErFaJtzL14zl9awXFHKKK+13ZNA71HBi8i6uFDDGF38MfQkHM9ThwnkRkvRKEsihL50VIe67rcSplR8n7g==@vger.kernel.org X-Gm-Message-State: APuU4Z8kELYn59rf0+eyamHvOpS6qHEQEeAHaX8PeR8Gpg/2JnUx/GuX CobrSXtlM44F6kOBNfI0HhDjAXF5NbmMi/qAzg3OwQ4mv7dzO7zxjlmM X-Gm-Gg: AZFdTZdSaKk13Fi9Oi3+Tb7Yl/41/s/QEsf8dtqXYSbsXXec5dRWOh20oMiowPBtuRW L6APejrBEkCOy5EwRoVee3ExIy/enQKSdh+sJ4JkXdI440UpDdnmHcBbE5LMyqpfND06lw9NrJl Mosl9DpfYtCkhiXi497ibjQ8bTnyDsL8drmJAd9ul/ceYjntFKgr3Kysacdnv4/WxM2n8c8gLBZ 5t69s0/QKGGhu4mfqkpcJXBPZE+MaCzQ+eNlkqqUrEfHPzIL5tEpNHorV64xGVb3Dliv2j4iYVs hhMj4LsvLlhA9CCg6/ojDx2ktYa+WcTseglAdQNCapGfVwsX8WJOavHyHb5qU9LZ7FGX6rYmM0M L5A0+jtpzX62i0xuRxWaHIZJuev0F78FWb+FDCzJrx5DyWN96aDNs5OMmjirHTqcsw5q8A986pk RUxk0RnBP79fZHejhoYxDhSbyjfa0CyRNU5UHh9W2CCfbOjJIqMSpzCIJpIBgSCfIM97U7PzKPg U9191TprkmZeayDh5aYiucX+6Cba/OjoM95dcAriYwlJ3XO273Y/qKIkL33HiAfaLdyadJWLivJ ZnlP+IcWbK70oyW9lbano49T X-Received: by 2002:a05:600c:4e0d:b0:4ab:e27d:e241 with SMTP id 5b1f17b1804b1-4bb88922c6amr778153385e9.15.1796293165671; Thu, 03 Dec 2026 02:19:25 -0800 (PST) Received: from infinity ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab69bf630esm85402565f8f.16.2026.12.03.02.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 02:19:25 -0800 (PST) From: koraynilay To: David Sterba Cc: Chris Mason , Qu Wenruo , Zygo Blaxell , linux-btrfs@vger.kernel.org, koraynilay Subject: [PATCH v6 RESEND 6/6] btrfs: preserve btrfs.compression when setting inode flags Date: Thu, 3 Dec 2026 11:19:04 +0100 Message-ID: <20261203101904.204251-7-koray.fra@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261203101904.204251-1-koray.fra@gmail.com> References: <20261203101904.204251-1-koray.fra@gmail.com> X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit e8a0095c7df170 ("btrfs: preserve the compression property when other inode flags change") fixed an issue where any call to FS_IOC_SETFLAGS (e.g. via chattr) would overwrite the btrfs.compression property with the mount default compression type, even when no flag bits change and even for flags unrelated to compression. Update the fixed code to also preserve the newly introduced level specification by using the new btrfs_compress_typelevel2str() helper. Also move BTRFS_COMPRESS_PROP_MAX_LEN from props.c to props.h so it can be used by ioctl.c, since it now requires a temporary buffer to write the property string to. [ Commit message and code adapted from Zygo's patch for this same issue ] Reported-by: Zygo Blaxell Suggested-by: Zygo Blaxell Assisted-by: Gemini:3.1-pro antigravity-cli-1.1.7 Signed-off-by: koraynilay --- fs/btrfs/ioctl.c | 27 ++++++++++++++------------- fs/btrfs/props.c | 9 --------- fs/btrfs/props.h | 9 +++++++++ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 651a780dd7b1..56aad3f98859 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -288,6 +288,7 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap, unsigned int fsflags, old_fsflags; int ret; const char *comp = NULL; + char comp_buf[BTRFS_COMPRESS_PROP_MAX_LEN]; u32 inode_flags; bool prop_set = false; @@ -397,7 +398,6 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap, inode_flags &= ~BTRFS_INODE_COMPRESS; inode_flags |= BTRFS_INODE_NOCOMPRESS; } else if (fsflags & FS_COMPR_FL) { - enum btrfs_compression_type comp_type; if (IS_SWAPFILE(&inode->vfs_inode)) return -ETXTBSY; @@ -406,22 +406,23 @@ int btrfs_fileattr_set(const struct mnt_idmap *idmap, inode_flags &= ~BTRFS_INODE_NOCOMPRESS; /* - * Keep the algorithm recorded in the compression property, - * otherwise changing an unrelated attribute would reset it to - * the mount default, since FS_IOC_SETFLAGS callers write back - * the whole flag set they got from FS_IOC_GETFLAGS and that - * includes FS_COMPR_FL for any inode carrying the property. + * If compression is already enabled, we must reconstruct the + * full "algo:level" property string and write it back. + * Otherwise changing an unrelated attribute would reset it to + * the mount default and drop the level, since FS_IOC_SETFLAGS + * callers write back the whole flag set they got from + * FS_IOC_GETFLAGS, and that includes FS_COMPR_FL. * * Inodes with the compress flag set but no property keep using * the mount default, so they behave as before. */ - if (inode->prop_compress) - comp_type = inode->prop_compress; - else if (fs_info->compress_type) - comp_type = fs_info->compress_type; - else - comp_type = BTRFS_COMPRESS_ZLIB; - comp = btrfs_compress_type2str(comp_type); + comp = btrfs_compress_typelevel2str(inode->prop_compress, + inode->prop_compress_level, + comp_buf, sizeof(comp_buf)); + if (!comp || comp[0] == 0) + comp = btrfs_compress_type2str(fs_info->compress_type); + if (!comp || comp[0] == 0) + comp = btrfs_compress_type2str(BTRFS_COMPRESS_ZLIB); } else { inode_flags &= ~(BTRFS_INODE_COMPRESS | BTRFS_INODE_NOCOMPRESS); } diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c index 3edda1f11a74..05e594ce613b 100644 --- a/fs/btrfs/props.c +++ b/fs/btrfs/props.c @@ -18,15 +18,6 @@ #include "super.h" #include "dir-item.h" -/* - * Max length of compression algorithm:level string. - * - * For now the longest possible string is "zstd:-15", which is - * 8 characters + 1 terminating null byte. - * Rounding it up to the closest power of 2 gives 16. - */ -#define BTRFS_COMPRESS_PROP_MAX_LEN 16 - #define BTRFS_PROP_HANDLERS_HT_BITS 8 static DEFINE_HASHTABLE(prop_handlers_ht, BTRFS_PROP_HANDLERS_HT_BITS); diff --git a/fs/btrfs/props.h b/fs/btrfs/props.h index 15d9a025c923..93b55a85a728 100644 --- a/fs/btrfs/props.h +++ b/fs/btrfs/props.h @@ -9,6 +9,15 @@ #include #include +/* + * Max length of compression algorithm:level string. + * + * For now the longest possible string is "zstd:-15", which is + * 8 characters + 1 terminating null byte. + * Rounding it up to the closest power of 2 gives 16. + */ +#define BTRFS_COMPRESS_PROP_MAX_LEN 16 + struct btrfs_inode; struct btrfs_path; struct btrfs_trans_handle; -- 2.56.0