From patchwork Wed Jul 27 11:01:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Whitcroft X-Patchwork-Id: 1011372 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6RB1stv021857 for ; Wed, 27 Jul 2011 11:01:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754501Ab1G0LBf (ORCPT ); Wed, 27 Jul 2011 07:01:35 -0400 Received: from adelie.canonical.com ([91.189.90.139]:33408 "EHLO adelie.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754496Ab1G0LBe (ORCPT ); Wed, 27 Jul 2011 07:01:34 -0400 Received: from youngberry.canonical.com ([91.189.89.112]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Qm1rp-000580-SR; Wed, 27 Jul 2011 11:01:33 +0000 Received: from [85.210.144.167] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1Qm1rp-0006eI-Ok; Wed, 27 Jul 2011 11:01:33 +0000 From: Andy Whitcroft To: Chris Mason , linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andy Whitcroft Subject: [PATCH 1/1] btrfs: btrfs_calc_avail_data_space cope with no read/write devices Date: Wed, 27 Jul 2011 12:01:31 +0100 Message-Id: <1311764491-5687-1-git-send-email-apw@canonical.com> X-Mailer: git-send-email 1.7.4.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 27 Jul 2011 11:01:54 +0000 (UTC) When we mount a btrfs filesystem from read-only media there will be no read/write devices; for example mounting an SD card with its lock enabled. This triggers an immediate BUG during mount: kernel BUG at .../fs/btrfs/super.c:984! This is triggered by statfs when calculating the free space in the filesytem. We bug if the number of read/write devices is 0. It seems more appropriate to indicate we have no writable space. Note that this does make df return 0 free blocks on a read-only device. Whether that is reasonable is debatable. BugLink: http://bugs.launchpad.net/bugs/816770 Signed-off-by: Andy Whitcroft --- fs/btrfs/super.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 15634d4..8d3f9b0 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -981,7 +981,10 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes) int ret; nr_devices = fs_info->fs_devices->rw_devices; - BUG_ON(!nr_devices); + if (!nr_devices) { + *free_bytes = 0; + return 0; + } devices_info = kmalloc(sizeof(*devices_info) * nr_devices, GFP_NOFS);