Bug 978302

Summary: mke2fs-J should give a meaningful error when specified type is anything except 'ext{2,3,4}'
Product: [Community] Virtualization Tools Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED UPSTREAM QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: bfan, dyasny, leiwang, mbooth, qguan, wshi
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 976299 Environment:
Last Closed: 2013-06-26 15:18:37 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 976299    

Description Richard W.M. Jones 2013-06-26 10:14:05 UTC
+++ This bug was initially created as a clone of Bug #976299 +++

Description of problem:
For example,
mke2fs doesn't support xfs, it should give a meaningful error message when you specified xfs, but not gives ext3 


Version-Release number of selected component (if applicable):
libguestfs-1.22.2-1.el7.x86_64

How reproducible:
100%


Steps to Reproduce:
1. create a disk with xfs
[root]# guestfish -N fsfs
><fs> quit

2.
[root]# eval `guestfish --listen`
[root]# guestfish --remote -x -- -add test1.img
[root]# guestfish --remote -x -- -alloc journalname 50M
[root]# guestfish --remote -x -- -run
[root]# guestfish --remote -- -mke2journal 1024  /dev/sdb
[root]# guestfish --remote -- -mke2fs-J xfs 1024 /dev/sda /dev/sdb
[root]# vfs_type=`guestfish --remote -- -vfs-type /dev/sda`
[root]# echo $vfs_type
ext3


Actual results:
Got ext3 type


Expected results:
Give a error message

Additional info:

--- Additional comment from Richard W.M. Jones on 2013-06-26 06:13:27 EDT ---

One line reproducer:

$ guestfish -N part -N part mke2journal 1024 /dev/sda1 : mke2fs-J xfs 1024 /dev/sdb1 /dev/sda1
$ echo $?
0

The mke2fs-J command should give an error instead of succeeding.

Comment 1 Richard W.M. Jones 2013-06-26 13:27:18 UTC
So the problem here is that we use the -F option to force
mke2fs not to ask any questions.  However it has the unfortunate
side-effect of making mke2fs also ignore bad -t xfs argument.

In virt-rescue:

><rescue> mke2fs -t xfs -b 4096 -J device=/dev/sdb /dev/sda
mke2fs 1.42.5 (29-Jul-2012)
/dev/sda is entire device, not just one partition!
Proceed anyway? (y,n) y

Your mke2fs.conf file does not define the xfs filesystem type.
Aborting...

vs:

><rescue> mke2fs -F -t xfs -b 4096 -J device=/dev/sdb /dev/sda
mke2fs 1.42.5 (29-Jul-2012)

Your mke2fs.conf file does not define the xfs filesystem type.
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Adding journal to device /dev/sdb: done
Writing superblocks and filesystem accounting information: done 

The second command creates an ext3 filesystem.

So this is a bug in mke2fs -F option.

Note it also affects the mke2fs API, if you use the forcecreate
argument (which causes -F to be passed to mke2fs).  eg:

><fs> mke2fs /dev/sda1 fstype:xfs forcecreate:true
[no error]

but:

><fs> mke2fs /dev/sda1 fstype:xfs forcecreate:false
libguestfs: error: mke2fs: /dev/sda1: mke2fs 1.42.5 (29-Jul-2012)

Anyhow I think the way I'm actually going to solve this is by
filtering the types allowed so they must match /^ext[234]$/.  The
reason is at the moment we also allow types from the /etc/mke2fs.conf
file, such as "floppy" or "big" which aren't supportable in a
stable API such as libguestfs.