@@ -220,11 +220,7 @@ int MountWithRetry(const char* Source, const char* Target, const char* FsType, c
220220
221221Routine Description:
222222
223- This routine will perform a mount using the /bin/mount binary, and will
224- retry it if it fails.
225-
226- N.B. This routine is used for virtio-9p and virtiofs which can transiently
227- fail to mount if the PCI device isn't ready yet.
223+ This routine performs a mount with retry logic for DrvFs filesystems.
228224
229225Arguments:
230226
@@ -246,52 +242,19 @@ Return Value:
246242
247243try
248244{
249- int Result;
250- try
245+ //
246+ // Verify the target directory exists before mounting.
247+ //
248+
249+ int Result = access (Target, F_OK);
250+ if (Result < 0 )
251251 {
252- bool PrintWarning = true ;
253- wsl::shared::retry::RetryWithTimeout<void >(
254- [&]() { THROW_LAST_ERROR_IF (mountutil::MountFilesystem (Source, Target, FsType, Options) < 0 ); },
255- std::chrono::milliseconds{100 },
256- std::chrono::seconds{2 },
257- [&]() {
258- // For virtio-9p, there are two errors that could indicate the PCI device is not ready:
259- // EBUSY - Returned if all devices with the tag are already in use.
260- // ENOENT - Returned if there are no devices with the tag, which can happen after the VM first boots.
261- // In this case, check if the target exists; if it doesn't, ENOENT is for that and there's no reason to retry.
262- //
263- // For virtiofs, EINVAL will be returned if the tag is not ready.
264- auto savedErrno = wil::ResultFromCaughtException ();
265- if (strcmp (FsType, PLAN9_FS_TYPE) == 0 )
266- {
267- if (errno != EBUSY && (errno != ENOENT || access (Target, F_OK) != 0 ))
268- {
269- errno = savedErrno;
270- return false ;
271- }
272- }
273- else if ((strcmp (FsType, VIRTIO_FS_TYPE) == 0 ) && (errno != EINVAL))
274- {
275- return false ;
276- }
277-
278- if (PrintWarning)
279- {
280- LOG_WARNING (" mount: waiting for virtio device {}" , Source);
281- PrintWarning = false ;
282- }
283-
284- return true ;
285- });
286-
287- Result = 0 ;
252+ LOG_STDERR (errno);
288253 }
289- catch (...)
254+ else
290255 {
291- errno = wil::ResultFromCaughtException ();
292- auto parsed = mountutil::MountParseFlags (Options);
293- LOG_ERROR (" mount({}, {}, {}, {:#x}, {}) failed: {}" , Source, Target, FsType, parsed.MountFlags , parsed.StringOptions .c_str (), strerror (errno));
294- Result = -1 ;
256+ auto Parsed = mountutil::MountParseFlags (Options);
257+ Result = UtilMount (Source, Target, FsType, Parsed.MountFlags , Parsed.StringOptions .c_str (), std::chrono::seconds{2 });
295258 }
296259
297260 if (ExitCode)
0 commit comments