From patchwork Wed Sep 26 07:52:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dong X-Patchwork-Id: 1507981 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id B0ED13FDAE for ; Wed, 26 Sep 2012 07:52:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753000Ab2IZHwR (ORCPT ); Wed, 26 Sep 2012 03:52:17 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:33951 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752809Ab2IZHwQ (ORCPT ); Wed, 26 Sep 2012 03:52:16 -0400 Received: by pbbrr4 with SMTP id rr4so1482808pbb.19 for ; Wed, 26 Sep 2012 00:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=GkjWF8MEOPjCBpSLAcdH3QLzjLfhwnbp0tFeUx6WHoE=; b=ngQ8ysiOfl2AMghrKPxwbjkIrpMjjG3v3eip8wAoyEXTl4eJq4WX6EfeIgtJGJ/Xrm zZAU/+LThL0qc9NlyMk03tgFxCgMAraPK1u1Ui61qEMCpBilh3bEot2v8jVSanss0SxO n30oD6VJzIhoj1CNAPvYXSgpgBklBVMjltxeHb5wKzYoPLKgk9BHVjzNxJ/XIlr0ykZh yDrbVKG7kVmh7BCTfdTgQyCv5+1iFUVntH6PIVPcYAJ3grggBwXjry4B/IKfdwi7gFpQ unsZ1HRLxZ7D9H2GPD7/jTL3lqbH7S3mXbc3RIN+VuEwHlVTVdompqeYZnXdo+0kjr3J JBrg== Received: by 10.68.234.98 with SMTP id ud2mr112195pbc.165.1348645936116; Wed, 26 Sep 2012 00:52:16 -0700 (PDT) Received: from localhost.localdomain ([110.75.120.247]) by mx.google.com with ESMTPS id qd9sm1671222pbb.31.2012.09.26.00.52.14 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Sep 2012 00:52:15 -0700 (PDT) From: Robin Dong To: linux-btrfs@vger.kernel.org Cc: Robin Dong Subject: [PATCH 1/2] btrfs-progs: limit the max value of leafsize and nodesize Date: Wed, 26 Sep 2012 15:52:07 +0800 Message-Id: <1348645928-3432-1-git-send-email-robin.k.dong@gmail.com> X-Mailer: git-send-email 1.7.3.2 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Robin Dong Using mkfs.btrfs like: mkfs.btrfs -l 131072 /dev/sda will return no error, but after mount it, the dmesg will report: BTRFS: couldn't mount because metadata blocksize (131072) was too large The user tools should use BTRFS_MAX_METADATA_BLOCKSIZE to limit leaf and node size. Signed-off-by: Robin Dong --- ctree.h | 6 ++++++ mkfs.c | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ctree.h b/ctree.h index 7f55229..75c1e0a 100644 --- a/ctree.h +++ b/ctree.h @@ -111,6 +111,12 @@ struct btrfs_trans_handle; #define BTRFS_DEV_ITEMS_OBJECTID 1ULL /* + * the max metadata block size. This limit is somewhat artificial, + * but the memmove costs go through the roof for larger blocks. + */ +#define BTRFS_MAX_METADATA_BLOCKSIZE 65536 + +/* * we can actually store much bigger names, but lets not confuse the rest * of linux */ diff --git a/mkfs.c b/mkfs.c index dff5eb8..bb01f64 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1291,11 +1291,13 @@ int main(int ac, char **av) } } sectorsize = max(sectorsize, (u32)getpagesize()); - if (leafsize < sectorsize || (leafsize & (sectorsize - 1))) { + if (leafsize < sectorsize || leafsize > BTRFS_MAX_METADATA_BLOCKSIZE || + (leafsize & (sectorsize - 1))) { fprintf(stderr, "Illegal leafsize %u\n", leafsize); exit(1); } - if (nodesize < sectorsize || (nodesize & (sectorsize - 1))) { + if (nodesize < sectorsize || nodesize > BTRFS_MAX_METADATA_BLOCKSIZE || + (nodesize & (sectorsize - 1))) { fprintf(stderr, "Illegal nodesize %u\n", nodesize); exit(1); }