sbin/newfs_hammer: Fail with "less than 10GB" without formatting half way through
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Mon, 15 Jun 2015 19:55:01 +0000 (04:55 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Tue, 16 Jun 2015 17:45:17 +0000 (02:45 +0900)
commit92d0a1c8c4617bf28a52a7086aefeb03ff638ad4
treeca8274d90bbbf6309efc7057e9c74d8a235dd01b
parentc000328c1532fb7fca02f11ebeb3c64b4b180e29
sbin/newfs_hammer: Fail with "less than 10GB" without formatting half way through

- This commit enables newfs_hammer to fail with "less than 10GB"
  error without formatting half way through, by using a new function
  count_freemap() which only counts potentially available bigblocks
  with no ondisk modification to layer1/2 bigblocks.

- It's simply better to fail with a sanity check without messing
  up disks whenever users have invalid inputs (which in this case
  is users specifying not large enough volumes). The formatting
  should start only after all sanity checks are done.

- Example1 - using existing /sbin/newfs_hammer
  # dd if=/dev/zero of=/dev/da9 bs=8M count=10 >/dev/null 2>&1; sync
  *** unplug /dev/da9 -> plug /dev/da9
  # dd if=/dev/da9 of=/tmp/out1 bs=8M count=10 >/dev/null 2>&1; sync
  # /sbin/newfs_hammer -L TEST /dev/da9; sync
  Volume 0 DEVICE /dev/da9        size   7.22GB
  initialize freemap volume 0
  newfs_hammer: Cannot create a HAMMER filesystem less than 10GB unless you use -f
  (for the size of Volume 0).  HAMMER filesystems less than 50GB are not recommended.

  *** unplug /dev/da9 -> plug /dev/da9
  # dd if=/dev/da9 of=/tmp/out2 bs=8M count=10 >/dev/null 2>&1; sync
  # cmp /tmp/out1 /tmp/out2
  /tmp/out1 /tmp/out2 differ: char 35913737, line 1
  # od -tx1 -Ad -N 838860800 /tmp/out1
  0000000    00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00
  *
  83886080
  # od -tx1 -Ad -N 838860800 /tmp/out2 | head -10
  0000000    00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00
  *
  35913728    00  00  00  00  00  00  00  00  ff  ff  ff  ff  ff  ff  ff  ff
  35913744    00  00  00  00  00  00  00  00  00  00  00  00  31  a7  1e  63
  35913760    00  00  00  00  00  00  00  00  ff  ff  ff  ff  ff  ff  ff  ff
  35913776    00  00  00  00  00  00  00  00  00  00  00  00  31  a7  1e  63
  35913792    00  00  00  00  00  00  00  00  ff  ff  ff  ff  ff  ff  ff  ff
  35913808    00  00  00  00  00  00  00  00  00  00  00  00  31  a7  1e  63
  35913824    00  00  00  00  00  00  00  00  ff  ff  ff  ff  ff  ff  ff  ff
              -----layer1.blocks_free=0-----  --layer1.phys_offset=UNAVAIL--
  35913840    00  00  00  00  00  00  00  00  00  00  00  00  31  a7  1e  63
              -----layer1.reserved----------  --layer2.crc--  --layer1.crc--
              (see sbin/hammer/ondisk.c:format_freemap())
  # /sbin/mount_hammer /dev/da9 /mnt
  /dev/da9: Not a valid HAMMER filesystem
  mount_hammer: mount /dev/da9 on /mnt: Inappropriate file type or format
  (it's only half way through done, so the device isn't mountable yet,
  but the layer1/2 structure still does overwrite the original content)

- Example2 - using this commit
  # dd if=/dev/zero of=/dev/da9 bs=8M count=10 >/dev/null 2>&1; sync
  *** unplug /dev/da9 -> plug /dev/da9
  # dd if=/dev/da9 of=/tmp/out1 bs=8M count=10 >/dev/null 2>&1; sync
  # /sbin/newfs_hammer -L TEST /dev/da9; sync
  Volume 0 DEVICE /dev/da9        size   7.22GB
  newfs_hammer: Cannot create a HAMMER filesystem less than 10GB unless you use -f
  (for the size of Volume 0).  HAMMER filesystems less than 50GB are not recommended.

  *** unplug /dev/da9 -> plug /dev/da9
  # dd if=/dev/da9 of=/tmp/out2 bs=8M count=10 >/dev/null 2>&1; sync
  # cmp /tmp/out1 /tmp/out2
  #
sbin/hammer/hammer_util.h
sbin/hammer/ondisk.c
sbin/newfs_hammer/newfs_hammer.c