diff mbox

[2/2] btrfs-progs: exit if there is not enough free space for mkfs

Message ID 521701CD.7060409@jp.fujitsu.com (mailing list archive)
State Under Review, archived
Headers show

Commit Message

Hidetoshi Seto Aug. 23, 2013, 6:31 a.m. UTC
Again, while playing mkfs with small volumes, I found that mkfs.btrfs
aborts if there is really no spaces for a brand-new filesystem:

  # ./mkfs.btrfs -f /dev/sdf1 /dev/sdf2
  :
  SMALL VOLUME: forcing mixed metadata/data groups
  adding device /dev/sdf2 id 2
  mkfs.btrfs: mkfs.c:184: create_one_raid_group: Assertion `!(ret)' failed.
  Aborted (core dumped)

This fix let mkfs prints error message if it cannot make filesystem due
to a lack of free spaces.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
---
 mkfs.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/mkfs.c b/mkfs.c
index b412b7e..3c0bc60 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -181,6 +181,10 @@  static int create_one_raid_group(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_alloc_chunk(trans, root->fs_info->extent_root,
 				&chunk_start, &chunk_size, type);
+	if (ret == -ENOSPC) {
+		fprintf(stderr, "not enough free space\n");
+		exit(1);
+	}
 	BUG_ON(ret);
 	ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0,
 				     type, BTRFS_FIRST_CHUNK_TREE_OBJECTID,