Unverified Commit 60b62637 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #64102 from atombender/ext-reserved-blocks

Automatic merge from submit-queue (batch tested with PRs 64102, 63303, 64150, 63841). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. When creating ext3/ext4 volume, disable reserved blocks **What this PR does / why we need it**: When creating ext3/ext4 volume, `mkfs` defaults to reserving 5% of the volume for the super-user (root). This patch changes the `mkfs` to pass `-m0` to disable this setting. Rationale: Reserving a percentage of the volume is generally a neither useful nor desirable feature for volumes that aren't used as root file systems for Linux distributions, since the reserved portion becomes unavailable for non-root users. For containers, the general case is to use the entire volume for data, without running as root. The case where one might want reserved blocks enabled is much rarer. **Special notes for your reviewer**: I also added some comments to describe the flags passed to `mkfs`. **Release note**: ```release-note Changes ext3/ext4 volume creation to not reserve any portion of the volume for the root user. ```
parents 23d9a48e 1b3dee95
...@@ -511,7 +511,11 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string, ...@@ -511,7 +511,11 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string,
} }
if fstype == "ext4" || fstype == "ext3" { if fstype == "ext4" || fstype == "ext3" {
args = []string{"-F", source} args = []string{
"-F", // Force flag
"-m0", // Zero blocks reserved for super-user
source,
}
} }
glog.Infof("Disk %q appears to be unformatted, attempting to format as type: %q with options: %v", source, fstype, args) glog.Infof("Disk %q appears to be unformatted, attempting to format as type: %q with options: %v", source, fstype, args)
_, err := mounter.Exec.Run("mkfs."+fstype, args...) _, err := mounter.Exec.Run("mkfs."+fstype, args...)
......
...@@ -116,7 +116,7 @@ func TestSafeFormatAndMount(t *testing.T) { ...@@ -116,7 +116,7 @@ func TestSafeFormatAndMount(t *testing.T) {
execScripts: []ExecArgs{ execScripts: []ExecArgs{
{"fsck", []string{"-a", "/dev/foo"}, "", nil}, {"fsck", []string{"-a", "/dev/foo"}, "", nil},
{"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}}, {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}},
{"mkfs.ext4", []string{"-F", "/dev/foo"}, "", fmt.Errorf("formatting failed")}, {"mkfs.ext4", []string{"-F", "-m0", "/dev/foo"}, "", fmt.Errorf("formatting failed")},
}, },
expectedError: fmt.Errorf("formatting failed"), expectedError: fmt.Errorf("formatting failed"),
}, },
...@@ -127,7 +127,7 @@ func TestSafeFormatAndMount(t *testing.T) { ...@@ -127,7 +127,7 @@ func TestSafeFormatAndMount(t *testing.T) {
execScripts: []ExecArgs{ execScripts: []ExecArgs{
{"fsck", []string{"-a", "/dev/foo"}, "", nil}, {"fsck", []string{"-a", "/dev/foo"}, "", nil},
{"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}}, {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}},
{"mkfs.ext4", []string{"-F", "/dev/foo"}, "", nil}, {"mkfs.ext4", []string{"-F", "-m0", "/dev/foo"}, "", nil},
}, },
expectedError: fmt.Errorf("Still cannot mount"), expectedError: fmt.Errorf("Still cannot mount"),
}, },
...@@ -138,7 +138,7 @@ func TestSafeFormatAndMount(t *testing.T) { ...@@ -138,7 +138,7 @@ func TestSafeFormatAndMount(t *testing.T) {
execScripts: []ExecArgs{ execScripts: []ExecArgs{
{"fsck", []string{"-a", "/dev/foo"}, "", nil}, {"fsck", []string{"-a", "/dev/foo"}, "", nil},
{"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}}, {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}},
{"mkfs.ext4", []string{"-F", "/dev/foo"}, "", nil}, {"mkfs.ext4", []string{"-F", "-m0", "/dev/foo"}, "", nil},
}, },
expectedError: nil, expectedError: nil,
}, },
...@@ -149,7 +149,7 @@ func TestSafeFormatAndMount(t *testing.T) { ...@@ -149,7 +149,7 @@ func TestSafeFormatAndMount(t *testing.T) {
execScripts: []ExecArgs{ execScripts: []ExecArgs{
{"fsck", []string{"-a", "/dev/foo"}, "", nil}, {"fsck", []string{"-a", "/dev/foo"}, "", nil},
{"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}}, {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}},
{"mkfs.ext3", []string{"-F", "/dev/foo"}, "", nil}, {"mkfs.ext3", []string{"-F", "-m0", "/dev/foo"}, "", nil},
}, },
expectedError: nil, expectedError: nil,
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment