From patchwork Thu Sep 12 23:55:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygo Blaxell X-Patchwork-Id: 11143893 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 102FC1395 for ; Fri, 13 Sep 2019 00:02:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED6A3208E4 for ; Fri, 13 Sep 2019 00:02:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728258AbfIMACX (ORCPT ); Thu, 12 Sep 2019 20:02:23 -0400 Received: from james.kirk.hungrycats.org ([174.142.39.145]:48584 "EHLO james.kirk.hungrycats.org" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726516AbfIMACX (ORCPT ); Thu, 12 Sep 2019 20:02:23 -0400 X-Greylist: delayed 410 seconds by postgrey-1.27 at vger.kernel.org; Thu, 12 Sep 2019 20:02:22 EDT Received: by james.kirk.hungrycats.org (Postfix, from userid 1002) id 3DE794232AF; Thu, 12 Sep 2019 19:55:04 -0400 (EDT) From: Zygo Blaxell To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs: fix balance convert to single on 32-bit host CPUs X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Message-Id: <20190912235507.3DE794232AF@james.kirk.hungrycats.org> Date: Thu, 12 Sep 2019 19:55:01 -0400 (EDT) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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. Signed-off-by: Zygo Blaxell --- fs/btrfs/volumes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 88a323a453d8..252c6049c6b7 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3906,7 +3906,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)