Skip to content

Commit 0a29cae

Browse files
committed
handle CreateInstance mount failure error
It is hard to distinguish between a corrupted disk and bad fsType/fsMountOptions for failures of mounting the rootfs. This change renamed the WSL_E_DISK_CORRUPTED into WSL_E_MOUNT_FAILED, and changed the error message to inform the user the possible causes of the failure.
1 parent e5bd2d8 commit 0a29cae

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

localization/strings/en-US/Resources.resw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,8 @@ Falling back to NAT networking.</value>
10561056
<value>The distribution failed to start. Error code: {}, failure step: {}</value>
10571057
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
10581058
</data>
1059-
<data name="MessageDiskCorrupted" xml:space="preserve">
1060-
<value>The distribution failed to start because its virtual disk is corrupted.</value>
1059+
<data name="MessageMountFailed" xml:space="preserve">
1060+
<value>The distribution failed to start because its virtual disk is corrupted, of non-expected filesystem, or invalid mount options.</value>
10611061
</data>
10621062
<data name="MessageConfigKeyDuplicated" xml:space="preserve">
10631063
<value>Duplicated config key '{}' in {}:{} (Conflicting key: '{}' in {}:{})</value>

src/windows/common/wslutil.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static const std::map<HRESULT, LPCWSTR> g_commonErrors{
8181
X(WSL_E_WSL1_DISABLED),
8282
X(WSL_E_VIRTUAL_MACHINE_PLATFORM_REQUIRED),
8383
X(WSL_E_LOCAL_SYSTEM_NOT_SUPPORTED),
84-
X(WSL_E_DISK_CORRUPTED),
84+
X(WSL_E_MOUNT_FAILED),
8585
X(WSL_E_DISTRIBUTION_NAME_NEEDED),
8686
X(WSL_E_INVALID_JSON),
8787
X(WSL_E_VM_CRASHED),
@@ -887,8 +887,8 @@ std::wstring wsl::windows::common::wslutil::GetErrorString(HRESULT result)
887887
case WSL_E_LOCAL_SYSTEM_NOT_SUPPORTED:
888888
return Localization::MessageLocalSystemNotSupported();
889889

890-
case WSL_E_DISK_CORRUPTED:
891-
return Localization::MessageDiskCorrupted();
890+
case WSL_E_MOUNT_FAILED:
891+
return Localization::MessageMountFailed();
892892

893893
case WSL_E_NOT_A_LINUX_DISTRO:
894894
return Localization::MessageInvalidDistributionTar();

src/windows/service/exe/WslCoreInstance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ WslCoreInstance::WslCoreInstance(
6060
if (result.Result != 0)
6161
{
6262
// N.B. EUCLEAN (117) can be returned if the disk's journal is corrupted.
63-
if ((result.Result == 117) && result.FailureStep == LxInitCreateInstanceStepMountDisk)
63+
if ((result.Result == EINVAL || result.Result == 117) && result.FailureStep == LxInitCreateInstanceStepMountDisk)
6464
{
65-
THROW_HR(WSL_E_DISK_CORRUPTED);
65+
THROW_HR(WSL_E_MOUNT_FAILED);
6666
}
6767
else
6868
{

src/windows/service/inc/wslservice.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ cpp_quote("#define WSL_E_DISK_MOUNT_DISABLED MAKE_HRESULT(SEVERITY_ERROR, FACILI
405405
cpp_quote("#define WSL_E_WSL1_DISABLED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSL_E_BASE + 0x2C) /* 0x8004032C */")
406406
cpp_quote("#define WSL_E_VIRTUAL_MACHINE_PLATFORM_REQUIRED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSL_E_BASE + 0x2D) /* 0x8004032D */")
407407
cpp_quote("#define WSL_E_LOCAL_SYSTEM_NOT_SUPPORTED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSL_E_BASE + 0x2E) /* 0x8004032E */")
408-
cpp_quote("#define WSL_E_DISK_CORRUPTED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSL_E_BASE + 0x2F) /* 0x8004032F */")
408+
cpp_quote("#define WSL_E_MOUNT_FAILED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSL_E_BASE + 0x2F) /* 0x8004032F */")
409409
cpp_quote("#define WSL_E_DISTRIBUTION_NAME_NEEDED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSL_E_BASE + 0x30) /* 0x80040330 */")
410410
cpp_quote("#define WSL_E_INVALID_JSON MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSL_E_BASE + 0x31) /* 0x80040331 */")
411411
cpp_quote("#define WSL_E_VM_CRASHED MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, WSL_E_BASE + 0x32) /* 0x80040332 */")

test/windows/UnitTests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,14 +2586,14 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
25862586
// Validate that starting the distribution fails with the correct error code.
25872587
validateOutput(
25882588
L"-d BrokenDistro echo ok",
2589-
L"The distribution failed to start because its virtual disk is corrupted.\r\n"
2590-
L"Error code: Wsl/Service/CreateInstance/WSL_E_DISK_CORRUPTED\r\n");
2589+
L"The distribution failed to start because its virtual disk is corrupted, of non-expected filesystem, or invalid mount options.\r\n"
2590+
L"Error code: Wsl/Service/CreateInstance/WSL_E_MOUNT_FAILED\r\n");
25912591

25922592
// Validate that trying to export the distribution fails with the correct error code.
25932593
validateOutput(
25942594
L"--export BrokenDistro dummy.tar",
2595-
L"The distribution failed to start because its virtual disk is corrupted.\r\n"
2596-
L"Error code: Wsl/Service/WSL_E_DISK_CORRUPTED\r\n");
2595+
L"The distribution failed to start because its virtual disk is corrupted, of non-expected filesystem, or invalid mount options.\r\n"
2596+
L"Error code: Wsl/Service/WSL_E_MOUNT_FAILED\r\n");
25972597

25982598
// Shutdown WSL to force the disk to detach.
25992599
VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--shutdown"), 0L);
@@ -2602,8 +2602,8 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
26022602
// Import a corrupted vhd.
26032603
validateOutput(
26042604
std::format(L"--import-in-place test-distro-corrupted \"{}\"", vhdPath.wstring()),
2605-
L"The distribution failed to start because its virtual disk is corrupted.\r\n"
2606-
L"Error code: Wsl/Service/RegisterDistro/WSL_E_DISK_CORRUPTED\r\n");
2605+
L"The distribution failed to start because its virtual disk is corrupted, of non-expected filesystem, or invalid mount options.\r\n"
2606+
L"Error code: Wsl/Service/RegisterDistro/WSL_E_MOUNT_FAILED\r\n");
26072607

26082608
// Ensure the VHD can be deleted to make sure it was properly ejected from the VM.
26092609
VERIFY_ARE_EQUAL(DeleteFileW(vhdPath.c_str()), TRUE);

0 commit comments

Comments
 (0)