From patchwork Mon Jan 21 13:55:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 2012511 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id A5236DF23A for ; Mon, 21 Jan 2013 13:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753310Ab3AUN4D (ORCPT ); Mon, 21 Jan 2013 08:56:03 -0500 Received: from mail-ee0-f44.google.com ([74.125.83.44]:46876 "EHLO mail-ee0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752909Ab3AUN4C (ORCPT ); Mon, 21 Jan 2013 08:56:02 -0500 Received: by mail-ee0-f44.google.com with SMTP id l10so2956135eei.31 for ; Mon, 21 Jan 2013 05:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=jE6xwKropqdT8JZDsyXbtsIAo3d295lsFZvswgQdJoo=; b=MsjAKp0TUW1MEjNv7iS/rromK4Ud1yCiGZM1dszc6RDp5nNmgXlsVaKL/roiDaIFD0 oY0DIRRO1Fnw2KfB/LarSzsWXu1mxLJcngcIzQVW0n40y58ltnS3dbgAFYz9IsnMyPJH JsZLLw/7J1w3M/wk6BIrSCkTPkb2LO4/I5NvKh84pqiDuGoxIjV+UQCK9/XBWWyDHJ+F 9dLAcJ0bTEHpTmV0+uKCJ2bKijSVfPwPEgwMZwXV+fSwAbqZXwj1Y117s4vZZ+UwjA8X eXKbaNhPaEHCsF9vWxwIq2Zc3N89wQ6zIkSeSWWQwEEATr7fC62NLRZvt0lHbPxhOktN xw1g== X-Received: by 10.14.223.200 with SMTP id v48mr60928586eep.24.1358776560269; Mon, 21 Jan 2013 05:56:00 -0800 (PST) Received: from localhost ([109.110.76.247]) by mx.google.com with ESMTPS id t4sm3349105eel.0.2013.01.21.05.55.58 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 21 Jan 2013 05:55:59 -0800 (PST) From: Ilya Dryomov To: linux-btrfs@vger.kernel.org Cc: Chris Mason , idryomov@gmail.com Subject: [PATCH] Btrfs: fix a regression in balance usage filter Date: Mon, 21 Jan 2013 15:55:57 +0200 Message-Id: <1358776557-5609-1-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 1.7.9.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Commit 3fed40cc ("Btrfs: cleanup duplicated division functions"), which was merged into 3.8-rc1, has introduced a regression by removing logic that was guarding us against bad user input. Bring it back. Signed-off-by: Ilya Dryomov --- fs/btrfs/volumes.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 86279c3..b577aee 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2614,7 +2614,14 @@ static int chunk_usage_filter(struct btrfs_fs_info *fs_info, u64 chunk_offset, cache = btrfs_lookup_block_group(fs_info, chunk_offset); chunk_used = btrfs_block_group_used(&cache->item); - user_thresh = div_factor_fine(cache->key.offset, bargs->usage); + if (bargs->usage == 0) + user_thresh = 0; + else if (bargs->usage > 100) + user_thresh = cache->key.offset; + else + user_thresh = div_factor_fine(cache->key.offset, + bargs->usage); + if (chunk_used < user_thresh) ret = 0;