From a31d23ea0e1839d14a4ac112d962735480276793 Mon Sep 17 00:00:00 2001 From: Huamin Chen Date: Thu, 29 Oct 2015 16:30:46 -0400 Subject: [PATCH] don't use ext4 mkfs options for other fs Signed-off-by: Huamin Chen --- pkg/util/mount/mount.go | 5 ++++- pkg/util/mount/safe_format_and_mount_test.go | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pkg/util/mount/mount.go b/pkg/util/mount/mount.go index ac5f9a57a9f..f3829fa197d 100644 --- a/pkg/util/mount/mount.go +++ b/pkg/util/mount/mount.go @@ -78,12 +78,15 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string, // It is possible that this disk is not formatted. Double check using diskLooksUnformatted notFormatted, err := mounter.diskLooksUnformatted(source) if err == nil && notFormatted { + args := []string{source} // Disk is unformatted so format it. // Use 'ext4' as the default if len(fstype) == 0 { fstype = "ext4" } - args := []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", source} + if fstype == "ext4" || fstype == "ext3" { + args = []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", source} + } cmd := mounter.Runner.Command("mkfs."+fstype, args...) _, err := cmd.CombinedOutput() if err == nil { diff --git a/pkg/util/mount/safe_format_and_mount_test.go b/pkg/util/mount/safe_format_and_mount_test.go index 26a23ae6e68..7a96219fda0 100644 --- a/pkg/util/mount/safe_format_and_mount_test.go +++ b/pkg/util/mount/safe_format_and_mount_test.go @@ -61,7 +61,7 @@ func TestSafeFormatAndMount(t *testing.T) { fstype: "ext4", }, - { // Test that 'file' is called and fails + { // Test that 'lsblk' is called and fails fstype: "ext4", mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'")}, execScripts: []ExecArgs{ @@ -69,7 +69,7 @@ func TestSafeFormatAndMount(t *testing.T) { }, expectedError: fmt.Errorf("unknown filesystem type '(null)'"), }, - { // Test that 'file' is called and confirms unformatted disk, format fails + { // Test that 'lsblk' is called and confirms unformatted disk, format fails fstype: "ext4", mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'")}, execScripts: []ExecArgs{ @@ -78,7 +78,7 @@ func TestSafeFormatAndMount(t *testing.T) { }, expectedError: fmt.Errorf("formatting failed"), }, - { // Test that 'file' is called and confirms unformatted disk, format passes, second mount fails + { // Test that 'lsblk' is called and confirms unformatted disk, format passes, second mount fails fstype: "ext4", mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), fmt.Errorf("Still cannot mount")}, execScripts: []ExecArgs{ @@ -87,7 +87,7 @@ func TestSafeFormatAndMount(t *testing.T) { }, expectedError: fmt.Errorf("Still cannot mount"), }, - { // Test that 'file' is called and confirms unformatted disk, format passes, second mount passes + { // Test that 'lsblk' is called and confirms unformatted disk, format passes, second mount passes fstype: "ext4", mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil}, execScripts: []ExecArgs{ @@ -96,7 +96,7 @@ func TestSafeFormatAndMount(t *testing.T) { }, expectedError: nil, }, - { // Test that 'file' is called and confirms unformatted disk, format passes, second mount passes with ext3 + { // Test that 'lsblk' is called and confirms unformatted disk, format passes, second mount passes with ext3 fstype: "ext3", mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil}, execScripts: []ExecArgs{ @@ -105,6 +105,16 @@ func TestSafeFormatAndMount(t *testing.T) { }, expectedError: nil, }, + { // Test that 'lsblk' is called and confirms unformatted disk, format passes, second mount passes + // test that none ext4 fs does not get called with ext4 options. + fstype: "xfs", + mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil}, + execScripts: []ExecArgs{ + {"lsblk", []string{"-nd", "-o", "FSTYPE", "/dev/foo"}, "", nil}, + {"mkfs.xfs", []string{"/dev/foo"}, "", nil}, + }, + expectedError: nil, + }, } for _, test := range tests {