]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
btrfs: fix balance convert to single on 32-bit host CPUs
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Thu, 12 Sep 2019 23:55:01 +0000 (19:55 -0400)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 23 Oct 2019 13:04:32 +0000 (15:04 +0200)
BugLink: https://bugs.launchpad.net/bugs/1848750
commit 7a54789074a54f64addf5b49bf1994f478337a83 upstream.

Currently, the command:

btrfs balance start -dconvert=single,soft .

on a Raspberry Pi produces the following kernel message:

BTRFS error (device mmcblk0p2): balance: invalid convert data profile single

This fails because we use is_power_of_2(unsigned long) to validate
the new data profile, the constant for 'single' profile uses bit 48,
and there are only 32 bits in a long on ARM.

Fix by open-coding the check using u64 variables.

Tested by completing the original balance command on several Raspberry
Pis.

Fixes: 818255feece6 ("btrfs: use common helper instead of open coding a bit test")
CC: stable@vger.kernel.org # 4.20+
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Connor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
fs/btrfs/volumes.c

index c350c284e548cf08093a4642013846d289674698..f3f072e18f83b371dd4b882ef7a5c2ace524016c 100644 (file)
@@ -3854,7 +3854,11 @@ static int alloc_profile_is_valid(u64 flags, int extended)
                return !extended; /* "0" is valid for usual profiles */
 
        /* true if exactly one bit set */
-       return is_power_of_2(flags);
+       /*
+        * Don't use is_power_of_2(unsigned long) because it won't work
+        * for the single profile (1ULL << 48) on 32-bit CPUs.
+        */
+       return flags != 0 && (flags & (flags - 1)) == 0;
 }
 
 static inline int balance_need_close(struct btrfs_fs_info *fs_info)